Re: A83: using hl as a label


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

Re: A83: using hl as a label




I don't think you can do offsets with hl.  The simplest way is add to hl.  
Now if you want to use offsets, you can use ix.  It is much like hl but a 
little slower.  You can only offset a set amount but ix can change.  like 
this:

ld a,(ix+1)


In a message dated 7/12/99 7:34:08 PM Eastern Daylight Time, 
jimbob_v@hotmail.com writes:

<< On Mon, 12 Jul 1999 14:58:01 PDT, the homonerdicus wrote:
 
 >yo ...
 >
 >Now, I have a place in memory where I strore data about several units and 
 >it
 >looks like this.
 >
 >#DEFINE beg 82A1h 		; 708 bytes
 >
 >#DEFINE hero1 beg
 >#DEFINE hero2 beg+60d
 >#DEFINE hero3 beg+120d
 >#DEFINE hero4 beg+180d
 >#DEFINE hero5 beg+240d
 >
 >#DEFINE unit1 30d
 >#DEFINE unit2 40d
 >#DEFINE unit3 50d
 >
 >#DEFINE type 0
 >#DEFINE heroN 2
 >#DEFINE Nofunits 3
 >#DEFINE x 4
 >#DEFINE y 5
 >#DEFINE hp 6
 >#DEFINE stat 7
 >#DEFINE kind 8
 >
 >So to find the hitpoints of the 3rd unit of the 2nd hero.
 >ld a,(hero2+unit3+hp)
 >
 >At a different place in the prog I have the adress of the unit in hl
 >and I want to add to it the offset for hitpoints....
 >
 >I tried :
 >ld a,(hl)+hp
 >ld a,(hl+hp)
 >ld a,((hl)+hp)
 >and none of them work ... The assembler takes hl for a label and says 
 >"label
 >not found"
 >
 >I know I can do it this way
 >ld d,0
 >ld a,(hp)
 >ld e,a
 >add hl,de
 >a,(hl)
 >
 >but it's very long and will be using this a lot of times in the game ...
 >
 >Does anybody know a way to do this ?
 >Ideas comments ....
 >
 >thanks
 
    One way you could possibly fix it is to make the last bit of code you 
 wrote into a separate routine so that you can just call it whenever.. 
 couldn't you? What about this:
 
 #define temp $858F
   ld (temp),hl    ; load the address into the temp var
   ld a,(temp+hp)  ; load into A the data you want
 
    This should work instead of what you had earlier, which was:
 
   ld a,(hl+hp)
 
    Anyways, hope that helps..
 
 James Vernon
 jimbob_v@hotmail.com >>