1 /**************************************************************************
2 * Intel 8039 Portable Emulator *
3 * *
4 * Copyright (C) 1997 by Mirko Buffoni *
5 * Based on the original work (C) 1997 by Dan Boris, an 8048 emulator *
6 * You are not allowed to distribute this software commercially *
7 * Please, notify me, if you make any changes to this file *
8 **************************************************************************/
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include "cpuintrf.h"
14 #include "i8039.h"
15
16 #include <retro_inline.h>
17
18 #define M_RDMEM(A) I8039_RDMEM(A)
19 #define M_RDOP(A) I8039_RDOP(A)
20 #define M_RDOP_ARG(A) I8039_RDOP_ARG(A)
21 #define M_IN(A) I8039_In(A)
22 #define M_OUT(A,V) I8039_Out(A,V)
23
24 #if OLDPORTHANDLING
25 #define port_r(A) I8039_port_r(A)
26 #define port_w(A,V) I8039_port_w(A,V)
27 #define test_r(A) I8039_test_r(A)
28 #define test_w(A,V) I8039_test_w(A,V)
29 #define bus_r I8039_bus_r
30 #define bus_w(V) I8039_bus_w(V)
31 #else
32 #define port_r(A) I8039_In(I8039_p0 + A)
33 #define port_w(A,V) I8039_Out(I8039_p0 + A,V)
34 #define test_r(A) I8039_In(I8039_t0 + A)
35 #define test_w(A,V) I8039_Out(I8039_t0 + A,V)
36 #define bus_r() I8039_In(I8039_bus)
37 #define bus_w(V) I8039_Out(I8039_bus,V)
38 #endif
39
40 #define C_FLAG 0x80
41 #define A_FLAG 0x40
42 #define F_FLAG 0x20
43 #define B_FLAG 0x10
44
45 typedef struct
46 {
47 PAIR PREPC; /* previous program counter */
48 PAIR PC; /* program counter */
49 UINT8 A, SP, PSW;
50 UINT8 RAM[128];
51 UINT8 bus, f1; /* Bus data, and flag1 */
52
53 int pending_irq,irq_executing, masterClock, regPtr;
54 UINT8 t_flag, timer, timerON, countON, xirq_en, tirq_en;
55 UINT16 A11, A11ff;
56 int irq_state;
57 int (*irq_callback)(int irqline);
58 } I8039_Regs;
59
60 static I8039_Regs R;
61 int i8039_ICount;
62 static UINT8 Old_T1;
63
64 /* The opcode table now is a combination of cycle counts and function pointers */
65 typedef struct {
66 unsigned cycles;
67 void (*function) (void);
68 } s_opcode;
69
70 #define POSITIVE_EDGE_T1 (((T1-Old_T1) > 0) ? 1 : 0)
71 #define NEGATIVE_EDGE_T1 (((Old_T1-T1) > 0) ? 1 : 0)
72
73 #define M_Cy ((R.PSW & C_FLAG) >> 7)
74 #define M_Cn (!M_Cy)
75 #define M_Ay ((R.PSW & A_FLAG))
76 #define M_An (!M_Ay)
77 #define M_F0y ((R.PSW & F_FLAG))
78 #define M_F0n (!M_F0y)
79 #define M_By ((R.PSW & B_FLAG))
80 #define M_Bn (!M_By)
81
82 #define intRAM R.RAM
83 #define regPTR R.regPtr
84
85 #define R0 intRAM[regPTR ]
86 #define R1 intRAM[regPTR+1]
87 #define R2 intRAM[regPTR+2]
88 #define R3 intRAM[regPTR+3]
89 #define R4 intRAM[regPTR+4]
90 #define R5 intRAM[regPTR+5]
91 #define R6 intRAM[regPTR+6]
92 #define R7 intRAM[regPTR+7]
93
94
CLR(UINT8 flag)95 static INLINE void CLR (UINT8 flag) { R.PSW &= ~flag; }
SET(UINT8 flag)96 static INLINE void SET (UINT8 flag) { R.PSW |= flag; }
97
98
99 /* Get next opcode argument and increment program counter */
M_RDMEM_OPCODE(void)100 static INLINE unsigned M_RDMEM_OPCODE (void)
101 {
102 unsigned retval;
103 retval=M_RDOP_ARG(R.PC.w.l);
104 R.PC.w.l++;
105 return retval;
106 }
107
push(UINT8 d)108 static INLINE void push(UINT8 d)
109 {
110 intRAM[8+R.SP++] = d;
111 R.SP = R.SP & 0x0f;
112 R.PSW = R.PSW & 0xf8;
113 R.PSW = R.PSW | (R.SP >> 1);
114 }
115
pull(void)116 static INLINE UINT8 pull(void) {
117 R.SP = (R.SP + 15) & 0x0f; /* if (--R.SP < 0) R.SP = 15; */
118 R.PSW = R.PSW & 0xf8;
119 R.PSW = R.PSW | (R.SP >> 1);
120 /* regPTR = ((M_By) ? 24 : 0); regPTR should not change */
121 return intRAM[8+R.SP];
122 }
123
daa_a(void)124 static INLINE void daa_a(void)
125 {
126 if ((R.A & 0x0f) > 0x09 || (R.PSW & A_FLAG))
127 R.A += 0x06;
128 if ((R.A & 0xf0) > 0x90 || (R.PSW & C_FLAG))
129 {
130 R.A += 0x60;
131 SET(C_FLAG);
132 } else CLR(C_FLAG);
133 }
134
M_ADD(UINT8 dat)135 static INLINE void M_ADD(UINT8 dat)
136 {
137 UINT16 temp;
138
139 CLR(C_FLAG | A_FLAG);
140 if ((R.A & 0xf) + (dat & 0xf) > 0xf) SET(A_FLAG);
141 temp = R.A + dat;
142 if (temp > 0xff) SET(C_FLAG);
143 R.A = temp & 0xff;
144 }
145
M_ADDC(UINT8 dat)146 static INLINE void M_ADDC(UINT8 dat)
147 {
148 UINT16 temp;
149
150 CLR(A_FLAG);
151 if ((R.A & 0xf) + (dat & 0xf) + M_Cy > 0xf) SET(A_FLAG);
152 temp = R.A + dat + M_Cy;
153 CLR(C_FLAG);
154 if (temp > 0xff) SET(C_FLAG);
155 R.A = temp & 0xff;
156 }
157
M_CALL(UINT16 addr)158 static INLINE void M_CALL(UINT16 addr)
159 {
160 push(R.PC.b.l);
161 push((R.PC.b.h & 0x0f) | (R.PSW & 0xf0));
162 R.PC.w.l = addr;
163 #ifdef MESS
164 change_pc(addr);
165 #endif
166
167 }
168
M_XCHD(UINT8 addr)169 static INLINE void M_XCHD(UINT8 addr)
170 {
171 UINT8 dat = R.A & 0x0f;
172 R.A &= 0xf0;
173 R.A |= intRAM[addr] & 0x0f;
174 intRAM[addr] &= 0xf0;
175 intRAM[addr] |= dat;
176 }
177
178
M_ILLEGAL(void)179 static INLINE void M_ILLEGAL(void)
180 {
181 /*logerror("I8039: PC = %04x, Illegal opcode = %02x\n", R.PC.w.l-1, M_RDMEM(R.PC.w.l-1));*/
182 }
183
M_UNDEFINED(void)184 static INLINE void M_UNDEFINED(void)
185 {
186 /*logerror("I8039: PC = %04x, Unimplemented opcode = %02x\n", R.PC.w.l-1, M_RDMEM(R.PC.w.l-1));*/
187 }
188
189
190 #if OLDPORTHANDLING
I8039_port_r(UINT8 port)191 UINT8 I8039_port_r(UINT8 port) { return R.p[port & 7]; }
I8039_port_w(UINT8 port,UINT8 data)192 void I8039_port_w(UINT8 port, UINT8 data) { R.p[port & 7] = data; }
193
I8039_test_r(UINT8 port)194 UINT8 I8039_test_r(UINT8 port) { return R.t[port & 1]; }
I8039_test_w(UINT8 port,UINT8 data)195 void I8039_test_w(UINT8 port, UINT8 data) { R.t[port & 1] = data; }
196
I8039_bus_r(void)197 UINT8 I8039_bus_r(void) { return R.bus; }
I8039_bus_w(UINT8 data)198 void I8039_bus_w(UINT8 data) { R.bus = data; }
199 #endif
200
illegal(void)201 static void illegal(void) { M_ILLEGAL(); }
202
add_a_n(void)203 static void add_a_n(void) { M_ADD(M_RDMEM_OPCODE()); }
add_a_r0(void)204 static void add_a_r0(void) { M_ADD(R0); }
add_a_r1(void)205 static void add_a_r1(void) { M_ADD(R1); }
add_a_r2(void)206 static void add_a_r2(void) { M_ADD(R2); }
add_a_r3(void)207 static void add_a_r3(void) { M_ADD(R3); }
add_a_r4(void)208 static void add_a_r4(void) { M_ADD(R4); }
add_a_r5(void)209 static void add_a_r5(void) { M_ADD(R5); }
add_a_r6(void)210 static void add_a_r6(void) { M_ADD(R6); }
add_a_r7(void)211 static void add_a_r7(void) { M_ADD(R7); }
add_a_xr0(void)212 static void add_a_xr0(void) { M_ADD(intRAM[R0 & 0x7f]); }
add_a_xr1(void)213 static void add_a_xr1(void) { M_ADD(intRAM[R1 & 0x7f]); }
adc_a_n(void)214 static void adc_a_n(void) { M_ADDC(M_RDMEM_OPCODE()); }
adc_a_r0(void)215 static void adc_a_r0(void) { M_ADDC(R0); }
adc_a_r1(void)216 static void adc_a_r1(void) { M_ADDC(R1); }
adc_a_r2(void)217 static void adc_a_r2(void) { M_ADDC(R2); }
adc_a_r3(void)218 static void adc_a_r3(void) { M_ADDC(R3); }
adc_a_r4(void)219 static void adc_a_r4(void) { M_ADDC(R4); }
adc_a_r5(void)220 static void adc_a_r5(void) { M_ADDC(R5); }
adc_a_r6(void)221 static void adc_a_r6(void) { M_ADDC(R6); }
adc_a_r7(void)222 static void adc_a_r7(void) { M_ADDC(R7); }
adc_a_xr0(void)223 static void adc_a_xr0(void) { M_ADDC(intRAM[R0 & 0x7f]); }
adc_a_xr1(void)224 static void adc_a_xr1(void) { M_ADDC(intRAM[R1 & 0x7f]); }
anl_a_n(void)225 static void anl_a_n(void) { R.A &= M_RDMEM_OPCODE(); }
anl_a_r0(void)226 static void anl_a_r0(void) { R.A &= R0; }
anl_a_r1(void)227 static void anl_a_r1(void) { R.A &= R1; }
anl_a_r2(void)228 static void anl_a_r2(void) { R.A &= R2; }
anl_a_r3(void)229 static void anl_a_r3(void) { R.A &= R3; }
anl_a_r4(void)230 static void anl_a_r4(void) { R.A &= R4; }
anl_a_r5(void)231 static void anl_a_r5(void) { R.A &= R5; }
anl_a_r6(void)232 static void anl_a_r6(void) { R.A &= R6; }
anl_a_r7(void)233 static void anl_a_r7(void) { R.A &= R7; }
anl_a_xr0(void)234 static void anl_a_xr0(void) { R.A &= intRAM[R0 & 0x7f]; }
anl_a_xr1(void)235 static void anl_a_xr1(void) { R.A &= intRAM[R1 & 0x7f]; }
anl_bus_n(void)236 static void anl_bus_n(void) { bus_w( bus_r() & M_RDMEM_OPCODE() ); }
anl_p1_n(void)237 static void anl_p1_n(void) { port_w( 1, port_r(1) & M_RDMEM_OPCODE() ); }
anl_p2_n(void)238 static void anl_p2_n(void) { port_w( 2, port_r(2) & M_RDMEM_OPCODE() ); }
anld_p4_a(void)239 static void anld_p4_a(void) { port_w( 4, port_r(4) & M_RDMEM_OPCODE() ); }
anld_p5_a(void)240 static void anld_p5_a(void) { port_w( 5, port_r(5) & M_RDMEM_OPCODE() ); }
anld_p6_a(void)241 static void anld_p6_a(void) { port_w( 6, port_r(6) & M_RDMEM_OPCODE() ); }
anld_p7_a(void)242 static void anld_p7_a(void) { port_w( 7, port_r(7) & M_RDMEM_OPCODE() ); }
call(void)243 static void call(void) { UINT8 i=M_RDMEM_OPCODE(); M_CALL(i | R.A11); }
call_1(void)244 static void call_1(void) { UINT8 i=M_RDMEM_OPCODE(); M_CALL(i | 0x100 | R.A11); }
call_2(void)245 static void call_2(void) { UINT8 i=M_RDMEM_OPCODE(); M_CALL(i | 0x200 | R.A11); }
call_3(void)246 static void call_3(void) { UINT8 i=M_RDMEM_OPCODE(); M_CALL(i | 0x300 | R.A11); }
call_4(void)247 static void call_4(void) { UINT8 i=M_RDMEM_OPCODE(); M_CALL(i | 0x400 | R.A11); }
call_5(void)248 static void call_5(void) { UINT8 i=M_RDMEM_OPCODE(); M_CALL(i | 0x500 | R.A11); }
call_6(void)249 static void call_6(void) { UINT8 i=M_RDMEM_OPCODE(); M_CALL(i | 0x600 | R.A11); }
call_7(void)250 static void call_7(void) { UINT8 i=M_RDMEM_OPCODE(); M_CALL(i | 0x700 | R.A11); }
clr_a(void)251 static void clr_a(void) { R.A=0; }
clr_c(void)252 static void clr_c(void) { CLR(C_FLAG); }
clr_f0(void)253 static void clr_f0(void) { CLR(F_FLAG); }
clr_f1(void)254 static void clr_f1(void) { R.f1 = 0; }
cpl_a(void)255 static void cpl_a(void) { R.A ^= 0xff; }
cpl_c(void)256 static void cpl_c(void) { R.PSW ^= C_FLAG; }
cpl_f0(void)257 static void cpl_f0(void) { R.PSW ^= F_FLAG; }
cpl_f1(void)258 static void cpl_f1(void) { R.f1 ^= 1; }
dec_a(void)259 static void dec_a(void) { R.A--; }
dec_r0(void)260 static void dec_r0(void) { R0--; }
dec_r1(void)261 static void dec_r1(void) { R1--; }
dec_r2(void)262 static void dec_r2(void) { R2--; }
dec_r3(void)263 static void dec_r3(void) { R3--; }
dec_r4(void)264 static void dec_r4(void) { R4--; }
dec_r5(void)265 static void dec_r5(void) { R5--; }
dec_r6(void)266 static void dec_r6(void) { R6--; }
dec_r7(void)267 static void dec_r7(void) { R7--; }
dis_i(void)268 static void dis_i(void) { R.xirq_en = 0; }
dis_tcnti(void)269 static void dis_tcnti(void) { R.tirq_en = 0; }
270 #ifdef MESS
djnz_r0(void)271 static void djnz_r0(void) { UINT8 i=M_RDMEM_OPCODE(); R0--; if (R0 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); }}
djnz_r1(void)272 static void djnz_r1(void) { UINT8 i=M_RDMEM_OPCODE(); R1--; if (R1 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
djnz_r2(void)273 static void djnz_r2(void) { UINT8 i=M_RDMEM_OPCODE(); R2--; if (R2 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
djnz_r3(void)274 static void djnz_r3(void) { UINT8 i=M_RDMEM_OPCODE(); R3--; if (R3 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
djnz_r4(void)275 static void djnz_r4(void) { UINT8 i=M_RDMEM_OPCODE(); R4--; if (R4 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
djnz_r5(void)276 static void djnz_r5(void) { UINT8 i=M_RDMEM_OPCODE(); R5--; if (R5 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
djnz_r6(void)277 static void djnz_r6(void) { UINT8 i=M_RDMEM_OPCODE(); R6--; if (R6 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
djnz_r7(void)278 static void djnz_r7(void) { UINT8 i=M_RDMEM_OPCODE(); R7--; if (R7 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
279 #else
djnz_r0(void)280 static void djnz_r0(void) { UINT8 i=M_RDMEM_OPCODE(); R0--; if (R0 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; }}
djnz_r1(void)281 static void djnz_r1(void) { UINT8 i=M_RDMEM_OPCODE(); R1--; if (R1 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
djnz_r2(void)282 static void djnz_r2(void) { UINT8 i=M_RDMEM_OPCODE(); R2--; if (R2 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
djnz_r3(void)283 static void djnz_r3(void) { UINT8 i=M_RDMEM_OPCODE(); R3--; if (R3 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
djnz_r4(void)284 static void djnz_r4(void) { UINT8 i=M_RDMEM_OPCODE(); R4--; if (R4 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
djnz_r5(void)285 static void djnz_r5(void) { UINT8 i=M_RDMEM_OPCODE(); R5--; if (R5 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
djnz_r6(void)286 static void djnz_r6(void) { UINT8 i=M_RDMEM_OPCODE(); R6--; if (R6 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
djnz_r7(void)287 static void djnz_r7(void) { UINT8 i=M_RDMEM_OPCODE(); R7--; if (R7 != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
288 #endif
en_i(void)289 static void en_i(void) { R.xirq_en = 1; if (R.irq_state != CLEAR_LINE) R.pending_irq |= I8039_EXT_INT; }
en_tcnti(void)290 static void en_tcnti(void) { R.tirq_en = 1; }
ento_clk(void)291 static void ento_clk(void) { M_UNDEFINED(); }
in_a_p1(void)292 static void in_a_p1(void) { R.A = port_r(1); }
in_a_p2(void)293 static void in_a_p2(void) { R.A = port_r(2); }
ins_a_bus(void)294 static void ins_a_bus(void) { R.A = bus_r(); }
inc_a(void)295 static void inc_a(void) { R.A++; }
inc_r0(void)296 static void inc_r0(void) { R0++; }
inc_r1(void)297 static void inc_r1(void) { R1++; }
inc_r2(void)298 static void inc_r2(void) { R2++; }
inc_r3(void)299 static void inc_r3(void) { R3++; }
inc_r4(void)300 static void inc_r4(void) { R4++; }
inc_r5(void)301 static void inc_r5(void) { R5++; }
inc_r6(void)302 static void inc_r6(void) { R6++; }
inc_r7(void)303 static void inc_r7(void) { R7++; }
inc_xr0(void)304 static void inc_xr0(void) { intRAM[R0 & 0x7f]++; }
inc_xr1(void)305 static void inc_xr1(void) { intRAM[R1 & 0x7f]++; }
306
307 /* static void jmp(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | R.A11; }
308 */
309
jmp(void)310 static void jmp(void)
311 {
312 UINT8 i=M_RDOP(R.PC.w.l);
313 UINT16 oldpc,newpc;
314
315 oldpc = R.PC.w.l-1;
316 R.PC.w.l = i | R.A11;
317 #ifdef MESS
318 change_pc(R.PC.w.l);
319 #endif
320 newpc = R.PC.w.l;
321 if (newpc == oldpc) { if (i8039_ICount > 0) i8039_ICount = 0; } /* speed up busy loop */
322 else if (newpc == oldpc-1 && M_RDOP(newpc) == 0x00) /* NOP - Gyruss */
323 { if (i8039_ICount > 0) i8039_ICount = 0; }
324 }
325
326 #ifdef MESS
jmp_1(void)327 static void jmp_1(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x100 | R.A11; change_pc(R.PC.w.l); }
jmp_2(void)328 static void jmp_2(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x200 | R.A11; change_pc(R.PC.w.l); }
jmp_3(void)329 static void jmp_3(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x300 | R.A11; change_pc(R.PC.w.l); }
jmp_4(void)330 static void jmp_4(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x400 | R.A11; change_pc(R.PC.w.l); }
jmp_5(void)331 static void jmp_5(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x500 | R.A11; change_pc(R.PC.w.l); }
jmp_6(void)332 static void jmp_6(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x600 | R.A11; change_pc(R.PC.w.l); }
jmp_7(void)333 static void jmp_7(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x700 | R.A11; change_pc(R.PC.w.l); }
jmpp_xa(void)334 static void jmpp_xa(void) { UINT16 addr = (R.PC.w.l & 0xf00) | R.A; R.PC.w.l = (R.PC.w.l & 0xf00) | M_RDMEM(addr); change_pc(R.PC.w.l); }
jb_0(void)335 static void jb_0(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x01) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jb_1(void)336 static void jb_1(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x02) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jb_2(void)337 static void jb_2(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x04) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jb_3(void)338 static void jb_3(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x08) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jb_4(void)339 static void jb_4(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x10) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jb_5(void)340 static void jb_5(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x20) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jb_6(void)341 static void jb_6(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x40) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jb_7(void)342 static void jb_7(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x80) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jf0(void)343 static void jf0(void) { UINT8 i=M_RDMEM_OPCODE(); if (M_F0y) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jf_1(void)344 static void jf_1(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.f1) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jnc(void)345 static void jnc(void) { UINT8 i=M_RDMEM_OPCODE(); if (M_Cn) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jc(void)346 static void jc(void) { UINT8 i=M_RDMEM_OPCODE(); if (M_Cy) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jni(void)347 static void jni(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.irq_state != CLEAR_LINE) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jnt_0(void)348 static void jnt_0(void) { UINT8 i=M_RDMEM_OPCODE(); if (!test_r(0)) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jt_0(void)349 static void jt_0(void) { UINT8 i=M_RDMEM_OPCODE(); if (test_r(0)) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jnt_1(void)350 static void jnt_1(void) { UINT8 i=M_RDMEM_OPCODE(); if (!test_r(1)) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jt_1(void)351 static void jt_1(void) { UINT8 i=M_RDMEM_OPCODE(); if (test_r(1)) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jnz(void)352 static void jnz(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jz(void)353 static void jz(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A == 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); } }
jtf(void)354 static void jtf(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.t_flag) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; change_pc(R.PC.w.l); R.t_flag = 0; } }
355 #else
jmp_1(void)356 static void jmp_1(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x100 | R.A11; }
jmp_2(void)357 static void jmp_2(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x200 | R.A11; }
jmp_3(void)358 static void jmp_3(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x300 | R.A11; }
jmp_4(void)359 static void jmp_4(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x400 | R.A11; }
jmp_5(void)360 static void jmp_5(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x500 | R.A11; }
jmp_6(void)361 static void jmp_6(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x600 | R.A11; }
jmp_7(void)362 static void jmp_7(void) { UINT8 i=M_RDOP(R.PC.w.l); R.PC.w.l = i | 0x700 | R.A11; }
jmpp_xa(void)363 static void jmpp_xa(void) { UINT16 addr = (R.PC.w.l & 0xf00) | R.A; R.PC.w.l = (R.PC.w.l & 0xf00) | M_RDMEM(addr); }
jb_0(void)364 static void jb_0(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x01) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jb_1(void)365 static void jb_1(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x02) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jb_2(void)366 static void jb_2(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x04) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jb_3(void)367 static void jb_3(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x08) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jb_4(void)368 static void jb_4(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x10) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jb_5(void)369 static void jb_5(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x20) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jb_6(void)370 static void jb_6(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x40) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jb_7(void)371 static void jb_7(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A & 0x80) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jf0(void)372 static void jf0(void) { UINT8 i=M_RDMEM_OPCODE(); if (M_F0y) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jf_1(void)373 static void jf_1(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.f1) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jnc(void)374 static void jnc(void) { UINT8 i=M_RDMEM_OPCODE(); if (M_Cn) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jc(void)375 static void jc(void) { UINT8 i=M_RDMEM_OPCODE(); if (M_Cy) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jni(void)376 static void jni(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.irq_state != CLEAR_LINE) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jnt_0(void)377 static void jnt_0(void) { UINT8 i=M_RDMEM_OPCODE(); if (!test_r(0)) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jt_0(void)378 static void jt_0(void) { UINT8 i=M_RDMEM_OPCODE(); if (test_r(0)) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jnt_1(void)379 static void jnt_1(void) { UINT8 i=M_RDMEM_OPCODE(); if (!test_r(1)) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jt_1(void)380 static void jt_1(void) { UINT8 i=M_RDMEM_OPCODE(); if (test_r(1)) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jnz(void)381 static void jnz(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A != 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jz(void)382 static void jz(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.A == 0) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; } }
jtf(void)383 static void jtf(void) { UINT8 i=M_RDMEM_OPCODE(); if (R.t_flag) { R.PC.w.l = (R.PC.w.l & 0xf00) | i; R.t_flag = 0; } }
384 #endif
385
mov_a_n(void)386 static void mov_a_n(void) { R.A = M_RDMEM_OPCODE(); }
mov_a_r0(void)387 static void mov_a_r0(void) { R.A = R0; }
mov_a_r1(void)388 static void mov_a_r1(void) { R.A = R1; }
mov_a_r2(void)389 static void mov_a_r2(void) { R.A = R2; }
mov_a_r3(void)390 static void mov_a_r3(void) { R.A = R3; }
mov_a_r4(void)391 static void mov_a_r4(void) { R.A = R4; }
mov_a_r5(void)392 static void mov_a_r5(void) { R.A = R5; }
mov_a_r6(void)393 static void mov_a_r6(void) { R.A = R6; }
mov_a_r7(void)394 static void mov_a_r7(void) { R.A = R7; }
mov_a_psw(void)395 static void mov_a_psw(void) { R.A = R.PSW; }
mov_a_xr0(void)396 static void mov_a_xr0(void) { R.A = intRAM[R0 & 0x7f]; }
mov_a_xr1(void)397 static void mov_a_xr1(void) { R.A = intRAM[R1 & 0x7f]; }
mov_r0_a(void)398 static void mov_r0_a(void) { R0 = R.A; }
mov_r1_a(void)399 static void mov_r1_a(void) { R1 = R.A; }
mov_r2_a(void)400 static void mov_r2_a(void) { R2 = R.A; }
mov_r3_a(void)401 static void mov_r3_a(void) { R3 = R.A; }
mov_r4_a(void)402 static void mov_r4_a(void) { R4 = R.A; }
mov_r5_a(void)403 static void mov_r5_a(void) { R5 = R.A; }
mov_r6_a(void)404 static void mov_r6_a(void) { R6 = R.A; }
mov_r7_a(void)405 static void mov_r7_a(void) { R7 = R.A; }
mov_psw_a(void)406 static void mov_psw_a(void) { R.PSW = R.A; regPTR = ((M_By) ? 24 : 0); R.SP = (R.PSW & 7) << 1; }
mov_r0_n(void)407 static void mov_r0_n(void) { R0 = M_RDMEM_OPCODE(); }
mov_r1_n(void)408 static void mov_r1_n(void) { R1 = M_RDMEM_OPCODE(); }
mov_r2_n(void)409 static void mov_r2_n(void) { R2 = M_RDMEM_OPCODE(); }
mov_r3_n(void)410 static void mov_r3_n(void) { R3 = M_RDMEM_OPCODE(); }
mov_r4_n(void)411 static void mov_r4_n(void) { R4 = M_RDMEM_OPCODE(); }
mov_r5_n(void)412 static void mov_r5_n(void) { R5 = M_RDMEM_OPCODE(); }
mov_r6_n(void)413 static void mov_r6_n(void) { R6 = M_RDMEM_OPCODE(); }
mov_r7_n(void)414 static void mov_r7_n(void) { R7 = M_RDMEM_OPCODE(); }
mov_a_t(void)415 static void mov_a_t(void) { R.A = R.timer; }
mov_t_a(void)416 static void mov_t_a(void) { R.timer = R.A; }
mov_xr0_a(void)417 static void mov_xr0_a(void) { intRAM[R0 & 0x7f] = R.A; }
mov_xr1_a(void)418 static void mov_xr1_a(void) { intRAM[R1 & 0x7f] = R.A; }
mov_xr0_n(void)419 static void mov_xr0_n(void) { intRAM[R0 & 0x7f] = M_RDMEM_OPCODE(); }
mov_xr1_n(void)420 static void mov_xr1_n(void) { intRAM[R1 & 0x7f] = M_RDMEM_OPCODE(); }
movd_a_p4(void)421 static void movd_a_p4(void) { R.A = port_r(4); }
movd_a_p5(void)422 static void movd_a_p5(void) { R.A = port_r(5); }
movd_a_p6(void)423 static void movd_a_p6(void) { R.A = port_r(6); }
movd_a_p7(void)424 static void movd_a_p7(void) { R.A = port_r(7); }
movd_p4_a(void)425 static void movd_p4_a(void) { port_w(4, R.A); }
movd_p5_a(void)426 static void movd_p5_a(void) { port_w(5, R.A); }
movd_p6_a(void)427 static void movd_p6_a(void) { port_w(6, R.A); }
movd_p7_a(void)428 static void movd_p7_a(void) { port_w(7, R.A); }
movp_a_xa(void)429 static void movp_a_xa(void) { R.A = M_RDMEM((R.PC.w.l & 0x0f00) | R.A); }
movp3_a_xa(void)430 static void movp3_a_xa(void) { R.A = M_RDMEM(0x300 | R.A); }
movx_a_xr0(void)431 static void movx_a_xr0(void) { R.A = M_IN(R0); }
movx_a_xr1(void)432 static void movx_a_xr1(void) { R.A = M_IN(R1); }
movx_xr0_a(void)433 static void movx_xr0_a(void) { M_OUT(R0, R.A); }
movx_xr1_a(void)434 static void movx_xr1_a(void) { M_OUT(R1, R.A); }
nop(void)435 static void nop(void) { }
orl_a_n(void)436 static void orl_a_n(void) { R.A |= M_RDMEM_OPCODE(); }
orl_a_r0(void)437 static void orl_a_r0(void) { R.A |= R0; }
orl_a_r1(void)438 static void orl_a_r1(void) { R.A |= R1; }
orl_a_r2(void)439 static void orl_a_r2(void) { R.A |= R2; }
orl_a_r3(void)440 static void orl_a_r3(void) { R.A |= R3; }
orl_a_r4(void)441 static void orl_a_r4(void) { R.A |= R4; }
orl_a_r5(void)442 static void orl_a_r5(void) { R.A |= R5; }
orl_a_r6(void)443 static void orl_a_r6(void) { R.A |= R6; }
orl_a_r7(void)444 static void orl_a_r7(void) { R.A |= R7; }
orl_a_xr0(void)445 static void orl_a_xr0(void) { R.A |= intRAM[R0 & 0x7f]; }
orl_a_xr1(void)446 static void orl_a_xr1(void) { R.A |= intRAM[R1 & 0x7f]; }
orl_bus_n(void)447 static void orl_bus_n(void) { bus_w( bus_r() | M_RDMEM_OPCODE() ); }
orl_p1_n(void)448 static void orl_p1_n(void) { port_w(1, port_r(1) | M_RDMEM_OPCODE() ); }
orl_p2_n(void)449 static void orl_p2_n(void) { port_w(2, port_r(2) | M_RDMEM_OPCODE() ); }
orld_p4_a(void)450 static void orld_p4_a(void) { port_w(4, port_r(4) | R.A ); }
orld_p5_a(void)451 static void orld_p5_a(void) { port_w(5, port_r(5) | R.A ); }
orld_p6_a(void)452 static void orld_p6_a(void) { port_w(6, port_r(6) | R.A ); }
orld_p7_a(void)453 static void orld_p7_a(void) { port_w(7, port_r(7) | R.A ); }
outl_bus_a(void)454 static void outl_bus_a(void) { bus_w(R.A); }
outl_p1_a(void)455 static void outl_p1_a(void) { port_w(1, R.A ); }
outl_p2_a(void)456 static void outl_p2_a(void) { port_w(2, R.A ); }
457 #ifdef MESS
ret(void)458 static void ret(void) { R.PC.w.l = ((pull() & 0x0f) << 8); R.PC.w.l |= pull(); change_pc(R.PC.w.l); }
459 #else
ret(void)460 static void ret(void) { R.PC.w.l = ((pull() & 0x0f) << 8); R.PC.w.l |= pull(); }
461 #endif
462
retr(void)463 static void retr(void)
464 {
465 UINT8 i=pull();
466 R.PC.w.l = ((i & 0x0f) << 8) | pull();
467 #ifdef MESS
468 change_pc(R.PC.w.l);
469 #endif
470 R.irq_executing = I8039_IGNORE_INT;
471 // R.A11 = R.A11ff; /* NS990113 */
472 R.PSW = (R.PSW & 0x0f) | (i & 0xf0); /* Stack is already changed by pull */
473 regPTR = ((M_By) ? 24 : 0);
474 }
rl_a(void)475 static void rl_a(void) { UINT8 i=R.A & 0x80; R.A <<= 1; if (i) R.A |= 0x01; else R.A &= 0xfe; }
476 /* NS990113 */
rlc_a(void)477 static void rlc_a(void) { UINT8 i=M_Cy; if (R.A & 0x80) SET(C_FLAG); else CLR(C_FLAG); R.A <<= 1; if (i) R.A |= 0x01; else R.A &= 0xfe; }
rr_a(void)478 static void rr_a(void) { UINT8 i=R.A & 1; R.A >>= 1; if (i) R.A |= 0x80; else R.A &= 0x7f; }
479 /* NS990113 */
rrc_a(void)480 static void rrc_a(void) { UINT8 i=M_Cy; if (R.A & 1) SET(C_FLAG); else CLR(C_FLAG); R.A >>= 1; if (i) R.A |= 0x80; else R.A &= 0x7f; }
sel_mb0(void)481 static void sel_mb0(void) { R.A11 = 0; R.A11ff = 0; }
sel_mb1(void)482 static void sel_mb1(void) { R.A11ff = 0x800; if (R.irq_executing == I8039_IGNORE_INT) R.A11 = 0x800; }
sel_rb0(void)483 static void sel_rb0(void) { CLR(B_FLAG); regPTR = 0; }
sel_rb1(void)484 static void sel_rb1(void) { SET(B_FLAG); regPTR = 24; }
stop_tcnt(void)485 static void stop_tcnt(void) { R.timerON = R.countON = 0; }
strt_cnt(void)486 static void strt_cnt(void) { R.countON = 1; Old_T1 = test_r(1); } /* NS990113 */
strt_t(void)487 static void strt_t(void) { R.timerON = 1; R.masterClock = 0; } /* NS990113 */
swap_a(void)488 static void swap_a(void) { UINT8 i=R.A >> 4; R.A <<= 4; R.A |= i; }
xch_a_r0(void)489 static void xch_a_r0(void) { UINT8 i=R.A; R.A=R0; R0=i; }
xch_a_r1(void)490 static void xch_a_r1(void) { UINT8 i=R.A; R.A=R1; R1=i; }
xch_a_r2(void)491 static void xch_a_r2(void) { UINT8 i=R.A; R.A=R2; R2=i; }
xch_a_r3(void)492 static void xch_a_r3(void) { UINT8 i=R.A; R.A=R3; R3=i; }
xch_a_r4(void)493 static void xch_a_r4(void) { UINT8 i=R.A; R.A=R4; R4=i; }
xch_a_r5(void)494 static void xch_a_r5(void) { UINT8 i=R.A; R.A=R5; R5=i; }
xch_a_r6(void)495 static void xch_a_r6(void) { UINT8 i=R.A; R.A=R6; R6=i; }
xch_a_r7(void)496 static void xch_a_r7(void) { UINT8 i=R.A; R.A=R7; R7=i; }
xch_a_xr0(void)497 static void xch_a_xr0(void) { UINT8 i=R.A; R.A=intRAM[R0 & 0x7f]; intRAM[R0 & 0x7f]=i; }
xch_a_xr1(void)498 static void xch_a_xr1(void) { UINT8 i=R.A; R.A=intRAM[R1 & 0x7f]; intRAM[R1 & 0x7f]=i; }
xchd_a_xr0(void)499 static void xchd_a_xr0(void) { M_XCHD(R0 & 0x7f); }
xchd_a_xr1(void)500 static void xchd_a_xr1(void) { M_XCHD(R1 & 0x7f); }
xrl_a_n(void)501 static void xrl_a_n(void) { R.A ^= M_RDMEM_OPCODE(); }
xrl_a_r0(void)502 static void xrl_a_r0(void) { R.A ^= R0; }
xrl_a_r1(void)503