Simplifications

This commit is contained in:
Sergio Martin 2024-01-19 17:21:04 +01:00
parent 131aa5bb97
commit ae2f61d029
38 changed files with 41 additions and 172 deletions

View File

@ -2,8 +2,7 @@
// Game_Music_Emu 0.3.0. http://www.slack.net/~ant/
#include "Effects_Buffer.h"
#include <string.h>
#include <cstring>
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser
@ -16,12 +15,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
#ifdef BLARGG_ENABLE_OPTIMIZER
#include BLARGG_ENABLE_OPTIMIZER
#endif
typedef long fixed_t;
#define TO_FIXED( f ) fixed_t ((f) * (1L << 15) + 0.5)
@ -98,8 +91,7 @@ const char *Effects_Buffer::set_sample_rate( long rate, int msec )
reverb_buf = new blip_sample_t [reverb_size];
}
for ( int i = 0; i < buf_count; i++ )
RETURN_ERR( bufs [i].set_sample_rate( rate, msec ) );
for ( int i = 0; i < buf_count; i++ ) bufs [i].set_sample_rate( rate, msec );
config( config_ );
clear();

View File

@ -14,8 +14,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
Multi_Buffer::Multi_Buffer( int spf ) : samples_per_frame_( spf )
{
length_ = 0;
@ -49,7 +47,7 @@ Mono_Buffer::~Mono_Buffer()
const char * Mono_Buffer::set_sample_rate( long rate, int msec )
{
RETURN_ERR( buf.set_sample_rate( rate, msec ) );
buf.set_sample_rate( rate, msec );
return Multi_Buffer::set_sample_rate( buf.sample_rate(), buf.length() );
}
@ -115,8 +113,7 @@ Stereo_Buffer::~Stereo_Buffer()
const char * Stereo_Buffer::set_sample_rate( long rate, int msec )
{
for ( int i = 0; i < buf_count; i++ )
RETURN_ERR( bufs [i].set_sample_rate( rate, msec ) );
for ( int i = 0; i < buf_count; i++ ) bufs [i].set_sample_rate( rate, msec ) ;
return Multi_Buffer::set_sample_rate( bufs [0].sample_rate(), bufs [0].length() );
}

View File

@ -14,8 +14,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
int const amp_range = 15;
Nes_Apu::Nes_Apu() :

View File

@ -5,7 +5,6 @@
// Nes_Snd_Emu 0.1.7
#include <cstdint>
#include "blargg_source.h"
#include "blargg_endian.h"
typedef long nes_time_t; // CPU clock cycle count

View File

@ -1,8 +1,6 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/
#include "Nes_Buffer.h"
#include "Nes_Apu.h"
/* Library Copyright (C) 2003-2006 Shay Green. This library is free software;
@ -16,11 +14,6 @@ details. You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
#ifdef BLARGG_ENABLE_OPTIMIZER
#include BLARGG_ENABLE_OPTIMIZER
#endif
// Nes_Buffer
@ -47,8 +40,8 @@ void Nes_Buffer::enable_nonlinearity( bool b )
const char * Nes_Buffer::set_sample_rate( long rate, int msec )
{
enable_nonlinearity( nonlin.enabled ); // reapply
RETURN_ERR( buf.set_sample_rate( rate, msec ) );
RETURN_ERR( tnd.set_sample_rate( rate, msec ) );
buf.set_sample_rate( rate, msec );
tnd.set_sample_rate( rate, msec );
return Multi_Buffer::set_sample_rate( buf.sample_rate(), buf.length() );
}

View File

@ -39,7 +39,7 @@ public:
BOOST_STATIC_ASSERT( sizeof (ines_header_t) == 16 );
// Load iNES file
const char * load_ines( const uint8_t* buffer )
void load_ines( const uint8_t* buffer )
{
ines_header_t h;
@ -61,8 +61,6 @@ public:
{ size_t copySize = prg_size(); memcpy(prg(), &buffer[bufferPos], copySize); bufferPos += copySize; }
{ size_t copySize = chr_size(); memcpy(chr(), &buffer[bufferPos], copySize); bufferPos += copySize; }
return 0;
}
inline bool has_battery_ram() const { return mapper & 0x02; }

View File

@ -159,10 +159,10 @@ public:
return 0;
}
const char * open( Nes_Cart const* new_cart )
void open( Nes_Cart const* new_cart )
{
close();
RETURN_ERR( init() );
init();
// Getting cartdrige mapper code
auto mapperCode = new_cart->mapper_code();
@ -228,20 +228,18 @@ public:
if (mapper == NULL)
{
fprintf(stderr, "Could not find mapper for code: %u\n", mapperCode);
return NULL;
exit(-1);
}
// Assigning backwards pointers to cartdrige and emulator now
mapper->cart_ = new_cart;
mapper->emu_ = this;
RETURN_ERR( ppu.open_chr( new_cart->chr(), new_cart->chr_size() ) );
ppu.open_chr( new_cart->chr(), new_cart->chr_size() );
cart = new_cart;
memset( impl->unmapped_page, unmapped_fill, sizeof impl->unmapped_page );
reset( true, true );
return 0;
}
size_t getLiteStateSize() const
@ -689,7 +687,7 @@ private:
inline nes_time_t earliest_irq( nes_time_t present )
{
return min( impl->apu.earliest_irq( present ), mapper->next_irq( present ) );
return std::min( impl->apu.earliest_irq( present ), mapper->next_irq( present ) );
}
inline nes_time_t ppu_frame_length( nes_time_t present )
@ -710,13 +708,13 @@ private:
// DMC
if ( wait_states_enabled )
t = min( t, impl->apu.next_dmc_read_time() + 1 );
t = std::min( t, impl->apu.next_dmc_read_time() + 1 );
// NMI
t = min( t, ppu.nmi_time() );
t = std::min( t, ppu.nmi_time() );
if ( single_instruction_mode )
t = min( t, present + 1 );
t = std::min( t, present + 1 );
return t;
}

View File

@ -2,7 +2,6 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/libs/
#include "Nes_Effects_Buffer.h"
#include "Nes_Apu.h"
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you
@ -16,8 +15,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
Nes_Effects_Buffer::Nes_Effects_Buffer() :
Effects_Buffer( true ) // nes never uses stereo channels
{

View File

@ -1,11 +1,9 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/
#include "Nes_Emu.h"
#include <cstdio>
#include <cstring>
#include "Nes_Mapper.h"
#include "Nes_Emu.h"
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser
@ -18,8 +16,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
int const sound_fade_size = 384;
// Constants are manually duplicated in Nes_Emu so their value can be seen
@ -70,12 +66,13 @@ inline const char * Nes_Emu::auto_init()
{
if ( !init_called )
{
RETURN_ERR( init_() );
init_();
init_called = true;
}
return 0;
}
inline void Nes_Emu::clear_sound_buf()
{
fade_sound_out = false;
@ -83,19 +80,16 @@ inline void Nes_Emu::clear_sound_buf()
sound_buf->clear();
}
const char * Nes_Emu::set_cart( Nes_Cart const* new_cart )
void Nes_Emu::set_cart( Nes_Cart const* new_cart )
{
RETURN_ERR( auto_init() );
RETURN_ERR( emu.open( new_cart ) );
auto_init();
emu.open( new_cart );
channel_count_ = Nes_Apu::osc_count + emu.mapper->channel_count();
RETURN_ERR( sound_buf->set_channel_count( channel_count() ) );
sound_buf->set_channel_count( channel_count() );
set_equalizer( equalizer_ );
enable_sound( true );
reset();
return 0;
}
void Nes_Emu::reset( bool full_reset, bool erase_battery_ram )
@ -175,10 +169,10 @@ const char * Nes_Emu::emulate_frame( int joypad1, int joypad2 )
// Extras
const char * Nes_Emu::load_ines( const uint8_t* buffer )
void Nes_Emu::load_ines( const uint8_t* buffer )
{
private_cart.load_ines( buffer );
return set_cart( &private_cart );
set_cart( &private_cart );
}
void Nes_Emu::write_chr( void const* p, long count, long offset )
@ -191,14 +185,14 @@ void Nes_Emu::write_chr( void const* p, long count, long offset )
const char * Nes_Emu::set_sample_rate( long rate, class Nes_Buffer* buf )
{
extern Multi_Buffer* set_apu( class Nes_Buffer*, Nes_Apu* );
RETURN_ERR( auto_init() );
auto_init();
return set_sample_rate( rate, set_apu( buf, &emu.impl->apu ) );
}
const char * Nes_Emu::set_sample_rate( long rate, class Nes_Effects_Buffer* buf )
{
extern Multi_Buffer* set_apu( class Nes_Effects_Buffer*, Nes_Apu* );
RETURN_ERR( auto_init() );
auto_init();
return set_sample_rate( rate, set_apu( buf, &emu.impl->apu ) );
}
@ -211,9 +205,9 @@ void Nes_Emu::set_frame_rate( double rate )
const char * Nes_Emu::set_sample_rate( long rate, Multi_Buffer* new_buf )
{
RETURN_ERR( auto_init() );
auto_init();
emu.impl->apu.volume( 1.0 ); // cancel any previous non-linearity
RETURN_ERR( new_buf->set_sample_rate( rate, 1200 / frame_rate ) );
new_buf->set_sample_rate( rate, 1200 / frame_rate );
sound_buf = new_buf;
sound_buf_changed_count = 0;
if ( new_buf != default_sound_buf )

View File

@ -20,7 +20,7 @@ public:
// Basic setup
// Load iNES file into emulator and clear recording
const char * load_ines( const uint8_t* buffer );
void load_ines( const uint8_t* buffer );
// Set sample rate for sound generation
const char * set_sample_rate( long );
@ -88,7 +88,7 @@ public:
// Use already-loaded cartridge. Retains pointer, so it must be kept around until
// closed. A cartridge can be shared among multiple emulators. After opening,
// cartridge's CHR data shouldn't be modified since a copy is cached internally.
const char * set_cart( Nes_Cart const* );
void set_cart( Nes_Cart const* );
// Pointer to current cartridge, or NULL if none is loaded
Nes_Cart const* cart() const { return emu.cart; }

View File

@ -16,8 +16,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
void Nes_Fme7_Apu::reset()
{
last_time = 0;

View File

@ -1,8 +1,8 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/
#include <cstring>
#include "Nes_Mapper.h"
#include <string.h>
#include "Nes_Core.h"
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you
@ -16,8 +16,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
Nes_Mapper::Nes_Mapper()
{
emu_ = NULL;

View File

@ -14,8 +14,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
Nes_Namco_Apu::Nes_Namco_Apu()
{
output( NULL );

View File

@ -14,12 +14,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
#ifdef BLARGG_ENABLE_OPTIMIZER
#include BLARGG_ENABLE_OPTIMIZER
#endif
// Nes_Osc
void Nes_Osc::clock_length( int halt_mask )

View File

@ -22,8 +22,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
// to do: remove unnecessary run_until() calls
#include "blargg_source.h"
// Timing
ppu_time_t const scanline_len = Nes_Ppu::scanline_len;
@ -271,7 +269,7 @@ void Nes_Ppu::update_sprite_hit( nes_time_t cpu_time )
if ( count_needed > 240 )
count_needed = 240;
while ( scanline_count < count_needed )
render_bg_until( max( cpu_time, next_bg_time + 1 ) );
render_bg_until( std::max( cpu_time, next_bg_time + 1 ) );
if ( sprite_hit_found < 0 )
return; // sprite won't hit

View File

@ -19,8 +19,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
int const cache_line_size = 128; // tile cache is kept aligned to this boundary
Nes_Ppu_Impl::Nes_Ppu_Impl()

View File

@ -2,9 +2,9 @@
// Nes_Emu 0.7.0. http://www.slack.net/~ant/
#include "Nes_Ppu_Rendering.h"
#include <string.h>
#include <stddef.h>
#include <algorithm>
#include <cstring>
#include <cstddef>
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you
can redistribute it and/or modify it under the terms of the GNU Lesser
@ -17,20 +17,10 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
#ifdef BLARGG_ENABLE_OPTIMIZER
#include BLARGG_ENABLE_OPTIMIZER
#endif
#ifdef __MWERKS__
static unsigned zero = 0; // helps CodeWarrior optimizer when added to constants
#else
const unsigned zero = 0; // compile-time constant on other compilers
#endif
// Nes_Ppu_Impl
static unsigned zero = 0; // helps CodeWarrior optimizer when added to constants
inline Nes_Ppu_Impl::cached_tile_t const&
Nes_Ppu_Impl::get_sprite_tile( uint8_t const* sprite )
{
@ -509,8 +499,8 @@ void Nes_Ppu_Rendering::draw_background( int start, int count )
{
// not rendering, but still handle sprite hit using mini graphics buffer
int y = spr_ram [0] + 1;
int skip = min( count, max( y - start, 0 ) );
int visible = min( count - skip, sprite_height() );
int skip = std::min( count, std::max( y - start, 0 ) );
int visible = std::min( count - skip, sprite_height() );
if ( visible > 0 )
{

View File

@ -14,8 +14,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
Nes_Vrc6_Apu::Nes_Vrc6_Apu()
{
output( NULL );

View File

@ -1,30 +0,0 @@
/* Included at the beginning of library source files, AFTER all other #include
lines. Sets up helpful macros and services used in my source code. Since this
is only "active" in my source code, I don't have to worry about polluting the
global namespace with unprefixed names. */
// File_Extractor 1.0.0
#ifndef BLARGG_SOURCE_H
#define BLARGG_SOURCE_H
#ifndef BLARGG_COMMON_H // optimization only
#include "blargg_common.h"
#endif
#include <string.h> /* memcpy(), memset(), memmove() */
#include <stddef.h> /* offsetof() */
/* If expr yields non-NULL error string, returns it from current function,
otherwise continues normally. */
#undef RETURN_ERR
#define RETURN_ERR( expr ) \
do {\
const char *blargg_return_err_ = (expr);\
if ( blargg_return_err_ )\
return blargg_return_err_;\
} while ( 0 )
template<typename T> T min( T x, T y ) { return x < y ? x : y; }
template<typename T> T max( T x, T y ) { return x > y ? x : y; }
#endif

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// NROM
class Mapper000 : public Nes_Mapper {

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// MMC1
struct mmc1_state_t

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// UNROM
class Mapper002 : public Nes_Mapper {

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// CNROM
class Mapper003 : public Nes_Mapper {

View File

@ -18,8 +18,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// 264 or less breaks Gargoyle's Quest II
// 267 or less breaks Magician
int const irq_fine_tune = 268;

View File

@ -20,9 +20,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
struct mmc5_state_t
{
enum { reg_count = 0x30 };

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// AOROM
class Mapper007 : public Nes_Mapper {

View File

@ -1,9 +1,7 @@
#pragma once
#include <cstring>
#include "Nes_Mapper.h"
#include "blargg_source.h"
// MMC2

View File

@ -1,8 +1,6 @@
#pragma once
#include <cstring>
#include "Nes_Mapper.h"
#include "blargg_source.h"
// MMC4

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// Color Dreams
class Mapper011 : public Nes_Mapper {

View File

@ -20,8 +20,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// to do: CHR mapping and nametable handling needs work
struct namco106_state_t

View File

@ -20,8 +20,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
struct vrc6_state_t
{
// written registers

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// Nina-1 (Deadly Towers only)
class Mapper034 : public Nes_Mapper {

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// GNROM
class Mapper066 : public Nes_Mapper {

View File

@ -21,8 +21,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
struct fme7_state_t
{
// first 16 bytes in register order
@ -43,8 +41,6 @@ struct fme7_state_t
};
BOOST_STATIC_ASSERT( sizeof (fme7_state_t) == 18 + sizeof (fme7_apu_state_t) );
// Fme7
class Mapper069 : public Nes_Mapper, fme7_state_t {

View File

@ -17,8 +17,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// Camerica
class Mapper071 : public Nes_Mapper {

View File

@ -18,8 +18,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// Jaleco/Konami/Taito
class Mapper087 : public Nes_Mapper {

View File

@ -18,8 +18,6 @@ more details. You should have received a copy of the GNU Lesser General
Public License along with this module; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "blargg_source.h"
// Quattro
class Mapper232 : public Nes_Mapper {

View File

@ -24,8 +24,8 @@ class QuickerNESInstance : public EmuInstance
virtual bool loadROMFileImpl(const std::string& romData) override
{
// Loading rom data
auto result = _nes->load_ines((uint8_t*)romData.data());
return result == 0;
_nes->load_ines((uint8_t*)romData.data());
return true;
}
uint8_t* getLowMem() const override { return _nes->low_mem(); };