Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DrawClippedSprite: ;D=X E=Y A=spriteID. Allows negative numbers to an extent.
- ;screen dimensions are 64x64 pixels
- jp $
- rrca
- rrca ;%11000000 get
- ld c,a
- ld a,d
- and %00000111
- ld b,a ;save for getting mask address
- add a,a
- add a,a
- add a,a ;x8 %00111000
- add a,c ;merge to get correct sprite position
- ld c,a ;position saved
- ld a,b
- add a,8 ;getting spritemask position
- ld h,$40
- ld L,a
- ld b,(hl) ;B=spritemask
- Getbfraddr:
- ld a,e
- add a,a
- ld l,a
- sbc a,a
- ld h,a
- add hl,hl
- add hl,hl
- ld a,d
- ld d,e
- add a,a
- add a,a
- add a,a ;*8
- ld e,a
- ld a,d ; used for alignment later on needs to be preserved here
- ld d,$80
- add hl,de ;leaves HL as the position on the buffer
- Getspraddr:
- ld e,b ;put mask into e
- ld b,$87
- push bc
- pop ix ;put sprite into ix
- ;we have bc free
- ld b,8
- Draw:
- and 7
- jp z,_aligned
- ld a,e
- cpl
- ld c,a
- _Unaligned:
- bit 1,h
- jp nz,_skipd
- ld a,e
- cpl
- ld c,a
- ld a,(ix) ;load a with ix
- and c
- or (hl) ;or with screen
- ld (hl),a ;draw to screen
- inc hl ;inc to next byte for alignment
- inc ix
- ld a,(ix) ;load a with ix
- and e ;or with mask
- or (hl) ;or with screen
- ld (hl),a ;draw to screen
- inc ix
- ld de,7 ;move to next row
- add hl,de
- _skipd:
- djnz _Unaligned
- ld ix,$8eeC
- ret ;done
- _aligned:
- bit 1,h
- jp nz,__skipd
- ld a,(ix) ;load a with ix
- or (hl) ;or with screen
- ld (hl),a ;draw to screen
- inc ix
- ld de,8 ;move to next row
- add hl,de
- __skipd:
- djnz _aligned
- ld ix,$8eeC
- ret ;done
Advertisement
Add Comment
Please, Sign In to add comment