123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- #define spritetmp 8000h
- sprite_width = spritetmp+0
- sprite_x = spritetmp+1
- sprite_mask0 = spritetmp+2
- sprite_mask1 = spritetmp+3
- sprite_method = spritetmp+4
- rshiftHA_7:
- rr h \ rra
- rr h \ rra
- rr h \ rra
- rr h \ rra
- rr h \ rra
- rr h \ rra
- rr h \ rra
- ex de,hl
- ld e,a
- ret
- spritemask:
- .db $00,$80,$C0,$E0,$F0,$F8,$FC,$FE
- call_ix:
- jp (ix)
- sprite:
- ;Inputs:
- ; A is the method:
- ; 0=Overwrite
- ; 1=AND
- ; 2=XOR
- ; 3=OR
- ; 5=Erase
- ; B is the X-coordinate
- ; C is the Y-Coordinate
- ; DE points to the sprite
- ; H is the height
- ; L is the width
- ; (gbuf_temp) is the buffer to which to draw
- ld (sprite_method),a
- ;First check if the sprite is on-screen in the horizontal direction
- ld a,c
- cp 64
- jr c,+_
- add a,h
- ret nc
- ld h,a
- push hl
- xor a
- ld h,a
- sub c
- ex de,hl
- add hl,de
- dec a
- jr nz,$-2
- ex de,hl
- pop hl
- xor a
- ld c,a
- _:
- ;Next check h+c<=64
- ld a,64
- sub c
- cp h
- jr nc,+_
- ld h,a
- _:
- ;Make sure the height is not now 0
- ld a,h
- or a
- ret z
- ;Save the width and height of the sprite
- push hl ;height,width
- ld h,b
- ld (sprite_width),hl ;x,width
- push de ;sprite pointer
- ;Set up a pointer to the routine for shifting the routine for shifting the sprite data
- ld ixh,rshiftHA_7>>8
- ld a,h
- cpl
- and 7
- ld l,a
- add a,a
- add a,l
- add a,rshiftHA_7&255
- ld ixl,a
- #if (rshiftHA_7&255)>234
- jr nc,$+4
- inc ixh
- #endif
- ld a,b
- and 7
- ld de,spritemask
- add a,e
- ld e,a
- #if spritemask&255>248
- jr nc,$+3
- inc d
- #endif
- ld a,(de)
- ld (sprite_mask0),a
- cpl
- ld (sprite_mask1),a
- ;
- ;
- ld a,c
- add a,a
- sbc a,a
- ld h,a
- ld a,b
- ld b,h
- ld l,c
- add hl,hl
- add hl,bc
- add hl,hl
- add hl,hl
- ld c,a
- add a,a
- sbc a,a
- ld b,a
- ld a,c
- sra c
- sra c
- sra c
- add hl,bc
- ld bc,(gbuf_temp)
- add hl,bc
- pop de
- pop bc
- ;B is height
- ;C is width
- ex de,hl
- _:
- push bc ;height,width
- push de ;gbuf ptr
- push hl ;sprite data pointer
- ld a,(sprite_x)
- ld c,a
- add a,8
- ld (sprite_x),a
- call spritemethod
- pop hl
- inc hl
- pop de
- inc de
- pop bc
- dec c
- jr nz,-_
- ret
- spritemethod:
- ld a,(sprite_method)
- dec a
- jp z,spriteloop_AND
- dec a
- jp z,spriteloop_XOR
- dec a
- jp z,spriteloop_OR
- sub 2
- jp z,spriteloop_Erase
- spriteloop_Overwrite:
- push bc
- push hl
- ld h,(hl)
- xor a
- call call_ix
- ld a,c
- cp 96
- jr nc,+_
- ld a,(sprite_mask0)
- and (hl)
- or d
- ld (hl),a
- ld a,c
- _:
- inc hl
- add a,8
- cp 96
- jr nc,+_
- ld a,(sprite_mask1)
- and (hl)
- or e
- ld (hl),a
- _:
- ld bc,11
- add hl,bc
- ex de,hl
- pop hl
- ld a,(sprite_width)
- ld c,a
- add hl,bc
- pop bc
- djnz spriteloop_Overwrite
- ret
- spriteloop_OR:
- push bc
- push hl
- ld h,(hl)
- xor a
- call call_ix
- ld a,c
- cp 96
- jr nc,+_
- ld a,(hl)
- or d
- ld (hl),a
- ld a,c
- _:
- inc hl
- add a,8
- cp 96
- jr nc,+_
- ld a,(sprite_mask1)
- ld a,(hl)
- or e
- ld (hl),a
- _:
- ld bc,11
- add hl,bc
- ex de,hl
- pop hl
- ld a,(sprite_width)
- ld c,a
- add hl,bc
- pop bc
- djnz spriteloop_OR
- ret
- spriteloop_XOR:
- push bc
- push hl
- ld h,(hl)
- xor a
- call call_ix
- ld a,c
- cp 96
- jr nc,+_
- ld a,(hl)
- xor d
- ld (hl),a
- ld a,c
- _:
- inc hl
- add a,8
- cp 96
- jr nc,+_
- ld a,(sprite_mask1)
- ld a,(hl)
- xor e
- ld (hl),a
- _:
- ld bc,11
- add hl,bc
- ex de,hl
- pop hl
- ld a,(sprite_width)
- ld c,a
- add hl,bc
- pop bc
- djnz spriteloop_XOR
- ret
- spriteloop_AND:
- push bc
- push hl
- ld h,(hl)
- scf \ sbc a,a
- call call_ix
- ld a,c
- cp 96
- jr nc,+_
- ld a,(hl)
- and d
- ld (hl),a
- ld a,c
- _:
- inc hl
- add a,8
- cp 96
- jr nc,+_
- ld a,(sprite_mask1)
- ld a,(hl)
- and e
- ld (hl),a
- _:
- ld bc,11
- add hl,bc
- ex de,hl
- pop hl
- ld a,(sprite_width)
- ld c,a
- add hl,bc
- pop bc
- djnz spriteloop_AND
- ret
- spriteloop_Erase:
- push bc
- push hl
- ld h,(hl)
- xor a
- call call_ix
- ld a,c
- cp 96
- jr nc,+_
- ld a,d
- cpl
- and (hl)
- ld (hl),a
- ld a,c
- _:
- inc hl
- add a,8
- cp 96
- jr nc,+_
- ld a,e
- cpl
- and (hl)
- ld (hl),a
- _:
- ld bc,11
- add hl,bc
- ex de,hl
- pop hl
- ld a,(sprite_width)
- ld c,a
- add hl,bc
- pop bc
- djnz spriteloop_Erase
- ret
|