home *** CD-ROM | disk | FTP | other *** search
- ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
- ;│█████ Z80 ██████│ Sprite demo │█████████████████████│ movax │████████████│
- ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
-
- ; Sprite example 1 v1.0
- ; Coded by Hannes Edfeldt in 1997
-
- ; This little program demonstrates the basics of DRWSPR and CLRSPR.
-
- ; 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
-
- .org 9327h
-
- ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
- ;│█████ Z80 ██████│ CODE │█████████████████████│ movax │████████████│
- ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
-
- START:
- call RINDOFF ; Turn off runindicator
- call BUFCLR ; Clear the graphbuf
- call BUFCOPY ; Copy the graphbuf to the LCD
- call WAITKEY ; Wait for a key
-
-
- ;████ Draw the sprite ████
-
- ld a,44 ; Load the x-coordinate in a
- ld e,28 ; Load the y-coordinate in e
- ld hl,ALIEN ; Load the address to the sprite in hl
- call DRWSPR ; Draw the sprite in the graphbuf
- call BUFCOPY ; Copy the graphbuf to the LCD
-
- call WAITKEY ; Wait for a key
-
-
- ;████ Clear the sprite ████
-
- ld a,44 ; Load the x-coordinate in a
- ld e,28 ; Load the y-coordinate in e
- ld hl,ALIEN ; Load the address to the sprite in hl
- call CLRSPR ; Clear the sprite in the graphbuf
- call BUFCOPY ; Copy the graphbuf to the LCD
-
- call WAITKEY ; Wait for a key
-
-
- ;████ Exit the program ████
-
- call CLRTSHD ; Clear textshadow
- call GOHOME ; Leave graphscreen and go to homescreen
- call BUFCLR ; Clear the graphbuf
- call READKEY ; Catch the clear press
- call HOMEUP ; Place cursor at home
- ret ; Exit program
-
- ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
- ;│█████ Z80 ██████│ PROCEDURES │█████████████████████│ 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 ██████│ EQUALS │█████████████████████│ movax │████████████│
- ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
-
- WAITKEY .equ 4CFEh ; Wait for a key and read
- BUFCLR .equ 515Bh ; Clear the graph backup
- BUFCOPY .equ 5164h ; Copy the graph backup to the screen
- RINDOFF .equ 4795h ; Turn off runindicator
- PRINTHL .equ 4709h ; Print HL in dec. on the screen
- OP2TOP1 .equ 41C2h ; Move OP2 to OP1
- CONVOP1 .equ 4EFCh ; Convert fp value in OP1 to a 2 byte hex
- READKEY .equ 4A18h ; Read key and place it in OP2 as a fp value
- GOHOME .equ 47A1h ; Go to home screen (finish gfx program)
- CLRTSHD .equ 4765h ; Clear text shadow
- HOMEUP .equ 4775h ; Place cursor at home
- STRING .equ 470Dh ; Print 0 terminated string to screen (hl->string)
-
- ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
- ;│█████ Z80 ██████│ DATA │█████████████████████│ movax │████████████│
- ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
-
- ALIEN .db 00011000b
- .db 01111110b
- .db 11111111b
- .db 10111101b
- .db 10011001b
- .db 11111111b
- .db 01111110b
- .db 00111100b
-
- .end
- ;┌────────────────┬────────────────┬─────────────────────┬───────┬────────────┐
- ;│█████ Z80 ██████│ Sprite demo │█████████████████████│ movax │████████████│
- ;└────────────────┴────────────────┴─────────────────────┴───────┴────────────┘
-