Re: A82: Sprite routine for ash


[Prev][Next][Index][Thread]

Re: A82: Sprite routine for ash



At 10:11 PM 8/14/97 -0600, you wrote:
>Andrew Von Dollen wrote:
>> 
>> At 02:53 PM 8/14/97 -0600, you wrote:
>> >What is the simplest way (doesn't have to be the fastest) to display a
>> >8x8 sprite at, say, (B,C) using Ash.
>> 
>> PutSprite:              ; Puts a sprite stored at (HL) at B,C  (by Jimmy
Mardell)
>...message here...
>Ok thank you.  But I have one more question.  How would i store a 
>sprite in HL?
>

By saying "the sprite in hl" we mean that in register hl is a pointer to
the place in memory where the sprite is defined. (The .db's in the program
source.)  (This is at the end of the program or a separate include file).
To find the place in memory where the sprite is, you have to know two
things.  First of all, the sprite's offset from the beginning of the
program is defined simply by the name of the variable, which, when
compiled, is replaced with the hex offset from the beginning (defined as $0
by mandatory .org) of the program in memory. Confused yet?  Now the second
element, the assembly shell (OS-82 or ASH) comes in.  The shell is the only
thing that knows where in memory your program resides.  This is defined in
OS-82 and ASH as (PROGRAM_ADDR).  The parentheses are necessary, because
the shell stores the address of the beginning of the program at the memory
location defined in ti-82.h as PROGRAM_ADDR, so the parentheses tell it to
look at the stuff in that mem location, rather than the address itself...
Confused more? :)  Anyway, we must add the address of the beginning of the
program and the offset of the sprite from the beginning of the program, and
put it in hl, which is the offset in memory of the beginning of the sprite
definition.  That's exactly what we need.  We just use these three lines of
code:

       ld hl,sprite			;stores the offset of the sprite from the
;beginning of the prog in hl.
   	ld   de,(PROGRAM_ADDR) 	;stores the offset in calc memory of the
;program that is currently executing in de.
   	add  hl,de			;adds the two, the answer is stored in hl

That is why and how a "sprite is put in hl"
					Rob Bonstein


References: