RE: LZ: Question...


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

RE: LZ: Question...



On Wed, 18 Dec 1996 14:36:17 -0600 (CST),
Carl Turner wrote...
>I know that this was just talked about on here, but I have seem to have 
>lost some of it.
>
>Could some one send me a _GOOD_ explanation of how to work with matrix in 
>z80?
>
>I want to set up a matrix like this.
>11111
>10101
>10001
>10101
>11111
>1=wall
>0=space
>now I want to know the best way i can set this up in the .db enteries, 
>and how to read them? to test for a wall.

The basic theory is this:

It is given that you know the address of the start of the matrix, okay!  
What is needed then is to find the address of the location within the 
matrix pointed to by (x, y)=(COLUMN, ROW).  The columns are put directly 
next to each other in memory.  If hl points to the begining of row 1 (which 
you KNOW (same as the address of the beginning of the matrix)), you can 
increase hl by COLUMN-1 (you are currently pointing to the FIRST column, 
ALREADY!) to point the matrix's value at (COLUMN, 1).

Because you will have values in locations where ROW>1, you will need to be 
able to find increase hl by the correct amount to find the address of the 
the value.  The correct amount (which you need to ADD to hl) is equal to 
COLUMN*(ROW-1).  So to find the address of the value in (5, 3) in your 
matrix, you would do something like this:

ld    hl, (PROGRAM_ADDR)
ld    de, MATRIX
add   hl, de            ;hl points to first value of MATRIX
ld    b, ROW-1          ;I'm assuming that ROW and COLUMN are fixed values
                        ;Though you could make them able to change in your
                        ;Program.
ld    de, #_OF_COLUMNS  ;You know the number of columns
ROW_FIND:
add   hl, de
djnz  ROW_FIND
ld    de, COLUMN
add   hl, de            ;hl now should point to the correct address for
                        ;(COLUMN, ROW).

MATRIX:
*db (stuff)             ;Your Matrix Here!
db (stuff)

I think that the routine above should work.  You may need to change it a 
bit so that ROW and COLUMN can change during your program, but I'll leave 
that to you.

Hope it helped,
Michael Wyman - SeaHorse Software
wyma0012@gold.tc.umn.edu




Follow-Ups: