;=================================================================== ; Very Fast Customizeable Sprite Routine ; written by Kirk Meyer ; ; You may use this library in your programs in unmodified form as ; long as you give me credit somewhere in your documentation. If ; you must modify the code, please ask first. You can customize this ; routine via #DEFINE. The default is an 8x8 non-clipped non-masked ; black and white sprite. Following is the list of all the #DEFINE's ; you can have (be sure to put them before including this file). ; Clipping may be added at a future date. ; ; #DEFINE BMPPUT_HEIGHT ; This sets the height for fixed-height sprites. The ; default is 8. ; ; #DEFINE BMPPUT_MASKED ; This will make bmpPut draw masked sprites. The mask ; is to be stored first in the sprite in UNUSUAL FORM! ; (clear pixels are 0, opaque pixels are 1) ; ; #DEFINE BMPPUT_GRAY ; This will make bmpPut draw grayscale sprites. The first ; part of the sprite is output to the $FC page, and the ; second part is output to the area given by . Be ; sure is the byte value of the page, not the word. ;=================================================================== ;Very Fast Sprite Routine ; ;Inputs: ; BC = (Y,X) coordinate ; HL = pointer to sprite ; ;Destroys: ; AF, BC, DE, HL ; ;Impacts: ; +------+------+------+----------------------------------------------------+ ; | CLIP | MASK | GRAY | Speed Range | 8x8 Speed Range | ; +------+------+------+----------------------------------------------------+ ; | | | | 97+(165*H) to 97+(242*H) | 1417 to 2033 t-states | ; +------+------+------+----------------------------------------------------+ ; | | | ./ | 129+(330*H) to 129+(484*H) | 2769 to 4001 t-states | ; +------+------+------+----------------------------------------------------+ ; | | ./ | | 125+(338*H) to 125+(492*H) | 2829 to 4061 t-states | ; +------+------+------+----------------------------------------------------+ ; | | ./ | ./ | 157+(568*H) to 157+(799*H) | 4701 to 6549 t-states | ; +------+------+------+----------------------------------------------------+ ; ;Notes: ; The number of cycles does not take into account cycles incurred ; while calling and returning from the routine. If you intend to ; use this function as a call and not inline, add 27 to the number ; of cycles. ; ;How it works: ; Rather than outputting the sprite a bit at a time, this function ; outputs it a line at a time. The main algorithm is the use of a ; self-modified jump to vary the number of times each line of the ; sprite is shifted. bmpPut: ld d,$3F ;7 ld a,b ;4 add a,a ;4 add a,a ;4 add a,a ;4 rl d ;8 add a,a ;4 rl d ;8 ld b,c ;4 srl c ;8 srl c ;8 srl c ;8 or c ;4 ld e,a ;4 ld a,b ;4 and $07 ;7 ld c,a ;4 #ifndef BMPPUT_HEIGHT #define BMPPUT_HEIGHT 8 #endif #ifdef BMPPUT_MASKED ld b,BMPPUT_HEIGHT ;7 push de ;11 bmpPutMask: ld a,c ;4 ld (bmpPutMaskMod-1),a ;13 push hl ;11 ld l,(hl) ;7 ld h,$00 ;7 jr bmpPutMaskMod ;12 bmpPutMaskMod: add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 ex de,hl ;4 ld a,d ;4 cpl ;4 #ifdef BMPPUT_GRAY ld d,a ;4 #endif and (hl) ;7 ld (hl),a ;7 inc hl ;6 ld a,e ;4 cpl ;4 #ifdef BMPPUT_GRAY ld e,a ;4 #endif and (hl) ;7 ld (hl),a ;7 #ifdef BMPPUT_GRAY ld a,h ;4 sub $FC-(BMPPUT_GRAY) ;7 ld h,a ;4 ld a,e ;4 and (hl) ;7 ld (hl),a ;7 dec hl ;6 ld a,d ;4 and (hl) ;7 ld (hl),a ;7 ld de,$FC10-((BMPPUT_GRAY)*$100) #else ld de,$000F ;10 (include in both) #endif add hl,de ;11 ex de,hl ;4 pop hl ;10 inc hl ;6 djnz bmpPutMask ;13 pop de ;10 #endif #ifdef BMPPUT_GRAY push de ;11 #endif ld b,BMPPUT_HEIGHT ;7 bmpPutPage1: ld a,c ;4 ld (bmpPutPage1Mod-1),a;13 push hl ;11 ld l,(hl) ;7 ld h,$00 ;7 jr bmpPutPage1Mod ;12 bmpPutPage1Mod: add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 ex de,hl ;4 ld a,d ;4 or (hl) ;7 ld (hl),a ;7 inc hl ;6 ld a,e ;4 or (hl) ;7 ld (hl),a ;7 ld de,$000F ;10 add hl,de ;11 ex de,hl ;4 pop hl ;10 inc hl ;6 djnz bmpPutPage1 ;13 #ifdef BMPPUT_GRAY pop de ;10 ld a,d ;4 sub $FC-(BMPPUT_GRAY) ;7 ld d,a ;4 ld b,BMPPUT_HEIGHT ;7 bmpPutPage2: ld a,c ;4 ld (bmpPutPage2Mod-1),a;7 push hl ;11 ld l,(hl) ;7 ld h,$00 ;7 jr bmpPutPage2Mod ;12 bmpPutPage2Mod: add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 add hl,hl ;11 ex de,hl ;4 ld a,d ;4 or (hl) ;7 ld (hl),a ;7 inc hl ;6 ld a,e ;4 or (hl) ;7 ld (hl),a ;7 ld de,$000F ;10 add hl,de ;11 ex de,hl ;4 pop hl ;10 inc hl ;6 djnz bmpPutPage2 ;13 #endif ret