static uintptr_t *mem_writetab;
static uintptr_t mem_iortab[(1+2+4) * 0x1000 / 4];
static uintptr_t mem_iowtab[(1+2+4) * 0x1000 / 4];
+static uintptr_t mem_ffrtab[(1+2+4) * 0x1000 / 4];
static uintptr_t mem_ffwtab[(1+2+4) * 0x1000 / 4];
//static uintptr_t mem_unmrtab[(1+2+4) * 0x1000 / 4];
static uintptr_t mem_unmwtab[(1+2+4) * 0x1000 / 4];
// size must be power of 2, at least 4k
#define map_l1_mem(tab, i, addr, size, base) \
- map_item(&tab[((addr)>>12) + i], \
+ map_item(&tab[((u32)(addr) >> 12) + i], \
(u8 *)(base) - (u32)((addr) + ((i << 12) & ~(size - 1))), 0)
#define IOMEM32(a) (((a) & 0xfff) / 4)
#define IOMEM16(a) (0x1000/4 + (((a) & 0xfff) / 2))
#define IOMEM8(a) (0x1000/4 + 0x1000/2 + ((a) & 0xfff))
-u8 zero_mem[0x1000];
+u32 zero_mem[0x1000/4];
+static u32 ffff_mem[0x1000/4];
-u32 read_mem_dummy()
+static u32 read_mem_dummy(u32 addr)
{
- return 0;
+ // use 'addr' and not 'address', yes the api is weird...
+ memprintf("unmapped r %08x @%08x %u\n", addr, psxRegs.pc, psxRegs.cycle);
+ return 0xffffffff;
}
static void write_mem_dummy(u32 data)
{
- memprintf("unmapped w %08x, %08x @%08x %u\n", address, data, psxRegs.pc, psxRegs.cycle);
+ if (!(psxRegs.CP0.n.Status & (1 << 16)))
+ memprintf("unmapped w %08x, %08x @%08x %u\n",
+ address, data, psxRegs.pc, psxRegs.cycle);
}
/* IO handlers */
gpuSyncPluginSR();
}
-static void map_ram_write(void)
+void new_dyna_pcsx_mem_isolate(int enable)
{
int i;
- for (i = 0; i < (0x800000 >> 12); i++) {
- map_l1_mem(mem_writetab, i, 0x80000000, 0x200000, psxM);
- map_l1_mem(mem_writetab, i, 0x00000000, 0x200000, psxM);
- map_l1_mem(mem_writetab, i, 0xa0000000, 0x200000, psxM);
+ // note: apparently 0xa0000000 uncached access still works,
+ // at least read does for sure, so assume write does too
+ memprintf("mem isolate %d\n", enable);
+ if (enable) {
+ for (i = 0; i < (0x800000 >> 12); i++) {
+ map_item(&mem_writetab[0x80000|i], mem_unmwtab, 1);
+ map_item(&mem_writetab[0x00000|i], mem_unmwtab, 1);
+ //map_item(&mem_writetab[0xa0000|i], mem_unmwtab, 1);
+ }
+ }
+ else {
+ for (i = 0; i < (0x800000 >> 12); i++) {
+ map_l1_mem(mem_writetab, i, 0x80000000, 0x200000, psxM);
+ map_l1_mem(mem_writetab, i, 0x00000000, 0x200000, psxM);
+ map_l1_mem(mem_writetab, i, 0xa0000000, 0x200000, psxM);
+ }
}
}
-static void unmap_ram_write(void)
+static u32 read_biu(u32 addr)
{
- int i;
-
- for (i = 0; i < (0x800000 >> 12); i++) {
- map_item(&mem_writetab[0x80000|i], mem_unmwtab, 1);
- map_item(&mem_writetab[0x00000|i], mem_unmwtab, 1);
- map_item(&mem_writetab[0xa0000|i], mem_unmwtab, 1);
- }
+ if (addr != 0xfffe0130)
+ return read_mem_dummy(addr);
+
+ FILE *f = fopen("/tmp/psxbiu.bin", "wb");
+ fwrite(psxM, 1, 0x200000, f);
+ fclose(f);
+ memprintf("read_biu %08x @%08x %u\n",
+ psxRegs.biuReg, psxRegs.pc, psxRegs.cycle);
+ return psxRegs.biuReg;
}
static void write_biu(u32 value)
{
- memprintf("write_biu %08x, %08x @%08x %u\n", address, value, psxRegs.pc, psxRegs.cycle);
-
- if (address != 0xfffe0130)
+ if (address != 0xfffe0130) {
+ write_mem_dummy(value);
return;
-
- switch (value) {
- case 0x800: case 0x804:
- unmap_ram_write();
- break;
- case 0: case 0x1e988:
- map_ram_write();
- break;
- default:
- printf("write_biu: unexpected val: %08x\n", value);
- break;
}
+
+ memprintf("write_biu %08x @%08x %u\n", value, psxRegs.pc, psxRegs.cycle);
+ psxRegs.biuReg = value;
}
void new_dyna_pcsx_mem_load_state(void)
{
int i;
+ memset(ffff_mem, 0xff, sizeof(ffff_mem));
+
// have to map these further to keep tcache close to .text
mem_readtab = psxMap(0x08000000, 0x200000 * sizeof(mem_readtab[0]), 0, MAP_TAG_LUTS);
if (mem_readtab == NULL) {
// default/unmapped memhandlers
for (i = 0; i < 0x100000; i++) {
//map_item(&mem_readtab[i], mem_unmrtab, 1);
- map_l1_mem(mem_readtab, i, 0, 0x1000, zero_mem);
+ map_l1_mem(mem_readtab, i, 0, 0x1000, ffff_mem);
map_item(&mem_writetab[i], mem_unmwtab, 1);
}
map_l1_mem(mem_readtab, i, 0x00000000, 0x200000, psxM);
map_l1_mem(mem_readtab, i, 0xa0000000, 0x200000, psxM);
}
- map_ram_write();
+ new_dyna_pcsx_mem_isolate(0);
// BIOS and it's mirrors
for (i = 0; i < (0x80000 >> 12); i++) {
map_l1_mem(mem_writetab, 0, 0x9f800000, 0x1000, psxH);
// I/O
- map_item(&mem_readtab[0x1f801000 >> 12], mem_iortab, 1);
- map_item(&mem_readtab[0x9f801000 >> 12], mem_iortab, 1);
- map_item(&mem_readtab[0xbf801000 >> 12], mem_iortab, 1);
- map_item(&mem_writetab[0x1f801000 >> 12], mem_iowtab, 1);
- map_item(&mem_writetab[0x9f801000 >> 12], mem_iowtab, 1);
- map_item(&mem_writetab[0xbf801000 >> 12], mem_iowtab, 1);
+ map_item(&mem_readtab[0x1f801000u >> 12], mem_iortab, 1);
+ map_item(&mem_readtab[0x9f801000u >> 12], mem_iortab, 1);
+ map_item(&mem_readtab[0xbf801000u >> 12], mem_iortab, 1);
+ map_item(&mem_writetab[0x1f801000u >> 12], mem_iowtab, 1);
+ map_item(&mem_writetab[0x9f801000u >> 12], mem_iowtab, 1);
+ map_item(&mem_writetab[0xbf801000u >> 12], mem_iowtab, 1);
// L2
// unmapped tables
}
// misc
- map_item(&mem_writetab[0xfffe0130 >> 12], mem_ffwtab, 1);
- for (i = 0; i < 0x1000/4 + 0x1000/2 + 0x1000; i++)
+ map_item(&mem_readtab[0xfffe0130u >> 12], mem_ffrtab, 1);
+ map_item(&mem_writetab[0xfffe0130u >> 12], mem_ffwtab, 1);
+ for (i = 0; i < 0x1000/4 + 0x1000/2 + 0x1000; i++) {
+ map_item(&mem_ffrtab[i], read_biu, 1);
map_item(&mem_ffwtab[i], write_biu, 1);
+ }
mem_rtab = mem_readtab;
mem_wtab = mem_writetab;
return -1;
}
- memset(psxMemRLUT, (uintptr_t)INVALID_PTR, 0x10000 * sizeof(void *));
- memset(psxMemWLUT, (uintptr_t)INVALID_PTR, 0x10000 * sizeof(void *));
+ memset(psxMemRLUT, (int)(uintptr_t)INVALID_PTR, 0x10000 * sizeof(void *));
+ memset(psxMemWLUT, (int)(uintptr_t)INVALID_PTR, 0x10000 * sizeof(void *));
// MemR
for (i = 0; i < 0x80; i++) psxMemRLUT[i + 0x0000] = (u8 *)&psxM[(i & 0x1f) << 16];
free(psxMemWLUT); psxMemWLUT = NULL;
}
-static int writeok = 1;
+void psxMemOnIsolate(int enable)
+{
+ if (enable) {
+ memset(psxMemWLUT + 0x0000, (int)(uintptr_t)INVALID_PTR, 0x80 * sizeof(void *));
+ memset(psxMemWLUT + 0x8000, (int)(uintptr_t)INVALID_PTR, 0x80 * sizeof(void *));
+ //memset(psxMemWLUT + 0xa000, (int)(uintptr_t)INVALID_PTR, 0x80 * sizeof(void *));
+ } else {
+ int i;
+ for (i = 0; i < 0x80; i++)
+ psxMemWLUT[i + 0x0000] = (void *)&psxM[(i & 0x1f) << 16];
+ memcpy(psxMemWLUT + 0x8000, psxMemWLUT, 0x80 * sizeof(void *));
+ memcpy(psxMemWLUT + 0xa000, psxMemWLUT, 0x80 * sizeof(void *));
+ }
+ psxCpu->Notify(enable ? R3000ACPU_NOTIFY_CACHE_ISOLATED
+ : R3000ACPU_NOTIFY_CACHE_UNISOLATED, NULL);
+}
u8 psxMemRead8(u32 mem) {
char *p;
DebugCheckBP((mem & 0xffffff) | 0x80000000, R4);
return SWAPu32(*(u32 *)(p + (mem & 0xffff)));
} else {
+ if (mem == 0xfffe0130)
+ return psxRegs.biuReg;
#ifdef PSXMEM_LOG
- if (writeok) { PSXMEM_LOG("err lw %8.8lx\n", mem); }
+ PSXMEM_LOG("err lw %8.8lx\n", mem);
#endif
return 0xFFFFFFFF;
}
psxCpu->Clear(mem, 1);
#endif
} else {
- if (mem != 0xfffe0130) {
-#ifndef DRC_DISABLE
- if (!writeok)
- psxCpu->Clear(mem, 1);
-#endif
-
-#ifdef PSXMEM_LOG
- if (writeok) { PSXMEM_LOG("err sw %8.8lx\n", mem); }
-#endif
- } else {
- int i;
-
- switch (value) {
- case 0x800: case 0x804:
- if (writeok == 0) break;
- writeok = 0;
- memset(psxMemWLUT + 0x0000, (uintptr_t)INVALID_PTR, 0x80 * sizeof(void *));
- memset(psxMemWLUT + 0x8000, (uintptr_t)INVALID_PTR, 0x80 * sizeof(void *));
- memset(psxMemWLUT + 0xa000, (uintptr_t)INVALID_PTR, 0x80 * sizeof(void *));
- /* Required for icache interpreter otherwise Armored Core won't boot on icache interpreter */
- psxCpu->Notify(R3000ACPU_NOTIFY_CACHE_ISOLATED, NULL);
- break;
- case 0x00: case 0x1e988:
- if (writeok == 1) break;
- writeok = 1;
- for (i = 0; i < 0x80; i++) psxMemWLUT[i + 0x0000] = (void *)&psxM[(i & 0x1f) << 16];
- memcpy(psxMemWLUT + 0x8000, psxMemWLUT, 0x80 * sizeof(void *));
- memcpy(psxMemWLUT + 0xa000, psxMemWLUT, 0x80 * sizeof(void *));
- /* Dynarecs might take this opportunity to flush their code cache */
- psxCpu->Notify(R3000ACPU_NOTIFY_CACHE_UNISOLATED, NULL);
- break;
- default:
+ if (mem == 0xfffe0130) {
+ psxRegs.biuReg = value;
+ return;
+ }
#ifdef PSXMEM_LOG
- PSXMEM_LOG("unk %8.8lx = %x\n", mem, value);
+ PSXMEM_LOG("err sw %8.8lx\n", mem);
#endif
- break;
- }
- }
}
}
}