;very fast sprite routine by Aaron Curtis ;(1213 clock cycles, though less if you in-line ;it or unroll the loops or something) ;usage: ; 1. Define "spritedata" in your program; ; it has to be aligned to a $1000-byte ; boundary, ($9000, $a000 are good). ; * this will take up 4k of memory * ; 2. Call init_ubersprite at the start of ; your program. This fills up spritedata ; with the necessary info. ; 3. Call ubersprite to draw a sprite, ; inputs are c=x coord, b=y coord, ; ix->bitmap data. ;This version only does 8x8 unmasked, unclipped, ;black and white sprites. Feel free to modify ;it to suit your needs. ;******************************************** ;initialization for ubersprite ;be sure to define "spritedata" somewhere ;******************************************** init_ubersprite: ;no inputs ;destroys hl,bc,d,af ld hl,spritedata ld d,l gengfx: ld c,0 ld b,c gfxloop: push bc ld b,d ld a,d or a jr z,notshifted xor a shiftloop: srl c rra djnz shiftloop notshifted: ld (hl),c inc h ld (hl),a dec h inc hl pop bc inc c djnz gfxloop inc h inc d ld a,d cp 8 jr nz,gengfx ret ;******************** ;main sprite routine ;******************** ubersprite: ;inputs: ; c=x coordinate ; b=y coordinate ; ix->graphic ;destroys ix,hl,de,bc,af call findpixel ;make this inline if you want it to go /really/ fast :) add a,a add a,spritedata/256 ;translate x-offset to address in spritedata ld d,a ld a,8 ;doing this for 8 lines ld bc,15 uberloop: push af ld e,(ix+0) ld a,(de) ;draw left half or (hl) ;** change this to xor (hl), and (hl), or whatever ld (hl),a inc hl inc d ld a,(de) ;draw right half or (hl) ;** see above ld (hl),a dec d inc ix ;move to next line in graphic add hl,bc ;and the next line on the screen pop af dec a jr nz,uberloop ret ;*********************************************** ;basic findpixel routine that everybody uses... ;translates coordinates to memory locations ;*********************************************** findpixel: ;inputs: ; c=x coordinate ; b=y coordinate ld h,$fc/4 ;this will get multiplied by 4 later ;(change the $fc to whatever if you're using a ; different video plane) ld a,b ;put y coord in a add a,a ;--multiply by 4 add a,a ;/ ld l,a ;now put that in l ld a,c ;put x coord in a rra ;\ add hl,hl ; \ rra ;--- divide a by 8, multiply hl by 4 (must be in this order) add hl,hl ; / rra ;/ ;so now hl is the y coord * 16, added to the appropriate offset add a,l ld l,a ;put the x coord together with hl, to get the offset in video mem ld a,c ;put the x coord in a and %00000111 ;this is the amount the pic must be shifted to the right ret ;outputs: hl=postion in video mem ;a=x-offset .end