1 |
/* |
2 |
* basilisk_glue.cpp - Glue UAE CPU to Basilisk II CPU engine interface |
3 |
* |
4 |
* Basilisk II (C) 1997-2000 Christian Bauer |
5 |
* |
6 |
* This program 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 |
* This program 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 this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#include "sysdeps.h" |
22 |
|
23 |
#include "cpu_emulation.h" |
24 |
#include "main.h" |
25 |
#include "emul_op.h" |
26 |
#include "rom_patches.h" |
27 |
#include "m68k.h" |
28 |
#include "memory.h" |
29 |
#include "readcpu.h" |
30 |
#include "newcpu.h" |
31 |
#include "compiler.h" |
32 |
|
33 |
|
34 |
// RAM and ROM pointers |
35 |
uint32 RAMBaseMac; // RAM base (Mac address space) |
36 |
uint8 *RAMBaseHost; // RAM base (host address space) |
37 |
uint32 RAMSize; // Size of RAM |
38 |
uint32 ROMBaseMac; // ROM base (Mac address space) |
39 |
uint8 *ROMBaseHost; // ROM base (host address space) |
40 |
uint32 ROMSize; // Size of ROM |
41 |
|
42 |
#if !REAL_ADDRESSING |
43 |
// Mac frame buffer |
44 |
uint8 *MacFrameBaseHost; // Frame buffer base (host address space) |
45 |
uint32 MacFrameSize; // Size of frame buffer |
46 |
int MacFrameLayout; // Frame buffer layout |
47 |
#endif |
48 |
|
49 |
// From newcpu.cpp |
50 |
extern int quit_program; |
51 |
|
52 |
|
53 |
/* |
54 |
* Initialize 680x0 emulation, CheckROM() must have been called first |
55 |
*/ |
56 |
|
57 |
bool Init680x0(void) |
58 |
{ |
59 |
#if REAL_ADDRESSING |
60 |
// Mac address space = host address space |
61 |
RAMBaseMac = (uint32)RAMBaseHost; |
62 |
ROMBaseMac = (uint32)ROMBaseHost; |
63 |
#else |
64 |
// Initialize UAE memory banks |
65 |
RAMBaseMac = 0; |
66 |
switch (ROMVersion) { |
67 |
case ROM_VERSION_64K: |
68 |
case ROM_VERSION_PLUS: |
69 |
case ROM_VERSION_CLASSIC: |
70 |
ROMBaseMac = 0x00400000; |
71 |
break; |
72 |
case ROM_VERSION_II: |
73 |
ROMBaseMac = 0x00a00000; |
74 |
break; |
75 |
case ROM_VERSION_32: |
76 |
ROMBaseMac = 0x40800000; |
77 |
break; |
78 |
default: |
79 |
return false; |
80 |
} |
81 |
memory_init(); |
82 |
#endif |
83 |
|
84 |
init_m68k(); |
85 |
#ifdef USE_COMPILER |
86 |
compiler_init(); |
87 |
#endif |
88 |
return true; |
89 |
} |
90 |
|
91 |
|
92 |
/* |
93 |
* Deinitialize 680x0 emulation |
94 |
*/ |
95 |
|
96 |
void Exit680x0(void) |
97 |
{ |
98 |
exit_m68k(); |
99 |
} |
100 |
|
101 |
|
102 |
/* |
103 |
* Reset and start 680x0 emulation (doesn't return) |
104 |
*/ |
105 |
|
106 |
void Start680x0(void) |
107 |
{ |
108 |
m68k_reset(); |
109 |
m68k_go(true); |
110 |
} |
111 |
|
112 |
|
113 |
/* |
114 |
* Trigger interrupt |
115 |
*/ |
116 |
|
117 |
void TriggerInterrupt(void) |
118 |
{ |
119 |
regs.spcflags |= SPCFLAG_INT; |
120 |
} |
121 |
|
122 |
void TriggerNMI(void) |
123 |
{ |
124 |
//!! not implemented yet |
125 |
} |
126 |
|
127 |
|
128 |
/* |
129 |
* Get 68k interrupt level |
130 |
*/ |
131 |
|
132 |
int intlev(void) |
133 |
{ |
134 |
return InterruptFlags ? 1 : 0; |
135 |
} |
136 |
|
137 |
|
138 |
/* |
139 |
* Execute MacOS 68k trap |
140 |
* r->a[7] and r->sr are unused! |
141 |
*/ |
142 |
|
143 |
void Execute68kTrap(uint16 trap, struct M68kRegisters *r) |
144 |
{ |
145 |
int i; |
146 |
|
147 |
// Save old PC |
148 |
uaecptr oldpc = m68k_getpc(); |
149 |
|
150 |
// Set registers |
151 |
for (i=0; i<8; i++) |
152 |
m68k_dreg(regs, i) = r->d[i]; |
153 |
for (i=0; i<7; i++) |
154 |
m68k_areg(regs, i) = r->a[i]; |
155 |
|
156 |
// Push trap and EXEC_RETURN on stack |
157 |
m68k_areg(regs, 7) -= 2; |
158 |
put_word(m68k_areg(regs, 7), M68K_EXEC_RETURN); |
159 |
m68k_areg(regs, 7) -= 2; |
160 |
put_word(m68k_areg(regs, 7), trap); |
161 |
|
162 |
// Execute trap |
163 |
m68k_setpc(m68k_areg(regs, 7)); |
164 |
fill_prefetch_0(); |
165 |
quit_program = 0; |
166 |
m68k_go(true); |
167 |
|
168 |
// Clean up stack |
169 |
m68k_areg(regs, 7) += 4; |
170 |
|
171 |
// Restore old PC |
172 |
m68k_setpc(oldpc); |
173 |
fill_prefetch_0(); |
174 |
|
175 |
// Get registers |
176 |
for (i=0; i<8; i++) |
177 |
r->d[i] = m68k_dreg(regs, i); |
178 |
for (i=0; i<7; i++) |
179 |
r->a[i] = m68k_areg(regs, i); |
180 |
quit_program = 0; |
181 |
} |
182 |
|
183 |
|
184 |
/* |
185 |
* Execute 68k subroutine |
186 |
* The executed routine must reside in UAE memory! |
187 |
* r->a[7] and r->sr are unused! |
188 |
*/ |
189 |
|
190 |
void Execute68k(uint32 addr, struct M68kRegisters *r) |
191 |
{ |
192 |
int i; |
193 |
|
194 |
// Save old PC |
195 |
uaecptr oldpc = m68k_getpc(); |
196 |
|
197 |
// Set registers |
198 |
for (i=0; i<8; i++) |
199 |
m68k_dreg(regs, i) = r->d[i]; |
200 |
for (i=0; i<7; i++) |
201 |
m68k_areg(regs, i) = r->a[i]; |
202 |
|
203 |
// Push EXEC_RETURN and faked return address (points to EXEC_RETURN) on stack |
204 |
m68k_areg(regs, 7) -= 2; |
205 |
put_word(m68k_areg(regs, 7), M68K_EXEC_RETURN); |
206 |
m68k_areg(regs, 7) -= 4; |
207 |
put_long(m68k_areg(regs, 7), m68k_areg(regs, 7) + 4); |
208 |
|
209 |
// Execute routine |
210 |
m68k_setpc(addr); |
211 |
fill_prefetch_0(); |
212 |
quit_program = 0; |
213 |
m68k_go(true); |
214 |
|
215 |
// Clean up stack |
216 |
m68k_areg(regs, 7) += 2; |
217 |
|
218 |
// Restore old PC |
219 |
m68k_setpc(oldpc); |
220 |
fill_prefetch_0(); |
221 |
|
222 |
// Get registers |
223 |
for (i=0; i<8; i++) |
224 |
r->d[i] = m68k_dreg(regs, i); |
225 |
for (i=0; i<7; i++) |
226 |
r->a[i] = m68k_areg(regs, i); |
227 |
quit_program = 0; |
228 |
} |