Jump to content

c64 (emulator) bug with $ffd2


wahsp
 Share

Recommended Posts

I am not sure if this is best forum to ask, but I don't have an account with any other retro-computing forums yet. 🙂

I have been learning some basic assembly language. I am currently working my way through Jim Butter's book on machine language and doing the various exercises on Vice and my the64. 

I was working on an exercise where I encountered a strange problem, and I was wondering if this is a common thing.

I was using turbo macro pro (although I believe the same problem occurred with snapshot's ml monitor), and the code I wrote is in the attached screenshots (note that screenshots 2 and 3 overlap a bit).

The problem that occurs is that with this example (and I've tried this multiple times), the call to jsr $ffd2 does not work anymore at some point (it gets stuck somewhere in the "main program" part). On Vice, I get a report that the cpu jammed at $fd24. I just checked on the64 with Snapshot's ml monitor, and there it seems to get stuck at the same point.

I found out in the meantime that $ffd2 points to $f1ca via $0326. So I replaced some of the jsr $ffd2 calls with $f1ca calls, and then it works! Weirdly enough, when I change them back to $ffd2 afterwards, it still works!

By the way, I thought something might have gotten messed up in the jump table, but if I disassemble $fd22 (after getting stuck), I can see it still jumps to ($0326) and if I do a memory dump of ($0326) I see it still contains the $ca and $f1 bytes.

I am pretty sure that I am overlooking something, as I am still more or less at the beginning of learning to write assembly language, but is this just a quirk of the C64, or perhaps the emulators, or is it an unintended side-effect of what I am doing in my code?

 

 

 

1.png

2.png

3.png

Edited by wahsp
Link to comment
Share on other sites

what's the JSR $fd22 in the getin routine?  And, are there more lines after the "and #$0f"?  because I see no RTS

If I'm reading "Compute!'s Mapping the Commodore 64" correctly, you're calling into the middle of the "VECTOR" kernal routine that goes from $fd1a to $fd2f (okay not the *middle*, but still...)

*edit
just reread your post, and you say it jams at $fd24... so yeah, that's two bytes after $fd22. 
gonna assume $fd22 is a typo for $ffd2

Edited by x16tial
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thanks for looking at this more carefully than I apparently did. I should say that I quickly typed in this example yesterday because I hadn't saved the code. 

1) Yes, I forgot the RTS there, but it was there on other occassions I had this problem.

2) The $fd22 thing: I am now wondering how often I make this typo, because it is indeed a typo. I had the behaviour I described on multiple occassions, so I will keep an eye on this, but it is very possible that I made this mistake more than once.

Thanks again! I feel a bit stupid now, but that is what happens when you do stupid things. 😉

Link to comment
Share on other sites

2 hours ago, x16tial said:

No problem, glad to help 🙂   Often times a second set of eyes will catch something like this where yours will just skim over it.   Been plenty of times I've been pulling my hair out only to discover it's some small dumb thing.

Programmer psychology: You didn't intend a bug, the code made perfect sense at the time it was typed, so it is easy to overlook the bug that you didn't intend! I wish I had a nickel for every time I've done that.

  • Like 1
Link to comment
Share on other sites

Anyway, I am pretty sure your analysis was spot on. I made the mistake deliberately in a 'test', and it does exactly what I described. I guess I have the unfortunate habit of typing $fd22 instead of $ffd2. At least now I know what to look for when it happens. 🙂

Edited by wahsp
Link to comment
Share on other sites

On 4/17/2021 at 10:52 AM, wahsp said:

Anyway, I am pretty sure your analysis was spot on. I made the mistake deliberately in a 'test', and it does exactly what I described. I guess I have the unfortunate habit of typing $fd22 instead of $ffd2. At least now I know what to look for when it happens. 🙂

Have you considered defining a label? You might be more able to catch a typo when typing CHROUT than you would for $ffd2.

  • Thanks 1
Link to comment
Share on other sites

13 minutes ago, kelli217 said:

Have you considered defining a label? You might be more able to catch a typo when typing CHROUT than you would for $ffd2.

I hadn't considered that yet. I'll keep that in mind. I caught myself making the same mistake today, so knowing about it already helps. It is actually a bit different than I typo. It's more like a fault in my memory. That is also why it happened more than once, I think. Labels would definitely solve that.

  • Like 1
Link to comment
Share on other sites

On 4/17/2021 at 10:52 AM, wahsp said:

I guess I have the unfortunate habit of typing $fd22 instead of $ffd2. At least now I know what to look for when it happens.

My newbie-mode mistake of this sort was to leave # off of immediate mode statements. I'd have a JMP/LDA/LDX/whatever with $some-address instead of #$some-address, and of course that builds and runs, but then strange things start happening. I had enough facepalms from this that I started to recognize when this was happening and I'd catch it a lot faster. The first debugging session took me almost 2 hours of stepping through the debugger before I found it.

We've all been there.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use