Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/m68kc68k.c
2 views
1
/* Copyright 2007 Guillaume Duhamel
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 "m68kc68k.h"
21
#include "c68k/c68k.h"
22
#include "memory.h"
23
#include "yabause.h"
24
25
/**
26
* PROFILE_68K: Perform simple profiling of the 68000 emulation, reporting
27
* the average time per 68000 clock cycle. (Realtime execution would be
28
* around 88.5 nsec/cycle.)
29
*/
30
// #define PROFILE_68K
31
32
33
static u8 *SoundDummy=NULL;
34
35
static int M68KC68KInit(void) {
36
int i;
37
38
// Setup a 64k buffer filled with invalid 68k instructions to serve
39
// as a default map
40
if ((SoundDummy = T2MemoryInit(0x10000)) != NULL)
41
memset(SoundDummy, 0xFF, 0x10000);
42
43
C68k_Init(&C68K, NULL); // not sure if I need the int callback or not
44
45
for (i = 0x10; i < 0x100; i++)
46
M68K->SetFetch(i << 16, (i << 16) + 0xFFFF, (pointer)SoundDummy);
47
48
return 0;
49
}
50
51
static void M68KC68KDeInit(void) {
52
if (SoundDummy)
53
T2MemoryDeInit(SoundDummy);
54
SoundDummy = NULL;
55
}
56
57
static void M68KC68KReset(void) {
58
C68k_Reset(&C68K);
59
}
60
61
static s32 FASTCALL M68KC68KExec(s32 cycle) {
62
#ifdef PROFILE_68K
63
static u32 tot_cycles = 0, tot_usec = 0, tot_ticks = 0, last_report = 0;
64
u32 start, end;
65
start = (u32) YabauseGetTicks();
66
int retval = C68k_Exec(&C68K, cycle);
67
end = (u32) YabauseGetTicks();
68
tot_cycles += cycle;
69
tot_ticks += end - start;
70
if (tot_cycles/1000000 > last_report) {
71
tot_usec += (u64)tot_ticks * 1000000 / yabsys.tickfreq;
72
tot_ticks = 0;
73
fprintf(stderr, "%ld cycles in %.3f sec = %.3f nsec/cycle\n",
74
(long)tot_cycles, (double)tot_usec/1000000,
75
((double)tot_usec / (double)tot_cycles) * 1000);
76
last_report = tot_cycles/1000000;
77
}
78
return retval;
79
#else
80
return C68k_Exec(&C68K, cycle);
81
#endif
82
}
83
84
static void M68KC68KSync(void) {
85
}
86
87
static u32 M68KC68KGetDReg(u32 num) {
88
return C68k_Get_DReg(&C68K, num);
89
}
90
91
static u32 M68KC68KGetAReg(u32 num) {
92
return C68k_Get_AReg(&C68K, num);
93
}
94
95
static u32 M68KC68KGetPC(void) {
96
return C68k_Get_PC(&C68K);
97
}
98
99
static u32 M68KC68KGetSR(void) {
100
return C68k_Get_SR(&C68K);
101
}
102
103
static u32 M68KC68KGetUSP(void) {
104
return C68k_Get_USP(&C68K);
105
}
106
107
static u32 M68KC68KGetMSP(void) {
108
return C68k_Get_MSP(&C68K);
109
}
110
111
static void M68KC68KSetDReg(u32 num, u32 val) {
112
C68k_Set_DReg(&C68K, num, val);
113
}
114
115
static void M68KC68KSetAReg(u32 num, u32 val) {
116
C68k_Set_AReg(&C68K, num, val);
117
}
118
119
static void M68KC68KSetPC(u32 val) {
120
C68k_Set_PC(&C68K, val);
121
}
122
123
static void M68KC68KSetSR(u32 val) {
124
C68k_Set_SR(&C68K, val);
125
}
126
127
static void M68KC68KSetUSP(u32 val) {
128
C68k_Set_USP(&C68K, val);
129
}
130
131
static void M68KC68KSetMSP(u32 val) {
132
C68k_Set_MSP(&C68K, val);
133
}
134
135
static void M68KC68KSetFetch(u32 low_adr, u32 high_adr, pointer fetch_adr) {
136
C68k_Set_Fetch(&C68K, low_adr, high_adr, fetch_adr);
137
}
138
139
static void FASTCALL M68KC68KSetIRQ(s32 level) {
140
C68k_Set_IRQ(&C68K, level);
141
}
142
143
static void FASTCALL M68KC68KWriteNotify(u32 address, u32 size) {
144
/* nothing to do */
145
}
146
147
static void M68KC68KSetReadB(M68K_READ *Func) {
148
C68k_Set_ReadB(&C68K, Func);
149
}
150
151
static void M68KC68KSetReadW(M68K_READ *Func) {
152
C68k_Set_ReadW(&C68K, Func);
153
}
154
155
static void M68KC68KSetWriteB(M68K_WRITE *Func) {
156
C68k_Set_WriteB(&C68K, Func);
157
}
158
159
static void M68KC68KSetWriteW(M68K_WRITE *Func) {
160
C68k_Set_WriteW(&C68K, Func);
161
}
162
163
M68K_struct M68KC68K = {
164
1,
165
"C68k Interface",
166
M68KC68KInit,
167
M68KC68KDeInit,
168
M68KC68KReset,
169
M68KC68KExec,
170
M68KC68KSync,
171
M68KC68KGetDReg,
172
M68KC68KGetAReg,
173
M68KC68KGetPC,
174
M68KC68KGetSR,
175
M68KC68KGetUSP,
176
M68KC68KGetMSP,
177
M68KC68KSetDReg,
178
M68KC68KSetAReg,
179
M68KC68KSetPC,
180
M68KC68KSetSR,
181
M68KC68KSetUSP,
182
M68KC68KSetMSP,
183
M68KC68KSetFetch,
184
M68KC68KSetIRQ,
185
M68KC68KWriteNotify,
186
M68KC68KSetReadB,
187
M68KC68KSetReadW,
188
M68KC68KSetWriteB,
189
M68KC68KSetWriteW
190
};
191
192