;=================================================
; Autogenerated AcheronVM instruction definitions
; See acheron.asm for source


;------------------
; Registers

.define r0 0
.define r1 1
.define r2 2
.define r3 3
.define r4 4
.define r5 5
.define r6 6
.define r7 7
.define r8 8
.define r9 9
.define r10 10
.define r11 11
.define r12 12
.define r13 13
.define r14 14
.define r15 15
.define r16 16
.define r17 17
.define r18 18
.define r19 19
.define r20 20
.define r21 21
.define r22 22
.define r23 23
.define r24 24
.define r25 25
.define r26 26
.define r27 27
.define r28 28
.define r29 29
.define r30 30
.define r31 31
.define r32 32
.define r33 33
.define r34 34
.define r35 35
.define r36 36
.define r37 37
.define r38 38
.define r39 39
.define r40 40
.define r41 41
.define r42 42
.define r43 43
.define r44 44
.define r45 45
.define r46 46
.define r47 47
.define r48 48
.define r49 49
.define r50 50
.define r51 51
.define r52 52
.define r53 53
.define r54 54
.define r55 55
.define r56 56
.define r57 57
.define r58 58
.define r59 59
.define r60 60
.define r61 61
.define r62 62
.define r63 63
.define r64 64
.define r65 65
.define r66 66
.define r67 67
.define r68 68
.define r69 69
.define r70 70
.define r71 71
.define r72 72
.define r73 73
.define r74 74
.define r75 75
.define r76 76
.define r77 77
.define r78 78
.define r79 79
.define r80 80
.define r81 81
.define r82 82
.define r83 83
.define r84 84
.define r85 85
.define r86 86
.define r87 87
.define r88 88
.define r89 89
.define r90 90
.define r91 91
.define r92 92
.define r93 93
.define r94 94
.define r95 95
.define r96 96
.define r97 97
.define r98 98
.define r99 99
.define r100 100
.define r101 101
.define r102 102
.define r103 103
.define r104 104
.define r105 105
.define r106 106
.define r107 107
.define r108 108
.define r109 109
.define r110 110
.define r111 111
.define r112 112
.define r113 113
.define r114 114
.define r115 115
.define r116 116
.define r117 117
.define r118 118
.define r119 119
.define r120 120
.define r121 121
.define r122 122
.define r123 123
.define r124 124
.define r125 125
.define r126 126
.define r127 127

.macro __doregname name, reg
  .ifnblank name
    name = reg
  .endif
.endmacro

.macro regnames n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19, n20, n21, n22, n23, n24, n25, n26, n27, n28, n29, n30, n31
 __doregname n0, r0
 __doregname n1, r1
 __doregname n2, r2
 __doregname n3, r3
 __doregname n4, r4
 __doregname n5, r5
 __doregname n6, r6
 __doregname n7, r7
 __doregname n8, r8
 __doregname n9, r9
 __doregname n10, r10
 __doregname n11, r11
 __doregname n12, r12
 __doregname n13, r13
 __doregname n14, r14
 __doregname n15, r15
 __doregname n16, r16
 __doregname n17, r17
 __doregname n18, r18
 __doregname n19, r19
 __doregname n20, r20
 __doregname n21, r21
 __doregname n22, r22
 __doregname n23, r23
 __doregname n24, r24
 __doregname n25, r25
 __doregname n26, r26
 __doregname n27, r27
 __doregname n28, r28
 __doregname n29, r29
 __doregname n30, r30
 __doregname n31, r31
.endmacro


;------------------
; Global Imports

.importzp zpTop
.importzp iptr
.importzp iptr_offset
.importzp rptr
.importzp pptr
.importzp cstack
.import clear_rstack
.import acheronNest
.import acheron
.importzp gptr
.importzp currentCatch
.import enableInstructionTrap
.import disableInstructionTrap
.import continueFromInstructionTrap
.import enableExceptionTrap
.import disableExceptionTrap
.import continueFromExceptionTrap
.importzp dsptr
.importzp rstackTop


;------------------
; Pseudo-instructions

.macro addi imm
 .if (imm > 255) .or (imm < -255)
   addi16 imm
 .elseif (imm < 0)
   subi8 -(imm)
 .elseif (imm <> 0)
   addi8 imm
 .endif
.endmacro

.macro addic imm
 .if (imm > 255) .or (imm < -255)
   addi16c imm
 .elseif (imm < 0)
   subi8c -(imm)
 .elseif (imm <> 0)
   addi8c imm
 .endif
.endmacro

.macro subi imm
 .if (imm > 255) .or (imm < -255)
   addi16 -(imm)
 .elseif (imm < 0)
   addi8 -(imm)
 .elseif (imm <> 0)
   subi8 imm
 .endif
.endmacro

