I personally would do something like the following:
Code:
collision_row_of_5:
;Inputs:
; BC = (x,y)
; x,y points to the left edge of the 5-pixel row to check
;Outputs:
; NC if out of bounds or collision
; C if in bounds and no collision
; NZ if collision
; Z if no collision
; Also assuming the object is not out of bounds.
call GetPixelLoc
ret nc ;means out of bounds here
; Now HL points to the byte in plotSScren for where to check
; Now we have A as a mask with only one bit set.
; Something like %00100000
; What we need is to AND a mask that is 5 pixels wide
; So we need %00111110
; We could do a bunch of complicated maneuvers to adjust for byte boundaries
; I'll keep it simple and not necessarily optimized
ld b,a
ld c,0
or b ;reset the c flag
rra \ rr c \ or b
rra \ rr c \ or b
rra \ rr c \ or b
rra \ rr c \ or b
rra \ rr c \ or b
;now 5 'set' bits span AC
;check if any bits are set (pixels are on) that match the mask:
and (hl) ;resets C flag, too
ret nz ;means pixels were set, -> collision
ld a,c
or a
scf ;sets carry flag
ret z ;means nothing crossed the byte boundary, so done checking, no collisions
inc hl
and (hl)
ret nz
scf
ret
GetPixelLoc:
;Input:
; b is X
; c is y
;Output:
; HL points to byte
; A is the mask
; nc if not computed, c if computed
ld a,c
cp 64 \ ret nc
ld a,b
cp 96 \ ret nc
ld l,c
ld h,0
ld b,h
add hl,hl
add hl,bc
add hl,hl
add hl,hl
ld b,a
rrca \ rrca \ rrca
and 0Fh
add a,plotSScreen&255
ld c,a
ld a,b
ld b,plotSScreen/256
add hl,bc
and 7
ld b,a
inc b
ld a,1
rrca
djnz $-1
scf
ret
(untested)
So what you would do is put (x,y) into BC, where X,Y points to the row of pixels under the sprite. It then scans the 5 pixels (going right) and returns flags if there was a boundary or not. I hope it works x.x I haven't coded in what seems like months.