ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/basilisk_glue.cpp
Revision: 1.12
Committed: 2002-01-15T14:58:43Z (22 years, 10 months ago) by cebix
Branch: MAIN
CVS Tags: snapshot-15012002
Changes since 1.11: +1 -1 lines
Log Message:
- documentation updates
- 2001 -> 2002
- version 0.9 -> 1.0

File Contents

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