ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/uae_cpu/memory.cpp
(Generate patch)

Comparing BasiliskII/src/uae_cpu/memory.cpp (file contents):
Revision 1.1.1.1 by cebix, 1999-10-03T14:16:26Z vs.
Revision 1.10 by asvitkine, 2012-03-30T01:25:46Z

# Line 1 | Line 1
1 < /*
2 <  * UAE - The Un*x Amiga Emulator
3 <  *
4 <  * Memory management
5 <  *
6 <  * (c) 1995 Bernd Schmidt
7 <  */
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>
# Line 12 | Line 26
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 < #include "main.h"
37 < #include "video.h"
36 >
37 > #if !REAL_ADDRESSING && !DIRECT_ADDRESSING
38  
39   static bool illegal_mem = false;
40  
# Line 27 | Line 44 | addrbank *mem_banks[65536];
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 < __inline__ uae_u32 longget (uaecptr addr)
54 > uae_u32 longget (uaecptr addr)
55   {
56      return call_mem_get_func (get_mem_bank (addr).lget, addr);
57   }
58 < __inline__ uae_u32 wordget (uaecptr addr)
58 > uae_u32 wordget (uaecptr addr)
59   {
60      return call_mem_get_func (get_mem_bank (addr).wget, addr);
61   }
62 < __inline__ uae_u32 byteget (uaecptr addr)
62 > uae_u32 byteget (uaecptr addr)
63   {
64      return call_mem_get_func (get_mem_bank (addr).bget, addr);
65   }
66 < __inline__ void longput (uaecptr addr, uae_u32 l)
66 > void longput (uaecptr addr, uae_u32 l)
67   {
68      call_mem_put_func (get_mem_bank (addr).lput, addr, l);
69   }
70 < __inline__ void wordput (uaecptr addr, uae_u32 w)
70 > void wordput (uaecptr addr, uae_u32 w)
71   {
72      call_mem_put_func (get_mem_bank (addr).wput, addr, w);
73   }
74 < __inline__ void byteput (uaecptr addr, uae_u32 b)
74 > void byteput (uaecptr addr, uae_u32 b)
75   {
76      call_mem_put_func (get_mem_bank (addr).bput, addr, b);
77   }
# Line 62 | Line 85 | static uae_u32 REGPARAM2 dummy_bget (uae
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;
65 static int REGPARAM2 dummy_check (uaecptr addr, uae_u32 size) REGPARAM;
88  
89   uae_u32 REGPARAM2 dummy_lget (uaecptr addr)
90   {
# Line 104 | Line 126 | void REGPARAM2 dummy_bput (uaecptr addr,
126          write_log ("Illegal bput at %08lx\n", addr);
127   }
128  
107 int REGPARAM2 dummy_check (uaecptr addr, uae_u32 size)
108 {
109    if (illegal_mem)
110        write_log ("Illegal check at %08lx\n", addr);
111
112    return 0;
113 }
114
129   /* Mac RAM (32 bit addressing) */
130  
131   static uae_u32 REGPARAM2 ram_lget(uaecptr) REGPARAM;
# Line 120 | Line 134 | static uae_u32 REGPARAM2 ram_bget(uaecpt
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;
123 static int REGPARAM2 ram_check(uaecptr addr, uae_u32 size) REGPARAM;
137   static uae_u8 *REGPARAM2 ram_xlate(uaecptr addr) REGPARAM;
138  
139 < static uae_u32 RAMBaseDiff;     // RAMBaseHost - RAMBaseMac
139 > static uintptr RAMBaseDiff;     // RAMBaseHost - RAMBaseMac
140  
141   uae_u32 REGPARAM2 ram_lget(uaecptr addr)
142   {
# Line 163 | Line 176 | void REGPARAM2 ram_bput(uaecptr addr, ua
176          *(uae_u8 *)(RAMBaseDiff + addr) = b;
177   }
178  
166 int REGPARAM2 ram_check(uaecptr addr, uae_u32 size)
167 {
168    return (addr - RAMBaseMac + size) < RAMSize;
169 }
170
179   uae_u8 *REGPARAM2 ram_xlate(uaecptr addr)
180   {
181      return (uae_u8 *)(RAMBaseDiff + addr);
# Line 181 | Line 189 | static uae_u32 REGPARAM2 ram24_bget(uaec
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;
184 static int REGPARAM2 ram24_check(uaecptr addr, uae_u32 size) REGPARAM;
192   static uae_u8 *REGPARAM2 ram24_xlate(uaecptr addr) REGPARAM;
193  
194   uae_u32 REGPARAM2 ram24_lget(uaecptr addr)
# Line 222 | Line 229 | void REGPARAM2 ram24_bput(uaecptr addr,
229          *(uae_u8 *)(RAMBaseDiff + (addr & 0xffffff)) = b;
230   }
231  
225 int REGPARAM2 ram24_check(uaecptr addr, uae_u32 size)
226 {
227    return ((addr & 0xffffff) - RAMBaseMac + size) < RAMSize;
228 }
229
232   uae_u8 *REGPARAM2 ram24_xlate(uaecptr addr)
233   {
234      return (uae_u8 *)(RAMBaseDiff + (addr & 0xffffff));
# Line 240 | Line 242 | static uae_u32 REGPARAM2 rom_bget(uaecpt
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;
243 static int REGPARAM2 rom_check(uaecptr addr, uae_u32 size) REGPARAM;
245   static uae_u8 *REGPARAM2 rom_xlate(uaecptr addr) REGPARAM;
246  
247 < static uae_u32 ROMBaseDiff;     // ROMBaseHost - ROMBaseMac
247 > static uintptr ROMBaseDiff;     // ROMBaseHost - ROMBaseMac
248  
249   uae_u32 REGPARAM2 rom_lget(uaecptr addr)
250   {
# Line 282 | Line 283 | void REGPARAM2 rom_bput(uaecptr addr, ua
283          write_log ("Illegal ROM bput at %08lx\n", addr);
284   }
285  
285 int REGPARAM2 rom_check(uaecptr addr, uae_u32 size)
286 {
287    return (addr - ROMBaseMac + size) < ROMSize;
288 }
289
286   uae_u8 *REGPARAM2 rom_xlate(uaecptr addr)
287   {
288      return (uae_u8 *)(ROMBaseDiff + addr);
# Line 297 | Line 293 | uae_u8 *REGPARAM2 rom_xlate(uaecptr addr
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;
300 static int REGPARAM2 rom24_check(uaecptr addr, uae_u32 size) REGPARAM;
296   static uae_u8 *REGPARAM2 rom24_xlate(uaecptr addr) REGPARAM;
297  
298   uae_u32 REGPARAM2 rom24_lget(uaecptr addr)
# Line 319 | Line 314 | uae_u32 REGPARAM2 rom24_bget(uaecptr add
314      return (uae_u32)*(uae_u8 *)(ROMBaseDiff + (addr & 0xffffff));
315   }
316  
322 int REGPARAM2 rom24_check(uaecptr addr, uae_u32 size)
323 {
324    return ((addr & 0xffffff) - ROMBaseMac + size) < ROMSize;
325 }
326
317   uae_u8 *REGPARAM2 rom24_xlate(uaecptr addr)
318   {
319      return (uae_u8 *)(ROMBaseDiff + (addr & 0xffffff));
# Line 351 | Line 341 | static void REGPARAM2 frame_host_565_wpu
341   static uae_u32 REGPARAM2 frame_host_888_lget(uaecptr) REGPARAM;
342   static void REGPARAM2 frame_host_888_lput(uaecptr, uae_u32) REGPARAM;
343  
354 static int REGPARAM2 frame_check(uaecptr addr, uae_u32 size) REGPARAM;
344   static uae_u8 *REGPARAM2 frame_xlate(uaecptr addr) REGPARAM;
345  
346 < static uae_u32 FrameBaseDiff;   // MacFrameBaseHost - MacFrameBaseMac
346 > static uintptr FrameBaseDiff;   // MacFrameBaseHost - MacFrameBaseMac
347  
348   uae_u32 REGPARAM2 frame_direct_lget(uaecptr addr)
349   {
# Line 399 | Line 388 | uae_u32 REGPARAM2 frame_host_555_lget(ua
388      uae_u32 *m, l;
389      m = (uae_u32 *)(FrameBaseDiff + addr);
390      l = *m;
391 <    return (l >> 16) | (l << 16);
391 >        return swap_words(l);
392   }
393  
394   uae_u32 REGPARAM2 frame_host_555_wget(uaecptr addr)
# Line 413 | Line 402 | void REGPARAM2 frame_host_555_lput(uaecp
402   {
403      uae_u32 *m;
404      m = (uae_u32 *)(FrameBaseDiff + addr);
405 <    *m = (l >> 16) | (l << 16);
405 >    *m = swap_words(l);
406   }
407  
408   void REGPARAM2 frame_host_555_wput(uaecptr addr, uae_u32 w)
# Line 429 | Line 418 | uae_u32 REGPARAM2 frame_host_565_lget(ua
418      m = (uae_u32 *)(FrameBaseDiff + addr);
419      l = *m;
420      l = (l & 0x001f001f) | ((l >> 1) & 0x7fe07fe0);
421 <    return (l >> 16) | (l << 16);
421 >    return swap_words(l);
422   }
423  
424   uae_u32 REGPARAM2 frame_host_565_wget(uaecptr addr)
# Line 445 | Line 434 | void REGPARAM2 frame_host_565_lput(uaecp
434      uae_u32 *m;
435      m = (uae_u32 *)(FrameBaseDiff + addr);
436      l = (l & 0x001f001f) | ((l << 1) & 0xffc0ffc0);
437 <    *m = (l >> 16) | (l << 16);
437 >    *m = swap_words(l);
438   }
439  
440   void REGPARAM2 frame_host_565_wput(uaecptr addr, uae_u32 w)
# Line 469 | Line 458 | void REGPARAM2 frame_host_888_lput(uaecp
458      *m = l;
459   }
460  
472 int REGPARAM2 frame_check(uaecptr addr, uae_u32 size)
473 {
474    return (addr - MacFrameBaseMac + size) < MacFrameSize;
475 }
476
461   uae_u8 *REGPARAM2 frame_xlate(uaecptr addr)
462   {
463      return (uae_u8 *)(FrameBaseDiff + addr);
# Line 481 | Line 465 | uae_u8 *REGPARAM2 frame_xlate(uaecptr ad
465  
466   /* Default memory access functions */
467  
484 int REGPARAM2 default_check (uaecptr a, uae_u32 b)
485 {
486    return 0;
487 }
488
468   uae_u8 *REGPARAM2 default_xlate (uaecptr a)
469   {
470      write_log("Your Mac program just did something terribly stupid\n");
# Line 497 | Line 476 | uae_u8 *REGPARAM2 default_xlate (uaecptr
476   addrbank dummy_bank = {
477      dummy_lget, dummy_wget, dummy_bget,
478      dummy_lput, dummy_wput, dummy_bput,
479 <    default_xlate, dummy_check
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, ram_check
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, ram24_check
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, rom_check
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, rom24_check
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, frame_check
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, frame_check
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, frame_check
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, frame_check
527 >    frame_xlate
528   };
529  
530   void memory_init(void)
531   {
532 <        int i;
554 <        for(i=0; i<65536; i++)
532 >        for(long i=0; i<65536; i++)
533                  put_mem_bank(i<<16, &dummy_bank);
534  
557        RAMBaseDiff = (uae_u32)RAMBaseHost - (uae_u32)RAMBaseMac;
558        ROMBaseDiff = (uae_u32)ROMBaseHost - (uae_u32)ROMBaseMac;
559        FrameBaseDiff = (uae_u32)MacFrameBaseHost - (uae_u32)MacFrameBaseMac;
560
535          // Limit RAM size to not overlap ROM
562 #if REAL_ADDRESSING
563        uint32 ram_size = RAMSize;
564 #else
536          uint32 ram_size = RAMSize > ROMBaseMac ? ROMBaseMac : RAMSize;
566 #endif
537  
538 <        // RAM and ROM
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);
# Line 574 | Line 548 | void memory_init(void)
548                  map_banks(&rom_bank, ROMBaseMac >> 16, ROMSize >> 16);
549          }
550  
551 <        // Frame buffer
551 >        // Map frame buffer
552          switch (MacFrameLayout) {
553                  case FLAYOUT_DIRECT:
554                          map_banks(&frame_direct_bank, MacFrameBaseMac >> 16, (MacFrameSize >> 16) + 1);
# Line 606 | Line 580 | void map_banks(addrbank *bank, int start
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 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines