Rrca

edited October 2007 in Development
I'm having trouble finding an exact explanation to how all the z80 instructions work, but I get by ok on most of them. I'm sure I've been given links before, but can't seem to find them now.

Anyway, the one I'm stuck with right now is RRCA

Exactly what does it do? I have guessed that is rotates the bits in the accumulator to the right (so, er, bit 0 becomes bit 1 and bit 7 becomes bit 0, is that right?), but what does circular mean, and how does this example only affect the carry flag as described in one of the articles on WOS?

In case you were wondering, I'm trying to decipher the routine that draws the 'airflow' map in Bubble Bobble. This map shows which direction a bubble has to move in when it's over each character square in the level map. I'm translating it to Delphi for the forthcoming v3.0 of my editor.

The routine starts at $7c43 in the game code, and does a lot of self-modifying and other things, whilst the map is drawn to $f800 and I think it's probably only 768 bytes long, although it could be more than that. The map is pre-loaded with data to show the layout of the platforms on the current level. If you fancy a challenge, give it a look, I could do with working out an equivalent program in ZX Basic which could help with the translation to Delphi :)
Post edited by mulder on

Comments

  • edited October 2007
    mulder wrote: »
    Exactly what does it do? I have guessed that is rotates the bits in the accumulator to the right (so, er, bit 0 becomes bit 1 and bit 7 becomes bit 0, is that right?),

    Nope - other way. (The bit that was previously in bit 1 is placed in bit 0, and the bit that was previously in bit 0 is placed in bit 7.)
    but what does circular mean, and how does this example only affect the carry flag as described in one of the articles on WOS?

    It's called circular because the bit that drops off one end immediately reappears on the other, whereas with the other rotate instructions (RRA and friends), the carry flag takes part in the rotation too: bit 0 moves to the carry flag, and the previous value of the carry flag moves to bit 7. So, if you do RRCA 8 times you get back where you started, whereas with RRA you'd have to do it 9 times.

    In fact, with RRCA, the bit that drops of the end is placed in the carry flag *as well* as being placed in bit 7. The previous value of the carry flag doesn't enter into it at all. The Toni Baker book (Mastering Machine Code On Your ZX Spectrum) refers to the mnemonic as "Rotate Right without Carry", which is a helpful way to think of it (if the back-to-front-ness of the 'without' doesn't piss you off, that is).

    Talking of which, I believe that a scan of that entire book is available here, and it has a chapter in the middle devoted to explaining each instruction individually - could be worth a look.
  • edited October 2007
    Thanks Gasman, good explanation, I'll grab the book asap :)
  • edited October 2007
    Also try and find the Z80 Reference Guide by Alan Tully. That explains all the opcodes and give examples as well.
    I wanna tell you a story 'bout a woman I know...
  • edited October 2007
Sign In or Register to comment.