Reset status when loading.
This commit is contained in:
parent
137bc208de
commit
12a6aa9552
|
@ -5,7 +5,7 @@ flags = ['-O3', '-march=native', '-std=c++11']
|
|||
env = Environment(ENV = { 'TERM' : environ['TERM'] },
|
||||
CXX = 'clang++',
|
||||
CPPPATH = 'src',
|
||||
CPPFLAGS = ['-Wno-unused-value', '-Wno-constant-conversion'],
|
||||
CPPFLAGS = ['-Wno-unused-value'],
|
||||
CXXFLAGS = flags,
|
||||
LINKFLAGS = flags,
|
||||
LIBS = ['SDL2', 'SDL2_image', 'SDL2_ttf'])
|
||||
|
|
|
@ -20,11 +20,17 @@ void init()
|
|||
apu.dmc_reader(CPU::dmc_read);
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
apu.reset();
|
||||
buf.clear();
|
||||
}
|
||||
|
||||
template <bool write> u8 access(int elapsed, u16 addr, u8 v)
|
||||
{
|
||||
if (write)
|
||||
apu.write_register(elapsed, addr, v);
|
||||
else if (addr == 0x4015)
|
||||
else if (addr == apu.status_addr)
|
||||
v = apu.read_status(elapsed);
|
||||
|
||||
return v;
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace APU {
|
|||
|
||||
template <bool write> u8 access(int elapsed, u16 addr, u8 v = 0);
|
||||
void run_frame(int elapsed);
|
||||
void reset();
|
||||
void init();
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <cstdio>
|
||||
#include "apu.hpp"
|
||||
#include "cpu.hpp"
|
||||
#include "mappers/mapper0.hpp"
|
||||
#include "mappers/mapper1.hpp"
|
||||
|
@ -45,6 +46,7 @@ void load(const char* fileName)
|
|||
fclose(f);
|
||||
|
||||
int mapperNum = (rom[7] & 0xF0) | (rom[6] >> 4);
|
||||
if (loaded()) delete mapper;
|
||||
switch (mapperNum)
|
||||
{
|
||||
case 0: mapper = new Mapper0(rom); break;
|
||||
|
@ -53,6 +55,7 @@ void load(const char* fileName)
|
|||
}
|
||||
|
||||
CPU::power();
|
||||
APU::reset();
|
||||
}
|
||||
|
||||
bool loaded()
|
||||
|
|
|
@ -170,7 +170,7 @@ void new_frame(u32* pixels)
|
|||
SDL_UpdateTexture(gameTexture, NULL, pixels, width * sizeof(u32));
|
||||
}
|
||||
|
||||
void new_samples(const blip_sample_t* samples, long count)
|
||||
void new_samples(const blip_sample_t* samples, size_t count)
|
||||
{
|
||||
soundQueue->write(samples, count);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ void render_texture(SDL_Texture* texture, int x, int y);
|
|||
|
||||
u8 get_joypad_state(int n);
|
||||
void new_frame(u32* pixels);
|
||||
void new_samples(const blip_sample_t* samples, long count);
|
||||
void new_samples(const blip_sample_t* samples, size_t count);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "mapper.hpp"
|
||||
|
||||
|
||||
Mapper::Mapper(u8* rom)
|
||||
Mapper::Mapper(u8* rom) : rom(rom)
|
||||
{
|
||||
// Read infos from header:
|
||||
prgSize = rom[4] * 0x4000;
|
||||
|
@ -19,11 +19,20 @@ Mapper::Mapper(u8* rom)
|
|||
// CHR RAM:
|
||||
else
|
||||
{
|
||||
chrRam = true;
|
||||
chrSize = 0x2000;
|
||||
this->chr = new u8[chrSize];
|
||||
}
|
||||
}
|
||||
|
||||
Mapper::~Mapper()
|
||||
{
|
||||
delete rom;
|
||||
delete prgRam;
|
||||
if (chrRam)
|
||||
delete chr;
|
||||
}
|
||||
|
||||
/* Access to memory */
|
||||
u8 Mapper::read(u16 addr)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
class Mapper
|
||||
{
|
||||
u8* rom;
|
||||
bool chrRam = false;
|
||||
|
||||
protected:
|
||||
u32 prgMap[4];
|
||||
u32 chrMap[8];
|
||||
|
@ -17,6 +20,7 @@ class Mapper
|
|||
|
||||
public:
|
||||
Mapper(u8* rom);
|
||||
~Mapper();
|
||||
|
||||
u8 read(u16 addr);
|
||||
virtual u8 write(u16 addr, u8 v) { return v; }
|
||||
|
|
|
@ -44,7 +44,7 @@ void Blip_Buffer::clear( bool entire_buffer )
|
|||
|
||||
blargg_err_t Blip_Buffer::sample_rate( long new_rate, int msec )
|
||||
{
|
||||
unsigned new_size = (ULONG_MAX >> BLIP_BUFFER_ACCURACY) + 1 - widest_impulse_ - 64;
|
||||
unsigned new_size = (UINT_MAX >> BLIP_BUFFER_ACCURACY) + 1 - widest_impulse_ - 64;
|
||||
if ( msec != blip_default_length )
|
||||
{
|
||||
size_t s = (new_rate * (msec + 1) + 999) / 1000;
|
||||
|
|
Reference in a new issue