Skip to content

Commit

Permalink
-added support for mappers 32, 49, 60, 65, 73 and 156
Browse files Browse the repository at this point in the history
-added soft reset keyboard command ctrl+r
  • Loading branch information
FIX94 committed Dec 9, 2017
1 parent fa8646d commit 93df290
Show file tree
Hide file tree
Showing 19 changed files with 971 additions and 16 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If you want to check it out for some reason I do include a windows binary in the
You will need freeglut as well as openal-soft to compile the project, it should run on most systems since it is fairly generic C code.
NTSC and PAL .nes ROMs are supported right now, it also creates .sav files if the chosen game supports saving.
Supported Mappers:
0,1,2,3,4,5,7,9,10,11,12,13,15,19,21,22,23,24,25,26,33,34,36,37,38,41,44,45,46,47,48,52,57,58,61,62,66,67,68,69,70,71,75,76,78,79,85,87,88,89,93,94,95,97,99,101,112,113,118,119,133,140,144,145,146,147,148,149,152,154,174,180,184,185,200,201,202,203,205,206,210,212,225,226,228,232,232,240 and 242.
0,1,2,3,4,5,7,9,10,11,12,13,15,19,21,22,23,24,25,26,32,33,34,36,37,38,41,44,45,46,47,48,49,52,57,58,60,61,62,65,66,67,68,69,70,71,73,75,76,78,79,85,87,88,89,93,94,95,97,99,101,112,113,118,119,133,140,144,145,146,147,148,149,152,154,155,156,174,180,184,185,200,201,202,203,205,206,210,212,225,226,228,232,232,240 and 242.
Supported Audio Expansions:
VRC6, VRC7, FDS, MMC5, N163, Sunsoft 5B
Normal .nes files are supported, if you are starting a PAL NES title then make sure it has (E),(Europe),(Australia),(France),(Germany),(Italy),(Spain) or (Sweden) in the filename to be started in PAL mode.
Expand All @@ -21,6 +21,7 @@ S is select
Arrow Keys is DPad
Keys 1-9 integer-scale the window to number
P is Pause
Ctrl+R is Soft Reset
B is Disk Switching (for FDS)
O is Enable/Disable vertical Overscan
If you really want controller support and you are on windows, go grab joy2key, it works just fine with fixNES (and fixGB).
Expand Down
6 changes: 6 additions & 0 deletions cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ static bool cpuHandleIrqUpdates()
//handle incoming IRQs
if(reset)
{
apuSet8(0x15, 0);
cpu_action_arr = cpu_reset_arr;
cpu_arr_pos = 0;
cpu_action_func = cpuNoAction;
Expand Down Expand Up @@ -1502,3 +1503,8 @@ void cpuInitNSF(uint16_t addr, uint8_t newA, uint8_t newX)
nsf_endPlayback = false;
//printf("Init at %04x\n", addr);
}

void cpuSoftReset()
{
reset = true;
}
1 change: 1 addition & 0 deletions cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void cpuSetupActionArr();
void cpuInitNSF(uint16_t addr, uint8_t newA, uint8_t newX);
void cpuStartPlayNSF();
void cpuEndPlayNSF();
void cpuSoftReset();
bool cpuCycle();
void cpuIncWaitCycles(uint32_t inc);
uint16_t cpuGetPc();
Expand Down
22 changes: 21 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define DEBUG_KEY 0
#define DEBUG_LOAD_INFO 1

static const char *VERSION_STRING = "fixNES Alpha v1.0.3";
static const char *VERSION_STRING = "fixNES Alpha v1.0.4";
static char window_title[256];
static char window_title_pause[256];

Expand Down Expand Up @@ -82,6 +82,7 @@ static bool inPause = false;
static bool inOverscanToggle = false;
static bool inResize = false;
static bool inDiskSwitch = false;
static bool inReset = false;

