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 |
} |
99 |
|
100 |
|
101 |
/* |
102 |
* Reset and start 680x0 emulation (doesn't return) |
103 |
*/ |
104 |
|
105 |
void Start680x0(void) |
106 |
{ |
107 |
m68k_reset(); |
108 |
m68k_go(true); |
109 |
} |
110 |
|
111 |
|
112 |
/* |
113 |
* Trigger interrupt |
114 |
*/ |
115 |
|
116 |
void TriggerInterrupt(void) |
117 |
{ |
118 |
regs.spcflags |= SPCFLAG_INT; |
119 |
} |
120 |
|
121 |
|
122 |
/* |
123 |
* Get 68k interrupt level |
124 |
*/ |
125 |
|
126 |
int intlev(void) |
127 |
{ |
128 |
return InterruptFlags ? 1 : 0; |
129 |
} |
130 |
|
131 |
|
132 |
/* |
133 |
* Execute MacOS 68k trap |
134 |
* r->a[7] and r->sr are unused! |
135 |
*/ |
136 |
|
137 |
void Execute68kTrap(uint16 trap, struct M68kRegisters *r) |
138 |
{ |
139 |
int i; |
140 |
|
141 |
// Save old PC |
142 |
uaecptr oldpc = m68k_getpc(); |
143 |
|
144 |
// Set registers |
145 |
for (i=0; i<8; i++) |
146 |
m68k_dreg(regs, i) = r->d[i]; |
147 |
for (i=0; i<7; i++) |
148 |
m68k_areg(regs, i) = r->a[i]; |
149 |
|
150 |
// Push trap and EXEC_RETURN on stack |
151 |
m68k_areg(regs, 7) -= 2; |
152 |
put_word(m68k_areg(regs, 7), M68K_EXEC_RETURN); |
153 |
m68k_areg(regs, 7) -= 2; |
154 |
put_word(m68k_areg(regs, 7), trap); |
155 |
|
156 |
// Execute trap |
157 |
m68k_setpc(m68k_areg(regs, 7)); |
158 |
fill_prefetch_0(); |
159 |
quit_program = 0; |
160 |
m68k_go(true); |
161 |
|
162 |
// Clean up stack |
163 |
m68k_areg(regs, 7) += 4; |
164 |
|
165 |
// Restore old PC |
166 |
m68k_setpc(oldpc); |
167 |
fill_prefetch_0(); |
168 |
|
169 |
// Get registers |
170 |
for (i=0; i<8; i++) |
171 |
r->d[i] = m68k_dreg(regs, i); |
172 |
for (i=0; i<7; i++) |
173 |
r->a[i] = m68k_areg(regs, i); |
174 |
quit_program = 0; |
175 |
} |
176 |
|
177 |
|
178 |
/* |
179 |
* Execute 68k subroutine |
180 |
* The executed routine must reside in UAE memory! |
181 |
* r->a[7] and r->sr are unused! |
182 |
*/ |
183 |
|
184 |
void Execute68k(uint32 addr, struct M68kRegisters *r) |
185 |
{ |
186 |
int i; |
187 |
|
188 |
// Save old PC |
189 |
uaecptr oldpc = m68k_getpc(); |
190 |
|
191 |
// Set registers |
192 |
for (i=0; i<8; i++) |
193 |
m68k_dreg(regs, i) = r->d[i]; |
194 |
for (i=0; i<7; i++) |
195 |
m68k_areg(regs, i) = r->a[i]; |
196 |
|
197 |
// Push EXEC_RETURN and faked return address (points to EXEC_RETURN) on stack |
198 |
m68k_areg(regs, 7) -= 2; |
199 |
put_word(m68k_areg(regs, 7), M68K_EXEC_RETURN); |
200 |
m68k_areg(regs, 7) -= 4; |
201 |
put_long(m68k_areg(regs, 7), m68k_areg(regs, 7) + 4); |
202 |
|
203 |
// Execute routine |
204 |
m68k_setpc(addr); |
205 |
fill_prefetch_0(); |
206 |
quit_program = 0; |
207 |
m68k_go(true); |
208 |
|
209 |
// Clean up stack |
210 |
m68k_areg(regs, 7) += 2; |
211 |
|
212 |
// Restore old PC |
213 |
m68k_setpc(oldpc); |
214 |
fill_prefetch_0(); |
215 |
|
216 |
// Get registers |
217 |
for (i=0; i<8; i++) |
218 |
r->d[i] = m68k_dreg(regs, i); |
219 |
for (i=0; i<7; i++) |
220 |
r->a[i] = m68k_areg(regs, i); |
221 |
quit_program = 0; |
222 |
} |