forked from nonakap/xnp2
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcpucore.h
306 lines (263 loc) · 5.9 KB
/
cpucore.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//----------------------------------------------------------------------------
//
// i286x : 80286 Engine for Pentium ver0.05
//
// Copyright by Yui/Studio Milmake 1999-2003
//
//----------------------------------------------------------------------------
#if defined(CPUCORE_IA32)
#error : not support CPUCORE_IA32
#endif
#if defined(CPUSTRUC_MEMWAIT)
#error : not support CPUSTRUC_MEMWAIT
#endif
#include "cpumem.h"
#if !defined(CPUDEBUG)
enum {
I286_MEMREADMAX = 0xa4000,
I286_MEMWRITEMAX = 0xa0000
};
#else // ダイレクトアクセス範囲を狭める
enum {
I286_MEMREADMAX = 0x00400,
I286_MEMWRITEMAX = 0x00400
};
#endif
enum {
C_FLAG = 0x0001,
P_FLAG = 0x0004,
A_FLAG = 0x0010,
Z_FLAG = 0x0040,
S_FLAG = 0x0080,
T_FLAG = 0x0100,
I_FLAG = 0x0200,
D_FLAG = 0x0400,
O_FLAG = 0x0800
};
enum {
MSW_PE = 0x0001,
MSW_MP = 0x0002,
MSW_EM = 0x0004,
MSW_TS = 0x0008
};
enum {
CPUTYPE_V30 = 0x01
};
#ifndef CPUCALL
#define CPUCALL __fastcall
#endif
#if defined(BYTESEX_LITTLE)
typedef struct {
UINT8 al;
UINT8 ah;
UINT8 cl;
UINT8 ch;
UINT8 dl;
UINT8 dh;
UINT8 bl;
UINT8 bh;
UINT8 sp_l;
UINT8 sp_h;
UINT8 bp_l;
UINT8 bp_h;
UINT8 si_l;
UINT8 si_h;
UINT8 di_l;
UINT8 di_h;
UINT8 es_l;
UINT8 es_h;
UINT8 cs_l;
UINT8 cs_h;
UINT8 ss_l;
UINT8 ss_h;
UINT8 ds_l;
UINT8 ds_h;
UINT8 flag_l;
UINT8 flag_h;
UINT8 ip_l;
UINT8 ip_h;
} I286REG8;
#else
typedef struct {
UINT8 ah;
UINT8 al;
UINT8 ch;
UINT8 cl;
UINT8 dh;
UINT8 dl;
UINT8 bh;
UINT8 bl;
UINT8 sp_h;
UINT8 sp_l;
UINT8 bp_h;
UINT8 bp_l;
UINT8 si_h;
UINT8 si_l;
UINT8 di_h;
UINT8 di_l;
UINT8 es_h;
UINT8 es_l;
UINT8 cs_h;
UINT8 cs_l;
UINT8 ss_h;
UINT8 ss_l;
UINT8 ds_h;
UINT8 ds_l;
UINT8 flag_h;
UINT8 flag_l;
UINT8 ip_h;
UINT8 ip_l;
} I286REG8;
#endif
typedef struct {
UINT16 ax;
UINT16 cx;
UINT16 dx;
UINT16 bx;
UINT16 sp;
UINT16 bp;
UINT16 si;
UINT16 di;
UINT16 es;
UINT16 cs;
UINT16 ss;
UINT16 ds;
UINT16 flag;
UINT16 ip;
} I286REG16;
typedef struct {
UINT16 limit;
UINT16 base;
UINT8 base24;
UINT8 reserved;
} I286DTR;
typedef struct {
union {
I286REG8 b;
I286REG16 w;
} r;
UINT32 es_base;
UINT32 cs_base;
UINT32 ss_base;
UINT32 ds_base;
UINT32 ss_fix;
UINT32 ds_fix;
UINT32 adrsmask; // ver0.72
UINT16 prefix;
UINT8 trap;
UINT8 resetreq; // ver0.72
UINT8 prefetchque[4];
I286DTR GDTR;
UINT16 MSW;
I286DTR IDTR;
UINT16 LDTR; // ver0.73
I286DTR LDTRC;
UINT16 TR;
I286DTR TRC;
UINT8 padding[2];
UINT8 cpu_type;
UINT8 itfbank; // ver0.72
UINT16 ram_d0;
SINT32 remainclock;
SINT32 baseclock;
UINT32 clock;
} I286STAT;
typedef struct { // for ver0.73
UINT8 *ext;
UINT32 extsize;
UINT8 *ems[4];
UINT32 repbak;
UINT32 inport;
} I286EXT;
typedef struct {
I286STAT s; // STATsaveされる奴
I286EXT e;
} I286CORE;
#ifdef __cplusplus
extern "C" {
#endif
extern I286CORE i286core;
extern const UINT8 iflags[];
void i286x_initialize(void);
void i286x_deinitialize(void);
void i286x_reset(void);
void i286x_shut(void);
void i286x_resetprefetch(void);
void i286x_setextsize(UINT32 size);
void i286x_setemm(UINT frame, UINT32 addr);
void CPUCALL i286x_interrupt(UINT8 vect);
void i286x(void);
void i286x_step(void);
void v30x(void);
void v30x_step(void);
#ifdef __cplusplus
}
#endif
// ---- macros
#define CPU_STATSAVE i286core.s
#define CPU_AX i286core.s.r.w.ax
#define CPU_BX i286core.s.r.w.bx
#define CPU_CX i286core.s.r.w.cx
#define CPU_DX i286core.s.r.w.dx
#define CPU_SI i286core.s.r.w.si
#define CPU_DI i286core.s.r.w.di
#define CPU_BP i286core.s.r.w.bp
#define CPU_SP i286core.s.r.w.sp
#define CPU_CS i286core.s.r.w.cs
#define CPU_DS i286core.s.r.w.ds
#define CPU_ES i286core.s.r.w.es
#define CPU_SS i286core.s.r.w.ss
#define CPU_IP i286core.s.r.w.ip
#define CPU_EAX i286core.s.r.w.ax
#define CPU_EBX i286core.s.r.w.bx
#define CPU_ECX i286core.s.r.w.cx
#define CPU_EDX i286core.s.r.w.dx
#define CPU_ESI i286core.s.r.w.si
#define CPU_EDI i286core.s.r.w.di
#define CPU_EBP i286core.s.r.w.bp
#define CPU_ESP i286core.s.r.w.sp
#define CPU_EIP i286core.s.r.w.ip
#define ES_BASE i286core.s.es_base
#define CS_BASE i286core.s.cs_base
#define SS_BASE i286core.s.ss_base
#define DS_BASE i286core.s.ds_base
#define CPU_AL i286core.s.r.b.al
#define CPU_BL i286core.s.r.b.bl
#define CPU_CL i286core.s.r.b.cl
#define CPU_DL i286core.s.r.b.dl
#define CPU_AH i286core.s.r.b.ah
#define CPU_BH i286core.s.r.b.bh
#define CPU_CH i286core.s.r.b.ch
#define CPU_DH i286core.s.r.b.dh
#define CPU_FLAG i286core.s.r.w.flag
#define CPU_FLAGL i286core.s.r.b.flag_l
#define CPU_REMCLOCK i286core.s.remainclock
#define CPU_BASECLOCK i286core.s.baseclock
#define CPU_CLOCK i286core.s.clock
#define CPU_ADRSMASK i286core.s.adrsmask
#define CPU_MSW i286core.s.MSW
#define CPU_RESETREQ i286core.s.resetreq
#define CPU_ITFBANK i286core.s.itfbank
#define CPU_RAM_D000 i286core.s.ram_d0
#define CPU_EXTMEM i286core.e.ext
#define CPU_EXTMEMSIZE i286core.e.extsize
#define CPU_INPADRS i286core.e.inport
#define CPU_TYPE i286core.s.cpu_type
#define CPU_isDI (!(i286core.s.r.w.flag & I_FLAG))
#define CPU_isEI (i286core.s.r.w.flag & I_FLAG)
#define CPU_CLI i286core.s.r.w.flag &= ~I_FLAG; \
i286core.s.trap = 0;
#define CPU_STI i286core.s.r.w.flag |= I_FLAG; \
i286core.s.trap = (i286core.s.r.w.flag >> 8) & 1;
#define CPU_A20EN(en) CPU_ADRSMASK = (en)?0x00ffffff:0x000fffff;
#define CPU_INITIALIZE i286x_initialize
#define CPU_DEINITIALIZE i286x_deinitialize
#define CPU_RESET i286x_reset
#define CPU_CLEARPREFETCH i286x_resetprefetch
#define CPU_INTERRUPT(vect, soft) i286x_interrupt(vect)
#define CPU_EXEC i286x
#define CPU_EXECV30 v30x
#define CPU_SHUT i286x_shut
#define CPU_SETEXTSIZE(size) i286x_setextsize((UINT32)(size) << 20)
#define CPU_SETEMM(frame, addr) i286x_setemm(frame, addr)
#define CPU_STEPEXEC i286x_step