#if WINDOWS_BUILD
#include <windows.h>
Expand Down Expand Up @@ -118,6 +119,8 @@ static uint16_t cpuCycleTimer;
extern uint8_t inValReads[8];
//from mapper.c
extern bool mapperUse78A;
//from m32.c
extern bool m32_singlescreen;

int main(int argc, char** argv)
{
Expand Down Expand Up @@ -184,6 +187,13 @@ int main(int argc, char** argv)
printf("Used Mapper: %i\n", mapper);
printf("PRG: 0x%x bytes PRG RAM: 0x%x bytes CHR: 0x%x bytes\n", prgROMsize, emuPrgRAMsize, chrROMsize);
#endif
if(mapper == 32)
{
if(strstr(emuFileName,"Major League") != NULL)
m32_singlescreen = true;
else
m32_singlescreen = false;
}
if(mapper == 78)
{
if(strstr(emuFileName,"Holy Diver") != NULL)
Expand Down Expand Up @@ -902,6 +912,13 @@ static void nesEmuHandleKeyDown(unsigned char key, int x, int y)
doOverscan ^= true;
}
break;
case '\x12': //ctrl-R
if(!inReset)
{
inReset = true;
if(!nesEmuNSFPlayback)
cpuSoftReset();
}
default:
break;
}
Expand Down Expand Up @@ -971,6 +988,9 @@ static void nesEmuHandleKeyUp(unsigned char key, int x, int y)
case 'O':
inOverscanToggle = false;
break;
case '\x12': //ctrl-R
inReset = false;
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "mapperList.h"
#include "mapper_h/nsf.h"
#include "mapper_h/fds.h"
#include "mapper_h/m32.h"
#include "mapper_h/p16c8.h"
#include "ppu.h"

Expand Down
167 changes: 167 additions & 0 deletions mapper/m156.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Copyright (C) 2017 FIX94
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

#include <stdio.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include "../ppu.h"
#include "../mapper.h"

static uint8_t *m156_prgROM;
static uint8_t *m156_prgRAM;
static uint8_t *m156_chrROM;
static uint32_t m156_prgROMsize;
static uint32_t m156_prgRAMsize;
static uint32_t m156_chrROMsize;
static uint32_t m156_prgROMand;
static uint32_t m156_prgRAMand;
static uint32_t m156_chrROMand;
static uint32_t m156_curPRGBank;
static uint32_t m156_lastPRGBank;
static uint32_t m156_CHRBank[8];

void m156init(uint8_t *prgROMin, uint32_t prgROMsizeIn,
uint8_t *prgRAMin, uint32_t prgRAMsizeIn,
uint8_t *chrROMin, uint32_t chrROMsizeIn)
{
m156_prgROM = prgROMin;
m156_prgROMsize = prgROMsizeIn;
m156_prgROMand = mapperGetAndValue(prgROMsizeIn);
m156_prgRAM = prgRAMin;
m156_prgRAMsize = prgRAMsizeIn;
m156_prgRAMand = mapperGetAndValue(prgRAMsizeIn);
m156_curPRGBank = 0;
m156_lastPRGBank = (prgROMsizeIn - 0x4000);
if(chrROMsizeIn > 0)
{
m156_chrROM = chrROMin;
m156_chrROMsize = chrROMsizeIn;
m156_chrROMand = mapperGetAndValue(chrROMsizeIn);
}
else
printf("m156???\n");
memset(m156_CHRBank,0,8*sizeof(uint32_t));
ppuSetNameTblSingleLower(); //seems to be default state?
printf("Mapper 156 inited\n");
}

uint8_t m156get8(uint16_t addr, uint8_t val)
{
if(addr >= 0x6000 && addr < 0x8000)
return m156_prgRAM[addr&0x1FFF];
else if(addr >= 0x8000)
{
if(addr < 0xC000)
return m156_prgROM[((m156_curPRGBank<<14)+(addr&0x3FFF))&m156_prgROMand];
return m156_prgROM[(m156_lastPRGBank+(addr&0x3FFF))&m156_prgROMand];
}
return val;
}

