1 |
/* |
2 |
* UAE - The Un*x Amiga Emulator |
3 |
* |
4 |
* Memory management |
5 |
* |
6 |
* (c) 1995 Bernd Schmidt |
7 |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
10 |
* the Free Software Foundation; either version 2 of the License, or |
11 |
* (at your option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
#include <stdio.h> |
24 |
#include <stdlib.h> |
25 |
|
26 |
#include "sysdeps.h" |
27 |
|
28 |
#include "cpu_emulation.h" |
29 |
#include "main.h" |
30 |
#include "video.h" |
31 |
|
32 |
#include "m68k.h" |
33 |
#include "memory.h" |
34 |
#include "readcpu.h" |
35 |
#include "newcpu.h" |
36 |
|
37 |
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
38 |
|
39 |
static bool illegal_mem = false; |
40 |
|
41 |
#ifdef SAVE_MEMORY_BANKS |
42 |
addrbank *mem_banks[65536]; |
43 |
#else |
44 |
addrbank mem_banks[65536]; |
45 |
#endif |
46 |
|
47 |
#ifdef WORDS_BIGENDIAN |
48 |
# define swap_words(X) (X) |
49 |
#else |
50 |
# define swap_words(X) (((X) >> 16) | ((X) << 16)) |
51 |
#endif |
52 |
|
53 |
#ifdef NO_INLINE_MEMORY_ACCESS |
54 |
uae_u32 longget (uaecptr addr) |
55 |
{ |
56 |
return call_mem_get_func (get_mem_bank (addr).lget, addr); |
57 |
} |
58 |
uae_u32 wordget (uaecptr addr) |
59 |
{ |
60 |
return call_mem_get_func (get_mem_bank (addr).wget, addr); |
61 |
} |
62 |
uae_u32 byteget (uaecptr addr) |
63 |
{ |
64 |
return call_mem_get_func (get_mem_bank (addr).bget, addr); |
65 |
} |
66 |
void longput (uaecptr addr, uae_u32 l) |
67 |
{ |
68 |
call_mem_put_func (get_mem_bank (addr).lput, addr, l); |
69 |
} |
70 |
void wordput (uaecptr addr, uae_u32 w) |
71 |
{ |
72 |
call_mem_put_func (get_mem_bank (addr).wput, addr, w); |
73 |
} |
74 |
void byteput (uaecptr addr, uae_u32 b) |
75 |
{ |
76 |
call_mem_put_func (get_mem_bank (addr).bput, addr, b); |
77 |
} |
78 |
#endif |
79 |
|
80 |
/* A dummy bank that only contains zeros */ |
81 |
|
82 |
static uae_u32 REGPARAM2 dummy_lget (uaecptr) REGPARAM; |
83 |
static uae_u32 REGPARAM2 dummy_wget (uaecptr) REGPARAM; |
84 |
static uae_u32 REGPARAM2 dummy_bget (uaecptr) REGPARAM; |
85 |
static void REGPARAM2 dummy_lput (uaecptr, uae_u32) REGPARAM; |
86 |
static void REGPARAM2 dummy_wput (uaecptr, uae_u32) REGPARAM; |
87 |
static void REGPARAM2 dummy_bput (uaecptr, uae_u32) REGPARAM; |
88 |
|
89 |
uae_u32 REGPARAM2 dummy_lget (uaecptr addr) |
90 |
{ |
91 |
if (illegal_mem) |
92 |
write_log ("Illegal lget at %08lx\n", addr); |
93 |
|
94 |
return 0; |
95 |
} |
96 |
|
97 |
uae_u32 REGPARAM2 dummy_wget (uaecptr addr) |
98 |
{ |
99 |
if (illegal_mem) |
100 |
write_log ("Illegal wget at %08lx\n", addr); |
101 |
|
102 |
return 0; |
103 |
} |
104 |
|
105 |
uae_u32 REGPARAM2 dummy_bget (uaecptr addr) |
106 |
{ |
107 |
if (illegal_mem) |
108 |
write_log ("Illegal bget at %08lx\n", addr); |
109 |
|
110 |
return 0; |
111 |
} |
112 |
|
113 |
void REGPARAM2 dummy_lput (uaecptr addr, uae_u32 l) |
114 |
{ |
115 |
if (illegal_mem) |
116 |
write_log ("Illegal lput at %08lx\n", addr); |
117 |
} |
118 |
void REGPARAM2 dummy_wput (uaecptr addr, uae_u32 w) |
119 |
{ |
120 |
if (illegal_mem) |
121 |
write_log ("Illegal wput at %08lx\n", addr); |
122 |
} |
123 |
void REGPARAM2 dummy_bput (uaecptr addr, uae_u32 b) |
124 |
{ |
125 |
if (illegal_mem) |
126 |
write_log ("Illegal bput at %08lx\n", addr); |
127 |
} |
128 |
|
129 |
/* Mac RAM (32 bit addressing) */ |
130 |
|
131 |
static uae_u32 REGPARAM2 ram_lget(uaecptr) REGPARAM; |
132 |
static uae_u32 REGPARAM2 ram_wget(uaecptr) REGPARAM; |
133 |
static uae_u32 REGPARAM2 ram_bget(uaecptr) REGPARAM; |
134 |
static void REGPARAM2 ram_lput(uaecptr, uae_u32) REGPARAM; |
135 |
static void REGPARAM2 ram_wput(uaecptr, uae_u32) REGPARAM; |
136 |
static void REGPARAM2 ram_bput(uaecptr, uae_u32) REGPARAM; |
137 |
static uae_u8 *REGPARAM2 ram_xlate(uaecptr addr) REGPARAM; |
138 |
|
139 |
static uintptr RAMBaseDiff; // RAMBaseHost - RAMBaseMac |
140 |
|
141 |
uae_u32 REGPARAM2 ram_lget(uaecptr addr) |
142 |
{ |
143 |
uae_u32 *m; |
144 |
m = (uae_u32 *)(RAMBaseDiff + addr); |
145 |
return do_get_mem_long(m); |
146 |
} |
147 |
|
148 |
uae_u32 REGPARAM2 ram_wget(uaecptr addr) |
149 |
{ |
150 |
uae_u16 *m; |
151 |
m = (uae_u16 *)(RAMBaseDiff + addr); |
152 |
return do_get_mem_word(m); |
153 |
} |
154 |
|
155 |
uae_u32 REGPARAM2 ram_bget(uaecptr addr) |
156 |
{ |
157 |
return (uae_u32)*(uae_u8 *)(RAMBaseDiff + addr); |
158 |
} |
159 |
|
160 |
void REGPARAM2 ram_lput(uaecptr addr, uae_u32 l) |
161 |
{ |
162 |
uae_u32 *m; |
163 |
m = (uae_u32 *)(RAMBaseDiff + addr); |
164 |
do_put_mem_long(m, l); |
165 |
} |
166 |
|
167 |
void REGPARAM2 ram_wput(uaecptr addr, uae_u32 w) |
168 |
{ |
169 |
uae_u16 *m; |
170 |
m = (uae_u16 *)(RAMBaseDiff + addr); |
171 |
do_put_mem_word(m, w); |
172 |
} |
173 |
|
174 |
void REGPARAM2 ram_bput(uaecptr addr, uae_u32 b) |
175 |
{ |
176 |
*(uae_u8 *)(RAMBaseDiff + addr) = b; |
177 |
} |
178 |
|
179 |
uae_u8 *REGPARAM2 ram_xlate(uaecptr addr) |
180 |
{ |
181 |
return (uae_u8 *)(RAMBaseDiff + addr); |
182 |
} |
183 |
|
184 |
/* Mac RAM (24 bit addressing) */ |
185 |
|
186 |
static uae_u32 REGPARAM2 ram24_lget(uaecptr) REGPARAM; |
187 |
static uae_u32 REGPARAM2 ram24_wget(uaecptr) REGPARAM; |
188 |
static uae_u32 REGPARAM2 ram24_bget(uaecptr) REGPARAM; |
189 |
static void REGPARAM2 ram24_lput(uaecptr, uae_u32) REGPARAM; |
190 |
static void REGPARAM2 ram24_wput(uaecptr, uae_u32) REGPARAM; |
191 |
static void REGPARAM2 ram24_bput(uaecptr, uae_u32) REGPARAM; |
192 |
static uae_u8 *REGPARAM2 ram24_xlate(uaecptr addr) REGPARAM; |
193 |
|
194 |
uae_u32 REGPARAM2 ram24_lget(uaecptr addr) |
195 |
{ |
196 |
uae_u32 *m; |
197 |
m = (uae_u32 *)(RAMBaseDiff + (addr & 0xffffff)); |
198 |
return do_get_mem_long(m); |
199 |
} |
200 |
|
201 |
uae_u32 REGPARAM2 ram24_wget(uaecptr addr) |
202 |
{ |
203 |
uae_u16 *m; |
204 |
m = (uae_u16 *)(RAMBaseDiff + (addr & 0xffffff)); |
205 |
return do_get_mem_word(m); |
206 |
} |
207 |
|
208 |
uae_u32 REGPARAM2 ram24_bget(uaecptr addr) |
209 |
{ |
210 |
return (uae_u32)*(uae_u8 *)(RAMBaseDiff + (addr & 0xffffff)); |
211 |
} |
212 |
|
213 |
void REGPARAM2 ram24_lput(uaecptr addr, uae_u32 l) |
214 |
{ |
215 |
uae_u32 *m; |
216 |
m = (uae_u32 *)(RAMBaseDiff + (addr & 0xffffff)); |
217 |
do_put_mem_long(m, l); |
218 |
} |
219 |
|
220 |
void REGPARAM2 ram24_wput(uaecptr addr, uae_u32 w) |
221 |
{ |
222 |
uae_u16 *m; |
223 |
m = (uae_u16 *)(RAMBaseDiff + (addr & 0xffffff)); |
224 |
do_put_mem_word(m, w); |
225 |
} |
226 |
|
227 |
void REGPARAM2 ram24_bput(uaecptr addr, uae_u32 b) |
228 |
{ |
229 |
*(uae_u8 *)(RAMBaseDiff + (addr & 0xffffff)) = b; |
230 |
} |
231 |
|
232 |
uae_u8 *REGPARAM2 ram24_xlate(uaecptr addr) |
233 |
{ |
234 |
return (uae_u8 *)(RAMBaseDiff + (addr & 0xffffff)); |
235 |
} |
236 |
|
237 |
/* Mac ROM (32 bit addressing) */ |
238 |
|
239 |
static uae_u32 REGPARAM2 rom_lget(uaecptr) REGPARAM; |
240 |
static uae_u32 REGPARAM2 rom_wget(uaecptr) REGPARAM; |
241 |
static uae_u32 REGPARAM2 rom_bget(uaecptr) REGPARAM; |
242 |
static void REGPARAM2 rom_lput(uaecptr, uae_u32) REGPARAM; |
243 |
static void REGPARAM2 rom_wput(uaecptr, uae_u32) REGPARAM; |
244 |
static void REGPARAM2 rom_bput(uaecptr, uae_u32) REGPARAM; |
245 |
static uae_u8 *REGPARAM2 rom_xlate(uaecptr addr) REGPARAM; |
246 |
|
247 |
static uintptr ROMBaseDiff; // ROMBaseHost - ROMBaseMac |
248 |
|
249 |
uae_u32 REGPARAM2 rom_lget(uaecptr addr) |
250 |
{ |
251 |
uae_u32 *m; |
252 |
m = (uae_u32 *)(ROMBaseDiff + addr); |
253 |
return do_get_mem_long(m); |
254 |
} |
255 |
|
256 |
uae_u32 REGPARAM2 rom_wget(uaecptr addr) |
257 |
{ |
258 |
uae_u16 *m; |
259 |
m = (uae_u16 *)(ROMBaseDiff + addr); |
260 |
return do_get_mem_word(m); |
261 |
} |
262 |
|
263 |
uae_u32 REGPARAM2 rom_bget(uaecptr addr) |
264 |
{ |
265 |
return (uae_u32)*(uae_u8 *)(ROMBaseDiff + addr); |
266 |
} |
267 |
|
268 |
void REGPARAM2 rom_lput(uaecptr addr, uae_u32 b) |
269 |
{ |
270 |
if (illegal_mem) |
271 |
write_log ("Illegal ROM lput at %08lx\n", addr); |
272 |
} |
273 |
|
274 |
void REGPARAM2 rom_wput(uaecptr addr, uae_u32 b) |
275 |
{ |
276 |
if (illegal_mem) |
277 |
write_log ("Illegal ROM wput at %08lx\n", addr); |
278 |
} |
279 |
|
280 |
void REGPARAM2 rom_bput(uaecptr addr, uae_u32 b) |
281 |
{ |
282 |
if (illegal_mem) |
283 |
write_log ("Illegal ROM bput at %08lx\n", addr); |
284 |
} |
285 |
|
286 |
uae_u8 *REGPARAM2 rom_xlate(uaecptr addr) |
287 |
{ |
288 |
return (uae_u8 *)(ROMBaseDiff + addr); |
289 |
} |
290 |
|
291 |
/* Mac ROM (24 bit addressing) */ |
292 |
|
293 |
static uae_u32 REGPARAM2 rom24_lget(uaecptr) REGPARAM; |
294 |
static uae_u32 REGPARAM2 rom24_wget(uaecptr) REGPARAM; |
295 |
static uae_u32 REGPARAM2 rom24_bget(uaecptr) REGPARAM; |
296 |
static uae_u8 *REGPARAM2 rom24_xlate(uaecptr addr) REGPARAM; |
297 |
|
298 |
uae_u32 REGPARAM2 rom24_lget(uaecptr addr) |
299 |
{ |
300 |
uae_u32 *m; |
301 |
m = (uae_u32 *)(ROMBaseDiff + (addr & 0xffffff)); |
302 |
return do_get_mem_long(m); |
303 |
} |
304 |
|
305 |
uae_u32 REGPARAM2 rom24_wget(uaecptr addr) |
306 |
{ |
307 |
uae_u16 *m; |
308 |
m = (uae_u16 *)(ROMBaseDiff + (addr & 0xffffff)); |
309 |
return do_get_mem_word(m); |
310 |
} |
311 |
|
312 |
uae_u32 REGPARAM2 rom24_bget(uaecptr addr) |
313 |
{ |
314 |
return (uae_u32)*(uae_u8 *)(ROMBaseDiff + (addr & 0xffffff)); |
315 |
} |
316 |
|
317 |
uae_u8 *REGPARAM2 rom24_xlate(uaecptr addr) |
318 |
{ |
319 |
return (uae_u8 *)(ROMBaseDiff + (addr & 0xffffff)); |
320 |
} |
321 |
|
322 |
/* Frame buffer */ |
323 |
|
324 |
static uae_u32 REGPARAM2 frame_direct_lget(uaecptr) REGPARAM; |
325 |
static uae_u32 REGPARAM2 frame_direct_wget(uaecptr) REGPARAM; |
326 |
static uae_u32 REGPARAM2 frame_direct_bget(uaecptr) REGPARAM; |
327 |
static void REGPARAM2 frame_direct_lput(uaecptr, uae_u32) REGPARAM; |
328 |
static void REGPARAM2 frame_direct_wput(uaecptr, uae_u32) REGPARAM; |
329 |
static void REGPARAM2 frame_direct_bput(uaecptr, uae_u32) REGPARAM; |
330 |
|
331 |
static uae_u32 REGPARAM2 frame_host_555_lget(uaecptr) REGPARAM; |
332 |
static uae_u32 REGPARAM2 frame_host_555_wget(uaecptr) REGPARAM; |
333 |
static void REGPARAM2 frame_host_555_lput(uaecptr, uae_u32) REGPARAM; |
334 |
static void REGPARAM2 frame_host_555_wput(uaecptr, uae_u32) REGPARAM; |
335 |
|
336 |
static uae_u32 REGPARAM2 frame_host_565_lget(uaecptr) REGPARAM; |
337 |
static uae_u32 REGPARAM2 frame_host_565_wget(uaecptr) REGPARAM; |
338 |
static void REGPARAM2 frame_host_565_lput(uaecptr, uae_u32) REGPARAM; |
339 |
static void REGPARAM2 frame_host_565_wput(uaecptr, uae_u32) REGPARAM; |
340 |
|
341 |
static uae_u32 REGPARAM2 frame_host_888_lget(uaecptr) REGPARAM; |
342 |
static void REGPARAM2 frame_host_888_lput(uaecptr, uae_u32) REGPARAM; |
343 |
|
344 |
static uae_u8 *REGPARAM2 frame_xlate(uaecptr addr) REGPARAM; |
345 |
|
346 |
static uintptr FrameBaseDiff; // MacFrameBaseHost - MacFrameBaseMac |
347 |
|
348 |
uae_u32 REGPARAM2 frame_direct_lget(uaecptr addr) |
349 |
{ |
350 |
uae_u32 *m; |
351 |
m = (uae_u32 *)(FrameBaseDiff + addr); |
352 |
return do_get_mem_long(m); |
353 |
} |
354 |
|
355 |
uae_u32 REGPARAM2 frame_direct_wget(uaecptr addr) |
356 |
{ |
357 |
uae_u16 *m; |
358 |
m = (uae_u16 *)(FrameBaseDiff + addr); |
359 |
return do_get_mem_word(m); |
360 |
} |
361 |
|
362 |
uae_u32 REGPARAM2 frame_direct_bget(uaecptr addr) |
363 |
{ |
364 |
return (uae_u32)*(uae_u8 *)(FrameBaseDiff + addr); |
365 |
} |
366 |
|
367 |
void REGPARAM2 frame_direct_lput(uaecptr addr, uae_u32 l) |
368 |
{ |
369 |
uae_u32 *m; |
370 |
m = (uae_u32 *)(FrameBaseDiff + addr); |
371 |
do_put_mem_long(m, l); |
372 |
} |
373 |
|
374 |
void REGPARAM2 frame_direct_wput(uaecptr addr, uae_u32 w) |
375 |
{ |
376 |
uae_u16 *m; |
377 |
m = (uae_u16 *)(FrameBaseDiff + addr); |
378 |
do_put_mem_word(m, w); |
379 |
} |
380 |
|
381 |
void REGPARAM2 frame_direct_bput(uaecptr addr, uae_u32 b) |
382 |
{ |
383 |
*(uae_u8 *)(FrameBaseDiff + addr) = b; |
384 |
} |
385 |
|
386 |
uae_u32 REGPARAM2 frame_host_555_lget(uaecptr addr) |
387 |
{ |
388 |
uae_u32 *m, l; |
389 |
m = (uae_u32 *)(FrameBaseDiff + addr); |
390 |
l = *m; |
391 |
return swap_words(l); |
392 |
} |
393 |
|
394 |
uae_u32 REGPARAM2 frame_host_555_wget(uaecptr addr) |
395 |
{ |
396 |
uae_u16 *m; |
397 |
m = (uae_u16 *)(FrameBaseDiff + addr); |
398 |
return *m; |
399 |
} |
400 |
|
401 |
void REGPARAM2 frame_host_555_lput(uaecptr addr, uae_u32 l) |
402 |
{ |
403 |
uae_u32 *m; |
404 |
m = (uae_u32 *)(FrameBaseDiff + addr); |
405 |
*m = swap_words(l); |
406 |
} |
407 |
|
408 |
void REGPARAM2 frame_host_555_wput(uaecptr addr, uae_u32 w) |
409 |
{ |
410 |
uae_u16 *m; |
411 |
m = (uae_u16 *)(FrameBaseDiff + addr); |
412 |
*m = w; |
413 |
} |
414 |
|
415 |
uae_u32 REGPARAM2 frame_host_565_lget(uaecptr addr) |
416 |
{ |
417 |
uae_u32 *m, l; |
418 |
m = (uae_u32 *)(FrameBaseDiff + addr); |
419 |
l = *m; |
420 |
l = (l & 0x001f001f) | ((l >> 1) & 0x7fe07fe0); |
421 |
return swap_words(l); |
422 |
} |
423 |
|
424 |
uae_u32 REGPARAM2 frame_host_565_wget(uaecptr addr) |
425 |
{ |
426 |
uae_u16 *m, w; |
427 |
m = (uae_u16 *)(FrameBaseDiff + addr); |
428 |
w = *m; |
429 |
return (w & 0x1f) | ((w >> 1) & 0x7fe0); |
430 |
} |
431 |
|
432 |
void REGPARAM2 frame_host_565_lput(uaecptr addr, uae_u32 l) |
433 |
{ |
434 |
uae_u32 *m; |
435 |
m = (uae_u32 *)(FrameBaseDiff + addr); |
436 |
l = (l & 0x001f001f) | ((l << 1) & 0xffc0ffc0); |
437 |
*m = swap_words(l); |
438 |
} |
439 |
|
440 |
void REGPARAM2 frame_host_565_wput(uaecptr addr, uae_u32 w) |
441 |
{ |
442 |
uae_u16 *m; |
443 |
m = (uae_u16 *)(FrameBaseDiff + addr); |
444 |
*m = (w & 0x1f) | ((w << 1) & 0xffc0); |
445 |
} |
446 |
|
447 |
uae_u32 REGPARAM2 frame_host_888_lget(uaecptr addr) |
448 |
{ |
449 |
uae_u32 *m, l; |
450 |
m = (uae_u32 *)(FrameBaseDiff + addr); |
451 |
return *m; |
452 |
} |
453 |
|
454 |
void REGPARAM2 frame_host_888_lput(uaecptr addr, uae_u32 l) |
455 |
{ |
456 |
uae_u32 *m; |
457 |
m = (uae_u32 *)(MacFrameBaseHost + addr - MacFrameBaseMac); |
458 |
*m = l; |
459 |
} |
460 |
|
461 |
uae_u8 *REGPARAM2 frame_xlate(uaecptr addr) |
462 |
{ |
463 |
return (uae_u8 *)(FrameBaseDiff + addr); |
464 |
} |
465 |
|
466 |
/* Default memory access functions */ |
467 |
|
468 |
uae_u8 *REGPARAM2 default_xlate (uaecptr a) |
469 |
{ |
470 |
write_log("Your Mac program just did something terribly stupid\n"); |
471 |
return NULL; |
472 |
} |
473 |
|
474 |
/* Address banks */ |
475 |
|
476 |
addrbank dummy_bank = { |
477 |
dummy_lget, dummy_wget, dummy_bget, |
478 |
dummy_lput, dummy_wput, dummy_bput, |
479 |
default_xlate |
480 |
}; |
481 |
|
482 |
addrbank ram_bank = { |
483 |
ram_lget, ram_wget, ram_bget, |
484 |
ram_lput, ram_wput, ram_bput, |
485 |
ram_xlate |
486 |
}; |
487 |
|
488 |
addrbank ram24_bank = { |
489 |
ram24_lget, ram24_wget, ram24_bget, |
490 |
ram24_lput, ram24_wput, ram24_bput, |
491 |
ram24_xlate |
492 |
}; |
493 |
|
494 |
addrbank rom_bank = { |
495 |
rom_lget, rom_wget, rom_bget, |
496 |
rom_lput, rom_wput, rom_bput, |
497 |
rom_xlate |
498 |
}; |
499 |
|
500 |
addrbank rom24_bank = { |
501 |
rom24_lget, rom24_wget, rom24_bget, |
502 |
rom_lput, rom_wput, rom_bput, |
503 |
rom24_xlate |
504 |
}; |
505 |
|
506 |
addrbank frame_direct_bank = { |
507 |
frame_direct_lget, frame_direct_wget, frame_direct_bget, |
508 |
frame_direct_lput, frame_direct_wput, frame_direct_bput, |
509 |
frame_xlate |
510 |
}; |
511 |
|
512 |
addrbank frame_host_555_bank = { |
513 |
frame_host_555_lget, frame_host_555_wget, frame_direct_bget, |
514 |
frame_host_555_lput, frame_host_555_wput, frame_direct_bput, |
515 |
frame_xlate |
516 |
}; |
517 |
|
518 |
addrbank frame_host_565_bank = { |
519 |
frame_host_565_lget, frame_host_565_wget, frame_direct_bget, |
520 |
frame_host_565_lput, frame_host_565_wput, frame_direct_bput, |
521 |
frame_xlate |
522 |
}; |
523 |
|
524 |
addrbank frame_host_888_bank = { |
525 |
frame_host_888_lget, frame_direct_wget, frame_direct_bget, |
526 |
frame_host_888_lput, frame_direct_wput, frame_direct_bput, |
527 |
frame_xlate |
528 |
}; |
529 |
|
530 |
void memory_init(void) |
531 |
{ |
532 |
for(long i=0; i<65536; i++) |
533 |
put_mem_bank(i<<16, &dummy_bank); |
534 |
|
535 |
// Limit RAM size to not overlap ROM |
536 |
uint32 ram_size = RAMSize > ROMBaseMac ? ROMBaseMac : RAMSize; |
537 |
|
538 |
RAMBaseDiff = (uintptr)RAMBaseHost - (uintptr)RAMBaseMac; |
539 |
ROMBaseDiff = (uintptr)ROMBaseHost - (uintptr)ROMBaseMac; |
540 |
FrameBaseDiff = (uintptr)MacFrameBaseHost - (uintptr)MacFrameBaseMac; |
541 |
|
542 |
// Map RAM and ROM |
543 |
if (TwentyFourBitAddressing) { |
544 |
map_banks(&ram24_bank, RAMBaseMac >> 16, ram_size >> 16); |
545 |
map_banks(&rom24_bank, ROMBaseMac >> 16, ROMSize >> 16); |
546 |
} else { |
547 |
map_banks(&ram_bank, RAMBaseMac >> 16, ram_size >> 16); |
548 |
map_banks(&rom_bank, ROMBaseMac >> 16, ROMSize >> 16); |
549 |
} |
550 |
|
551 |
// Map frame buffer |
552 |
switch (MacFrameLayout) { |
553 |
case FLAYOUT_DIRECT: |
554 |
map_banks(&frame_direct_bank, MacFrameBaseMac >> 16, (MacFrameSize >> 16) + 1); |
555 |
break; |
556 |
case FLAYOUT_HOST_555: |
557 |
map_banks(&frame_host_555_bank, MacFrameBaseMac >> 16, (MacFrameSize >> 16) + 1); |
558 |
break; |
559 |
case FLAYOUT_HOST_565: |
560 |
map_banks(&frame_host_565_bank, MacFrameBaseMac >> 16, (MacFrameSize >> 16) + 1); |
561 |
break; |
562 |
case FLAYOUT_HOST_888: |
563 |
map_banks(&frame_host_888_bank, MacFrameBaseMac >> 16, (MacFrameSize >> 16) + 1); |
564 |
break; |
565 |
} |
566 |
} |
567 |
|
568 |
void map_banks(addrbank *bank, int start, int size) |
569 |
{ |
570 |
int bnr; |
571 |
unsigned long int hioffs = 0, endhioffs = 0x100; |
572 |
|
573 |
if (start >= 0x100) { |
574 |
for (bnr = start; bnr < start + size; bnr++) |
575 |
put_mem_bank (bnr << 16, bank); |
576 |
return; |
577 |
} |
578 |
if (TwentyFourBitAddressing) endhioffs = 0x10000; |
579 |
for (hioffs = 0; hioffs < endhioffs; hioffs += 0x100) |
580 |
for (bnr = start; bnr < start+size; bnr++) |
581 |
put_mem_bank((bnr + hioffs) << 16, bank); |
582 |
} |
583 |
|
584 |
#endif /* !REAL_ADDRESSING && !DIRECT_ADDRESSING */ |
585 |
|