ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/basilisk_glue.cpp
Revision: 1.5
Committed: 2000-08-22T12:44:30Z (23 years, 9 months ago) by cebix
Branch: MAIN
Changes since 1.4: +5 -0 lines
Log Message:
- fixed compilation problem under Linux
- TriggerNMI() declaration moved to cpu_emulation.h

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * basilisk_glue.cpp - Glue UAE CPU to Basilisk II CPU engine interface
3     *
4 cebix 1.3 * Basilisk II (C) 1997-2000 Christian Bauer
5 cebix 1.1 *
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 cebix 1.4
23 cebix 1.1 #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 cebix 1.4 #ifdef USE_COMPILER
86 cebix 1.2 compiler_init();
87 cebix 1.4 #endif
88 cebix 1.1 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 cebix 1.5 void TriggerNMI(void)
122     {
123     //!! not implemented yet
124     }
125    
126 cebix 1.1
127     /*
128     * Get 68k interrupt level
129     */
130    
131     int intlev(void)
132     {
133     return InterruptFlags ? 1 : 0;
134     }
135    
136    
137     /*
138     * Execute MacOS 68k trap
139     * r->a[7] and r->sr are unused!
140     */
141    
142     void Execute68kTrap(uint16 trap, struct M68kRegisters *r)
143     {
144     int i;
145    
146     // Save old PC
147     uaecptr oldpc = m68k_getpc();
148    
149     // Set registers
150     for (i=0; i<8; i++)
151     m68k_dreg(regs, i) = r->d[i];
152     for (i=0; i<7; i++)
153     m68k_areg(regs, i) = r->a[i];
154    
155     // Push trap and EXEC_RETURN on stack
156     m68k_areg(regs, 7) -= 2;
157     put_word(m68k_areg(regs, 7), M68K_EXEC_RETURN);
158     m68k_areg(regs, 7) -= 2;
159     put_word(m68k_areg(regs, 7), trap);
160    
161     // Execute trap
162     m68k_setpc(m68k_areg(regs, 7));
163     fill_prefetch_0();
164     quit_program = 0;
165     m68k_go(true);
166    
167     // Clean up stack
168     m68k_areg(regs, 7) += 4;
169    
170     // Restore old PC
171     m68k_setpc(oldpc);
172     fill_prefetch_0();
173    
174     // Get registers
175     for (i=0; i<8; i++)
176     r->d[i] = m68k_dreg(regs, i);
177     for (i=0; i<7; i++)
178     r->a[i] = m68k_areg(regs, i);
179     quit_program = 0;
180     }
181    
182    
183     /*
184     * Execute 68k subroutine
185     * The executed routine must reside in UAE memory!
186     * r->a[7] and r->sr are unused!
187     */
188    
189     void Execute68k(uint32 addr, struct M68kRegisters *r)
190     {
191     int i;
192    
193     // Save old PC
194     uaecptr oldpc = m68k_getpc();
195    
196     // Set registers
197     for (i=0; i<8; i++)
198     m68k_dreg(regs, i) = r->d[i];
199     for (i=0; i<7; i++)
200     m68k_areg(regs, i) = r->a[i];
201    
202     // Push EXEC_RETURN and faked return address (points to EXEC_RETURN) on stack
203     m68k_areg(regs, 7) -= 2;
204     put_word(m68k_areg(regs, 7), M68K_EXEC_RETURN);
205     m68k_areg(regs, 7) -= 4;
206     put_long(m68k_areg(regs, 7), m68k_areg(regs, 7) + 4);
207    
208     // Execute routine
209     m68k_setpc(addr);
210     fill_prefetch_0();
211     quit_program = 0;
212     m68k_go(true);
213    
214     // Clean up stack
215     m68k_areg(regs, 7) += 2;
216    
217     // Restore old PC
218     m68k_setpc(oldpc);
219     fill_prefetch_0();
220    
221     // Get registers
222     for (i=0; i<8; i++)
223     r->d[i] = m68k_dreg(regs, i);
224     for (i=0; i<7; i++)
225     r->a[i] = m68k_areg(regs, i);
226     quit_program = 0;
227     }