ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/basilisk_glue.cpp
Revision: 1.7
Committed: 2000-09-22T17:18:15Z (23 years, 9 months ago) by gbeauche
Branch: MAIN
Changes since 1.6: +7 -1 lines
Log Message:
- added memory initilization for direct addressing (MEMBaseDiff)

File Contents

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