.macro subic imm
 .if (imm > 255) .or (imm < -255)
   addi16c -(imm)
 .elseif (imm < 0)
   addi8c -(imm)
 .elseif (imm <> 0)
   subi8c imm
 .endif
.endmacro

.macro setp imm
 .if (imm > 255) .or (imm < 0)
   setp16 imm
 .elseif (imm > 0)
   setp8 imm
 .else
   clrp
 .endif
.endmacro

.macro case imm, rel8
 .if (imm >= 0) .and (imm <=255)
   case8 imm, rel8
 .else
   case16 imm, rel8
 .endif
.endmacro


;------------------
; Opcodes

opcode_dupc                 = $00
opcode_pushcs               = $01
opcode_pushcc               = $02
opcode_dropc                = $03
opcode_flipc                = $04
opcode_incp2                = $05
opcode_incp                 = $06
opcode_addi8c               = $07
opcode_addi8                = $08
opcode_addi16c              = $09
opcode_addi16               = $0a
opcode_addc                 = $0b
opcode_add                  = $0c
opcode_decp                 = $0d
opcode_decp2                = $0e
opcode_subi8c               = $0f
opcode_subi8                = $10
opcode_subc                 = $11
opcode_sub                  = $12
opcode_cmpr                 = $13
opcode_cmpi16               = $14
opcode_cmpi8                = $15
opcode_stmba                = $16
opcode_stma                 = $17
opcode_stmbi                = $18
opcode_stmi                 = $19
opcode_stmb                 = $1a
opcode_stm                  = $1b
opcode_ldmba                = $1c
opcode_ldma                 = $1d
opcode_ldmbi                = $1e
opcode_ldmi                 = $1f
opcode_ldmb                 = $20
opcode_ldm                  = $21
opcode_derefi               = $22
opcode_deref                = $23
opcode_derefbi              = $24
opcode_clrmn                = $25
opcode_clrm                 = $26
opcode_ldmr                 = $27
opcode_ldmbr                = $28
opcode_stmr                 = $29
opcode_stmbr                = $2a
opcode_decloop              = $2b
opcode_decloopi             = $2c
opcode_native               = $2d
opcode_mgrow                = $2e
opcode_grow                 = $2f
opcode_shrinkm              = $30
opcode_shrink               = $31
opcode_bswap                = $32
opcode_nswap                = $33
opcode_negate               = $34
opcode_not                  = $35
opcode_andr                 = $36
opcode_orr                  = $37
opcode_xorr                 = $38
opcode_andi                 = $39
opcode_ori                  = $3a
opcode_xori                 = $3b
opcode_tohex                = $3c
opcode_fromhex              = $3d
opcode_signx                = $3e
opcode_mul                  = $3f
opcode_mac                  = $40
opcode_div                  = $41
opcode_ldiv                 = $42
opcode_callp                = $43
opcode_jumpp                = $44
opcode_call                 = $45
opcode_jump                 = $46
opcode_retm                 = $47
opcode_ret                  = $48
opcode_calln                = $49
opcode_roll                 = $4a
opcode_shl                  = $4b
opcode_shr                  = $4c
opcode_sshr                 = $4d
opcode_addea2               = $4e
opcode_ldg                  = $4f
opcode_stg                  = $50
opcode_getgptr              = $51
opcode_catch                = $52
opcode_throw                = $53
opcode_popcatch             = $54
opcode_dsalloc              = $55
opcode_dspop                = $56
opcode_dsi                  = $57
opcode_getdsptr             = $58
opcode_derefb               = $59
opcode_ldrptr               = $5a
opcode_hibyte               = $5b
opcode_clrp                 = $5c
opcode_setp8                = $5d
opcode_lobyte               = $5e
opcode_movep                = $5f
opcode_copyr                = $60
opcode_setp16               = $61
opcode_clrmb                = $62
opcode_pushp                = $63
opcode_popp                 = $64
opcode_dropp                = $65
opcode_getsp                = $66
opcode_setsp                = $67
opcode_noop                 = $68
opcode_bneg                 = $69
opcode_bpos                 = $6a
opcode_bz                   = $6b
opcode_bnz                  = $6c
opcode_bnc                  = $6d
opcode_bc                   = $6e
opcode_ba                   = $6f
opcode_case8                = $70
opcode_case16               = $71
opcode_caser                = $72


;------------------
; Instruction Implementations

; Note that 'with' is a build-time construct that pushes itself into
; the encoding of the next assembled Acheron instruction.  It is
; not a standard instruction and generates no opcode itself.

::__with_flag .set 0
::__with_reg  .set 0

.macro with reg
  ::__with_flag .set 1
  ::__with_reg  .set (reg)
.endmacro

.macro __wbit opcode, operands
  .if ::__with_flag
    ::__with_flag .set 0
    .byte $80+(opcode), ((::__with_reg)<<1) operands
  .else
    .byte opcode operands
  .endif
.endmacro

