I have been a bit sloppy with the R register, which has led to some strange emulation problems in games like Green Beret where the R register is frequently used. The R register should be incremented once for every instruction, with some additional rules and conditions. For example, prefixed instructions like CB-02 (RLC D) causes R to be incremented twice. Furthermore, only bit 0-6 are incremented, while bit 7 remains untouched. For a complete description of these rules and conditions, see http://www.z80.info.
One of my mistakes was that I treated bit 7 as completely static - I forgot that there are instructions to set R to any value 0-255. Now the code for incrementing R looks like this: R = (R & 128) | (R + 1) & 127; The R-register can be used either as a counter, like in Green Beret where it controls the timing of some sound effects, or as a way to get some sort of random number triggered by user input at a random certain point in time.
0 Comments
|
Archives
November 2020
Categories
All
|