[A83] Structs in asm


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

[A83] Structs in asm




Hey guys, I'm sure you all have programmed structs sometime before(yeah blah 
blah blah) and i'm sure you have all realised, but I'm going to write 
something about how to do them in asm, just incase you guys have realised it, 
and would appreciate it(yeah like that will happen)

ok, first step, design the struct, here we decide what data will be placed 
into it and what not
(example from the code i'll be using for doors)
;1st 2 bytes, x and y on current map
;2nd 2 bytes, new map in memory
;3rd 2 bytes, new x and y cordinates(where to move them too)
;4th 2 bytes, misc data (need key(1st byte), which key(2nd byte) etc...)

so the data would look like this:
door:
    .db 5,2     ;x,y
    .dw NewMap; Map's name
    .db 4,3     ;new x and y
    .db 0,0

and then to get the x and y cordinates i would do this:
    ld hl,door
    ld a,(hl)
    inc hl
    ld b,(hl)       ;now the x and y cordinates are in a and b respectivly

and to get the new door:
    ld hl,door
    inc hl
    inc hl
    inc hl  ;maybe i could just say,add hl,3 i dunno
    ld de,(hl)
    ld hl,de        ;i could leave this out and just work with de too, but oh 
well

etc...

just a quick thought i had, and thought i would give that bit of "wisdom" out.