void m156set8(uint16_t addr, uint8_t val)
{
if(addr >= 0x6000 && addr < 0x8000)
{
//printf("m156set8 %04x %02x\n", addr, val);
m156_prgRAM[addr&0x1FFF] = val;
}
else if(addr >= 0xC000 && addr < 0xC020)
{
switch(addr&0x1F)
{
case 0x0:
m156_CHRBank[0] = (m156_CHRBank[0]&0xFF00)|val;
break;
case 0x1:
m156_CHRBank[1] = (m156_CHRBank[1]&0xFF00)|val;
break;
case 0x2:
m156_CHRBank[2] = (m156_CHRBank[2]&0xFF00)|val;
break;
case 0x3:
m156_CHRBank[3] = (m156_CHRBank[3]&0xFF00)|val;
break;
case 0x4:
m156_CHRBank[0] = (m156_CHRBank[0]&0xFF)|(val<<8);
break;
case 0x5:
m156_CHRBank[1] = (m156_CHRBank[1]&0xFF)|(val<<8);
break;
case 0x6:
m156_CHRBank[2] = (m156_CHRBank[2]&0xFF)|(val<<8);
break;
case 0x7:
m156_CHRBank[3] = (m156_CHRBank[3]&0xFF)|(val<<8);
break;
case 0x8:
m156_CHRBank[4] = (m156_CHRBank[4]&0xFF00)|val;
break;
case 0x9:
m156_CHRBank[5] = (m156_CHRBank[5]&0xFF00)|val;
break;
case 0xA:
m156_CHRBank[6] = (m156_CHRBank[6]&0xFF00)|val;
break;
case 0xB:
m156_CHRBank[7] = (m156_CHRBank[7]&0xFF00)|val;
break;
case 0xC:
m156_CHRBank[4] = (m156_CHRBank[4]&0xFF)|(val<<8);
break;
case 0xD:
m156_CHRBank[5] = (m156_CHRBank[5]&0xFF)|(val<<8);
break;
case 0xE:
m156_CHRBank[6] = (m156_CHRBank[6]&0xFF)|(val<<8);
break;
case 0xF:
m156_CHRBank[7] = (m156_CHRBank[7]&0xFF)|(val<<8);
break;
case 0x10:
m156_curPRGBank = val;
break;
case 0x14:
if(val&1)
ppuSetNameTblHorizontal();
else
ppuSetNameTblVertical();
break;
default:
break;
}
}
}

uint8_t m156chrGet8(uint16_t addr)
{
//printf("%04x\n",addr);
addr &= 0x1FFF;
if(addr < 0x400)
return m156_chrROM[((m156_CHRBank[0]<<10)+(addr&0x3FF))&m156_chrROMand];
else if(addr < 0x800)
return m156_chrROM[((m156_CHRBank[1]<<10)+(addr&0x3FF))&m156_chrROMand];
else if(addr < 0xC00)
return m156_chrROM[((m156_CHRBank[2]<<10)+(addr&0x3FF))&m156_chrROMand];
else if(addr < 0x1000)
return m156_chrROM[((m156_CHRBank[3]<<10)+(addr&0x3FF))&m156_chrROMand];
else if(addr < 0x1400)
return m156_chrROM[((m156_CHRBank[4]<<10)+(addr&0x3FF))&m156_chrROMand];
else if(addr < 0x1800)
return m156_chrROM[((m156_CHRBank[5]<<10)+(addr&0x3FF))&m156_chrROMand];
else if(addr < 0x1C00)
return m156_chrROM[((m156_CHRBank[6]<<10)+(addr&0x3FF))&m156_chrROMand];
return m156_chrROM[((m156_CHRBank[7]<<10)+(addr&0x3FF))&m156_chrROMand];
}

void m156chrSet8(uint16_t addr, uint8_t val)
{
//printf("m156chrSet8 %04x %02x\n", addr, val);
(void)addr;
(void)val;
}

Loading

0 comments on commit 93df290

Please sign in to comment.