incTime();
READTRACK();
- if (ptr != NULL) memcpy(ptr, buf+12, 2048);
+ if (ptr != INVALID_PTR) memcpy(ptr, buf+12, 2048);
tmpHead.t_size -= 2048;
tmpHead.t_addr += 2048;
READTRACK();
mem = PSXM(addr);
- if (mem)
+ if (mem != INVALID_PTR)
memcpy(mem, buf + 12, 2048);
size -= 2048;
section_address = SWAP32(tmpHead.t_addr);
section_size = SWAP32(tmpHead.t_size);
mem = PSXM(section_address);
- if (mem != NULL) {
+ if (mem != INVALID_PTR) {
fseek(tmpFile, 0x800, SEEK_SET);
fread_to_ram(mem, section_size, 1, tmpFile);
psxCpu->Clear(section_address, section_size / 4);
EMU_LOG("Loading %08X bytes from %08X to %08X\n", section_size, ftell(tmpFile), section_address);
#endif
mem = PSXM(section_address);
- if (mem != NULL) {
+ if (mem != INVALID_PTR) {
fread_to_ram(mem, section_size, 1, tmpFile);
psxCpu->Clear(section_address, section_size / 4);
}
#endif
v0 = -1;
- if (pa1) {
+ if (pa1 != INVALID_PTR) {
switch (a0) {
case 2: buread(pa1, 1, 1); break;
case 3: buread(pa1, 2, 1); break;
PSXBIOS_LOG("psxBios_%s\n", biosA0n[0x09]);
#endif
v0 = -1;
- if (!pa1) {
+ if (pa1 == INVALID_PTR) {
pc0 = ra;
return;
}
void *psp;
psp = PSXM(sp);
- if (psp) {
+ if (psp != INVALID_PTR) {
memcpy(save, psp, 4 * 4);
psxMu32ref(sp) = SWAP32((u32)a0);
psxMu32ref(sp + 4) = SWAP32((u32)a1);
v0 = -1;
- if (pa0) {
+ if (pa0 != INVALID_PTR) {
if (!strncmp(pa0, "bu00", 4)) {
buopen(1, Mcd1Data, Config.Mcd1);
}
v0 = -1;
- if (pa1) {
+ if (pa1 != INVALID_PTR) {
switch (a0) {
case 2: buread(pa1, 1, a2); break;
case 3: buread(pa1, 2, a2); break;
#endif
v0 = -1;
- if (!pa1) {
+ if (pa1 == INVALID_PTR) {
pc0 = ra;
return;
}
v0 = 0;
- if (pa0) {
+ if (pa0 != INVALID_PTR) {
strcpy(ffile, pa0);
pfile = ffile+5;
nfile = 0;
v0 = 0;
- if (pa0 && pa1) {
+ if (pa0 != INVALID_PTR && pa1 != INVALID_PTR) {
if (!strncmp(pa0, "bu00", 4) && !strncmp(pa1, "bu00", 4)) {
burename(1);
}
v0 = 0;
- if (pa0) {
+ if (pa0 != INVALID_PTR) {
if (!strncmp(pa0, "bu00", 4)) {
budelete(1);
}
card_active_chan = a0;
port = a0 >> 4;
- if (pa2) {
+ if (pa2 != INVALID_PTR) {
if (port == 0) {
memcpy(Mcd1Data + a1 * 128, pa2, 128);
SaveMcd(Config.Mcd1, Mcd1Data, a1 * 128, 128);
card_active_chan = a0;
port = a0 >> 4;
- if (pa2) {
+ if (pa2 != INVALID_PTR) {
if (port == 0) {
memcpy(pa2, Mcd1Data + a1 * 128, 128);
} else {
PSXDMA_LOG("*** DMA4 SPU - mem2spu *** %x addr = %x size = %x\n", chcr, madr, bcr);
#endif
ptr = (u16 *)PSXM(madr);
- if (ptr == NULL) {
+ if (ptr == INVALID_PTR) {
#ifdef CPU_LOG
CPU_LOG("*** DMA4 SPU - mem2spu *** NULL Pointer!!!\n");
#endif
PSXDMA_LOG("*** DMA4 SPU - spu2mem *** %x addr = %x size = %x\n", chcr, madr, bcr);
#endif
ptr = (u16 *)PSXM(madr);
- if (ptr == NULL) {
+ if (ptr == INVALID_PTR) {
#ifdef CPU_LOG
CPU_LOG("*** DMA4 SPU - spu2mem *** NULL Pointer!!!\n");
#endif
PSXDMA_LOG("*** DMA2 GPU - vram2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr);
#endif
ptr = (u32 *)PSXM(madr);
- if (ptr == NULL) {
+ if (ptr == INVALID_PTR) {
#ifdef CPU_LOG
CPU_LOG("*** DMA2 GPU - vram2mem *** NULL Pointer!!!\n");
#endif
PSXDMA_LOG("*** DMA 2 - GPU mem2vram *** %lx addr = %lx size = %lx\n", chcr, madr, bcr);
#endif
ptr = (u32 *)PSXM(madr);
- if (ptr == NULL) {
+ if (ptr == INVALID_PTR) {
#ifdef CPU_LOG
CPU_LOG("*** DMA2 GPU - mem2vram *** NULL Pointer!!!\n");
#endif
#endif
if (chcr == 0x11000002) {
- if (mem == NULL) {
+ if (mem == INVALID_PTR) {
#ifdef CPU_LOG
CPU_LOG("*** DMA6 OT *** NULL Pointer!!!\n");
#endif
if (psxMapHook != NULL) {
ret = psxMapHook(addr, size, 0, tag);
if (ret == NULL)
- return NULL;
+ return MAP_FAILED;
}
else {
/* avoid MAP_FIXED, it overrides existing mappings.. */
req = (void *)addr;
ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0);
if (ret == MAP_FAILED)
- return NULL;
+ return ret;
}
if (addr != 0 && ret != (void *)addr) {
if (is_fixed) {
psxUnmap(ret, size, tag);
- return NULL;
+ return MAP_FAILED;
}
if (((addr ^ (unsigned long)ret) & ~0xff000000l) && try_ < 2)
int psxMemInit() {
int i;
- psxMemRLUT = (u8 **)malloc(0x10000 * sizeof(void *));
- psxMemWLUT = (u8 **)malloc(0x10000 * sizeof(void *));
- memset(psxMemRLUT, 0, 0x10000 * sizeof(void *));
- memset(psxMemWLUT, 0, 0x10000 * sizeof(void *));
-
psxM = psxMap(0x80000000, 0x00210000, 1, MAP_TAG_RAM);
- if (psxM == NULL)
+ if (psxM == MAP_FAILED)
psxM = psxMap(0x77000000, 0x00210000, 0, MAP_TAG_RAM);
- if (psxM == NULL) {
+ if (psxM == MAP_FAILED) {
SysMessage(_("mapping main RAM failed"));
return -1;
}
psxH = psxMap(0x1f800000, 0x10000, 0, MAP_TAG_OTHER);
psxR = psxMap(0x1fc00000, 0x80000, 0, MAP_TAG_OTHER);
- if (psxMemRLUT == NULL || psxMemWLUT == NULL ||
- psxR == NULL || psxP == NULL || psxH == NULL) {
+ if (psxR == MAP_FAILED || psxH == MAP_FAILED) {
SysMessage(_("Error allocating memory!"));
psxMemShutdown();
return -1;
}
+ psxMemRLUT = (u8 **)malloc(0x10000 * sizeof(void *));
+ psxMemWLUT = (u8 **)malloc(0x10000 * sizeof(void *));
+
+ if (psxMemRLUT == NULL || psxMemWLUT == NULL) {
+ SysMessage(_("Error allocating memory!"));
+ psxMemShutdown();
+ return -1;
+ }
+
+ memset(psxMemRLUT, 0xff, 0x10000 * sizeof(void *));
+ memset(psxMemWLUT, 0xff, 0x10000 * sizeof(void *));
+
// MemR
for (i = 0; i < 0x80; i++) psxMemRLUT[i + 0x0000] = (u8 *)&psxM[(i & 0x1f) << 16];
// NOTE: Not sure if this is needed to fix any games but seems wise,
// seeing as some games do read from PIO as part of copy-protection
// check. (See fix in psxMemReset() regarding psxP region reads).
- psxMemWLUT[0x1f00] = NULL;
+ psxMemWLUT[0x1f00] = INVALID_PTR;
psxMemWLUT[0x1f80] = (u8 *)psxH;
return 0;
return psxHwRead8(mem);
} else {
p = (char *)(psxMemRLUT[t]);
- if (p != NULL) {
+ if (p != INVALID_PTR) {
if (Config.Debug)
DebugCheckBP((mem & 0xffffff) | 0x80000000, R1);
return *(u8 *)(p + (mem & 0xffff));
return psxHwRead16(mem);
} else {
p = (char *)(psxMemRLUT[t]);
- if (p != NULL) {
+ if (p != INVALID_PTR) {
if (Config.Debug)
DebugCheckBP((mem & 0xffffff) | 0x80000000, R2);
return SWAPu16(*(u16 *)(p + (mem & 0xffff)));
return psxHwRead32(mem);
} else {
p = (char *)(psxMemRLUT[t]);
- if (p != NULL) {
+ if (p != INVALID_PTR) {
if (Config.Debug)
DebugCheckBP((mem & 0xffffff) | 0x80000000, R4);
return SWAPu32(*(u32 *)(p + (mem & 0xffff)));
psxHwWrite8(mem, value);
} else {
p = (char *)(psxMemWLUT[t]);
- if (p != NULL) {
+ if (p != INVALID_PTR) {
if (Config.Debug)
DebugCheckBP((mem & 0xffffff) | 0x80000000, W1);
*(u8 *)(p + (mem & 0xffff)) = value;
psxHwWrite16(mem, value);
} else {
p = (char *)(psxMemWLUT[t]);
- if (p != NULL) {
+ if (p != INVALID_PTR) {
if (Config.Debug)
DebugCheckBP((mem & 0xffffff) | 0x80000000, W2);
*(u16 *)(p + (mem & 0xffff)) = SWAPu16(value);
psxHwWrite32(mem, value);
} else {
p = (char *)(psxMemWLUT[t]);
- if (p != NULL) {
+ if (p != INVALID_PTR) {
if (Config.Debug)
DebugCheckBP((mem & 0xffffff) | 0x80000000, W4);
*(u32 *)(p + (mem & 0xffff)) = SWAPu32(value);
case 0x800: case 0x804:
if (writeok == 0) break;
writeok = 0;
- memset(psxMemWLUT + 0x0000, 0, 0x80 * sizeof(void *));
- memset(psxMemWLUT + 0x8000, 0, 0x80 * sizeof(void *));
- memset(psxMemWLUT + 0xa000, 0, 0x80 * sizeof(void *));
+ memset(psxMemWLUT + 0x0000, 0xff, 0x80 * sizeof(void *));
+ memset(psxMemWLUT + 0x8000, 0xff, 0x80 * sizeof(void *));
+ memset(psxMemWLUT + 0xa000, 0xff, 0x80 * sizeof(void *));
/* Required for icache interpreter otherwise Armored Core won't boot on icache interpreter */
psxCpu->Notify(R3000ACPU_NOTIFY_CACHE_ISOLATED, NULL);
break;
return NULL;
} else {
p = (char *)(psxMemWLUT[t]);
- if (p != NULL) {
+ if (p != INVALID_PTR) {
return (void *)(p + (mem & 0xffff));
}
return NULL;