diff --git a/source/core/Data_Reader.cpp b/source/core/Data_Reader.cpp index cb366a3..579b279 100644 --- a/source/core/Data_Reader.cpp +++ b/source/core/Data_Reader.cpp @@ -20,7 +20,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ // Data_Reader -const char * Data_Reader::read( void* p, int n ) +const char * Data_Reader::read( void* p, size_t n ) { if ( n < 0 ) return "Internal usage bug"; @@ -38,14 +38,11 @@ const char * Data_Reader::read( void* p, int n ) return err; } -const char * Data_Reader::read_avail( void* p, int* n_ ) +const char * Data_Reader::read_avail( void* p, size_t* n_ ) { int n = min( (uint64_t)(*n_), remain() ); *n_ = 0; - if ( n < 0 ) - return "Internal usage bug"; - if ( n <= 0 ) return 0; @@ -59,14 +56,6 @@ const char * Data_Reader::read_avail( void* p, int* n_ ) return err; } -const char * Data_Reader::read_avail( void* p, long* n ) -{ - int i = STATIC_CAST(int, *n); - const char * err = read_avail( p, &i ); - *n = i; - return err; -} - const char * Data_Reader::skip_v( int count ) { char buf [512]; @@ -79,11 +68,8 @@ const char * Data_Reader::skip_v( int count ) return 0; } -const char * Data_Reader::skip( int n ) +const char * Data_Reader::skip( size_t n ) { - if ( n < 0 ) - return "Internal usage bug"; - if ( n <= 0 ) return 0; diff --git a/source/core/Data_Reader.h b/source/core/Data_Reader.h index 110108c..dc76643 100644 --- a/source/core/Data_Reader.h +++ b/source/core/Data_Reader.h @@ -22,18 +22,17 @@ public: // Reads min(*n,remain()) bytes and sets *n to this number, thus trying to read more // tham remain() bytes doesn't result in error, just *n being set to remain(). - const char * read_avail( void* p, int* n ); - const char * read_avail( void* p, long* n ); + const char * read_avail( void* p, size_t* n ); // Reads exactly n bytes, or returns error if they couldn't ALL be read. // Reading past end of file results in blargg_err_file_eof. - const char * read( void* p, int n ); + const char * read( void* p, size_t n ); // Number of bytes remaining until end of file - uint64_t remain() const { return remain_; } + size_t remain() const { return remain_; } // Reads and discards n bytes. Skipping past end of file results in blargg_err_file_eof. - const char * skip( int n ); + const char * skip( size_t n ); virtual ~Data_Reader() { } @@ -47,7 +46,7 @@ protected: Data_Reader() : remain_( 0 ) { } // Sets remain - void set_remain( uint64_t n ) { remain_ = n; } + void set_remain( size_t n ) { remain_ = n; } // Do same as read(). Guaranteed that 0 < n <= remain(). Value of remain() is updated // AFTER this call succeeds, not before. set_remain() should NOT be called from this. diff --git a/source/core/Nes_Buffer.cpp b/source/core/Nes_Buffer.cpp index 731e05a..c0979df 100644 --- a/source/core/Nes_Buffer.cpp +++ b/source/core/Nes_Buffer.cpp @@ -163,7 +163,7 @@ Nes_Nonlinearizer::Nes_Nonlinearizer() float const gain = 0x7fff * 1.3f; // don't use entire range, so any overflow will stay within table int const range = (int) (table_size * Nes_Apu::nonlinear_tnd_gain()); - for ( int i = 0; i < table_size; i++ ) + for (uint32_t i = 0; i < table_size; i++ ) { int const offset = table_size - range; int j = i - offset; diff --git a/source/core/Nes_Buffer.h b/source/core/Nes_Buffer.h index 6d70fe4..f7a64f4 100644 --- a/source/core/Nes_Buffer.h +++ b/source/core/Nes_Buffer.h @@ -11,8 +11,8 @@ class Nes_Apu; class Nes_Nonlinearizer { private: - enum { table_bits = 11 }; - enum { table_size = 1 << table_bits }; + static const uint8_t table_bits = 11; + static const uint32_t table_size = 1 << table_bits; int16_t table [table_size]; Nes_Apu* apu; long accum; diff --git a/source/core/Nes_Core.cpp b/source/core/Nes_Core.cpp index cf62b8a..c673733 100644 --- a/source/core/Nes_Core.cpp +++ b/source/core/Nes_Core.cpp @@ -207,9 +207,6 @@ void Nes_Core::enable_sram( bool b, bool read_only ) // Unmapped memory -#ifndef NDEBUG -static nes_addr_t last_unmapped_addr; -#endif void Nes_Core::log_unmapped( nes_addr_t addr, int data ) { diff --git a/source/core/Nes_Fme7_Apu.h b/source/core/Nes_Fme7_Apu.h index 79d714b..507d98b 100644 --- a/source/core/Nes_Fme7_Apu.h +++ b/source/core/Nes_Fme7_Apu.h @@ -60,7 +60,7 @@ private: } oscs [osc_count]; blip_time_t last_time; - enum { amp_range = 192 }; // can be any value; this gives best error/quality tradeoff + static const uint8_t amp_range = 192; // can be any value; this gives best error/quality tradeoff Blip_Synth synth; void run_until( blip_time_t ); diff --git a/source/core/Nes_Namco_Apu.h b/source/core/Nes_Namco_Apu.h index 6f793f0..6e76784 100644 --- a/source/core/Nes_Namco_Apu.h +++ b/source/core/Nes_Namco_Apu.h @@ -20,7 +20,7 @@ public: void volume( double ); void treble_eq( const blip_eq_t& ); void output( Blip_Buffer* ); - enum { osc_count = 8 }; + static const uint8_t osc_count = 8; void osc_output( int index, Blip_Buffer* ); void reset(); void end_frame( nes_time_t ); diff --git a/source/core/Nes_Ppu_Bg.h b/source/core/Nes_Ppu_Bg.h deleted file mode 100644 index 81e1eb3..0000000 --- a/source/core/Nes_Ppu_Bg.h +++ /dev/null @@ -1,68 +0,0 @@ -while ( true ) -{ - while ( count-- ) - { - int attrib = attr_table [addr >> 2 & 0x07]; - attrib >>= (addr >> 4 & 4) | (addr & 2); - unsigned long offset = (attrib & 3) * attrib_factor + this->palette_offset; - - // draw one tile - cache_t const* lines = this->get_bg_tile( nametable [addr] + bg_bank ); - uint8_t* p = pixels; - addr++; - pixels += 8; // next tile - - if ( !clipped ) - { - // optimal case: no clipping - for ( int n = 4; n--; ) - { - unsigned long line = *lines++; - ((unaligned_uint32_t*) p) [0].val = (line >> 4 & mask) + offset; - ((unaligned_uint32_t*) p) [1].val = (line & mask) + offset; - p += row_bytes; - ((unaligned_uint32_t*) p) [0].val = (line >> 6 & mask) + offset; - ((unaligned_uint32_t*) p) [1].val = (line >> 2 & mask) + offset; - p += row_bytes; - } - } - else - { - lines += fine_y >> 1; - - if ( fine_y & 1 ) - { - unsigned long line = *lines++; - ((unaligned_uint32_t*) p) [0].val = (line >> 6 & mask) + offset; - ((unaligned_uint32_t*) p) [1].val = (line >> 2 & mask) + offset; - p += row_bytes; - } - - for ( int n = height >> 1; n--; ) - { - unsigned long line = *lines++; - ((unaligned_uint32_t*) p) [0].val = (line >> 4 & mask) + offset; - ((unaligned_uint32_t*) p) [1].val = (line & mask) + offset; - p += row_bytes; - ((unaligned_uint32_t*) p) [0].val = (line >> 6 & mask) + offset; - ((unaligned_uint32_t*) p) [1].val = (line >> 2 & mask) + offset; - p += row_bytes; - } - - if ( height & 1 ) - { - unsigned long line = *lines; - ((unaligned_uint32_t*) p) [0].val = (line >> 4 & mask) + offset; - ((unaligned_uint32_t*) p) [1].val = (line & mask) + offset; - } - } - } - - count = count2; - count2 = 0; - addr -= 32; - attr_table = attr_table - nametable + nametable2; - nametable = nametable2; - if ( !count ) - break; -} diff --git a/source/core/Nes_Ppu_Rendering.cpp b/source/core/Nes_Ppu_Rendering.cpp index 2abef34..62110ce 100644 --- a/source/core/Nes_Ppu_Rendering.cpp +++ b/source/core/Nes_Ppu_Rendering.cpp @@ -190,23 +190,80 @@ void Nes_Ppu_Rendering::draw_background_( int remain ) unsigned long const mask = 0x03030303 + zero; unsigned long const attrib_factor = 0x04040404 + zero; - if ( height == 8 ) + const int fine_y = (height == 8) ? 0 : addr >> 12; + const int clipped = (height == 8) ? false : true; + addr &= 0x03ff; + if (height == 8) height -= fine_y & 1; + + while ( true ) { - // unclipped - addr &= 0x03ff; - int const fine_y = 0; - int const clipped = false; - #include "Nes_Ppu_Bg.h" - } - else - { - // clipped - int const fine_y = addr >> 12; - addr &= 0x03ff; - height -= fine_y & 1; - int const clipped = true; - #include "Nes_Ppu_Bg.h" + while ( count-- ) + { + int attrib = attr_table [addr >> 2 & 0x07]; + attrib >>= (addr >> 4 & 4) | (addr & 2); + unsigned long offset = (attrib & 3) * attrib_factor + this->palette_offset; + + // draw one tile + cache_t const* lines = this->get_bg_tile( nametable [addr] + bg_bank ); + uint8_t* p = pixels; + addr++; + pixels += 8; // next tile + + if ( !clipped ) + { + // optimal case: no clipping + for ( int n = 4; n--; ) + { + unsigned long line = *lines++; + ((unaligned_uint32_t*) p) [0].val = (line >> 4 & mask) + offset; + ((unaligned_uint32_t*) p) [1].val = (line & mask) + offset; + p += row_bytes; + ((unaligned_uint32_t*) p) [0].val = (line >> 6 & mask) + offset; + ((unaligned_uint32_t*) p) [1].val = (line >> 2 & mask) + offset; + p += row_bytes; + } + } + else + { + lines += fine_y >> 1; + + if ( fine_y & 1 ) + { + unsigned long line = *lines++; + ((unaligned_uint32_t*) p) [0].val = (line >> 6 & mask) + offset; + ((unaligned_uint32_t*) p) [1].val = (line >> 2 & mask) + offset; + p += row_bytes; + } + + for ( int n = height >> 1; n--; ) + { + unsigned long line = *lines++; + ((unaligned_uint32_t*) p) [0].val = (line >> 4 & mask) + offset; + ((unaligned_uint32_t*) p) [1].val = (line & mask) + offset; + p += row_bytes; + ((unaligned_uint32_t*) p) [0].val = (line >> 6 & mask) + offset; + ((unaligned_uint32_t*) p) [1].val = (line >> 2 & mask) + offset; + p += row_bytes; + } + + if ( height & 1 ) + { + unsigned long line = *lines; + ((unaligned_uint32_t*) p) [0].val = (line >> 4 & mask) + offset; + ((unaligned_uint32_t*) p) [1].val = (line & mask) + offset; + } + } + } + + count = count2; + count2 = 0; + addr -= 32; + attr_table = attr_table - nametable + nametable2; + nametable = nametable2; + if ( !count ) + break; } + } while ( remain ); } diff --git a/source/core/abstract_file.cpp b/source/core/abstract_file.cpp index 417cf8f..0280032 100644 --- a/source/core/abstract_file.cpp +++ b/source/core/abstract_file.cpp @@ -1,8 +1,6 @@ #include "abstract_file.h" -#include "blargg_config.h" - #include #include diff --git a/source/core/nes_ntsc.h b/source/core/nes_ntsc.h index 1f53187..044d485 100644 --- a/source/core/nes_ntsc.h +++ b/source/core/nes_ntsc.h @@ -111,6 +111,7 @@ typedef unsigned long nes_ntsc_rgb_t; struct nes_ntsc_t { nes_ntsc_rgb_t table [nes_ntsc_palette_size] [nes_ntsc_entry_size]; }; + enum { nes_ntsc_burst_size = nes_ntsc_entry_size / nes_ntsc_burst_count }; #define NES_NTSC_ENTRY_( ktable, n ) \