?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.     MACRO SECTION sectionName?
  2.         ; init new section to ORG 0
  3.         IFNDEF SECTION_MACRO_KNOWN_SECTION_sectionName?
  4.             DEFINE SECTION_MACRO_KNOWN_SECTION_sectionName?
  5. SECTION_MACRO_LAST_ADR_sectionName? = 0
  6.         ENDIF
  7.         ; if sections are switching, remember position of previous
  8.         IFDEF SECTION_MACRO_PREVIOUS_SECTION
  9. SECTION_MACRO_LAST_ADR_SECTION_MACRO_PREVIOUS_SECTION = $
  10.             UNDEFINE SECTION_MACRO_PREVIOUS_SECTION
  11.         ENDIF
  12.         DEFINE SECTION_MACRO_PREVIOUS_SECTION sectionName?
  13.         ; and set/restore the position of requested section
  14.         ORG SECTION_MACRO_LAST_ADR_sectionName?
  15.     ENDM
  16.  
  17.     DEVICE ZXSPECTRUM48
  18. ; WARNING - the SECTION macro makes sense only with DEVICE virtual memory
  19. ; if you do just simple `OUTPUT "section.bin"`, the output will mix all
  20. ; sections together.
  21. ; To output separate sections without mixing you have to save each section
  22. ; separately at the end of assembling from the virtual-device memory.
  23.  
  24.     SECTION @code       ; use reasonable section names which can form part of label name
  25.         rst     0       ; this will land to address $0000, because no ORG was done
  26.         ORG     $8000   ; at the first usage of SECTION, use ORG to set initial address
  27. @code_start equ   $
  28.         nop             ; `nop` at $8000
  29.  
  30.     SECTION @data
  31.         ORG     $D000
  32. @data_start equ   $
  33. s1:     DZ      "abc"
  34.  
  35.     SECTION @code
  36.         ld      hl,s1   ; `ld hl,..` at $8001, s1 = $D000
  37.         ld      bc,s2   ; s2 = $D004
  38.  
  39.     SECTION @data
  40. s2:     DZ      "efg"
  41. @data_end equ   $
  42.  
  43.     SECTION @code
  44.         jr      $       ; `jr` at $8007 after `ld bc,..`
  45. @code_end equ   $
  46.  
  47.     ; save the binary result of sections
  48.  
  49.     ; saving code (except that `rst 0`)
  50.     SAVEBIN "section.bin", code_start, code_end-code_start
  51.     ; saving strings
  52.     SAVEBIN "section.raw", data_start, data_end-data_start
  53.