Skip to content

Commit

Permalink
-do frame skipping if running out of audio buffers
Browse files Browse the repository at this point in the history
-added mappers 94,97 and 180
  • Loading branch information
FIX94 committed Mar 9, 2017
1 parent d55ed06 commit 111f837
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This is yet another NES Emulator which was written so I can learn about the NES,
If you want to check it out for some reason I do include a windows binary in the "Releases" tab, if you want to compile it go check out the "build" files.
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,7,9,10,11,13,15,21,22,23,24,25,26,33,34,36,37,38,44,45,46,47,48,52,66,70,71,78,79,87,99,101,113,133,140,144,145,146,147,148,149,152,185,240 and 242.
Supported Mappers: 0,1,2,3,4,7,9,10,11,13,15,21,22,23,24,25,26,33,34,36,37,38,44,45,46,47,48,52,66,70,71,78,79,87,94,97,99,101,113,133,140,144,145,146,147,148,149,152,180,185,240 and 242.
To start a game, simply drag and drop its .nes file into it or call it via command line with the .nes file as argument.
If you are starting a PAL NES title then make sure it has (E) in the name to be started in PAL mode.
You can also play FDS titles if you have the FDS BIOS named disksys.rom in the same folder as your .fds files.
Expand Down
16 changes: 13 additions & 3 deletions apu.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void apuClockTimers()
static float lastHPOut = 0, lastLPOut = 0;
static uint8_t lastP1Out = 0, lastP2Out = 0, lastTriOut = 0, lastNoiseOut = 0;

extern bool emuSkipVsync;
extern bool emuSkipVsync, emuSkipFrame;

int apuCycle()
{
Expand All @@ -321,13 +321,23 @@ int apuCycle()
int updateRes = audioUpdate();
if(updateRes == 0)
{
emuSkipFrame = false;
emuSkipVsync = false;
return 0;
}
if(updateRes > 4)
if(updateRes > 6)
{
emuSkipVsync = true;
emuSkipFrame = true;
}
else
emuSkipVsync = false;
{
emuSkipFrame = false;
if(updateRes > 2)
emuSkipVsync = true;
else
emuSkipVsync = false;
}
curBufPos = 0;
}
uint8_t p1Out = lastP1Out, p2Out = lastP2Out,
Expand Down
2 changes: 1 addition & 1 deletion apu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef _apu_h_
#define _apu_h_

#define NUM_BUFFERS 8
#define NUM_BUFFERS 10

void apuInitBufs();
void apuDeinitBufs();
Expand Down
8 changes: 7 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define DEBUG_KEY 0
#define DEBUG_LOAD_INFO 1

static const char *VERSION_STRING = "fixNES Alpha v0.6.2";
static const char *VERSION_STRING = "fixNES Alpha v0.6.3";

static void nesEmuDisplayFrame(void);
static void nesEmuMainLoop(void);
Expand Down Expand Up @@ -381,6 +381,7 @@ static void nesEmuDeinit(void)

//used externally
bool emuSkipVsync = false;
bool emuSkipFrame = false;

