static void write(RomMapperPAC* rm, UInt16 address, UInt8 value) { int update = 0; address &= 0x3fff; switch (address) { case 0x1ffe: rm->sram[0x1ffe] = value; rm->sramEnabled = rm->sram[0x1ffe] == 0x4d && rm->sram[0x1fff] == 0x69; update = 1; break; case 0x1fff: rm->sram[0x1fff] = value; rm->sramEnabled = rm->sram[0x1ffe] == 0x4d && rm->sram[0x1fff] == 0x69; update = 1; break; default: if (rm->sramEnabled && address < 0x1ffe) { rm->sram[address] = value; } break; } if (update) { if (rm->sramEnabled) { slotMapPage(rm->slot, rm->sslot, rm->startPage, rm->sram, 1, 0); } else { slotMapPage(rm->slot, rm->sslot, rm->startPage, NULL, 0, 0); } } }
int romMapperPlayBallCreate(char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { (DeviceCallback)destroy, NULL, NULL, NULL }; RomMapperPlayBall* rm; rm = malloc(sizeof(RomMapperPlayBall)); if (size > 0x8000) { size = 0x8000; } rm->deviceHandle = deviceManagerRegister(ROM_PLAYBALL, &callbacks, rm); slotRegister(slot, sslot, startPage, 4, NULL, NULL, NULL, (SlotEject)destroy, rm); rm->romData = malloc(0x8000); memset(rm->romData + size, 0xff, 0x8000 - size); memcpy(rm->romData, romData, size); rm->size = size; rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; slotMapPage(rm->slot, rm->sslot, rm->startPage, rm->romData + 0x0000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 1, rm->romData + 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 2, rm->romData + 0x4000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 3, rm->romData + 0x6000, 0, 0); return 1; }
int romMapperPlayBallCreate(char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, NULL, NULL }; RomMapperPlayBall* rm; rm = malloc(sizeof(RomMapperPlayBall)); rm->samplePlayer = samplePlayerCreate(boardGetMixer(), MIXER_CHANNEL_PCM, 8, 11025); if (size > 0x8000) { size = 0x8000; } rm->deviceHandle = deviceManagerRegister(ROM_PLAYBALL, &callbacks, rm); slotRegister(slot, sslot, startPage, 4, read, read, write, destroy, rm); rm->romData = malloc(0x8000); memset(rm->romData + size, 0xff, 0x8000 - size); memcpy(rm->romData, romData, size); rm->size = size; rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; slotMapPage(rm->slot, rm->sslot, rm->startPage, rm->romData + 0x0000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 1, rm->romData + 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 2, rm->romData + 0x4000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 3, rm->romData + 0x6000, 0, 0); return 1; }
int romMapperBasicCreate(char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, NULL, NULL }; RomMapperBasic* rm; if (size > 0x8000) { return 0; } rm = malloc(sizeof(RomMapperBasic)); rm->romData = malloc(0x8000); memset(rm->romData, 0xff, 0x8000); memcpy(rm->romData, romData, size); rm->size = size; rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; rm->deviceHandle = deviceManagerRegister(ROM_BASIC, &callbacks, rm); slotRegister(slot, sslot, startPage, 4, NULL, NULL, NULL, destroy, rm); slotMapPage(slot, sslot, startPage + 0, rm->romData + 0x0000, 1, 0); slotMapPage(slot, sslot, startPage + 1, rm->romData + 0x2000, 1, 0); slotMapPage(slot, sslot, startPage + 2, rm->romData + 0x4000, 1, 0); slotMapPage(slot, sslot, startPage + 3, rm->romData + 0x6000, 1, 0); return 1; }
int romMapperKorean126Create(const char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; RomMapperKorean126* rm; int i; if (size < 0x8000) { return 0; } rm = malloc(sizeof(RomMapperKorean126)); rm->deviceHandle = deviceManagerRegister(ROM_KOREAN126, &callbacks, rm); slotRegister(slot, sslot, startPage, 4, NULL, NULL, write, destroy, rm); rm->romData = malloc(size); memcpy(rm->romData, romData, size); rm->size = size; rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; rm->romMapper[0] = 0; rm->romMapper[2] = 0; for (i = 0; i < 4; i += 2) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->romData + rm->romMapper[i] * 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + i + 1, rm->romData + rm->romMapper[i] * 0x2000 + 0x2000, 1, 0); } return 1; }
int romMapperOpcodeSaveRamCreate(int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, reset, saveState, loadState }; DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL }; RomMapperOpcodeSaveRam* rm = malloc(sizeof(RomMapperOpcodeSaveRam)); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; memset(rm->saveRam, 0xff, sizeof(rm->saveRam)); slotRegister(rm->slot, rm->sslot, rm->startPage, 4, NULL, NULL, write, destroy, rm); rm->deviceHandle = deviceManagerRegister(ROM_OPCODESAVE, &callbacks, rm); rm->debugHandle = debugDeviceRegister(DBGTYPE_RAM, "SAVERAM", &dbgCallbacks, rm); slotMapPage(rm->slot, rm->sslot, rm->startPage + 0, rm->saveRam + 0x0000, 1, 1); slotMapPage(rm->slot, rm->sslot, rm->startPage + 1, rm->saveRam + 0x2000, 1, 1); slotMapPage(rm->slot, rm->sslot, rm->startPage + 2, rm->saveRam + 0x4000, 1, 1); slotMapPage(rm->slot, rm->sslot, rm->startPage + 3, rm->saveRam + 0x6000, 1, 1); strcpy(rm->saveRamFilename, sramCreateFilename("SaveRam")); sramLoad(rm->saveRamFilename, rm->saveRam, sizeof(rm->saveRam), NULL, 0); reset(rm); return 1; }
static void setDram(RomMapperDram* rm, int enable) { if (enable) { if (rm->slot == 0 && rm->sslot == 0) { // int endPage = MIN(4, rm->startPage + rm->pages); int page; for (page = rm->startPage; page < 4; page++) { slotMapPage(rm->slot, rm->sslot, page, boardGetRamPage(page - 8), 1, 0); } } else if (rm->slot == 3 && rm->sslot == 1) { // int endPage = MIN(4, rm->startPage + rm->pages); int page; for (page = rm->startPage; page < 4; page++) { slotMapPage(rm->slot, rm->sslot, page, boardGetRamPage(page - 4), 1, 0); } } } else { // int endPage = MIN(4, rm->startPage + rm->pages); int page; for (page = rm->startPage; page < 4; page++) { slotMapPage(rm->slot, rm->sslot, page, rm->romData + 0x2000 * (page - rm->startPage), 1, 0); } } }
static void loadState(RomMapperKonami5* rm) { SaveState* state = saveStateOpenForRead("mapperKonami5"); char tag[16]; int i; for (i = 0; i < 4; i++) { sprintf(tag, "romMapper%d", i); rm->romMapper[i] = saveStateGet(state, tag, 0); } rm->sccEnable = saveStateGet(state, "sccEnable", 0); saveStateClose(state); sccLoadState(rm->scc); for (i = 0; i < 4; i++) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->romData + rm->romMapper[i] * 0x2000, 1, 0); } if (rm->sccEnable) { slotMapPage(rm->slot, rm->sslot, rm->startPage + 2, rm->romData + rm->romMapper[2] * 0x2000, 0, 0); } else { slotMapPage(rm->slot, rm->sslot, rm->startPage + 2, rm->romData + rm->romMapper[2] * 0x2000, 1, 0); } }
static void write(RomMapperMsxDos2* rm, UInt16 address, UInt8 value) { int bank; address += 0x4000; if (address < 0x4000 && address >= 0xC000) { return; } bank = (address & 0x8000) >> 14; if (rm->romMapper[bank] != value) { UInt8* bankData; if (value > rm->size / 0x4000) { value %= rm->size / 0x4000; } bankData = rm->romData + ((int)value << 14); rm->romMapper[bank] = value; slotMapPage(rm->slot, rm->sslot, rm->startPage + bank, bankData, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + bank + 1, bankData + 0x2000, 1, 0); } }
int romMapperPACCreate(const char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; RomMapperPAC* rm; rm = malloc(sizeof(RomMapperPAC)); rm->deviceHandle = deviceManagerRegister(ROM_PAC, &callbacks, rm); slotRegister(slot, sslot, startPage, 2, read, read, write, destroy, rm); memset(rm->sram, 0xff, 0x2000); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; rm->sramEnabled = 0; strcpy(rm->sramFilename, sramCreateFilename(filename)); sramLoad(rm->sramFilename, rm->sram, 0x1ffe, pacHeader, strlen(pacHeader)); slotMapPage(rm->slot, rm->sslot, rm->startPage, NULL, 0, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 1, NULL, 0, 0); return 1; }
static void write(RomMapperSCCplus* rm, UInt16 address, UInt8 value) { int bank; address += 0x4000; if (address < 0x4000 && address >= 0xc000) { return; } if ((address | 1) == 0xbfff) { rm->modeRegister = value; rm->isRamSegment[0] = (value & 0x10) | (value & 0x01); rm->isRamSegment[1] = (value & 0x10) | (value & 0x02); rm->isRamSegment[2] = (value & 0x10) | ((value & 0x24) == 0x24); rm->isRamSegment[3] = (value & 0x10); updateEnable(rm); return; } bank = (address - 0x4000) >> 13; if (rm->isRamSegment[bank]) { if (rm->isMapped[bank]) { rm->romData[0x2000 * (rm->romMapper[bank] & rm->mapperMask) + (address & 0x1fff)] = value; } return; } if ((address & 0x1800) == 0x1000) { rm->romMapper[bank] = value; value &= rm->mapperMask; rm->isMapped[bank] = (value >= 8 && rm->sccType != SCC_SNATCHER) || (value < 8 && rm->sccType != SCC_SDSNATCHER); if (rm->isMapped[bank]) { slotMapPage(rm->slot, rm->sslot, rm->startPage + bank, rm->romData + 0x2000 * value, 1, 0); } else { slotMapPage(rm->slot, rm->sslot, rm->startPage + bank, rm->romData + 0x20000, 1, 0); } updateEnable(rm); return; } if (rm->sccMode == SCC_COMPATIBLE && address >= 0x9800 && address < 0xa000) { sccWrite(rm->scc, address & 0xff, value); } else if (rm->sccMode == SCC_PLUS && address >= 0xb800 && address < 0xc000) { sccWrite(rm->scc, address & 0xff, value); } }
static void writeIo(RomMapperMegaRAM* rm, UInt16 ioPort, UInt8 value) { if (rm->writeEnabled) { int i; for (i = 0; i < 4; i++) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->ramData + rm->romMapper[i] * 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + i + 4, rm->ramData + rm->romMapper[i] * 0x2000, 1, 0); } } rm->writeEnabled = 0; }
static void loadState(RomMapperCvMegaCart* rm) { SaveState* state = saveStateOpenForRead("mapperCvMegaCart"); UInt8* bankData; rm->romMapper = saveStateGet(state, "romMapper", 0); saveStateClose(state); bankData = rm->romData + (rm->romMapper << 14); slotMapPage(rm->slot, rm->sslot, rm->startPage + 2, bankData, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 3, bankData + 0x2000, 0, 0); }
static UInt8 readIo(RomMapperMegaRAM* rm, UInt16 ioPort) { if (!rm->writeEnabled) { int i; for (i = 0; i < 4; i++) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->ramData + rm->romMapper[i] * 0x2000, 1, 1); slotMapPage(rm->slot, rm->sslot, rm->startPage + i + 4, rm->ramData + rm->romMapper[i] * 0x2000, 1, 1); } } rm->writeEnabled = 1; return 0xff; }
static void reset(RomMapperTC8566AF* rm) { int i; tc8566afReset(rm->fdc); rm->romMapper[0] = 0; rm->romMapper[2] = 0; for (i = 0; i < 4; i += 2) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->romData + rm->romMapper[i] * 0x2000, 0, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + i + 1, rm->romData + rm->romMapper[i] * 0x2000 + 0x2000, 0, 0); } }
int romMapperFmDasCreate(char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, NULL, NULL }; RomMapperFmDas* rm; if (size != 0x8000 || startPage != 0) { return 0; } rm = malloc(sizeof(RomMapperFmDas)); rm->deviceHandle = deviceManagerRegister(ROM_FMDAS, &callbacks, rm); slotRegister(slot, sslot, startPage, 8, NULL, NULL, NULL, destroy, rm); rm->romData = malloc(0x8000); memcpy(rm->romData, romData, 0x8000); memset(rm->romData + 0x2000, 0xff, 0x2000); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; slotMapPage(slot, sslot, 0, rm->romData + 0x0000, 1, 0); slotMapPage(slot, sslot, 1, rm->romData + 0x2000, 1, 1); slotMapPage(slot, sslot, 2, rm->romData + 0x4000, 1, 0); slotMapPage(slot, sslot, 3, rm->romData + 0x6000, 1, 0); slotMapPage(slot, sslot, 4, rm->romData + 0x0000, 1, 0); slotMapPage(slot, sslot, 5, rm->romData + 0x2000, 1, 1); slotMapPage(slot, sslot, 6, rm->romData + 0x4000, 1, 0); slotMapPage(slot, sslot, 7, rm->romData + 0x6000, 1, 0); return 1; }
static void slotUpdate(RomMapperOpcodeModule* rm) { UInt8 slotSelect = rm->slotSelect; int i; slotMapPage(rm->slot, rm->sslot, 0, rm->biosRom + rm->biosLatch * 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, 1, rm->ram + 0x0000, 1, 1); slotMapPage(rm->slot, rm->sslot, 2, rm->ram + 0x2000, 1, 1); slotMapPage(rm->slot, rm->sslot, 3, rm->ram + 0x4000, 1, 1); for (i = 0; i < 4; i++, slotSelect >>= 2) { switch (slotSelect & 3) { case SLOT_CARTRIDGE: slotMapPage(rm->slot, rm->sslot, 4 + i, rm->rom + 0x2000 * i, 1, 0); break; case SLOT_MEGARAM: slotMapPage(rm->slot, rm->sslot, 4 + i, rm->megaRam + 0x2000 * rm->megaRamLatch[i], 1, 1); break; case SLOT_SAVERAM: slotMapPage(rm->slot, rm->sslot, 4 + i, rm->saveRam + 0x2000 * i, 1, 0); break; case SLOT_EMPTY: slotMapPage(rm->slot, rm->sslot, 4 + i, NULL, 0, 0); break; } } }
static void write(RomMapperCrossBlaim* rm, UInt16 address, UInt8 value) { value&=3; if (rm->romMapper[2] != value) { rm->romMapper[2] = value; if (value&2) { // ROM 1 // page 2 specified bank UInt8* bankData = rm->romData + ((int)value << 14); slotMapPage(rm->slot, rm->sslot, 4, bankData, 1, 0); slotMapPage(rm->slot, rm->sslot, 5, bankData + 0x2000, 1, 0); // page 0 and 3 unmapped slotMapPage(rm->slot, rm->sslot, 0, NULL, 0, 0); slotMapPage(rm->slot, rm->sslot, 1, NULL, 0, 0); slotMapPage(rm->slot, rm->sslot, 6, NULL, 0, 0); slotMapPage(rm->slot, rm->sslot, 7, NULL, 0, 0); } else { int i; // ROM 0 // page 2 bank 1, page 0 and 3 mirrors of page 2 for (i=0;i<8;i+=2) { if (i==2) continue; slotMapPage(rm->slot, rm->sslot, i, rm->romData+0x4000, 1, 0); slotMapPage(rm->slot, rm->sslot, i+1, rm->romData+0x6000, 1, 0); } } } }
int romMapperNationalFdcCreate(const char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; RomMapperNationalFdc* rm; int pages = 4; int i; if ((startPage + pages) > 8) { return 0; } rm = malloc(sizeof(RomMapperNationalFdc)); rm->deviceHandle = deviceManagerRegister(ROM_NATIONALFDC, &callbacks, rm); slotRegister(slot, sslot, startPage, pages, read, peek, write, destroy, rm); rm->romData = malloc(size); memcpy(rm->romData, romData, size); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; for (i = 0; i < pages; i++) { slotMapPage(slot, sslot, i + startPage, NULL, 0, 0); } rm->fdc = wd2793Create(FDC_TYPE_WD2793); reset(rm); return 1; }
int romMapperKonamiWordProCreate(char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, reset, saveState, loadState }; RomMapperKonamiWordPro* rm; int pages = 8; int i; if (size != 0x8000) { return 0; } rm = malloc(sizeof(RomMapperKonamiWordPro)); if (pages == 8) startPage = 0; rm->deviceHandle = deviceManagerRegister(ROM_KONWORDPRO, &callbacks, rm); slotRegister(slot, sslot, startPage, pages, read, read, write, destroy, rm); rm->romData = calloc(1, size); memcpy(rm->romData, romData, size); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; for (i = 0; i < pages; i++) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->romData + i * 0x2000, 0, 0); } reset(rm); return 1; }
int romMapperMajutsushiCreate(const char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; RomMapperMajutsushi* rm; int i; if (size < 0x8000) { return 0; } rm = malloc(sizeof(RomMapperMajutsushi)); rm->deviceHandle = deviceManagerRegister(ROM_MAJUTSUSHI, &callbacks, rm); slotRegister(slot, sslot, startPage, 4, NULL, NULL, write, destroy, rm); rm->romData = malloc(size); memcpy(rm->romData, romData, size); rm->dac = dacCreate(boardGetMixer(), DAC_MONO); rm->size = size; rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; rm->romMapper[0] = 0; rm->romMapper[1] = 1; rm->romMapper[2] = 2; rm->romMapper[3] = 3; for (i = 0; i < 4; i++) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->romData + rm->romMapper[i] * 0x2000, 1, 0); } return 1; }
int romMapperSg1000Create(const char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, NULL, NULL }; RomMapperSg1000* rm; int pages = size / 0x2000 + ((size & 0x1fff) ? 1 : 0); int i; if (pages == 0 || (startPage + pages) > 8) { return 0; } rm = malloc(sizeof(RomMapperSg1000)); rm->deviceHandle = deviceManagerRegister(ROM_SG1000, &callbacks, rm); slotRegister(slot, sslot, startPage, pages, NULL, NULL, NULL, destroy, rm); rm->romData = malloc(pages * 0x2000); memcpy(rm->romData, romData, size); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; for (i = 0; i < pages; i++) { if (i + startPage >= 2) slot = 0; slotMapPage(slot, sslot, i + startPage, rm->romData + 0x2000 * i, 1, 0); } return 1; }
int romMapperKonamiSynthCreate(const char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, NULL, NULL }; RomMapperKonamiSynth* rm; int i; if (size != 0x8000) { return 0; } rm = malloc(sizeof(RomMapperKonamiSynth)); rm->deviceHandle = deviceManagerRegister(ROM_KONAMISYNTH, &callbacks, rm); slotRegister(slot, sslot, startPage, 4, NULL, NULL, write, destroy, rm); rm->romData = malloc(size); memcpy(rm->romData, romData, size); rm->dac = dacCreate(boardGetMixer(), DAC_MONO); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; for (i = 0; i < 4; i++) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->romData + i * 0x2000, 1, 0); } return 1; }
static void write(RomMapperMajutsushi* rm, UInt16 address, UInt8 value) { int bank; address += 0x4000; if (address >= 0x5000 && address < 0x6000) { dacWrite(rm->dac, DAC_CH_MONO, value); return; } /* Page at 4000h is fixed */ if (address < 0x6000 || address >= 0xc000) { return; } bank = (address - 0x4000) >> 13; value %= rm->size / 0x2000; if (rm->romMapper[bank] != value) { UInt8* bankData = rm->romData + ((int)value << 13); rm->romMapper[bank] = value; slotMapPage(rm->slot, rm->sslot, rm->startPage + bank, bankData, 1, 0); } }
int romMapperGameReaderCreate(int cartSlot, int slot, int sslot) { DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState }; RomMapperGameReader* rm; int i; rm = malloc(sizeof(RomMapperGameReader)); rm->deviceHandle = deviceManagerRegister(ROM_GAMEREADER, &callbacks, rm); rm->slot = slot; rm->sslot = sslot; rm->cartSlot = cartSlot; // f = fopen("c:\\grlog.txt", "w+"); rm->gameReader = gameReaderCreate(cartSlot); for (i = 0; i < CACHE_LINES; i++) { rm->cacheLineEnabled[i] = 0; } if (rm->gameReader != NULL) { ioPortRegisterUnused(cartSlot, readIo, writeIo, rm); slotRegister(slot, sslot, 0, 8, read, read, write, destroy, rm); for (i = 0; i < 8; i++) { slotMapPage(rm->slot, rm->sslot, i, NULL, 0, 0); } } return 1; }
int romMapperSf7000IplCreate(char* filename, UInt8* romData, int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { destroy, NULL, NULL, NULL }; RomMapperSf7000Ipl* rm; int pages = 2; int i; rm = malloc(sizeof(RomMapperSf7000Ipl)); rm->deviceHandle = deviceManagerRegister(ROM_NORMAL, &callbacks, rm); slotRegister(slot, sslot, startPage, pages, NULL, NULL, write, destroy, rm); rm->romData = malloc(0x4000); if (size > 0x4000) { size = 0x4000; } memcpy(rm->romData, romData, size); memset(rm->romData + size, 0xff, 0x4000 - size); rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; for (i = 0; i < pages; i++) { slotMapPage(slot, sslot, i + startPage, rm->romData + 0x2000 * i, 1, 0); } return 1; }
int romMapperSCCplusCreate(const char* filename, UInt8* romData, int size, int slot, int sslot, int startPage, SccType sccType) { DeviceCallbacks callbacks = { destroy, reset, saveState, loadState }; RomMapperSCCplus* rm; rm = malloc(sizeof(RomMapperSCCplus)); rm->deviceHandle = deviceManagerRegister(ROM_SCCEXTENDED, &callbacks, rm); slotRegister(slot, sslot, startPage, 4, read, peek, write, destroy, rm); memset(rm->romData, 0xff, 0x22000); if (romData) { if (size > 0x20000) { size = 0x20000; } memcpy(rm->romData, romData, size); } rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; rm->modeRegister = sccType == SCCP_EXTENDED ? 0x20 : 0; rm->isRamSegment[0] = 0; rm->isRamSegment[1] = 0; rm->isRamSegment[2] = 0; rm->isRamSegment[3] = 0; rm->isMapped[0] = sccType != SCC_SDSNATCHER; rm->isMapped[1] = sccType != SCC_SDSNATCHER; rm->isMapped[2] = sccType != SCC_SDSNATCHER; rm->isMapped[3] = sccType != SCC_SDSNATCHER; rm->mapperMask = sccType == SCC_MIRRORED ? 0x07 : 0x0f; rm->scc = sccCreate(boardGetMixer()); rm->sccType = sccType; rm->sccMode = SCC_NONE; rm->romMapper[0] = 0; rm->romMapper[1] = 1; rm->romMapper[2] = 2; rm->romMapper[3] = 3; if (sccType != SCC_SDSNATCHER) { slotMapPage(rm->slot, rm->sslot, rm->startPage, rm->romData + 0x0000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 1, rm->romData + 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 2, rm->romData + 0x4000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 3, rm->romData + 0x6000, 1, 0); } else { slotMapPage(rm->slot, rm->sslot, rm->startPage, rm->romData + 0x20000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 1, rm->romData + 0x20000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 2, rm->romData + 0x20000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + 3, rm->romData + 0x20000, 1, 0); } return 1; }
static void slotUpdate(RomMapperOpcodeMegaRam* rm) { int i; for (i = 0; i < 4; i++) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->megaRam + 0x2000 * rm->megaRamLatch[i], 1, 1); } }
int ramMirroredCreate(int size, int slot, int sslot, int startPage, UInt32 ramBlockSize, UInt8** ramPtr, UInt32* ramSize) { DeviceCallbacks callbacks = { (DeviceCallback)destroy, NULL, (DeviceCallback)saveState, (DeviceCallback)loadState }; DebugCallbacks dbgCallbacks = { (void(*)(void*,DbgDevice*))getDebugInfo, (int(*)(void*,char*,void*,int,int))dbgWriteMemory, NULL, NULL }; Ram1kBMirrored* rm; int pages = size / 0x2000; int i; if (size > 0x10000 || (size & 0x1fff)) { return 0; } // Start page must be zero (only full slot allowed) if (startPage + pages > 8) { return 0; } rm = malloc(sizeof(Ram1kBMirrored)); rm->mask = ramBlockSize - 1; rm->slot = slot; rm->sslot = sslot; rm->startPage = startPage; rm->pages = pages; memset(rm->ramData, 0, sizeof(rm->ramData)); rm->debugHandle = debugDeviceRegister(DBGTYPE_RAM, langDbgDevRam(), &dbgCallbacks, rm); for (i = 0; i < pages; i++) { slotMapPage(slot, sslot, i + startPage, NULL, 0, 0); } rm->deviceHandle = deviceManagerRegister(ramBlockSize == 0x400 ? RAM_1KB_MIRRORED : RAM_2KB_MIRRORED, &callbacks, rm); slotRegister(slot, sslot, startPage, pages, (SlotRead)read, (SlotRead)read, (SlotWrite)write, (SlotEject)destroy, rm); if (ramPtr != NULL) { *ramPtr = rm->ramData; } if (ramSize != NULL) { *ramSize = rm->pages * 0x2000; } return 1; }
int romMapperMegaRAMCreate(int size, int slot, int sslot, int startPage) { DeviceCallbacks callbacks = { (DeviceCallback)destroy, NULL, (DeviceCallback)saveState, (DeviceCallback)loadState }; DebugCallbacks dbgCallbacks = { (void(*)(void*,DbgDevice*))getDebugInfo, NULL, NULL, NULL }; RomMapperMegaRAM* rm; int i; if (startPage != 0) { return 0; } rm = malloc(sizeof(RomMapperMegaRAM)); rm->deviceHandle = deviceManagerRegister(ROM_MEGARAM, &callbacks, rm); rm->debugHandle = debugDeviceRegister(DBGTYPE_CART, langDbgDevMegaRam(), &dbgCallbacks, rm); slotRegister(slot, sslot, startPage, 8, NULL, NULL, (SlotWrite)write, (SlotEject)destroy, rm); rm->ramData = malloc(size); memset(rm->ramData, 0xff, size); rm->size = size; rm->slot = slot; rm->sslot = sslot; rm->writeEnabled = 0; rm->startPage = startPage; rm->romMapper[0] = 0; rm->romMapper[1] = 0; rm->romMapper[2] = 0; rm->romMapper[3] = 0; for (i = 0; i < 4; i++) { slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->ramData + rm->romMapper[i] * 0x2000, 1, 0); slotMapPage(rm->slot, rm->sslot, rm->startPage + i + 4, rm->ramData + rm->romMapper[i] * 0x2000, 1, 0); } ioPortRegister(0x8e, (IoPortRead)readIo, (IoPortWrite)writeIo, rm); return 1; }