예제 #1
0
void sviPPICreate(SviJoyIo* joyIO)
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL };
    SviPPI* ppi = malloc(sizeof(SviPPI));

    ppi->deviceHandle = deviceManagerRegister(RAM_MAPPER, &callbacks, ppi);
    ppi->debugHandle = debugDeviceRegister(DBGTYPE_BIOS, langDbgDevPpi(), &dbgCallbacks, ppi);

    ppi->joyIO = joyIO;
    ppi->i8255 = i8255Create(peekA, readA, NULL,
                             peekB, readB, NULL,
                             NULL,  NULL,  writeCLo,
                             NULL,  NULL,  writeCHi,
                             ppi);

    ppi->keyClick = audioKeyClickCreate(boardGetMixer());

    ppi->dac = dacCreate(boardGetMixer(), DAC_MONO);

    ioPortRegister(0x98, i8255Read, i8255Write, ppi->i8255); // PPI Port A
    ioPortRegister(0x99, i8255Read, i8255Write, ppi->i8255); // PPI Port B
    ioPortRegister(0x96, i8255Read, i8255Write, ppi->i8255); // PPI Port C
    ioPortRegister(0x97, i8255Read, i8255Write, ppi->i8255); // PPI Mode
    ioPortRegister(0x9A, readRow, NULL,  ppi); // PPI Return Port C (Low)

    reset(ppi);
}
예제 #2
0
int romMapperMoonsoundCreate(char* filename, UInt8* romData, int size, int sramSize)
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL };
    RomMapperMoonsound* rm = malloc(sizeof(RomMapperMoonsound));

    rm->deviceHandle = deviceManagerRegister(ROM_MOONSOUND, &callbacks, rm);
    rm->debugHandle = debugDeviceRegister(DBGTYPE_AUDIO, langDbgDevMoonsound(), &dbgCallbacks, rm);
    
    rm->moonsound = NULL;

    if (boardGetMoonsoundEnable()) {
        rm->moonsound = moonsoundCreate(boardGetMixer(), romData, size, sramSize);
        ioPortRegister(0x7e, read, write, rm);
        ioPortRegister(0x7f, read, write, rm);
        ioPortRegister(0xc4, read, write, rm);
        ioPortRegister(0xc5, read, write, rm);
        ioPortRegister(0xc6, read, write, rm);
        ioPortRegister(0xc7, read, write, rm);
    }
    else {
        // moonsound emulation has ownership of rom data. Need to
        // free it if its not being used.
        free(romData);
    }

    reset(rm);

    return 1;
}
예제 #3
0
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;
}
예제 #4
0
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 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;
}
예제 #6
0
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;
}
int romMapperKonamiKeyboardMasterCreate(const char* filename, UInt8* romData, 
                                        int size, int slot, int sslot, 
                                        int startPage,
                                       void* voiceRom, int voiceSize) 
{
    DeviceCallbacks callbacks = { destroy, NULL, saveState, loadState };
    DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL };
    RomMapperKonamiKeyboardMaster* rm;
    int i;

    if (size != 0x4000) {
        return 0;
    }

    rm = malloc(sizeof(RomMapperKonamiKeyboardMaster));

    rm->deviceHandle = deviceManagerRegister(ROM_KONAMKBDMAS, &callbacks, rm);
    rm->debugHandle = debugDeviceRegister(DBGTYPE_CART, langDbgDevKonamiKbd(), &dbgCallbacks, rm);

    slotRegister(slot, sslot, startPage, 4, NULL, NULL, NULL, destroy, rm);

    rm->romData = malloc(size);
    memcpy(rm->romData, romData, size);

    rm->voiceData = calloc(1, 0x4000);
    if (voiceRom != NULL) {
        if (voiceSize > 0x4000) {
            voiceSize = 0x4000;
        }
        memcpy(rm->voiceData, voiceRom, voiceSize);
    }
    else {
        memcpy(rm->voiceData, voiceData, 0x4000);
    }

    rm->vlm5030 = vlm5030Create(boardGetMixer(), rm->voiceData, 0x4000);
    rm->slot  = slot;
    rm->sslot = sslot;
    rm->startPage  = startPage;

    for (i = 0; i < 2; i++) {   
        slotMapPage(rm->slot, rm->sslot, rm->startPage + i, rm->romData + i * 0x2000, 1, 0);
    }

    ioPortRegister(0x00, read, write, rm);
    ioPortRegister(0x20, read, write, rm);

    return 1;
}
int romMapperOpcodeModuleCreate(char* filename, UInt8* romData, 
                                int size, int slot, int sslot, 
                                int startPage,
                                void* biosRom, int biosSize) 
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL };
    
    RomMapperOpcodeModule* rm = malloc(sizeof(RomMapperOpcodeModule));
    
    rm->slot      = slot;
    rm->sslot     = sslot;
    rm->startPage = startPage;
    
    memset(rm->ram, 0xff, sizeof(rm->ram));
    memset(rm->biosRom, 0xff, sizeof(rm->biosRom));
    memset(rm->rom, 0xff, sizeof(rm->rom));
    memset(rm->megaRam, 0xff, sizeof(rm->megaRam));
    memset(rm->saveRam, 0xff, sizeof(rm->saveRam));

    if (biosRom != NULL) {
        if (biosSize > sizeof(rm->biosRom)) {
            biosSize = sizeof(rm->biosRom);
        }
        memcpy(rm->biosRom, biosRom, biosSize);
    }

    if (romData != NULL) {
        if (size > sizeof(rm->rom)) {
            size = sizeof(rm->rom);
        }
        memcpy(rm->rom, romData, size);
    }

    rm->deviceHandle = deviceManagerRegister(ROM_OPCODEPSG, &callbacks, rm);
    rm->debugHandle = debugDeviceRegister(DBGTYPE_AUDIO, "AY8910", &dbgCallbacks, rm);

    rm->ay8910 = ay8910Create(boardGetMixer(), AY8910_MSX, PSGTYPE_AY8910, 0, NULL);

    ioPortRegister(0x40, read, write, rm);
    ioPortRegister(0x50, NULL, write, rm);
    ioPortRegister(0x51, NULL, write, rm);
    ioPortRegister(0x52, read, NULL, rm);

    reset(rm);

    return 1;
}
예제 #9
0
static void setType(PrinterIO* printerIO)
{
    printerIO->type = thePrinterType;

    switch (printerIO->type) {
    case PRN_HOST:
        printerIO->printerReady = archPrinterCreate();
        break;
    case PRN_FILE:
        printerIO->file = archFileOpen(theFileName, "w+");
        break;
    case PRN_SIMPL:
        printerIO->dac = dacCreate(boardGetMixer(), DAC_MONO);
        break;
    }
}
예제 #10
0
int romMapperTurboRPcmCreate() 
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL };
    RomMapperTurboRPcm* rm = malloc(sizeof(RomMapperTurboRPcm));

    rm->deviceHandle = deviceManagerRegister(ROM_TURBORPCM, &callbacks, rm);
    rm->debugHandle = debugDeviceRegister(DBGTYPE_AUDIO, langDbgDevPcm(), &dbgCallbacks, rm);

    rm->mixer  = boardGetMixer();

    rm->dac    = dacCreate(rm->mixer, DAC_MONO);
	rm->status = 0;
    rm->time   = 0;

    ioPortRegister(0xa4, read, write, rm);
    ioPortRegister(0xa5, read, write, rm);

    return 1;
}
예제 #11
0
int romMapperKonami5Create(const char* filename, UInt8* romData,
                           int size, int slot, int sslot, int startPage) 
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    RomMapperKonami5* rm;
    int i;

    int origSize = size;
    
    size = 0x8000;
    while (size < origSize) {
        size *= 2;
    }


    rm = malloc(sizeof(RomMapperKonami5));

    rm->deviceHandle = deviceManagerRegister(ROM_KONAMI5, &callbacks, rm);
    slotRegister(slot, sslot, startPage, 4, read, peek, write, destroy, rm);

    rm->romData = calloc(1, size);
    memcpy(rm->romData, romData, origSize);
    rm->romMask = size / 0x2000 - 1;
    rm->slot  = slot;
    rm->sslot = sslot;
    rm->startPage  = startPage;
    rm->scc = sccCreate(boardGetMixer());
    sccSetMode(rm->scc, SCC_REAL);
    rm->sccEnable = 0;

    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;
}
예제 #12
0
int romMapperNetCreate(const char* filename, UInt8* romData,
                       int size, int slot, int sslot, int startPage) 
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL };
    RomMapperNet* rm;
    int i;
    int pages = size / 0x2000;

    if (size != 0x4000 && size != 0x8000) {
        return 0;
    }

    rm = malloc(sizeof(RomMapperNet));

    rm->deviceHandle = deviceManagerRegister(ROM_YAMAHANET, &callbacks, rm);
    rm->debugHandle = debugDeviceRegister(DBGTYPE_BIOS, "Yamaha Net", &dbgCallbacks, rm);

    slotRegister(slot, sslot, startPage, pages, read, read, write, destroy, rm);

    rm->romData = malloc(size);
    memcpy(rm->romData, romData, size);
    rm->slot  = slot;
    rm->sslot = sslot;
    rm->startPage  = startPage;
    rm->sizeMask = size - 1;

    for (i = 0; i < pages; i++) {
        slotMapPage(rm->slot, rm->sslot, rm->startPage + i, NULL, 0, 0);
    }

    rm->ym2151 = ym2151Create(boardGetMixer());
    rm->ym2148 = ym2148Create();
    rm->ykIo = ykIoCreate();

    reset(rm);

    return 1;
}
int romMapperMegaFlashRomSccCreate(const char* filename, UInt8* romData,
                                   int size, int slot, int sslot, int startPage, UInt32 writeProtectMask) 
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    RomMapperMegaFlashRomScc* rm;
    int i;

    rm = calloc(1, sizeof(RomMapperMegaFlashRomScc));

    rm->deviceHandle = deviceManagerRegister(ROM_MEGAFLSHSCC, &callbacks, rm);
    slotRegister(slot, sslot, startPage, 4, read, peek, write, destroy, rm);

    if (size >= 0x80000) {
        size = 0x80000;
    }
    
    rm->romData = malloc(0x80000);
    memset(rm->romData, 0xff, 0x80000);
    memcpy(rm->romData, romData, size);
    rm->size = 0x80000;
    rm->slot  = slot;
    rm->sslot = sslot;
    rm->romMask = rm->size / 0x2000 - 1;
    rm->startPage  = startPage;
    rm->scc = sccCreate(boardGetMixer());
    sccSetMode(rm->scc, SCC_REAL);
    rm->sccEnable = 0;

    rm->flash = amdFlashCreate(AMD_TYPE_2, 0x80000, 0x10000, writeProtectMask, romData, size, sramCreateFilenameWithSuffix(filename, "", ".sram"), 1);

    for (i = 0; i < 4; i++) {   
        mapPage(rm, i, i);
    }

    return 1;
}
예제 #14
0
int sg1000Create(Machine* machine, 
                 VdpSyncMode vdpSyncMode,
                 BoardInfo* boardInfo)
{
    int success;
    int i;

    sfRam = NULL;

    r800 = r800Create(0, slotRead, slotWrite, ioPortRead, ioPortWrite, NULL, boardTimerCheckTimeout, NULL, NULL, NULL, NULL);

    boardInfo->cartridgeCount   = 1;
    boardInfo->diskdriveCount   = 0;
    boardInfo->casetteCount     = 0;
    boardInfo->cpuRef           = r800;

    boardInfo->destroy          = destroy;
    boardInfo->softReset        = reset;
    boardInfo->loadState        = loadState;
    boardInfo->saveState        = saveState;
    boardInfo->getRefreshRate   = getRefreshRate;
    boardInfo->getRamPage       = getRamPage;

    boardInfo->run              = r800Execute;
    boardInfo->stop             = r800StopExecution;
    boardInfo->setInt           = r800SetInt;
    boardInfo->clearInt         = r800ClearInt;
    boardInfo->setCpuTimeout    = r800SetTimeoutAt;
    boardInfo->setBreakpoint    = r800SetBreakpoint;
    boardInfo->clearBreakpoint  = r800ClearBreakpoint;
    boardInfo->setDataBus       = r800SetDataBus;

    boardInfo->changeCartridge  = changeCartridge;

    deviceManagerCreate();
    
    boardInit(&r800->systemTime);
    ioPortReset();

    r800Reset(r800, 0);
    mixerReset(boardGetMixer());

    r800DebugCreate(r800);

    sn76489 = sn76489Create(boardGetMixer());

    slotManagerCreate();

    if (vdpSyncMode == VDP_SYNC_AUTO) {
        vdpSyncMode = VDP_SYNC_60HZ;
    }
    vdpCreate(VDP_SG1000, machine->video.vdpVersion, vdpSyncMode, machine->video.vramSize / 0x4000);

    joyIo = sg1000JoyIoCreate();
    if (machine->board.type == BOARD_SC3000) {
        sc3000PPICreate(joyIo);
    }
    if (machine->board.type == BOARD_SF7000) {
        sc3000PPICreate(joyIo);
        sf7000PPICreate();
            
        diskEnable(0, machine->fdc.count > 0);
        diskEnable(1, machine->fdc.count > 1);
    }
    sg1000IoPortCreate();

	ledSetCapslock(0);

    for (i = 0; i < 4; i++) {
        slotSetSubslotted(i, 0);
    }
    for (i = 0; i < 2; i++) {
        cartridgeSetSlotInfo(i, 2 + i, 0);
    }

    success = machineInitialize(machine, &sfRam, &sfRamSize, &sfRamStart);

    for (i = 0; i < 8; i++) {
        slotMapRamPage(0, 0, i);
    }

    if (machine->board.type == BOARD_SF7000) {
        slotSetRamSlot(0, 1);
    }

    if (success) {
        success = boardInsertExternalDevices();
    }

    r800SetFrequency(r800, CPU_Z80,  machine->cpu.freqZ80);
    r800SetFrequency(r800, CPU_R800, machine->cpu.freqR800);

    if (!success) {
        destroy();
    }

    return success;
}
예제 #15
0
int romMapperMsxAudioCreate(const char* filename, UInt8* romData, 
                            int size, int slot, int sslot, int startPage) 
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL };
    RomMapperMsxAudio* rm;
    int i;

    rm = malloc(sizeof(RomMapperMsxAudio));

    rm->deviceHandle = deviceManagerRegister(ROM_MSXAUDIO, &callbacks, rm);
    rm->debugHandle = debugDeviceRegister(DBGTYPE_AUDIO, langDbgDevMsxAudio(), &dbgCallbacks, rm);

    rm->ioBase = 0xc0 + deviceCount++ * 2;

    rm->romData = NULL;

    if (size > 0) {
        int pages=8;
        rm->is_fs_ca1 = (size == 0x20000); // meh
        // pages=rm->is_fs_ca1?4:8;
        
        // For FS-CA1, $8000-$FFFF is unmapped
        // firmware locks up, needs more testing
        slotRegister(slot, sslot, startPage, pages, read, read, write, destroy, rm);

        rm->romData = malloc(size);
        memcpy(rm->romData, romData, size);
        memset(rm->ram, 0, 0x1000);
        rm->bankSelect = 0;
        rm->sizeMask = size - 1;
        rm->slot  = slot;
        rm->sslot = sslot;
        rm->startPage  = startPage;
        rm->midi = NULL;

        if (!switchGetAudio()) {
            // FS-CA1 BIOS hack, ret z -> nop
            // not needed if port select register is emulated
            rm->romData[0x408e] = 0;
        }
        
        for (i = 0; i < pages; i++) {
            slotMapPage(rm->slot, rm->sslot, rm->startPage + i, NULL, 0, 0);
        }
    }

    rm->y8950 = NULL;

    if (boardGetY8950Enable()) {
        rm->y8950 = y8950Create(boardGetMixer());
       	
       	ioPortRegister(rm->ioBase + 0, y8950Read, y8950Write, rm->y8950);
       	ioPortRegister(rm->ioBase + 1, y8950Read, y8950Write, rm->y8950);
	
        ioPortRegister(0x00, NULL, midiWrite, rm);
        ioPortRegister(0x01, NULL, midiWrite, rm);
        ioPortRegister(0x04, midiRead, NULL, rm);
        ioPortRegister(0x05, midiRead, NULL, rm);
    }
    
    if (deviceCount == 1) {
        rm->midi = philipsMidiCreate();
    }
    
    reset(rm);

    return 1;
}
예제 #16
0
int romMapperFMPAKCreate(const char* filename, UInt8* romData,
                         int size, int slot, int sslot, int startPage) 
{
    DeviceCallbacks callbacks = { destroy, reset, saveState, loadState };
    DebugCallbacks dbgCallbacks = { getDebugInfo, NULL, NULL, NULL };
    RomMapperFMPAK* rm;
    int romMapper[8];
    int i;

    if (size > 0x10000) {
        return 0;
    }

    rm = malloc(sizeof(RomMapperFMPAK));

    rm->romData = malloc(0x10000);
    memset(rm->romData, 0xff, 0x10000);
    memcpy(rm->romData, romData, size);

    // Align ROM size up to next valid rom size
    if      (size <= 0x2000)  size = 0x2000;
    else if (size <= 0x4000)  size = 0x4000;
    else if (size <= 0x8000)  size = 0x8000;
    else if (size <= 0xc000)  size = 0xc000;
    else if (size <= 0x10000) size = 0x10000;

    rm->size = size;
    rm->slot  = slot;
    rm->sslot = sslot;
    rm->startPage  = startPage;

    switch (size) {
    case 0x2000:
        for (i = 0; i < 8; i++) {
            romMapper[i] = 0;
        }
        break;

    case 0x4000:
        for (i = 0; i < 8; i++) {
            romMapper[i] = i & 1;
        }
        break;
        
    case 0x8000:
        if (getRomStart(romData, size) == 0x4000) {
            for (i = 0; i < 4; i++) {
                romMapper[i] = i & 1;
                romMapper[i + 4] = 2 + (i & 1);
            }
        }
        else {
            for (i = 0; i < 8; i++) {
                romMapper[i] = i & 3;
            }
        }
        break;
        
    case 0xc000:
        if (getRomStart(romData, size) == 0x4000) {
            romMapper[0] = 0;
            romMapper[1] = 1;

            for (i = 0; i < 6; i++) {
                romMapper[i + 2] = i;
            }
        }
        else {
            for (i = 0; i < 6; i++) {
                romMapper[i] = i;
            }
            
            romMapper[6] = 0;
            romMapper[7] = 1;
        }
        break;

    case 0x10000:
        for (i = 0; i < 8; i++) {
            romMapper[i] = i;
        }
        break;
        
    default:
        free(rm);
        return 0;
    }
    
    rm->ym2413 = NULL;
    if (boardGetYm2413Enable()) {
        rm->ym2413 = ym2413Create(boardGetMixer());
        rm->debugHandle = debugDeviceRegister(DBGTYPE_AUDIO, langDbgDevFmpak(), &dbgCallbacks, rm);
        ioPortRegister(0x7c, NULL, writeIo, rm);
        ioPortRegister(0x7d, NULL, writeIo, rm);
    }

    rm->deviceHandle = deviceManagerRegister(ROM_FMPAK, &callbacks, rm);
    slotRegister(slot, sslot, startPage, 8, NULL, NULL, NULL, destroy, rm);

    for (i = 0; i < 8; i++) {
        slotMapPage(slot, sslot, startPage + i, rm->romData + 0x2000 * romMapper[i], 1, 0);
    }

    return 1;
}
예제 #17
0
파일: SVI.c 프로젝트: imclab/CocoaMSX
int sviCreate(Machine* machine, 
              VdpSyncMode vdpSyncMode,
              BoardInfo* boardInfo)
{
    int success;
    int i;

    r800 = r800Create(CPU_ENABLE_M1, sviMemRead, sviMemWrite, ioPortRead, ioPortWrite, PatchZ80, (R800TimerCb)boardTimerCheckTimeout, NULL, NULL, NULL, NULL);

    boardInfo->cartridgeCount   = 1;
    boardInfo->diskdriveCount   = 2;
    boardInfo->casetteCount     = 1;
    boardInfo->cpuRef           = r800;

    boardInfo->destroy          = destroy;
    boardInfo->softReset        = reset;
    boardInfo->loadState        = loadState;
    boardInfo->saveState        = saveState;
    boardInfo->getRefreshRate   = getRefreshRate;
    boardInfo->getRamPage       = NULL;

    boardInfo->run              = (void(*)(void*))r800Execute;
    boardInfo->stop             = (void(*)(void*))r800StopExecution;
    boardInfo->setInt           = (void(*)(void*))r800SetInt;
    boardInfo->clearInt         = (void(*)(void*))r800ClearInt;
    boardInfo->setCpuTimeout    = (void(*)(void*, UInt32))r800SetTimeoutAt;
    boardInfo->setBreakpoint    = (void(*)(void*, UInt16))r800SetBreakpoint;
    boardInfo->clearBreakpoint  = (void(*)(void*, UInt16))r800ClearBreakpoint;
    boardInfo->setDataBus       = (void(*)(void*, UInt8, UInt8, int))r800SetDataBus;

    deviceManagerCreate();
    boardInit(&r800->systemTime);
    ioPortReset();
    r800Reset(r800, 0);
    mixerReset(boardGetMixer());

    r800DebugCreate(r800);

    ay8910 = ay8910Create(boardGetMixer(), AY8910_SVI, PSGTYPE_AY8910, 0, machine->audio.psgpan);
    ay8910SetIoPort(ay8910, sviPsgReadHandler, sviPsgPollHandler, sviPsgWriteHandler, NULL);

    keyClick  = audioKeyClickCreate(boardGetMixer());

    joyIO = sviJoyIoCreate();
    
    sviPPICreate(joyIO);
    slotManagerCreate();

    svi80ColEnabled = 0;

    /* Initialize VDP */
    vdpCreate(VDP_SVI, machine->video.vdpVersion, vdpSyncMode, machine->video.vramSize / 0x4000);

    /* Initialize memory */
    for (i = 0; i < 4; i++) {
        slotSetSubslotted(i, 0);
    }
    for (i = 0; i < 2; i++) {
        cartridgeSetSlotInfo(i, machine->cart[i].slot, 0);
    }

    success = machineInitialize(machine, &sviRam, &sviRamSize, &sviRamStart);
    success &= sviLoad80Col(machine, vdpSyncMode);

    for (i = 0; i < 8; i++) {
        slotMapRamPage(0, 0, i);
    }

    sviMemSetBank(0xDF);
    ledSetCapslock(0);

    if (success) {
        success = boardInsertExternalDevices();
    }

    memset(KeyboardMap, 0xff, 16);

    r800SetFrequency(r800, CPU_Z80,  machine->cpu.freqZ80);
    r800SetFrequency(r800, CPU_R800, machine->cpu.freqR800);

    diskEnable(0, machine->fdc.count > 0);
    diskEnable(1, machine->fdc.count > 1);

    if (!success) {
        destroy();
    }

    return success;
}