This piece of code:
Code: Select all
ScreenSize equ &4000 org &8200 ld a, %00001111 FillAgain: ld hl, &C000 ld de, &C000+1 ld bc, ScreenSize-1 ld (hl), a ldir dec a cp 255 jp nz, FillAgain ret
1) In this specific example, I don't understand well how "CP" works and why we need it.
According to what I read, JP C, ## jumps to ## if the condition of the last operation is met.
In this case, if the result of the last operation (DEC A) is NOT ZERO, then jump.
Why we need to compare A to 255?
Also, when A reaches 0, why it goes back to 255 in the instruction "CP 255"?
2) I don't quite understand how screen memory works. When I write bits to screen memory (i.e. &C000 on wards), the screen shows vertical parallel stripes, instead of solid horizontal sprites. For example, if I want to fill the screen with solid cyan colour, if I start writing byte by byte to screen mem, shouldn't it print pixel by pixel from left to right first, then moving to next "line", just under the previous one, creating a solid colour?
Anyway, if this last question is answered in a later lesson (right now I'm in lesson 3), I don't need an explanation now anyway.