~ubuntu-branches/ubuntu/trusty/basilisk2/trusty

« back to all changes in this revision

Viewing changes to src/uae_cpu/basilisk_glue.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2003-07-24 00:48:57 UTC
  • Revision ID: james.westby@ubuntu.com-20030724004857-vnv33v6vf7a7u0z6
Tags: upstream-0.9.20030722
ImportĀ upstreamĀ versionĀ 0.9.20030722

Show diffs side-by-side

added added

removed removed

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