//static int mCycles = 0;
static bool emuApuDoCycle = false;
Expand Down Expand Up @@ -789,6 +790,11 @@ static void nesEmuDisplayFrame()
{
if(emuRenderFrame)
{
if(emuSkipFrame)
{
emuRenderFrame = false;
return;
}
if(textureImage != NULL)
glTexImage2D(GL_TEXTURE_2D, 0, 4, VISIBLE_DOTS, VISIBLE_LINES, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, textureImage);
emuRenderFrame = false;
Expand Down
91 changes: 75 additions & 16 deletions mapper/p16c8.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static uint8_t *p16c8_prgROM;
static uint8_t *p16c8_chrROM;
static uint32_t p16c8_prgROMsize;
static uint32_t p16c8_chrROMsize;
static uint32_t p16c8_firstPRGBank;
static uint32_t p16c8_curPRGBank;
static uint32_t p16c8_curCHRBank;
static uint32_t p16c8_lastPRGBank;
Expand All @@ -28,7 +29,8 @@ void p16c8init(uint8_t *prgROMin, uint32_t prgROMsizeIn,
p16c8_prgROMsize = prgROMsizeIn;
(void)prgRAMin;
(void)prgRAMsizeIn;
p16c8_curPRGBank = 0;
p16c8_firstPRGBank = 0;
p16c8_curPRGBank = p16c8_firstPRGBank;
p16c8_lastPRGBank = prgROMsizeIn - 0x4000;
if(chrROMsizeIn > 0)
{
Expand All @@ -54,12 +56,30 @@ uint8_t p16c8get8(uint16_t addr)
return p16c8_prgROM[((p16c8_lastPRGBank&~0x3FFF)+(addr&0x3FFF))&(p16c8_prgROMsize-1)];
}

uint8_t m97_get8(uint16_t addr)
{
if(addr < 0x8000)
return 0;
if(addr < 0xC000)
return p16c8_prgROM[((p16c8_lastPRGBank&~0x3FFF)+(addr&0x3FFF))&(p16c8_prgROMsize-1)];
return p16c8_prgROM[((p16c8_curPRGBank&~0x3FFF)+(addr&0x3FFF))&(p16c8_prgROMsize-1)];
}

uint8_t m180_get8(uint16_t addr)
{
if(addr < 0x8000)
return 0;
if(addr < 0xC000)
return p16c8_prgROM[((p16c8_firstPRGBank&~0x3FFF)+(addr&0x3FFF))&(p16c8_prgROMsize-1)];
return p16c8_prgROM[((p16c8_curPRGBank&~0x3FFF)+(addr&0x3FFF))&(p16c8_prgROMsize-1)];
}

void m2_set8(uint16_t addr, uint8_t val)
{
//printf("p16c8set8 %04x %02x\n", addr, val);
if(addr < 0x8000)
return;
p16c8_curPRGBank = ((val & 15)<<14)&(p16c8_prgROMsize-1);
p16c8_curPRGBank = ((val & 0xF)<<14)&(p16c8_prgROMsize-1);
}

void m70_set8(uint16_t addr, uint8_t val)
Expand All @@ -76,20 +96,7 @@ void m71_set8(uint16_t addr, uint8_t val)
//printf("p16c8set8 %04x %02x\n", addr, val);
if(addr < 0xC000)
return;
p16c8_curPRGBank = ((val & 15)<<14)&(p16c8_prgROMsize-1);
}

void m152_set8(uint16_t addr, uint8_t val)
{
//printf("p16c8set8 %04x %02x\n", addr, val);
if(addr < 0x8000)
return;
p16c8_curPRGBank = (((val >> 4)&7)<<14)&(p16c8_prgROMsize-1);
p16c8_curCHRBank = ((val & 0xF)<<13)&(p16c8_chrROMsize-1);
if((val&0x80) == 0)
ppuSetNameTblSingleLower();
else
ppuSetNameTblSingleUpper();
p16c8_curPRGBank = ((val & 0xF)<<14)&(p16c8_prgROMsize-1);
}

void m78a_set8(uint16_t addr, uint8_t val)
Expand Down Expand Up @@ -118,6 +125,58 @@ void m78b_set8(uint16_t addr, uint8_t val)
ppuSetNameTblSingleUpper();
}

void m94_set8(uint16_t addr, uint8_t val)
{
//printf("p16c8set8 %04x %02x\n", addr, val);
if(addr < 0x8000)
return;
p16c8_curPRGBank = (((val>>2) & 0xF)<<14)&(p16c8_prgROMsize-1);
}

void m97_set8(uint16_t addr, uint8_t val)
{
//printf("p16c8set8 %04x %02x\n", addr, val);
if(addr < 0x8000)
return;
p16c8_curPRGBank = ((val & 0xF)<<14)&(p16c8_prgROMsize-1);
switch(val>>6)
{
case 0:
ppuSetNameTblSingleLower();
break;
case 1:
ppuSetNameTblHorizontal();
break;
case 2:
ppuSetNameTblVertical();
break;
default: //case 3
ppuSetNameTblSingleUpper();
break;
}
}

void m152_set8(uint16_t addr, uint8_t val)
{
//printf("p16c8set8 %04x %02x\n", addr, val);
if(addr < 0x8000)
return;
p16c8_curPRGBank = (((val >> 4)&7)<<14)&(p16c8_prgROMsize-1);
p16c8_curCHRBank = ((val & 0xF)<<13)&(p16c8_chrROMsize-1);
if((val&0x80) == 0)
ppuSetNameTblSingleLower();
else
ppuSetNameTblSingleUpper();
}

void m180_set8(uint16_t addr, uint8_t val)
{
//printf("p16c8set8 %04x %02x\n", addr, val);
if(addr < 0x8000)
return;
p16c8_curPRGBank = ((val & 0xF)<<14)&(p16c8_prgROMsize-1);
}

uint8_t p16c8chrGet8(uint16_t addr)
{
if(p16c8_chrROM == p16c8_chrRAM) //Writable
Expand Down
6 changes: 3 additions & 3 deletions mapperList.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ mapperList_t mapperList[256] = {
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ p16c8init, p16c8get8, m94_set8, p16c8chrGet8, p16c8chrSet8, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ p16c8init, m97_get8, m97_set8, p16c8chrGet8, p16c8chrSet8, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ p8c8init, p8c8get8, m99_set8, p8c8chrGet8, p8c8chrSet8, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
Expand Down Expand Up @@ -207,7 +207,7 @@ mapperList_t mapperList[256] = {
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ p16c8init, m180_get8, m180_set8, p16c8chrGet8, p16c8chrSet8, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL },
Expand Down
5 changes: 5 additions & 0 deletions mapper_h/p16c8.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ void p16c8init(uint8_t *prgROM, uint32_t prgROMsize,
uint8_t *prgRAM, uint32_t prgRAMsize,
uint8_t *chrROM, uint32_t chrROMsize);
uint8_t p16c8get8(uint16_t addr);
uint8_t m97_get8(uint16_t addr);
uint8_t m180_get8(uint16_t addr);
void m2_set8(uint16_t addr, uint8_t val);
void m70_set8(uint16_t addr, uint8_t val);
void m71_set8(uint16_t addr, uint8_t val);
void m78a_set8(uint16_t addr, uint8_t val);
void m78b_set8(uint16_t addr, uint8_t val);
void m94_set8(uint16_t addr, uint8_t val);
void m97_set8(uint16_t addr, uint8_t val);
void m152_set8(uint16_t addr, uint8_t val);
void m180_set8(uint16_t addr, uint8_t val);
uint8_t p16c8chrGet8(uint16_t addr);
void p16c8chrSet8(uint16_t addr, uint8_t val);

Expand Down

0 comments on commit 111f837

Please sign in to comment.