RGBDS "data" segment

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
RGBDS "data" segment
by on (#227893)
Is there any way to implement something like a "data" segment using RGBDS? Specificall, it would be really nice to define and declare data once and end up with a block in the ROM I can just memcpy into place. Not really a big deal, I'm just coming to a realization how handy that is in more sophisticated assemblers.
Re: RGBDS "data" segment
by on (#227894)
Upvote issue #274.
Re: RGBDS "data" segment
by on (#227906)
Hmm. Ok. Good to know I'm not the only one.
Re: RGBDS "data" segment
by on (#229102)
I've solved this by having a bunch of macros that cover all relevant instructions.

Code:
;; Relocated code macros
JPR:   MACRO      ; Relocated jump absolute
   jp   \1+(RCODE-RCODE_S)
   ENDM

JPRC:   MACRO      ; Relocated jump absolute conditional
   jp   \1,\2+(RCODE-RCODE_S)
   ENDM

CALLR:   MACRO      ; Relocated call
   call   \1+(RCODE-RCODE_S)
   ENDM

CALLRC:   MACRO      ; Relocated call conditional
   call   \1,\2+(RCODE-RCODE_S)
   ENDM

LDHLR:   MACRO      ; Relocated ld   HL,addr
   ld   HL,\1+(RCODE-RCODE_S)
   ENDM

LDBCR:   MACRO      ; Relocated ld   BC,addr
   ld   BC,\1+(RCODE-RCODE_S)
   ENDM

LDDER:   MACRO      ; Relocated ld   DE,addr
   ld   DE,\1+(RCODE-RCODE_S)
   ENDM

LDAR:   MACRO      ; Relocated ld   A,[addr]
   ld   A,[\1+(RCODE-RCODE_S)]
   ENDM

DWR:   MACRO      ; Relocated dw   addr
   DW   \1+(RCODE-RCODE_S)
   ENDM


STAR:   MACRO      ; Relocated ld   [addr],A
   ld   [\1+(RCODE-RCODE_S)],A
   ENDM

PREPRELOCATE:   MACRO
        ld      HL,RCODE_S    ; Src
        ld      BC,(RCODE_S_END-RCODE_S)    ; Size
        ld      DE,RCODE        ; Dest
       
        call    COPYPROC


   ENDM

RCODE_AREA_START:   MACRO
RCODE_S::
   ENDM
   
RCODE_AREA_FINISH:   MACRO
RCODE_S_END::
   ENDM

RCODE_RAM_ALLOC:   MACRO
SECTION   "RAMCODE",BSS;;[\1-(RCODE_S_END-RCODE_S)]
RCODE::
   ds   RCODE_S_END-RCODE_S
RCODE_END::
   ENDM