Jump to content
Posted Sun May 31, 2009 2:13 AM
Posted Sun May 31, 2009 2:39 AM
The nature of the problem is actually not hard to understand, and only occurs under very specific conditions: a taken reverse branch located at $FFxx jumps to $FEF8-9. On the 4th cycle, a read of $FFF8-9 will occur. This happens because the 6507 must perform a read or write every cycle, and it needs an extra cycle to fix the address, so it does dummy reads in these cases.
Have any of you every encountered a fatal bug with bankswitching? I sure as heck just did. This one really had me stumped and I spent a few hours on it, so you might want to learn how I Eff'd it up so badly and avoid doing it yourself.
Posted Sun May 31, 2009 3:37 AM
Posted Sun May 31, 2009 5:41 AM
I have nothing to add The dummy reads are seen by the cartridge and so it is forced to trigger the bankswitch. I think it is good that Stella obviously emulates this in a quite realistic way already.
Armin if you are reading this maybe you can pipe in.
Posted Sun May 31, 2009 8:26 AM
Posted Sun May 31, 2009 11:43 PM
This just shows that z26 doesn't always do a cycle-accurate emulation. There will be a point very soon when Stella is in virtually all ways more accurate than z26, and I think the new TIA code will make this happen.
This problem really stumped me because Z26 played the rom perfectly. I always thought between Stella and Z26, that Z26 was more accurate. I know that Stella will soon surpass Z26, but this problem was perplexing to me.
I kept convincing myself that it must be an emulator problem, and Z26 was working right while Stella wasn't. When the rom didn't work on the Krok I kept convincing myself that there was something fundamental about bankswitching I didn't understand...
If it hadn't been for Stella's debugger I would never have discovered what was happening. While I spent a few hours coming to terms with it, it might have taken a few days for the programmers of old. We are lucky to have the tools that we do. However, can Batari Basic can assemble a rom with this error, or is the rom laid out in a way that it will never happen? This type of error would be much harder to figure out if more banks were in play, like an F6 or F4 bankswitch. There you might move the code up or down a few lines and it'd still execute a BS on you. All you would know is that it crashed.
I sort of came to the same conclusion of what was going wrong, at least I knew what it had to do with. I only distantly remember the dummy reads. I looked in the Stella's programmer guide, and glanced at Machine Language for Beginners, but couldn't find the section where the cycles of a branch was explained, and what happened to the PC. I did read about it a long time ago though.
I was wondering if you could riddle me this and explain what it does on each cycle, or point me in the right direction. We studied a PIC18F452 in school and learned how it fetched, decoded, and fetched the next instruction while it was excuting the previous one. What does it do on the 6507?
Relative addressing (BCC, BCS, BNE, BEQ, BPL, BMI, BVC, BVS) # address R/W description --- --------- --- --------------------------------------------- 1 PC R fetch opcode, increment PC 2 PC R fetch operand, increment PC 3 PC R Fetch opcode of next instruction, If branch is taken, add operand to PCL. Otherwise increment PC. 4+ PC* R Fetch opcode of next instruction. Fix PCH. If it did not change, increment PC. 5! PC R Fetch opcode of next instruction, increment PC. Notes: The opcode fetch of the next instruction is included to this diagram for illustration purposes. When determining real execution times, remember to subtract the last cycle. * The high byte of Program Counter (PCH) may be invalid at this time, i.e. it may be smaller or bigger by $100. + If branch is taken, this cycle will be executed. ! If branch occurs to different page, this cycle will be executed.The above may be a little odd because there is no cycle 5 in a branch, and no cycle 4 if the page didn't wrap - that is actually the first cycle of the next instruction.
Posted Mon Aug 17, 2009 9:28 PM
Posted Tue Aug 18, 2009 10:59 PM
0 members, 0 guests, 0 anonymous users