Re: A86: Please help


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

Re: A86: Please help



At 08:28 PM 9/10/97 -0700, you wrote:
>Russ Hanson wrote:
>
>> i am having some trouble. I have a 16x8 map
>> Level1:
>>   .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
>>   .db 0,1,2,2,0,3,0,1,0,0,0,0,0,0,3,0
>>   .db 0,2,0,0,0,3,0,3,0,0,0,1,0,0,2,0
>>   .db 0,2,0,0,0,3,0,2,0,0,1,0,2,0,0,0
>>   .db 0,0,0,0,0,3,0,0,2,3,2,0,0,0,0,0
>>   .db 0,2,0,0,0,3,0,0,0,0,0,0,0,0,2,0
>>   .db 0,1,2,2,0,3,0,0,0,0,0,2,0,0,2,0
>>   .db 0,0,0,0,0,0,0,0,0,0,0,0,2,0,1,0
>> and need to be able to check what is on the map be it 0,1...16.
>> depending on x,y coordinates (x is stored into the e register and y
>> into
>> the d register) i would like the number the x,y coordinates coorispond
>
>that isn't hard at all.. this should work:you want basically the
>y*16+x item in the map right?
>so this is basically what we want to do:
>hl points to pic
>b=0
>c = d
>c = c*16
>c = c+e
>hl=hl+bc
>right? so in asm this is:
>
>;IN: D = Y coord E = X coord  OUT: A=Value at (e,d)  CHANGED: BC
>CoolFunc:
>  ld hl,Level1 ;hl points to begining of map
>  ld b,0
>  ld a,d
>  sla a ; a = a * 2
>  sla a ; a = a * 4
>  sla a ; a = a * 8
>  sla a ; a = a *16
>  add a,e  ; add your x offset
>  ld c,a     ;store that answer into c
>  add hl,bc ; add to our  pointer
>  ld a,(hl) ; get the value
>  ret

Those 'sla a' lines above should be changed to 'add a,a' which does the
same thing and is shorter.

A better way to do matrices (though not always applicable to certain
situations) is to use an offset from the beginning of the matrix in place
of x and y coords, it is then much easier to get/store elements etc.

	-Andrew


References: