|
|
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: #define call_mem_get_func(func, addr) ((*func)(addr))
20: #define call_mem_put_func(func, addr, v) ((*func)(addr, v))
21:
22: #define NEXT_SCREEN_SIZE 0x00040000
23: extern uae_u8 NEXTVideo[256*1024];
24:
25:
26: /* Enabling this adds one additional native memory reference per 68k memory
27: * access, but saves one shift (on the x86). Enabling this is probably
28: * better for the cache. My favourite benchmark (PP2) doesn't show a
29: * difference, so I leave this enabled. */
30: #if 1 || defined SAVE_MEMORY
31: #define SAVE_MEMORY_BANKS
32: #endif
33:
34:
35: typedef uae_u32 (*mem_get_func)(uaecptr) REGPARAM;
36: typedef void (*mem_put_func)(uaecptr, uae_u32) REGPARAM;
37: typedef uae_u8 *(*xlate_func)(uaecptr) REGPARAM;
38: typedef int (*check_func)(uaecptr, uae_u32) REGPARAM;
39:
40: extern char *address_space, *good_address_map;
41:
42:
43: typedef struct {
44: /* These ones should be self-explanatory... */
45: mem_get_func lget, wget, bget;
46: mem_put_func lput, wput, bput;
47: /* Use xlateaddr to translate an Atari address to a uae_u8 * that can
48: * be used to address memory without calling the wget/wput functions.
49: * This doesn't work for all memory banks, so this function may call
50: * abort(). */
51: xlate_func xlateaddr;
52: /* To prevent calls to abort(), use check before calling xlateaddr.
53: * It checks not only that the memory bank can do xlateaddr, but also
54: * that the pointer points to an area of at least the specified size.
55: * This is used for example to translate bitplane pointers in custom.c */
56: check_func check;
57: } addrbank;
58:
59:
60: #define bankindex(addr) (((uaecptr)(addr)) >> 16)
61:
62: #ifdef SAVE_MEMORY_BANKS
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: #else
67: extern addrbank mem_banks[65536];
68: #define get_mem_bank(addr) (mem_banks[bankindex(addr)])
69: #define put_mem_bank(addr, b) (mem_banks[bankindex(addr)] = *(b))
70: #endif
71:
72: extern void memory_init(uae_u32 nNewNEXTMemSize);
73: extern void memory_uninit (void);
74: extern void map_banks(addrbank *bank, int first, int count);
75:
76: #ifndef NO_INLINE_MEMORY_ACCESS
77:
78: #define longget(addr) (call_mem_get_func(get_mem_bank(addr).lget, addr))
79: #define wordget(addr) (call_mem_get_func(get_mem_bank(addr).wget, addr))
80: #define byteget(addr) (call_mem_get_func(get_mem_bank(addr).bget, addr))
81: #define longput(addr,l) (call_mem_put_func(get_mem_bank(addr).lput, addr, l))
82: #define wordput(addr,w) (call_mem_put_func(get_mem_bank(addr).wput, addr, w))
83: #define byteput(addr,b) (call_mem_put_func(get_mem_bank(addr).bput, addr, b))
84:
85: #else
86:
87: extern uae_u32 alongget(uaecptr addr);
88: extern uae_u32 awordget(uaecptr addr);
89: extern uae_u32 longget(uaecptr addr);
90: extern uae_u32 wordget(uaecptr addr);
91: extern uae_u32 byteget(uaecptr addr);
92: extern void longput(uaecptr addr, uae_u32 l);
93: extern void wordput(uaecptr addr, uae_u32 w);
94: extern void byteput(uaecptr addr, uae_u32 b);
95:
96: #endif
97:
98:
99: static inline uae_u32 get_long(uaecptr addr)
100: {
101: return longget(addr);
102: }
103:
104: static inline uae_u32 get_word(uaecptr addr)
105: {
106: return wordget(addr);
107: }
108:
109: static inline uae_u32 get_byte(uaecptr addr)
110: {
111: return byteget(addr);
112: }
113:
114: static inline void put_long(uaecptr addr, uae_u32 l)
115: {
116: longput(addr, l);
117: }
118:
119: static inline void put_word(uaecptr addr, uae_u32 w)
120: {
121: wordput(addr, w);
122: }
123:
124: static inline void put_byte(uaecptr addr, uae_u32 b)
125: {
126: byteput(addr, b);
127: }
128:
129: static inline uae_u8 *get_real_address(uaecptr addr)
130: {
131: return get_mem_bank(addr).xlateaddr(addr);
132: }
133:
134: static inline int valid_address(uaecptr addr, uae_u32 size)
135: {
136: return get_mem_bank(addr).check(addr, size);
137: }
138:
139:
140: #endif /* UAE_MEMORY_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.