1 #ifdef SMPCORE_CPP
2 
op_bra()3 void SMPcore::op_bra() {
4   rd = op_readpc();
5   op_io();
6   op_io();
7   regs.pc += (int8)rd;
8 }
9 
op_branch()10 template<int flag, int value> void SMPcore::op_branch() {
11   rd = op_readpc();
12   if((bool)(regs.p & flag) != value) return;
13   op_io();
14   op_io();
15   regs.pc += (int8)rd;
16 }
17 
op_bitbranch()18 template<int mask, int value> void SMPcore::op_bitbranch() {
19   dp = op_readpc();
20   sp = op_readdp(dp);
21   rd = op_readpc();
22   op_io();
23   if((bool)(sp & mask) != value) return;
24   op_io();
25   op_io();
26   regs.pc += (int8)rd;
27 }
28 
op_cbne_dp()29 void SMPcore::op_cbne_dp() {
30   dp = op_readpc();
31   sp = op_readdp(dp);
32   rd = op_readpc();
33   op_io();
34   if(regs.a == sp) return;
35   op_io();
36   op_io();
37   regs.pc += (int8)rd;
38 }
39 
op_cbne_dpx()40 void SMPcore::op_cbne_dpx() {
41   dp = op_readpc();
42   op_io();
43   sp = op_readdp(dp + regs.x);
44   rd = op_readpc();
45   op_io();
46   if(regs.a == sp) return;
47   op_io();
48   op_io();
49   regs.pc += (int8)rd;
50 }
51 
op_dbnz_dp()52 void SMPcore::op_dbnz_dp() {
53   dp = op_readpc();
54   wr = op_readdp(dp);
55   op_writedp(dp, --wr);
56   rd = op_readpc();
57   if(wr == 0) return;
58   op_io();
59   op_io();
60   regs.pc += (int8)rd;
61 }
62 
op_dbnz_y()63 void SMPcore::op_dbnz_y() {
64   rd = op_readpc();
65   op_io();
66   regs.y--;
67   op_io();
68   if(regs.y == 0) return;
69   op_io();
70   op_io();
71   regs.pc += (int8)rd;
72 }
73 
op_jmp_addr()74 void SMPcore::op_jmp_addr() {
75   rd  = op_readpc() << 0;
76   rd |= op_readpc() << 8;
77   regs.pc = rd;
78 }
79 
op_jmp_iaddrx()80 void SMPcore::op_jmp_iaddrx() {
81   dp  = op_readpc() << 0;
82   dp |= op_readpc() << 8;
83   op_io();
84   dp += regs.x;
85   rd  = op_readaddr(dp + 0) << 0;
86   rd |= op_readaddr(dp + 1) << 8;
87   regs.pc = rd;
88 }
89 
op_call()90 void SMPcore::op_call() {
91   rd  = op_readpc() << 0;
92   rd |= op_readpc() << 8;
93   op_io();
94   op_io();
95   op_io();
96   op_writestack(regs.pc >> 8);
97   op_writestack(regs.pc >> 0);
98   regs.pc = rd;
99 }
100 
op_pcall()101 void SMPcore::op_pcall() {
102   rd = op_readpc();
103   op_io();
104   op_io();
105   op_writestack(regs.pc >> 8);
106   op_writestack(regs.pc >> 0);
107   regs.pc = 0xff00 | rd;
108 }
109 
op_tcall()110 template<int n> void SMPcore::op_tcall() {
111   dp  = 0xffde - (n << 1);
112   rd  = op_readaddr(dp + 0) << 0;
113   rd |= op_readaddr(dp + 1) << 8;
114   op_io();
115   op_io();
116   op_io();
117   op_writestack(regs.pc >> 8);
118   op_writestack(regs.pc >> 0);
119   regs.pc = rd;
120 }
121 
op_brk()122 void SMPcore::op_brk() {
123   rd  = op_readaddr(0xffde) << 0;
124   rd |= op_readaddr(0xffdf) << 8;
125   op_io();
126   op_io();
127   op_writestack(regs.pc >> 8);
128   op_writestack(regs.pc >> 0);
129   op_writestack(regs.p);
130   regs.pc = rd;
131   regs.p.b = 1;
132   regs.p.i = 0;
133 }
134 
op_ret()135 void SMPcore::op_ret() {
136   rd  = op_readstack() << 0;
137   rd |= op_readstack() << 8;
138   op_io();
139   op_io();
140   regs.pc = rd;
141 }
142 
op_reti()143 void SMPcore::op_reti() {
144   regs.p = op_readstack();
145   rd  = op_readstack() << 0;
146   rd |= op_readstack() << 8;
147   op_io();
148   op_io();
149   regs.pc = rd;
150 }
151 
152 #endif
153