-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[VIC-20] CRAM_PTR incorrect at startup #946
Comments
First of all thanks for the detailed problem description :-) For now I'll classify this issue as question. I hope the Subject Matter Experts will pick it up and there will be a conclusion on how to proceed... |
Ah! Looking through this further, I see we have a (In My guess at this point about what's going on is:
My guess at a good solution would be that |
I wonder if it wouldnt be a good idea to define conio so that we guarantee that when conio is being used, the program will start with screen cleared, and the text color being different to the background color (this will take care of initializing the mentioned pointers too). Simply because conio does not support scrolling, which (on some targets) means a single call to any of the text output functions results in undefined behaviour (or even a crash). |
Ok, further research seems to indicate that a good solution for this would indeed be to add a BTW, just read through *It clears the carry and loads |
@mrdudz Well, on the CBM machines, or any machine really, it's certainly not necessary that we do that, and my immediate thought is that it might be better to preserve the flexibility of being able to, if you're careful, e.g., print just a little bit without blowing away the screen contents or changing the current colour, or even read those screen contents. That said, it may be more helpful to those not familiar with *Until I read this and tested it just now, I didn't know it doesn't scroll! Or how it gets weird when you do things that would normally scroll. I now suspect that the poster of the original question should have been using |
my point is that you (the program) do not "know" where the cursor is when you start printing, unless you explicitly set the cursor position first (the user may have typed "RUN" in the bottom line of the screen, for example). the same is true for the text- and background color (although less likely that the user would use an unreadable combination, of course). |
If you don't know without setting the cursor position, it's because you decided not to call I do understand the point you're making, or at least I understand how there are reasonable arguments that can be made that If conio is defined to clear the screen and set colours, you're basically saying that conio can no longer be linked in to certain types of programs. That's probably a worthwhile discussion to have, but it is certainly not one for this issue, which is focused on something quite different, so if you really want this to be considered you should start a new issue. (If you click the |
That means every program must do this, and also react accordingly. Thats likely more overhead than just clearing the screen (especially if you, as you say, include other output as an alternative).
My proposal is changing undefined behaviour into defined behaviour - thats not a breaking API change at all. (It is not guaranteed the screen will NOT be cleared on startup either - and some targets (must) do it) |
No, only programs that use
You are proposing a change that could break programs that rely on the current behaviour of At any rate, can you please, please, take this to an appropriate forum (like a new issue in this repo) for "I want to change how an API works"? Like I said, I'm not saying you don't have a point worth discussion, but I am very definitely saying that if you restrict your discussion to this issue you will definitely not get the change you're suggesting. |
i dont care if i "will get" the change i am suggesting. i am suggesting a possible fix for the problem described. but sure, i will stop. just one thing: the point of conio is portability across all(!) supported targets. a program relying on undefined behaviour is broken, even if it happens to work on some target. and i am not proposing to change the API at all - i am suggesting to define how it works more clearly, in a way which happens to fix this bug, and also makes the API inhibt less surprises for portable programs. and using very little overhead at that, for any non trivial program anyway. |
I think that the condition of the screen when a program starts should be labelled "platform-defined behaviour". I agree that a portable program shouldn't rely on that behaviour. But, that's the responsibility of the portable program, not the system library. conio is supposed to be simple, small, and fast. It shouldn't change the screen, or move the cursor -- except when told to do it by the program. It should give us the flexibility to exploit the previous contents of screens on systems that don't erase them when starting a program. (I remember that we had this discussion about TGI, a long time ago. We decided that TGI shouldn't pre-clear the graphics screen. It should let us re-use old pictures -- if it is possible.) |
I looked at the VIC-20 firmware. I concluded that the behavior of its The Commodore 64's ROMs were copied from the VIC-20's ROM. Therefore, its Kernal had that inefficiency. But, the firmware was improved in a later revision. After that change, the color pointer is updated only when the screen pointer is updated. "kplot.s" uses the new method; and, Both .constructor initcram
initcram := $EAB2 It will add two bytes to programs. (The advantage of the |
To do this we add a constructor call to the routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. We also add a symbol for this, UPDCRAMPTR, and use that in vic20/kplot.s where it is also called. We also clarify a comment in kplot.s. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem. [1]: cc65#946 (comment)
To do this we add a constructor call to the routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. We also add a symbol for this, UPDCRAMPTR, and use that in vic20/kplot.s where it is also called. (We also clarify a comment there.) This adds two additional bytes to programs using cputc() or other routines that call it. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem. [1]: cc65#946 (comment)
To do this we add a constructor call to the routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. We also add a symbol for this, UPDCRAMPTR, and use that in vic20/kplot.s where it is also called. (We also clarify a comment there.) This adds two additional bytes to programs using cputc() or other routines that call it. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem.[1] [1]: cc65#946 (comment)
… cursor In a comment[1] on cc65 issue #946, @greg-king5 describes the problem well but says that cgetc() also needs the constructor that would fix the color RAM cursor problem. I am not clear on why this is, since cgetc() alone doesn't produce any output. This program is an attempt to demonstrate that I think it's ok not to initialize the color RAM cursor position. [1]: cc65/cc65#946 (comment)
To do this we add a constructor call to the routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. We also add a symbol for this, UPDCRAMPTR, and use that in vic20/kplot.s where it is also called. (We also clarify a comment there.) This adds two additional bytes to programs using cputc() or other routines that call it. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem.[1] [1]: cc65#946 (comment)
To do this we add a constructor call to UPDCRAMPTR, which is the ROM routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. This adds two additional bytes to programs using cputc() or other routines that call it. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem.[1] [1]: cc65#946 (comment)
To do this we add a constructor call to UPDCRAMPTR, which is the ROM routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. This adds two additional bytes to programs using cputc() or other routines that call it. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem.[1] [1]: cc65#946 (comment)
To do this we add a constructor call to UPDCRAMPTR, which is the ROM routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. This adds two additional bytes to programs using cputc() or other routines that call it. These are in theory recoverable, but the VIC-20 does not yet free space used by constructors after the constructors have been called. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem.[1] [1]: cc65#946 (comment)
To do this we add a constructor call to UPDCRAMPTR, which is the ROM routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. This adds two additional bytes to programs using cputc() or other routines that call it. These are in theory recoverable, but the VIC-20 does not yet free space used by constructors after the constructors have been called. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem.[1] [1]: cc65#946 (comment)
To do this we add a constructor call to UPDCRAMPTR, which is the ROM routine that fixes up CRAM_PTR to match the screen location pointed to by SCREEN_PTR. This adds two additional bytes to programs using cputc() or other routines that call it. These are in theory recoverable, but the VIC-20 does not yet free space used by constructors after the constructors have been called. Thanks to <greg.king5@verizon.net> (GitHub: greg-king5) for investigating the difference in the VIC-20 KERNAL from the C64 and proposing this solution to the problem.[1] [1]: #946 (comment)
This is now fixed by #965. Many thanks to @greg-king5 for his extensive help with this. |
Thanks to both of you from my side. |
As described in detail in this Retrocomputing StackExchange answer, at the start of
main()
on the VIC-20, when loading/running the PRG with VICE's-autostartprgmode 1
option,CRAM_PTR
is incorrectly set and any printing usingcputc()
will not be visible (because the colour data is being set in the wrong place) until something is done that would reset the cursor position, such as clearing the screen, doing agotoxy()
or printing a newline. My vic20cc65 repo contains code and scripts to easily demonstrate this.(I've reproduced this using VICE 3.0.0 on Debian and ROM images from a source I can't remember now; as you can see from the post another user has reproduced this too, most likely with a different system.)
I'm not sure exactly what the true source of the problem is. If the bug is in VICE it should obviously be fixed there, but that seems less likely to me than a bug in the VIC ROM or a misunderstanding on the part of vic20.lib on how
CRAM_PTR
is supposed to work. (That said, I'm no expert on this, so I could well be wrong.)I've looked through
libsrc/vic20/crt0.s
and I don't see anything obviously wrong there, unless it's actually supposed to be checking or resettingCRAM_PTR
; right now it doesn't appear to touch it at all, so whenmain()
is run it should be exactly what it was set to by the VIC ROMs.So, does this need a fix in vic20.lib? If so, what should the nature of the fix be?
I'd be very pleased to code up the fix and submit a PR if the fix should be done here and someone can give me a quick summary of what approach to take. (I need the coding practice and, hey, it's Hacktoberfest. :-))
The text was updated successfully, but these errors were encountered: