void psxMemWrite16(u32 mem, u16 value) { char *p; u32 t; psxRegs.cycle += 1; t = mem >> 16; if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { if ((mem & 0xffff) < 0x400) psxHu16ref(mem) = SWAPu16(value); else psxHwWrite16(mem, value); } else { p = (char *)(psxMemWLUT[t]); if (p != NULL) { if (Config.Debug) DebugCheckBP((mem & 0xffffff) | 0x80000000, BW2); *(u16 *)(p + (mem & 0xffff)) = SWAPu16(value); #ifdef PSXREC psxCpu->Clear((mem & (~3)), 1); #endif } else { #ifdef PSXMEM_LOG PSXMEM_LOG("err sh %8.8lx\n", mem); #endif } } }
static int PSXGetFileType(FILE *f) { unsigned long current; u8 mybuf[sizeof(EXE_HEADER)]; // EXE_HEADER currently biggest EXE_HEADER *exe_hdr; FILHDR *coff_hdr; size_t amt; memset(mybuf, 0, sizeof(mybuf)); current = ftell(f); fseek(f, 0L, SEEK_SET); amt = fread(mybuf, sizeof(mybuf), 1, f); fseek(f, current, SEEK_SET); exe_hdr = (EXE_HEADER *)mybuf; if (memcmp(exe_hdr->id, "PS-X EXE", 8) == 0) return PSX_EXE; if (mybuf[0] == 'C' && mybuf[1] == 'P' && mybuf[2] == 'E') return CPE_EXE; coff_hdr = (FILHDR *)mybuf; if (SWAPu16(coff_hdr->f_magic) == 0x0162) return COFF_EXE; return INVALID_EXE; }
u16 psxMemRead16(u32 mem) { char *p; u32 t; psxRegs.cycle += 1; t = mem >> 16; if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { if ((mem & 0xffff) < 0x400) return psxHu16(mem); else return psxHwRead16(mem); } else { p = (char *)(psxMemRLUT[t]); if (p != NULL) { if (Config.Debug) DebugCheckBP((mem & 0xffffff) | 0x80000000, BR2); return SWAPu16(*(u16 *)(p + (mem & 0xffff))); } else { #ifdef PSXMEM_LOG PSXMEM_LOG("err lh %8.8lx\n", mem); #endif return 0; } } }
void psxMemWrite16(u32 mem, u16 value) { u32 t; t = mem >> 16; if (t == 0x1f80) { if (mem < 0x1f801000) psxHu16ref(mem) = SWAPu16(value); else psxHwWrite16(mem, value); } else { char *p = (char *)(psxMemWLUT[t]); if (p != NULL) { *(u16 *)(p + (mem & 0xffff)) = SWAPu16(value); #ifdef PSXREC psxCpu->Clear((mem&(~1)), 1); #endif } else { #ifdef PSXMEM_LOG PSXMEM_LOG("err sh %8.8lx\n", mem); #endif } } }
u16 psxMemRead16(u32 mem) { u32 t; t = mem >> 16; if (t == 0x1f80) { if (mem < 0x1f801000) return psxHu16(mem); else return psxHwRead16(mem); } else { char *p = (char *)(psxMemRLUT[t]); if (p != NULL) { return SWAPu16(*(u16 *)(p + (mem & 0xffff))); } else { #ifdef PSXMEM_LOG PSXMEM_LOG("err lh %8.8lx\n", mem); #endif return 0; } } }
static int PSXGetFileType(FILE *f) { unsigned long current; u8 mybuf[2048]; EXE_HEADER *exe_hdr; FILHDR *coff_hdr; current = ftell(f); fseek(f, 0L, SEEK_SET); fread(mybuf, 2048, 1, f); fseek(f, current, SEEK_SET); exe_hdr = (EXE_HEADER *)mybuf; if (memcmp(exe_hdr->id, "PS-X EXE", 8) == 0) return PSX_EXE; if (mybuf[0] == 'C' && mybuf[1] == 'P' && mybuf[2] == 'E') return CPE_EXE; coff_hdr = (FILHDR *)mybuf; if (SWAPu16(coff_hdr->f_magic) == 0x0162) return COFF_EXE; return INVALID_EXE; }
void psxHwWrite16(u32 add, u16 value) { switch (add) { case 0x1f801040: sioWrite8((unsigned char)value); sioWrite8((unsigned char)(value>>8)); #ifdef PAD_LOG PAD_LOG ("sio write16 %x, %x\n", add&0xf, value); #endif return; case 0x1f801044: sioWriteStat16(value); #ifdef PAD_LOG PAD_LOG ("sio write16 %x, %x\n", add&0xf, value); #endif return; case 0x1f801048: sioWriteMode16(value); #ifdef PAD_LOG PAD_LOG ("sio write16 %x, %x\n", add&0xf, value); #endif return; case 0x1f80104a: // control register sioWriteCtrl16(value); #ifdef PAD_LOG PAD_LOG ("sio write16 %x, %x\n", add&0xf, value); #endif return; case 0x1f80104e: // baudrate register sioWriteBaud16(value); #ifdef PAD_LOG PAD_LOG ("sio write16 %x, %x\n", add&0xf, value); #endif return; #ifdef ENABLE_SIO1API case 0x1f801050: SIO1_writeData16(value); return; case 0x1f801054: SIO1_writeStat16(value); return; case 0x1f80105a: SIO1_writeCtrl16(value); return; case 0x1f80105e: SIO1_writeBaud16(value); return; #endif case 0x1f801070: #ifdef PSXHW_LOG PSXHW_LOG("IREG 16bit write %x\n", value); #endif if (Config.Sio) psxHu16ref(0x1070) |= SWAPu16(0x80); if (Config.SpuIrq) psxHu16ref(0x1070) |= SWAPu16(0x200); psxHu16ref(0x1070) &= SWAPu16((psxHu16(0x1074) & value)); return; case 0x1f801074: #ifdef PSXHW_LOG PSXHW_LOG("IMASK 16bit write %x\n", value); #endif psxHu16ref(0x1074) = SWAPu16(value); if (psxHu16ref(0x1070) & value) new_dyna_set_event(PSXINT_NEWDRC_CHECK, 1); return; case 0x1f801100: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 0 COUNT 16bit write %x\n", value); #endif psxRcntWcount(0, value); return; case 0x1f801104: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 0 MODE 16bit write %x\n", value); #endif psxRcntWmode(0, value); return; case 0x1f801108: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 0 TARGET 16bit write %x\n", value); #endif psxRcntWtarget(0, value); return; case 0x1f801110: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 1 COUNT 16bit write %x\n", value); #endif psxRcntWcount(1, value); return; case 0x1f801114: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 1 MODE 16bit write %x\n", value); #endif psxRcntWmode(1, value); return; case 0x1f801118: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 1 TARGET 16bit write %x\n", value); #endif psxRcntWtarget(1, value); return; case 0x1f801120: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 2 COUNT 16bit write %x\n", value); #endif psxRcntWcount(2, value); return; case 0x1f801124: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 2 MODE 16bit write %x\n", value); #endif psxRcntWmode(2, value); return; case 0x1f801128: #ifdef PSXHW_LOG PSXHW_LOG("COUNTER 2 TARGET 16bit write %x\n", value); #endif psxRcntWtarget(2, value); return; default: if (add>=0x1f801c00 && add<0x1f801e00) { SPU_writeRegister(add, value); return; } psxHu16ref(add) = SWAPu16(value); #ifdef PSXHW_LOG PSXHW_LOG("*Unknown 16bit write at address %x value %x\n", add, value); #endif return; } psxHu16ref(add) = SWAPu16(value); #ifdef PSXHW_LOG PSXHW_LOG("*Known 16bit write at address %x value %x\n", add, value); #endif }