?login_element?

Subversion Repositories NedoOS

Rev

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

  1. ;; test to exercise instructions which are not Z80-identical into greater depth
  2. ;; focus is mostly on IDA syntax variants, the goal is to have it thoroughly tested
  3.     OPT --syntax=abf    ; but this is expected "default" mode of syntax for new sources
  4.  
  5. ;; example macro to get "halt" which emits automatically halt+nop like rgbasm does
  6. halt    MACRO
  7.             @halt
  8.             nop
  9.         ENDM
  10.     halt    ; = halt+nop
  11.     @halt   ; = halt (only)
  12.  
  13.     ; "variables" crossing into the $FF00 area, so some of them can be accessed with LDH
  14.         STRUCT struct1
  15. a           BYTE    1
  16. b           BYTE    2
  17.         ENDS
  18.  
  19.         ORG     $FF00-4
  20. varSX       struct1
  21. var1        db      0x34
  22. var2        dw      0x5678
  23. var3        db      0xAB
  24. var4        dw      0xCDEF
  25. varS        struct1
  26.  
  27.         ORG     $8000
  28.             ld      a,[var1]        ; like LD a,(a16) on Z80
  29.             ld      a,[var3]
  30.             ldh     a,[low var3]
  31.             ldh     a,[var3]
  32.             ldh     a,[var1]        ; should warn about truncating value (bug in source)
  33.             ld      [var1],a        ; like LD (a16),a on Z80
  34.             ld      [var3],a
  35.             ldh     [low var3],a
  36.             ldh     [var3],a
  37.             ldh     [var1],a        ; should warn about truncating value (bug in source)
  38.             ; repeat the same exercise, but with parentheses
  39.             ld      a,(var1)
  40.             ld      a,(var3)
  41.             ldh     a,(low var3)
  42.             ldh     a,(var3)
  43.             ldh     a,(var1)
  44.             ld      (var1),a
  45.             ld      (var3),a
  46.             ldh     (low var3),a
  47.             ldh     (var3),a
  48.             ldh     (var1),a
  49.             ; the uselessly more explicit syntax (but should work)
  50.             ld      a,[$ff00 + low var3]
  51.             ld      [$ff00 + low var3],a
  52.             ; these should warn, this is not correct way of writing it (bug in source)
  53.             ld      a,[$ff00 + var3]
  54.             ld      [$ff00 + var3],a
  55.             ; accessing the structure members
  56.             ldh     a,[varS.a]
  57.             ldh     [varS.b],a
  58.             ldh     a,[varSX.a]     ; warning, outside of $FFxx area
  59.             ldh     [varSX.b],a     ; warning, outside of $FFxx area
  60.             ld      a,[varS.a]      ; regular LD is optimized if possible
  61.             ld      [varS.b],a      ; regular LD is optimized if possible
  62.             ld      a,[varSX.a]
  63.             ld      [varSX.b],a
  64.  
  65.             ; whitespace parsing in "(c)" operand (not much else to test)
  66.             ld      a , ( c )
  67.             ld      ( c ) , a
  68.             ; illegal register combinations, all should produce some error (mostly "illegal instruction")
  69.             ld      a , ( b )
  70.             ld      ( b ) , a
  71.             ld      b , ( c )       ; error, illegal instruction; --syntax=b reports "ld b,(mem)"
  72.             ld      ( c ) , b
  73.             ld      hl,(c)
  74.             ld      (c),hl
  75.  
  76.             ld      a,(123)         ; check if low-memory warning is off in LR35902 mode (good idea?? not sure)
  77.  
  78.             ldi     a,(hl+)         ; error, mixed invalid syntax
  79.             ldi     a , ( hl )
  80.             ld      a , [ hl+ ]
  81.             ld      a , [ hl + ]    ; error, the "hl+" must be together
  82.             ld      a,(hl+0)        ; error, there's no such thing
  83.  
  84.             ldd     a,(hl-)         ; error, mixed invalid syntax
  85.             ldd     a , ( hl )
  86.             ld      a , [ hl- ]
  87.             ld      a , [ hl - ]    ; error, the "hl-" must be together
  88.             ld      a,(hl-0)        ; error, there's no such thing
  89.  
  90.             ldi     (hl+),a         ; error, mixed invalid syntax
  91.             ldi     ( hl ) , a
  92.             ld      [ hl+ ] , a
  93.             ld      [ hl + ] , a    ; error, the "hl+" must be together
  94.             ld      (hl+0),a        ; error, there's no such thing
  95.  
  96.             ldd     (hl-),a         ; error, mixed invalid syntax
  97.             ldd     ( hl ) , a
  98.             ld      [ hl- ] , a
  99.             ld      [ hl - ] , a    ; error, the "hl-" must be together
  100.             ld      (hl-0),a        ; error, there's no such thing
  101.  
  102.             ; wrong registers => errors
  103.             ldi     a,(de)
  104.             ldd     a,(de)
  105.             ld      a,(de+)
  106.             ld      a,(de-)
  107.             ldi     l,(hl)
  108.             ldd     l,(hl)
  109.             ld      l,(hl+)
  110.             ld      l,(hl-)
  111.             ldi     (de),a
  112.             ldd     (de),a
  113.             ld      (de+),a
  114.             ld      (de-),a
  115.             ldi     (hl),l
  116.             ldd     (hl),l
  117.             ld      (hl+),l
  118.             ld      (hl-),l
  119.             ldi     (hl),1
  120.             ldd     (hl),2
  121.             ld      (hl+),3
  122.             ld      (hl-),4
  123.  
  124.             ld      hl,sp               ; implicit +0
  125.             ld      hl , sp + 0
  126.             ld      hl , sp - 0
  127.             ld      hl , sp + 1
  128.             ld      hl , sp - 1
  129.             ld      hl , sp + +1
  130.             ld      hl , sp + -1
  131.             ld      hl , sp + +1
  132.             ld      hl , sp (+1)        ; error, there must be + or - right after "sp"
  133.             ld      hl , sp + struct1   ; hl = sp + sizeof(struct1)
  134.             ld      hl , sp + 127
  135.             ld      hl , sp + 128       ; error, value is beyond range
  136.             ld      hl , sp - 128
  137.             ld      hl , sp - 129       ; error, value is beyond range
  138.             ld      hl , de + 1         ; invalid
  139.             ld      de , sp + 1         ; invalid
  140.  
  141.             ld      ( var2 + 4 ) , sp
  142.             ld      ( var2 + 4 ) , hl   ; invalid
  143.  
  144.             ; illegal "add sp,r8" variants
  145.             add     sp
  146.             add     sp ,
  147.             add     sp , hl
  148.             add     sp , +128
  149.             add     sp , -129
  150.             ; legit "add sp,r8"
  151.             add     sp , 0
  152.             add     sp , +127
  153.             add     sp , -128
  154.             add     sp , struct1        ; sp += sizeof(struct1)
  155.  
  156.             ; some more malformed lines (intermezzo ... getting back to opcodes already above)
  157.             ld      (hl+)
  158.             ld      [hl+]
  159.             ld      (hl+),
  160.             ld      [hl+],
  161.             ld      [hl+),a
  162.             ld      (hl+],a
  163.             ldi     (hl)
  164.             ldi     [hl]
  165.             ldd     (hl)
  166.             ldd     [hl]
  167.             ldi     (hl),
  168.             ldi     [hl],
  169.             ldd     (hl),
  170.             ldd     [hl],
  171.             ldh     a
  172.             ldh     a,
  173.             ldh     (var3)
  174.             ldh     (var3),
  175.             ldh     [var3]
  176.             ldh     [var3],
  177.             ldh     [var3),a
  178.             ldh     (var3],a
  179.             ld      hl,s
  180.  
  181.             ; illegal syntax of swap
  182.             swap
  183.             swap    (var3)
  184.             swap    var3
  185.             swap    de
  186.             swap    [de]
  187.             swap    (a)
  188.             swap    a,b
  189.             ; legit ones
  190.             swap    a
  191.             swap    a,,b        ; multi-arg
  192.  
  193.             ; illegal syntax of stop
  194.             stop    a
  195.             stop    [0]
  196.             stop    (hl)
  197.             stop    0,,1        ; no multi-arg for STOP implemented
  198.             ; legit ones
  199.             stop                ; implicit 0
  200.             stop    0
  201.             stop    0xE0
  202.  
  203.             ; more multi-args exercised (only in "--syntax=a" mode)
  204.             ldi     a,[hl],,a,(hl),,[hl],a,,(hl),a
  205.             ldd     a,[hl],,a,(hl),,[hl],a,,(hl),a
  206.             ld      a,[hl+],,a,(hl+),,[hl+],a,,(hl+),a
  207.             ld      a,[hl-],,a,(hl-),,[hl-],a,,(hl-),a
  208.             ldh     a,[varS.a],,[varS.b],a,,a,(varS.a),,(varS.b),a
  209.             add     sp,3,,sp,4
  210.             ld      hl,sp,,hl,sp+5,,hl,sp+6
  211.  
  212.             ;;;; more extra tests after pushing the commit (as always)
  213.  
  214.             ; LDH automagic in LD - range checks
  215.             ld      a,(0xFEFF+0)        ; outside
  216.             ld      a,(0xFEFF+1)        ; LDH
  217.             ld      a,(0xFEFF+256)      ; LDH
  218.             ld      a,(0xFEFF+257)      ; outside + warning
  219.             ld      (0xFEFF+0),a        ; outside
  220.             ld      (0xFEFF+1),a        ; LDH
  221.             ld      (0xFEFF+256),a      ; LDH
  222.             ld      (0xFEFF+257),a      ; outside + warning
  223.  
  224.     END     ; scratcharea
  225.