A83: Re: Lists & Tables


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

A83: Re: Lists & Tables




If the table supposed to look like (in hex):

05 0A 08
07 03 0F
02 01 04

then you could do (this isn't tested):

ld (table),01

to change the first item to 01, for example.  To get the value, do:

ld a,(table)

for example.  This would put the value of the first item into a.  I haven't
tested any of this, but it should work.

----------Ignore this next part if the first solution works for what you
want----------

Another (slower) solution would be to do this:

#define row1col1 saferam1
#define row1col2 row1col1+1
#define row1col3 row1col2+1
#define row2col1 row1col3+1
etc.

then to load the data into saferam1 use this code:

ld hl,table
ld de,saferam1
ld bc,9
ldir                      ;copies data at address hl to address de, for bc
number of bytes

That would copy the table to saferam1 (defined in ion.inc for ion
programming).  You could change this to whatever safe ram spot you want, as
long as you change the defines also.  To access the data just do:

ld (row1col1),03 ;to change row 1 column 1 to 03

or

ld a,(row1col1) ;to load a with row 1 column 1

for example, and to copy it back to the table do:

ld hl,saferam1
ld de,table
ld bc,9
ldir

or use a special writeback routine.

The advantage of this approach is that you can use a writeback routine or
write to another program (or anywhere else in ram) if needed, because the
data is stored in saferam1.  The disadvantages are slower speed (due to the
load and save routines needed) and larger code (same reason), as well as
using up 9 bytes of saferam1 (whoopee!)  So if you're using Ion and don't
need a special writeback routine, use the first, direct method.  You could
#define those too, go crazy with defines if you want.

----------End ignoring----------

I hope this helps (and works!) and isn't too complicated (I tend to be too
helpful (yeah right says a little voice)).

Signed,
Asm83P aka Bobthemonkey13

PGP public key available




References: