A86: Re: 2 More Questions


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

A86: Re: 2 More Questions




>Question 1) Say I use this equate:  Xcoord    =  _textshadow
>                  How would I load data into or use data from Xcoord ?

Xcoord is the same thing as an address in hex, only you (the programmer)
don't have to know exactly what the value is.  Just like when you do a

  call _dispAHL

It's the same as doing a

  call $4a33

  _dispAHL = $4a33

Does this make more sense?  Equates (defined with .equ or the equal sign)
take the job off of the programmer of remembering five hundred different
addresses.  I for one have an easier time remembering _dispAHL instead of
$4a33 (which is incidentally the only rom call I can remember the address
for right now...point proven?).

But as a little example...

  ld a,37            ; load 37 into A, which will be used next
  ld (Xcoord),a      ; load A into the memory address that Xcoord stands for

--or--  (in exactly the same number of bytes and t-states)

  ld hl,Xcoord       ; load the address Xcoord (it's a hex address) into HL
   ld (hl),37         ; load 37 into the address that HL points to

This stuff is simple pointer indirection.  If the concept of pointers is
confusing to you, I suggest that you read some tutorials (or try some stuff
in C or Pascal, but imho, pointers are easier to understand in asm because
compilers confuse everything with multiple layers of indirection, etc).

Basically, the processor works with memory using pointers and indirection.
The Z80 has $ffff (in hex) bytes of memory.  You have to access it using
16-bit address like this (usually, but I'm keeping it simple).  Say you want
to access the byte at $fc01.  You do it like this:

  ld a,($fc01)    ; this loads the _value at_ $fc01 into A

The parenthesis means that the _value at_ $fc01 is loaded into A, and not
the value $fc01 (which wouldn't exactly work anyway, since A isn't 16 bits).
Or thinking of it using HL as a pointer:

  ld hl,$fc01     ; the value $fc01 is loaded into HL

HL would now contain the value $fc01.  This could be a value, or a memory
location.  To load a value into that location

  ld (hl),65      ; load the value 65 into the _address HL points to_

If this doesn't make sense at first, try to think about how the processor
works.  It might help if you draw yourself a little diagram on paper
(sounded like a good idea when I typed it).


[snip sprite stuff]

I'm not going delve into this one.  I suggest rewriting it to use variables
instead of trying to preserve the value of BC on the stack.  If you want to
see an example that doesn't use variables, check out sprmove.asm.  But if
you use variables, it will be much easier.