From 137b5fc460a11633f53d2fa567db9527990e0e80 Mon Sep 17 00:00:00 2001 From: FIX94 Date: Sun, 17 Feb 2019 21:02:33 +0100 Subject: [PATCH] -added support for mappers 80, 82 and 207 -clearing prg ram on first creation so theres no random garbage in new saves --- README.md | 2 +- libretro/Makefile | 2 + main.c | 4 +- mapper/m80.c | 182 +++++++++++++++++++++++++++++++++++++++++++ mapper/m82.c | 194 ++++++++++++++++++++++++++++++++++++++++++++++ mapperList.c | 8 +- mapper_h/m80.h | 21 +++++ mapper_h/m82.h | 17 ++++ 8 files changed, 425 insertions(+), 5 deletions(-) create mode 100644 mapper/m80.c create mode 100644 mapper/m82.c create mode 100644 mapper_h/m80.h create mode 100644 mapper_h/m82.h diff --git a/README.md b/README.md index 1291c8e..fe4d9f8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ To start a file, simply drag and drop it into the fixNES Application or call it You can also load from a .zip file, the first found supported file from that .zip will be used. Supported .nes Mappers: -0,1,2,3,4,5,7,9,10,11,12,13,15,19,21,22,23,24,25,26,28,30,31,32,33,34,36,37,38,41,44,45,46,47,48,49,52,57,58,60,61,62,64,65,66,67,68,69,70,71,73,75,76,77,78,79,85,87,88,89,93,94,95,97,101,107,112,113,118,119,132,133,136,137,138,139,140,141,144,145,146,147,148,149,152,154,155,156,158,172,173,174,180,184,185,193,200,201,202,203,205,206,210,212,221,225,226,228,229,230,231,232,235,237,240 and 242. +0,1,2,3,4,5,7,9,10,11,12,13,15,19,21,22,23,24,25,26,28,30,31,32,33,34,36,37,38,41,44,45,46,47,48,49,52,57,58,60,61,62,64,65,66,67,68,69,70,71,73,75,76,77,78,79,80,82,85,87,88,89,93,94,95,97,101,107,112,113,118,119,132,133,136,137,138,139,140,141,144,145,146,147,148,149,152,154,155,156,158,172,173,174,180,184,185,193,200,201,202,203,205,206,207,210,212,221,225,226,228,229,230,231,232,235,237,240 and 242. Supported Audio Expansions (for both ROMs and NSF Files): VRC6, VRC7, FDS, MMC5, N163, Sunsoft 5B diff --git a/libretro/Makefile b/libretro/Makefile index 6a92aa8..dffb59a 100644 --- a/libretro/Makefile +++ b/libretro/Makefile @@ -367,6 +367,8 @@ OBJS += ../mapper/m34.o OBJS += ../mapper/m48.o OBJS += ../mapper/m65.o OBJS += ../mapper/m77.o +OBJS += ../mapper/m80.o +OBJS += ../mapper/m82.o OBJS += ../mapper/mmc1.o OBJS += ../mapper/mmc2_4.o OBJS += ../mapper/mmc3.o diff --git a/main.c b/main.c index b86f11b..e88b5ed 100644 --- a/main.c +++ b/main.c @@ -38,7 +38,7 @@ #define DEBUG_KEY 0 #define DEBUG_LOAD_INFO 1 -const char *VERSION_STRING = "fixNES Alpha v1.2.5"; +const char *VERSION_STRING = "fixNES Alpha v1.2.6"; static char window_title[256]; static char window_title_pause[256]; @@ -245,6 +245,8 @@ int main(int argc, char** argv) } } emuPrgRAM = malloc(emuPrgRAMsize); + //start out clear + memset(emuPrgRAM, 0, emuPrgRAMsize); uint8_t *prgROM = emuNesROM+16; if(m30_flashable) //initial prg fill memcpy(emuPrgRAM, prgROM, prgROMsize); diff --git a/mapper/m80.c b/mapper/m80.c new file mode 100644 index 0000000..56da710 --- /dev/null +++ b/mapper/m80.c @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2019 FIX94 + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ + +#include +#include +#include +#include +#include "../ppu.h" +#include "../mapper.h" +#include "../mem.h" +#include "../mapper_h/common.h" + +static struct { + bool usesPrgRAM; + bool prgRAMenabled; + uint8_t *prgRAM; +} m80; + +void m80init(uint8_t *prgROMin, uint32_t prgROMsizeIn, + uint8_t *prgRAMin, uint32_t prgRAMsizeIn, + uint8_t *chrROMin, uint32_t chrROMsizeIn) +{ + prg8init(prgROMin, prgROMsizeIn); + prg8setBank3(prgROMsizeIn - 0x2000); + if(prgRAMin && prgRAMsizeIn) + { + m80.prgRAM = prgRAMin; + m80.usesPrgRAM = true; + } + else + m80.usesPrgRAM = true; + m80.prgRAMenabled = false; + chr1init(chrROMin, chrROMsizeIn); + printf("Taito X1-005 inited\n"); +} + +static uint16_t m207nt0, m207nt1; +void m207init(uint8_t *prgROMin, uint32_t prgROMsizeIn, + uint8_t *prgRAMin, uint32_t prgRAMsizeIn, + uint8_t *chrROMin, uint32_t chrROMsizeIn) +{ + m80init(prgROMin,prgROMsizeIn,prgRAMin,prgRAMsizeIn,chrROMin,chrROMsizeIn); + //some extra regs + m207nt0 = 0, m207nt1 = 0; + ppuSetNameTblCustom(m207nt0,m207nt0,m207nt1,m207nt1); +} + +extern uint8_t memLastVal; +static uint8_t m80prgRAMget8(uint16_t addr) +{ + if(m80.usesPrgRAM && m80.prgRAMenabled) + return m80.prgRAM[addr&0x7F]; + return memLastVal; //aka open bus +} + +void m80initGet8(uint16_t addr) +{ + if(addr >= 0x7F00 && addr < 0x8000) + memInitMapperGetPointer(addr, m80prgRAMget8); + else + prg8initGet8(addr); +} + +static void m80setParams7EF0(uint16_t addr, uint8_t val) +{ + (void)addr; + chr1setBank0((val&0xFE)<<10); + chr1setBank1((val|0x01)<<10); +} + +static void m80setParams7EF1(uint16_t addr, uint8_t val) +{ + (void)addr; + chr1setBank2((val&0xFE)<<10); + chr1setBank3((val|0x01)<<10); +} + +static void m80setParams7EF2(uint16_t addr, uint8_t val) { (void)addr; chr1setBank4(val<<10); } +static void m80setParams7EF3(uint16_t addr, uint8_t val) { (void)addr; chr1setBank5(val<<10); } +static void m80setParams7EF4(uint16_t addr, uint8_t val) { (void)addr; chr1setBank6(val<<10); } +static void m80setParams7EF5(uint16_t addr, uint8_t val) { (void)addr; chr1setBank7(val<<10); } + +static void m80setParams7EF6(uint16_t addr, uint8_t val) +{ + (void)addr; + if(!ppu4Screen) + { + if(val&1) + { + //printf("Vertical mode\n"); + ppuSetNameTblVertical(); + } + else + { + //printf("Horizontal mode\n"); + ppuSetNameTblHorizontal(); + } + } +} + +static void m80setParams7EF8(uint16_t addr, uint8_t val) { (void)addr; m80.prgRAMenabled = (val == 0xA3); } + +static void m80setParams7EFA(uint16_t addr, uint8_t val) { (void)addr; prg8setBank0(val<<13); } +static void m80setParams7EFC(uint16_t addr, uint8_t val) { (void)addr; prg8setBank1(val<<13); } +static void m80setParams7EFE(uint16_t addr, uint8_t val) { (void)addr; prg8setBank2(val<<13); } + +static void m80prgRAMset8(uint16_t addr, uint8_t val) { if(m80.usesPrgRAM && m80.prgRAMenabled) m80.prgRAM[addr&0x7F] = val; } + +void m80initSet8(uint16_t addr) +{ + if(addr >= 0x7EF0 && addr < 0x7F00) + { + switch(addr&0xF) + { + case 0: + memInitMapperSetPointer(addr, m80setParams7EF0); + break; + case 1: + memInitMapperSetPointer(addr, m80setParams7EF1); + break; + case 2: + memInitMapperSetPointer(addr, m80setParams7EF2); + break; + case 3: + memInitMapperSetPointer(addr, m80setParams7EF3); + break; + case 4: + memInitMapperSetPointer(addr, m80setParams7EF4); + break; + case 5: + memInitMapperSetPointer(addr, m80setParams7EF5); + break; + case 6: case 7: + memInitMapperSetPointer(addr, m80setParams7EF6); + break; + case 8: case 9: + memInitMapperSetPointer(addr, m80setParams7EF8); + break; + case 0xA: case 0xB: + memInitMapperSetPointer(addr, m80setParams7EFA); + break; + case 0xC: case 0xD: + memInitMapperSetPointer(addr, m80setParams7EFC); + break; + case 0xE: case 0xF: + memInitMapperSetPointer(addr, m80setParams7EFE); + break; + } + } + else if(addr >= 0x7F00 && addr < 0x8000) + memInitMapperSetPointer(addr, m80prgRAMset8); +} + +static void m207setParams7EF0(uint16_t addr, uint8_t val) +{ + (void)addr; + m207nt0 = (val&0x80) ? 0x400 : 0; + ppuSetNameTblCustom(m207nt0,m207nt0,m207nt1,m207nt1); + m80setParams7EF0(addr, val&0x7F); +} + +static void m207setParams7EF1(uint16_t addr, uint8_t val) +{ + (void)addr; + m207nt1 = (val&0x80) ? 0x400 : 0; + ppuSetNameTblCustom(m207nt0,m207nt0,m207nt1,m207nt1); + m80setParams7EF1(addr, val&0x7F); +} + +void m207initSet8(uint16_t addr) +{ + if(addr == 0x7EF0) + memInitMapperSetPointer(addr, m207setParams7EF0); + else if(addr == 0x7EF1) + memInitMapperSetPointer(addr, m207setParams7EF1); + else if(addr != 0x7EF6 && addr != 0x7EF7) + m80initSet8(addr); +} diff --git a/mapper/m82.c b/mapper/m82.c new file mode 100644 index 0000000..8a9bd1b --- /dev/null +++ b/mapper/m82.c @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2019 FIX94 + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ + +#include +#include +#include +#include +#include "../ppu.h" +#include "../mapper.h" +#include "../mem.h" +#include "../mapper_h/common.h" + +static struct { + bool usesPrgRAM; + bool prgRAMenabled[3]; + uint8_t *prgRAM; + uint32_t CHRBank[8]; + uint8_t chr_bank_flip; +} m82; + +static void m82SetChrROMBanks() +{ + chr1setBank0(m82.CHRBank[0^m82.chr_bank_flip]); chr1setBank1(m82.CHRBank[1^m82.chr_bank_flip]); + chr1setBank2(m82.CHRBank[2^m82.chr_bank_flip]); chr1setBank3(m82.CHRBank[3^m82.chr_bank_flip]); + chr1setBank4(m82.CHRBank[4^m82.chr_bank_flip]); chr1setBank5(m82.CHRBank[5^m82.chr_bank_flip]); + chr1setBank6(m82.CHRBank[6^m82.chr_bank_flip]); chr1setBank7(m82.CHRBank[7^m82.chr_bank_flip]); +} + +void m82init(uint8_t *prgROMin, uint32_t prgROMsizeIn, + uint8_t *prgRAMin, uint32_t prgRAMsizeIn, + uint8_t *chrROMin, uint32_t chrROMsizeIn) +{ + prg8init(prgROMin, prgROMsizeIn); + prg8setBank3(prgROMsizeIn - 0x2000); + if(prgRAMin && prgRAMsizeIn) + { + m82.prgRAM = prgRAMin; + m82.usesPrgRAM = true; + } + else + m82.usesPrgRAM = false; + m82.prgRAMenabled[0] = false; + m82.prgRAMenabled[1] = false; + m82.prgRAMenabled[2] = false; + chr1init(chrROMin, chrROMsizeIn); + m82.chr_bank_flip = 0; + memset(m82.CHRBank,0,8*sizeof(uint32_t)); + m82SetChrROMBanks(); + printf("Taito X1-017 inited\n"); +} + +extern uint8_t memLastVal; +static uint8_t m82prgRAMBank0Get8(uint16_t addr) +{ + if(m82.usesPrgRAM && m82.prgRAMenabled[0]) + return m82.prgRAM[addr&0x1FFF]; + return memLastVal; //aka open bus +} +static uint8_t m82prgRAMBank1Get8(uint16_t addr) +{ + if(m82.usesPrgRAM && m82.prgRAMenabled[1]) + return m82.prgRAM[addr&0x1FFF]; + return memLastVal; //aka open bus +} +static uint8_t m82prgRAMBank2Get8(uint16_t addr) +{ + if(m82.usesPrgRAM && m82.prgRAMenabled[2]) + return m82.prgRAM[addr&0x1FFF]; + return memLastVal; //aka open bus +} + +void m82initGet8(uint16_t addr) +{ + if(addr >= 0x6000 && addr < 0x6800) + memInitMapperGetPointer(addr, m82prgRAMBank0Get8); + else if(addr >= 0x6800 && addr < 0x7000) + memInitMapperGetPointer(addr, m82prgRAMBank1Get8); + else if(addr >= 0x7000 && addr < 0x7400) + memInitMapperGetPointer(addr, m82prgRAMBank2Get8); + else + prg8initGet8(addr); +} + +static void m82setParams7EF0(uint16_t addr, uint8_t val) +{ + (void)addr; + m82.CHRBank[0] = ((val&0xFE)<<10); + m82.CHRBank[1] = ((val|0x01)<<10); + m82SetChrROMBanks(); +} + +static void m82setParams7EF1(uint16_t addr, uint8_t val) +{ + (void)addr; + m82.CHRBank[2] = ((val&0xFE)<<10); + m82.CHRBank[3] = ((val|0x01)<<10); + m82SetChrROMBanks(); +} + +static void m82setParams7EF2(uint16_t addr, uint8_t val) { (void)addr; m82.CHRBank[4] = (val<<10); m82SetChrROMBanks(); } +static void m82setParams7EF3(uint16_t addr, uint8_t val) { (void)addr; m82.CHRBank[5] = (val<<10); m82SetChrROMBanks(); } +static void m82setParams7EF4(uint16_t addr, uint8_t val) { (void)addr; m82.CHRBank[6] = (val<<10); m82SetChrROMBanks(); } +static void m82setParams7EF5(uint16_t addr, uint8_t val) { (void)addr; m82.CHRBank[7] = (val<<10); m82SetChrROMBanks(); } + +static void m82setParams7EF6(uint16_t addr, uint8_t val) +{ + (void)addr; + if(!ppu4Screen) + { + if(val&1) + { + //printf("Vertical mode\n"); + ppuSetNameTblVertical(); + } + else + { + //printf("Horizontal mode\n"); + ppuSetNameTblHorizontal(); + } + } + m82.chr_bank_flip = (val&2) ? 4 : 0; + m82SetChrROMBanks(); +} + +static void m82setParams7EF7(uint16_t addr, uint8_t val) { (void)addr; m82.prgRAMenabled[0] = (val == 0xCA); } +static void m82setParams7EF8(uint16_t addr, uint8_t val) { (void)addr; m82.prgRAMenabled[1] = (val == 0x69); } +static void m82setParams7EF9(uint16_t addr, uint8_t val) { (void)addr; m82.prgRAMenabled[2] = (val == 0x84); } + +static void m82setParams7EFA(uint16_t addr, uint8_t val) { (void)addr; prg8setBank0((val&0xFC)<<11); } +static void m82setParams7EFB(uint16_t addr, uint8_t val) { (void)addr; prg8setBank1((val&0xFC)<<11); } +static void m82setParams7EFC(uint16_t addr, uint8_t val) { (void)addr; prg8setBank2((val&0xFC)<<11); } + +static void m82prgRAMBank0Set8(uint16_t addr, uint8_t val) { if(m82.usesPrgRAM && m82.prgRAMenabled[0]) m82.prgRAM[addr&0x1FFF] = val; } +static void m82prgRAMBank1Set8(uint16_t addr, uint8_t val) { if(m82.usesPrgRAM && m82.prgRAMenabled[1]) m82.prgRAM[addr&0x1FFF] = val; } +static void m82prgRAMBank2Set8(uint16_t addr, uint8_t val) { if(m82.usesPrgRAM && m82.prgRAMenabled[2]) m82.prgRAM[addr&0x1FFF] = val; } + +void m82initSet8(uint16_t addr) +{ + if(addr >= 0x7EF0 && addr <= 0x7EFC) + { + switch(addr&0xF) + { + case 0: + memInitMapperSetPointer(addr, m82setParams7EF0); + break; + case 1: + memInitMapperSetPointer(addr, m82setParams7EF1); + break; + case 2: + memInitMapperSetPointer(addr, m82setParams7EF2); + break; + case 3: + memInitMapperSetPointer(addr, m82setParams7EF3); + break; + case 4: + memInitMapperSetPointer(addr, m82setParams7EF4); + break; + case 5: + memInitMapperSetPointer(addr, m82setParams7EF5); + break; + case 6: + memInitMapperSetPointer(addr, m82setParams7EF6); + break; + case 7: + memInitMapperSetPointer(addr, m82setParams7EF7); + break; + case 8: + memInitMapperSetPointer(addr, m82setParams7EF8); + break; + case 9: + memInitMapperSetPointer(addr, m82setParams7EF9); + break; + case 0xA: + memInitMapperSetPointer(addr, m82setParams7EFA); + break; + case 0xB: + memInitMapperSetPointer(addr, m82setParams7EFB); + break; + case 0xC: + memInitMapperSetPointer(addr, m82setParams7EFC); + break; + } + } + else if(addr >= 0x6000 && addr < 0x6800) + memInitMapperSetPointer(addr, m82prgRAMBank0Set8); + else if(addr >= 0x6800 && addr < 0x7000) + memInitMapperSetPointer(addr, m82prgRAMBank1Set8); + else if(addr >= 0x7000 && addr < 0x7400) + memInitMapperSetPointer(addr, m82prgRAMBank2Set8); +} diff --git a/mapperList.c b/mapperList.c index cc0de35..6985eea 100644 --- a/mapperList.c +++ b/mapperList.c @@ -24,6 +24,8 @@ #include "mapper_h/m48.h" #include "mapper_h/m65.h" #include "mapper_h/m77.h" +#include "mapper_h/m80.h" +#include "mapper_h/m82.h" #include "mapper_h/m137.h" #include "mapper_h/m156.h" #include "mapper_h/m193.h" @@ -131,9 +133,9 @@ mapperList_t mapperList[256] = { { m77init, prg32initGet8, m77initSet8, m77initPPUGet8, m77initPPUSet8, NULL, NULL }, { p16c8init, prg16initGet8, m78_initSet8, chr8initPPUGet8, chr8initPPUSet8, NULL, NULL }, { p32c8init, prg32initGet8, m79_initSet8, chr8initPPUGet8, chr8initPPUSet8, NULL, NULL }, + { m80init, m80initGet8, m80initSet8, chr1initPPUGet8, chr1initPPUSet8, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, - { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, + { m82init, m82initGet8, m82initSet8, chr1initPPUGet8, chr1initPPUSet8, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, { vrc7init, vrc7initGet8, vrc7initSet8, chr1initPPUGet8, chr1initPPUSet8, vrc_irq_cycle, NULL }, @@ -258,7 +260,7 @@ mapperList_t mapperList[256] = { { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, { m205_init, mmc3NoRAMInitGet8, m205_initSet8, mmc3initPPUGet8, mmc3initPPUSet8, NULL, m205_reset }, { m206init, prg8initGet8, m206initSet8, m206initPPUGet8, m206initPPUSet8, NULL, NULL }, - { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, + { m207init, m80initGet8, m207initSet8, chr1initPPUGet8, chr1initPPUSet8, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL, NULL, NULL }, { namco_init, namco_initGet8, namco_initSet8, namco_initPPUGet8, namco_initPPUSet8, namco_cycle, NULL }, diff --git a/mapper_h/m80.h b/mapper_h/m80.h new file mode 100644 index 0000000..a0899ce --- /dev/null +++ b/mapper_h/m80.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2019 FIX94 + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ + +#ifndef m80_h_ +#define m80_h_ + +void m80init(uint8_t *prgROM, uint32_t prgROMsize, + uint8_t *prgRAM, uint32_t prgRAMsize, + uint8_t *chrROM, uint32_t chrROMsize); +void m207init(uint8_t *prgROM, uint32_t prgROMsize, + uint8_t *prgRAM, uint32_t prgRAMsize, + uint8_t *chrROM, uint32_t chrROMsize); +void m80initGet8(uint16_t addr); +void m80initSet8(uint16_t addr); +void m207initSet8(uint16_t addr); + +#endif diff --git a/mapper_h/m82.h b/mapper_h/m82.h new file mode 100644 index 0000000..da2ff20 --- /dev/null +++ b/mapper_h/m82.h @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2019 FIX94 + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ + +#ifndef m82_h_ +#define m82_h_ + +void m82init(uint8_t *prgROM, uint32_t prgROMsize, + uint8_t *prgRAM, uint32_t prgRAMsize, + uint8_t *chrROM, uint32_t chrROMsize); +void m82initGet8(uint16_t addr); +void m82initSet8(uint16_t addr); + +#endif