A86: Reading The Array


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

A86: Reading The Array




Ok from my knowledge on arrays I got from learning Pascal I'm fairly 
sure this will read through the array and make hl point to the spot in 
the array we wanted to get.



Make_Array:

;my stuff for making the array is here


Array:
 
;your array is here

;lets pretend your array is like a graph
;you pick the x and y coords of where you wanna read assuming this is 
;the grid~~~>  0,0 +---------+ 40,0
;                  |         |
;                  |         |
;                  |         |
;              0,24+---------+40,24 
;I think thats right anways you get the idea I hope
;b=the "x" and c=the "y" of the spot you wanna read
;also hl=area of you array
;and (array) is your actual array's label (if that makes sense)

Get_Coords:  ;this can also be some kinda input routine if you want
             ;it to get somewhere the users says
 ld b,4 ;x
 ld c,5 ;y
 ld d,b ;saved x
 ld e,c ;saved y
 ld b,c ;get y into b so I can use djnz to recurse

Find_Array:
 ld hl,Array  ;we need to know where the array is

Get_Y_Of_Array:
 inc hl  ;move down a .db
 djnz Get_Y_Of_Array  ;repeat until we're at our .db

Init_Get_X_Of_Array:
 ld b,d  ;get x back into b so we can recurse again

Get_X_Of_Array:
 ld hl,(Array+1)  ;move over a cell
 djnz Get_X_Of_Array   ;repeat until until we're at our spot



Now that I think about it this might over shoot by one in each direction 
b/c when you load it into hl its already pointing to the first line so 
we would end up one too many down.  But thats easily fixable by 
subtracting 1 from b and c after they're obtained and before they're 
saved into d and e respectively.  I in no way guarentee that this is 
correct or that it will even work.  I admit I'm not the best programmer 
but I try and sometimes I do good.  As a matter of fact you've probably 
helped me more than I've helped you (seeing as I might need arrays too 
and didn't think I could create or read them using ASM but lo and behold 
I think I did).  Tell me if these work if you don't mind I'm itching to 
know.

Matt

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com


Follow-Ups: