
Сообщение от
0xDEAD
can I use something like ld a,(COLOR.GREEN)
you can use currently any of those symbols in all possible ways, it will get assembled "correctly", but using the structure offset as absolute address is probably not what you want, sounds like bug in your logic.
I tried to prepare example about basic usage of STRUCT (it has more extended stuff, but this should be enough to illustrate what the docs warning is about):
Код:
; structure definition (ie. like "struct" in C, defining structure)
STRUCT SCOLOR
RED BYTE 4 ; offset 0
GREEN BYTE 5 ; offset 1
BLUE BYTE 6 ; offset 2
ENDS
STRUCT SDOT
ID WORD 0 ; offset 0
C SCOLOR 0,0,0 ; offset 2
X BYTE 0 ; offset 5
Y BYTE 0 ; offset 6
ENDS
; this will assemble the same way as if you did define these symbols by EQU:
; (but sjasmplus will also remember default values of fields to create instances)
; (that part can't be replicated by EQU, only the symbol definitions)
; SCOLOR.RED EQU 0x0000
; SCOLOR.GREEN EQU 0x0001
; SCOLOR.BLUE EQU 0x0002
; SCOLOR EQU 0x0003 ; length of SCOLOR struct
; SDOT.ID EQU 0x0000
; SDOT.C EQU 0x0002 ; offset of SCOLOR struct inside SDOT struct
; SDOT.C.RED EQU 0x0002
; SDOT.C.GREEN EQU 0x0003
; SDOT.C.BLUE EQU 0x0004
; SDOT.X EQU 0x0005
; SDOT.Y EQU 0x0006
; SDOT EQU 0x0007 ; length of SDOT struct
; after structures are defined, you can create instances of them in memory
ORG $8000
myDot SDOT {0x1234, {11, 22, 33}, 44, 55} ; defines "myDot" with ID 0x1234, X=44, Y=55, and C=[11,22,33]
; using it in code
ld ix,myDot ; address of instance
ld c,(ix+SDOT.C.GREEN) ; C = 22 ; assembles as "ld c,(ix+3)"
ld a,(myDot.C.BLUE) ; A = 33 ; assembles as "ld a,(0x8004)"
ld de,SDOT.X ; DE = 5 ; offset inside SDOT struct to field X
ld de,(myDot.X) ; E = 44, D = 55 ; "ld de,(0x8005)"
; ^ this is using instance myDot label, not structure offset
; what docs warns against:
ld de,(SDOT.X) ; ld de,(0x0005) -> reading ROM
; but this doesn't make lot of sense, as you are reading memory from offset
; so it looks rather like bug, like missing "ix+", for example:
ld e,(ix+SDOT.X)
ld d,(ix+SDOT.Y) ; here using the +5 and +6 offsets makes sense
Try to build this with listing: sjasmplus --lst --lstlab example.asm
and check the symbol table and machine code emitted, hopefully this will make more sense.