Re: A86: Please help


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

Re: A86: Please help



At 09:02 PM 3/13/97 -0800, you 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
>to to be stored into the a register. Will someone help me... everytime i
>try something it screws up. Thank you
>Russ Hanson
>
>

This is a good example of stuff that comes up a lot, basically matrix stuff

here's the actual code, not tested:

GetType:
	ld a,d		;y coord
	rlca		;mult'd by 16
	rlca
	rlca
	rlca
	add a,e		;add the x coord, now we have the relative offset
	ld hl,Level1	;get absolute
	ld e,a		;put this in de
	ld d,0
	add hl,de	;and get the total absolute address
	ld a,(hl)	;and get the value pointed to
	ret

There's prolly a slightly better way, but that's my way


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Alan Bailey            mailto:bailela@charlie.cns.iit.edu
 IRC:Abalone              Web:http://www.iit.edu/~bailela/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 


References: