ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/basilisk_glue.cpp
Revision: 1.2
Committed: 1999-11-03T10:56:33Z (25 years, 1 month ago) by cebix
Branch: MAIN
CVS Tags: snapshot-22121999, release-0_8-1
Changes since 1.1: +1 -0 lines
Log Message:
- imported UAE CPU 0.8.10 changes
- new utility functions Mac_memset, Mac2Host_memcpy, Host2Mac_memcpu and
  Mac2Mac_memcpy
- extfs.cpp: fixed bug in fs_rename() and fs_cat_move() (auxiliary IOParam
  block was not in Mac address space)
- some provisions for using UAE CPU compiler (doesn't work yet)

File Contents

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