Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/c68k/c68k.h
2 views
1
/* Copyright 2003-2004 Stephane Dallongeville
2
Copyright 2004 Theo Berkau
3
4
This file is part of Yabause.
5
6
Yabause is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
11
Yabause is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with Yabause; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
/*********************************************************************************
22
* C68K.H :
23
*
24
* C68K include file
25
*
26
********************************************************************************/
27
28
#ifndef _C68K_H_
29
#define _C68K_H_
30
31
#ifdef __cplusplus
32
extern "C" {
33
#endif
34
35
#include "../core.h"
36
37
// setting
38
///////////
39
40
//#define NEOCD_HLE
41
42
//#define C68K_GEN
43
#define C68K_BYTE_SWAP_OPT
44
45
#ifdef WORDS_BIGENDIAN
46
#define C68K_BIG_ENDIAN
47
#endif
48
49
#ifdef C68K_BIG_ENDIAN
50
#define BYTE_OFF 3
51
#define WORD_OFF 1
52
#else
53
#define BYTE_OFF 0
54
#define WORD_OFF 0
55
#endif
56
57
//#define C68K_NO_JUMP_TABLE
58
//#define C68K_DEBUG
59
#define C68K_TAS_CAN_SET_MEMORY
60
//#define C68K_CONST_JUMP_TABLE
61
//#define C68K_AUTOVECTOR_CALLBACK
62
63
// 68K core types definitions
64
//////////////////////////////
65
66
#define C68K_FETCH_BITS 8 // [4-12] default = 8
67
#define C68K_ADR_BITS 24
68
69
#define C68K_FETCH_SFT (C68K_ADR_BITS - C68K_FETCH_BITS)
70
#define C68K_FETCH_BANK (1 << C68K_FETCH_BITS)
71
#define C68K_FETCH_MASK (C68K_FETCH_BANK - 1)
72
73
#define C68K_SR_C_SFT 8
74
#define C68K_SR_V_SFT 7
75
#define C68K_SR_Z_SFT 0
76
#define C68K_SR_N_SFT 7
77
#define C68K_SR_X_SFT 8
78
79
#define C68K_SR_S_SFT 13
80
81
#define C68K_SR_C (1 << C68K_SR_C_SFT)
82
#define C68K_SR_V (1 << C68K_SR_V_SFT)
83
#define C68K_SR_Z 0
84
#define C68K_SR_N (1 << C68K_SR_N_SFT)
85
#define C68K_SR_X (1 << C68K_SR_X_SFT)
86
87
#define C68K_SR_S (1 << C68K_SR_S_SFT)
88
89
#define C68K_CCR_MASK 0x1F
90
#define C68K_SR_MASK (0x2700 | C68K_CCR_MASK)
91
92
// exception defines taken from musashi core
93
#define C68K_RESET_EX 1
94
#define C68K_BUS_ERROR_EX 2
95
#define C68K_ADDRESS_ERROR_EX 3
96
#define C68K_ILLEGAL_INSTRUCTION_EX 4
97
#define C68K_ZERO_DIVIDE_EX 5
98
#define C68K_CHK_EX 6
99
#define C68K_TRAPV_EX 7
100
#define C68K_PRIVILEGE_VIOLATION_EX 8
101
#define C68K_TRACE_EX 9
102
#define C68K_1010_EX 10
103
#define C68K_1111_EX 11
104
#define C68K_FORMAT_ERROR_EX 14
105
#define C68K_UNINITIALIZED_INTERRUPT_EX 15
106
#define C68K_SPURIOUS_INTERRUPT_EX 24
107
#define C68K_INTERRUPT_AUTOVECTOR_EX 24
108
#define C68K_TRAP_BASE_EX 32
109
110
#define C68K_INT_ACK_AUTOVECTOR -1
111
112
#define C68K_RUNNING 0x01
113
#define C68K_HALTED 0x02
114
#define C68K_WAITING 0x04
115
#define C68K_DISABLE 0x10
116
#define C68K_FAULTED 0x40
117
118
typedef u32 FASTCALL C68K_READ(const u32 adr);
119
typedef void FASTCALL C68K_WRITE(const u32 adr, u32 data);
120
121
typedef s32 FASTCALL C68K_INT_CALLBACK(s32 level);
122
typedef void FASTCALL C68K_RESET_CALLBACK(void);
123
124
typedef struct {
125
u32 D[8]; // 32 bytes aligned
126
u32 A[8]; // 16 bytes aligned
127
128
u32 flag_C; // 32 bytes aligned
129
u32 flag_V;
130
u32 flag_notZ;
131
u32 flag_N;
132
133
u32 flag_X; // 16 bytes aligned
134
u32 flag_I;
135
u32 flag_S;
136
137
u32 USP;
138
139
pointer PC; // 32 bytes aligned
140
pointer BasePC;
141
u32 Status;
142
s32 IRQLine;
143
144
s32 CycleToDo; // 16 bytes aligned
145
s32 CycleIO;
146
s32 CycleSup;
147
u32 dirty1;
148
149
C68K_READ *Read_Byte; // 32 bytes aligned
150
C68K_READ *Read_Word;
151
152
C68K_WRITE *Write_Byte;
153
C68K_WRITE *Write_Word;
154
155
C68K_INT_CALLBACK *Interrupt_CallBack; // 16 bytes aligned
156
C68K_RESET_CALLBACK *Reset_CallBack;
157
158
pointer Fetch[C68K_FETCH_BANK]; // 32 bytes aligned
159
} c68k_struc;
160
161
162
// 68K core var declaration
163
////////////////////////////
164
165
extern c68k_struc C68K;
166
167
168
// 68K core function declaration
169
/////////////////////////////////
170
171
void C68k_Init(c68k_struc *cpu, C68K_INT_CALLBACK *int_cb);
172
173
s32 FASTCALL C68k_Reset(c68k_struc *cpu);
174
175
// if < 0 --> error (cpu state returned)
176
// if >= 0 --> number of extras cycles done
177
s32 FASTCALL C68k_Exec(c68k_struc *cpu, s32 cycle);
178
179
void FASTCALL C68k_Set_IRQ(c68k_struc *cpu, s32 level);
180
181
s32 FASTCALL C68k_Get_CycleToDo(c68k_struc *cpu);
182
s32 FASTCALL C68k_Get_CycleRemaining(c68k_struc *cpu);
183
s32 FASTCALL C68k_Get_CycleDone(c68k_struc *cpu);
184
void FASTCALL C68k_Release_Cycle(c68k_struc *cpu);
185
void FASTCALL C68k_Add_Cycle(c68k_struc *cpu, s32 cycle);
186
187
void C68k_Set_Fetch(c68k_struc *cpu, u32 low_adr, u32 high_adr, pointer fetch_adr);
188
189
void C68k_Set_ReadB(c68k_struc *cpu, C68K_READ *Func);
190
void C68k_Set_ReadW(c68k_struc *cpu, C68K_READ *Func);
191
void C68k_Set_WriteB(c68k_struc *cpu, C68K_WRITE *Func);
192
void C68k_Set_WriteW(c68k_struc *cpu, C68K_WRITE *Func);
193
194
u32 C68k_Get_DReg(c68k_struc *cpu, u32 num);
195
u32 C68k_Get_AReg(c68k_struc *cpu, u32 num);
196
u32 C68k_Get_PC(c68k_struc *cpu);
197
u32 C68k_Get_SR(c68k_struc *cpu);
198
u32 C68k_Get_USP(c68k_struc *cpu);
199
u32 C68k_Get_MSP(c68k_struc *cpu);
200
201
void C68k_Set_DReg(c68k_struc *cpu, u32 num, u32 val);
202
void C68k_Set_AReg(c68k_struc *cpu, u32 num, u32 val);
203
void C68k_Set_PC(c68k_struc *cpu, u32 val);
204
void C68k_Set_SR(c68k_struc *cpu, u32 val);
205
void C68k_Set_USP(c68k_struc *cpu, u32 val);
206
void C68k_Set_MSP(c68k_struc *cpu, u32 val);
207
208
#ifdef __cplusplus
209
}
210
#endif
211
212
#endif // _C68K_H_
213
214
215