Re: LZ: Question...


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

Re: LZ: Question...



Michael Wyman wrote:

> 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.

It won't work... if you want to get something from row 1, B will become
0 and when you then come to DJNZ, b will be 255, THEN the check for zero
comes. So, you'll add hl,de 256 times instead of 0... You must check if
B=0 or not.

Btw, very often the size of a row is 2,4,8... If that's the case you should
use SLA. If thw row size is 4 (4 columns, each one byte):

GetValue;  Gets from MATRIX, row E, col C. Value stored in A.
 ld hl,Matrix
 ld de,(PROGRAM_ADDR)
 add hl,de
 ld d,0
 sla e  ; This multiplicates E with 4. If there are more than
 sla e  ; 64 rows, you must change D with RL D after this row
 add hl,de
 ld e,c     ; ld d,0 is necessary if you did RL D before
 add hl,de
 ld a,(hl)
 ret

Both column and rows start with 0, not 1. This is always the case when
programming, so you should start thinking that way in your head too.

To store, do the same thing except change ld a,(hl) to lh (hl),a

-- 
Jimmy Mårdell                "To tell you the truth I'm so damned tired
mailto:mja@algonet.se         A life-long leave is what I require
http://www.algonet.se/~mja    Rules, regulations try to form us
IRC: Yarin                    But not me, I'm gonna be enormous" /CRD



References: