Re: A85: Sprite help...
[Prev][Next][Index][Thread]
Re: A85: Sprite help...
In a message dated 7/5/99 4:32:31 PM MDT, shunt@apex.net writes:
>
> Im trying DEPSERATELY to learn to use sprites in my progs. Ive learned to
> move sprites on the screen byte by byte, that is, I can move a sprite over
8
> pixels at a time, and up and down any number or pixels i want, but I wanna
> know how to
> move them left and right a single pixel at a time.
Well...hmmm...someone else I know was trying to do this... It's really
pretty easy to do (sorry ;).
>
>
> Ive tried several routines, checked my code and quadruple checked it, but
> cant get any routines to work right. Here is my code, using the newest
> routine(i think) SDR by Jay L of Macross Software:
Okay (that's me ;).
>
>
> #include "usgard.h"
>
> .org 0
> .db "Test", 0
>
> call CLEARLCD
>
>
> jr Draw
Here, you could just do a < call &Draw> and stick a < ret> at the end of the
Draw routine.
>
>
>
> Wait:
>
> call GET_KEY
> cp K_EXIT
> jr nz, Wait
> ret
Put a < halt> before the < call GET_KEY>; saves battery life.
>
>
>
> Draw:
> ld hl, &Sprite
> ld b, 9
> ld c, 9
This could be optimized to < ld bc,9 * $100 + 9>.
>
>
>
>
>
> ;***this is the routine here:***
> ;Sprite Drawing Routine (SDR): 8 Bit Normal Version
> ;by JL
> ;<JayEll64@aol.com>
> ;
> ;Inputs:
> ; b=x coordinate
> ; c=y coordinate
> ; hl=pointer to sprite data
> ;Outputs:
> ; af=destroyed
> ; bc=destroyed
> ; de=destroyed
> ; hl=pointer to byte after sprite
> ; no other registers are changed
> ;If you want to save those registers that are destroyed, push/pop them!
> ;
> ;Sprite data should be stored as follows:
> ;.db (# rows/bytes/height of sprite)
> ;.db (bitmap of sprite)
> ;
>
>
>
> PutSprite:
Whoa, whoa, whoa...does *this* look like SDR8?! I think you've put the
header of my routine with PutSprite! ;)
> push ix
> push bc
> push de
> ld a,63 ;\
> sub c ; |63-y, so the drawing starts at the top
> ld c,a ;/
> push hl
> push hl
> call FIND_PIXEL ;hl has offset in viedo mem; a has bit^2
> ld de,GRAPH_MEM ;store into graph mem for virtual screen
Since DE is loaded with the graphics memory address, then the sprite will be
drawn to the graphics memory. Try changing this to < ld de,VIDEO_MEM>.
> add hl,de
> ex de,hl ;de physical address in vid mem
> pop hl ;hl has sprite's beginning address again
> ld b,8 ;ld b with width
> ld c,8 ;ld c with height
> push hl ;(hl) has the graphics of the sprite
> pop ix ;(ix) has the graphics of the sprite
> ex de,hl ;\(de) has gfx of sprite
> ;/hl has addr. in video mem
> PS_NewRow:
> push bc
> ld d,(ix) ;d has graphics for one row of sprite
> inc ix ;point to next row of sprite
> push af
> push hl
> PS_NewCol:
> rl d
> ld e,a
> jr nc,PS_NoPixel
> or (hl)
> ; ld (hl),a ;Michael Optimization
> jr PS_NextPixel
> PS_NoPixel:
> cpl ;complement of a, ~a
> and (hl) ;\ a = what's in video mem AND ~bit^2
> ; |only bit^2 is affected (erased)
> ;/ all others AND'ed w/1, which has no affect
> ; ld (hl),a ;Michael Optimization
> PS_NextPixel:
> ld (hl),a ;ld a back into video mem (where it should be)
> ld a,e ;restore bit^2 into a
> rrca ;\circular rotation of a, so a affects next bit
> jr nc,PS_SameByte ;C flag set when the 1 in a is shifted out of a
> inc hl ;next byte in video memory
> PS_SameByte:
> djnz PS_NewCol ;go to the next column if b not = 0
> pop hl ;restore the video mem address
> pop af ;restore the byte from FIND_PIXEL
> ld de,16 ;\move down a row (which is 16 bytes)
> add hl,de ;/
> pop bc ;bc again contains the width and height
> dec c ;one less row to draw
> jr nz,PS_NewRow ;when c=0, don't draw anymore rows
> pop hl ;\
> pop de ; |pixel plotted so restore the registers
> pop bc ; |
> pop ix ;/
>
> ;***End Routine***
>
>
>
>
>
>
> jr Wait ;return to main program
>
>
> ;End:
> ; ret
>
> Sprite:
>
> .db %00001000, %00001000
You should just do <.db 8,8>; makes the code easier to read.
>
> .db %00111100
> .db %01100110
> .db %11000011
> .db %11000011
> .db %11000011
> .db %11000011
> .db %01100110
> .db %00111100
>
> .end
>
> Any help would be GREATLY appreciated.
>
> THanks
>
> Stu
Hope that fixes it.
JL
Macross Software