1 all numbers are int16_t
11 if argX is 255, then we have 'immediate' 2-byte value
15 bits 6-7: # of operands (0-3)
16 bits 0-5: opcode (0-31)
19 255: immediate value, else:
20 bits 0-6: variable number
21 bit 7: if set, use global
23 'immediate' for storing: ignore
25 all jumps are absolute offsets (in bytes)
27 spriteid: bit 7 != 0: right (have any meaning only for banks 84 and 90)
31 ; no args: op1=pop, op0=pop; push result
32 ; 1 op: op0=pop, op1=arg0; push result
33 ; op0, op1: op0 = op0 MATH op1
34 ; op0, op1, op2: op2 = op0 MATH op1
46 ; no args: pc=pop, vi1=pop, vi0=pop
47 ; 1 arg: pc=arg0, vi1=pop, vi0=pop
48 ; 2 args: pc=arg0, vi0=pop, vi1=arg0
49 ; 3 args: pc=arg0, vi0=arg1, vi1=arg1
58 ; no args: pc=pop (ret, hehe)
65 VM_BSR ; 'call'; use JMP w/o args to return (asm understands RET mnemonics)
68 VM_BRK ; 'break' until the next frame
71 VM_END ; stop thread and destroy object
75 ; 1 arg: pc=arg0; push tid
76 ; 2 args: pc=arg0; [arg1]=tid (literals ignored)
77 VM_NEW ; spawn thread, fatal error if can't spawn
80 ; no args: varid=pop, value=pop; varid<0: set global (note that you can't set global #0 this way)
81 ; 1 arg: value=pop, varid=arg0 (literals ignored)
82 ; 2 args: varid=arg0 (literals ignored), value=arg1
83 ; 3 args: varid=arg0 (literals ignored), value=arg1, destthreadid=arg2 -- set thread local var
87 ; no args: varid=pop, tid=pop, push result
88 ; 1 arg: tid=pop, varid=arg0, push result
89 ; 2 args: tid=arg0, varid=arg1, push result
90 ; 3 args: tid=arg0, varid=arg1, dest=arg2 (literals ignored)
91 VM_GET ; get thread local var
94 VM_PSH ; 1-3 args; no args: DUP
95 VM_POP ; no args: drop one item; numeric arg: drop*num, var: pop to var; can have 0-3 args
96 VM_SWP ; 0 args: swap 2 top stack items; 1 arg: swap stack top and arg; 2 args: swap 'em
97 VM_PCK ; 'pick', first arg: number (0: top); 2nd arg: dest (push if no 2nd var)
98 VM_ROL ; remove nth item from stack (and possibly place to var)/push to stack (no 2nd arg)
99 VM_DPT ; get stack depth (optional arg: var to store; else: push)
101 ; VM_POP: one arg, and it's literal number, and number<0: alloc stack space, fill it with 0
104 VM_TID ; get current thread id (destarg or to stack)
105 VM_KIL ; kill thread (arg: tid)
106 VM_SUS ; suspend thread (arg: tid)
107 VM_RES ; resume (arg: tid)
108 VM_STA ; get thread state (arg1: tid; arg2: dvar; no: push); -1: invalid tid; 0: running; 1: suspended
111 ; no args: addr=pop, push result
112 ; 1 arg: addr=arg0, push result
113 ; 2-3 args: addr=arg0, destvar=arg1
114 VM_RXC ; read byte from code area
115 ; no args: byte=pop, addr=pop
116 ; 1 arg: byte=pop, addr=arg0
117 ; 2-3 args: addr=arg0, byte=arg1
118 VM_WXC ; write byte to code area
121 ; no args: simple 'ret'
122 ; 1 arg: FATAL ERROR (was: # of locals to pop)
123 ; 2 args: # of locals to pop, # of arguments to pop
124 ; 3 args: # of locals to pop, # of arguments to pop, retvalue (taken before all pops, pushes after returning)
129 ; no args: arguments on stack, fid
134 ; working with map: get/set foreground/background
136 ; no args: y=pop, x=pop, push result
137 ; 1 arg: it's destvar
139 ; 3 args: x, y, destvar
140 VM_MGF ; get foreground tile
141 VM_MGB ; get background tile
143 ; no args: tile=pop, y=pop, x=pop
144 ; 1 arg: tile, y=pop, x=pop
145 ; 2 args: tile=pop, x, y
147 VM_MSF ; set foreground tile
148 VM_MSB ; set background tile
151 thread 0 is 'main' thread: title, professor, etc
155 [vname] -- thread local, global or stack local
156 [inum] -- thread local
158 [.inum] -- stack index (<0: push order; >=0: from stack bottom)
160 [@retval] -- proc return value
163 [e]const: name = number