Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/c68k/c68kexec.c
2 views
1
/* Copyright 2003-2004 Stephane Dallongeville
2
3
This file is part of Yabause.
4
5
Yabause is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
9
10
Yabause is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with Yabause; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
#include "../core.h"
21
#include "c68k.h"
22
23
// #define TRACE_WITH_Q68 // Define to use Q68 tracing code to trace insns
24
// (requires Q68 built in, of course)
25
26
#ifdef NEOCD_HLE
27
void cdrom_load_files(void);
28
void neogeo_cdda_control(void);
29
void neogeo_prio_switch(void);
30
void neogeo_upload(void);
31
#endif
32
33
// exception cycle table (taken from musashi core)
34
static const s32 c68k_exception_cycle_table[256] =
35
{
36
4, // 0: Reset - Initial Stack Pointer
37
4, // 1: Reset - Initial Program Counter
38
50, // 2: Bus Error
39
50, // 3: Address Error
40
34, // 4: Illegal Instruction
41
38, // 5: Divide by Zero
42
40, // 6: CHK
43
34, // 7: TRAPV
44
34, // 8: Privilege Violation
45
34, // 9: Trace
46
4, // 10:
47
4, // 11:
48
4, // 12: RESERVED
49
4, // 13: Coprocessor Protocol Violation
50
4, // 14: Format Error
51
44, // 15: Uninitialized Interrupt
52
4, // 16: RESERVED
53
4, // 17: RESERVED
54
4, // 18: RESERVED
55
4, // 19: RESERVED
56
4, // 20: RESERVED
57
4, // 21: RESERVED
58
4, // 22: RESERVED
59
4, // 23: RESERVED
60
44, // 24: Spurious Interrupt
61
44, // 25: Level 1 Interrupt Autovector
62
44, // 26: Level 2 Interrupt Autovector
63
44, // 27: Level 3 Interrupt Autovector
64
44, // 28: Level 4 Interrupt Autovector
65
44, // 29: Level 5 Interrupt Autovector
66
44, // 30: Level 6 Interrupt Autovector
67
44, // 31: Level 7 Interrupt Autovector
68
34, // 32: TRAP #0
69
34, // 33: TRAP #1
70
34, // 34: TRAP #2
71
34, // 35: TRAP #3
72
34, // 36: TRAP #4
73
34, // 37: TRAP #5
74
34, // 38: TRAP #6
75
34, // 39: TRAP #7
76
34, // 40: TRAP #8
77
34, // 41: TRAP #9
78
34, // 42: TRAP #10
79
34, // 43: TRAP #11
80
34, // 44: TRAP #12
81
34, // 45: TRAP #13
82
34, // 46: TRAP #14
83
34, // 47: TRAP #15
84
4, // 48: FP Branch or Set on Unknown Condition
85
4, // 49: FP Inexact Result
86
4, // 50: FP Divide by Zero
87
4, // 51: FP Underflow
88
4, // 52: FP Operand Error
89
4, // 53: FP Overflow
90
4, // 54: FP Signaling NAN
91
4, // 55: FP Unimplemented Data Type
92
4, // 56: MMU Configuration Error
93
4, // 57: MMU Illegal Operation Error
94
4, // 58: MMU Access Level Violation Error
95
4, // 59: RESERVED
96
4, // 60: RESERVED
97
4, // 61: RESERVED
98
4, // 62: RESERVED
99
4, // 63: RESERVED
100
// 64-255: User Defined
101
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
102
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
103
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
104
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
105
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
106
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4
107
};
108
109
// global variable
110
///////////////////
111
112
#ifndef C68K_GEN
113
114
#ifndef C68K_NO_JUMP_TABLE
115
#ifndef C68K_CONST_JUMP_TABLE
116
static void *JumpTable[0x10000];
117
#endif
118
#endif
119
120
static u32 C68k_Initialised = 0;
121
122
#endif // C68K_GEN
123
124
#ifdef NEOCD_HLE
125
extern int img_display;
126
#endif
127
128
// include macro file
129
//////////////////////
130
131
#include "c68kmac.inc"
132
133
#ifndef C68K_GEN
134
# ifdef TRACE_WITH_Q68
135
#include "../q68/q68.h"
136
static c68k_struc *TRACE_CPU;
137
static uint32_t readw(uint32_t address) {
138
return TRACE_CPU->Read_Word(address);
139
}
140
/* Make our own version of the structure to avoid the overhead of dozens of
141
* function calls every instruction */
142
static struct {
143
u32 D[8], A[8], PC, SR, USP, SSP, dummy[7];
144
void *readb, *readw, *writeb, *writew;
145
} state = {.readw = readw};
146
void TRACE(int PC,c68k_struc *CPU,int Opcode,int CCnt) {
147
static FILE *f;
148
if (!f) f = fopen("c68k.log", "w");
149
TRACE_CPU = CPU;
150
memcpy(state.D, CPU->D, 16*4);
151
state.PC = PC - 2 - CPU->BasePC;
152
state.SR = GET_SR;
153
if (f) q68_trace((Q68State *)&state, f,
154
CPU->CycleToDo - CCnt, CPU->CycleToDo);
155
}
156
# endif // TRACE_WITH_Q68
157
#endif // !C68K_GEN
158
159
// main exec function
160
//////////////////////
161
162
s32 FASTCALL C68k_Exec(c68k_struc *cpu, s32 cycle)
163
{
164
#ifndef C68K_GEN
165
#if 0
166
register c68k_struc *CPU asm ("ebx");
167
register pointer PC asm ("esi");
168
register s32 CCnt asm ("edi");
169
// register u32 Opcode asm ("edi");
170
// c68k_struc *CPU;
171
// u32 PC;
172
// s32 CCnt;
173
u32 Opcode;
174
#else
175
// register c68k_struc *CPU asm ("r10");
176
// register u32 PC asm ("r11");
177
// register s32 CCnt asm ("r12");
178
// register u32 Opcode asm ("r13");
179
c68k_struc *CPU;
180
pointer PC;
181
s32 CCnt;
182
u32 Opcode;
183
#endif
184
#endif
185
186
#ifndef C68K_GEN
187
188
#ifndef C68K_NO_JUMP_TABLE
189
#ifdef C68K_CONST_JUMP_TABLE
190
#include "c68k_ini.inc"
191
#endif
192
#else
193
C68k_Initialised = 1;
194
#endif
195
196
CPU = cpu;
197
PC = CPU->PC;
198
199
if (CPU->Status & (C68K_RUNNING | C68K_DISABLE | C68K_FAULTED))
200
{
201
#ifndef C68K_NO_JUMP_TABLE
202
#ifndef C68K_CONST_JUMP_TABLE
203
if (!C68k_Initialised) goto C68k_Init;
204
#endif
205
#endif
206
return (CPU->Status | 0x80000000);
207
}
208
209
if (cycle <= 0) return -cycle;
210
211
CPU->CycleToDo = CCnt = cycle;
212
213
#ifndef C68K_DEBUG
214
CHECK_INT
215
#else
216
{
217
s32 line, vect;
218
219
line = CPU->IRQLine;
220
221
if ((line == 7) || (line > CPU->flag_I))
222
{
223
PRE_IO
224
225
/* get vector */
226
CPU->IRQLine = 0;
227
vect = CPU->Interrupt_CallBack(line);
228
if (vect == C68K_INT_ACK_AUTOVECTOR)
229
vect = C68K_INTERRUPT_AUTOVECTOR_EX + (line & 7);
230
231
/* adjust CCnt */
232
CCnt -= c68k_exception_cycle_table[vect];
233
234
/* swap A7 and USP */
235
if (!CPU->flag_S)
236
{
237
u32 tmpSP;
238
239
tmpSP = CPU->USP;
240
CPU->USP = CPU->A[7];
241
CPU->A[7] = tmpSP;
242
}
243
244
/* push PC and SR */
245
PUSH_32_F(PC - CPU->BasePC)
246
PUSH_16_F(GET_SR)
247
248
/* adjust SR */
249
CPU->flag_S = C68K_SR_S;
250
CPU->flag_I = line;
251
252
/* fetch new PC */
253
READ_LONG_F(vect * 4, PC)
254
SET_PC(PC)
255
256
POST_IO
257
}
258
}
259
#endif
260
261
if (CPU->Status & (C68K_HALTED | C68K_WAITING)) return CPU->CycleToDo;
262
263
CPU->CycleSup = 0;
264
CPU->Status |= C68K_RUNNING;
265
266
#ifndef C68K_DEBUG
267
NEXT
268
#else
269
#ifdef C68K_NO_JUMP_TABLE
270
NEXT
271
#else
272
Opcode = FETCH_WORD;
273
PC += 2;
274
goto *JumpTable[Opcode];
275
#endif
276
#endif
277
278
#ifdef C68K_NO_JUMP_TABLE
279
SwitchTable:
280
switch(Opcode)
281
{
282
#endif
283
#include "c68k_op0.inc"
284
#include "c68k_op1.inc"
285
#include "c68k_op2.inc"
286
#include "c68k_op3.inc"
287
#include "c68k_op4.inc"
288
#include "c68k_op5.inc"
289
#include "c68k_op6.inc"
290
#include "c68k_op7.inc"
291
#include "c68k_op8.inc"
292
#include "c68k_op9.inc"
293
#include "c68k_opA.inc"
294
#include "c68k_opB.inc"
295
#include "c68k_opC.inc"
296
#include "c68k_opD.inc"
297
#include "c68k_opE.inc"
298
#include "c68k_opF.inc"
299
#ifdef C68K_NO_JUMP_TABLE
300
}
301
#endif
302
303
C68k_Exec_End:
304
CHECK_INT
305
if ((CCnt += CPU->CycleSup) > 0)
306
{
307
CPU->CycleSup = 0;
308
NEXT;
309
}
310
311
C68k_Exec_Really_End:
312
CPU->Status &= ~C68K_RUNNING;
313
CPU->PC = PC;
314
315
return (CPU->CycleToDo - CCnt);
316
317
#ifndef C68K_CONST_JUMP_TABLE
318
#ifndef C68K_NO_JUMP_TABLE
319
C68k_Init:
320
{
321
u32 i, j;
322
323
#include "c68k_ini.inc"
324
325
C68k_Initialised = 1;
326
}
327
328
return 0;
329
#endif
330
#endif
331
#else
332
return 0;
333
#endif
334
}
335
336
337