From 82368f4a27d86599f6cbb4cf5e751f4b123ab056 Mon Sep 17 00:00:00 2001 From: Sergio Martin Date: Tue, 16 Jan 2024 18:49:46 +0100 Subject: [PATCH] more simplifications --- source/quickerNES/Nes_Ppu_Bg.h | 68 --------------- source/quickerNES/meson.build | 1 - source/quickerNES/nes_util.cpp | 153 --------------------------------- source/quickerNES/nes_util.h | 64 -------------- 4 files changed, 286 deletions(-) delete mode 100644 source/quickerNES/Nes_Ppu_Bg.h delete mode 100644 source/quickerNES/nes_util.cpp delete mode 100644 source/quickerNES/nes_util.h diff --git a/source/quickerNES/Nes_Ppu_Bg.h b/source/quickerNES/Nes_Ppu_Bg.h deleted file mode 100644 index 81e1eb3..0000000 --- a/source/quickerNES/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/quickerNES/meson.build b/source/quickerNES/meson.build index b64dc84..1eb1fc8 100644 --- a/source/quickerNES/meson.build +++ b/source/quickerNES/meson.build @@ -14,7 +14,6 @@ quickerNESSrc = [ 'Effects_Buffer.cpp', 'Nes_State.cpp', 'emu2413.cpp', - 'nes_util.cpp', 'emu2413_state.cpp', 'Nes_Effects_Buffer.cpp', 'Nes_Namco_Apu.cpp', diff --git a/source/quickerNES/nes_util.cpp b/source/quickerNES/nes_util.cpp deleted file mode 100644 index 93e371f..0000000 --- a/source/quickerNES/nes_util.cpp +++ /dev/null @@ -1,153 +0,0 @@ - -// Nes_Emu 0.7.0. http://www.slack.net/~ant/ - -#include "nes_util.h" - -#include "Nes_Cart.h" -#include "Nes_Emu.h" -#include -#include - -/* 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 -General Public License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. This -module is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for -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" - -// game_genie_patch_t - -const char *game_genie_patch_t::decode( const char* in ) -{ - int const code_len = 8; - unsigned char result [code_len] = { 0 }; - int in_len = strlen( in ); - if ( in_len != 6 && in_len != 8 ) - return "Game Genie code is wrong length"; - for ( int i = 0; i < code_len; i++ ) - { - char c = 'A'; - if ( i < in_len ) - c = toupper( in [i] ); - - static char const letters [17] = "AEPOZXLUGKISTVYN"; - char const* p = strchr( (char*) letters, c ); - if ( !p ) - return "Game Genie code had invalid character"; - int n = p - letters; - - result [i] |= n >> 1; - result [(i + 1) % code_len] |= (n << 3) & 0x0f; - } - - addr = result [3]<<12 | result [5]<<8 | result [2]<<4 | result [4]; - change_to = result [1]<<4 | result [0]; - compare_with = -1; - if ( addr & 0x8000 ) - compare_with = result [7]<<4 | result [6]; - addr |= 0x8000; - - return 0; -} - -int game_genie_patch_t::apply( Nes_Cart& cart ) const -{ - // determine bank size - long bank_size = 32 * 1024L; // mappers 0, 2, 3, 7, 11, 34, 71, 87 - switch ( cart.mapper_code() ) - { - case 1: // MMC1 - case 71: // Camerica - case 232: // Quattro - bank_size = 16 * 1024L; - break; - - case 4: // MMC3 - case 5: // MMC5 - case 24: // VRC6 - case 26: // VRC6 - case 69: // FME7 - bank_size = 8 * 1024L; - break; - } - - // patch each bank (not very good, since it might patch banks that never occupy - // that address) - int mask = (compare_with >= 0 ? ~0 : 0); - uint8_t* p = cart.prg() + addr % bank_size; - int count = 0; - for ( int n = cart.prg_size() / bank_size; n--; p += bank_size ) - { - if ( !((*p ^ compare_with) & mask) ) - { - *p = change_to; - count++; - } - } - return count; -} - -// Cheat_Value_Finder - -Cheat_Value_Finder::Cheat_Value_Finder() -{ - emu = NULL; -} - -void Cheat_Value_Finder::start( Nes_Emu* new_emu ) -{ - emu = new_emu; - pos = 0; - memcpy( original, emu->low_mem(), low_mem_size ); - memset( changed, 0, low_mem_size ); -} - -void Cheat_Value_Finder::rescan() -{ - uint8_t const* low_mem = emu->low_mem(); - for ( int i = 0; i < low_mem_size; i++ ) - changed [i] |= original [i] ^ low_mem [i]; - memcpy( original, emu->low_mem(), low_mem_size ); -} - -void Cheat_Value_Finder::search( int new_original, int new_changed ) -{ - original_value = new_original; - changed_value = new_changed; - pos = -1; -} - -int Cheat_Value_Finder::next_match( int* addr ) -{ - uint8_t const* low_mem = emu->low_mem(); - while ( ++pos < low_mem_size ) - { - if ( !changed [pos] ) - { - int old = (original [pos] - original_value) & 0xff; - int cur = (low_mem [pos] - changed_value) & 0xff; - - if ( old == cur ) - { - if ( addr ) - *addr = pos; - return (char) old; // sign-extend - } - } - } - - return no_match; -} - -int Cheat_Value_Finder::change_value( int new_value ) -{ - int result = emu->low_mem() [pos]; - emu->low_mem() [pos] = new_value; - return result; -} diff --git a/source/quickerNES/nes_util.h b/source/quickerNES/nes_util.h deleted file mode 100644 index f604acb..0000000 --- a/source/quickerNES/nes_util.h +++ /dev/null @@ -1,64 +0,0 @@ - -// Experimental utilities for NES emulator - -// Nes_Emu 0.7.0 - -#ifndef NES_UTIL_H -#define NES_UTIL_H - -#include -#include "blargg_common.h" - -class Nes_Emu; -class Nes_Cart; - -struct game_genie_patch_t -{ - unsigned addr; // always 0x8000 or greater - int change_to; - int compare_with; // if -1, always change byte - - // Decode Game Genie code - const char *decode( const char* in ); - - // Apply patch to cartridge data. Might not work for some codes, since this really - // requires emulator support. Returns number of bytes changed, where 0 - // means patch wasn't for that cartridge. - int apply( Nes_Cart& ) const; -}; - -class Cheat_Value_Finder { -public: - Cheat_Value_Finder(); - - // Start scanning emulator's memory for values that are constantly changing. - void start( Nes_Emu* ); - - // Rescan memory and eliminate any changed bytes from later matching. - // Should be called many times after begin_scan() and before begin_matching(). - void rescan(); - - // Start search for any bytes which changed by difference between original and - // changed values. - void search( int original, int changed ); - - // Get next match and return its delta from changed value (closer to 0 - // is more likely to be a match), or no_match if there are no more matches. - // Optionally returns address of matched byte. - enum { no_match = 0x100 }; - int next_match( int* addr = NULL ); - - // Change current match to new value. Returns previous value. - int change_value( int new_value ); - -private: - Nes_Emu* emu; - int original_value; - int changed_value; - int pos; - enum { low_mem_size = 0x800 }; - uint8_t original [low_mem_size]; - uint8_t changed [low_mem_size]; -}; - -#endif