;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄ¿ ;³ÛÛÛÛÛ Z80 ÛÛÛÛÛÛ³ Spr xor demo ³ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ³ movax ³ÛÛÛÛÛÛÛÛÛÛÛÛ³ ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÙ ; Sprite xor example v1.0 ; Coded by Hannes Edfeldt in 1997 ; This little program demonstrates how to use the routine SPRXOR and shows ; what happens when you use xor to draw and erase sprites. ; Use the graphkeys to alternate between five diffrent speeds, press clear to ; quit. ; Feel free to use this routine 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 call BUFCLR ld b,88 ; -- Initiate sprite directions ld ix,SPRDIR DIRLOP: ld a,r srl a and 00000001b cp 1 jp nz,SKP01 ld (ix+0),a jp SKP02 SKP01: ld a,-1 ld (ix+0),a SKP02: inc ix djnz DIRLOP MAIN: ld b,44 ; -- Draw sprites ld ix,SPRCORD ld hl,ALIEN ; Get address to the alien sprite SPRLOP: ld a,(ix+0) ; Get x-coordinate ld e,(ix+1) ; Get y-coordinate push bc push hl push ix call SPRXOR ; Draw the sprite pop ix pop hl pop bc inc ix ; Make ix point to next sprite's coordinates inc ix djnz SPRLOP ld a,(SPEED) ld b,a WAITL1: push bc call BUFCOPY ; Copy graphbuf to LCD pop bc djnz WAITL1 ld b,44 ; -- Clear sprites ld ix,SPRCORD ld hl,ALIEN ; Get address to the alien sprite CLRLOP: ld a,(ix+0) ; Get x-coordinate ld e,(ix+1) ; Get y-coordinate push bc push hl push ix call SPRXOR ; Clear the sprite pop ix pop hl pop bc inc ix ; Make ix point to next sprite's coordinates inc ix djnz CLRLOP ld b,44 ; -- Update sprite directions ld ix,SPRCORD ld hl,SPRDIR CHGDIR: ld a,(ix+0) cp 0 ; Reached left edge? jp nz,SKP03 ld a,1 ld (hl),a SKP03: cp 88 ; Reached right edge? jp nz,SKP04 ld a,-1 ld (hl),a SKP04: inc hl ld a,(ix+1) cp 0 ; Reached top? jp nz,SKP05 ld a,1 ld (hl),a SKP05: cp 56 ; Reached bottom? jp nz,SKP06 ld a,-1 ld (hl),a SKP06: inc ix inc ix inc hl djnz CHGDIR ld b,88 ; -- Sprite movement ld ix,SPRCORD ld hl,SPRDIR SPRMOV: ld a,(ix+0) add a,(hl) ld (ix+0),a inc ix inc hl djnz SPRMOV call READKEY ; Look for speedchange call OP2TOP1 call CONVOP1 sub 10 cp 6 jp nc,SKP08 ld (KEY),a SKP08: ld a,(KEY) ld (SPEED),a ld a,0ffh ; Reset the keyport (kinda) out (1),a ld a,0fdh ; Enable the row with CLEAR out (1),a in a,(1) cp 191 ; Check for CLEAR jp nz,MAIN ; Exit if clear is pressed 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 ³ÛÛÛÛÛÛÛÛÛÛÛÛ³ ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÙ ;ÜÛÛÛÛÛÛÛÛÛÛÛÛß SPRXOR ßÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ;³ Xor 8x8 sprite þ a=x, e=y, hl=sprite address ³ ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ SPRXOR: 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 xor (hl) ld (hl),a inc hl ld a,c xor (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) xor (hl) ld (hl),a inc de push bc ld bc,12 add hl,bc pop bc djnz ALOP1 DONE1: ret ;ÜÛÛÛÛÛÛÛÛÛÛÛÛÜ SPRXOR ÜÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ ;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄ¿ ;³ÛÛÛÛÛ 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 SPRCORD .db 40,0,48,0 .db 24,8,32,8,40,8,48,8,56,8,64,8 .db 16,16,24,16,32,16,40,16,48,16,56,16,64,16,72,16 .db 16,24,32,24,40,24,48,24,56,24,72,24 .db 16,32,40,32,48,32,72,32 .db 16,40,24,40,32,40,40,40,48,40,56,40,64,40,72,40 .db 24,48,32,48,40,48,48,48,56,48,64,48 .db 32,56,40,56,48,56,56,56 SPEED .db 64 KEY .db 1 SPRDIR .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .end ;ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄ¿ ;³ÛÛÛÛÛ Z80 ÛÛÛÛÛÛ³ Spr xor demo ³ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ³ movax ³ÛÛÛÛÛÛÛÛÛÛÛÛ³ ;ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÙