log unhandled io more clearly
[pcsx_rearmed.git] / libpcsxcore / new_dynarec / pcsxmem.c
CommitLineData
7e605697 1/*
274c4243 2 * (C) GraÅžvydas "notaz" Ignotas, 2010-2011
7e605697 3 *
4 * This work is licensed under the terms of GNU GPL version 2 or later.
5 * See the COPYING file in the top-level directory.
6 */
7
8#include <stdio.h>
9#include "../psxhw.h"
10#include "../cdrom.h"
11#include "../mdec.h"
ddbaf678 12#include "../gpu.h"
87e5b45f 13#include "../psxmem_map.h"
7e605697 14#include "emu_if.h"
15#include "pcsxmem.h"
16
5905989e 17#ifdef __thumb__
9f704290 18#error the dynarec is incompatible with Thumb functions,
19#error please add -marm to compile flags
5905989e 20#endif
21
7e605697 22//#define memprintf printf
23#define memprintf(...)
24
be516ebe 25static uintptr_t *mem_readtab;
26static uintptr_t *mem_writetab;
27static uintptr_t mem_iortab[(1+2+4) * 0x1000 / 4];
28static uintptr_t mem_iowtab[(1+2+4) * 0x1000 / 4];
679d5ee3 29static uintptr_t mem_ffrtab[(1+2+4) * 0x1000 / 4];
be516ebe 30static uintptr_t mem_ffwtab[(1+2+4) * 0x1000 / 4];
31//static uintptr_t mem_unmrtab[(1+2+4) * 0x1000 / 4];
32static uintptr_t mem_unmwtab[(1+2+4) * 0x1000 / 4];
33
34static
578c6882 35#ifdef __clang__
be516ebe 36// When this is called in a loop, and 'h' is a function pointer, clang will crash.
37__attribute__ ((noinline))
578c6882 38#endif
be516ebe 39void map_item(uintptr_t *out, const void *h, uintptr_t flag)
b1be1eee 40{
be516ebe 41 uintptr_t hv = (uintptr_t)h;
5905989e 42 if (hv & 1) {
f29fbd53 43 SysPrintf("FATAL: %p has LSB set\n", h);
5905989e 44 abort();
45 }
be516ebe 46 *out = (hv >> 1) | (flag << (sizeof(hv) * 8 - 1));
b1be1eee 47}
48
49// size must be power of 2, at least 4k
50#define map_l1_mem(tab, i, addr, size, base) \
679d5ee3 51 map_item(&tab[((u32)(addr) >> 12) + i], \
e3973c69 52 (u8 *)(base) - (u32)((addr) + ((i << 12) & ~(size - 1))), 0)
b1be1eee 53
54#define IOMEM32(a) (((a) & 0xfff) / 4)
55#define IOMEM16(a) (0x1000/4 + (((a) & 0xfff) / 2))
56#define IOMEM8(a) (0x1000/4 + 0x1000/2 + ((a) & 0xfff))
57
679d5ee3 58u32 zero_mem[0x1000/4];
59static u32 ffff_mem[0x1000/4];
7a481d40 60
679d5ee3 61static u32 read_mem_dummy(u32 addr)
7e605697 62{
679d5ee3 63 // use 'addr' and not 'address', yes the api is weird...
64 memprintf("unmapped r %08x @%08x %u\n", addr, psxRegs.pc, psxRegs.cycle);
65 return 0xffffffff;
7e605697 66}
67
b96d3df7 68static void write_mem_dummy(u32 data)
7e605697 69{
bc7c5acb 70 if (!(psxRegs.CP0.n.SR & (1 << 16)))
679d5ee3 71 memprintf("unmapped w %08x, %08x @%08x %u\n",
72 address, data, psxRegs.pc, psxRegs.cycle);
7e605697 73}
74
7e605697 75/* IO handlers */
76static u32 io_read_sio16()
77{
78 return sioRead8() | (sioRead8() << 8);
79}
80
81static u32 io_read_sio32()
82{
83 return sioRead8() | (sioRead8() << 8) | (sioRead8() << 16) | (sioRead8() << 24);
84}
85
86static void io_write_sio16(u32 value)
87{
88 sioWrite8((unsigned char)value);
89 sioWrite8((unsigned char)(value>>8));
90}
91
92static void io_write_sio32(u32 value)
93{
94 sioWrite8((unsigned char)value);
b96d3df7 95 sioWrite8((unsigned char)(value >> 8));
96 sioWrite8((unsigned char)(value >> 16));
97 sioWrite8((unsigned char)(value >> 24));
7e605697 98}
99
be516ebe 100#if !defined(DRC_DBG) && defined(__arm__)
19776aef 101
b1be1eee 102static void map_rcnt_rcount0(u32 mode)
103{
59fb0bb4 104 if (mode & 0x100) { // pixel clock
b1be1eee 105 map_item(&mem_iortab[IOMEM32(0x1100)], rcnt0_read_count_m1, 1);
106 map_item(&mem_iortab[IOMEM16(0x1100)], rcnt0_read_count_m1, 1);
107 }
108 else {
109 map_item(&mem_iortab[IOMEM32(0x1100)], rcnt0_read_count_m0, 1);
110 map_item(&mem_iortab[IOMEM16(0x1100)], rcnt0_read_count_m0, 1);
111 }
112}
113
114static void map_rcnt_rcount1(u32 mode)
115{
59fb0bb4 116 if (mode & 0x100) { // hcnt
b1be1eee 117 map_item(&mem_iortab[IOMEM32(0x1110)], rcnt1_read_count_m1, 1);
118 map_item(&mem_iortab[IOMEM16(0x1110)], rcnt1_read_count_m1, 1);
119 }
120 else {
121 map_item(&mem_iortab[IOMEM32(0x1110)], rcnt1_read_count_m0, 1);
122 map_item(&mem_iortab[IOMEM16(0x1110)], rcnt1_read_count_m0, 1);
123 }
124}
125
126static void map_rcnt_rcount2(u32 mode)
127{
128 if (mode & 0x01) { // gate
129 map_item(&mem_iortab[IOMEM32(0x1120)], &psxH[0x1000], 0);
130 map_item(&mem_iortab[IOMEM16(0x1120)], &psxH[0x1000], 0);
131 }
132 else if (mode & 0x200) { // clk/8
133 map_item(&mem_iortab[IOMEM32(0x1120)], rcnt2_read_count_m1, 1);
134 map_item(&mem_iortab[IOMEM16(0x1120)], rcnt2_read_count_m1, 1);
135 }
136 else {
137 map_item(&mem_iortab[IOMEM32(0x1120)], rcnt2_read_count_m0, 1);
138 map_item(&mem_iortab[IOMEM16(0x1120)], rcnt2_read_count_m0, 1);
139 }
140}
141
19776aef 142#else
143#define map_rcnt_rcount0(mode)
144#define map_rcnt_rcount1(mode)
145#define map_rcnt_rcount2(mode)
146#endif
147
7e605697 148#define make_rcnt_funcs(i) \
149static u32 io_rcnt_read_count##i() { return psxRcntRcount(i); } \
150static u32 io_rcnt_read_mode##i() { return psxRcntRmode(i); } \
151static u32 io_rcnt_read_target##i() { return psxRcntRtarget(i); } \
152static void io_rcnt_write_count##i(u32 val) { psxRcntWcount(i, val & 0xffff); } \
b1be1eee 153static void io_rcnt_write_mode##i(u32 val) { psxRcntWmode(i, val); map_rcnt_rcount##i(val); } \
7e605697 154static void io_rcnt_write_target##i(u32 val) { psxRcntWtarget(i, val & 0xffff); }
155
156make_rcnt_funcs(0)
157make_rcnt_funcs(1)
158make_rcnt_funcs(2)
159
160static void io_write_ireg16(u32 value)
161{
9705788a 162 psxHu16ref(0x1070) &= value;
7e605697 163}
164
165static void io_write_imask16(u32 value)
166{
167 psxHu16ref(0x1074) = value;
168 if (psxHu16ref(0x1070) & value)
d28b54b1 169 new_dyna_set_event(PSXINT_NEWDRC_CHECK, 1);
7e605697 170}
171
172static void io_write_ireg32(u32 value)
173{
9705788a 174 psxHu32ref(0x1070) &= value;
7e605697 175}
176
177static void io_write_imask32(u32 value)
178{
179 psxHu32ref(0x1074) = value;
180 if (psxHu32ref(0x1070) & value)
d28b54b1 181 new_dyna_set_event(PSXINT_NEWDRC_CHECK, 1);
7e605697 182}
183
184static void io_write_dma_icr32(u32 value)
185{
1f77c863 186 u32 tmp = value & 0x00ff803f;
187 tmp |= (SWAPu32(HW_DMA_ICR) & ~value) & 0x7f000000;
188 if ((tmp & HW_DMA_ICR_GLOBAL_ENABLE && tmp & 0x7f000000)
189 || tmp & HW_DMA_ICR_BUS_ERROR) {
190 if (!(SWAPu32(HW_DMA_ICR) & HW_DMA_ICR_IRQ_SENT))
191 psxHu32ref(0x1070) |= SWAP32(8);
192 tmp |= HW_DMA_ICR_IRQ_SENT;
193 }
194 HW_DMA_ICR = SWAPu32(tmp);
7e605697 195}
196
197#define make_dma_func(n) \
198static void io_write_chcr##n(u32 value) \
199{ \
200 HW_DMA##n##_CHCR = value; \
201 if (value & 0x01000000 && HW_DMA_PCR & (8 << (n * 4))) { \
202 psxDma##n(HW_DMA##n##_MADR, HW_DMA##n##_BCR, value); \
203 } \
204}
205
206make_dma_func(0)
207make_dma_func(1)
208make_dma_func(2)
209make_dma_func(3)
210make_dma_func(4)
211make_dma_func(6)
212
b96d3df7 213static void io_spu_write16(u32 value)
214{
215 // meh
650adfd2 216 SPU_writeRegister(address, value, psxRegs.cycle);
b96d3df7 217}
218
219static void io_spu_write32(u32 value)
220{
221 SPUwriteRegister wfunc = SPU_writeRegister;
222 u32 a = address;
223
650adfd2 224 wfunc(a, value & 0xffff, psxRegs.cycle);
225 wfunc(a + 2, value >> 16, psxRegs.cycle);
b96d3df7 226}
227
ddbaf678 228static u32 io_gpu_read_status(void)
229{
0486fdc9 230 u32 v;
231
ddbaf678 232 // meh2, syncing for img bit, might want to avoid it..
233 gpuSyncPluginSR();
0486fdc9 234 v = HW_GPU_STATUS;
235
236 // XXX: because of large timeslices can't use hSyncCount, using rough
237 // approximization instead. Perhaps better use hcounter code here or something.
238 if (hSyncCount < 240 && (HW_GPU_STATUS & PSXGPU_ILACE_BITS) != PSXGPU_ILACE_BITS)
239 v |= PSXGPU_LCF & (psxRegs.cycle << 20);
240 return v;
ddbaf678 241}
242
243static void io_gpu_write_status(u32 value)
244{
245 GPU_writeStatus(value);
246 gpuSyncPluginSR();
247}
248
679d5ee3 249void new_dyna_pcsx_mem_isolate(int enable)
b96d3df7 250{
251 int i;
252
679d5ee3 253 // note: apparently 0xa0000000 uncached access still works,
254 // at least read does for sure, so assume write does too
255 memprintf("mem isolate %d\n", enable);
256 if (enable) {
257 for (i = 0; i < (0x800000 >> 12); i++) {
258 map_item(&mem_writetab[0x80000|i], mem_unmwtab, 1);
259 map_item(&mem_writetab[0x00000|i], mem_unmwtab, 1);
260 //map_item(&mem_writetab[0xa0000|i], mem_unmwtab, 1);
261 }
262 }
263 else {
264 for (i = 0; i < (0x800000 >> 12); i++) {
265 map_l1_mem(mem_writetab, i, 0x80000000, 0x200000, psxM);
266 map_l1_mem(mem_writetab, i, 0x00000000, 0x200000, psxM);
267 map_l1_mem(mem_writetab, i, 0xa0000000, 0x200000, psxM);
268 }
b96d3df7 269 }
270}
271
679d5ee3 272static u32 read_biu(u32 addr)
b96d3df7 273{
679d5ee3 274 if (addr != 0xfffe0130)
275 return read_mem_dummy(addr);
276
277 FILE *f = fopen("/tmp/psxbiu.bin", "wb");
278 fwrite(psxM, 1, 0x200000, f);
279 fclose(f);
280 memprintf("read_biu %08x @%08x %u\n",
281 psxRegs.biuReg, psxRegs.pc, psxRegs.cycle);
282 return psxRegs.biuReg;
b96d3df7 283}
284
285static void write_biu(u32 value)
286{
679d5ee3 287 if (address != 0xfffe0130) {
288 write_mem_dummy(value);
b96d3df7 289 return;
b96d3df7 290 }
679d5ee3 291
292 memprintf("write_biu %08x @%08x %u\n", value, psxRegs.pc, psxRegs.cycle);
293 psxRegs.biuReg = value;
b96d3df7 294}
295
b1be1eee 296void new_dyna_pcsx_mem_load_state(void)
297{
298 map_rcnt_rcount0(rcnts[0].mode);
299 map_rcnt_rcount1(rcnts[1].mode);
300 map_rcnt_rcount2(rcnts[2].mode);
301}
302
003cfc63 303int pcsxmem_is_handler_dynamic(unsigned int addr)
b1be1eee 304{
305 if ((addr & 0xfffff000) != 0x1f801000)
306 return 0;
307
308 addr &= 0xffff;
309 return addr == 0x1100 || addr == 0x1110 || addr == 0x1120;
310}
311
7e605697 312void new_dyna_pcsx_mem_init(void)
313{
314 int i;
63cb0298 315
679d5ee3 316 memset(ffff_mem, 0xff, sizeof(ffff_mem));
317
c6c3b1b3 318 // have to map these further to keep tcache close to .text
be516ebe 319 mem_readtab = psxMap(0x08000000, 0x200000 * sizeof(mem_readtab[0]), 0, MAP_TAG_LUTS);
87e5b45f 320 if (mem_readtab == NULL) {
f29fbd53 321 SysPrintf("failed to map mem tables\n");
c6c3b1b3 322 exit(1);
323 }
324 mem_writetab = mem_readtab + 0x100000;
325
326 // 1st level lookup:
327 // 0: direct mem
328 // 1: use 2nd lookup
329 // 2nd level lookup:
330 // 0: direct mem variable
331 // 1: memhandler
332
333 // default/unmapped memhandlers
334 for (i = 0; i < 0x100000; i++) {
335 //map_item(&mem_readtab[i], mem_unmrtab, 1);
679d5ee3 336 map_l1_mem(mem_readtab, i, 0, 0x1000, ffff_mem);
c6c3b1b3 337 map_item(&mem_writetab[i], mem_unmwtab, 1);
338 }
339
340 // RAM and it's mirrors
341 for (i = 0; i < (0x800000 >> 12); i++) {
342 map_l1_mem(mem_readtab, i, 0x80000000, 0x200000, psxM);
c6c3b1b3 343 map_l1_mem(mem_readtab, i, 0x00000000, 0x200000, psxM);
c6c3b1b3 344 map_l1_mem(mem_readtab, i, 0xa0000000, 0x200000, psxM);
c6c3b1b3 345 }
679d5ee3 346 new_dyna_pcsx_mem_isolate(0);
c6c3b1b3 347
348 // BIOS and it's mirrors
349 for (i = 0; i < (0x80000 >> 12); i++) {
350 map_l1_mem(mem_readtab, i, 0x1fc00000, 0x80000, psxR);
351 map_l1_mem(mem_readtab, i, 0xbfc00000, 0x80000, psxR);
352 }
353
354 // scratchpad
355 map_l1_mem(mem_readtab, 0, 0x1f800000, 0x1000, psxH);
9dd7d179 356 map_l1_mem(mem_readtab, 0, 0x9f800000, 0x1000, psxH);
c6c3b1b3 357 map_l1_mem(mem_writetab, 0, 0x1f800000, 0x1000, psxH);
9dd7d179 358 map_l1_mem(mem_writetab, 0, 0x9f800000, 0x1000, psxH);
c6c3b1b3 359
360 // I/O
679d5ee3 361 map_item(&mem_readtab[0x1f801000u >> 12], mem_iortab, 1);
362 map_item(&mem_readtab[0x9f801000u >> 12], mem_iortab, 1);
363 map_item(&mem_readtab[0xbf801000u >> 12], mem_iortab, 1);
364 map_item(&mem_writetab[0x1f801000u >> 12], mem_iowtab, 1);
365 map_item(&mem_writetab[0x9f801000u >> 12], mem_iowtab, 1);
366 map_item(&mem_writetab[0xbf801000u >> 12], mem_iowtab, 1);
7e605697 367
c6c3b1b3 368 // L2
369 // unmapped tables
b96d3df7 370 for (i = 0; i < (1+2+4) * 0x1000 / 4; i++)
c6c3b1b3 371 map_item(&mem_unmwtab[i], write_mem_dummy, 1);
372
373 // fill IO tables
374 for (i = 0; i < 0x1000/4; i++) {
375 map_item(&mem_iortab[i], &psxH[0x1000], 0);
376 map_item(&mem_iowtab[i], &psxH[0x1000], 0);
377 }
378 for (; i < 0x1000/4 + 0x1000/2; i++) {
379 map_item(&mem_iortab[i], &psxH[0x1000], 0);
380 map_item(&mem_iowtab[i], &psxH[0x1000], 0);
381 }
382 for (; i < 0x1000/4 + 0x1000/2 + 0x1000; i++) {
383 map_item(&mem_iortab[i], &psxH[0x1000], 0);
384 map_item(&mem_iowtab[i], &psxH[0x1000], 0);
385 }
386
387 map_item(&mem_iortab[IOMEM32(0x1040)], io_read_sio32, 1);
906b1599 388 map_item(&mem_iortab[IOMEM16(0x1044)], sioReadStat16, 1);
c6c3b1b3 389 map_item(&mem_iortab[IOMEM32(0x1100)], io_rcnt_read_count0, 1);
390 map_item(&mem_iortab[IOMEM32(0x1104)], io_rcnt_read_mode0, 1);
391 map_item(&mem_iortab[IOMEM32(0x1108)], io_rcnt_read_target0, 1);
392 map_item(&mem_iortab[IOMEM32(0x1110)], io_rcnt_read_count1, 1);
393 map_item(&mem_iortab[IOMEM32(0x1114)], io_rcnt_read_mode1, 1);
394 map_item(&mem_iortab[IOMEM32(0x1118)], io_rcnt_read_target1, 1);
395 map_item(&mem_iortab[IOMEM32(0x1120)], io_rcnt_read_count2, 1);
396 map_item(&mem_iortab[IOMEM32(0x1124)], io_rcnt_read_mode2, 1);
397 map_item(&mem_iortab[IOMEM32(0x1128)], io_rcnt_read_target2, 1);
398// map_item(&mem_iortab[IOMEM32(0x1810)], GPU_readData, 1);
ddbaf678 399 map_item(&mem_iortab[IOMEM32(0x1814)], io_gpu_read_status, 1);
c6c3b1b3 400 map_item(&mem_iortab[IOMEM32(0x1820)], mdecRead0, 1);
401 map_item(&mem_iortab[IOMEM32(0x1824)], mdecRead1, 1);
402
403 map_item(&mem_iortab[IOMEM16(0x1040)], io_read_sio16, 1);
404 map_item(&mem_iortab[IOMEM16(0x1044)], sioReadStat16, 1);
405 map_item(&mem_iortab[IOMEM16(0x1048)], sioReadMode16, 1);
406 map_item(&mem_iortab[IOMEM16(0x104a)], sioReadCtrl16, 1);
407 map_item(&mem_iortab[IOMEM16(0x104e)], sioReadBaud16, 1);
408 map_item(&mem_iortab[IOMEM16(0x1100)], io_rcnt_read_count0, 1);
409 map_item(&mem_iortab[IOMEM16(0x1104)], io_rcnt_read_mode0, 1);
410 map_item(&mem_iortab[IOMEM16(0x1108)], io_rcnt_read_target0, 1);
411 map_item(&mem_iortab[IOMEM16(0x1110)], io_rcnt_read_count1, 1);
412 map_item(&mem_iortab[IOMEM16(0x1114)], io_rcnt_read_mode1, 1);
413 map_item(&mem_iortab[IOMEM16(0x1118)], io_rcnt_read_target1, 1);
414 map_item(&mem_iortab[IOMEM16(0x1120)], io_rcnt_read_count2, 1);
415 map_item(&mem_iortab[IOMEM16(0x1124)], io_rcnt_read_mode2, 1);
416 map_item(&mem_iortab[IOMEM16(0x1128)], io_rcnt_read_target2, 1);
417
418 map_item(&mem_iortab[IOMEM8(0x1040)], sioRead8, 1);
419 map_item(&mem_iortab[IOMEM8(0x1800)], cdrRead0, 1);
420 map_item(&mem_iortab[IOMEM8(0x1801)], cdrRead1, 1);
421 map_item(&mem_iortab[IOMEM8(0x1802)], cdrRead2, 1);
422 map_item(&mem_iortab[IOMEM8(0x1803)], cdrRead3, 1);
423
b96d3df7 424 // write(u32 data)
425 map_item(&mem_iowtab[IOMEM32(0x1040)], io_write_sio32, 1);
426 map_item(&mem_iowtab[IOMEM32(0x1070)], io_write_ireg32, 1);
427 map_item(&mem_iowtab[IOMEM32(0x1074)], io_write_imask32, 1);
428 map_item(&mem_iowtab[IOMEM32(0x1088)], io_write_chcr0, 1);
429 map_item(&mem_iowtab[IOMEM32(0x1098)], io_write_chcr1, 1);
430 map_item(&mem_iowtab[IOMEM32(0x10a8)], io_write_chcr2, 1);
431 map_item(&mem_iowtab[IOMEM32(0x10b8)], io_write_chcr3, 1);
432 map_item(&mem_iowtab[IOMEM32(0x10c8)], io_write_chcr4, 1);
433 map_item(&mem_iowtab[IOMEM32(0x10e8)], io_write_chcr6, 1);
434 map_item(&mem_iowtab[IOMEM32(0x10f4)], io_write_dma_icr32, 1);
435 map_item(&mem_iowtab[IOMEM32(0x1100)], io_rcnt_write_count0, 1);
436 map_item(&mem_iowtab[IOMEM32(0x1104)], io_rcnt_write_mode0, 1);
437 map_item(&mem_iowtab[IOMEM32(0x1108)], io_rcnt_write_target0, 1);
438 map_item(&mem_iowtab[IOMEM32(0x1110)], io_rcnt_write_count1, 1);
439 map_item(&mem_iowtab[IOMEM32(0x1114)], io_rcnt_write_mode1, 1);
440 map_item(&mem_iowtab[IOMEM32(0x1118)], io_rcnt_write_target1, 1);
441 map_item(&mem_iowtab[IOMEM32(0x1120)], io_rcnt_write_count2, 1);
442 map_item(&mem_iowtab[IOMEM32(0x1124)], io_rcnt_write_mode2, 1);
443 map_item(&mem_iowtab[IOMEM32(0x1128)], io_rcnt_write_target2, 1);
444// map_item(&mem_iowtab[IOMEM32(0x1810)], GPU_writeData, 1);
ddbaf678 445 map_item(&mem_iowtab[IOMEM32(0x1814)], io_gpu_write_status, 1);
b96d3df7 446 map_item(&mem_iowtab[IOMEM32(0x1820)], mdecWrite0, 1);
447 map_item(&mem_iowtab[IOMEM32(0x1824)], mdecWrite1, 1);
448
449 map_item(&mem_iowtab[IOMEM16(0x1040)], io_write_sio16, 1);
450 map_item(&mem_iowtab[IOMEM16(0x1044)], sioWriteStat16, 1);
451 map_item(&mem_iowtab[IOMEM16(0x1048)], sioWriteMode16, 1);
452 map_item(&mem_iowtab[IOMEM16(0x104a)], sioWriteCtrl16, 1);
453 map_item(&mem_iowtab[IOMEM16(0x104e)], sioWriteBaud16, 1);
454 map_item(&mem_iowtab[IOMEM16(0x1070)], io_write_ireg16, 1);
455 map_item(&mem_iowtab[IOMEM16(0x1074)], io_write_imask16, 1);
456 map_item(&mem_iowtab[IOMEM16(0x1100)], io_rcnt_write_count0, 1);
457 map_item(&mem_iowtab[IOMEM16(0x1104)], io_rcnt_write_mode0, 1);
458 map_item(&mem_iowtab[IOMEM16(0x1108)], io_rcnt_write_target0, 1);
459 map_item(&mem_iowtab[IOMEM16(0x1110)], io_rcnt_write_count1, 1);
460 map_item(&mem_iowtab[IOMEM16(0x1114)], io_rcnt_write_mode1, 1);
461 map_item(&mem_iowtab[IOMEM16(0x1118)], io_rcnt_write_target1, 1);
462 map_item(&mem_iowtab[IOMEM16(0x1120)], io_rcnt_write_count2, 1);
463 map_item(&mem_iowtab[IOMEM16(0x1124)], io_rcnt_write_mode2, 1);
464 map_item(&mem_iowtab[IOMEM16(0x1128)], io_rcnt_write_target2, 1);
465
466 map_item(&mem_iowtab[IOMEM8(0x1040)], sioWrite8, 1);
467 map_item(&mem_iowtab[IOMEM8(0x1800)], cdrWrite0, 1);
468 map_item(&mem_iowtab[IOMEM8(0x1801)], cdrWrite1, 1);
469 map_item(&mem_iowtab[IOMEM8(0x1802)], cdrWrite2, 1);
470 map_item(&mem_iowtab[IOMEM8(0x1803)], cdrWrite3, 1);
471
906b1599 472 for (i = 0x1c00; i < 0x2000; i += 2) {
b96d3df7 473 map_item(&mem_iowtab[IOMEM16(i)], io_spu_write16, 1);
474 map_item(&mem_iowtab[IOMEM32(i)], io_spu_write32, 1);
475 }
476
477 // misc
679d5ee3 478 map_item(&mem_readtab[0xfffe0130u >> 12], mem_ffrtab, 1);
479 map_item(&mem_writetab[0xfffe0130u >> 12], mem_ffwtab, 1);
480 for (i = 0; i < 0x1000/4 + 0x1000/2 + 0x1000; i++) {
481 map_item(&mem_ffrtab[i], read_biu, 1);
b96d3df7 482 map_item(&mem_ffwtab[i], write_biu, 1);
679d5ee3 483 }
b96d3df7 484
c6c3b1b3 485 mem_rtab = mem_readtab;
486 mem_wtab = mem_writetab;
b1be1eee 487
488 new_dyna_pcsx_mem_load_state();
7e605697 489}
490
491void new_dyna_pcsx_mem_reset(void)
492{
c6c3b1b3 493 int i;
494
7e605697 495 // plugins might change so update the pointers
c6c3b1b3 496 map_item(&mem_iortab[IOMEM32(0x1810)], GPU_readData, 1);
c6c3b1b3 497
906b1599 498 for (i = 0x1c00; i < 0x2000; i += 2)
c6c3b1b3 499 map_item(&mem_iortab[IOMEM16(i)], SPU_readRegister, 1);
500
b96d3df7 501 map_item(&mem_iowtab[IOMEM32(0x1810)], GPU_writeData, 1);
7e605697 502}
92879b62 503
504void new_dyna_pcsx_mem_shutdown(void)
505{
ed7afeef 506 psxUnmap(mem_readtab, 0x200000 * sizeof(mem_readtab[0]), MAP_TAG_LUTS);
92879b62 507 mem_writetab = mem_readtab = NULL;
508}