?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.         OPT --zxnext
  2.  
  3.         STRUCT RELSTRUCT
  4. Byte        BYTE        $11
  5. Word        WORD        $2233
  6. Tribyte     D24         $445566
  7. Dword       DWORD       $778899AA
  8. Text        TEXT        6, { "Hello", 0 }
  9.         ENDS
  10.  
  11. ; first section is not part of relocation table
  12. ; =============================================
  13.  
  14.         ORG $8000
  15.         ; same as the relocatable block, but outside of RELOCATE_START -> RELOCATE_END
  16.             ld      hl,label1
  17.             ld      hl,(label1)
  18.             ld      (label1),hl
  19.             ld      iy,label1
  20.             ld      iy,(label1)
  21.             ld      (label1),iy
  22.             ld      de,label1
  23.             ld      de,(label1)
  24.             ld      (label1),de
  25.             ld      a,(label1)
  26.             ld      (label1),a
  27.             call    label1
  28.             jp      label1
  29.             add     hl,label1
  30.             RELSTRUCT {,label1,,,{"text",0}}
  31.             DW      s1, s1.end, s1.Tribyte, s1.Text, $
  32.             push    label2
  33.             push    high label2
  34.             ld      b,high label2
  35.             ld      c,high label2
  36.             ld      d,high label2
  37.             ld      e,high label2
  38.             ld      l,high label2
  39.             ld      h,high label2
  40.             ld      (hl),high label2
  41.             ld      a,high label2
  42.             add     a,high label2
  43.             adc     a,high label2
  44.             sub     high label2
  45.             sbc     a,high label2
  46.             and     high label2
  47.             xor     high label2
  48.             or      high label2
  49.             cp      high label2
  50.             test    high label2
  51.             nextreg $00,high label2
  52.             ld      ixh,high label2
  53.             ld      ixl,high label2
  54.             ld      (ix+123),high label2
  55.             ld      iyh,high label2
  56.             ld      iyl,high label2
  57.             ld      (iy+123),high label2
  58.             RELSTRUCT {high label2,high label2,,,{"ZX",0}}
  59.             DB      high s2, high s2.end, high s2.Tribyte, high s2.Text, high $
  60.             ABYTE   123 high label2-123
  61.             ABYTEZ  123 high label2-123
  62.             add     a,l2_high
  63.             ld      hl,l2_high
  64.             ld      hl,(l2_high)
  65.             ld      (l2_high),hl
  66.             ld      iy,l2_high
  67.             ld      iy,(l2_high)
  68.             ld      (l2_high),iy
  69.             ld      de,l2_high
  70.             ld      de,(l2_high)
  71.             ld      (l2_high),de
  72.             ld      a,(l2_high)
  73.             ld      (l2_high),a
  74.             call    l2_high
  75.             jp      l2_high
  76.             add     de,l2_high
  77.             RELSTRUCT {,l2_high,,,{"text",0}}
  78.             DW      high s4, high s4.end, high s4.Tribyte, high s4.Text, high $
  79.  
  80. ; resulting relocation data
  81. ; =========================
  82.  
  83.         DW      relocate_count, relocate_size
  84.  
  85.         RELOCATE_TABLE      ; provides relocation addresses pointing directly at the high byte
  86.  
  87.         RELOCATE_TABLE +1   ; provides relocation addresses pointing one byte ahead of the high byte
  88.  
  89. ; second section does test relocation
  90. ; ===================================
  91.  
  92.     RELOCATE_START HIGH
  93.         ORG $0000
  94.         ; relocation cases - word immediate instructions (relocation points at high byte)
  95.             ld      hl,label1
  96.             ld      hl,(label1)
  97.             ld      (label1),hl
  98.             ld      iy,label1
  99.             ld      iy,(label1)
  100.             ld      (label1),iy
  101.             ld      de,label1
  102.             ld      de,(label1)
  103.             ld      (label1),de
  104.             ld      a,(label1)
  105.             ld      (label1),a
  106. label1:
  107.             call    label1
  108.             jp      label1
  109.             add     hl,label1           ; z80n extras
  110. s1          RELSTRUCT {,label1,,,{"text",0}}
  111. .end:
  112.             DW      s1, s1.end, s1.Tribyte, s1.Text, $
  113.  
  114.         ORG $0FF0
  115.         ; super special z80n extra, not working in regular full-word relocation mode
  116.             push    label2              ; but these are possible in HIGH mode
  117.             push    high label2
  118.  
  119.         ORG $1101
  120.         ; relocation cases - byte immediate instructions (relocation points at immediate (high byte))
  121.             ld      b,high label2
  122.             ld      c,high label2
  123.             ld      d,high label2
  124.             ld      e,high label2
  125. label2:
  126.             ld      l,high label2
  127.             ld      h,high label2
  128.             ld      (hl),high label2
  129.             ld      a,high label2
  130.             add     a,high label2
  131.             adc     a,high label2
  132.             sub     high label2
  133.             sbc     a,high label2
  134.             and     high label2
  135.             xor     high label2
  136.             or      high label2
  137.             cp      high label2
  138.             test    high label2         ; z80n extras
  139.             nextreg $00,high label2     ; z80n extras
  140.             ; IX block
  141.             ld      ixh,high label2
  142.             ld      ixl,high label2
  143.             ld      (ix+123),high label2
  144.             ; IY block
  145.             ld      iyh,high label2
  146.             ld      iyl,high label2
  147.             ld      (iy+123),high label2
  148. s2          RELSTRUCT {high label2,high label2,,,{"ZX",0}}
  149. .end:
  150.             DB      high s2, high s2.end, high s2.Tribyte, high s2.Text, high $
  151.             ABYTE   123 high label2-123
  152.             ABYTEZ  123 high label2-123
  153.  
  154.             ; test EQU "transitiviness" and test word instruction with high byte only
  155.         ORG $1380
  156. l2_high     EQU     high label2
  157.             add     a,l2_high           ; is equ transitive (keeping high/regular knowledge)?
  158.             ld      hl,l2_high
  159.             ld      hl,(l2_high)
  160.             ld      (l2_high),hl
  161.             ld      iy,l2_high
  162.             ld      iy,(l2_high)
  163.             ld      (l2_high),iy
  164.             ld      de,l2_high
  165.             ld      de,(l2_high)
  166.             ld      (l2_high),de
  167.             ld      a,(l2_high)
  168.             ld      (l2_high),a
  169.             call    l2_high
  170.             jp      l2_high
  171.             add     de,l2_high           ; z80n extras
  172. s4          RELSTRUCT {,l2_high,,,{"text",0}}
  173. .end:
  174.             DW      high s4, high s4.end, high s4.Tribyte, high s4.Text, high $
  175.  
  176.         ORG $2200
  177.         ; no relocation cases
  178.             rst     $08
  179.             DB      low label2, low s2, low s2.end, low s2.Tribyte, low s2.Text, low $
  180.             ld      bc,label2 - label1
  181.             ld      a,low label2
  182.             ld      a,high label2 - high label1
  183.             ld      (hl),high label2 - high label1
  184.             ; IX block
  185.             ld      (ix+low label2),123
  186.             ld      (ix+123),low label2
  187.             add     a,(ix+low label2)
  188.             adc     a,(ix+low label2)
  189.             sub     (ix+low label2)
  190.             sbc     a,(ix+low label2)
  191.             and     (ix+low label2)
  192.             xor     (ix+low label2)
  193.             or      (ix+low label2)
  194.             cp      (ix+low label2)
  195.             bit     0,(ix+low label2)
  196.             bit     7&low label2,(ix+123)
  197.             res     0,(ix+low label2)
  198.             res     7&low label2,(ix+123)
  199.             set     0,(ix+low label2)
  200.             set     7&low label2,(ix+123)
  201.             ; IY block
  202.             ld      (iy+low label2),123
  203.             ld      (iy+123),low label2
  204.             add     a,(iy+low label2)
  205.             adc     a,(iy+low label2)
  206.             sub     (iy+low label2)
  207.             sbc     a,(iy+low label2)
  208.             and     (iy+low label2)
  209.             xor     (iy+low label2)
  210.             or      (iy+low label2)
  211.             cp      (iy+low label2)
  212.             bit     0,(iy+low label2)
  213.             bit     7&low label2,(iy+123)
  214.             res     0,(iy+low label2)
  215.             res     7&low label2,(iy+123)
  216.             set     0,(iy+low label2)
  217.             set     7&low label2,(iy+123)
  218.  
  219.         ORG $4400
  220.         ; unstable/can't be relocated by +offset mechanics
  221.             out     (high label2),a     ; exception: out (imm8),a is never relocatable
  222.             in      a,(high label2)     ; exception: in a,(imm8) is never relocatable
  223.             nextreg high label2,$00     ; z80n extras - register number is never relocatable
  224.             nextreg high label2,a       ; z80n extras - register number is never relocatable
  225.             ; 16bit relocation should be warned against when only high-byte is possible
  226.             ld      b,label1            ; even if the label is 8bit value like $0026
  227.             ld      c,label1
  228.             ld      d,label1
  229.             ld      e,label1
  230.             ld      l,label1
  231.             ld      h,label1
  232.             ld      (hl),label1
  233.             ld      a,label1
  234.             add     a,label1
  235.             adc     a,label1
  236.             sub     label1
  237.             sbc     a,label1
  238.             and     label1
  239.             xor     label1
  240.             or      label1
  241.             cp      label1
  242.             test    label1              ; z80n extras
  243.             nextreg $00,label1          ; z80n extras
  244. s3          RELSTRUCT {label1,,,,{"ZX",0}}
  245.             DB      label1
  246.             ; IX block
  247.             ld      ixh,label1
  248.             ld      ixl,label1
  249.             ld      (ix+123),label1
  250.             ld      (ix+high label2),123
  251.             add     a,(ix+high label2)
  252.             adc     a,(ix+high label2)
  253.             sub     (ix+high label2)
  254.             sbc     a,(ix+high label2)
  255.             and     (ix+high label2)
  256.             xor     (ix+high label2)
  257.             or      (ix+high label2)
  258.             cp      (ix+high label2)
  259.             rlc     (ix+high label2)
  260.             rrc     (ix+high label2)
  261.             rl      (ix+high label2)
  262.             rr      (ix+high label2)
  263.             sla     (ix+high label2)
  264.             sra     (ix+high label2)
  265.             sli     (ix+high label2)
  266.             srl     (ix+high label2)
  267.             bit     0,(ix+high label2)
  268.             bit     7&high label2,(ix+123)
  269.             res     0,(ix+high label2)
  270.             res     7&high label2,(ix+123)
  271.             set     0,(ix+high label2)
  272.             set     7&high label2,(ix+123)
  273.             ; IY block
  274.             ld      iyh,label1
  275.             ld      iyl,label1
  276.             ld      (iy+123),label1
  277.             ld      (iy+high label2),123
  278.             add     a,(iy+high label2)
  279.             adc     a,(iy+high label2)
  280.             sub     (iy+high label2)
  281.             sbc     a,(iy+high label2)
  282.             and     (iy+high label2)
  283.             xor     (iy+high label2)
  284.             or      (iy+high label2)
  285.             cp      (iy+high label2)
  286.             rlc     (iy+high label2)
  287.             rrc     (iy+high label2)
  288.             rl      (iy+high label2)
  289.             rr      (iy+high label2)
  290.             sla     (iy+high label2)
  291.             sra     (iy+high label2)
  292.             sli     (iy+high label2)
  293.             srl     (iy+high label2)
  294.             bit     0,(iy+high label2)
  295.             bit     7&high label2,(iy+123)
  296.             res     0,(iy+high label2)
  297.             res     7&high label2,(iy+123)
  298.             set     0,(iy+high label2)
  299.             set     7&high label2,(iy+123)
  300.             ; can't be relocated by +offset
  301.             ld      hl,label2+label2
  302.             ld      hl,label2>>1
  303.             ld      a,high label2 + high label2
  304.             ; transitive EQU
  305. l1_regular  EQU     label1
  306.             add     a,l1_regular
  307.  
  308.             ; ABYTE variants should report unstable when relocatable value is used for "offset" argument
  309.             ABYTE   high label1 1, 2
  310.             ABYTEZ  high label1 3
  311.  
  312.     RELOCATE_END
  313.  
  314.     RELOCATE_START      ; check if regular-mode emits error about mixing modes
  315.