Z80 Routines:Graphic:put16xBsprite
From WikiTI
The put16xBsprite routine is used to plot a 16xB sized sprite.
Code
Basic Version
;2-byte (across) sprite xor routine by Jon Martin ;optimized to be faster than Joe Wingbermeuhle's largesprite routine ;based on the 1-byte xor routine from "learn ti 83+ asm in 28 days" ;inputs: ;a=xc ;e=yc ;b=height ;IX=sprite pointer ;destroys all except shadow registers DoubleSprite: ld h,0 ;7 ld l,e ;4 ld d,h ;4 add hl,hl ;11 add hl,de ;11 add hl,hl ;11 add hl,hl ;11 ld de,plotsscreen ;10 add hl,de ;11 ld e,a ;4 srl e ;8 srl e ;8 srl e ;8 ld d,0 ;7 add hl,de ;11 ld d,h ;4 ld e,l ;4 and 7 ;4 jp z,aligned ;10 ld c,a ;4 ld de,12 ;10 rowloop: ;total: 194 push bc ;11 ld b,c ;4 xor a ;4 ld d,(ix) ;19 ld e,(ix+1) ;19 shiftloop: ;60 per loop srl d ;8 rr e ;8 rra ;4 djnz shiftloop ;13/8,37 per loop inc hl inc hl xor (hl) ld (hl),a ld a,e dec hl xor (hl) ld (hl),a ld a,d dec hl xor (hl) ld (hl),a pop bc ;10 ld de,12 ;10 add hl,de ;11 inc ix ;10 inc ix ;10 djnz rowloop ;13/8 ret ;10 aligned: ld de,11 alignedloop: ld a,(ix) xor (hl) ld (hl),a ld a,(ix+1) inc hl xor (hl) ld (hl),a add hl,de inc ix inc ix djnz alignedloop ret
Masked Version
;Double Masked Sprite Routine by Jon Martin ;for placing a 16xn sprite with a mask on plotsscreen ;ANDs a sprite mask,1's are transperent, 0's are blank ;ORs a sprite where the mask was placed (all black parts of sprite must match 0's on the mask) ;inputs: ;a=column ;b=number of rows of sprite ;e=row ;ix=sprite pointer ;iy=sprite mask pointer ;outputs: ;sprite copied to plotsscreen ;destroys: ;all (including IY) except shadows doublemaskedsprite: ld h,0 ;multiply e by 12 ld l,e ld d,h add hl,hl add hl,de add hl,hl add hl,hl ;e*12=hl ld de,plotsscreen add hl,de ;now hl is on correct row of plotsscreen ld e,a srl e ;divide e by8 srl e srl e ld d,0 add hl,de ;now hl is at top-left byte of where sprite goes and 7 ;check if row is multiple of 8, if it is not then a=bitmask jp z,daligned ;if it is, then the sprite is aligned ld c,a ;now c contains bitmask drowloop: ;this loop will be done b times push bc ;save bc for later ld b,c ;b has bitmask ld d,(ix) ;d is first byte of sprite ld e,(ix+1) ;e is second xor a ;a is 0 dshiftloop1: srl d ;rotate d into e, e into a rr e rra djnz dshiftloop1 ;do this as many times as bitmask says push de ;now save sprite data push af ld b,c ;now b has bitmask again ld d,(iy) ;d is first byte of sprite mask ld e,(iy+1) ;e is second xor a ;a is 0 dshiftloop2: srl d ;rotate d into e, e into a rr e rra djnz dshiftloop2 inc hl ;move hl to byte for a inc hl and (hl) ;and logic a with that location ld (hl),a ;now the byte is masked pop af ;now use old a or (hl) ;use or logic ld (hl),a ;now the byte has been properly written ld a,e ;go to e, 1 left of a dec hl and (hl) ld (hl),a dec hl ld a,d and (hl) ld (hl),a pop de ld a,d or (hl) ld (hl),a inc hl ld a,e or (hl) ld (hl),a pop bc ld de,11 add hl,de inc ix inc ix inc iy inc iy djnz drowloop ld iy,flags ret daligned: ld de,11 dalignedloop: ld a,(iy) and (hl) ld (hl),a ld a,(ix) or (hl) ld (hl),a inc hl ld a,(iy+1) and (hl) ld (hl),a ld a,(ix+1) or (hl) ld (hl),a inc ix inc ix inc iy inc iy add hl,de djnz dalignedloop ld iy,flags ret
Customization
Example
A example using the basic version of PutSprite16.
;... ld e,8 ;y ld a,16 ;x ld b,8 ;height ld ix,sprite call putsprite call fastcopy ;... sprite: .db %11111111,%11111111 .db %10000001,%10000001 .db %10000001,%10000001 .db %10000001,%10000001 .db %10000001,%10000001 .db %10000001,%10000001 .db %10000001,%10000001 .db %11111111,%11111111