- Shift a quarter of the screen
- 14 Nov 2011 07:02:33 pm
- Last edited by Deep Toaster on 14 Nov 2011 07:18:18 pm; edited 1 time in total
I wrote a quick routine to shift a quarter of PlotSScreen down, but it doesn't work and ends up putting garbage on the last row (and corrupting things below that, I'm assuming). I've run it through my head a few times, and I can't figure out where I went wrong, so here's my code:
Z80 Assembly wrote:
ShiftDown:
xor A
ld B, A
ld A, 31
DownStart:
ld C, 6
add HL, BC
ex DE, HL
ld HL, -12
add HL, DE
lddr
dec A
jr nz, UpStart
ret
I'm even more confused because it's almost exactly the reverse of another routine that shifts a quarter of the screen up, which works:xor A
ld B, A
ld A, 31
DownStart:
ld C, 6
add HL, BC
ex DE, HL
ld HL, -12
add HL, DE
lddr
dec A
jr nz, UpStart
ret
Z80 Assembly wrote:
ShiftUp:
xor A
ld B, A
ld A, 31
UpStart:
ld C, 6
sbc HL, BC
ex DE, HL
ld HL, 12
add HL, DE
ldir
dec A
jr nz, UpStart
ret
Does anyone see where I went wrong in the first block? The input for ShiftUp is PlotSScreen + 6 to shift the first quarter of the screen, and the input for ShiftDown to shift the same block is supposed to be PlotSScreen + (768 / 2) - 1 - 12. xor A
ld B, A
ld A, 31
UpStart:
ld C, 6
sbc HL, BC
ex DE, HL
ld HL, 12
add HL, DE
ldir
dec A
jr nz, UpStart
ret