Btw, the code works just fine (except it doesn't clip the bottom, but that's easy enough to add in). I just want to see how badly offtrack I am!
Thanks!
Code: Select all
;##############SPRITE CLIPPING ROUTINE!
;input: spritex = x position on screen, spritey = y position on screen, hl = sprite data pointer
clip: ld ix,gbuf ;graphbuffer!
ld d,0
ld c,8 ;how many bytes to draw to the gbuf
ld a,(spritey)
cp 64
jr c,shiftydown ;0<=y<64 i can't think of a better way! correct y position
cliptop:
cpl ;invert bits
and $07 ;3 LSB
inc a ;since $FF is -1, cpl will give us $00. we need to increase a by 1
ld b,a
dec c ;decrease # bytes to display and move pointer one byte ahead
inc hl
djnz $-2
returnfromshift:
ld a,(spritex)
cp 96
jr nc,clipleft ;if x coordinate is negative, we don't need to change the gbuf location
ld e,a ;x coords/8, save x coord
srl e
srl e
srl e
add ix,de ;location on gbuf to draw
ld e,12 ;de=12, add to ix to move gbuf down one set of pixels
cp 89 \ jr c,skipclip ;if x position is between 0 and 88, we don't need to clip
jr clipright ;if x position is between 89 and 95, we need to clip on the right
clipleft: cpl
and $07
inc a
ld b,a
ld e,12
repeatclip_l:
push bc
ld a,(hl)
sla a
djnz $-2
ld (ix),a
add ix,de
pop bc
inc hl
dec c
jr nz,repeatclip_l
ret
shiftydown:
ld e,a
ld b,12
add ix,de
djnz $-2
jr returnfromshift
skipclip: and $07 \ jr z,skipshift ;sprite is aligned
xor $07
inc a
ld b,a
repeatnoclip:
push bc
ld c,0
ld a,(hl)
rla
rl c
djnz $-3
ld (ix),c
inc ix
ld (ix),a
add ix,de
dec ix
pop bc
inc hl
dec c
jr nz,repeatnoclip
ret
skipshift:
ld a,(hl)
ld (ix),a
add ix,de
inc hl
dec c
jr nz,skipshift
ret
clipright: and $07
ld b,a
repeatclip_r:
push bc
ld a,(hl)
and a
rr a
djnz $-3
ld (ix),a
add ix,de
pop bc
inc hl
dec c
jr nz,repeatclip_r
ret
EDIT: Oh, and eventually, it will be an XOR sprite routine (I'm just too lazy to add the two or three lines right now).