.define dupc()                __wbit opcode_dupc      , {}
.define pushcs()              __wbit opcode_pushcs    , {}
.define pushcc()              __wbit opcode_pushcc    , {}
.define dropc()               __wbit opcode_dropc     , {}
.define flipc()               __wbit opcode_flipc     , {}
.define incp2()               __wbit opcode_incp2     , {}
.define incp()                __wbit opcode_incp      , {}
.define addi8c(imm8p)         __wbit opcode_addi8c    , {, ((imm8p)-1)}
.define addi8(imm8p)          __wbit opcode_addi8     , {, ((imm8p)-1)}
.define addi16c(imm16)        __wbit opcode_addi16c   , {, <(imm16), >(imm16)}
.define addi16(imm16)         __wbit opcode_addi16    , {, <(imm16), >(imm16)}
.define addc(rA)              __wbit opcode_addc      , {, ((rA)<<1)}
.define add(rA)               __wbit opcode_add       , {, ((rA)<<1)}
.define decp()                __wbit opcode_decp      , {}
.define decp2()               __wbit opcode_decp2     , {}
.define subi8c(imm8p)         __wbit opcode_subi8c    , {, ((imm8p)-1)}
.define subi8(imm8p)          __wbit opcode_subi8     , {, ((imm8p)-1)}
.define subc(rA)              __wbit opcode_subc      , {, ((rA)<<1)}
.define sub(rA)               __wbit opcode_sub       , {, ((rA)<<1)}
.define cmpr(rA)              __wbit opcode_cmpr      , {, ((rA)<<1)}
.define cmpi16(imm16)         __wbit opcode_cmpi16    , {, <(imm16), >(imm16)}
.define cmpi8(imm8)           __wbit opcode_cmpi8     , {, imm8}
.define stmba(imm16)          __wbit opcode_stmba     , {, <(imm16), >(imm16)}
.define stma(imm16)           __wbit opcode_stma      , {, <(imm16), >(imm16)}
.define stmbi(rA, imm8)       __wbit opcode_stmbi     , {, (imm8), ((rA)<<1)}
.define stmi(rA, imm8)        __wbit opcode_stmi      , {, (imm8), ((rA)<<1)}
.define stmb(rA)              __wbit opcode_stmb      , {, ((rA)<<1)}
.define stm(rA)               __wbit opcode_stm       , {, ((rA)<<1)}
.define ldmba(imm16)          __wbit opcode_ldmba     , {, <(imm16), >(imm16)}
.define ldma(imm16)           __wbit opcode_ldma      , {, <(imm16), >(imm16)}
.define ldmbi(rD, imm8)       __wbit opcode_ldmbi     , {, (imm8), ((rD)<<1)}
.define ldmi(rD, imm8)        __wbit opcode_ldmi      , {, (imm8), ((rD)<<1)}
.define ldmb(rD)              __wbit opcode_ldmb      , {, ((rD)<<1)}
.define ldm(rD)               __wbit opcode_ldm       , {, ((rD)<<1)}
.define derefi(imm8)          __wbit opcode_derefi    , {, imm8}
.define deref()               __wbit opcode_deref     , {}
.define derefbi(imm8)         __wbit opcode_derefbi   , {, imm8}
.define clrmn(imm8p)          __wbit opcode_clrmn     , {, <(imm8p)}
.define clrm()                __wbit opcode_clrm      , {}
.define ldmr(rD, rA)          __wbit opcode_ldmr      , {, ((rD)<<1), ((rA)<<1)}
.define ldmbr(rD, rA)         __wbit opcode_ldmbr     , {, ((rD)<<1), ((rA)<<1)}
.define stmr(rD, rA)          __wbit opcode_stmr      , {, ((rD)<<1), ((rA)<<1)}
.define stmbr(rD, rA)         __wbit opcode_stmbr     , {, ((rD)<<1), ((rA)<<1)}
.define decloop(rel8neg)      __wbit opcode_decloop   , {(* - (rel8neg))}
.define decloopi(imm8, rel8neg) __wbit opcode_decloopi  , {, imm8, (* - (rel8neg))}
.define native()              __wbit opcode_native    , {}
.define mgrow(imm8)           __wbit opcode_mgrow     , {, (-((imm8)<<1)) & $ff}
.define grow(imm8)            __wbit opcode_grow      , {, (-((imm8)<<1)) & $ff}
.define shrinkm()             __wbit opcode_shrinkm   , {}
.define shrink(imm8)          __wbit opcode_shrink    , {, ((imm8)<<1)}
.define bswap()               __wbit opcode_bswap     , {}
.define nswap()               __wbit opcode_nswap     , {}
.define negate()              __wbit opcode_negate    , {}
.define not()                 __wbit opcode_not       , {}
.define andr(rA)              __wbit opcode_andr      , {, ((rA)<<1)}
.define orr(rA)               __wbit opcode_orr       , {, ((rA)<<1)}
.define xorr(rA)              __wbit opcode_xorr      , {, ((rA)<<1)}
.define andi(imm16)           __wbit opcode_andi      , {, <(imm16), >(imm16)}
.define ori(imm16)            __wbit opcode_ori       , {, <(imm16), >(imm16)}
.define xori(imm16)           __wbit opcode_xori      , {, <(imm16), >(imm16)}
.define tohex()               __wbit opcode_tohex     , {}
.define fromhex()             __wbit opcode_fromhex   , {}
.define signx()               __wbit opcode_signx     , {}
.define mul(rA)               __wbit opcode_mul       , {, ((rA)<<1)}
.define mac(rA)               __wbit opcode_mac       , {, ((rA)<<1)}
.define div(rA)               __wbit opcode_div       , {, ((rA)<<1)}
.define ldiv(rA)              __wbit opcode_ldiv      , {, ((rA)<<1)}
.define callp()               __wbit opcode_callp     , {}
.define jumpp()               __wbit opcode_jumpp     , {}
.define call(imm16)           __wbit opcode_call      , {, <(imm16), >(imm16)}
.define jump(imm16)           __wbit opcode_jump      , {, <(imm16), >(imm16)}
.define retm()                __wbit opcode_retm      , {}
.define ret()                 __wbit opcode_ret       , {}
.define calln(imm16)          __wbit opcode_calln     , {, <(imm16), >(imm16)}
.define roll(imm8)            __wbit opcode_roll      , {, imm8}
.define shl(imm8)             __wbit opcode_shl       , {, imm8}
.define shr(imm8)             __wbit opcode_shr       , {, imm8}
.define sshr(imm8)            __wbit opcode_sshr      , {, imm8}
.define addea2(rA)            __wbit opcode_addea2    , {, ((rA)<<1)}
.define ldg(imm8)             __wbit opcode_ldg       , {, imm8}
.define stg(imm8)             __wbit opcode_stg       , {, imm8}
.define getgptr(imm8)         __wbit opcode_getgptr   , {, imm8}
.define catch(imm16)          __wbit opcode_catch     , {, <(imm16), >(imm16)}
.define throw()               __wbit opcode_throw     , {}
.define popcatch()            __wbit opcode_popcatch  , {}
.define dsalloc()             __wbit opcode_dsalloc   , {}
.define dspop()               __wbit opcode_dspop     , {}
.define dsi(imm8)             __wbit opcode_dsi       , {, imm8}
.define getdsptr()            __wbit opcode_getdsptr  , {}
.define derefb()              __wbit opcode_derefb    , {}
.define ldrptr(rA)            __wbit opcode_ldrptr    , {, ((rA)<<1)}
.define hibyte()              __wbit opcode_hibyte    , {}
.define clrp()                __wbit opcode_clrp      , {}
.define setp8(imm8)           __wbit opcode_setp8     , {, imm8}
.define lobyte()              __wbit opcode_lobyte    , {}
.define movep(rD)             __wbit opcode_movep     , {, ((rD)<<1)}
.define copyr(rA)             __wbit opcode_copyr     , {, ((rA)<<1)}
.define setp16(imm16)         __wbit opcode_setp16    , {, <(imm16), >(imm16)}
.define clrmb()               __wbit opcode_clrmb     , {}
.define pushp()               __wbit opcode_pushp     , {}
.define popp()                __wbit opcode_popp      , {}
.define dropp()               __wbit opcode_dropp     , {}
.define getsp()               __wbit opcode_getsp     , {}
.define setsp()               __wbit opcode_setsp     , {}
.define noop()                __wbit opcode_noop      , {}
.define bneg(rel8)            __wbit opcode_bneg      , {, <((rel8) - * + 1)}
.define bpos(rel8)            __wbit opcode_bpos      , {, <((rel8) - * + 1)}
.define bz(rel8)              __wbit opcode_bz        , {, <((rel8) - * + 1)}
.define bnz(rel8)             __wbit opcode_bnz       , {, <((rel8) - * + 1)}
.define bnc(rel8)             __wbit opcode_bnc       , {, <((rel8) - * + 1)}
.define bc(rel8)              __wbit opcode_bc        , {, <((rel8) - * + 1)}
.define ba(rel8)              __wbit opcode_ba        , {, <((rel8) - * + 1)}
.define case8(imm8, rel8)     __wbit opcode_case8     , {, imm8, <((rel8) - * + 1)}
.define case16(imm16, rel8)   __wbit opcode_case16    , {, <(imm16), >(imm16), <((rel8) - * + 1)}
.define caser(rA, rel8)       __wbit opcode_caser     , {, ((rA)<<1), <((rel8) - * + 1)}


; Number of allocated opcodes:  115
; Number of opcodes remaining:  13
