Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/wonderswan/v30mz-private.h
2 views
1
//#define cpu_readop sys->memory.Read20
2
//cpu_readmem20
3
//#define cpu_readop_arg sys->memory.Read20
4
//cpu_readmem20
5
//#define cpu_readmem20 sys->memory.Read20
6
//#define cpu_writemem20 sys->memory.Write20
7
#define cpu_readport sys->memory.readport
8
#define cpu_writeport sys->memory.writeport
9
10
#define NEC_NMI_INT_VECTOR 2
11
12
/* parameter x = result, y = source 1, z = source 2 */
13
14
#define SetTF(x) (I.TF = (x))
15
#define SetIF(x) (I.IF = (x))
16
#define SetDF(x) (I.DF = (x))
17
18
#define SetCFB(x) (I.CarryVal = (x) & 0x100)
19
#define SetCFW(x) (I.CarryVal = (x) & 0x10000)
20
21
#define SetAF(x,y,z) (I.AuxVal = ((x) ^ ((y) ^ (z))) & 0x10)
22
23
24
25
26
#define SetSF(x) (I.SignVal = (x))
27
#define SetZF(x) (I.ZeroVal = (x))
28
#define SetPF(x) (I.ParityVal = (x))
29
30
#define SetSZPF_Byte(x) (I.SignVal=I.ZeroVal=I.ParityVal=(int8)(x))
31
#define SetSZPF_Word(x) (I.SignVal=I.ZeroVal=I.ParityVal=(int16)(x))
32
33
#define SetOFW_Add(x,y,z) (I.OverVal = ((x) ^ (y)) & ((x) ^ (z)) & 0x8000)
34
#define SetOFB_Add(x,y,z) (I.OverVal = ((x) ^ (y)) & ((x) ^ (z)) & 0x80)
35
#define SetOFW_Sub(x,y,z) (I.OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x8000)
36
#define SetOFB_Sub(x,y,z) (I.OverVal = ((z) ^ (y)) & ((z) ^ (x)) & 0x80)
37
38
#define ADDB { uint32 res=dst+src; SetCFB(res); SetOFB_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(uint8)res; }
39
#define ADDW { uint32 res=dst+src; SetCFW(res); SetOFW_Add(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(uint16)res; }
40
41
#define SUBB { uint32 res=dst-src; SetCFB(res); SetOFB_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Byte(res); dst=(uint8)res; }
42
#define SUBW { uint32 res=dst-src; SetCFW(res); SetOFW_Sub(res,src,dst); SetAF(res,src,dst); SetSZPF_Word(res); dst=(uint16)res; }
43
44
#define ORB dst|=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Byte(dst)
45
#define ORW dst|=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Word(dst)
46
47
#define ANDB dst&=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Byte(dst)
48
#define ANDW dst&=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Word(dst)
49
50
#define XORB dst^=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Byte(dst)
51
#define XORW dst^=src; I.CarryVal=I.OverVal=I.AuxVal=0; SetSZPF_Word(dst)
52
53
#define CF (I.CarryVal!=0)
54
#define SF (I.SignVal<0)
55
#define ZF (I.ZeroVal==0)
56
#define PF parity_table[(uint8)I.ParityVal]
57
#define AF (I.AuxVal!=0)
58
#define FLAG_O (I.OverVal!=0)
59
60
/************************************************************************/
61
62
#define SegBase(Seg) (I.sregs[Seg] << 4)
63
64
#define DefaultBase(Seg) ((seg_prefix && (Seg==DS0 || Seg==SS)) ? prefix_base : I.sregs[Seg] << 4)
65
66
#define GetMemB(Seg,Off) ((uint8)cpu_readmem20((DefaultBase(Seg)+(Off))))
67
#define GetMemW(Seg,Off) ((uint16) cpu_readmem20((DefaultBase(Seg)+(Off))) + (cpu_readmem20((DefaultBase(Seg)+((Off)+1)))<<8) )
68
69
#define PutMemB(Seg,Off,x) { cpu_writemem20((DefaultBase(Seg)+(Off)),(x)); }
70
#define PutMemW(Seg,Off,x) { PutMemB(Seg,Off,(x)&0xff); PutMemB(Seg,(Off)+1,(uint8)((x)>>8)); }
71
72
/* Todo: Remove these later - plus readword could overflow */
73
#define ReadByte(ea) ((uint8)cpu_readmem20((ea)))
74
#define ReadWord(ea) (cpu_readmem20((ea))+(cpu_readmem20(((ea)+1))<<8))
75
#define WriteByte(ea,val) { cpu_writemem20((ea),val); }
76
#define WriteWord(ea,val) { cpu_writemem20((ea),(uint8)(val)); cpu_writemem20(((ea)+1),(val)>>8); }
77
78
#define read_port(port) cpu_readport(port)
79
#define write_port(port,val) cpu_writeport(port,val)
80
81
#define FETCH (cpu_readop_arg((I.sregs[PS]<<4)+I.pc++))
82
#define FETCHOP (cpu_readop((I.sregs[PS]<<4)+I.pc++))
83
#define FETCHuint16(var) { var=cpu_readop_arg((((I.sregs[PS]<<4)+I.pc)))+(cpu_readop_arg((((I.sregs[PS]<<4)+I.pc+1)))<<8); I.pc+=2; }
84
#define PUSH(val) { I.regs.w[SP]-=2; WriteWord((((I.sregs[SS]<<4)+I.regs.w[SP])),val); }
85
#define POP(var) { var = ReadWord((((I.sregs[SS]<<4)+I.regs.w[SP]))); I.regs.w[SP]+=2; }
86
#define PEEK(addr) ((uint8)cpu_readop_arg(addr))
87
#define PEEKOP(addr) ((uint8)cpu_readop(addr))
88
89
#define GetModRM uint32 ModRM=cpu_readop_arg((I.sregs[PS]<<4)+I.pc++)
90
91
/* Cycle count macros:
92
CLK - cycle count is the same on all processors
93
CLKM - cycle count for reg/mem instructions
94
95
96
Prefetch & buswait time is not emulated.
97
Extra cycles for PUSH'ing or POP'ing registers to odd addresses is not emulated.
98
*/
99
100
#define _REAL_CLK(cycles) { ICount -= cycles; timestamp += cycles; }
101
#define CLK _REAL_CLK
102
//#define CLK(cycles) { _REAL_CLK(cycles); if(ws_CheckDMA(cycles)) _REAL_CLK(1); }
103
104
#define CLKM(mcount, ccount) { if(ModRM >=0xc0 ) { CLK(ccount);} else {CLK(mcount);} }
105
106
107
#define CompressFlags() (uint16)(CF | (PF << 2) | (AF << 4) | (ZF << 6) \
108
| (SF << 7) | (I.TF << 8) | (I.IF << 9) \
109
| (I.DF << 10) | (FLAG_O << 11) | (0xF002))
110
111
112
#define ExpandFlags(f) \
113
{ \
114
I.CarryVal = (f) & 1; \
115
I.ParityVal = !((f) & 4); \
116
I.AuxVal = (f) & 16; \
117
I.ZeroVal = !((f) & 64); \
118
I.SignVal = (f) & 128 ? -1 : 0; \
119
I.TF = ((f) & 256) == 256; \
120
I.IF = ((f) & 512) == 512; \
121
I.DF = ((f) & 1024) == 1024; \
122
I.OverVal = (f) & 2048; \
123
}
124
125
126
127
#define IncWordReg(Reg) \
128
unsigned tmp = (unsigned)I.regs.w[Reg]; \
129
unsigned tmp1 = tmp+1; \
130
I.OverVal = (tmp == 0x7fff); \
131
SetAF(tmp1,tmp,1); \
132
SetSZPF_Word(tmp1); \
133
I.regs.w[Reg]=tmp1
134
135
136
137
#define DecWordReg(Reg) \
138
unsigned tmp = (unsigned)I.regs.w[Reg]; \
139
unsigned tmp1 = tmp-1; \
140
I.OverVal = (tmp == 0x8000); \
141
SetAF(tmp1,tmp,1); \
142
SetSZPF_Word(tmp1); \
143
I.regs.w[Reg]=tmp1
144
145
#define JMP(flag) \
146
int tmp = (int)((int8)FETCH); \
147
if (flag) \
148
{ \
149
I.pc = (uint16)(I.pc+tmp); \
150
CLK(3); \
151
ADDBRANCHTRACE(I.sregs[PS], I.pc); \
152
return; \
153
}
154
155
#define ADJ4(param1,param2) \
156
if (AF || ((I.regs.b[AL] & 0xf) > 9)) \
157
{ \
158
uint16 tmp; \
159
tmp = I.regs.b[AL] + param1; \
160
I.regs.b[AL] = tmp; \
161
I.AuxVal = 1; \
162
I.CarryVal |= tmp & 0x100; /*if(tmp&0x100){puts("Meow"); }*//* Correct? */ \
163
} \
164
if (CF || (I.regs.b[AL] > 0x9f)) \
165
{ \
166
I.regs.b[AL] += param2; \
167
I.CarryVal = 1; \
168
} \
169
SetSZPF_Byte(I.regs.b[AL])
170
171
#define ADJB(param1,param2) \
172
if (AF || ((I.regs.b[AL] & 0xf) > 9)) \
173
{ \
174
I.regs.b[AL] += param1; \
175
I.regs.b[AH] += param2; \
176
I.AuxVal = 1; \
177
I.CarryVal = 1; \
178
} \
179
else \
180
{ \
181
I.AuxVal = 0; \
182
I.CarryVal = 0; \
183
} \
184
I.regs.b[AL] &= 0x0F
185
186
#define BIT_NOT \
187
if (tmp & (1<<tmp2)) \
188
tmp &= ~(1<<tmp2); \
189
else \
190
tmp |= (1<<tmp2)
191
192
#define XchgAWReg(Reg) \
193
uint16 tmp; \
194
tmp = I.regs.w[Reg]; \
195
I.regs.w[Reg] = I.regs.w[AW]; \
196
I.regs.w[AW] = tmp
197
198
#define ROL_uint8 I.CarryVal = dst & 0x80; dst = (dst << 1)+CF
199
#define ROL_uint16 I.CarryVal = dst & 0x8000; dst = (dst << 1)+CF
200
#define ROR_uint8 I.CarryVal = dst & 0x1; dst = (dst >> 1)+(CF<<7)
201
#define ROR_uint16 I.CarryVal = dst & 0x1; dst = (dst >> 1)+(CF<<15)
202
#define ROLC_uint8 dst = (dst << 1) + CF; SetCFB(dst)
203
#define ROLC_uint16 dst = (dst << 1) + CF; SetCFW(dst)
204
#define RORC_uint8 dst = (CF<<8)+dst; I.CarryVal = dst & 0x01; dst >>= 1
205
#define RORC_uint16 dst = (CF<<16)+dst; I.CarryVal = dst & 0x01; dst >>= 1
206
#define SHL_uint8(c) dst <<= c; SetCFB(dst); SetSZPF_Byte(dst); PutbackRMByte(ModRM,(uint8)dst)
207
#define SHL_uint16(c) dst <<= c; SetCFW(dst); SetSZPF_Word(dst); PutbackRMWord(ModRM,(uint16)dst)
208
#define SHR_uint8(c) dst >>= c-1; I.CarryVal = dst & 0x1; dst >>= 1; SetSZPF_Byte(dst); PutbackRMByte(ModRM,(uint8)dst)
209
#define SHR_uint16(c) dst >>= c-1; I.CarryVal = dst & 0x1; dst >>= 1; SetSZPF_Word(dst); PutbackRMWord(ModRM,(uint16)dst)
210
#define SHRA_uint8(c) dst = ((int8)dst) >> (c-1); I.CarryVal = dst & 0x1; dst = ((int8)((uint8)dst)) >> 1; SetSZPF_Byte(dst); PutbackRMByte(ModRM,(uint8)dst)
211
#define SHRA_uint16(c) dst = ((int16)dst) >> (c-1); I.CarryVal = dst & 0x1; dst = ((int16)((uint16)dst)) >> 1; SetSZPF_Word(dst); PutbackRMWord(ModRM,(uint16)dst)
212
213
#define DIVUB \
214
uresult = I.regs.w[AW]; \
215
uresult2 = uresult % tmp; \
216
if ((uresult /= tmp) > 0xff) { \
217
nec_interrupt(0); break; \
218
} else { \
219
I.regs.b[AL] = uresult; \
220
I.regs.b[AH] = uresult2; \
221
}
222
223
#define DIVB \
224
result = (int16)I.regs.w[AW]; \
225
result2 = result % (int16)((int8)tmp); \
226
if ((result /= (int16)((int8)tmp)) > 0xff) { \
227
nec_interrupt(0); break; \
228
} else { \
229
I.regs.b[AL] = result; \
230
I.regs.b[AH] = result2; \
231
}
232
233
#define DIVUW \
234
uresult = (((uint32)I.regs.w[DW]) << 16) | I.regs.w[AW];\
235
uresult2 = uresult % tmp; \
236
if ((uresult /= tmp) > 0xffff) { \
237
nec_interrupt(0); break; \
238
} else { \
239
I.regs.w[AW]=uresult; \
240
I.regs.w[DW]=uresult2; \
241
}
242
243
#define DIVW \
244
result = ((uint32)I.regs.w[DW] << 16) + I.regs.w[AW]; \
245
result2 = result % (int32)((int16)tmp); \
246
if ((result /= (int32)((int16)tmp)) > 0xffff) { \
247
nec_interrupt(0); break; \
248
} else { \
249
I.regs.w[AW]=result; \
250
I.regs.w[DW]=result2; \
251
}
252
253
254