; Ultimate Sprite Routine Version 1.1 (normal version) ; Copyright 1997 - 2000 by Patrick Davidson ; ; This is absolutely the *fastest* sprite routine. ; It is even faster than the one in Jimmy Mardell's Game Engine. ; ; E-Mail: pad@ocf.berkeley.edu ; Web Site: http://www.ocf.berkeley.edu/~pad/ ; ; You may use this routine (or a modified version of it) in any program ; provided that you do all of the following: ; 1) Give credit for it in your documentation ; 2) Make the full source code of your program available ; 3) Permit others to modify your program ; ; Draws sprites 8 pixels wide, unlimited height ; Draws unmasked in XOR mode (easily converted to OR) ; Draws to 16-byte-wide buffer at $FC00 (easily changed) ; For calculators other than TI-85, it might help to remove the &s ; ; Does not disable interrupts ; Code size approximately 250 bytes ; Does not need any external storage ; ; Paramters: ; HL points to sprite image ; D is X coordinate ; E is Y coordinate ; ; For normal mode, the sprite contains first the width (unused) and height ; as bytes, then the sprite data line by line. ; ; Speed (8x16 sprites drawn per second, spread across all X coordinates): ; ; Ultimate Sprite Routine Version 1.1: 2150 ; Routine from Jimmy Mardell's Game Engine: 2100 (didn't test this myself) ; Kirk Meyer's VFSprite: 1450 ; Jimmy Mardell's PutSprite: 440 ; ; Reasons for speed: ; 1. Selects separate routine each amount of shifting (also gives huge size) ; 2. Rotates in reverse direction when shifted more than 4 pixels right drw_spr: push hl ; Save sprite image pointer ld b,0 ld hl,$FC00 ; HL -> start of buffer ld a,e add a,a add a,a ; A = Y * 4 add a,a rl b ; BA = Y * 8 add a,a rl b ; BA = Y * 16 ld c,d srl c srl c srl c ; C = X / 8 or c ld c,a add hl,bc ; HL = Screen address ex de,hl ; DE = Screen address ld a,h ; A = X coordinate and 7 ld b,a add a,a add a,b ld (&jumpintable+1),a pop hl inc hl ld b,(hl) ; B = height inc hl ; HL -> image ex de,hl ; HL -> screen, DE -> image ld c,0 jumpintable: jr table table: jp &routine jp &routine1 jp &routine2 jp &routine3 jp &routine4 jp &routine5 jp &routine6 routine7: inc hl routine7l: ld a,(de) ;7 inc de ;6 add a,a ;4 rl c ;8 xor (hl) ;7 ld (hl),a ;7 dec hl ;6 ld a,(hl) ;7 xor c ;4 ld (hl),a ;7 ld a,b ;4 ld bc,17 ;10 add hl,bc ;11 ld c,b ;4 ld b,a ;4 djnz routine7l ret routine: ld a,(de) ;7 inc de ;6 xor (hl) ;7 ld (hl),a ;7 ld a,b ;4 ld bc,16 ;10 add hl,bc ;11 ld b,a ;4 djnz routine ret routine1: ld a,(de) ;7 inc de ;6 rra ;4 rr c ;8 xor (hl) ;7 ld (hl),a ;7 inc hl ;6 ld a,(hl) ;7 xor c ;4 ld (hl),a ;7 ld a,b ;4 ld bc,15 ;10 add hl,bc ;11 ld c,b ;4 ld b,a ;4 djnz routine1 ret routine2: ld a,(de) ;7 inc de ;6 rrca ;4 rrca ;4 ld c,a ;4 and $3F ;7 xor (hl) ;7 ld (hl),a ;7 ld a,c ;4 and $C0 ;7 inc hl ;6 xor (hl) ;7 ld (hl),a ;7 ld a,b ;4 ld bc,15 ;10 add hl,bc ;11 ld b,a ;4 djnz routine2 ret routine3: ld a,(de) ;7 inc de ;6 rrca ;4 rrca ;4 rrca ;4 ld c,a ;4 and $1F ;7 xor (hl) ;7 ld (hl),a ;7 ld a,c ;4 and $E0 ;7 inc hl ;6 xor (hl) ;7 ld (hl),a ;7 ld a,b ;4 ld bc,15 ;10 add hl,bc ;11 ld b,a ;4 djnz routine3 ret routine4: ld a,(de) ;7 inc de ;6 rrca ;4 rrca ;4 rrca ;4 rrca ;4 ld c,a ;4 and $0F ;7 xor (hl) ;7 ld (hl),a ;7 ld a,c ;4 and $F0 ;7 inc hl ;6 xor (hl) ;7 ld (hl),a ;7 ld a,b ;4 ld bc,15 ;10 add hl,bc ;11 ld b,a ;4 djnz routine4 ;13 ret routine6: ld a,(de) ;7 inc de ;6 rlca ;4 rlca ;4 ld c,a ;4 and $03 ;7 xor (hl) ;7 ld (hl),a ;7 ld a,c ;4 and $FC ;7 inc hl ;6 xor (hl) ;7 ld (hl),a ;7 ld a,b ;4 ld bc,15 ;10 add hl,bc ;11 ld b,a ;4 djnz routine6 ;13 ret routine5: ld a,(de) ;7 inc de ;6 rlca ;4 rlca ;4 rlca ;4 ld c,a ;4 and $07 ;7 xor (hl) ;7 ld (hl),a ;7 ld a,c ;4 and $F8 ;7 inc hl ;6 xor (hl) ;7 ld (hl),a ;7 ld a,b ;4 ld bc,15 ;10 add hl,bc ;11 ld b,a ;4 djnz routine5 ;13 ret