home *** CD-ROM | disk | FTP | other *** search
- ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
- ;│█████ Z80 ██████│ Sprite83 │█████████████████████│ movax │████████████│
- ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
-
- ; Sprite draw routine v1.0 and sprite clear routine v1.0
- ; Coded by Hannes Edfeldt in 1997
-
- ; With these two routines you can draw and clear non-aligned sprites. See
- ; sprdemo.z80 for an example of how to use these routines.
-
- ; Feel free to use these routines in your own productions as long as you give
- ; me some credit.
-
- ; This file should of course be viewed in a DOS texteditor ;)
-
- ; Hannes Edfeldt -+- movax@algonet.se -+- http://www.algonet.se/~movax
-
-
- ;▄████████████▀ DRWSPR ▀███████████████████████████████████████████████████████
- ;┌────────────────────────────────────────────────────────────────────────────┐
- ;│ Draw 8x8 sprite ■ a=x, e=y, hl=sprite address │
- ;└────────────────────────────────────────────────────────────────────────────┘
- DRWSPR:
-
- push hl ; Save sprite address
-
- ;████ Calculate the address in graphbuf ████
-
- ld hl,0 ; Do y*12
- ld d,0
- add hl,de
- add hl,de
- add hl,de
- add hl,hl
- add hl,hl
-
- ld d,0 ; Do x/8
- ld e,a
- srl e
- srl e
- srl e
- add hl,de
-
- ld de,8e29h
- add hl,de ; Add address to graphbuf
-
- ld b,00000111b ; Get the remainder of x/8
- and b
- cp 0 ; Is this sprite aligned to 8*n,y?
- jp z,ALIGN
-
-
- ;████ Non aligned sprite blit starts here ████
-
- pop ix ; ix->sprite
- ld d,a ; d=how many bits to shift each line
-
- ld e,8 ; Line loop
- LILOP: ld b,(ix+0) ; Get sprite data
-
- ld c,0 ; Shift loop
- push de
- SHLOP: srl b
- rr c
- dec d
- jp nz,SHLOP
- pop de
-
- ld a,b ; Write line to graphbuf
- or (hl)
- ld (hl),a
- inc hl
- ld a,c
- or (hl)
- ld (hl),a
-
- ld bc,11 ; Calculate next line address
- add hl,bc
- inc ix ; Inc spritepointer
-
- dec e
- jp nz,LILOP ; Next line
-
- jp DONE1
-
-
- ;████ Aligned sprite blit starts here ████
-
- ALIGN: ; Blit an aligned sprite to graphbuf
- pop de ; de->sprite
- ld b,8
- ALOP1: ld a,(de)
- or (hl) ; xor=erase/blit
- ld (hl),a
- inc de
- push bc
- ld bc,12
- add hl,bc
- pop bc
- djnz ALOP1
-
- DONE1:
- ret
- ;▄████████████▄ DRWSPR ▄███████████████████████████████████████████████████████
-
-
- ;▄████████████▀ CLRSPR ▀███████████████████████████████████████████████████████
- ;┌────────────────────────────────────────────────────────────────────────────┐
- ;│ Clear 8x8 sprite ■ a=x, e=y, hl=sprite address │
- ;└────────────────────────────────────────────────────────────────────────────┘
- CLRSPR:
- push hl ; Save sprite address
-
- ;████ Calculate the address in graphbuf ████
-
- ld hl,0 ; Do y*12
- ld d,0
- add hl,de
- add hl,de
- add hl,de
- add hl,hl
- add hl,hl
-
- ld d,0 ; Do x/8
- ld e,a
- srl e
- srl e
- srl e
- add hl,de
-
- ld de,8e29h
- add hl,de ; Add address to graphbuf
-
- ld b,00000111b ; Get the remainder of x/8
- and b
- cp 0 ; Is this sprite aligned to 8*n,y?
- jp z,ALIGN2
-
-
- ;████ Non aligned sprite erase starts here ████
-
- pop ix ; ix->sprite
- ld d,a ; d=how many bits to shift each line
-
- ld e,8 ; Line loop
- LILOP2: ld b,(ix+0) ; Get sprite data
-
- ld c,0 ; Shift loop
- push de
- SHLOP2: srl b
- rr c
- dec d
- jp nz,SHLOP2
- pop de
-
- ld a,b ; Write line to graphbuf
- cpl
- and (hl)
- ld (hl),a
- inc hl
- ld a,c
- cpl
- and (hl)
- ld (hl),a
-
- ld bc,11 ; Calculate next line address
- add hl,bc
- inc ix ; Inc spritepointer
-
- dec e
- jp nz,LILOP2 ; Next line
-
- jp DONE5
-
-
- ;████ Aligned sprite erase starts here ████
-
- ALIGN2: ; Erase an aligned sprite in graphbuf
- pop de ; de->sprite
- ld b,8
- ALOP2: ld a,(de)
- cpl
- and (hl)
- ld (hl),a
- inc de
- push bc
- ld bc,12
- add hl,bc
- pop bc
- djnz ALOP2
-
- DONE5:
- ret
- ;▄████████████▄ CLRSPR ▄███████████████████████████████████████████████████████
-
- ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
- ;│█████ Z80 ██████│ Sprite83 │█████████████████████│ movax │████████████│
- ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
-