King Harold wrote:ok i put it in, it works, i also made a not-aligned version (clipped aswell) but guess what, it doesnt work! i didnt expect it to ofcourse, but it doesnt even draw anything, quite depressing.. srl + rr is the way to shift sprites over a byte border isnt it?
It's probably not the only way but almost certainly the easiest!
With the shift instructions, you need to keep in mind how they affect the carry flag.
Within a byte, the bits are numbered 7, 6, 5, 4, 3, 2, 1, 0. Bit 7 is the highest bit (128) and zero is the lowest (1). From a graphics point of view, bit 7 is the leftmost pixel and bit 0 is the rightmost.
With all the different types of shift, the bit which is being shifted out becomes the new carry flag. So with SRL, the carry flag will have the same value as the low bit of the number you just shifted (bit 0). SLA has the opposite effect - bit 7 will become the carry.
The rotate instructions (RR, RL) do the same thing as a shift, but the "new" bit will take the value of the carry flag.
I hope this isn't too confusing. I'm not good at explaining things! I will do a little diagram of what happens:
Lets say you have two bytes you want to shift. They both contain 01010101 (in binary, of course!).
First, you shift the first byte using SRL:
Code: Select all
BEFORE:
Carry flag - unkown
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
+---+---+---+---+---+---+---+---+
AFTER:
Carry flag: 1
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
+---+---+---+---+---+---+---+---+
A zero was shifted into bit 7, since SRL will always shift a zero, and the 1 that was in bit 0 has been put into the carry flag.
Now, you RR into the next byte:
Code: Select all
BEFORE:
Carry flag - 1
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
+---+---+---+---+---+---+---+---+
AFTER:
Carry flag: 1
7 6 5 4 3 2 1 0
+---+---+---+---+---+---+---+---+
| 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
+---+---+---+---+---+---+---+---+
The carry flag was shifted into bit 7 and the 1 in bit 0 was, once again, shifted into the carry flag. So if you are shifting across multiple bytes, you would only SRL on the first, and RR on the rest. Just make sure you are not executing any instruction which will affect the carry flag in between the shifts!
I hope this helps, but knowing my crappy explainations, it won't!