|
|
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: #ifdef JIT
20: extern int special_mem;
21: #define S_READ 1
22: #define S_WRITE 2
23:
24: extern uae_u8 *cache_alloc (int);
25: extern void cache_free (uae_u8*);
26: #endif
27:
28: #define call_mem_get_func(func, addr) ((*func)(addr))
29: #define call_mem_put_func(func, addr, v) ((*func)(addr, v))
30:
31: #define NEXT_SCREEN_SIZE 0x00040000
32: extern uae_u8 NEXTVideo[256*1024];
33:
34:
35: /* Enabling this adds one additional native memory reference per 68k memory
36: * access, but saves one shift (on the x86). Enabling this is probably
37: * better for the cache. My favourite benchmark (PP2) doesn't show a
38: * difference, so I leave this enabled. */
39: #if 1 || defined SAVE_MEMORY
40: #define SAVE_MEMORY_BANKS
41: #endif
42:
43: extern void memory_hardreset (void);
44:
45: typedef uae_u32 (*mem_get_func)(uaecptr) REGPARAM;
46: typedef void (*mem_put_func)(uaecptr, uae_u32) REGPARAM;
47: typedef uae_u8 *(*xlate_func)(uaecptr) REGPARAM;
48: typedef int (*check_func)(uaecptr, uae_u32) REGPARAM;
49:
50: extern char *address_space, *good_address_map;
51:
52: extern uae_u32 wait_cpu_cycle_read (uaecptr addr, int mode);
53: extern void wait_cpu_cycle_write (uaecptr addr, int mode, uae_u32 v);
54: extern uae_u32 wait_cpu_cycle_read_ce020 (uaecptr addr, int mode);
55: extern void wait_cpu_cycle_write_ce020 (uaecptr addr, int mode, uae_u32 v);
56:
57: enum { ABFLAG_UNK = 0, ABFLAG_RAM = 1, ABFLAG_ROM = 2, ABFLAG_ROMIN = 4, ABFLAG_IO = 8, ABFLAG_NONE = 16, ABFLAG_SAFE = 32 };
58: typedef struct {
59: /* These ones should be self-explanatory... */
60: mem_get_func lget, wget, bget;
61: mem_put_func lput, wput, bput;
62: /* Use xlateaddr to translate an Amiga address to a uae_u8 * that can
63: * be used to address memory without calling the wget/wput functions.
64: * This doesn't work for all memory banks, so this function may call
65: * abort(). */
66: xlate_func xlateaddr;
67: /* To prevent calls to abort(), use check before calling xlateaddr.
68: * It checks not only that the memory bank can do xlateaddr, but also
69: * that the pointer points to an area of at least the specified size.
70: * This is used for example to translate bitplane pointers in custom.c */
71: check_func check;
72: /* For those banks that refer to real memory, we can save the whole trouble
73: of going through function calls, and instead simply grab the memory
74: ourselves. This holds the memory address where the start of memory is
75: for this particular bank. */
76: uae_u8 *baseaddr;
77: TCHAR *name;
78: /* for instruction opcode/operand fetches */
79: mem_get_func lgeti, wgeti;
80: int flags;
81: } addrbank;
82:
83: #define CE_MEMBANK_FAST 0
84: #define CE_MEMBANK_CHIP 1
85: #define CE_MEMBANK_CIA 2
86: #define CE_MEMBANK_FAST16BIT 3
87: extern uae_u8 ce_banktype[65536], ce_cachable[65536];
88:
89:
90: #define bankindex(addr) (((uaecptr)(addr)) >> 16)
91:
92: #ifdef SAVE_MEMORY_BANKS
93: extern addrbank *mem_banks[65536];
94: #define get_mem_bank(addr) (*mem_banks[bankindex(addr)])
95: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = (b))
96: #else
97: extern addrbank mem_banks[65536];
98: #define get_mem_bank(addr) (mem_banks[bankindex(addr)])
99: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = *(b))
100: #endif
101:
102: extern void memory_init(uae_u32 nNewNEXTMemSize);
103: extern void memory_uninit (void);
104: extern void map_banks(addrbank *bank, int first, int count);
105:
106: #ifndef NO_INLINE_MEMORY_ACCESS
107:
108: #define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr))
109: #define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr))
110: #define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr))
111: #define longput(addr,l) (call_mem_put_func(get_mem_bank(addr).lput, addr, l))
112: #define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w))
113: #define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b))
114:
115: #else
116:
117: extern uae_u32 alongget(uaecptr addr);
118: extern uae_u32 awordget(uaecptr addr);
119: extern uae_u32 longget(uaecptr addr);
120: extern uae_u32 wordget(uaecptr addr);
121: extern uae_u32 byteget(uaecptr addr);
122: extern void longput(uaecptr addr, uae_u32 l);
123: extern void wordput(uaecptr addr, uae_u32 w);
124: extern void byteput(uaecptr addr, uae_u32 b);
125:
126: #endif
127:
128: #define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr))
129: #define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr))
130: #define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr))
131: #define longgeti(addr) (call_mem_get_func(get_mem_bank(addr).lgeti, addr))
132: #define wordgeti(addr) (call_mem_get_func(get_mem_bank(addr).wgeti, addr))
133: #define longput(addr,l) (call_mem_put_func(get_mem_bank(addr).lput, addr, l))
134: #define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w))
135: #define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b))
136:
137: static inline uae_u32 get_long(uaecptr addr)
138: {
139: return longget(addr);
140: }
141:
142: static inline uae_u32 get_word(uaecptr addr)
143: {
144: return wordget(addr);
145: }
146:
147: static inline uae_u32 get_byte(uaecptr addr)
148: {
149: return byteget(addr);
150: }
151:
152: static inline void put_long(uaecptr addr, uae_u32 l)
153: {
154: longput(addr, l);
155: }
156:
157: static inline void put_word(uaecptr addr, uae_u32 w)
158: {
159: wordput(addr, w);
160: }
161:
162: static inline void put_byte(uaecptr addr, uae_u32 b)
163: {
164: byteput(addr, b);
165: }
166:
167: static inline uae_u8 *get_real_address(uaecptr addr)
168: {
169: return get_mem_bank(addr).xlateaddr(addr);
170: }
171:
172: static inline int valid_address(uaecptr addr, uae_u32 size)
173: {
174: return get_mem_bank(addr).check(addr, size);
175: }
176:
177: static inline uae_u32 get_longi(uaecptr addr)
178: {
179: return longgeti (addr);
180: }
181:
182: static inline uae_u32 get_wordi(uaecptr addr)
183: {
184: return wordgeti (addr);
185: }
186:
187: #endif /* UAE_MEMORY_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.