|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * memory management
5: *
6: * Copyright 1995 Bernd Schmidt
7: *
8: * Adaptation to Hatari by Thomas Huth
9: *
10: * This file is distributed under the GNU Public License, version 2 or at
11: * your option any later version. Read the file gpl.txt for details.
12: */
13:
14: #ifndef UAE_MEMORY_H
15: #define UAE_MEMORY_H
16:
17: #include "maccess.h"
18:
19:
20: /* Enabling this adds one additional native memory reference per 68k memory
21: * access, but saves one shift (on the x86). Enabling this is probably
22: * better for the cache. My favourite benchmark (PP2) doesn't show a
23: * difference, so I leave this enabled. */
24: #if 1 || defined SAVE_MEMORY
25: #define SAVE_MEMORY_BANKS
26: #endif
27:
28:
29: typedef uae_u32 (*mem_get_func)(uaecptr) REGPARAM;
30: typedef void (*mem_put_func)(uaecptr, uae_u32) REGPARAM;
31: typedef uae_u8 *(*xlate_func)(uaecptr) REGPARAM;
32: typedef int (*check_func)(uaecptr, uae_u32) REGPARAM;
33:
34: extern char *address_space, *good_address_map;
35:
36: #undef DIRECT_MEMFUNCS_SUCCESSFUL
37:
38:
39: typedef struct {
40: /* These ones should be self-explanatory... */
41: mem_get_func lget, wget, bget;
42: mem_put_func lput, wput, bput;
43: /* Use xlateaddr to translate an Atari address to a uae_u8 * that can
44: * be used to address memory without calling the wget/wput functions.
45: * This doesn't work for all memory banks, so this function may call
46: * abort(). */
47: xlate_func xlateaddr;
48: /* To prevent calls to abort(), use check before calling xlateaddr.
49: * It checks not only that the memory bank can do xlateaddr, but also
50: * that the pointer points to an area of at least the specified size.
51: * This is used for example to translate bitplane pointers in custom.c */
52: check_func check;
53: } addrbank;
54:
55:
56: #define bankindex(addr) (((uaecptr)(addr)) >> 16)
57:
58: #ifdef SAVE_MEMORY_BANKS
59: extern addrbank *mem_banks[65536];
60: #define get_mem_bank(addr) (*mem_banks[bankindex(addr)])
61: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = (b))
62: #else
63: extern addrbank mem_banks[65536];
64: #define get_mem_bank(addr) (mem_banks[bankindex(addr)])
65: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = *(b))
66: #endif
67:
68: extern void memory_init(uae_u32 f_STMemSize, uae_u32 f_TTMemSize, uae_u32 f_RomMemStart);
69: extern void memory_uninit (void);
70: extern void map_banks(addrbank *bank, int first, int count);
71:
72: #ifndef NO_INLINE_MEMORY_ACCESS
73:
74: #define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr))
75: #define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr))
76: #define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr))
77: #define longput(addr,l) (call_mem_put_func(get_mem_bank(addr).lput, addr, l))
78: #define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w))
79: #define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b))
80:
81: #else
82:
83: extern uae_u32 alongget(uaecptr addr);
84: extern uae_u32 awordget(uaecptr addr);
85: extern uae_u32 longget(uaecptr addr);
86: extern uae_u32 wordget(uaecptr addr);
87: extern uae_u32 byteget(uaecptr addr);
88: extern void longput(uaecptr addr, uae_u32 l);
89: extern void wordput(uaecptr addr, uae_u32 w);
90: extern void byteput(uaecptr addr, uae_u32 b);
91:
92: #endif
93:
94: #ifndef MD_HAVE_MEM_1_FUNCS
95:
96: #define longget_1 longget
97: #define wordget_1 wordget
98: #define byteget_1 byteget
99: #define longput_1 longput
100: #define wordput_1 wordput
101: #define byteput_1 byteput
102:
103: #endif
104:
105: STATIC_INLINE uae_u32 get_long(uaecptr addr)
106: {
107: return longget_1(addr);
108: }
109: STATIC_INLINE uae_u32 get_word(uaecptr addr)
110: {
111: return wordget_1(addr);
112: }
113: STATIC_INLINE uae_u32 get_byte(uaecptr addr)
114: {
115: return byteget_1(addr);
116: }
117: STATIC_INLINE void put_long(uaecptr addr, uae_u32 l)
118: {
119: longput_1(addr, l);
120: }
121: STATIC_INLINE void put_word(uaecptr addr, uae_u32 w)
122: {
123: wordput_1(addr, w);
124: }
125: STATIC_INLINE void put_byte(uaecptr addr, uae_u32 b)
126: {
127: byteput_1(addr, b);
128: }
129:
130: STATIC_INLINE uae_u8 *get_real_address(uaecptr addr)
131: {
132: return get_mem_bank(addr).xlateaddr(addr);
133: }
134:
135: STATIC_INLINE int valid_address(uaecptr addr, uae_u32 size)
136: {
137: return get_mem_bank(addr).check(addr, size);
138: }
139:
140:
141: #endif /* UAE_MEMORY_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.