(PSP/PS3) Resolve namespace conflict with memcpy16 for PS3 -
[picodrive.git] / pico / memory.h
CommitLineData
af37bca8 1// memory map related stuff
2
3typedef unsigned char u8;
4typedef unsigned short u16;
5typedef unsigned int u32;
bcf65fd6 6typedef unsigned long uptr; // unsigned pointer-sized int
af37bca8 7
8#define M68K_MEM_SHIFT 16
45f2f245 9// minimum size we can map
10#define M68K_BANK_SIZE (1 << M68K_MEM_SHIFT)
11#define M68K_BANK_MASK (M68K_BANK_SIZE - 1)
af37bca8 12
bcf65fd6 13extern uptr m68k_read8_map [0x1000000 >> M68K_MEM_SHIFT];
14extern uptr m68k_read16_map [0x1000000 >> M68K_MEM_SHIFT];
15extern uptr m68k_write8_map [0x1000000 >> M68K_MEM_SHIFT];
16extern uptr m68k_write16_map[0x1000000 >> M68K_MEM_SHIFT];
af37bca8 17
bcf65fd6 18extern uptr s68k_read8_map [0x1000000 >> M68K_MEM_SHIFT];
19extern uptr s68k_read16_map [0x1000000 >> M68K_MEM_SHIFT];
20extern uptr s68k_write8_map [0x1000000 >> M68K_MEM_SHIFT];
21extern uptr s68k_write16_map[0x1000000 >> M68K_MEM_SHIFT];
af37bca8 22
b8a1c09a 23// top-level handlers that cores can use
24// (or alternatively build them into themselves)
25// XXX: unhandled: *16 and *32 might cross the bank boundaries
26typedef u32 (cpu68k_read_f)(u32 a);
27typedef void (cpu68k_write_f)(u32 a, u32 d);
28
77e58d93 29extern u32 m68k_read8(u32 a);
30extern u32 m68k_read16(u32 a);
31extern void m68k_write8(u32 a, u8 d);
32extern void m68k_write16(u32 a, u16 d);
33
b8a1c09a 34// z80
35#define Z80_MEM_SHIFT 13
36extern uptr z80_read_map [0x10000 >> Z80_MEM_SHIFT];
37extern uptr z80_write_map[0x10000 >> Z80_MEM_SHIFT];
38typedef unsigned char (z80_read_f)(unsigned short a);
39typedef void (z80_write_f)(unsigned int a, unsigned char data);
40
bcf65fd6 41void z80_map_set(uptr *map, int start_addr, int end_addr,
0ace9b9a 42 const void *func_or_mh, int is_func);
bcf65fd6 43void cpu68k_map_set(uptr *map, int start_addr, int end_addr,
0ace9b9a 44 const void *func_or_mh, int is_func);
af37bca8 45void cpu68k_map_all_ram(int start_addr, int end_addr, void *ptr, int is_sub);
46void m68k_map_unmap(int start_addr, int end_addr);
47
add51c49 48#define MAP_FLAG ((uptr)1 << (sizeof(uptr) * 8 - 1))
49#define map_flag_set(x) ((x) & MAP_FLAG)
af37bca8 50
51#define MAKE_68K_READ8(name, map) \
52u32 name(u32 a) \
53{ \
bcf65fd6 54 uptr v; \
af37bca8 55 a &= 0x00ffffff; \
56 v = map[a >> M68K_MEM_SHIFT]; \
b8a1c09a 57 if (map_flag_set(v)) \
af37bca8 58 return ((cpu68k_read_f *)(v << 1))(a); \
59 else \
60 return *(u8 *)((v << 1) + (a ^ 1)); \
61}
62
63#define MAKE_68K_READ16(name, map) \
64u32 name(u32 a) \
65{ \
bcf65fd6 66 uptr v; \
af37bca8 67 a &= 0x00fffffe; \
68 v = map[a >> M68K_MEM_SHIFT]; \
b8a1c09a 69 if (map_flag_set(v)) \
af37bca8 70 return ((cpu68k_read_f *)(v << 1))(a); \
71 else \
72 return *(u16 *)((v << 1) + a); \
73}
74
75#define MAKE_68K_READ32(name, map) \
76u32 name(u32 a) \
77{ \
bcf65fd6 78 uptr v, vs; \
af37bca8 79 u32 d; \
80 a &= 0x00fffffe; \
81 v = map[a >> M68K_MEM_SHIFT]; \
82 vs = v << 1; \
b8a1c09a 83 if (map_flag_set(v)) { \
af37bca8 84 d = ((cpu68k_read_f *)vs)(a) << 16; \
85 d |= ((cpu68k_read_f *)vs)(a + 2); \
86 } \
87 else { \
88 u16 *m = (u16 *)(vs + a); \
89 d = (m[0] << 16) | m[1]; \
90 } \
91 return d; \
92}
93
94#define MAKE_68K_WRITE8(name, map) \
95void name(u32 a, u8 d) \
96{ \
bcf65fd6 97 uptr v; \
af37bca8 98 a &= 0x00ffffff; \
99 v = map[a >> M68K_MEM_SHIFT]; \
b8a1c09a 100 if (map_flag_set(v)) \
af37bca8 101 ((cpu68k_write_f *)(v << 1))(a, d); \
102 else \
103 *(u8 *)((v << 1) + (a ^ 1)) = d; \
104}
105
106#define MAKE_68K_WRITE16(name, map) \
107void name(u32 a, u16 d) \
108{ \
bcf65fd6 109 uptr v; \
af37bca8 110 a &= 0x00fffffe; \
111 v = map[a >> M68K_MEM_SHIFT]; \
b8a1c09a 112 if (map_flag_set(v)) \
af37bca8 113 ((cpu68k_write_f *)(v << 1))(a, d); \
114 else \
115 *(u16 *)((v << 1) + a) = d; \
116}
117
118#define MAKE_68K_WRITE32(name, map) \
119void name(u32 a, u32 d) \
120{ \
bcf65fd6 121 uptr v, vs; \
af37bca8 122 a &= 0x00fffffe; \
123 v = map[a >> M68K_MEM_SHIFT]; \
124 vs = v << 1; \
b8a1c09a 125 if (map_flag_set(v)) { \
af37bca8 126 ((cpu68k_write_f *)vs)(a, d >> 16); \
127 ((cpu68k_write_f *)vs)(a + 2, d); \
128 } \
129 else { \
130 u16 *m = (u16 *)(vs + a); \
131 m[0] = d >> 16; \
132 m[1] = d; \
133 } \
134}
135
00faec9c 136// 32x
137typedef struct {
138 uptr addr; // stores (membase >> 1) or ((handler >> 1) | (1<<31))
139 u32 mask;
140} sh2_memmap;