diff -upr --new-file puNES-0.105.org/src/audio/alsa/snd.c puNES-0.105.new/src/audio/alsa/snd.c --- puNES-0.105.org/src/audio/alsa/snd.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/audio/alsa/snd.c 2020-03-18 11:46:27.357649299 +0100 @@ -81,6 +81,12 @@ static _snd_thread snd_thread; static _alsa alsa; static _callback_data cbd; +_snd snd; +_snd_list snd_list; + +void (*snd_apu_tick)(void); +void (*snd_end_frame)(void); + BYTE snd_init(void) { memset(&snd, 0x00, sizeof(_snd)); memset(&alsa, 0x00, sizeof(_alsa)); diff -upr --new-file puNES-0.105.org/src/audio/blipbuf.c puNES-0.105.new/src/audio/blipbuf.c --- puNES-0.105.org/src/audio/blipbuf.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/audio/blipbuf.c 2020-03-18 11:46:27.357649299 +0100 @@ -18,7 +18,6 @@ #include #include -#include "apu.h" #include "audio/snd.h" #include "mappers.h" #include "mappers/mapper_VRC7_snd.h" diff -upr --new-file puNES-0.105.org/src/audio/channels.c puNES-0.105.new/src/audio/channels.c --- puNES-0.105.org/src/audio/channels.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/audio/channels.c 2020-03-18 11:46:27.357649299 +0100 @@ -23,6 +23,11 @@ #include "audio/delay.h" #include "audio/panning.h" +BYTE (*audio_channels_init)(void); +void (*audio_channels_quit)(void); +void (*audio_channels_reset)(void); +void (*audio_channels_tick)(SWORD value); + void audio_channels(BYTE channels) { if (audio_channels_quit) { audio_channels_quit(); diff -upr --new-file puNES-0.105.org/src/audio/channels.h puNES-0.105.new/src/audio/channels.h --- puNES-0.105.org/src/audio/channels.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/audio/channels.h 2020-03-18 11:46:27.357649299 +0100 @@ -23,6 +23,11 @@ enum types_of_audio_channels { CH_MONO, CH_STEREO_DELAY, CH_STEREO_PANNING }; +extern BYTE (*audio_channels_init)(void); +extern void (*audio_channels_quit)(void); +extern void (*audio_channels_reset)(void); +extern void (*audio_channels_tick)(SWORD value); + #if defined (__cplusplus) #define EXTERNC extern "C" #else @@ -31,10 +36,6 @@ enum types_of_audio_channels { CH_MONO, EXTERNC void audio_channels(BYTE channels); EXTERNC void audio_channels_init_mode(void); -EXTERNC BYTE (*audio_channels_init)(void); -EXTERNC void (*audio_channels_quit)(void); -EXTERNC void (*audio_channels_reset)(void); -EXTERNC void (*audio_channels_tick)(SWORD value); #undef EXTERNC diff -upr --new-file puNES-0.105.org/src/audio/snd.h puNES-0.105.new/src/audio/snd.h --- puNES-0.105.org/src/audio/snd.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/audio/snd.h 2020-03-18 11:46:27.358649291 +0100 @@ -79,6 +79,16 @@ typedef struct _snd { } limit; } buffer; } _snd; +typedef struct _snd_list { + _snd_list_dev playback; + _snd_list_dev capture; +} _snd_list; + +extern _snd snd; +extern _snd_list snd_list; + +extern void (*snd_apu_tick)(void); +extern void (*snd_end_frame)(void); #if defined (__cplusplus) #define EXTERNC extern "C" @@ -86,12 +96,6 @@ typedef struct _snd { #define EXTERNC #endif -EXTERNC _snd snd; -EXTERNC struct _snd_list { - _snd_list_dev playback; - _snd_list_dev capture; -} snd_list; - EXTERNC BYTE snd_init(void); EXTERNC void snd_quit(void); @@ -119,9 +123,6 @@ EXTERNC void snd_list_devices(void); EXTERNC BYTE snd_handler(void); -EXTERNC void (*snd_apu_tick)(void); -EXTERNC void (*snd_end_frame)(void); - #undef EXTERNC #endif /* SND_H_ */ diff -upr --new-file puNES-0.105.org/src/audio/sndio/snd.c puNES-0.105.new/src/audio/sndio/snd.c --- puNES-0.105.org/src/audio/sndio/snd.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/audio/sndio/snd.c 2020-03-18 11:46:27.358649291 +0100 @@ -66,6 +66,12 @@ static _snd_thread snd_thread; static _sndio sndio; static _callback_data cbd; +_snd snd; +_snd_list snd_list; + +void (*snd_apu_tick)(void); +void (*snd_end_frame)(void); + BYTE snd_init(void) { memset(&snd, 0x00, sizeof(_snd)); memset(&sndio, 0x00, sizeof(_sndio)); diff -upr --new-file puNES-0.105.org/src/audio/xaudio/snd.c puNES-0.105.new/src/audio/xaudio/snd.c --- puNES-0.105.org/src/audio/xaudio/snd.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/audio/xaudio/snd.c 2020-03-18 11:46:27.358649291 +0100 @@ -25,7 +25,6 @@ #include "gui.h" #include "fps.h" #include "clock.h" -#include "apu.h" #include "wave.h" #if defined (DEBUG) #define __inline @@ -93,6 +92,12 @@ static IXAudio2VoiceCallbackVtbl voice_c static IXAudio2VoiceCallback voice_callbacks = { &voice_callbacks_vtable }; static _callback_data cbd; +_snd snd; +_snd_list snd_list; + +void (*snd_apu_tick)(void); +void (*snd_end_frame)(void); + BYTE snd_init(void) { memset(&snd, 0x00, sizeof(_snd)); memset(&xaudio2, 0x00, sizeof(xaudio2)); diff -upr --new-file puNES-0.105.org/src/core/apu.c puNES-0.105.new/src/core/apu.c --- puNES-0.105.org/src/core/apu.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/apu.c 2020-03-18 11:46:27.358649291 +0100 @@ -29,6 +29,16 @@ #include "mappers.h" #include "info.h" +_nla_table nla_table; +_apu apu; +_r4011 r4011; +_r4015 r4015; +_r4017 r4017; +_apuSquare S1, S2; +_apuTriangle TR; +_apuNoise NS; +_apuDMC DMC; + void apu_tick(BYTE *hwtick) { /* sottraggo il numero di cicli eseguiti */ apu.cycles--; diff -upr --new-file puNES-0.105.org/src/core/apu.h puNES-0.105.new/src/core/apu.h --- puNES-0.105.org/src/core/apu.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/apu.h 2020-03-18 11:46:27.358649291 +0100 @@ -362,6 +362,10 @@ typedef struct _config_apu { BYTE channel[APU_MASTER + 1]; double volume[APU_MASTER + 1]; } _config_apu; +typedef struct _nla_table { + SWORD pulse[32]; + SWORD tnd[203]; +} _nla_table; typedef struct _apu { BYTE mode; BYTE type; @@ -503,26 +507,6 @@ typedef struct _apuDMC { BYTE tick_type; } _apuDMC; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _nla_table { - SWORD pulse[32]; - SWORD tnd[203]; -} nla_table; - -EXTERNC _apu apu; -EXTERNC _r4011 r4011; -EXTERNC _r4015 r4015; -EXTERNC _r4017 r4017; -EXTERNC _apuSquare S1, S2; -EXTERNC _apuTriangle TR; -EXTERNC _apuNoise NS; -EXTERNC _apuDMC DMC; - /* apuPeriod[mode][type][cycles] */ static const WORD apuPeriod[2][3][7] = { /* @@ -625,6 +609,22 @@ static const WORD dmc_rate[3][16] = { } }; +extern _nla_table nla_table; +extern _apu apu; +extern _r4011 r4011; +extern _r4015 r4015; +extern _r4017 r4017; +extern _apuSquare S1, S2; +extern _apuTriangle TR; +extern _apuNoise NS; +extern _apuDMC DMC; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + EXTERNC void apu_tick(BYTE *hwtick); EXTERNC void apu_turn_on(void); diff -upr --new-file puNES-0.105.org/src/core/cheat.c puNES-0.105.new/src/core/cheat.c --- puNES-0.105.org/src/core/cheat.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/cheat.c 2020-03-18 11:47:29.361142706 +0100 @@ -32,6 +32,9 @@ #define GGFILE "gamegenie.rom" +_gamegenie gamegenie; +_cheats_list cheats_list; + void gamegenie_init(void) { memset(&gamegenie, 0x00, sizeof(gamegenie)); gamegenie_reset(); diff -upr --new-file puNES-0.105.org/src/core/cheat.h puNES-0.105.new/src/core/cheat.h --- puNES-0.105.org/src/core/cheat.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/cheat.h 2020-03-18 11:47:29.361142706 +0100 @@ -50,14 +50,7 @@ typedef struct _type_cheat { int counter; _cheat cheat[CL_CHEATS]; } _type_cheat; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _gamegenie { +typedef struct _gamegenie { uTCHAR *rom; uTCHAR *patch; BYTE phase; @@ -65,11 +58,20 @@ EXTERNC struct _gamegenie { BYTE value; BYTE counter; _cheat cheat[GG_CHEATS]; -} gamegenie; -EXTERNC struct _cheats_list { +} _gamegenie; +typedef struct _cheats_list { _type_cheat rom; _type_cheat ram; -} cheats_list; +} _cheats_list; + +extern _gamegenie gamegenie; +extern _cheats_list cheats_list; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void gamegenie_init(void); EXTERNC void gamegenie_quit(void); diff -upr --new-file puNES-0.105.org/src/core/clock.h puNES-0.105.new/src/core/clock.h --- puNES-0.105.org/src/core/clock.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/clock.h 2020-03-18 11:47:29.361142706 +0100 @@ -19,6 +19,8 @@ #ifndef CLOCK_H_ #define CLOCK_H_ +#include "common.h" + typedef struct { WORD type; /* il tipo di formato */ BYTE fps; /* il framerate */ @@ -104,14 +106,6 @@ static const _machine machinedb[] = { } }; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC _machine machine; - -#undef EXTERNC +extern _machine machine; #endif /* CLOCK_H_ */ diff -upr --new-file puNES-0.105.org/src/core/compilation_unit_orphan.h puNES-0.105.new/src/core/compilation_unit_orphan.h --- puNES-0.105.org/src/core/compilation_unit_orphan.h 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/compilation_unit_orphan.h 2020-03-18 11:47:29.361142706 +0100 @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef COMPILATION_UNIT_ORPHAN_H_ +#define COMPILATION_UNIT_ORPHAN_H_ + +#include "conf.h" +_config *cfg; +_config cfg_from_file; + +#include "tas.h" +_tas tas; + +void (*tas_header)(uTCHAR *file); +void (*tas_read)(void); +void (*tas_frame)(void); +void (*tas_rewind)(int32_t frames_to_rewind); + +#include "gui.h" +_gui gui; +_gui_mouse gmouse; +_external_windows ext_win; + +double (*gui_get_ms)(void); + +#include "info.h" +_info info; + +#include "clock.h" +_machine machine; + +#include "vs_system.h" +_vs_system vs_system; + +#include "mem_map.h" +_mmcpu mmcpu; +_prg prg; +_chr chr; +_nametables ntbl; +_mmap_palette mmap_palette; +_oam oam; + +#include "debugger.h" +_debugger debugger; + +#endif /* COMPILATION_UNIT_ORPHAN_H_ */ diff -upr --new-file puNES-0.105.org/src/core/conf.h puNES-0.105.new/src/core/conf.h --- puNES-0.105.org/src/core/conf.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/conf.h 2020-03-18 11:47:29.361142706 +0100 @@ -21,7 +21,6 @@ #include "apu.h" #include "input.h" -#include "overscan.h" typedef struct _last_pos { int x; @@ -96,14 +95,7 @@ typedef struct _config { _last_pos last_pos_settings; } _config; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC _config cfg_from_file, *cfg; - -#undef EXTERNC +extern _config *cfg; +extern _config cfg_from_file; #endif /* CONF_H_ */ diff -upr --new-file puNES-0.105.org/src/core/cpu.c puNES-0.105.new/src/core/cpu.c --- puNES-0.105.org/src/core/cpu.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/cpu.c 2020-03-18 11:47:29.361142706 +0100 @@ -560,6 +560,10 @@ static const BYTE table_opcode_cycles[25 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ }; +_cpu cpu; +_irq irq; +_nmi nmi; + void cpu_exe_op(void) { cpu.opcode = FALSE; DMC.tick_type = DMC_NORMAL; diff -upr --new-file puNES-0.105.org/src/core/cpu.h puNES-0.105.new/src/core/cpu.h --- puNES-0.105.org/src/core/cpu.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/cpu.h 2020-03-18 11:47:29.361142706 +0100 @@ -102,16 +102,16 @@ typedef struct _nmi { uint32_t cpu_cycles_from_last_nmi; } _nmi; +extern _cpu cpu; +extern _irq irq; +extern _nmi nmi; + #if defined (__cplusplus) #define EXTERNC extern "C" #else #define EXTERNC #endif -EXTERNC _cpu cpu; -EXTERNC _irq irq; -EXTERNC _nmi nmi; - EXTERNC void cpu_exe_op(void); EXTERNC void cpu_init_PC(void); EXTERNC void cpu_turn_on(void); diff -upr --new-file puNES-0.105.org/src/core/debugger.h puNES-0.105.new/src/core/debugger.h --- puNES-0.105.org/src/core/debugger.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/debugger.h 2020-03-18 11:47:29.362142698 +0100 @@ -23,22 +23,15 @@ enum debugger_mode { DBG_NODBG, DBG_GO, DBG_STEP, DBG_BREAKPOINT, DBG_SLEEP }; -typedef struct _debugger_breakpoint { - -} _debugger_breakpoint; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _debugger { +typedef struct _debugger { BYTE mode; WORD breakpoint; BYTE breakframe; -} debugger; +} _debugger; +typedef struct _debugger_breakpoint { + +} _debugger_breakpoint; -#undef EXTERNC +extern _debugger debugger; #endif /* DEBUGGER_H_ */ diff -upr --new-file puNES-0.105.org/src/core/emu.c puNES-0.105.new/src/core/emu.c --- puNES-0.105.org/src/core/emu.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/emu.c 2020-03-18 11:47:29.362142698 +0100 @@ -16,7 +16,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include #include #include #include @@ -27,39 +26,28 @@ #include "debugger.h" #include "emu.h" #include "rom_mem.h" -#include "info.h" #include "settings.h" #include "audio/snd.h" #include "clock.h" #include "cpu.h" #include "mem_map.h" -#include "mappers.h" -#include "fps.h" -#include "apu.h" #include "ppu.h" #include "video/gfx.h" -#include "text.h" #include "sha1.h" #include "database.h" -#include "input.h" #include "version.h" #include "conf.h" #include "save_slot.h" -#include "rewind.h" #include "tas.h" #include "ines.h" #include "unif.h" #include "fds.h" -#include "nsf.h" #include "nsfe.h" #include "patcher.h" -#include "cheat.h" -#include "overscan.h" #include "recent_roms.h" #if defined (WITH_OPENGL) #include "opengl.h" #endif -#include "uncompress.h" #include "gui.h" #include "video/effects/pause.h" #include "video/effects/tv_noise.h" diff -upr --new-file puNES-0.105.org/src/core/emu.h puNES-0.105.new/src/core/emu.h --- puNES-0.105.org/src/core/emu.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/emu.h 2020-03-18 11:47:29.362142698 +0100 @@ -20,7 +20,6 @@ #define EMU_H_ #include "common.h" -#include "uncompress.h" #define emu_irand(x) ((unsigned int)((x) * emu_drand())) diff -upr --new-file puNES-0.105.org/src/core/external_calls.c puNES-0.105.new/src/core/external_calls.c --- puNES-0.105.org/src/core/external_calls.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/external_calls.c 2020-03-18 11:47:29.362142698 +0100 @@ -18,6 +18,55 @@ #include "external_calls.h" +// viene chiamata dopo il map_init(), map_prg_ram_init() e map_chr_ram_init() +void (*extcl_after_mapper_init)(void); +void (*extcl_cpu_wr_mem)(WORD address, BYTE value); +BYTE (*extcl_cpu_rd_mem)(WORD address, BYTE openbus, BYTE before); +BYTE (*extcl_save_mapper)(BYTE mode, BYTE slot, FILE *fp); +// CPU +void (*extcl_cpu_every_cycle)(void); +// viene chiamata ogni volta si scrive qualcosa nel registro $4016 +void (*extcl_cpu_wr_r4016)(BYTE value); +// PPU +// viene chiamata sempre, ad ogni ciclo della PPU +void (*extcl_ppu_000_to_34x)(void); +// viene chiamata se (!ppu.vblank && (ppu.screen_y < SCR_LINES)) +// quindi per essere sicuri di essere durante il rendering della PPU +// nella funzione devo controllare anche se r2001.visible non e' a zero. +void (*extcl_ppu_000_to_255)(void); +// vengono chiamate solo se la PPU e' in fase di rendering +// (!ppu.vblank && r2001.visible && (ppu.screen_y < SCR_LINES)) +void (*extcl_ppu_256_to_319)(void); +void (*extcl_ppu_320_to_34x)(void); +// viene chiamata ogni volta viene modificato ppu.screen_y +void (*extcl_ppu_update_screen_y)(void); +// viene chiamata dopo ogni cambiamento del $2006 in cpu_inline.h +void (*extcl_update_r2006)(WORD new_r2006, WORD old_r2006); +// viene chiamata alla lettura del $2007 in cpu_inline.h +void (*extcl_rd_r2007)(void); +// vengono chiamate in ppu_inline.h +void (*extcl_rd_ppu)(WORD address); +BYTE (*extcl_rd_nmt)(WORD address); +BYTE (*extcl_rd_chr)(WORD address); +// viene chiamata dopo il FETCHB e dopo il fetch dello sprite +void (*extcl_after_rd_chr)(WORD address); +// viene chiamato quando si tenta di scrivere nella Nametable Ram +void (*extcl_wr_nmt)(WORD address, BYTE value); +// viene chiamato quando si tenta di scrivere nella CHR Ram +void (*extcl_wr_chr)(WORD address, BYTE value); +// APU +void (*extcl_length_clock)(void); +void (*extcl_envelope_clock)(void); +void (*extcl_apu_tick)(void); +// irqA12 +void (*extcl_irq_A12_clock)(void); +// battery +void (*extcl_battery_io)(BYTE mode, FILE *fp); +// snd +void (*extcl_snd_playback_start)(WORD samplarate); +// audio +void (*extcl_audio_samples_mod)(SWORD *samples, int count); + void extcl_init(void) { /* Mappers */ extcl_after_mapper_init = NULL; diff -upr --new-file puNES-0.105.org/src/core/external_calls.h puNES-0.105.new/src/core/external_calls.h --- puNES-0.105.org/src/core/external_calls.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/external_calls.h 2020-03-18 11:47:29.362142698 +0100 @@ -22,17 +22,15 @@ #include #include "common.h" -/* mappers */ +// mappers #define EXTCL_AFTER_MAPPER_INIT(n) extcl_after_mapper_init = extcl_after_mapper_init_##n #define EXTCL_CPU_WR_MEM(n) extcl_cpu_wr_mem = extcl_cpu_wr_mem_##n #define EXTCL_CPU_RD_MEM(n) extcl_cpu_rd_mem = extcl_cpu_rd_mem_##n #define EXTCL_SAVE_MAPPER(n) extcl_save_mapper = extcl_save_mapper_##n - -/* CPU */ +// CPU #define EXTCL_CPU_EVERY_CYCLE(n) extcl_cpu_every_cycle = extcl_cpu_every_cycle_##n #define EXTCL_CPU_WR_R4016(n) extcl_cpu_wr_r4016 = extcl_cpu_wr_r4016_##n - -/* PPU */ +// PPU #define EXTCL_PPU_000_TO_34X(n) extcl_ppu_000_to_34x = extcl_ppu_000_to_34x_##n #define EXTCL_PPU_000_TO_255(n) extcl_ppu_000_to_255 = extcl_ppu_000_to_255_##n #define EXTCL_PPU_256_TO_319(n) extcl_ppu_256_to_319 = extcl_ppu_256_to_319_##n @@ -46,92 +44,68 @@ #define EXTCL_RD_CHR(n) extcl_rd_chr = extcl_rd_chr_##n #define EXTCL_WR_NMT(n) extcl_wr_nmt = extcl_wr_nmt_##n #define EXTCL_WR_CHR(n) extcl_wr_chr = extcl_wr_chr_##n - -/* APU */ +// APU #define EXTCL_LENGTH_CLOCK(n) extcl_length_clock = extcl_length_clock_##n #define EXTCL_ENVELOPE_CLOCK(n) extcl_envelope_clock = extcl_envelope_clock_##n #define EXTCL_APU_TICK(n) extcl_apu_tick = extcl_apu_tick_##n - -/* irqA12 */ +// irqA12 #define EXTCL_IRQ_A12_CLOCK(n) extcl_irq_A12_clock = extcl_irq_A12_clock_##n - -/* battery */ +// battery #define EXTCL_BATTERY_IO(n) extcl_battery_io = extcl_battery_io_##n - -/* snd */ +// snd #define EXTCL_SND_PLAYBACK_START(n) extcl_snd_playback_start = extcl_snd_playback_start_##n -/* audio */ +// audio #define EXTCL_AUDIO_SAMPLES_MOD(n) extcl_audio_samples_mod = extcl_audio_samples_mod_##n -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC void extcl_init(void); - -/* mappers */ -/* viene chiamata dopo il map_init(), map_prg_ram_init() e map_chr_ram_init() */ -EXTERNC void (*extcl_after_mapper_init)(void); -/* */ -EXTERNC void (*extcl_cpu_wr_mem)(WORD address, BYTE value); -EXTERNC BYTE (*extcl_cpu_rd_mem)(WORD address, BYTE openbus, BYTE before); -EXTERNC BYTE (*extcl_save_mapper)(BYTE mode, BYTE slot, FILE *fp); - -/* CPU */ -EXTERNC void (*extcl_cpu_every_cycle)(void); -/* viene chiamata ogni volta si scrive qualcosa nel registro $4016 */ -EXTERNC void (*extcl_cpu_wr_r4016)(BYTE value); - -/* PPU */ -/* viene chiamata sempre, ad ogni ciclo della PPU */ -EXTERNC void (*extcl_ppu_000_to_34x)(void); -/* - * viene chiamata se (!ppu.vblank && (ppu.screen_y < SCR_LINES)) - * quindi per essere sicuri di essere durante il rendering della PPU - * nella funzione devo controllare anche se r2001.visible non e' a zero. - */ -EXTERNC void (*extcl_ppu_000_to_255)(void); -/* - * vengono chiamate solo se la PPU e' in fase di rendering - * (!ppu.vblank && r2001.visible && (ppu.screen_y < SCR_LINES)) - */ -EXTERNC void (*extcl_ppu_256_to_319)(void); -EXTERNC void (*extcl_ppu_320_to_34x)(void); -/* viene chiamata ogni volta viene modificato ppu.screen_y */ -EXTERNC void (*extcl_ppu_update_screen_y)(void); -/* viene chiamata dopo ogni cambiamento del $2006 in cpu_inline.h */ -EXTERNC void (*extcl_update_r2006)(WORD new_r2006, WORD old_r2006); -/* viene chiamata alla lettura del $2007 in cpu_inline.h */ -EXTERNC void (*extcl_rd_r2007)(void); -/* vengono chiamate in ppu_inline.h */ -EXTERNC void (*extcl_rd_ppu)(WORD address); -EXTERNC BYTE (*extcl_rd_nmt)(WORD address); -EXTERNC BYTE (*extcl_rd_chr)(WORD address); -/* viene chiamata dopo il FETCHB e dopo il fetch dello sprite */ -EXTERNC void (*extcl_after_rd_chr)(WORD address); -/* viene chiamato quando si tenta di scrivere nella Nametable Ram */ -EXTERNC void (*extcl_wr_nmt)(WORD address, BYTE value); -/* viene chiamato quando si tenta di scrivere nella CHR Ram */ -EXTERNC void (*extcl_wr_chr)(WORD address, BYTE value); - -/* APU */ -EXTERNC void (*extcl_length_clock)(void); -EXTERNC void (*extcl_envelope_clock)(void); -EXTERNC void (*extcl_apu_tick)(void); - -/* irqA12 */ -EXTERNC void (*extcl_irq_A12_clock)(void); - -/* battery */ -EXTERNC void (*extcl_battery_io)(BYTE mode, FILE *fp); - -/* snd */ -EXTERNC void (*extcl_snd_playback_start)(WORD samplarate); -/* audio */ -EXTERNC void (*extcl_audio_samples_mod)(SWORD *samples, int count); +// viene chiamata dopo il map_init(), map_prg_ram_init() e map_chr_ram_init() +extern void (*extcl_after_mapper_init)(void); +extern void (*extcl_cpu_wr_mem)(WORD address, BYTE value); +extern BYTE (*extcl_cpu_rd_mem)(WORD address, BYTE openbus, BYTE before); +extern BYTE (*extcl_save_mapper)(BYTE mode, BYTE slot, FILE *fp); +// CPU +extern void (*extcl_cpu_every_cycle)(void); +// viene chiamata ogni volta si scrive qualcosa nel registro $4016 +extern void (*extcl_cpu_wr_r4016)(BYTE value); +// PPU +// viene chiamata sempre, ad ogni ciclo della PPU +extern void (*extcl_ppu_000_to_34x)(void); +// viene chiamata se (!ppu.vblank && (ppu.screen_y < SCR_LINES)) +// quindi per essere sicuri di essere durante il rendering della PPU +// nella funzione devo controllare anche se r2001.visible non e' a zero. +extern void (*extcl_ppu_000_to_255)(void); +// vengono chiamate solo se la PPU e' in fase di rendering +// (!ppu.vblank && r2001.visible && (ppu.screen_y < SCR_LINES)) +extern void (*extcl_ppu_256_to_319)(void); +extern void (*extcl_ppu_320_to_34x)(void); +// viene chiamata ogni volta viene modificato ppu.screen_y +extern void (*extcl_ppu_update_screen_y)(void); +// viene chiamata dopo ogni cambiamento del $2006 in cpu_inline.h +extern void (*extcl_update_r2006)(WORD new_r2006, WORD old_r2006); +// viene chiamata alla lettura del $2007 in cpu_inline.h +extern void (*extcl_rd_r2007)(void); +// vengono chiamate in ppu_inline.h +extern void (*extcl_rd_ppu)(WORD address); +extern BYTE (*extcl_rd_nmt)(WORD address); +extern BYTE (*extcl_rd_chr)(WORD address); +// viene chiamata dopo il FETCHB e dopo il fetch dello sprite +extern void (*extcl_after_rd_chr)(WORD address); +// viene chiamato quando si tenta di scrivere nella Nametable Ram +extern void (*extcl_wr_nmt)(WORD address, BYTE value); +// viene chiamato quando si tenta di scrivere nella CHR Ram +extern void (*extcl_wr_chr)(WORD address, BYTE value); +// APU +extern void (*extcl_length_clock)(void); +extern void (*extcl_envelope_clock)(void); +extern void (*extcl_apu_tick)(void); +// irqA12 +extern void (*extcl_irq_A12_clock)(void); +// battery +extern void (*extcl_battery_io)(BYTE mode, FILE *fp); +// snd +extern void (*extcl_snd_playback_start)(WORD samplarate); +// audio +extern void (*extcl_audio_samples_mod)(SWORD *samples, int count); -#undef EXTERNC +void extcl_init(void); #endif /* EXTERNAL_CALLS_H_ */ diff -upr --new-file puNES-0.105.org/src/core/fds.c puNES-0.105.new/src/core/fds.c --- puNES-0.105.org/src/core/fds.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/fds.c 2020-03-18 11:47:29.362142698 +0100 @@ -42,6 +42,8 @@ typedef struct _fds_diff_ele { uint32_t position; } _fds_diff_ele; +_fds fds; + void fds_init(void) { memset(&fds, 0x00, sizeof(fds)); diff -upr --new-file puNES-0.105.org/src/core/fds.h puNES-0.105.new/src/core/fds.h --- puNES-0.105.org/src/core/fds.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/fds.h 2020-03-18 11:47:29.362142698 +0100 @@ -50,13 +50,7 @@ enum fds_misc { FDS_DISK_CRC_CHAR2 = 0x01AA }; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _fds { +typedef struct _fds { // generali struct _fds_info { BYTE enabled; @@ -185,7 +179,15 @@ EXTERNC struct _fds { SWORD mod; } modulation; } snd; -} fds; +} _fds; + +extern _fds fds; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void fds_init(void); EXTERNC void fds_quit(void); diff -upr --new-file puNES-0.105.org/src/core/fps.c puNES-0.105.new/src/core/fps.c --- puNES-0.105.org/src/core/fps.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/fps.c 2020-03-18 11:47:29.362142698 +0100 @@ -22,6 +22,8 @@ #include "conf.h" #include "ppu.h" +_fps fps; + void fps_init(void) { if (machine.type == NTSC) { machine.fps = 60; diff -upr --new-file puNES-0.105.org/src/core/fps.h puNES-0.105.new/src/core/fps.h --- puNES-0.105.org/src/core/fps.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/fps.h 2020-03-18 11:47:29.362142698 +0100 @@ -26,13 +26,7 @@ enum ff_velocity_values { FF_2X = 2, FF_ #define fps_machine_ms(factor)\ machine.ms_frame = fps.frame.estimated_ms = (1000.0f / (double)machine.fps) * factor; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _fps { +typedef struct _fps { double gfx; uint8_t fast_forward; uint32_t frames_skipped; @@ -41,7 +35,15 @@ EXTERNC struct _fps { double estimated_ms; double expected_end; } frame; -} fps; +} _fps; + +extern _fps fps; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void fps_init(void); EXTERNC void fps_fast_forward(void); diff -upr --new-file puNES-0.105.org/src/core/ines.c puNES-0.105.new/src/core/ines.c --- puNES-0.105.org/src/core/ines.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/ines.c 2020-03-18 11:47:29.362142698 +0100 @@ -35,6 +35,8 @@ void nes20_submapper(void); BYTE nes20_ram_size(BYTE mode); +_ines ines; + BYTE ines_load_rom(void) { _rom_mem rom; BYTE tmp; diff -upr --new-file puNES-0.105.org/src/core/ines.h puNES-0.105.new/src/core/ines.h --- puNES-0.105.org/src/core/ines.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/ines.h 2020-03-18 11:47:29.362142698 +0100 @@ -23,9 +23,11 @@ enum ines_flags { FL6, FL7, FL8, FL9, FL10, FL11, FL12, FL13, FL14, FL15, TOTAL_FL }; -struct _ines { +typedef struct _ines { BYTE flags[TOTAL_FL]; -} ines; +} _ines; + +extern _ines ines; BYTE ines_load_rom(void); diff -upr --new-file puNES-0.105.org/src/core/info.h puNES-0.105.new/src/core/info.h --- puNES-0.105.org/src/core/info.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/info.h 2020-03-18 11:47:29.362142698 +0100 @@ -37,14 +37,7 @@ typedef struct _info_sh1sum { char string[41]; } chr; } _info_sh1sum; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _info { +typedef struct _info { uTCHAR base_folder[LENGTH_FILE_NAME_MID]; struct _info_rom { uTCHAR file[LENGTH_FILE_NAME_LONG]; @@ -134,8 +127,8 @@ EXTERNC struct _info { #if !defined (RELEASE) BYTE snd_info; #endif -} info; +} _info; -#undef EXTERNC +extern _info info; #endif /* INFO_H_ */ diff -upr --new-file puNES-0.105.org/src/core/input/arkanoid.h puNES-0.105.new/src/core/input/arkanoid.h --- puNES-0.105.org/src/core/input/arkanoid.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/arkanoid.h 2020-03-18 11:47:29.362142698 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_ARKANOID_H #define INPUT_ARKANOID_H -#include "../input.h" +#include "input.h" void input_init_arkanoid(void); void input_wr_arkanoid(BYTE *value, BYTE nport); diff -upr --new-file puNES-0.105.org/src/core/input/famicom.h puNES-0.105.new/src/core/input/famicom.h --- puNES-0.105.org/src/core/input/famicom.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/famicom.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_FAMICON_H_ #define INPUT_FAMICON_H_ -#include "../input.h" +#include "input.h" BYTE input_wr_reg_famicom(BYTE value); BYTE input_rd_reg_famicom_r4016(BYTE openbus, BYTE nport); diff -upr --new-file puNES-0.105.org/src/core/input/four_score.h puNES-0.105.new/src/core/input/four_score.h --- puNES-0.105.org/src/core/input/four_score.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/four_score.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_FOUR_SCORE_H #define INPUT_FOUR_SCORE_H -#include "../input.h" +#include "input.h" void input_init_four_score(void); BYTE input_wr_reg_four_score(BYTE value); diff -upr --new-file puNES-0.105.org/src/core/input/mouse.h puNES-0.105.new/src/core/input/mouse.h --- puNES-0.105.org/src/core/input/mouse.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/mouse.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,6 @@ #ifndef INPUT_MOUSE_H_ #define INPUT_MOUSE_H_ -#include "../input.h" #include "gui.h" #include "video/gfx.h" diff -upr --new-file puNES-0.105.org/src/core/input/nes_001.h puNES-0.105.new/src/core/input/nes_001.h --- puNES-0.105.org/src/core/input/nes_001.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/nes_001.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_NES_001_H #define INPUT_NES_001_H -#include "../input.h" +#include "input.h" BYTE input_wr_reg_nes_001(BYTE value); BYTE input_rd_reg_nes_001(BYTE openbus, BYTE nport); diff -upr --new-file puNES-0.105.org/src/core/input/nsf_controller.h puNES-0.105.new/src/core/input/nsf_controller.h --- puNES-0.105.org/src/core/input/nsf_controller.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/nsf_controller.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef NSF_CONTROLLER_H_ #define NSF_CONTROLLER_H_ -#include "../input.h" +#include "input.h" void input_add_event_nsf_controller(BYTE index); BYTE input_decode_event_nsf_controller(BYTE mode, BYTE autorepeat, DBWORD event, BYTE type, _port *port); diff -upr --new-file puNES-0.105.org/src/core/input/nsf_mouse.c puNES-0.105.new/src/core/input/nsf_mouse.c --- puNES-0.105.org/src/core/input/nsf_mouse.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/nsf_mouse.c 2020-03-18 11:47:29.363142690 +0100 @@ -20,7 +20,6 @@ #include "input/nsf_mouse.h" #include "input/mouse.h" #include "conf.h" -#include "gui.h" #include "nsf.h" struct _nsf_mouse { diff -upr --new-file puNES-0.105.org/src/core/input/nsf_mouse.h puNES-0.105.new/src/core/input/nsf_mouse.h --- puNES-0.105.org/src/core/input/nsf_mouse.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/nsf_mouse.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef NSF_MOUSE_H_ #define NSF_MOUSE_H_ -#include "../input.h" +#include "input.h" void input_init_nsf_mouse(void); void input_add_event_nsf_mouse(BYTE index); diff -upr --new-file puNES-0.105.org/src/core/input/oeka_kids_tablet.h puNES-0.105.new/src/core/input/oeka_kids_tablet.h --- puNES-0.105.org/src/core/input/oeka_kids_tablet.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/oeka_kids_tablet.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_OEKA_KIDS_TABLET_H_ #define INPUT_OEKA_KIDS_TABLET_H_ -#include "../input.h" +#include "input.h" void input_init_oeka_kids_tablet(void); void input_wr_oeka_kids_tablet(BYTE *value, BYTE nport); diff -upr --new-file puNES-0.105.org/src/core/input/snes_mouse.h puNES-0.105.new/src/core/input/snes_mouse.h --- puNES-0.105.org/src/core/input/snes_mouse.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/snes_mouse.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_SNES_MOUSE_H_ #define INPUT_SNES_MOUSE_H_ -#include "../input.h" +#include "input.h" void input_init_snes_mouse(void); void input_wr_snes_mouse(BYTE *value, BYTE nport); diff -upr --new-file puNES-0.105.org/src/core/input/standard_controller.h puNES-0.105.new/src/core/input/standard_controller.h --- puNES-0.105.org/src/core/input/standard_controller.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/standard_controller.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_STANDARD_CONTROLLER_H_ #define INPUT_STANDARD_CONTROLLER_H_ -#include "../input.h" +#include "input.h" void input_wr_standard_controller(BYTE *value, BYTE nport); void input_rd_standard_controller(BYTE *value, BYTE nport, BYTE shift); diff -upr --new-file puNES-0.105.org/src/core/input/vs.h puNES-0.105.new/src/core/input/vs.h --- puNES-0.105.org/src/core/input/vs.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/vs.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_VS_H #define INPUT_VS_H -#include "../input.h" +#include "input.h" BYTE input_wr_reg_vs(BYTE value); BYTE input_rd_reg_vs_r4016(BYTE openbus, BYTE nport); diff -upr --new-file puNES-0.105.org/src/core/input/zapper.c puNES-0.105.new/src/core/input/zapper.c --- puNES-0.105.org/src/core/input/zapper.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/zapper.c 2020-03-18 11:47:29.363142690 +0100 @@ -25,6 +25,7 @@ #include "vs_system.h" #include "input/mouse.h" #include "tas.h" +#include "palette.h" struct _zapper { BYTE data; diff -upr --new-file puNES-0.105.org/src/core/input/zapper.h puNES-0.105.new/src/core/input/zapper.h --- puNES-0.105.org/src/core/input/zapper.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input/zapper.h 2020-03-18 11:47:29.363142690 +0100 @@ -19,7 +19,7 @@ #ifndef INPUT_ZAPPER_H_ #define INPUT_ZAPPER_H_ -#include "../input.h" +#include "input.h" void input_init_zapper(void); void input_rd_zapper(BYTE *value, BYTE nport, BYTE shift); diff -upr --new-file puNES-0.105.org/src/core/input.c puNES-0.105.new/src/core/input.c --- puNES-0.105.org/src/core/input.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input.c 2020-03-18 11:47:29.362142698 +0100 @@ -17,7 +17,6 @@ */ #include -#include "input.h" #include "clock.h" #include "video/gfx.h" #include "info.h" @@ -45,6 +44,13 @@ #define SET_DECODE_EVENT(id, funct) port_funct[id].input_decode_event = funct #define SET_ADD_EVENT(id, funct) port_funct[id].input_add_event = funct +_r4016 r4016; +_port port[PORT_MAX]; +_port_funct port_funct[PORT_MAX]; + +BYTE (*input_wr_reg)(BYTE value); +BYTE (*input_rd_reg[2])(BYTE openbus, BYTE nport); + void input_init(BYTE set_cursor) { BYTE a; diff -upr --new-file puNES-0.105.org/src/core/input.h puNES-0.105.new/src/core/input.h --- puNES-0.105.org/src/core/input.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/input.h 2020-03-18 11:47:29.362142698 +0100 @@ -111,16 +111,19 @@ typedef struct _port_funct { BYTE (*input_decode_event)(BYTE mode, BYTE autorepeat, DBWORD event, BYTE type, _port *port); } _port_funct; +extern _r4016 r4016; +extern _port port[PORT_MAX]; +extern _port_funct port_funct[PORT_MAX]; + +extern BYTE (*input_wr_reg)(BYTE value); +extern BYTE (*input_rd_reg[2])(BYTE openbus, BYTE nport); + #if defined (__cplusplus) #define EXTERNC extern "C" #else #define EXTERNC #endif -EXTERNC _r4016 r4016; -EXTERNC _port port[PORT_MAX]; -EXTERNC _port_funct port_funct[PORT_MAX]; - EXTERNC void input_init(BYTE set_cursor); EXTERNC void input_wr_disabled(BYTE *value, BYTE nport); @@ -128,9 +131,6 @@ EXTERNC void input_rd_disabled(BYTE *val EXTERNC BYTE input_draw_target(); -EXTERNC BYTE (*input_wr_reg)(BYTE value); -EXTERNC BYTE (*input_rd_reg[2])(BYTE openbus, BYTE nport); - #undef EXTERNC #endif /* INPUT_H_ */ diff -upr --new-file puNES-0.105.org/src/core/input.h.orig puNES-0.105.new/src/core/input.h.orig --- puNES-0.105.org/src/core/input.h.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/input.h.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef INPUT_H_ +#define INPUT_H_ + +#if defined (_WIN32) +#define INITGUID +#include +#undef INITGUID +#endif +#include "common.h" + +#define TURBO_BUTTON_DELAY_DEFAULT 1 +#define TURBO_BUTTON_DELAY_MAX 20 + +enum controller_modes { CTRL_MODE_NES, CTRL_MODE_FAMICOM, CTRL_MODE_FOUR_SCORE }; +enum controller_types { + CTRL_DISABLED, + CTRL_STANDARD, + CTRL_ZAPPER, + CTRL_SNES_MOUSE, + CTRL_ARKANOID_PADDLE, + CTRL_OEKA_KIDS_TABLET +}; +enum pad_types { CTRL_PAD_AUTO, CTRL_PAD_ORIGINAL, CTRL_PAD_3RD_PARTY }; +enum controller_buttons { + BUT_A, + BUT_B, + SELECT, + START, + UP, + DOWN, + LEFT, + RIGHT, + TRB_A, + TRB_B, + MAX_STD_PAD_BUTTONS +}; +enum turbo_buttons { TURBOA, TURBOB }; +enum input_types { KEYBOARD, JOYSTICK }; +enum button_states { RELEASED = 0x00, PRESSED = 0x01 }; +enum input_max_values { MAX_JOYSTICK = 16 }; +enum input_set_cursor { NO_SET_CURSOR = FALSE, SET_CURSOR = TRUE}; +enum port_controllers { + PORT1, + PORT2, + PORT_BASE, + PORT3 = PORT_BASE, + PORT4, + PORT_MAX +}; + +typedef struct _config_input { + BYTE permit_updown_leftright; + BYTE hide_zapper_cursor; + BYTE controller_mode; + BYTE expansion; +#if defined (_WIN32) + GUID shcjoy_id; +#else + BYTE shcjoy_id; +#endif +} _config_input; +typedef struct _r4016 { + BYTE value; +} _r4016; +typedef struct _turbo_button { + BYTE frequency; + BYTE active; + BYTE counter; +} _turbo_button; +typedef struct _port { + BYTE type; +#if defined (_WIN32) + GUID joy_id; +#else + BYTE joy_id; +#endif + + // standard controller + BYTE type_pad; + BYTE index; + BYTE data[24]; + DBWORD input[2][24]; + // turbo buttons + _turbo_button turbo[2]; +} _port; +typedef struct _array_pointers_port { + _port *port[PORT_MAX]; +} _array_pointers_port; +typedef struct _port_funct { + void (*input_wr)(BYTE *value, BYTE nport); + void (*input_rd)(BYTE *value, BYTE nport, BYTE shift); + void (*input_add_event)(BYTE index); + BYTE (*input_decode_event)(BYTE mode, BYTE autorepeat, DBWORD event, BYTE type, _port *port); +} _port_funct; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + +EXTERNC _r4016 r4016; +EXTERNC _port port[PORT_MAX]; +EXTERNC _port_funct port_funct[PORT_MAX]; + +EXTERNC void input_init(BYTE set_cursor); + +EXTERNC void input_wr_disabled(BYTE *value, BYTE nport); +EXTERNC void input_rd_disabled(BYTE *value, BYTE nport, BYTE shift); + +EXTERNC BYTE input_draw_target(); + +EXTERNC BYTE (*input_wr_reg)(BYTE value); +EXTERNC BYTE (*input_rd_reg[2])(BYTE openbus, BYTE nport); + +#undef EXTERNC + +#endif /* INPUT_H_ */ diff -upr --new-file puNES-0.105.org/src/core/irqA12.c puNES-0.105.new/src/core/irqA12.c --- puNES-0.105.org/src/core/irqA12.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/irqA12.c 2020-03-18 11:47:29.363142690 +0100 @@ -20,6 +20,9 @@ #include "ppu_inline.h" #include "irqA12.h" +_irqA12 irqA12; +BYTE irqA12_delay; + void irqA12_IO(WORD value, WORD value_old) { if (!(value_old & 0x1000) && (value & 0x1000)) { if (irqA12.cycles > irqA12_min_cpu_cycles_prev_rising_edge) { diff -upr --new-file puNES-0.105.org/src/core/irqA12.h puNES-0.105.new/src/core/irqA12.h --- puNES-0.105.org/src/core/irqA12.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/irqA12.h 2020-03-18 11:47:29.363142690 +0100 @@ -82,7 +82,7 @@ enum irqA12_misc_value { irqA12_min_cpu_cycles_prev_rising_edge = 18 }; -typedef struct { +typedef struct _irqA12 { BYTE present; BYTE delay; BYTE counter; @@ -104,9 +104,9 @@ typedef struct { } race; } _irqA12; -_irqA12 irqA12; +extern _irqA12 irqA12; /* questo non e' necessario salvarlo */ -BYTE irqA12_delay; +extern BYTE irqA12_delay; void irqA12_IO(WORD value, WORD value_old); void irqA12_BS(void); diff -upr --new-file puNES-0.105.org/src/core/irql2f.c puNES-0.105.new/src/core/irql2f.c --- puNES-0.105.org/src/core/irql2f.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/irql2f.c 2020-03-18 11:47:29.363142690 +0100 @@ -18,6 +18,8 @@ #include "irql2f.h" +_irql2f irql2f; + void irql2f_tick(void) { if (irql2f.frame_x != ppu.frame_x) { return; diff -upr --new-file puNES-0.105.org/src/core/irql2f.h puNES-0.105.new/src/core/irql2f.h --- puNES-0.105.org/src/core/irql2f.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/irql2f.h 2020-03-18 11:47:29.363142690 +0100 @@ -27,7 +27,7 @@ enum { IRQL2F_PENDING = 0x80 }; -typedef struct { +typedef struct _irql2f { BYTE present; BYTE enable; BYTE counter; @@ -38,7 +38,7 @@ typedef struct { BYTE pending; } _irql2f; -_irql2f irql2f; +extern _irql2f irql2f; void irql2f_tick(void); diff -upr --new-file puNES-0.105.org/src/core/main.c puNES-0.105.new/src/core/main.c --- puNES-0.105.org/src/core/main.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/main.c 2020-03-18 11:47:29.363142690 +0100 @@ -20,21 +20,15 @@ #include #include #include "main.h" -#include "debugger.h" +#include "compilation_unit_orphan.h" #include "../gui/cmd_line.h" #include "emu.h" #include "emu_thread.h" -#include "info.h" #include "settings.h" -#include "mem_map.h" #include "video/gfx.h" -#include "text.h" -#include "conf.h" #include "version.h" -#include "gui.h" #include "cheat.h" #include "recent_roms.h" -#include "uncompress.h" #include "patcher.h" #include "ppu.h" diff -upr --new-file puNES-0.105.org/src/core/Makefile.am puNES-0.105.new/src/core/Makefile.am --- puNES-0.105.org/src/core/Makefile.am 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/Makefile.am 2020-03-18 11:46:27.358649291 +0100 @@ -7,6 +7,7 @@ libcore_a_SOURCES = \ cheat.h \ clock.h \ common.h \ + compilation_unit_orphan.h \ conf.h \ cpu.c \ cpu.h \ diff -upr --new-file puNES-0.105.org/src/core/Makefile.am.orig puNES-0.105.new/src/core/Makefile.am.orig --- puNES-0.105.org/src/core/Makefile.am.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/Makefile.am.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,488 @@ +noinst_LIBRARIES = libcore.a +libcore_a_SOURCES = \ + apu.c \ + apu.h \ + build.h \ + cheat.c \ + cheat.h \ + clock.h \ + common.h \ + conf.h \ + cpu.c \ + cpu.h \ + cpu_inline.h \ + database.h \ + debugger.h \ + draw_on_screen.h \ + draw_on_screen.c \ + emu.c \ + emu.h \ + emu_thread.c \ + emu_thread.h \ + external_calls.c \ + external_calls.h \ + fds.c \ + fds.h \ + font.h \ + fps.c \ + fps.h \ + gui.h \ + ines.c \ + ines.h \ + info.h \ + input.c \ + input.h \ + irqA12.c \ + irqA12.h \ + irql2f.c \ + irql2f.h \ + main.h \ + mappers.c \ + mappers.h \ + mem_map.h \ + miniz.h \ + nsf.c \ + nsf.h \ + nsfe.c \ + nsfe.h \ + overscan.c \ + overscan.h \ + patcher.c \ + patcher.h \ + patcher_xdelta3_wrap.c \ + patcher_xdelta3_wrap.h \ + paldef.h \ + palette.h \ + ppu.c \ + ppu.h \ + ppu_inline.h \ + rewind.c \ + rewind.h \ + rom_mem.c \ + rom_mem.h \ + save_slot.c \ + save_slot.h \ + sha1.c \ + sha1.h \ + text.c \ + text.h \ + uncompress.c \ + uncompress.h \ + uncompress_selection.h \ + unif.c \ + unif.h \ + version.h\ + vs_system.h + +libcore_a_SOURCES += \ + input/arkanoid.h \ + input/arkanoid.c \ + input/famicom.h \ + input/famicom.c \ + input/four_score.h \ + input/four_score.c \ + input/mouse.h \ + input/nes_001.h \ + input/nes_001.c \ + input/nsf_controller.h \ + input/nsf_controller.c \ + input/nsf_mouse.h \ + input/nsf_mouse.c \ + input/oeka_kids_tablet.h \ + input/oeka_kids_tablet.c \ + input/snes_mouse.h \ + input/snes_mouse.c \ + input/standard_controller.h \ + input/standard_controller.c \ + input/vs.h \ + input/vs.c \ + input/zapper.h \ + input/zapper.c + +libcore_a_SOURCES += \ + ../extra/kiss_fft130/kiss_fft.c \ + ../extra/kiss_fft130/_kiss_fft_guts.h \ + ../extra/kiss_fft130/kiss_fft.h + +libcore_a_SOURCES += \ + mappers/mapper_0.c \ + mappers/mapper_0.h \ + mappers/mapper_105.c \ + mappers/mapper_105.h \ + mappers/mapper_114.c \ + mappers/mapper_114.h \ + mappers/mapper_116.c \ + mappers/mapper_116.h \ + mappers/mapper_120.c \ + mappers/mapper_120.h \ + mappers/mapper_121.c \ + mappers/mapper_121.h \ + mappers/mapper_134.c \ + mappers/mapper_134.h \ + mappers/mapper_156.c \ + mappers/mapper_156.h \ + mappers/mapper_163.c \ + mappers/mapper_163.h \ + mappers/mapper_164.c \ + mappers/mapper_164.h \ + mappers/mapper_166.c \ + mappers/mapper_166.h \ + mappers/mapper_167.c \ + mappers/mapper_167.h \ + mappers/mapper_168.c \ + mappers/mapper_168.h \ + mappers/mapper_176.c \ + mappers/mapper_176.h \ + mappers/mapper_178.c \ + mappers/mapper_178.h \ + mappers/mapper_182.c \ + mappers/mapper_182.h \ + mappers/mapper_183.c \ + mappers/mapper_183.h \ + mappers/mapper_186.c \ + mappers/mapper_186.h \ + mappers/mapper_187.c \ + mappers/mapper_187.h \ + mappers/mapper_188.c \ + mappers/mapper_188.h \ + mappers/mapper_190.c \ + mappers/mapper_190.h \ + mappers/mapper_196.c \ + mappers/mapper_196.h \ + mappers/mapper_197.c \ + mappers/mapper_197.h \ + mappers/mapper_200.c \ + mappers/mapper_200.h \ + mappers/mapper_201.c \ + mappers/mapper_201.h \ + mappers/mapper_202.c \ + mappers/mapper_202.h \ + mappers/mapper_203.c \ + mappers/mapper_203.h \ + mappers/mapper_204.c \ + mappers/mapper_204.h \ + mappers/mapper_205.c \ + mappers/mapper_205.h \ + mappers/mapper_208.c \ + mappers/mapper_208.h \ + mappers/mapper_212.c \ + mappers/mapper_212.h \ + mappers/mapper_213.c \ + mappers/mapper_213.h \ + mappers/mapper_214.c \ + mappers/mapper_214.h \ + mappers/mapper_215.c \ + mappers/mapper_215.h \ + mappers/mapper_217.c \ + mappers/mapper_217.h \ + mappers/mapper_219.c \ + mappers/mapper_219.h \ + mappers/mapper_221.c \ + mappers/mapper_221.h \ + mappers/mapper_222.c \ + mappers/mapper_222.h \ + mappers/mapper_225.c \ + mappers/mapper_225.h \ + mappers/mapper_226.c \ + mappers/mapper_226.h \ + mappers/mapper_227.c \ + mappers/mapper_227.h \ + mappers/mapper_229.c \ + mappers/mapper_229.h \ + mappers/mapper_230.c \ + mappers/mapper_230.h \ + mappers/mapper_231.c \ + mappers/mapper_231.h \ + mappers/mapper_233.c \ + mappers/mapper_233.h \ + mappers/mapper_235.c \ + mappers/mapper_235.h \ + mappers/mapper_240.c \ + mappers/mapper_240.h \ + mappers/mapper_241.c \ + mappers/mapper_241.h \ + mappers/mapper_242.c \ + mappers/mapper_242.h \ + mappers/mapper_244.c \ + mappers/mapper_244.h \ + mappers/mapper_246.c \ + mappers/mapper_246.h \ + mappers/mapper_249.c \ + mappers/mapper_249.h \ + mappers/mapper_250.c \ + mappers/mapper_250.h \ + mappers/mapper_252.c \ + mappers/mapper_252.h \ + mappers/mapper_253.c \ + mappers/mapper_253.h \ + mappers/mapper_254.c \ + mappers/mapper_254.h \ + mappers/mapper_28.c \ + mappers/mapper_28.h \ + mappers/mapper_31.c \ + mappers/mapper_31.h \ + mappers/mapper_36.c \ + mappers/mapper_36.h \ + mappers/mapper_37.c \ + mappers/mapper_37.h \ + mappers/mapper_40.c \ + mappers/mapper_40.h \ + mappers/mapper_42.c \ + mappers/mapper_42.h \ + mappers/mapper_43.c \ + mappers/mapper_43.h \ + mappers/mapper_44.c \ + mappers/mapper_44.h \ + mappers/mapper_45.c \ + mappers/mapper_45.h \ + mappers/mapper_46.c \ + mappers/mapper_46.h \ + mappers/mapper_47.c \ + mappers/mapper_47.h \ + mappers/mapper_49.c \ + mappers/mapper_49.h \ + mappers/mapper_50.c \ + mappers/mapper_50.h \ + mappers/mapper_51.c \ + mappers/mapper_51.h \ + mappers/mapper_52.c \ + mappers/mapper_52.h \ + mappers/mapper_53.c \ + mappers/mapper_53.h \ + mappers/mapper_57.c \ + mappers/mapper_57.h \ + mappers/mapper_58.c \ + mappers/mapper_58.h \ + mappers/mapper_60.c \ + mappers/mapper_60.h \ + mappers/mapper_61.c \ + mappers/mapper_61.h \ + mappers/mapper_62.c \ + mappers/mapper_62.h \ + mappers/mapper_74x138x161.c \ + mappers/mapper_74x138x161.h \ + mappers/mapper_74x161x161x32.c \ + mappers/mapper_74x161x161x32.h \ + mappers/mapper_8_IN_1.c \ + mappers/mapper_8_IN_1.h \ + mappers/mapper_83.c \ + mappers/mapper_83.h \ + mappers/mapper_90_209_211.c \ + mappers/mapper_90_209_211.h \ + mappers/mapper_91.c \ + mappers/mapper_91.h \ + mappers/mapper_A65AS.c \ + mappers/mapper_A65AS.h \ + mappers/mapper_AC08.c \ + mappers/mapper_AC08.h \ + mappers/mapper_Active.c \ + mappers/mapper_Active.h \ + mappers/mapper_Agci.c \ + mappers/mapper_Agci.h \ + mappers/mapper_Ave.c \ + mappers/mapper_Ave.h \ + mappers/mapper_AX5705.c \ + mappers/mapper_AX5705.h \ + mappers/mapper_AxROM.c \ + mappers/mapper_AxROM.h \ + mappers/mapper_Bandai.c \ + mappers/mapper_Bandai.h \ + mappers/mapper_BB.c \ + mappers/mapper_BB.h \ + mappers/mapper_BMC11160.c \ + mappers/mapper_BMC11160.h \ + mappers/mapper_BMC12IN1.c \ + mappers/mapper_BMC12IN1.h \ + mappers/mapper_BMC411120C.c \ + mappers/mapper_BMC411120C.h \ + mappers/mapper_BMC70IN1.c \ + mappers/mapper_BMC70IN1.h \ + mappers/mapper_BMC830118C.c \ + mappers/mapper_BMC830118C.h \ + mappers/mapper_BMCFK23C.c \ + mappers/mapper_BMCFK23C.h \ + mappers/mapper_BMCG146.c \ + mappers/mapper_BMCG146.h \ + mappers/mapper_BMCGhostbusters63in1.c \ + mappers/mapper_BMCGhostbusters63in1.h \ + mappers/mapper_BMCHP898F.c \ + mappers/mapper_BMCHP898F.h \ + mappers/mapper_BMC64IN1NOREPEAT.c \ + mappers/mapper_BMC64IN1NOREPEAT.h \ + mappers/mapper_BMC810544CA1.c \ + mappers/mapper_BMC810544CA1.h \ + mappers/mapper_BMCNTD03.c \ + mappers/mapper_BMCNTD03.h \ + mappers/mapper_BOY.c \ + mappers/mapper_BOY.h \ + mappers/mapper_BS5.c \ + mappers/mapper_BS5.h \ + mappers/mapper_BxROM.c \ + mappers/mapper_BxROM.h \ + mappers/mapper_Caltron.c \ + mappers/mapper_Caltron.h \ + mappers/mapper_Camerica.c \ + mappers/mapper_Camerica.h \ + mappers/mapper_CC_21.c \ + mappers/mapper_CC_21.h \ + mappers/mapper_CITYFIGHT.c \ + mappers/mapper_CITYFIGHT.h \ + mappers/mapper_CNROM.c \ + mappers/mapper_CNROM.h \ + mappers/mapper_ColorDreams.c \ + mappers/mapper_ColorDreams.h \ + mappers/mapper_CPROM.c \ + mappers/mapper_CPROM.h \ + mappers/mapper_DRAGONFIGHTER.c \ + mappers/mapper_DRAGONFIGHTER.h \ + mappers/mapper_DREAMTECH01.c \ + mappers/mapper_DREAMTECH01.h \ + mappers/mapper_EDU2000.c \ + mappers/mapper_EDU2000.h \ + mappers/mapper_EH8813A.c \ + mappers/mapper_EH8813A.h \ + mappers/mapper_FDS.c \ + mappers/mapper_FDS.h \ + mappers/mapper_Futuremedia.c \ + mappers/mapper_Futuremedia.h \ + mappers/mapper_FS304.c \ + mappers/mapper_FS304.h \ + mappers/mapper_GameGenie.c \ + mappers/mapper_GameGenie.h \ + mappers/mapper_GxROM.c \ + mappers/mapper_GxROM.h \ + mappers/mapper_GS_2004.c \ + mappers/mapper_GS_2004.h \ + mappers/mapper_GS_2013.c \ + mappers/mapper_GS_2013.h \ + mappers/mapper_H2288.c \ + mappers/mapper_H2288.h \ + mappers/mapper_Hen.c \ + mappers/mapper_Hen.h \ + mappers/mapper_Hes.c \ + mappers/mapper_Hes.h \ + mappers/mapper_Irem.c \ + mappers/mapper_Irem.h \ + mappers/mapper_Jaleco.c \ + mappers/mapper_Jaleco.h \ + mappers/mapper_Kaiser.c \ + mappers/mapper_Kaiser.h \ + mappers/mapper_Kasing.c \ + mappers/mapper_Kasing.h \ + mappers/mapper_KOF97.c \ + mappers/mapper_KOF97.h \ + mappers/mapper_KS7012.c \ + mappers/mapper_KS7012.h \ + mappers/mapper_KS7013B.c \ + mappers/mapper_KS7013B.h \ + mappers/mapper_KS7016.c \ + mappers/mapper_KS7016.h \ + mappers/mapper_KS7017.c \ + mappers/mapper_KS7017.h \ + mappers/mapper_KS7031.c \ + mappers/mapper_KS7031.h \ + mappers/mapper_KS7032.c \ + mappers/mapper_KS7032.h \ + mappers/mapper_KS7037.c \ + mappers/mapper_KS7037.h \ + mappers/mapper_KS7057.c \ + mappers/mapper_KS7057.h \ + mappers/mapper_LH10.c \ + mappers/mapper_LH10.h \ + mappers/mapper_LH32.c \ + mappers/mapper_LH32.h \ + mappers/mapper_Magic.c \ + mappers/mapper_Magic.h \ + mappers/mapper_Malee.c \ + mappers/mapper_Malee.h \ + mappers/mapper_MALISB.c \ + mappers/mapper_MALISB.h \ + mappers/mapper_MMC1.c \ + mappers/mapper_MMC1.h \ + mappers/mapper_MMC2andMMC4.c \ + mappers/mapper_MMC2andMMC4.h \ + mappers/mapper_MMC3.c \ + mappers/mapper_MMC3.h \ + mappers/mapper_MMC5.c \ + mappers/mapper_MMC5.h \ + mappers/mapper_MTECH01.c \ + mappers/mapper_MTECH01.h \ + mappers/mapper_Namco.c \ + mappers/mapper_Namco.h \ + mappers/mapper_NovelDiamond.c \ + mappers/mapper_NovelDiamond.h \ + mappers/mapper_NSF.c \ + mappers/mapper_NSF.h \ + mappers/mapper_Ntdec.c \ + mappers/mapper_Ntdec.h \ + mappers/mapper_Rcm.c \ + mappers/mapper_Rcm.h \ + mappers/mapper_Rex.c \ + mappers/mapper_Rex.h \ + mappers/mapper_RT_01.c \ + mappers/mapper_RT_01.h \ + mappers/mapper_SA_9602B.c \ + mappers/mapper_SA_9602B.h \ + mappers/mapper_Sachen.c \ + mappers/mapper_Sachen.h \ + mappers/mapper_SC_127.c \ + mappers/mapper_SC_127.h \ + mappers/mapper_SHERO.c \ + mappers/mapper_SHERO.h \ + mappers/mapper_SL1632.c \ + mappers/mapper_SL1632.h \ + mappers/mapper_Sunsoft.c \ + mappers/mapper_Sunsoft.h \ + mappers/mapper_Super24in1.c \ + mappers/mapper_Super24in1.h \ + mappers/mapper_T262.c \ + mappers/mapper_T262.h \ + mappers/mapper_Taito.c \ + mappers/mapper_Taito.h \ + mappers/mapper_Tengen.c \ + mappers/mapper_Tengen.h \ + mappers/mapper_TF1201.c \ + mappers/mapper_TF1201.h \ + mappers/mapper_Txc.c \ + mappers/mapper_Txc.h \ + mappers/mapper_TxROM.c \ + mappers/mapper_TxROM.h \ + mappers/mapper_UNIF158B.c \ + mappers/mapper_UNIF158B.h \ + mappers/mapper_UNIF43272.c \ + mappers/mapper_UNIF43272.h \ + mappers/mapper_UNIF603_5052.c \ + mappers/mapper_UNIF603_5052.h \ + mappers/mapper_UNIF8157.c \ + mappers/mapper_UNIF8157.h \ + mappers/mapper_UNIF8237.c \ + mappers/mapper_UNIF8237.h \ + mappers/mapper_UNIFSMB2J.c \ + mappers/mapper_UNIFSMB2J.h \ + mappers/mapper_UxROM.c \ + mappers/mapper_UxROM.h \ + mappers/mapper_VRC1.c \ + mappers/mapper_VRC1.h \ + mappers/mapper_VRC2.c \ + mappers/mapper_VRC2.h \ + mappers/mapper_VRC3.c \ + mappers/mapper_VRC3.h \ + mappers/mapper_VRC4.c \ + mappers/mapper_VRC4.h \ + mappers/mapper_VRC6.c \ + mappers/mapper_VRC6.h \ + mappers/mapper_VRC7.c \ + mappers/mapper_VRC7.h \ + mappers/mapper_VRC7_snd.c \ + mappers/mapper_VRC7_snd.h \ + mappers/mapper_Vs.c \ + mappers/mapper_Vs.h \ + mappers/mapper_Waixing.c \ + mappers/mapper_Waixing.h \ + mappers/mapper_Whirlwind.c \ + mappers/mapper_Whirlwind.h \ + mappers/mapper_YOKO.c \ + mappers/mapper_YOKO.h + +patcher_xdelta3_wrap.o: patcher_xdelta3_wrap.c patcher_xdelta3_wrap.h + ${CC} -w ${DEFS} ${DEFAULT_INCLUDES} ${CFLAGS} -c -o $@ $< \ Manca newline alla fine del file diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_105.c puNES-0.105.new/src/core/mappers/mapper_105.c --- puNES-0.105.org/src/core/mappers/mapper_105.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_105.c 2020-03-18 11:47:29.364142681 +0100 @@ -58,7 +58,25 @@ INLINE static void swap_prg_rom_105(void enum MMC1_regs { CTRL, CHR0, CHR1, PRG0 }; -uint32_t counter_must_reach; +struct _m105 { + BYTE reg; + BYTE pos; + BYTE ctrl; + BYTE reset; + struct _prg_m105 { + BYTE mode; + BYTE locked; + BYTE upper; + BYTE reg[2]; + } prg; + struct _irq_m105 { + BYTE reg; + uint32_t count; + } irq; +} m105; +struct _m105tmp { + uint32_t counter_must_reach; +} m105tmp; void map_init_105(void) { EXTCL_CPU_WR_MEM(105); @@ -67,7 +85,7 @@ void map_init_105(void) { mapper.internal_struct[0] = (BYTE *) &m105; mapper.internal_struct_size[0] = sizeof(m105); - counter_must_reach = M105_DIPSWITCH << 25; + m105tmp.counter_must_reach = M105_DIPSWITCH << 25; if (info.reset >= HARD) { memset(&m105, 0x00, sizeof(m105)); @@ -180,7 +198,7 @@ BYTE extcl_save_mapper_105(BYTE mode, BY } void extcl_cpu_every_cycle_105(void) { if (!m105.irq.reg) { - if (++m105.irq.count == counter_must_reach) { + if (++m105.irq.count == m105tmp.counter_must_reach) { m105.irq.count = 0; irq.high |= EXT_IRQ; } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_105.h puNES-0.105.new/src/core/mappers/mapper_105.h --- puNES-0.105.org/src/core/mappers/mapper_105.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_105.h 2020-03-18 11:47:29.364142681 +0100 @@ -21,23 +21,6 @@ #include "common.h" -struct m105 { - BYTE reg; - BYTE pos; - BYTE ctrl; - BYTE reset; - struct _prg_m105 { - BYTE mode; - BYTE locked; - BYTE upper; - BYTE reg[2]; - } prg; - struct _irq_m105 { - BYTE reg; - uint32_t count; - } irq; -} m105; - void map_init_105(void); void extcl_cpu_wr_mem_105(WORD address, BYTE value); BYTE extcl_save_mapper_105(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_114.c puNES-0.105.new/src/core/mappers/mapper_114.c --- puNES-0.105.org/src/core/mappers/mapper_114.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_114.c 2020-03-18 11:47:29.364142681 +0100 @@ -34,6 +34,12 @@ mapper.rom_map_to[2] = m114.prg_rom_bank[2];\ mapper.rom_map_to[3] = m114.prg_rom_bank[3] +struct _m114 { + BYTE prg_rom_switch; + BYTE mmc3_ctrl_change; + WORD prg_rom_bank[4]; +} m114; + void map_init_114(void) { EXTCL_CPU_WR_MEM(114); EXTCL_SAVE_MAPPER(114); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_114.h puNES-0.105.new/src/core/mappers/mapper_114.h --- puNES-0.105.org/src/core/mappers/mapper_114.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_114.h 2020-03-18 11:47:29.364142681 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m114 { - BYTE prg_rom_switch; - BYTE mmc3_ctrl_change; - WORD prg_rom_bank[4]; -} m114; - static const BYTE vlu114[8] = {0, 3, 1, 5, 6, 7, 2, 4}; void map_init_114(void); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_116.c puNES-0.105.new/src/core/mappers/mapper_116.c --- puNES-0.105.org/src/core/mappers/mapper_116.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_116.c 2020-03-18 11:47:29.364142681 +0100 @@ -384,6 +384,31 @@ }\ } +struct _m116 { + BYTE mode; + + struct { + WORD chr[8]; + WORD prg[4]; + BYTE nmt; + BYTE padding; + } mode0; + struct { + WORD banks[10]; + BYTE ctrl; + BYTE nmt; + } mode1; + struct { + BYTE reg[4]; + BYTE buffer; + BYTE shifter; + BYTE padding[2]; + } mode2; + + WORD prg_map[4]; + WORD chr_map[8]; +} m116; + void map_init_116(void) { switch (info.mapper.submapper) { default: diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_116.h puNES-0.105.new/src/core/mappers/mapper_116.h --- puNES-0.105.org/src/core/mappers/mapper_116.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_116.h 2020-03-18 11:47:29.364142681 +0100 @@ -27,31 +27,6 @@ enum { MAP116_TYPE_C }; -struct _m116 { - BYTE mode; - - struct { - WORD chr[8]; - WORD prg[4]; - BYTE nmt; - BYTE padding; - } mode0; - struct { - WORD banks[10]; - BYTE ctrl; - BYTE nmt; - } mode1; - struct { - BYTE reg[4]; - BYTE buffer; - BYTE shifter; - BYTE padding[2]; - } mode2; - - WORD prg_map[4]; - WORD chr_map[8]; -} m116; - void map_init_116(void); void extcl_cpu_wr_mem_116_type_A(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_120.c puNES-0.105.new/src/core/mappers/mapper_120.c --- puNES-0.105.org/src/core/mappers/mapper_120.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_120.c 2020-03-18 11:47:29.364142681 +0100 @@ -23,6 +23,10 @@ #include "cpu.h" #include "save_slot.h" +struct _m120 { + BYTE *prg_ram_rd; +} m120; + void map_init_120(void) { EXTCL_CPU_WR_MEM(120); EXTCL_CPU_RD_MEM(120); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_120.h puNES-0.105.new/src/core/mappers/mapper_120.h --- puNES-0.105.org/src/core/mappers/mapper_120.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_120.h 2020-03-18 11:47:29.364142681 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m120 { - BYTE *prg_ram_rd; -} m120; - void map_init_120(void); void extcl_cpu_wr_mem_120(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_120(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_121.c puNES-0.105.new/src/core/mappers/mapper_121.c --- puNES-0.105.org/src/core/mappers/mapper_121.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_121.c 2020-03-18 11:47:29.364142681 +0100 @@ -79,6 +79,11 @@ INLINE static void m121_update_chr(void) break;\ } +struct _m121 { + BYTE reg[8]; + WORD prg_map[4]; + WORD chr_map[8]; +} m121; static const BYTE vlu121[4] = { 0x83, 0x83, 0x42, 0x00 }; void map_init_121(void) { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_121.h puNES-0.105.new/src/core/mappers/mapper_121.h --- puNES-0.105.org/src/core/mappers/mapper_121.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_121.h 2020-03-18 11:47:29.364142681 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m121 { - BYTE reg[8]; - WORD prg_map[4]; - WORD chr_map[8]; -} m121; - void map_init_121(void); void extcl_cpu_wr_mem_121(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_121(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_134.c puNES-0.105.new/src/core/mappers/mapper_134.c --- puNES-0.105.org/src/core/mappers/mapper_134.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_134.c 2020-03-18 11:47:29.364142681 +0100 @@ -155,6 +155,12 @@ }\ } +struct _m134 { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} m134; + void map_init_134(void) { EXTCL_CPU_WR_MEM(134); EXTCL_SAVE_MAPPER(134); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_134.h puNES-0.105.new/src/core/mappers/mapper_134.h --- puNES-0.105.org/src/core/mappers/mapper_134.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_134.h 2020-03-18 11:47:29.364142681 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m134 { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} m134; - void map_init_134(void); void extcl_cpu_wr_mem_134(WORD address, BYTE value); BYTE extcl_save_mapper_134(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_156.c puNES-0.105.new/src/core/mappers/mapper_156.c --- puNES-0.105.org/src/core/mappers/mapper_156.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_156.c 2020-03-18 11:47:29.364142681 +0100 @@ -24,6 +24,13 @@ INLINE static void chr_setup_156(void); +struct _m156 { + struct _m156_chr { + BYTE low[8]; + BYTE high[8]; + } chr; +} m156; + void map_init_156(void) { EXTCL_CPU_WR_MEM(156); EXTCL_SAVE_MAPPER(156); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_156.h puNES-0.105.new/src/core/mappers/mapper_156.h --- puNES-0.105.org/src/core/mappers/mapper_156.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_156.h 2020-03-18 11:47:29.364142681 +0100 @@ -21,13 +21,6 @@ #include "common.h" -struct _m156 { - struct _m156_chr { - BYTE low[8]; - BYTE high[8]; - } chr; -} m156; - void map_init_156(void); void extcl_cpu_wr_mem_156(WORD address, BYTE value); BYTE extcl_save_mapper_156(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_163.c puNES-0.105.new/src/core/mappers/mapper_163.c --- puNES-0.105.org/src/core/mappers/mapper_163.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_163.c 2020-03-18 11:47:29.364142681 +0100 @@ -23,6 +23,15 @@ #include "ppu.h" #include "save_slot.h" +struct _m163 { + BYTE prg; + BYTE chr; + BYTE reg; + BYTE security; + BYTE trigger; + BYTE chr_mode; +} m163; + void map_init_163(void) { EXTCL_CPU_WR_MEM(163); EXTCL_CPU_RD_MEM(163); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_163.h puNES-0.105.new/src/core/mappers/mapper_163.h --- puNES-0.105.org/src/core/mappers/mapper_163.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_163.h 2020-03-18 11:47:29.364142681 +0100 @@ -21,15 +21,6 @@ #include "common.h" -struct _m163 { - BYTE prg; - BYTE chr; - BYTE reg; - BYTE security; - BYTE trigger; - BYTE chr_mode; -} m163; - void map_init_163(void); void extcl_cpu_wr_mem_163(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_163(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_164.c puNES-0.105.new/src/core/mappers/mapper_164.c --- puNES-0.105.org/src/core/mappers/mapper_164.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_164.c 2020-03-18 11:47:29.364142681 +0100 @@ -23,6 +23,10 @@ #include "ppu.h" #include "save_slot.h" +struct _m164 { + BYTE prg; +} m164; + void map_init_164(void) { EXTCL_CPU_WR_MEM(164); EXTCL_CPU_RD_MEM(164); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_164.h puNES-0.105.new/src/core/mappers/mapper_164.h --- puNES-0.105.org/src/core/mappers/mapper_164.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_164.h 2020-03-18 11:47:29.364142681 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m164 { - BYTE prg; -} m164; - void map_init_164(void); void extcl_cpu_wr_mem_164(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_164(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_166.c puNES-0.105.new/src/core/mappers/mapper_166.c --- puNES-0.105.org/src/core/mappers/mapper_166.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_166.c 2020-03-18 11:47:29.365142673 +0100 @@ -21,6 +21,10 @@ #include "info.h" #include "save_slot.h" +struct _m166 { + BYTE reg[4]; +} m166; + void map_init_166(void) { EXTCL_CPU_WR_MEM(166); EXTCL_SAVE_MAPPER(166); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_166.h puNES-0.105.new/src/core/mappers/mapper_166.h --- puNES-0.105.org/src/core/mappers/mapper_166.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_166.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m166 { - BYTE reg[4]; -} m166; - void map_init_166(void); void extcl_cpu_wr_mem_166(WORD address, BYTE value); BYTE extcl_save_mapper_166(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_167.c puNES-0.105.new/src/core/mappers/mapper_167.c --- puNES-0.105.org/src/core/mappers/mapper_167.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_167.c 2020-03-18 11:47:29.365142673 +0100 @@ -21,6 +21,10 @@ #include "info.h" #include "save_slot.h" +struct _m167 { + BYTE reg[4]; +} m167; + void map_init_167(void) { EXTCL_CPU_WR_MEM(167); EXTCL_SAVE_MAPPER(167); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_167.h puNES-0.105.new/src/core/mappers/mapper_167.h --- puNES-0.105.org/src/core/mappers/mapper_167.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_167.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m167 { - BYTE reg[4]; -} m167; - void map_init_167(void); void extcl_cpu_wr_mem_167(WORD address, BYTE value); BYTE extcl_save_mapper_167(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_168.c puNES-0.105.new/src/core/mappers/mapper_168.c --- puNES-0.105.org/src/core/mappers/mapper_168.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_168.c 2020-03-18 11:47:29.365142673 +0100 @@ -25,6 +25,10 @@ INLINE static void m168_update_chr(void); +struct _m168 { + WORD chr_map[8]; +} m168; + void map_init_168(void) { EXTCL_CPU_WR_MEM(168); EXTCL_SAVE_MAPPER(168); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_168.h puNES-0.105.new/src/core/mappers/mapper_168.h --- puNES-0.105.org/src/core/mappers/mapper_168.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_168.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m168 { - WORD chr_map[8]; -} m168; - void map_init_168(void); void extcl_cpu_wr_mem_168(WORD address, BYTE value); BYTE extcl_save_mapper_168(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_178.c puNES-0.105.new/src/core/mappers/mapper_178.c --- puNES-0.105.org/src/core/mappers/mapper_178.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_178.c 2020-03-18 11:47:29.365142673 +0100 @@ -24,7 +24,13 @@ INLINE static void prg_setup_178(void); -BYTE model; +struct _m178 { + BYTE reg[3]; + BYTE prg_mode; +} m178; +struct _m178tmp { + BYTE model; +} m178tmp; void map_init_178(BYTE type) { EXTCL_CPU_WR_MEM(178); @@ -41,7 +47,7 @@ void map_init_178(BYTE type) { info.mapper.extend_wr = TRUE; - model = type; + m178tmp.model = type; } void extcl_cpu_wr_mem_178(WORD address, BYTE value) { switch (address) { @@ -55,7 +61,7 @@ void extcl_cpu_wr_mem_178(WORD address, prg_setup_178(); return; case 0x4801: - if (model == M178EC32IN1) { + if (m178tmp.model == M178EC32IN1) { m178.reg[1] = value; } else { m178.reg[0] = value; @@ -63,7 +69,7 @@ void extcl_cpu_wr_mem_178(WORD address, prg_setup_178(); return; case 0x4802: - if (model == M178EC32IN1) { + if (m178tmp.model == M178EC32IN1) { m178.reg[0] = value; } else { m178.reg[1] = value; @@ -86,7 +92,7 @@ BYTE extcl_save_mapper_178(BYTE mode, BY INLINE static void prg_setup_178(void) { DBWORD value; - if (model == M178EC32IN1) { + if (m178tmp.model == M178EC32IN1) { value = (m178.reg[1] << 3) | ((m178.reg[0] & 0x07) << 1); } else { value = (m178.reg[1] << 3) | (m178.reg[0] & 0x07); @@ -101,7 +107,7 @@ INLINE static void prg_setup_178(void) { case 1: control_bank(info.prg.rom[0].max.banks_16k) map_prg_rom_8k(2, 0, value); - if (model == M178EC32IN1) { + if (m178tmp.model == M178EC32IN1) { value = (m178.reg[1] << 3) | 0x07; } else { value = (m178.reg[1] << 3) | 0x07; @@ -117,7 +123,7 @@ INLINE static void prg_setup_178(void) { case 3: control_bank(info.prg.rom[0].max.banks_16k) map_prg_rom_8k(2, 0, value); - if (model == M178EC32IN1) { + if (m178tmp.model == M178EC32IN1) { value = (m178.reg[1] << 3) | 0x06 | ((m178.reg[0] & 0x01) << 1); } else { value = (m178.reg[1] << 3) | 0x06 | (m178.reg[0] & 0x01); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_178.h puNES-0.105.new/src/core/mappers/mapper_178.h --- puNES-0.105.org/src/core/mappers/mapper_178.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_178.h 2020-03-18 11:47:29.365142673 +0100 @@ -23,11 +23,6 @@ enum { M178EC32IN1 }; -struct _m178 { - BYTE reg[3]; - BYTE prg_mode; -} m178; - void map_init_178(BYTE type); void extcl_cpu_wr_mem_178(WORD address, BYTE value); BYTE extcl_save_mapper_178(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_183.c puNES-0.105.new/src/core/mappers/mapper_183.c --- puNES-0.105.org/src/core/mappers/mapper_183.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_183.c 2020-03-18 11:47:29.365142673 +0100 @@ -23,6 +23,14 @@ #include "cpu.h" #include "save_slot.h" +struct _m183 { + BYTE enabled; + BYTE prescaler; + BYTE count; + BYTE delay; + BYTE chr_rom_bank[8]; +} m183; + void map_init_183(void) { EXTCL_CPU_WR_MEM(183); EXTCL_CPU_RD_MEM(183); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_183.h puNES-0.105.new/src/core/mappers/mapper_183.h --- puNES-0.105.org/src/core/mappers/mapper_183.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_183.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,14 +21,6 @@ #include "common.h" -struct _m183 { - BYTE enabled; - BYTE prescaler; - BYTE count; - BYTE delay; - BYTE chr_rom_bank[8]; -} m183; - void map_init_183(void); void extcl_cpu_wr_mem_183(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_183(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_186.c puNES-0.105.new/src/core/mappers/mapper_186.c --- puNES-0.105.org/src/core/mappers/mapper_186.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_186.c 2020-03-18 11:47:29.365142673 +0100 @@ -23,6 +23,10 @@ #include "cpu.h" #include "save_slot.h" +struct _m186 { + BYTE *prg_ram_bank2; +} m186; + void map_init_186(void) { EXTCL_CPU_WR_MEM(186); EXTCL_CPU_RD_MEM(186); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_186.h puNES-0.105.new/src/core/mappers/mapper_186.h --- puNES-0.105.org/src/core/mappers/mapper_186.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_186.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m186 { - BYTE *prg_ram_bank2; -} m186; - void map_init_186(void); void extcl_cpu_wr_mem_186(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_186(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_187.c puNES-0.105.new/src/core/mappers/mapper_187.c --- puNES-0.105.org/src/core/mappers/mapper_187.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_187.c 2020-03-18 11:47:29.365142673 +0100 @@ -77,6 +77,11 @@ INLINE static void m187_update_chr(void) break;\ } +struct _m187 { + BYTE reg[8]; + WORD prg_map[4]; + WORD chr_map[8]; +} m187; static const BYTE vlu187[4] = { 0x83, 0x83, 0x42, 0x00 }; void map_init_187(void) { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_187.h puNES-0.105.new/src/core/mappers/mapper_187.h --- puNES-0.105.org/src/core/mappers/mapper_187.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_187.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m187 { - BYTE reg[8]; - WORD prg_map[4]; - WORD chr_map[8]; -} m187; - void map_init_187(void); void extcl_cpu_wr_mem_187(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_187(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_196.c puNES-0.105.new/src/core/mappers/mapper_196.c --- puNES-0.105.org/src/core/mappers/mapper_196.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_196.c 2020-03-18 11:47:29.365142673 +0100 @@ -43,6 +43,11 @@ INLINE static void m196_update_prg(void) break;\ } +struct _m196 { + BYTE reg[2]; + WORD prg_map[4]; +} m196; + void map_init_196(void) { EXTCL_CPU_WR_MEM(196); EXTCL_SAVE_MAPPER(196); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_196.h puNES-0.105.new/src/core/mappers/mapper_196.h --- puNES-0.105.org/src/core/mappers/mapper_196.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_196.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _m196 { - BYTE reg[2]; - WORD prg_map[4]; -} m196; - void map_init_196(void); void extcl_cpu_wr_mem_196(WORD address, BYTE value); BYTE extcl_save_mapper_196(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_197.c puNES-0.105.new/src/core/mappers/mapper_197.c --- puNES-0.105.org/src/core/mappers/mapper_197.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_197.c 2020-03-18 11:47:29.365142673 +0100 @@ -63,6 +63,10 @@ INLINE static void m197_update_chr(void) break;\ } +struct _m197 { + WORD chr_map[8]; +} m197; + void map_init_197(void) { EXTCL_CPU_WR_MEM(197); EXTCL_SAVE_MAPPER(197); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_197.h puNES-0.105.new/src/core/mappers/mapper_197.h --- puNES-0.105.org/src/core/mappers/mapper_197.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_197.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m197 { - WORD chr_map[8]; -} m197; - void map_init_197(void); void extcl_cpu_wr_mem_197(WORD address, BYTE value); BYTE extcl_save_mapper_197(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_205.c puNES-0.105.new/src/core/mappers/mapper_205.c --- puNES-0.105.org/src/core/mappers/mapper_205.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_205.c 2020-03-18 11:47:29.365142673 +0100 @@ -79,6 +79,8 @@ INLINE static void m205_update_chr(void) break;\ } +_m205 m205; + void map_init_205(void) { EXTCL_CPU_WR_MEM(205); EXTCL_SAVE_MAPPER(205); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_205.h puNES-0.105.new/src/core/mappers/mapper_205.h --- puNES-0.105.org/src/core/mappers/mapper_205.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_205.h 2020-03-18 11:47:29.365142673 +0100 @@ -21,11 +21,13 @@ #include "common.h" -struct _m205 { +typedef struct _m205 { BYTE reg[2]; WORD prg_map[4]; WORD chr_map[8]; -} m205; +} _m205; + +extern _m205 m205; void map_init_205(void); void extcl_cpu_wr_mem_205(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_208.c puNES-0.105.new/src/core/mappers/mapper_208.c --- puNES-0.105.org/src/core/mappers/mapper_208.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_208.c 2020-03-18 11:47:29.366142665 +0100 @@ -24,6 +24,10 @@ #include "irqA12.h" #include "save_slot.h" +struct _m208 { + BYTE ctrl; + BYTE reg[4]; +} m208; static const BYTE vlu208[256] = { 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_208.h puNES-0.105.new/src/core/mappers/mapper_208.h --- puNES-0.105.org/src/core/mappers/mapper_208.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_208.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _m208 { - BYTE ctrl; - BYTE reg[4]; -} m208; - void map_init_208(void); void extcl_cpu_wr_mem_208(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_208(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_215.c puNES-0.105.new/src/core/mappers/mapper_215.c --- puNES-0.105.org/src/core/mappers/mapper_215.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_215.c 2020-03-18 11:47:29.366142665 +0100 @@ -158,6 +158,11 @@ }\ } +struct _m215 { + BYTE reg[4]; + WORD prg_8k_bank[4]; +} m215; + void map_init_215(void) { EXTCL_CPU_WR_MEM(215); EXTCL_SAVE_MAPPER(215); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_215.h puNES-0.105.new/src/core/mappers/mapper_215.h --- puNES-0.105.org/src/core/mappers/mapper_215.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_215.h 2020-03-18 11:47:29.366142665 +0100 @@ -23,11 +23,6 @@ enum { M215_MK3E }; -struct _m215 { - BYTE reg[4]; - WORD prg_8k_bank[4]; -} m215; - void map_init_215(void); void extcl_cpu_wr_mem_215(WORD address, BYTE value); BYTE extcl_save_mapper_215(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_217.c puNES-0.105.new/src/core/mappers/mapper_217.c --- puNES-0.105.org/src/core/mappers/mapper_217.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_217.c 2020-03-18 11:47:29.366142665 +0100 @@ -136,6 +136,11 @@ }\ } +struct _m217 { + BYTE reg[4]; + WORD prg_8k_bank[4]; +} m217; + void map_init_217(void) { EXTCL_CPU_WR_MEM(217); EXTCL_SAVE_MAPPER(217); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_217.h puNES-0.105.new/src/core/mappers/mapper_217.h --- puNES-0.105.org/src/core/mappers/mapper_217.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_217.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _m217 { - BYTE reg[4]; - WORD prg_8k_bank[4]; -} m217; - void map_init_217(void); void extcl_cpu_wr_mem_217(WORD address, BYTE value); BYTE extcl_save_mapper_217(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_219.c puNES-0.105.new/src/core/mappers/mapper_219.c --- puNES-0.105.org/src/core/mappers/mapper_219.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_219.c 2020-03-18 11:47:29.366142665 +0100 @@ -28,6 +28,10 @@ control_bank(info.chr.rom[0].max.banks_1k)\ chr.bank_1k[b] = chr_chip_byte_pnt(0, value << 10) +struct _m219 { + BYTE reg[3]; +} m219; + void map_init_219(void) { EXTCL_CPU_WR_MEM(219); EXTCL_SAVE_MAPPER(219); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_219.h puNES-0.105.new/src/core/mappers/mapper_219.h --- puNES-0.105.org/src/core/mappers/mapper_219.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_219.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m219 { - BYTE reg[3]; -} m219; - void map_init_219(void); void extcl_cpu_wr_mem_219(WORD address, BYTE value); BYTE extcl_save_mapper_219(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_221.c puNES-0.105.new/src/core/mappers/mapper_221.c --- puNES-0.105.org/src/core/mappers/mapper_221.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_221.c 2020-03-18 11:47:29.366142665 +0100 @@ -32,6 +32,10 @@ control_bank(info.prg.rom[0].max.banks_16k)\ map_prg_rom_8k(2, 2, value) +struct _m221 { + BYTE reg[2]; +} m221; + void map_init_221(void) { EXTCL_CPU_WR_MEM(221); EXTCL_SAVE_MAPPER(221); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_221.h puNES-0.105.new/src/core/mappers/mapper_221.h --- puNES-0.105.org/src/core/mappers/mapper_221.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_221.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m221 { - BYTE reg[2]; -} m221; - void map_init_221(void); void extcl_cpu_wr_mem_221(WORD address, BYTE value); BYTE extcl_save_mapper_221(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_222.c puNES-0.105.new/src/core/mappers/mapper_222.c --- puNES-0.105.org/src/core/mappers/mapper_222.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_222.c 2020-03-18 11:47:29.366142665 +0100 @@ -24,6 +24,11 @@ #include "irqA12.h" #include "save_slot.h" +struct _m222 { + BYTE count; + BYTE delay; +} m222; + void map_init_222(void) { EXTCL_CPU_WR_MEM(222); EXTCL_SAVE_MAPPER(222); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_222.h puNES-0.105.new/src/core/mappers/mapper_222.h --- puNES-0.105.org/src/core/mappers/mapper_222.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_222.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _m222 { - BYTE count; - BYTE delay; -} m222; - void map_init_222(void); void extcl_cpu_wr_mem_222(WORD address, BYTE value); BYTE extcl_save_mapper_222(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_226.c puNES-0.105.new/src/core/mappers/mapper_226.c --- puNES-0.105.org/src/core/mappers/mapper_226.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_226.c 2020-03-18 11:47:29.366142665 +0100 @@ -22,6 +22,10 @@ #include "mem_map.h" #include "save_slot.h" +struct _m226 { + BYTE reg[2]; +} m226; + void map_init_226(void) { EXTCL_CPU_WR_MEM(226); EXTCL_SAVE_MAPPER(226); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_226.h puNES-0.105.new/src/core/mappers/mapper_226.h --- puNES-0.105.org/src/core/mappers/mapper_226.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_226.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m226 { - BYTE reg[2]; -} m226; - void map_init_226(void); void extcl_cpu_wr_mem_226(WORD address, BYTE value); BYTE extcl_save_mapper_226(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_230.c puNES-0.105.new/src/core/mappers/mapper_230.c --- puNES-0.105.org/src/core/mappers/mapper_230.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_230.c 2020-03-18 11:47:29.366142665 +0100 @@ -21,6 +21,10 @@ #include "mem_map.h" #include "save_slot.h" +struct _m230 { + BYTE mode; +} m230; + void map_init_230(void) { EXTCL_CPU_WR_MEM(230); EXTCL_SAVE_MAPPER(230); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_230.h puNES-0.105.new/src/core/mappers/mapper_230.h --- puNES-0.105.org/src/core/mappers/mapper_230.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_230.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m230 { - BYTE mode; -} m230; - void map_init_230(void); void extcl_cpu_wr_mem_230(WORD address, BYTE value); BYTE extcl_save_mapper_230(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_235.c puNES-0.105.new/src/core/mappers/mapper_235.c --- puNES-0.105.org/src/core/mappers/mapper_235.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_235.c 2020-03-18 11:47:29.366142665 +0100 @@ -28,27 +28,32 @@ static const BYTE slots[4][4][2] = { { { 0x00, 0 }, { 0x20, 0 }, { 0x40, 0 }, { 0x60, 0 } } }; -BYTE type; +struct _m235 { + BYTE openbus; +} m235; +struct _m235tmp { + BYTE type; +} m235tmp; void map_init_235(void) { switch (info.prg.rom[0].banks_16k) { case 64: - type = 0; + m235tmp.type = 0; break; case 128: - type = 1; + m235tmp.type = 1; break; case 192: - type = 2; + m235tmp.type = 2; break; case 256: default: - type = 3; + m235tmp.type = 3; break; } EXTCL_CPU_WR_MEM(235); - if (type != 3) { + if (m235tmp.type != 3) { EXTCL_CPU_RD_MEM(235); EXTCL_SAVE_MAPPER(235); mapper.internal_struct[0] = (BYTE *) &m235; @@ -63,8 +68,8 @@ void map_init_235(void) { } } void extcl_cpu_wr_mem_235(WORD address, BYTE value) { - BYTE bank = slots[type][(address >> 8) & 0x03][0] | (address & 0x1F); - m235.openbus = slots[type][(address >> 8) & 0x03][1]; + BYTE bank = slots[m235tmp.type][(address >> 8) & 0x03][0] | (address & 0x1F); + m235.openbus = slots[m235tmp.type][(address >> 8) & 0x03][1]; if (address & 0x0800) { value = (bank << 1) | ((address >> 12) & 0x01); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_235.h puNES-0.105.new/src/core/mappers/mapper_235.h --- puNES-0.105.org/src/core/mappers/mapper_235.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_235.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m235 { - BYTE openbus; -} m235; - void map_init_235(void); void extcl_cpu_wr_mem_235(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_235(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_249.c puNES-0.105.new/src/core/mappers/mapper_249.c --- puNES-0.105.org/src/core/mappers/mapper_249.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_249.c 2020-03-18 11:47:29.366142665 +0100 @@ -64,6 +64,12 @@ } */ +struct _m249 { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} m249; + void map_init_249(void) { EXTCL_CPU_WR_MEM(249); EXTCL_CPU_RD_MEM(249); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_249.h puNES-0.105.new/src/core/mappers/mapper_249.h --- puNES-0.105.org/src/core/mappers/mapper_249.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_249.h 2020-03-18 11:47:29.366142665 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m249 { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} m249; - void map_init_249(void); void extcl_cpu_wr_mem_249(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_249(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_252.c puNES-0.105.new/src/core/mappers/mapper_252.c --- puNES-0.105.org/src/core/mappers/mapper_252.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_252.c 2020-03-18 11:47:29.367142656 +0100 @@ -28,6 +28,16 @@ INLINE static void m252_update_chr_extra(void); +struct _m252 { + WORD chr_map[8]; + struct _m252_irq { + BYTE active; + WORD prescaler; + WORD count; + WORD reload; + } irq; +} m252; + void map_init_252(void) { EXTCL_CPU_WR_MEM(252); EXTCL_SAVE_MAPPER(252); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_252.h puNES-0.105.new/src/core/mappers/mapper_252.h --- puNES-0.105.org/src/core/mappers/mapper_252.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_252.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,16 +21,6 @@ #include "common.h" -struct _m252 { - WORD chr_map[8]; - struct _m252_irq { - BYTE active; - WORD prescaler; - WORD count; - WORD reload; - } irq; -} m252; - void map_init_252(void); void extcl_cpu_wr_mem_252(WORD address, BYTE value); BYTE extcl_save_mapper_252(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_253.c puNES-0.105.new/src/core/mappers/mapper_253.c --- puNES-0.105.org/src/core/mappers/mapper_253.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_253.c 2020-03-18 11:47:29.367142656 +0100 @@ -25,6 +25,18 @@ INLINE static void m253_update_chr(void); +struct _m253 { + BYTE disabled_vram; + WORD chr_map_high[8]; + BYTE chr_map[8]; + struct _m253_irq { + BYTE active; + WORD prescaler; + WORD count; + WORD reload; + } irq; +} m253; + void map_init_253(void) { EXTCL_CPU_WR_MEM(253); EXTCL_SAVE_MAPPER(253); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_253.h puNES-0.105.new/src/core/mappers/mapper_253.h --- puNES-0.105.org/src/core/mappers/mapper_253.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_253.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,18 +21,6 @@ #include "common.h" -struct _m253 { - BYTE disabled_vram; - WORD chr_map_high[8]; - BYTE chr_map[8]; - struct _m253_irq { - BYTE active; - WORD prescaler; - WORD count; - WORD reload; - } irq; -} m253; - void map_init_253(void); void extcl_cpu_wr_mem_253(WORD address, BYTE value); BYTE extcl_save_mapper_253(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_254.c puNES-0.105.new/src/core/mappers/mapper_254.c --- puNES-0.105.org/src/core/mappers/mapper_254.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_254.c 2020-03-18 11:47:29.367142656 +0100 @@ -23,6 +23,10 @@ #include "irqA12.h" #include "save_slot.h" +struct _m254 { + BYTE reg[2]; +} m254; + void map_init_254(void) { EXTCL_CPU_WR_MEM(254); EXTCL_CPU_RD_MEM(254); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_254.h puNES-0.105.new/src/core/mappers/mapper_254.h --- puNES-0.105.org/src/core/mappers/mapper_254.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_254.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m254 { - BYTE reg[2]; -} m254; - void map_init_254(void); void extcl_cpu_wr_mem_254(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_254(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_28.c puNES-0.105.new/src/core/mappers/mapper_28.c --- puNES-0.105.org/src/core/mappers/mapper_28.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_28.c 2020-03-18 11:47:29.367142656 +0100 @@ -28,6 +28,11 @@ INLINE static void nmt_setup_28(void); INLINE static void prg_setup_28(void); INLINE static BYTE calc_prg_bank_28(WORD address); +struct _m28 { + BYTE index; + BYTE mirroring; + BYTE prg[3]; +} m28; static BYTE const inner_and[4] = { 0x01, 0x03, 0x07, 0x0F }; void map_init_28(void) { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_28.h puNES-0.105.new/src/core/mappers/mapper_28.h --- puNES-0.105.org/src/core/mappers/mapper_28.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_28.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m28 { - BYTE index; - BYTE mirroring; - BYTE prg[3]; -} m28; - void map_init_28(void); void extcl_cpu_wr_mem_28(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_28(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_31.c puNES-0.105.new/src/core/mappers/mapper_31.c --- puNES-0.105.org/src/core/mappers/mapper_31.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_31.c 2020-03-18 11:47:29.367142656 +0100 @@ -25,6 +25,11 @@ INLINE static void sync_31(void); +struct _m31 { + WORD regs[8]; + BYTE *rom_4k[8]; +} m31; + void map_init_31(void) { EXTCL_CPU_WR_MEM(31); EXTCL_CPU_RD_MEM(31); @@ -39,7 +44,6 @@ void map_init_31(void) { info.mapper.extend_wr = TRUE; info.mapper.extend_rd = TRUE; } - void extcl_cpu_wr_mem_31(WORD address, BYTE value) { if ((address < 0x5000) && (address > 0x5FFF)) { return; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_31.h puNES-0.105.new/src/core/mappers/mapper_31.h --- puNES-0.105.org/src/core/mappers/mapper_31.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_31.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _m31 { - WORD regs[8]; - BYTE *rom_4k[8]; -} m31; - void map_init_31(void); void extcl_cpu_wr_mem_31(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_31(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_36.c puNES-0.105.new/src/core/mappers/mapper_36.c --- puNES-0.105.org/src/core/mappers/mapper_36.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_36.c 2020-03-18 11:47:29.367142656 +0100 @@ -23,6 +23,10 @@ #include "cpu.h" #include "save_slot.h" +struct _m36 { + BYTE regs[5]; +} m36; + void map_init_36(void) { EXTCL_CPU_WR_MEM(36); EXTCL_CPU_RD_MEM(36); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_36.h puNES-0.105.new/src/core/mappers/mapper_36.h --- puNES-0.105.org/src/core/mappers/mapper_36.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_36.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m36 { - BYTE regs[5]; -} m36; - void map_init_36(void); void extcl_cpu_wr_mem_36(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_36(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_37.c puNES-0.105.new/src/core/mappers/mapper_37.c --- puNES-0.105.org/src/core/mappers/mapper_37.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_37.c 2020-03-18 11:47:29.367142656 +0100 @@ -157,6 +157,12 @@ }\ } +struct _m37 { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} m37; + void map_init_37(void) { EXTCL_CPU_WR_MEM(37); EXTCL_SAVE_MAPPER(37); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_37.h puNES-0.105.new/src/core/mappers/mapper_37.h --- puNES-0.105.org/src/core/mappers/mapper_37.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_37.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m37 { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} m37; - void map_init_37(void); void extcl_cpu_wr_mem_37(WORD address, BYTE value); BYTE extcl_save_mapper_37(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_40.c puNES-0.105.new/src/core/mappers/mapper_40.c --- puNES-0.105.org/src/core/mappers/mapper_40.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_40.c 2020-03-18 11:47:29.367142656 +0100 @@ -23,7 +23,14 @@ #include "cpu.h" #include "save_slot.h" -BYTE *prg_6000; +struct _m40 { + BYTE enabled; + WORD count; + BYTE delay; +} m40; +struct _m40tmp { + BYTE *prg_6000; +} m40tmp; void map_init_40(void) { EXTCL_CPU_WR_MEM(40); @@ -39,7 +46,7 @@ void map_init_40(void) { mapper.rom_map_to[2] = 0; } - prg_6000 = prg_chip_byte_pnt(0, 6 << 13); + m40tmp.prg_6000 = prg_chip_byte_pnt(0, 6 << 13); mapper.rom_map_to[0] = 4; mapper.rom_map_to[1] = 5; @@ -73,7 +80,7 @@ BYTE extcl_cpu_rd_mem_40(WORD address, B return (openbus); } - return (prg_6000[address & 0x1FFF]); + return (m40tmp.prg_6000[address & 0x1FFF]); } BYTE extcl_save_mapper_40(BYTE mode, BYTE slot, FILE *fp) { save_slot_ele(mode, slot, m40.enabled); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_40.h puNES-0.105.new/src/core/mappers/mapper_40.h --- puNES-0.105.org/src/core/mappers/mapper_40.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_40.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m40 { - BYTE enabled; - WORD count; - BYTE delay; -} m40; - void map_init_40(void); void extcl_cpu_wr_mem_40(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_40(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_42.c puNES-0.105.new/src/core/mappers/mapper_42.c --- puNES-0.105.org/src/core/mappers/mapper_42.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_42.c 2020-03-18 11:47:29.367142656 +0100 @@ -22,6 +22,15 @@ #include "save_slot.h" #include "cpu.h" +struct _m42 { + WORD rom_map_to; + BYTE *prg_8k_6000; + struct _m42_irq { + BYTE active; + uint32_t count; + } irq; +} m42; + void map_init_42(void) { EXTCL_CPU_WR_MEM(42); EXTCL_CPU_RD_MEM(42); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_42.h puNES-0.105.new/src/core/mappers/mapper_42.h --- puNES-0.105.org/src/core/mappers/mapper_42.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_42.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,15 +21,6 @@ #include "common.h" -struct _m42 { - WORD rom_map_to; - BYTE *prg_8k_6000; - struct _m42_irq { - BYTE active; - uint32_t count; - } irq; -} m42; - void map_init_42(void); void extcl_cpu_wr_mem_42(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_42(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_43.c puNES-0.105.new/src/core/mappers/mapper_43.c --- puNES-0.105.org/src/core/mappers/mapper_43.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_43.c 2020-03-18 11:47:29.367142656 +0100 @@ -26,17 +26,27 @@ #define prg_5000_43()\ value = 8 << 1;\ control_bank(info.prg.rom[0].max.banks_4k)\ - prg_5000 = prg_chip_byte_pnt(0, value << 12) + m43tmp.prg_5000 = prg_chip_byte_pnt(0, value << 12) #define prg_6000_swap_43()\ value = m43.swap ? 0 : 2;\ control_bank(info.prg.rom[0].max.banks_8k)\ - prg_6000 = prg_chip_byte_pnt(0, value << 13) + m43tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13) #define prg_E000_swap_43()\ value = m43.swap ? 8 : 9;\ control_bank(info.prg.rom[0].max.banks_8k)\ map_prg_rom_8k(1, 3, value) -BYTE *prg_5000, *prg_6000; +struct _m43 { + BYTE swap; + struct _m43_irq { + BYTE active; + WORD count; + } irq; +} m43; +struct _m43tmp { + BYTE *prg_5000; + BYTE *prg_6000; +} m43tmp; void map_init_43(void) { EXTCL_CPU_WR_MEM(43); @@ -93,10 +103,10 @@ BYTE extcl_cpu_rd_mem_43(WORD address, B } if (address < 0x6000) { - return (prg_5000[address & 0x0FFF]); + return (m43tmp.prg_5000[address & 0x0FFF]); } - return (prg_6000[address & 0x1FFF]); + return (m43tmp.prg_6000[address & 0x1FFF]); } BYTE extcl_save_mapper_43(BYTE mode, BYTE slot, FILE *fp) { save_slot_ele(mode, slot, m43.swap); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_43.h puNES-0.105.new/src/core/mappers/mapper_43.h --- puNES-0.105.org/src/core/mappers/mapper_43.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_43.h 2020-03-18 11:47:29.367142656 +0100 @@ -21,14 +21,6 @@ #include "common.h" -struct _m43 { - BYTE swap; - struct _m43_irq { - BYTE active; - WORD count; - } irq; -} m43; - void map_init_43(void); void extcl_cpu_wr_mem_43(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_43(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_44.c puNES-0.105.new/src/core/mappers/mapper_44.c --- puNES-0.105.org/src/core/mappers/mapper_44.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_44.c 2020-03-18 11:47:29.368142648 +0100 @@ -155,6 +155,12 @@ }\ } +struct _m44 { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} m44; + void map_init_44(void) { EXTCL_CPU_WR_MEM(44); EXTCL_SAVE_MAPPER(44); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_44.h puNES-0.105.new/src/core/mappers/mapper_44.h --- puNES-0.105.org/src/core/mappers/mapper_44.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_44.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m44 { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} m44; - void map_init_44(void); void extcl_cpu_wr_mem_44(WORD address, BYTE value); BYTE extcl_save_mapper_44(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_45.c puNES-0.105.new/src/core/mappers/mapper_45.c --- puNES-0.105.org/src/core/mappers/mapper_45.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_45.c 2020-03-18 11:47:29.368142648 +0100 @@ -160,6 +160,14 @@ }\ } +struct _m45 { + BYTE reg[4]; + BYTE index; + BYTE read; + WORD prg_map[4]; + WORD chr_map[8]; +} m45; + void map_init_45(void) { EXTCL_CPU_WR_MEM(45); EXTCL_CPU_RD_MEM(45); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_45.h puNES-0.105.new/src/core/mappers/mapper_45.h --- puNES-0.105.org/src/core/mappers/mapper_45.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_45.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,14 +21,6 @@ #include "common.h" -struct _m45 { - BYTE reg[4]; - BYTE index; - BYTE read; - WORD prg_map[4]; - WORD chr_map[8]; -} m45; - void map_init_45(void); void extcl_cpu_wr_mem_45(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_45(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_46.c puNES-0.105.new/src/core/mappers/mapper_46.c --- puNES-0.105.org/src/core/mappers/mapper_46.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_46.c 2020-03-18 11:47:29.368142648 +0100 @@ -22,6 +22,11 @@ #include "mem_map.h" #include "save_slot.h" +struct _m46 { + BYTE prg; + BYTE chr; +} m46; + void map_init_46(void) { EXTCL_CPU_WR_MEM(46); EXTCL_SAVE_MAPPER(46); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_46.h puNES-0.105.new/src/core/mappers/mapper_46.h --- puNES-0.105.org/src/core/mappers/mapper_46.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_46.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _m46 { - BYTE prg; - BYTE chr; -} m46; - void map_init_46(void); void extcl_cpu_wr_mem_46(WORD address, BYTE value); BYTE extcl_save_mapper_46(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_47.c puNES-0.105.new/src/core/mappers/mapper_47.c --- puNES-0.105.org/src/core/mappers/mapper_47.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_47.c 2020-03-18 11:47:29.368142648 +0100 @@ -155,6 +155,12 @@ }\ } +struct _m47 { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} m47; + void map_init_47(void) { EXTCL_CPU_WR_MEM(47); EXTCL_SAVE_MAPPER(47); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_47.h puNES-0.105.new/src/core/mappers/mapper_47.h --- puNES-0.105.org/src/core/mappers/mapper_47.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_47.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m47 { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} m47; - void map_init_47(void); void extcl_cpu_wr_mem_47(WORD address, BYTE value); BYTE extcl_save_mapper_47(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_49.c puNES-0.105.new/src/core/mappers/mapper_49.c --- puNES-0.105.org/src/core/mappers/mapper_49.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_49.c 2020-03-18 11:47:29.368142648 +0100 @@ -159,6 +159,12 @@ }\ } +struct _m49 { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} m49; + void map_init_49(void) { EXTCL_CPU_WR_MEM(49); EXTCL_SAVE_MAPPER(49); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_49.h puNES-0.105.new/src/core/mappers/mapper_49.h --- puNES-0.105.org/src/core/mappers/mapper_49.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_49.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m49 { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} m49; - void map_init_49(void); void extcl_cpu_wr_mem_49(WORD address, BYTE value); BYTE extcl_save_mapper_49(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_50.c puNES-0.105.new/src/core/mappers/mapper_50.c --- puNES-0.105.org/src/core/mappers/mapper_50.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_50.c 2020-03-18 11:47:29.368142648 +0100 @@ -23,7 +23,14 @@ #include "cpu.h" #include "save_slot.h" -BYTE *prg_6000; +struct _m50 { + BYTE enabled; + WORD count; + BYTE delay; +} m50; +struct _m50tmp { + BYTE *prg_6000; +} m50tmp; void map_init_50(void) { EXTCL_CPU_WR_MEM(50); @@ -39,7 +46,7 @@ void map_init_50(void) { mapper.rom_map_to[2] = 0; } - prg_6000 = prg_chip_byte_pnt(0, info.prg.rom[0].max.banks_8k << 13); + m50tmp.prg_6000 = prg_chip_byte_pnt(0, info.prg.rom[0].max.banks_8k << 13); mapper.rom_map_to[0] = 8; mapper.rom_map_to[1] = 9; @@ -69,7 +76,7 @@ BYTE extcl_cpu_rd_mem_50(WORD address, B return (openbus); } - return (prg_6000[address & 0x1FFF]); + return (m50tmp.prg_6000[address & 0x1FFF]); } BYTE extcl_save_mapper_50(BYTE mode, BYTE slot, FILE *fp) { save_slot_ele(mode, slot, m50.enabled); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_50.h puNES-0.105.new/src/core/mappers/mapper_50.h --- puNES-0.105.org/src/core/mappers/mapper_50.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_50.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m50 { - BYTE enabled; - WORD count; - BYTE delay; -} m50; - void map_init_50(void); void extcl_cpu_wr_mem_50(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_50(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_51.c puNES-0.105.new/src/core/mappers/mapper_51.c --- puNES-0.105.org/src/core/mappers/mapper_51.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_51.c 2020-03-18 11:47:29.368142648 +0100 @@ -22,7 +22,14 @@ #include "mem_map.h" #include "save_slot.h" -BYTE *prg_6000; +struct _m51 { + BYTE mode; + WORD bank; + BYTE prg_6000; +} m51; +struct _m51tmp { + BYTE *prg_6000; +} m51tmp; void map_init_51(void) { EXTCL_CPU_WR_MEM(51); @@ -76,7 +83,7 @@ void extcl_cpu_wr_mem_51(WORD address, B m51.prg_6000 = m51.prg_6000 | (m51.bank << 2); _control_bank(m51.prg_6000, info.prg.rom[0].max.banks_8k) - prg_6000 = prg_chip_byte_pnt(0, m51.prg_6000 << 13); + m51tmp.prg_6000 = prg_chip_byte_pnt(0, m51.prg_6000 << 13); if (m51.mode == 0x03) { mirroring_H(); @@ -89,7 +96,7 @@ BYTE extcl_cpu_rd_mem_51(WORD address, B return (openbus); } - return (prg_6000[address & 0x1FFF]); + return (m51tmp.prg_6000[address & 0x1FFF]); } BYTE extcl_save_mapper_51(BYTE mode, BYTE slot, FILE *fp) { save_slot_ele(mode, slot, m51.bank); @@ -97,7 +104,7 @@ BYTE extcl_save_mapper_51(BYTE mode, BYT save_slot_ele(mode, slot, m51.prg_6000); if (mode == SAVE_SLOT_READ) { - prg_6000 = prg_chip_byte_pnt(0, m51.prg_6000 << 13); + m51tmp.prg_6000 = prg_chip_byte_pnt(0, m51.prg_6000 << 13); } return (EXIT_OK); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_51.h puNES-0.105.new/src/core/mappers/mapper_51.h --- puNES-0.105.org/src/core/mappers/mapper_51.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_51.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m51 { - BYTE mode; - WORD bank; - BYTE prg_6000; -} m51; - void map_init_51(void); void extcl_cpu_wr_mem_51(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_51(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_52.c puNES-0.105.new/src/core/mappers/mapper_52.c --- puNES-0.105.org/src/core/mappers/mapper_52.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_52.c 2020-03-18 11:47:29.368142648 +0100 @@ -24,7 +24,7 @@ #include "save_slot.h" #define m52_chr_1k(vl)\ - if (model == MARIO7IN1) {\ + if (m52tmp.model == MARIO7IN1) {\ bank = ((((m52.reg >> 3) & 0x04) | ((m52.reg >> 1) & 0x02) |\ ((m52.reg >> 6) & (m52.reg >> 4) & 0x01)) << 7) |\ (vl & (((m52.reg & 0x40) << 1) ^ 0xFF));\ @@ -34,8 +34,7 @@ (vl & (((m52.reg << 1) & 0x80) ^ 0xFF));\ } #define m52_prg_8k(vl)\ - value = (((m52.reg & 0x06) | ((m52.reg >> 3) & m52.reg & 0x01)) << 4) |\ - (vl & (((m52.reg << 1) & 0x10) ^ 0x1F)) + value = (((m52.reg & 0x06) | ((m52.reg >> 3) & m52.reg & 0x01)) << 4) | (vl & (((m52.reg << 1) & 0x10) ^ 0x1F)) #define m52_chr_1k_update()\ {\ BYTE i;\ @@ -166,7 +165,15 @@ }\ } -BYTE model; +struct _m52 { + BYTE disabled; + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} m52; +struct _m52tmp { + BYTE model; +} m52tmp; void map_init_52(BYTE type) { EXTCL_CPU_WR_MEM(52); @@ -208,7 +215,7 @@ void map_init_52(BYTE type) { irqA12.present = TRUE; irqA12_delay = 1; - model = type; + m52tmp.model = type; } void extcl_cpu_wr_mem_52(WORD address, BYTE value) { switch (address & 0xE001) { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_52.h puNES-0.105.new/src/core/mappers/mapper_52.h --- puNES-0.105.org/src/core/mappers/mapper_52.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_52.h 2020-03-18 11:47:29.368142648 +0100 @@ -23,13 +23,6 @@ enum { MARIO7IN1 }; -struct _m52 { - BYTE disabled; - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} m52; - void map_init_52(BYTE type); void extcl_cpu_wr_mem_52(WORD address, BYTE value); BYTE extcl_save_mapper_52(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_53.c puNES-0.105.new/src/core/mappers/mapper_53.c --- puNES-0.105.org/src/core/mappers/mapper_53.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_53.c 2020-03-18 11:47:29.368142648 +0100 @@ -24,7 +24,13 @@ INLINE static void m53_update_6000(void); -BYTE *prg_6000; +struct _m53 { + BYTE reg[2]; + BYTE prg_6000; +} m53; +struct _m53tmp { + BYTE *prg_6000; +} m53tmp; void map_init_53(void) { EXTCL_CPU_WR_MEM(53); @@ -99,7 +105,7 @@ BYTE extcl_cpu_rd_mem_53(WORD address, B return (openbus); } - return (prg_6000[address & 0x1FFF]); + return (m53tmp.prg_6000[address & 0x1FFF]); } BYTE extcl_save_mapper_53(BYTE mode, BYTE slot, FILE *fp) { save_slot_ele(mode, slot, m53.reg); @@ -121,10 +127,10 @@ INLINE static void m53_update_6000(void) m53.prg_6000 = ((m53.reg[0] << 4) & 0x30) | 0x0F; _control_bank(m53.prg_6000, info.prg.rom[chip].max.banks_8k) - prg_6000 = prg_chip_byte_pnt(chip, m53.prg_6000 << 13); + m53tmp.prg_6000 = prg_chip_byte_pnt(chip, m53.prg_6000 << 13); } else { m53.prg_6000 = (((m53.reg[0] << 4) & 0xF0) | 0x0F) + 4; _control_bank(m53.prg_6000, info.prg.rom[0].max.banks_8k) - prg_6000 = prg_chip_byte_pnt(0, m53.prg_6000 << 13); + m53tmp.prg_6000 = prg_chip_byte_pnt(0, m53.prg_6000 << 13); } } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_53.h puNES-0.105.new/src/core/mappers/mapper_53.h --- puNES-0.105.org/src/core/mappers/mapper_53.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_53.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _m53 { - BYTE reg[2]; - BYTE prg_6000; -} m53; - void map_init_53(void); void extcl_cpu_wr_mem_53(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_53(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_57.c puNES-0.105.new/src/core/mappers/mapper_57.c --- puNES-0.105.org/src/core/mappers/mapper_57.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_57.c 2020-03-18 11:47:29.368142648 +0100 @@ -22,6 +22,10 @@ #include "mem_map.h" #include "save_slot.h" +struct _m57 { + BYTE reg[2]; +} m57; + void map_init_57(void) { EXTCL_CPU_WR_MEM(57); EXTCL_SAVE_MAPPER(57); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_57.h puNES-0.105.new/src/core/mappers/mapper_57.h --- puNES-0.105.org/src/core/mappers/mapper_57.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_57.h 2020-03-18 11:47:29.368142648 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _m57 { - BYTE reg[2]; -} m57; - void map_init_57(void); void extcl_cpu_wr_mem_57(WORD address, BYTE value); BYTE extcl_save_mapper_57(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_60.c puNES-0.105.new/src/core/mappers/mapper_60.c --- puNES-0.105.org/src/core/mappers/mapper_60.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_60.c 2020-03-18 11:47:29.369142640 +0100 @@ -22,6 +22,12 @@ #include "save_slot.h" #include "cpu.h" +struct _m60 { + BYTE index; + // per la variante vt5201 + WORD address; +} m60; + void map_init_60(void) { EXTCL_CPU_WR_MEM(60); EXTCL_SAVE_MAPPER(60); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_60.h puNES-0.105.new/src/core/mappers/mapper_60.h --- puNES-0.105.org/src/core/mappers/mapper_60.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_60.h 2020-03-18 11:47:29.369142640 +0100 @@ -23,12 +23,6 @@ enum { MAP60, MAP60_VT5201 }; -struct _m60 { - BYTE index; - // per la variante vt5201 - WORD address; -} m60; - void map_init_60(void); void extcl_cpu_wr_mem_60(WORD address, BYTE value); BYTE extcl_save_mapper_60(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_74x161x161x32.c puNES-0.105.new/src/core/mappers/mapper_74x161x161x32.c --- puNES-0.105.org/src/core/mappers/mapper_74x161x161x32.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_74x161x161x32.c 2020-03-18 11:47:29.369142640 +0100 @@ -20,19 +20,21 @@ #include "info.h" #include "mem_map.h" -BYTE type; +struct _m74x161x161x32tmp { + BYTE type; +} m74x161x161x32tmp; void map_init_74x161x161x32(BYTE model) { EXTCL_CPU_WR_MEM(74x161x161x32); - type = model; + m74x161x161x32tmp.type = model; } void extcl_cpu_wr_mem_74x161x161x32(WORD address, BYTE value) { /* bus conflict */ const BYTE save = value &= prg_rom_rd(address); DBWORD bank; - if (type == IC74X161X161X32B) { + if (m74x161x161x32tmp.type == IC74X161X161X32B) { if (value & 0x80) { mirroring_SCR1(); } else { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_83.c puNES-0.105.new/src/core/mappers/mapper_83.c --- puNES-0.105.org/src/core/mappers/mapper_83.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_83.c 2020-03-18 11:47:29.369142640 +0100 @@ -25,6 +25,21 @@ INLINE static void sync_83(void); +struct _m83 { + BYTE is2kbank; + BYTE isnot2kbank; + BYTE mode; + BYTE bank; + BYTE dip; + BYTE low[4]; + BYTE reg[11]; + + struct _m83_irq { + BYTE active; + WORD count; + } irq; +} m83; + void map_init_83(void) { EXTCL_CPU_WR_MEM(83); EXTCL_CPU_RD_MEM(83); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_83.h puNES-0.105.new/src/core/mappers/mapper_83.h --- puNES-0.105.org/src/core/mappers/mapper_83.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_83.h 2020-03-18 11:47:29.369142640 +0100 @@ -23,21 +23,6 @@ enum { MAP83_REG0, MAP83_DGP }; -struct _m83 { - BYTE is2kbank; - BYTE isnot2kbank; - BYTE mode; - BYTE bank; - BYTE dip; - BYTE low[4]; - BYTE reg[11]; - - struct _m83_irq { - BYTE active; - WORD count; - } irq; -} m83; - void map_init_83(void); void extcl_cpu_wr_mem_83(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_83(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_8_IN_1.c puNES-0.105.new/src/core/mappers/mapper_8_IN_1.c --- puNES-0.105.org/src/core/mappers/mapper_8_IN_1.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_8_IN_1.c 2020-03-18 11:47:29.369142640 +0100 @@ -77,6 +77,12 @@ INLINE static void m8in1_update_chr(void break;\ } +struct _m8in1 { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} m8in1; + void map_init_8_IN_1(void) { EXTCL_CPU_WR_MEM(8_IN_1); EXTCL_SAVE_MAPPER(8_IN_1); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_8_IN_1.h puNES-0.105.new/src/core/mappers/mapper_8_IN_1.h --- puNES-0.105.org/src/core/mappers/mapper_8_IN_1.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_8_IN_1.h 2020-03-18 11:47:29.369142640 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _m8in1 { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} m8in1; - void map_init_8_IN_1(void); void extcl_cpu_wr_mem_8_IN_1(WORD address, BYTE value); BYTE extcl_save_mapper_8_IN_1(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_90_209_211.c puNES-0.105.new/src/core/mappers/mapper_90_209_211.c --- puNES-0.105.org/src/core/mappers/mapper_90_209_211.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_90_209_211.c 2020-03-18 11:47:29.369142640 +0100 @@ -43,6 +43,47 @@ INLINE static void irq_clock_count_90_20 ntbl.bank_1k[index] = &ntbl.data[value << 10];\ m90_209_211.nmt.write[index] = TRUE +struct _m90_209_211 { + BYTE mul[2]; + BYTE single_byte_ram; + BYTE tekker; + + BYTE mode[4]; + + BYTE prg[4]; + + struct _m90_209_211_chr { + BYTE latch[2]; + BYTE low[8]; + BYTE high[8]; + } chr; + + struct _m90_209_211_nmt { + BYTE extended_mode; + WORD reg[4]; + BYTE write[4]; + } nmt; + + struct _m90_209_211_irq { + BYTE active; + BYTE mode; + BYTE prescaler; + BYTE count; + BYTE xor_value; + BYTE pre_size; + BYTE premask; + } irq; + +/* questi non serve salvarli */ + BYTE model; + + struct _m90_209_211_m6000 { + WORD prg; + BYTE *rom_8k; + } m6000; +/* */ +} m90_209_211; + void map_init_90_209_211(BYTE model) { BYTE i; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_90_209_211.h puNES-0.105.new/src/core/mappers/mapper_90_209_211.h --- puNES-0.105.org/src/core/mappers/mapper_90_209_211.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_90_209_211.h 2020-03-18 11:47:29.369142640 +0100 @@ -27,47 +27,6 @@ enum { MAP211 }; -struct _m90_209_211 { - BYTE mul[2]; - BYTE single_byte_ram; - BYTE tekker; - - BYTE mode[4]; - - BYTE prg[4]; - - struct _m90_209_211_chr { - BYTE latch[2]; - BYTE low[8]; - BYTE high[8]; - } chr; - - struct _m90_209_211_nmt { - BYTE extended_mode; - WORD reg[4]; - BYTE write[4]; - } nmt; - - struct _m90_209_211_irq { - BYTE active; - BYTE mode; - BYTE prescaler; - BYTE count; - BYTE xor_value; - BYTE pre_size; - BYTE premask; - } irq; - -/* questi non serve salvarli */ - BYTE model; - - struct _m90_209_211_m6000 { - WORD prg; - BYTE *rom_8k; - } m6000; -/* */ -} m90_209_211; - void map_init_90_209_211(BYTE model); void extcl_cpu_wr_mem_90_209_211(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_90_209_211(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_91.c puNES-0.105.new/src/core/mappers/mapper_91.c --- puNES-0.105.org/src/core/mappers/mapper_91.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_91.c 2020-03-18 11:47:29.369142640 +0100 @@ -24,6 +24,13 @@ #include "cpu.h" #include "ppu.h" +struct _m91 { + struct _m91_irq { + BYTE active; + BYTE count; + } irq; +} m91; + void map_init_91(void) { EXTCL_CPU_WR_MEM(91); EXTCL_SAVE_MAPPER(91); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_91.h puNES-0.105.new/src/core/mappers/mapper_91.h --- puNES-0.105.org/src/core/mappers/mapper_91.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_91.h 2020-03-18 11:47:29.369142640 +0100 @@ -21,13 +21,6 @@ #include "common.h" -struct _m91 { - struct _m91_irq { - BYTE active; - BYTE count; - } irq; -} m91; - void map_init_91(void); void extcl_cpu_wr_mem_91(WORD address, BYTE value); BYTE extcl_save_mapper_91(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_AC08.c puNES-0.105.new/src/core/mappers/mapper_AC08.c --- puNES-0.105.org/src/core/mappers/mapper_AC08.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_AC08.c 2020-03-18 11:47:29.369142640 +0100 @@ -21,7 +21,12 @@ #include "mem_map.h" #include "save_slot.h" -BYTE *ac08_prg_6000; +struct _ac08 { + BYTE reg; +} ac08; +struct _ac08tmp { + BYTE *prg_6000; +} ac08tmp; void map_init_AC08(void) { EXTCL_CPU_WR_MEM(AC08); @@ -56,7 +61,7 @@ void extcl_cpu_wr_mem_AC08(WORD address, value = value & 0x0F; } control_bank(info.prg.rom[0].max.banks_8k) - ac08_prg_6000 = prg_chip_byte_pnt(0, value << 13); + ac08tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13); ac08.reg = value; return; } @@ -72,7 +77,7 @@ void extcl_cpu_wr_mem_AC08(WORD address, } BYTE extcl_cpu_rd_mem_AC08(WORD address, BYTE openbus, UNUSED(BYTE before)) { if ((address >= 0x6000) && (address <= 0x7FFF)) { - return (ac08_prg_6000[address & 0x1FFF]); + return (ac08tmp.prg_6000[address & 0x1FFF]); } return (openbus); } @@ -80,7 +85,7 @@ BYTE extcl_save_mapper_AC08(BYTE mode, B save_slot_ele(mode, slot, ac08.reg); if (mode == SAVE_SLOT_READ) { - ac08_prg_6000 = prg_chip_byte_pnt(0, ac08.reg << 13); + ac08tmp.prg_6000 = prg_chip_byte_pnt(0, ac08.reg << 13); } return (EXIT_OK); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_AC08.h puNES-0.105.new/src/core/mappers/mapper_AC08.h --- puNES-0.105.org/src/core/mappers/mapper_AC08.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_AC08.h 2020-03-18 11:47:29.369142640 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _ac08 { - BYTE reg; -} ac08; - void map_init_AC08(void); void extcl_cpu_wr_mem_AC08(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_AC08(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Active.c puNES-0.105.new/src/core/mappers/mapper_Active.c --- puNES-0.105.org/src/core/mappers/mapper_Active.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Active.c 2020-03-18 11:47:29.369142640 +0100 @@ -22,6 +22,11 @@ #include "mem_map.h" #include "save_slot.h" +struct _active { + BYTE openbus; + BYTE prg_ram[4]; +} active; + void map_init_Active(void) { EXTCL_CPU_WR_MEM(Active); EXTCL_CPU_RD_MEM(Active); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Active.h puNES-0.105.new/src/core/mappers/mapper_Active.h --- puNES-0.105.org/src/core/mappers/mapper_Active.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Active.h 2020-03-18 11:47:29.369142640 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _active { - BYTE openbus; - BYTE prg_ram[4]; -} active; - void map_init_Active(void); void extcl_cpu_wr_mem_Active(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_Active(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Ave.c puNES-0.105.new/src/core/mappers/mapper_Ave.c --- puNES-0.105.org/src/core/mappers/mapper_Ave.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Ave.c 2020-03-18 11:47:29.369142640 +0100 @@ -45,6 +45,10 @@ chr.bank_1k[7] = chr_chip_byte_pnt(0, bank | 0x1C00);\ } +struct _ave_d1012 { + BYTE reg[3]; +} ave_d1012; + void map_init_Ave(BYTE model) { switch (model) { case NINA06: diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Ave.h puNES-0.105.new/src/core/mappers/mapper_Ave.h --- puNES-0.105.org/src/core/mappers/mapper_Ave.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Ave.h 2020-03-18 11:47:29.369142640 +0100 @@ -23,10 +23,6 @@ enum { NINA06, D1012, PUZZLEUNL }; -struct _ave_d1012 { - BYTE reg[3]; -} ave_d1012; - void map_init_Ave(BYTE model); void extcl_cpu_wr_mem_Ave_NINA06(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_AX5705.c puNES-0.105.new/src/core/mappers/mapper_AX5705.c --- puNES-0.105.org/src/core/mappers/mapper_AX5705.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_AX5705.c 2020-03-18 11:47:29.369142640 +0100 @@ -33,6 +33,10 @@ value = (ax5705.chr_map[slot] & 0xF0) | (value & 0x0F);\ _ax5705_chr_rom_1k_update(slot) +struct _ax5705 { + WORD chr_map[8]; +} ax5705; + void map_init_AX5705(void) { EXTCL_CPU_WR_MEM(AX5705); EXTCL_SAVE_MAPPER(AX5705); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_AX5705.h puNES-0.105.new/src/core/mappers/mapper_AX5705.h --- puNES-0.105.org/src/core/mappers/mapper_AX5705.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_AX5705.h 2020-03-18 11:47:29.369142640 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _ax5705 { - WORD chr_map[8]; -} ax5705; - void map_init_AX5705(void); void extcl_cpu_wr_mem_AX5705(WORD address, BYTE value); BYTE extcl_save_mapper_AX5705(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Bandai.c puNES-0.105.new/src/core/mappers/mapper_Bandai.c --- puNES-0.105.org/src/core/mappers/mapper_Bandai.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Bandai.c 2020-03-18 11:47:29.371142623 +0100 @@ -24,9 +24,21 @@ #include "ppu.h" #include "save_slot.h" +enum { + MODE_IDLE, + MODE_DATA, + MODE_ADDRESS, + MODE_READ, + MODE_WRITE, + MODE_ACK, + MODE_NOT_ACK, + MODE_ACK_WAIT, + MODE_MAX +}; + #define b161x02x74_chr_4k_update()\ value = (save & 0x04) | (b161x02x74.chr_rom_bank & 0x03);\ - control_bank(chr_ram_4k_max)\ + control_bank(bandaitmp.chr_ram_4k_max)\ b161x02x74.chr_rom_bank = value;\ bank = value << 12;\ chr.bank_1k[0] = chr_chip_byte_pnt(0, bank);\ @@ -34,7 +46,7 @@ chr.bank_1k[2] = chr_chip_byte_pnt(0, bank | 0x0800);\ chr.bank_1k[3] = chr_chip_byte_pnt(0, bank | 0x0C00);\ value = (save & 0x04) | 0x03;\ - control_bank(chr_ram_4k_max)\ + control_bank(bandaitmp.chr_ram_4k_max)\ bank = value << 12;\ chr.bank_1k[4] = chr_chip_byte_pnt(0, bank);\ chr.bank_1k[5] = chr_chip_byte_pnt(0, bank | 0x0400);\ @@ -66,25 +78,41 @@ save_slot_ele(mode, slot, epr.rw);\ save_slot_ele(mode, slot, epr.output) -void e24C0x_set(BYTE scl, BYTE sda, _FCGXeeprom *eeprom); +typedef struct _FCGXeeprom { + BYTE eeprom[256]; + WORD size; + BYTE mode; + BYTE next; + BYTE bit; + BYTE address; + BYTE data; + BYTE scl; + BYTE sda; + BYTE rw; + BYTE output; +} _FCGXeeprom; -enum { - MODE_IDLE, - MODE_DATA, - MODE_ADDRESS, - MODE_READ, - MODE_WRITE, - MODE_ACK, - MODE_NOT_ACK, - MODE_ACK_WAIT, - MODE_MAX -}; +void e24C0x_set(BYTE scl, BYTE sda, _FCGXeeprom *eeprom); -WORD chr_ram_4k_max; -BYTE type; +struct _b161x02x74 { + BYTE chr_rom_bank; +} b161x02x74; +struct _FCGX { + BYTE reg[8]; + BYTE enabled; + WORD count; + WORD reload; + BYTE delay; + _FCGXeeprom e0; + _FCGXeeprom e1; +} FCGX; +struct _bandaitmp { + BYTE type; + WORD chr_ram_4k_max; +} bandaitmp; void map_init_Bandai(BYTE model) { - chr_ram_4k_max = info.chr.rom[0].banks_4k - 1; + bandaitmp.chr_ram_4k_max = info.chr.rom[0].banks_4k - 1; switch (model) { case B161X02X74: @@ -162,7 +190,7 @@ void map_init_Bandai(BYTE model) { break; } - type = model; + bandaitmp.type = model; } void extcl_cpu_wr_mem_Bandai_161x02x74(WORD address, BYTE value) { @@ -234,7 +262,7 @@ void extcl_cpu_wr_mem_Bandai_FCGX(WORD a value = FCGX.reg[slot]; } - if (type == DATACH) { + if (bandaitmp.type == DATACH) { datach_set_scl((value << 2) & 0x20); } if (!mapper.write_vram) { @@ -282,7 +310,7 @@ void extcl_cpu_wr_mem_Bandai_FCGX(WORD a case 0x800D: if (FCGX.e0.size) { e24C0x_set(value & 0x20, value & 0x40, &FCGX.e0); - if (type == DATACH) { + if (bandaitmp.type == DATACH) { datach_set_sda(value & 0x40); } } @@ -297,7 +325,7 @@ BYTE extcl_cpu_rd_mem_Bandai_FCGX(WORD a if (address & 0x0100) { BYTE value = FCGX.e0.output; - if (type == DATACH) { + if (bandaitmp.type == DATACH) { value &= FCGX.e1.output; } return (value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Bandai.h puNES-0.105.new/src/core/mappers/mapper_Bandai.h --- puNES-0.105.org/src/core/mappers/mapper_Bandai.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Bandai.h 2020-03-18 11:47:29.371142623 +0100 @@ -30,32 +30,6 @@ enum { FAMICOMJUMPII = 100 }; -typedef struct { - BYTE eeprom[256]; - WORD size; - BYTE mode; - BYTE next; - BYTE bit; - BYTE address; - BYTE data; - BYTE scl; - BYTE sda; - BYTE rw; - BYTE output; -} _FCGXeeprom; -struct _b161x02x74 { - BYTE chr_rom_bank; -} b161x02x74; -struct _FCGX { - BYTE reg[8]; - BYTE enabled; - WORD count; - WORD reload; - BYTE delay; - _FCGXeeprom e0; - _FCGXeeprom e1; -} FCGX; - void map_init_Bandai(BYTE model); void extcl_cpu_wr_mem_Bandai_161x02x74(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BB.c puNES-0.105.new/src/core/mappers/mapper_BB.c --- puNES-0.105.org/src/core/mappers/mapper_BB.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BB.c 2020-03-18 11:47:29.370142631 +0100 @@ -21,7 +21,12 @@ #include "info.h" #include "save_slot.h" -BYTE *bb_prg_6000; +struct _bb { + BYTE reg; +} bb; +struct _bbtmp { + BYTE *prg_6000; +} bbtmp; void map_init_BB(void) { EXTCL_CPU_WR_MEM(BB); @@ -39,7 +44,7 @@ void map_init_BB(void) { bb.reg = 0xFF; _control_bank(bb.reg, info.prg.rom[0].max.banks_8k) - bb_prg_6000 = prg_chip_byte_pnt(0, bb.reg << 13); + bbtmp.prg_6000 = prg_chip_byte_pnt(0, bb.reg << 13); } void extcl_cpu_wr_mem_BB(WORD address, BYTE value) { BYTE save = value; @@ -48,7 +53,7 @@ void extcl_cpu_wr_mem_BB(WORD address, B if ((address & 0x9000) == 0x8000) { value = value & 0x03; control_bank(info.prg.rom[0].max.banks_8k) - bb_prg_6000 = prg_chip_byte_pnt(0, value << 13); + bbtmp.prg_6000 = prg_chip_byte_pnt(0, value << 13); bb.reg = value; value = save; } else { @@ -68,7 +73,7 @@ void extcl_cpu_wr_mem_BB(WORD address, B } BYTE extcl_cpu_rd_mem_BB(WORD address, BYTE openbus, UNUSED(BYTE before)) { if ((address >= 0x6000) && (address <= 0x7FFF)) { - return (bb_prg_6000[address & 0x1FFF]); + return (bbtmp.prg_6000[address & 0x1FFF]); } return (openbus); } @@ -76,7 +81,7 @@ BYTE extcl_save_mapper_BB(BYTE mode, BYT save_slot_ele(mode, slot, bb.reg); if (mode == SAVE_SLOT_READ) { - bb_prg_6000 = prg_chip_byte_pnt(0, bb.reg << 13); + bbtmp.prg_6000 = prg_chip_byte_pnt(0, bb.reg << 13); } return (EXIT_OK); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BB.h puNES-0.105.new/src/core/mappers/mapper_BB.h --- puNES-0.105.org/src/core/mappers/mapper_BB.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BB.h 2020-03-18 11:47:29.370142631 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _bb { - BYTE reg; -} bb; - void map_init_BB(void); void extcl_cpu_wr_mem_BB(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_BB(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC12IN1.c puNES-0.105.new/src/core/mappers/mapper_BMC12IN1.c --- puNES-0.105.org/src/core/mappers/mapper_BMC12IN1.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC12IN1.c 2020-03-18 11:47:29.370142631 +0100 @@ -22,6 +22,10 @@ #include "mem_map.h" #include "save_slot.h" +struct _bmc12in1 { + BYTE reg[3]; +} bmc12in1; + void map_init_BMC12IN1(void) { EXTCL_CPU_WR_MEM(BMC12IN1); EXTCL_SAVE_MAPPER(BMC12IN1); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC12IN1.h puNES-0.105.new/src/core/mappers/mapper_BMC12IN1.h --- puNES-0.105.org/src/core/mappers/mapper_BMC12IN1.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC12IN1.h 2020-03-18 11:47:29.370142631 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _bmc12in1 { - BYTE reg[3]; -} bmc12in1; - void map_init_BMC12IN1(void); void extcl_cpu_wr_mem_BMC12IN1(WORD address, BYTE value); BYTE extcl_save_mapper_BMC12IN1(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC411120C.c puNES-0.105.new/src/core/mappers/mapper_BMC411120C.c --- puNES-0.105.org/src/core/mappers/mapper_BMC411120C.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC411120C.c 2020-03-18 11:47:29.370142631 +0100 @@ -80,7 +80,14 @@ INLINE static void bmc411120c_update_chr break;\ } -BYTE bmc411120c_reset; +struct _bmc411120c { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} bmc411120c; +struct _bmc411120ctmp { + BYTE reset; +} bmc411120ctmp; void map_init_BMC411120C(void) { EXTCL_CPU_WR_MEM(BMC411120C); @@ -115,9 +122,9 @@ void map_init_BMC411120C(void) { } if (info.reset >= HARD) { - bmc411120c_reset = 0; + bmc411120ctmp.reset = 0; } else if (info.reset == RESET) { - bmc411120c_reset ^= 0x04; + bmc411120ctmp.reset ^= 0x04; } bmc411120c_update_prg(); @@ -170,7 +177,7 @@ BYTE extcl_save_mapper_BMC411120C(BYTE m INLINE static void bmc411120c_update_prg(void) { BYTE value; - if (bmc411120c.reg & (0x08 | bmc411120c_reset)) { + if (bmc411120c.reg & (0x08 | bmc411120ctmp.reset)) { value = 0x0C | ((bmc411120c.reg >> 4) & 0x03); control_bank(info.prg.rom[0].max.banks_32k) map_prg_rom_8k(4, 0, value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC411120C.h puNES-0.105.new/src/core/mappers/mapper_BMC411120C.h --- puNES-0.105.org/src/core/mappers/mapper_BMC411120C.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC411120C.h 2020-03-18 11:47:29.370142631 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _bmc411120c { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} bmc411120c; - void map_init_BMC411120C(void); void extcl_cpu_wr_mem_BMC411120C(WORD address, BYTE value); BYTE extcl_save_mapper_BMC411120C(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC64IN1NOREPEAT.c puNES-0.105.new/src/core/mappers/mapper_BMC64IN1NOREPEAT.c --- puNES-0.105.org/src/core/mappers/mapper_BMC64IN1NOREPEAT.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC64IN1NOREPEAT.c 2020-03-18 11:47:29.370142631 +0100 @@ -27,6 +27,10 @@ INLINE static void bmc64in1norepeat_upda #define bmc64in1norepeat_prg_8k()\ ((bmc64in1norepeat.reg[1] & 0x1F) << 1) | ((bmc64in1norepeat.reg[1] >> 6) & 0x01); +struct _bmc64in1norepeat { + BYTE reg[4]; +} bmc64in1norepeat; + void map_init_BMC64IN1NOREPEAT(void) { EXTCL_CPU_WR_MEM(BMC64IN1NOREPEAT); EXTCL_SAVE_MAPPER(BMC64IN1NOREPEAT); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC64IN1NOREPEAT.h puNES-0.105.new/src/core/mappers/mapper_BMC64IN1NOREPEAT.h --- puNES-0.105.org/src/core/mappers/mapper_BMC64IN1NOREPEAT.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC64IN1NOREPEAT.h 2020-03-18 11:47:29.370142631 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _bmc64in1norepeat { - BYTE reg[4]; -} bmc64in1norepeat; - void map_init_BMC64IN1NOREPEAT(void); void extcl_cpu_wr_mem_BMC64IN1NOREPEAT(WORD address, BYTE value); BYTE extcl_save_mapper_BMC64IN1NOREPEAT(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC70IN1.c puNES-0.105.new/src/core/mappers/mapper_BMC70IN1.c --- puNES-0.105.org/src/core/mappers/mapper_BMC70IN1.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC70IN1.c 2020-03-18 11:47:29.370142631 +0100 @@ -22,7 +22,13 @@ #include "mem_map.h" #include "save_slot.h" -BYTE bmc70in1_reset, bmc70in1_type; +struct _bmc70in1 { + WORD reg[3]; +} bmc70in1; +struct _bmc70in1tmp { + BYTE type; + BYTE reset; +} bmc70in1tmp; void map_init_BMC70IN1(BYTE type) { EXTCL_CPU_WR_MEM(BMC70IN1); @@ -37,16 +43,16 @@ void map_init_BMC70IN1(BYTE type) { if (info.reset >= HARD) { if (type == BMC70IN1) { - bmc70in1_reset = 0x0D; + bmc70in1tmp.reset = 0x0D; } else { - bmc70in1_reset = 0x06; + bmc70in1tmp.reset = 0x06; } } else if (info.reset == RESET) { - bmc70in1_reset++; - bmc70in1_reset = bmc70in1_reset & 0x0F; + bmc70in1tmp.reset++; + bmc70in1tmp.reset = bmc70in1tmp.reset & 0x0F; } - bmc70in1_type = type; + bmc70in1tmp.type = type; info.mapper.extend_rd = TRUE; extcl_cpu_wr_mem_BMC70IN1(0x0000, 0); @@ -62,7 +68,7 @@ void extcl_cpu_wr_mem_BMC70IN1(WORD addr mirroring_V(); } - if (bmc70in1_type == BMC70IN1B) { + if (bmc70in1tmp.type == BMC70IN1B) { bmc70in1.reg[2] = (address & 0x03) << 3; } else { DBWORD bank; @@ -108,7 +114,7 @@ void extcl_cpu_wr_mem_BMC70IN1(WORD addr } BYTE extcl_cpu_rd_mem_BMC70IN1(WORD address, BYTE openbus, UNUSED(BYTE before)) { if ((address >= 0x8000) && (bmc70in1.reg[0] == 0x10)) { - address = (address & 0xFFF0) | bmc70in1_reset; + address = (address & 0xFFF0) | bmc70in1tmp.reset; return (prg_rom_rd(address)); } return (openbus); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC70IN1.h puNES-0.105.new/src/core/mappers/mapper_BMC70IN1.h --- puNES-0.105.org/src/core/mappers/mapper_BMC70IN1.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC70IN1.h 2020-03-18 11:47:29.370142631 +0100 @@ -23,10 +23,6 @@ enum _bmc70in1_type { BMC70IN1, BMC70IN1B }; -struct _bmc70in1 { - WORD reg[3]; -} bmc70in1; - void map_init_BMC70IN1(BYTE type); void extcl_cpu_wr_mem_BMC70IN1(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_BMC70IN1(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC830118C.c puNES-0.105.new/src/core/mappers/mapper_BMC830118C.c --- puNES-0.105.org/src/core/mappers/mapper_BMC830118C.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC830118C.c 2020-03-18 11:47:29.370142631 +0100 @@ -80,6 +80,12 @@ INLINE static void bmc830118c_update_chr break;\ } +struct _bmc830118c { + BYTE reg; + WORD prg_map[4]; + WORD chr_map[8]; +} bmc830118c; + void map_init_BMC830118C(void) { EXTCL_CPU_WR_MEM(BMC830118C); EXTCL_SAVE_MAPPER(BMC830118C); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMC830118C.h puNES-0.105.new/src/core/mappers/mapper_BMC830118C.h --- puNES-0.105.org/src/core/mappers/mapper_BMC830118C.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMC830118C.h 2020-03-18 11:47:29.370142631 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _bmc830118c { - BYTE reg; - WORD prg_map[4]; - WORD chr_map[8]; -} bmc830118c; - void map_init_BMC830118C(void); void extcl_cpu_wr_mem_BMC830118C(WORD address, BYTE value); BYTE extcl_save_mapper_BMC830118C(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMCFK23C.c puNES-0.105.new/src/core/mappers/mapper_BMCFK23C.c --- puNES-0.105.org/src/core/mappers/mapper_BMCFK23C.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMCFK23C.c 2020-03-18 11:47:29.370142631 +0100 @@ -28,6 +28,18 @@ static void prg_swap_BMCFK23CPW(WORD add static void chr_fix_BMCFK23CPW(BYTE value); static void chr_swap_BMCFK23CCW(WORD address, WORD value); +struct _bmcfk23c { + uint32_t dipswitch; + BYTE unromchr; + BYTE A000; + BYTE A001; + BYTE reg[8]; + BYTE mmc3[8]; + WORD chr_map[8]; + /* questo posso tranquillamente non salvarlo */ + BYTE prg_mask; +} bmcfk23c; + void map_init_BMCFK23C(void) { EXTCL_CPU_WR_MEM(BMCFK23C); EXTCL_SAVE_MAPPER(BMCFK23C); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMCFK23C.h puNES-0.105.new/src/core/mappers/mapper_BMCFK23C.h --- puNES-0.105.org/src/core/mappers/mapper_BMCFK23C.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMCFK23C.h 2020-03-18 11:47:29.370142631 +0100 @@ -23,18 +23,6 @@ enum bmcfk23c_types { NOBMCFK23C, BMCFK23C_0 = 1, BMCFK23C_1 = 2, BMCFK23CA = 8 }; -struct _bmcfk23c { - uint32_t dipswitch; - BYTE unromchr; - BYTE A000; - BYTE A001; - BYTE reg[8]; - BYTE mmc3[8]; - WORD chr_map[8]; - /* questo posso tranquillamente non salvarlo */ - BYTE prg_mask; -} bmcfk23c; - void map_init_BMCFK23C(void); void extcl_cpu_wr_mem_BMCFK23C(WORD address, BYTE value); void extcl_wr_chr_BMCFK23C(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMCGhostbusters63in1.c puNES-0.105.new/src/core/mappers/mapper_BMCGhostbusters63in1.c --- puNES-0.105.org/src/core/mappers/mapper_BMCGhostbusters63in1.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMCGhostbusters63in1.c 2020-03-18 11:47:29.370142631 +0100 @@ -25,6 +25,10 @@ INLINE static void bmcghostbusters63in1_update_chr(void); +struct _bmcghostbusters63in1 { + BYTE reg[2]; + BYTE index; +} bmcghostbusters63in1; static const BYTE bmcghostbusters63in1_chip[4] = { 0, 0, 1, 2 }; void map_init_BMCGHOSTBUSTERS63IN1(void) { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BMCGhostbusters63in1.h puNES-0.105.new/src/core/mappers/mapper_BMCGhostbusters63in1.h --- puNES-0.105.org/src/core/mappers/mapper_BMCGhostbusters63in1.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BMCGhostbusters63in1.h 2020-03-18 11:47:29.370142631 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _bmcghostbusters63in1 { - BYTE reg[2]; - BYTE index; -} bmcghostbusters63in1; - void map_init_BMCGHOSTBUSTERS63IN1(void); void extcl_cpu_wr_mem_BMCGHOSTBUSTERS63IN1(WORD address, BYTE value); //BYTE extcl_cpu_rd_mem_BMCGHOSTBUSTERS63IN1(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BOY.c puNES-0.105.new/src/core/mappers/mapper_BOY.c --- puNES-0.105.org/src/core/mappers/mapper_BOY.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BOY.c 2020-03-18 11:47:29.370142631 +0100 @@ -77,6 +77,12 @@ INLINE static void boy_update_chr(void); break;\ } +struct _boy { + BYTE reg[4]; + WORD prg_map[4]; + WORD chr_map[8]; +} boy; + void map_init_BOY(void) { EXTCL_CPU_WR_MEM(BOY); EXTCL_SAVE_MAPPER(BOY); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BOY.h puNES-0.105.new/src/core/mappers/mapper_BOY.h --- puNES-0.105.org/src/core/mappers/mapper_BOY.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BOY.h 2020-03-18 11:47:29.370142631 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _boy { - BYTE reg[4]; - WORD prg_map[4]; - WORD chr_map[8]; -} boy; - void map_init_BOY(void); void extcl_cpu_wr_mem_BOY(WORD address, BYTE value); BYTE extcl_save_mapper_BOY(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_BS5.c puNES-0.105.new/src/core/mappers/mapper_BS5.c --- puNES-0.105.org/src/core/mappers/mapper_BS5.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_BS5.c 2020-03-18 11:47:29.370142631 +0100 @@ -21,7 +21,9 @@ #include "info.h" #include "mem_map.h" -BYTE bs5_reset; +struct _bs5mp { + BYTE reset; +} bs5tmp; void map_init_BS5(void) { EXTCL_CPU_WR_MEM(BS5); @@ -35,10 +37,10 @@ void map_init_BS5(void) { } if (info.reset >= HARD) { - bs5_reset = 0; + bs5tmp.reset = 0; } else if (info.reset == RESET) { - bs5_reset++; - bs5_reset = bs5_reset & 0x03; + bs5tmp.reset++; + bs5tmp.reset = bs5tmp.reset & 0x03; } mirroring_V(); @@ -59,7 +61,7 @@ void extcl_cpu_wr_mem_BS5(WORD address, return; } case 0xA000: - if (address & (1 << (bs5_reset + 4))) { + if (address & (1 << (bs5tmp.reset + 4))) { value = address & 0x0F; control_bank(info.prg.rom[0].max.banks_8k) map_prg_rom_8k(1, base, value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Caltron.c puNES-0.105.new/src/core/mappers/mapper_Caltron.c --- puNES-0.105.org/src/core/mappers/mapper_Caltron.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Caltron.c 2020-03-18 11:47:29.371142623 +0100 @@ -21,6 +21,10 @@ #include "mem_map.h" #include "save_slot.h" +struct _caltron { + BYTE reg; +} caltron; + void map_init_Caltron(void) { EXTCL_CPU_WR_MEM(Caltron); mapper.internal_struct[0] = (BYTE *) &caltron; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Caltron.h puNES-0.105.new/src/core/mappers/mapper_Caltron.h --- puNES-0.105.org/src/core/mappers/mapper_Caltron.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Caltron.h 2020-03-18 11:47:29.371142623 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _caltron { - BYTE reg; -} caltron; - void map_init_Caltron(void); void extcl_cpu_wr_mem_Caltron(WORD address, BYTE value); BYTE extcl_save_mapper_Caltron(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_CITYFIGHT.c puNES-0.105.new/src/core/mappers/mapper_CITYFIGHT.c --- puNES-0.105.org/src/core/mappers/mapper_CITYFIGHT.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_CITYFIGHT.c 2020-03-18 11:47:29.371142623 +0100 @@ -31,6 +31,15 @@ INLINE static void cityfight_prg_update(void); +struct _cityfight { + BYTE reg[2]; + WORD chr_map[8]; + struct _cityfight_irq { + BYTE enable; + WORD count; + } irq; +} cityfight; + void map_init_CITYFIGHT(void) { EXTCL_CPU_WR_MEM(CITYFIGHT); EXTCL_SAVE_MAPPER(CITYFIGHT); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_CITYFIGHT.h puNES-0.105.new/src/core/mappers/mapper_CITYFIGHT.h --- puNES-0.105.org/src/core/mappers/mapper_CITYFIGHT.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_CITYFIGHT.h 2020-03-18 11:47:29.371142623 +0100 @@ -21,15 +21,6 @@ #include "common.h" -struct _cityfight { - BYTE reg[2]; - WORD chr_map[8]; - struct _cityfight_irq { - BYTE enable; - WORD count; - } irq; -} cityfight; - void map_init_CITYFIGHT(void); void extcl_cpu_wr_mem_CITYFIGHT(WORD address, BYTE value); BYTE extcl_save_mapper_CITYFIGHT(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_CNROM.c puNES-0.105.new/src/core/mappers/mapper_CNROM.c --- puNES-0.105.org/src/core/mappers/mapper_CNROM.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_CNROM.c 2020-03-18 11:47:29.371142623 +0100 @@ -22,12 +22,18 @@ #include "mem_map.h" #include "save_slot.h" -BYTE mask, state; +struct _cnrom_2627 { + BYTE chr_rd_enable; +} cnrom_2627; +struct _cnromtmp { + BYTE mask; + BYTE state; +} cnromtmp; void map_init_CNROM() { EXTCL_CPU_WR_MEM(CNROM); - mask = state = 0x00; + cnromtmp.mask = cnromtmp.state = 0x00; /* * "Cybernoid - The Fighting Machine (U) [!].nes" vuole @@ -41,20 +47,20 @@ void map_init_CNROM() { mapper.internal_struct_size[0] = sizeof(cnrom_2627); memset(&cnrom_2627, 0x00, sizeof(cnrom_2627)); - mask = 0x03; + cnromtmp.mask = 0x03; switch (info.id) { case CNROM_26CE27CE: - state = 0x03; + cnromtmp.state = 0x03; break; case CNROM_26CE27NCE: - state = 0x01; + cnromtmp.state = 0x01; break; case CNROM_26NCE27CE: - state = 0x02; + cnromtmp.state = 0x02; break; case CNROM_26NCE27NCE: - state = 0x00; + cnromtmp.state = 0x00; break; } } @@ -67,13 +73,13 @@ void extcl_cpu_wr_mem_CNROM(WORD address value &= prg_rom_rd(address); } - if (mask) { - if ((value & mask) == state) { + if (cnromtmp.mask) { + if ((value & cnromtmp.mask) == cnromtmp.state) { cnrom_2627.chr_rd_enable = FALSE; } else { cnrom_2627.chr_rd_enable = TRUE; } - value &= ~mask; + value &= ~cnromtmp.mask; } control_bank(info.chr.rom[0].max.banks_8k) diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_CNROM.h puNES-0.105.new/src/core/mappers/mapper_CNROM.h --- puNES-0.105.org/src/core/mappers/mapper_CNROM.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_CNROM.h 2020-03-18 11:47:29.371142623 +0100 @@ -30,10 +30,6 @@ enum { BAD_INES_TETRIS_BPS = 20 }; -struct _cnrom_2627 { - BYTE chr_rd_enable; -} cnrom_2627; - void map_init_CNROM(); void extcl_cpu_wr_mem_CNROM(WORD address, BYTE value); BYTE extcl_save_mapper_CNROM(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_DRAGONFIGHTER.c puNES-0.105.new/src/core/mappers/mapper_DRAGONFIGHTER.c --- puNES-0.105.org/src/core/mappers/mapper_DRAGONFIGHTER.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_DRAGONFIGHTER.c 2020-03-18 11:47:29.371142623 +0100 @@ -77,6 +77,12 @@ INLINE static void dragonfighter_update_ break;\ } +struct _dragonfighter { + BYTE reg[3]; + WORD prg_map[4]; + WORD chr_map[8]; +} dragonfighter; + void map_init_DRAGONFIGHTER(void) { EXTCL_CPU_WR_MEM(DRAGONFIGHTER); EXTCL_CPU_RD_MEM(DRAGONFIGHTER); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_DRAGONFIGHTER.h puNES-0.105.new/src/core/mappers/mapper_DRAGONFIGHTER.h --- puNES-0.105.org/src/core/mappers/mapper_DRAGONFIGHTER.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_DRAGONFIGHTER.h 2020-03-18 11:47:29.371142623 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _dragonfighter { - BYTE reg[3]; - WORD prg_map[4]; - WORD chr_map[8]; -} dragonfighter; - void map_init_DRAGONFIGHTER(void); void extcl_cpu_wr_mem_DRAGONFIGHTER(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_DRAGONFIGHTER(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_DREAMTECH01.c puNES-0.105.new/src/core/mappers/mapper_DREAMTECH01.c --- puNES-0.105.org/src/core/mappers/mapper_DREAMTECH01.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_DREAMTECH01.c 2020-03-18 11:47:29.371142623 +0100 @@ -29,7 +29,6 @@ void map_init_DREAMTECH01(void) { map_prg_rom_8k(2, 0, 8); //} } - void extcl_cpu_wr_mem_DREAMTECH01(WORD address, BYTE value) { if (address != 0x5020) { return; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_DREAMTECH01.h puNES-0.105.new/src/core/mappers/mapper_DREAMTECH01.h --- puNES-0.105.org/src/core/mappers/mapper_DREAMTECH01.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_DREAMTECH01.h 2020-03-18 11:47:29.371142623 +0100 @@ -22,7 +22,6 @@ #include "common.h" void map_init_DREAMTECH01(void); - void extcl_cpu_wr_mem_DREAMTECH01(WORD address, BYTE value); #endif /* MAPPER_DREAMTECH01_H_ */ diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_EDU2000.c puNES-0.105.new/src/core/mappers/mapper_EDU2000.c --- puNES-0.105.org/src/core/mappers/mapper_EDU2000.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_EDU2000.c 2020-03-18 11:47:29.371142623 +0100 @@ -22,6 +22,11 @@ #include "mem_map.h" #include "save_slot.h" +struct _edu2000 { + BYTE reg; + uint32_t prg_ram_address; +} edu2000; + void map_init_EDU2000(void) { EXTCL_CPU_WR_MEM(EDU2000); EXTCL_CPU_RD_MEM(EDU2000); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_EDU2000.h puNES-0.105.new/src/core/mappers/mapper_EDU2000.h --- puNES-0.105.org/src/core/mappers/mapper_EDU2000.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_EDU2000.h 2020-03-18 11:47:29.371142623 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _edu2000 { - BYTE reg; - uint32_t prg_ram_address; -} edu2000; - void map_init_EDU2000(void); void extcl_cpu_wr_mem_EDU2000(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_EDU2000(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_EH8813A.c puNES-0.105.new/src/core/mappers/mapper_EH8813A.c --- puNES-0.105.org/src/core/mappers/mapper_EH8813A.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_EH8813A.c 2020-03-18 11:47:29.371142623 +0100 @@ -21,6 +21,11 @@ #include "mem_map.h" #include "save_slot.h" +struct _eh8813a { + WORD address; + BYTE hwmode; +} eh88131a; + void map_init_EH8813A(void) { EXTCL_CPU_WR_MEM(EH8813A); EXTCL_CPU_RD_MEM(EH8813A); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_EH8813A.h puNES-0.105.new/src/core/mappers/mapper_EH8813A.h --- puNES-0.105.org/src/core/mappers/mapper_EH8813A.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_EH8813A.h 2020-03-18 11:47:29.371142623 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _eh8813a { - WORD address; - BYTE hwmode; -} eh88131a; - void map_init_EH8813A(void); void extcl_cpu_wr_mem_EH8813A(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_EH8813A(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_FS304.c puNES-0.105.new/src/core/mappers/mapper_FS304.c --- puNES-0.105.org/src/core/mappers/mapper_FS304.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_FS304.c 2020-03-18 11:47:29.371142623 +0100 @@ -20,6 +20,10 @@ #include "info.h" #include "save_slot.h" +struct _fs304 { + BYTE reg[4]; +} fs304; + void map_init_FS304(void) { EXTCL_CPU_WR_MEM(FS304); EXTCL_SAVE_MAPPER(FS304); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_FS304.h puNES-0.105.new/src/core/mappers/mapper_FS304.h --- puNES-0.105.org/src/core/mappers/mapper_FS304.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_FS304.h 2020-03-18 11:47:29.371142623 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _fs304 { - BYTE reg[4]; -} fs304; - void map_init_FS304(void); void extcl_cpu_wr_mem_FS304(WORD address, BYTE value); BYTE extcl_save_mapper_FS304(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Futuremedia.c puNES-0.105.new/src/core/mappers/mapper_Futuremedia.c --- puNES-0.105.org/src/core/mappers/mapper_Futuremedia.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Futuremedia.c 2020-03-18 11:47:29.371142623 +0100 @@ -23,6 +23,10 @@ #include "irqA12.h" #include "save_slot.h" +struct _futuremedia { + BYTE delay; +} futuremedia; + void map_init_Futuremedia(void) { EXTCL_CPU_WR_MEM(Futuremedia); EXTCL_SAVE_MAPPER(Futuremedia); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Futuremedia.h puNES-0.105.new/src/core/mappers/mapper_Futuremedia.h --- puNES-0.105.org/src/core/mappers/mapper_Futuremedia.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Futuremedia.h 2020-03-18 11:47:29.372142615 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _futuremedia { - BYTE delay; -} futuremedia; - void map_init_Futuremedia(void); void extcl_cpu_wr_mem_Futuremedia(WORD address, BYTE value); BYTE extcl_save_mapper_Futuremedia(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_GS_2004.c puNES-0.105.new/src/core/mappers/mapper_GS_2004.c --- puNES-0.105.org/src/core/mappers/mapper_GS_2004.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_GS_2004.c 2020-03-18 11:47:29.372142615 +0100 @@ -20,7 +20,9 @@ #include "mem_map.h" #include "info.h" -BYTE *gs_2004_prg_6000; +struct _gs2004tmp { + BYTE *prg_6000; +} gs2004tmp; void map_init_GS_2004(void) { EXTCL_CPU_WR_MEM(GS_2004); @@ -33,7 +35,7 @@ void map_init_GS_2004(void) { map_prg_rom_8k(4, 0, value); } - gs_2004_prg_6000 = prg_chip_byte_pnt(1, 0); + gs2004tmp.prg_6000 = prg_chip_byte_pnt(1, 0); } void extcl_cpu_wr_mem_GS_2004(UNUSED(WORD address), BYTE value) { control_bank(info.prg.rom[0].max.banks_32k) @@ -42,7 +44,7 @@ void extcl_cpu_wr_mem_GS_2004(UNUSED(WOR } BYTE extcl_cpu_rd_mem_GS_2004(WORD address, BYTE openbus, UNUSED(BYTE before)) { if ((address >= 0x6000) && (address <= 0x7FFF)) { - return (gs_2004_prg_6000[address & 0x1FFF]); + return (gs2004tmp.prg_6000[address & 0x1FFF]); } return (openbus); } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_GS_2013.c puNES-0.105.new/src/core/mappers/mapper_GS_2013.c --- puNES-0.105.org/src/core/mappers/mapper_GS_2013.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_GS_2013.c 2020-03-18 11:47:29.372142615 +0100 @@ -20,7 +20,9 @@ #include "mem_map.h" #include "info.h" -BYTE *gs_2013_prg_6000; +struct _gs2013tmp { + BYTE *prg_6000; +} gs2013tmp; void map_init_GS_2013(void) { EXTCL_CPU_WR_MEM(GS_2013); @@ -31,7 +33,7 @@ void map_init_GS_2013(void) { value = 0xFF; control_bank(info.prg.rom[0].max.banks_8k) - gs_2013_prg_6000 = prg_chip_byte_pnt(0, value << 13); + gs2013tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13); } extcl_cpu_wr_mem_GS_2013(0x0000, 0xFF); @@ -46,7 +48,7 @@ void extcl_cpu_wr_mem_GS_2013(UNUSED(WOR } BYTE extcl_cpu_rd_mem_GS_2013(WORD address, BYTE openbus, UNUSED(BYTE before)) { if ((address >= 0x6000) && (address <= 0x7FFF)) { - return (gs_2013_prg_6000[address & 0x1FFF]); + return (gs2013tmp.prg_6000[address & 0x1FFF]); } return (openbus); } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_H2288.c puNES-0.105.new/src/core/mappers/mapper_H2288.c --- puNES-0.105.org/src/core/mappers/mapper_H2288.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_H2288.c 2020-03-18 11:49:55.295890150 +0100 @@ -1,209 +1,215 @@ -/* - * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include -#include "mappers.h" -#include "info.h" -#include "mem_map.h" -#include "cpu.h" -#include "irqA12.h" -#include "save_slot.h" - -INLINE static void h2288_update_prg(void); -INLINE static void h2288_update_chr(void); - -#define h2288_chr_1k(vl) value = vl -#define h2288_prg_8k(vl) value = (vl & 0x3F) -#define h2288_swap_chr_1k(a, b)\ - chr1k = h2288.chr_map[b];\ - h2288.chr_map[b] = h2288.chr_map[a];\ - h2288.chr_map[a] = chr1k -#define h2288_8000()\ - if (mmc3.chr_rom_cfg != old_chr_rom_cfg) {\ - BYTE chr1k;\ - h2288_swap_chr_1k(0, 4);\ - h2288_swap_chr_1k(1, 5);\ - h2288_swap_chr_1k(2, 6);\ - h2288_swap_chr_1k(3, 7);\ - }\ - if (mmc3.prg_rom_cfg != old_prg_rom_cfg) {\ - mapper.rom_map_to[2] = h2288.prg_map[0];\ - mapper.rom_map_to[0] = h2288.prg_map[2];\ - h2288.prg_map[0] = mapper.rom_map_to[0];\ - h2288.prg_map[2] = mapper.rom_map_to[2];\ - h2288.prg_map[mmc3.prg_rom_cfg ^ 0x02] = info.prg.rom[0].max.banks_8k_before_last;\ - } -#define h2288_8001()\ - switch (mmc3.bank_to_update) {\ - case 0:\ - control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\ - h2288.chr_map[mmc3.chr_rom_cfg] = value;\ - h2288.chr_map[mmc3.chr_rom_cfg | 0x01] = value + 1;\ - break;\ - case 1:\ - control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\ - h2288.chr_map[mmc3.chr_rom_cfg | 0x02] = value;\ - h2288.chr_map[mmc3.chr_rom_cfg | 0x03] = value + 1;\ - break;\ - case 2:\ - h2288.chr_map[mmc3.chr_rom_cfg ^ 0x04] = value;\ - break;\ - case 3:\ - h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x01] = value;\ - break;\ - case 4:\ - h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x02] = value;\ - break;\ - case 5:\ - h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x03] = value;\ - break;\ - case 6:\ - h2288.prg_map[mmc3.prg_rom_cfg] = value;\ - break;\ - case 7:\ - h2288.prg_map[1] = value;\ - break;\ - } - -void map_init_H2288(void) { - EXTCL_CPU_WR_MEM(H2288); - EXTCL_SAVE_MAPPER(H2288); - EXTCL_CPU_EVERY_CYCLE(MMC3); - EXTCL_PPU_000_TO_34X(MMC3); - EXTCL_PPU_000_TO_255(MMC3); - EXTCL_PPU_256_TO_319(MMC3); - EXTCL_PPU_320_TO_34X(MMC3); - EXTCL_UPDATE_R2006(MMC3); - mapper.internal_struct[0] = (BYTE *) &h2288; - mapper.internal_struct_size[0] = sizeof(h2288); - mapper.internal_struct[1] = (BYTE *) &mmc3; - mapper.internal_struct_size[1] = sizeof(mmc3); - - memset(&h2288, 0x00, sizeof(h2288)); - memset(&mmc3, 0x00, sizeof(mmc3)); - memset(&irqA12, 0x00, sizeof(irqA12)); - - { - BYTE i; - - map_prg_rom_8k_reset(); - map_chr_bank_1k_reset(); - - for (i = 0; i < 8; i++) { - if (i < 4) { - h2288.prg_map[i] = mapper.rom_map_to[i]; - } - h2288.chr_map[i] = i; - } - } - - h2288_update_prg(); - h2288_update_chr(); - - info.mapper.extend_wr = TRUE; - - irqA12.present = TRUE; - irqA12_delay = 1; -} -void extcl_cpu_wr_mem_H2288(WORD address, BYTE value) { - if (address >= 0x8000) { - BYTE old_prg_rom_cfg = mmc3.prg_rom_cfg; - BYTE old_chr_rom_cfg = mmc3.chr_rom_cfg; - - switch (address & 0xE001) { - case 0x8000: - extcl_cpu_wr_mem_MMC3(address, (value & 0xC0) | vlu114[value & 7]); - h2288_8000() - h2288_update_prg(); - h2288_update_chr(); - return; - case 0x8001: - extcl_cpu_wr_mem_MMC3(address, value); - h2288_8001() - h2288_update_prg(); - h2288_update_chr(); - return; - default: - extcl_cpu_wr_mem_MMC3(address, value); - return; - } - } - - if ((address >= 0x5000) && (address <= 0x5FFF)) { - if (address & 0x0800) { - if (address & 0x0001) { - h2288.reg[1] = value; - } else { - h2288.reg[0] = value; - h2288_update_prg(); - } - } - } -} -BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp) { - save_slot_ele(mode, slot, h2288.reg); - save_slot_ele(mode, slot, h2288.prg_map); - save_slot_ele(mode, slot, h2288.chr_map); - extcl_save_mapper_MMC3(mode, slot, fp); - - return (EXIT_OK); -} - -INLINE static void h2288_update_prg(void) { - BYTE value; - - if (h2288.reg[0] & 0x40) { - value = (h2288.reg[0] & 0x05) | ((h2288.reg[0] & 0x08) >> 2) | ((h2288.reg[0] & 0x20) >> 2); - if (h2288.reg[0] & 0x02) { - value = value >> 1; - control_bank(info.prg.rom[0].max.banks_32k) - map_prg_rom_8k(4, 0, value); - } else { - control_bank(info.prg.rom[0].max.banks_16k) - map_prg_rom_8k(2, 0, value); - map_prg_rom_8k(2, 2, value); - } - } else { - h2288_prg_8k(h2288.prg_map[0]); - control_bank(info.prg.rom[0].max.banks_8k) - map_prg_rom_8k(1, 0, value); - - h2288_prg_8k(h2288.prg_map[1]); - control_bank(info.prg.rom[0].max.banks_8k) - map_prg_rom_8k(1, 1, value); - - h2288_prg_8k(h2288.prg_map[2]); - control_bank(info.prg.rom[0].max.banks_8k) - map_prg_rom_8k(1, 2, value); - - h2288_prg_8k(h2288.prg_map[3]); - control_bank(info.prg.rom[0].max.banks_8k) - map_prg_rom_8k(1, 3, value); - } - map_prg_rom_8k_update(); -} -INLINE static void h2288_update_chr(void) { - BYTE i; - WORD value; - - for (i = 0; i < 8; i++) { - h2288_chr_1k(h2288.chr_map[i]); - control_bank(info.chr.rom[0].max.banks_1k) - chr.bank_1k[i] = chr_chip_byte_pnt(0, value << 10); - } -} +/* + * Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include "mappers.h" +#include "info.h" +#include "mem_map.h" +#include "cpu.h" +#include "irqA12.h" +#include "save_slot.h" + +INLINE static void h2288_update_prg(void); +INLINE static void h2288_update_chr(void); + +#define h2288_chr_1k(vl) value = vl +#define h2288_prg_8k(vl) value = (vl & 0x3F) +#define h2288_swap_chr_1k(a, b)\ + chr1k = h2288.chr_map[b];\ + h2288.chr_map[b] = h2288.chr_map[a];\ + h2288.chr_map[a] = chr1k +#define h2288_8000()\ + if (mmc3.chr_rom_cfg != old_chr_rom_cfg) {\ + BYTE chr1k;\ + h2288_swap_chr_1k(0, 4);\ + h2288_swap_chr_1k(1, 5);\ + h2288_swap_chr_1k(2, 6);\ + h2288_swap_chr_1k(3, 7);\ + }\ + if (mmc3.prg_rom_cfg != old_prg_rom_cfg) {\ + mapper.rom_map_to[2] = h2288.prg_map[0];\ + mapper.rom_map_to[0] = h2288.prg_map[2];\ + h2288.prg_map[0] = mapper.rom_map_to[0];\ + h2288.prg_map[2] = mapper.rom_map_to[2];\ + h2288.prg_map[mmc3.prg_rom_cfg ^ 0x02] = info.prg.rom[0].max.banks_8k_before_last;\ + } +#define h2288_8001()\ + switch (mmc3.bank_to_update) {\ + case 0:\ + control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\ + h2288.chr_map[mmc3.chr_rom_cfg] = value;\ + h2288.chr_map[mmc3.chr_rom_cfg | 0x01] = value + 1;\ + break;\ + case 1:\ + control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\ + h2288.chr_map[mmc3.chr_rom_cfg | 0x02] = value;\ + h2288.chr_map[mmc3.chr_rom_cfg | 0x03] = value + 1;\ + break;\ + case 2:\ + h2288.chr_map[mmc3.chr_rom_cfg ^ 0x04] = value;\ + break;\ + case 3:\ + h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x01] = value;\ + break;\ + case 4:\ + h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x02] = value;\ + break;\ + case 5:\ + h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x03] = value;\ + break;\ + case 6:\ + h2288.prg_map[mmc3.prg_rom_cfg] = value;\ + break;\ + case 7:\ + h2288.prg_map[1] = value;\ + break;\ + } + +struct _h2288 { + BYTE reg[2]; + WORD prg_map[4]; + WORD chr_map[8]; +} h2288; + +void map_init_H2288(void) { + EXTCL_CPU_WR_MEM(H2288); + EXTCL_SAVE_MAPPER(H2288); + EXTCL_CPU_EVERY_CYCLE(MMC3); + EXTCL_PPU_000_TO_34X(MMC3); + EXTCL_PPU_000_TO_255(MMC3); + EXTCL_PPU_256_TO_319(MMC3); + EXTCL_PPU_320_TO_34X(MMC3); + EXTCL_UPDATE_R2006(MMC3); + mapper.internal_struct[0] = (BYTE *) &h2288; + mapper.internal_struct_size[0] = sizeof(h2288); + mapper.internal_struct[1] = (BYTE *) &mmc3; + mapper.internal_struct_size[1] = sizeof(mmc3); + + memset(&h2288, 0x00, sizeof(h2288)); + memset(&mmc3, 0x00, sizeof(mmc3)); + memset(&irqA12, 0x00, sizeof(irqA12)); + + { + BYTE i; + + map_prg_rom_8k_reset(); + map_chr_bank_1k_reset(); + + for (i = 0; i < 8; i++) { + if (i < 4) { + h2288.prg_map[i] = mapper.rom_map_to[i]; + } + h2288.chr_map[i] = i; + } + } + + h2288_update_prg(); + h2288_update_chr(); + + info.mapper.extend_wr = TRUE; + + irqA12.present = TRUE; + irqA12_delay = 1; +} +void extcl_cpu_wr_mem_H2288(WORD address, BYTE value) { + if (address >= 0x8000) { + BYTE old_prg_rom_cfg = mmc3.prg_rom_cfg; + BYTE old_chr_rom_cfg = mmc3.chr_rom_cfg; + + switch (address & 0xE001) { + case 0x8000: + extcl_cpu_wr_mem_MMC3(address, (value & 0xC0) | vlu114[value & 7]); + h2288_8000() + h2288_update_prg(); + h2288_update_chr(); + return; + case 0x8001: + extcl_cpu_wr_mem_MMC3(address, value); + h2288_8001() + h2288_update_prg(); + h2288_update_chr(); + return; + default: + extcl_cpu_wr_mem_MMC3(address, value); + return; + } + } + + if ((address >= 0x5000) && (address <= 0x5FFF)) { + if (address & 0x0800) { + if (address & 0x0001) { + h2288.reg[1] = value; + } else { + h2288.reg[0] = value; + h2288_update_prg(); + } + } + } +} +BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp) { + save_slot_ele(mode, slot, h2288.reg); + save_slot_ele(mode, slot, h2288.prg_map); + save_slot_ele(mode, slot, h2288.chr_map); + extcl_save_mapper_MMC3(mode, slot, fp); + + return (EXIT_OK); +} + +INLINE static void h2288_update_prg(void) { + BYTE value; + + if (h2288.reg[0] & 0x40) { + value = (h2288.reg[0] & 0x05) | ((h2288.reg[0] & 0x08) >> 2) | ((h2288.reg[0] & 0x20) >> 2); + if (h2288.reg[0] & 0x02) { + value = value >> 1; + control_bank(info.prg.rom[0].max.banks_32k) + map_prg_rom_8k(4, 0, value); + } else { + control_bank(info.prg.rom[0].max.banks_16k) + map_prg_rom_8k(2, 0, value); + map_prg_rom_8k(2, 2, value); + } + } else { + h2288_prg_8k(h2288.prg_map[0]); + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 0, value); + + h2288_prg_8k(h2288.prg_map[1]); + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 1, value); + + h2288_prg_8k(h2288.prg_map[2]); + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 2, value); + + h2288_prg_8k(h2288.prg_map[3]); + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 3, value); + } + map_prg_rom_8k_update(); +} +INLINE static void h2288_update_chr(void) { + BYTE i; + WORD value; + + for (i = 0; i < 8; i++) { + h2288_chr_1k(h2288.chr_map[i]); + control_bank(info.chr.rom[0].max.banks_1k) + chr.bank_1k[i] = chr_chip_byte_pnt(0, value << 10); + } +} diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_H2288.c.orig puNES-0.105.new/src/core/mappers/mapper_H2288.c.orig --- puNES-0.105.org/src/core/mappers/mapper_H2288.c.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/mappers/mapper_H2288.c.orig 2020-03-18 11:47:29.372142615 +0100 @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include "mappers.h" +#include "info.h" +#include "mem_map.h" +#include "cpu.h" +#include "irqA12.h" +#include "save_slot.h" + +INLINE static void h2288_update_prg(void); +INLINE static void h2288_update_chr(void); + +#define h2288_chr_1k(vl) value = vl +#define h2288_prg_8k(vl) value = (vl & 0x3F) +#define h2288_swap_chr_1k(a, b)\ + chr1k = h2288.chr_map[b];\ + h2288.chr_map[b] = h2288.chr_map[a];\ + h2288.chr_map[a] = chr1k +#define h2288_8000()\ + if (mmc3.chr_rom_cfg != old_chr_rom_cfg) {\ + BYTE chr1k;\ + h2288_swap_chr_1k(0, 4);\ + h2288_swap_chr_1k(1, 5);\ + h2288_swap_chr_1k(2, 6);\ + h2288_swap_chr_1k(3, 7);\ + }\ + if (mmc3.prg_rom_cfg != old_prg_rom_cfg) {\ + mapper.rom_map_to[2] = h2288.prg_map[0];\ + mapper.rom_map_to[0] = h2288.prg_map[2];\ + h2288.prg_map[0] = mapper.rom_map_to[0];\ + h2288.prg_map[2] = mapper.rom_map_to[2];\ + h2288.prg_map[mmc3.prg_rom_cfg ^ 0x02] = info.prg.rom[0].max.banks_8k_before_last;\ + } +#define h2288_8001()\ + switch (mmc3.bank_to_update) {\ + case 0:\ + control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\ + h2288.chr_map[mmc3.chr_rom_cfg] = value;\ + h2288.chr_map[mmc3.chr_rom_cfg | 0x01] = value + 1;\ + break;\ + case 1:\ + control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\ + h2288.chr_map[mmc3.chr_rom_cfg | 0x02] = value;\ + h2288.chr_map[mmc3.chr_rom_cfg | 0x03] = value + 1;\ + break;\ + case 2:\ + h2288.chr_map[mmc3.chr_rom_cfg ^ 0x04] = value;\ + break;\ + case 3:\ + h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x01] = value;\ + break;\ + case 4:\ + h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x02] = value;\ + break;\ + case 5:\ + h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x03] = value;\ + break;\ + case 6:\ + h2288.prg_map[mmc3.prg_rom_cfg] = value;\ + break;\ + case 7:\ + h2288.prg_map[1] = value;\ + break;\ + } + +void map_init_H2288(void) { + EXTCL_CPU_WR_MEM(H2288); + EXTCL_SAVE_MAPPER(H2288); + EXTCL_CPU_EVERY_CYCLE(MMC3); + EXTCL_PPU_000_TO_34X(MMC3); + EXTCL_PPU_000_TO_255(MMC3); + EXTCL_PPU_256_TO_319(MMC3); + EXTCL_PPU_320_TO_34X(MMC3); + EXTCL_UPDATE_R2006(MMC3); + mapper.internal_struct[0] = (BYTE *) &h2288; + mapper.internal_struct_size[0] = sizeof(h2288); + mapper.internal_struct[1] = (BYTE *) &mmc3; + mapper.internal_struct_size[1] = sizeof(mmc3); + + memset(&h2288, 0x00, sizeof(h2288)); + memset(&mmc3, 0x00, sizeof(mmc3)); + memset(&irqA12, 0x00, sizeof(irqA12)); + + { + BYTE i; + + map_prg_rom_8k_reset(); + map_chr_bank_1k_reset(); + + for (i = 0; i < 8; i++) { + if (i < 4) { + h2288.prg_map[i] = mapper.rom_map_to[i]; + } + h2288.chr_map[i] = i; + } + } + + h2288_update_prg(); + h2288_update_chr(); + + info.mapper.extend_wr = TRUE; + + irqA12.present = TRUE; + irqA12_delay = 1; +} +void extcl_cpu_wr_mem_H2288(WORD address, BYTE value) { + if (address >= 0x8000) { + BYTE old_prg_rom_cfg = mmc3.prg_rom_cfg; + BYTE old_chr_rom_cfg = mmc3.chr_rom_cfg; + + switch (address & 0xE001) { + case 0x8000: + extcl_cpu_wr_mem_MMC3(address, (value & 0xC0) | vlu114[value & 7]); + h2288_8000() + h2288_update_prg(); + h2288_update_chr(); + return; + case 0x8001: + extcl_cpu_wr_mem_MMC3(address, value); + h2288_8001() + h2288_update_prg(); + h2288_update_chr(); + return; + default: + extcl_cpu_wr_mem_MMC3(address, value); + return; + } + } + + if ((address >= 0x5000) && (address <= 0x5FFF)) { + if (address & 0x0800) { + if (address & 0x0001) { + h2288.reg[1] = value; + } else { + h2288.reg[0] = value; + h2288_update_prg(); + } + } + } +} +BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp) { + save_slot_ele(mode, slot, h2288.reg); + save_slot_ele(mode, slot, h2288.prg_map); + save_slot_ele(mode, slot, h2288.chr_map); + extcl_save_mapper_MMC3(mode, slot, fp); + + return (EXIT_OK); +} + +INLINE static void h2288_update_prg(void) { + BYTE value; + + if (h2288.reg[0] & 0x40) { + value = (h2288.reg[0] & 0x05) | ((h2288.reg[0] & 0x08) >> 2) | ((h2288.reg[0] & 0x20) >> 2); + if (h2288.reg[0] & 0x02) { + value = value >> 1; + control_bank(info.prg.rom[0].max.banks_32k) + map_prg_rom_8k(4, 0, value); + } else { + control_bank(info.prg.rom[0].max.banks_16k) + map_prg_rom_8k(2, 0, value); + map_prg_rom_8k(2, 2, value); + } + } else { + h2288_prg_8k(h2288.prg_map[0]); + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 0, value); + + h2288_prg_8k(h2288.prg_map[1]); + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 1, value); + + h2288_prg_8k(h2288.prg_map[2]); + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 2, value); + + h2288_prg_8k(h2288.prg_map[3]); + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 3, value); + } + map_prg_rom_8k_update(); +} +INLINE static void h2288_update_chr(void) { + BYTE i; + WORD value; + + for (i = 0; i < 8; i++) { + h2288_chr_1k(h2288.chr_map[i]); + control_bank(info.chr.rom[0].max.banks_1k) + chr.bank_1k[i] = chr_chip_byte_pnt(0, value << 10); + } +} diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_H2288.h puNES-0.105.new/src/core/mappers/mapper_H2288.h --- puNES-0.105.org/src/core/mappers/mapper_H2288.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_H2288.h 2020-03-18 11:49:55.295890150 +0100 @@ -1,34 +1,28 @@ -/* - * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef MAPPER_H2288_H_ -#define MAPPER_H2288_H_ - -#include "common.h" - -struct _h2288 { - BYTE reg[2]; - WORD prg_map[4]; - WORD chr_map[8]; -} h2288; - -void map_init_H2288(void); -void extcl_cpu_wr_mem_H2288(WORD address, BYTE value); -BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp); - -#endif /* MAPPER_H2288_H_ */ +/* + * Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef MAPPER_H2288_H_ +#define MAPPER_H2288_H_ + +#include "common.h" + +void map_init_H2288(void); +void extcl_cpu_wr_mem_H2288(WORD address, BYTE value); +BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp); + +#endif /* MAPPER_H2288_H_ */ diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_H2288.h.orig puNES-0.105.new/src/core/mappers/mapper_H2288.h.orig --- puNES-0.105.org/src/core/mappers/mapper_H2288.h.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/mappers/mapper_H2288.h.orig 2020-03-18 11:47:29.372142615 +0100 @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef MAPPER_H2288_H_ +#define MAPPER_H2288_H_ + +#include "common.h" + +struct _h2288 { + BYTE reg[2]; + WORD prg_map[4]; + WORD chr_map[8]; +} h2288; + +void map_init_H2288(void); +void extcl_cpu_wr_mem_H2288(WORD address, BYTE value); +BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp); + +#endif /* MAPPER_H2288_H_ */ diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Hen.c puNES-0.105.new/src/core/mappers/mapper_Hen.c --- puNES-0.105.org/src/core/mappers/mapper_Hen.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Hen.c 2020-03-18 11:47:29.372142615 +0100 @@ -20,7 +20,9 @@ #include "info.h" #include "mem_map.h" -BYTE type; +struct _hentmp { + BYTE type; +} hentmp; void map_init_Hen(BYTE model) { switch (model) { @@ -38,11 +40,11 @@ void map_init_Hen(BYTE model) { map_prg_rom_8k(4, 0, 0); } - type = model; + hentmp.type = model; } void extcl_cpu_wr_mem_Hen_177(UNUSED(WORD address), BYTE value) { - if (type != HEN_FANKONG) { + if (hentmp.type != HEN_FANKONG) { if (value & 0x20) { mirroring_H(); } else { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Irem.c puNES-0.105.new/src/core/mappers/mapper_Irem.c --- puNES-0.105.org/src/core/mappers/mapper_Irem.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Irem.c 2020-03-18 11:47:29.372142615 +0100 @@ -41,6 +41,20 @@ chr.bank_1k[6] = &chr.extra.data[0x1000];\ chr.bank_1k[7] = &chr.extra.data[0x1400] +struct _irem_G101 { + BYTE prg_mode; + BYTE prg_reg; +} irem_G101; +struct _irem_H3000 { + BYTE enable; + WORD count; + WORD reload; + BYTE delay; +} irem_H3000; +struct _irem_LROG017 { + BYTE filler; +} irem_LROG017; + void map_init_Irem(BYTE model) { switch (model) { case G101: diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Irem.h puNES-0.105.new/src/core/mappers/mapper_Irem.h --- puNES-0.105.org/src/core/mappers/mapper_Irem.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Irem.h 2020-03-18 11:47:29.372142615 +0100 @@ -31,20 +31,6 @@ enum { MAJORLEAGUE }; -struct _irem_G101 { - BYTE prg_mode; - BYTE prg_reg; -} irem_G101; -struct _irem_H3000 { - BYTE enable; - WORD count; - WORD reload; - BYTE delay; -} irem_H3000; -struct _irem_LROG017 { - BYTE filler; -} irem_LROG017; - void map_init_Irem(BYTE model); void extcl_cpu_wr_mem_Irem_G101(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Jaleco.c puNES-0.105.new/src/core/mappers/mapper_Jaleco.c --- puNES-0.105.org/src/core/mappers/mapper_Jaleco.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Jaleco.c 2020-03-18 11:47:29.372142615 +0100 @@ -35,6 +35,15 @@ chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\ ss8806.chr_rom_bank[slot] = value +struct _ss8806 { + BYTE chr_rom_bank[8]; + BYTE enabled; + WORD mask; + WORD reload; + WORD count; + BYTE delay; +} ss8806; + void map_init_Jaleco(BYTE model) { switch (model) { case JF05: diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Jaleco.h puNES-0.105.new/src/core/mappers/mapper_Jaleco.h --- puNES-0.105.org/src/core/mappers/mapper_Jaleco.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Jaleco.h 2020-03-18 11:47:29.372142615 +0100 @@ -36,15 +36,6 @@ enum { MEZASETOPPRO, }; -struct _ss8806 { - BYTE chr_rom_bank[8]; - BYTE enabled; - WORD mask; - WORD reload; - WORD count; - BYTE delay; -} ss8806; - void map_init_Jaleco(BYTE model); void extcl_cpu_wr_mem_Jaleco_JF05(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Kaiser.c puNES-0.105.new/src/core/mappers/mapper_Kaiser.c --- puNES-0.105.org/src/core/mappers/mapper_Kaiser.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Kaiser.c 2020-03-18 11:47:29.373142607 +0100 @@ -23,6 +23,18 @@ #include "cpu.h" #include "save_slot.h" +struct _ks202 { + BYTE enabled; + WORD count; + WORD reload; + BYTE delay; + BYTE reg; + BYTE *prg_ram_rd; +} ks202; +struct _ks7022 { + BYTE reg; +} ks7022; + void map_init_Kaiser(BYTE model) { switch (model) { case KS202: diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Kaiser.h puNES-0.105.new/src/core/mappers/mapper_Kaiser.h --- puNES-0.105.org/src/core/mappers/mapper_Kaiser.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Kaiser.h 2020-03-18 11:47:29.373142607 +0100 @@ -28,18 +28,6 @@ enum { KS7022 }; -struct _ks202 { - BYTE enabled; - WORD count; - WORD reload; - BYTE delay; - BYTE reg; - BYTE *prg_ram_rd; -} ks202; -struct _ks7022 { - BYTE reg; -} ks7022; - void map_init_Kaiser(BYTE model); void extcl_cpu_wr_mem_Kaiser_ks202(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Kasing.c puNES-0.105.new/src/core/mappers/mapper_Kasing.c --- puNES-0.105.org/src/core/mappers/mapper_Kasing.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Kasing.c 2020-03-18 11:47:29.373142607 +0100 @@ -60,6 +60,14 @@ }\ } +struct _kasing { + BYTE prg_mode; + BYTE prg_high; + WORD prg_rom_bank[4]; + BYTE chr_high; + WORD chr_rom_bank[8]; +} kasing; + void map_init_Kasing(void) { EXTCL_CPU_WR_MEM(Kasing); EXTCL_SAVE_MAPPER(Kasing); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Kasing.h puNES-0.105.new/src/core/mappers/mapper_Kasing.h --- puNES-0.105.org/src/core/mappers/mapper_Kasing.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Kasing.h 2020-03-18 11:47:29.373142607 +0100 @@ -21,14 +21,6 @@ #include "common.h" -struct _kasing { - BYTE prg_mode; - BYTE prg_high; - WORD prg_rom_bank[4]; - BYTE chr_high; - WORD chr_rom_bank[8]; -} kasing; - void map_init_Kasing(void); void extcl_cpu_wr_mem_Kasing(WORD address, BYTE value); BYTE extcl_save_mapper_Kasing(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7016.c puNES-0.105.new/src/core/mappers/mapper_KS7016.c --- puNES-0.105.org/src/core/mappers/mapper_KS7016.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7016.c 2020-03-18 11:47:29.372142615 +0100 @@ -23,7 +23,12 @@ INLINE static void ks7016_6000_update(void); -BYTE *ks7016_prg_6000; +struct _ks7016 { + BYTE reg; +} ks7016; +struct _ks7016tmp { + BYTE *prg_6000; +} ks7016tmp; void map_init_KS7016(void) { EXTCL_CPU_WR_MEM(KS7016); @@ -76,7 +81,7 @@ void extcl_cpu_wr_mem_KS7016(WORD addres } BYTE extcl_cpu_rd_mem_KS7016(WORD address, BYTE openbus, UNUSED(BYTE before)) { if ((address >= 0x6000) && (address <= 0x7FFF)) { - return (ks7016_prg_6000[address & 0x1FFF]); + return (ks7016tmp.prg_6000[address & 0x1FFF]); } return (openbus); } @@ -95,5 +100,5 @@ INLINE static void ks7016_6000_update(vo value = ks7016.reg; control_bank(info.prg.rom[0].max.banks_8k) - ks7016_prg_6000 = prg_chip_byte_pnt(0, value << 13); + ks7016tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13); } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7016.h puNES-0.105.new/src/core/mappers/mapper_KS7016.h --- puNES-0.105.org/src/core/mappers/mapper_KS7016.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7016.h 2020-03-18 11:47:29.372142615 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _ks7016 { - BYTE reg; -} ks7016; - void map_init_KS7016(void); void extcl_cpu_wr_mem_KS7016(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_KS7016(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7017.c puNES-0.105.new/src/core/mappers/mapper_KS7017.c --- puNES-0.105.org/src/core/mappers/mapper_KS7017.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7017.c 2020-03-18 11:47:29.372142615 +0100 @@ -23,6 +23,14 @@ #include "cpu.h" #include "save_slot.h" +struct _ks7017 { + BYTE reg; + struct _ks7017_irq { + BYTE active; + WORD count; + } irq; +} ks7017; + void map_init_KS7017(void) { EXTCL_CPU_WR_MEM(KS7017); EXTCL_CPU_RD_MEM(KS7017); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7017.h puNES-0.105.new/src/core/mappers/mapper_KS7017.h --- puNES-0.105.org/src/core/mappers/mapper_KS7017.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7017.h 2020-03-18 11:47:29.372142615 +0100 @@ -21,14 +21,6 @@ #include "common.h" -struct _ks7017 { - BYTE reg; - struct _ks7017_irq { - BYTE active; - WORD count; - } irq; -} ks7017; - void map_init_KS7017(void); void extcl_cpu_wr_mem_KS7017(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_KS7017(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7031.c puNES-0.105.new/src/core/mappers/mapper_KS7031.c --- puNES-0.105.org/src/core/mappers/mapper_KS7031.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7031.c 2020-03-18 11:47:29.373142607 +0100 @@ -25,26 +25,31 @@ INLINE static void ks7031_init_prg(void); INLINE static void ks7031_update(void); -BYTE *ks7031_prg_6000; -BYTE *ks7031_prg_6800; -BYTE *ks7031_prg_7000; -BYTE *ks7031_prg_7800; -BYTE *ks7031_prg_8000; -BYTE *ks7031_prg_8800; -BYTE *ks7031_prg_9000; -BYTE *ks7031_prg_9800; -BYTE *ks7031_prg_A000; -BYTE *ks7031_prg_A800; -BYTE *ks7031_prg_B000; -BYTE *ks7031_prg_B800; -BYTE *ks7031_prg_C000; -BYTE *ks7031_prg_C800; -BYTE *ks7031_prg_D000; -BYTE *ks7031_prg_D800; -BYTE *ks7031_prg_E000; -BYTE *ks7031_prg_E800; -BYTE *ks7031_prg_F000; -BYTE *ks7031_prg_F800; +struct _ks7031 { + BYTE reg[4]; +} ks7031; +struct _ks7031tmp { + BYTE *prg_6000; + BYTE *prg_6800; + BYTE *prg_7000; + BYTE *prg_7800; + BYTE *prg_8000; + BYTE *prg_8800; + BYTE *prg_9000; + BYTE *prg_9800; + BYTE *prg_A000; + BYTE *prg_A800; + BYTE *prg_B000; + BYTE *prg_B800; + BYTE *prg_C000; + BYTE *prg_C800; + BYTE *prg_D000; + BYTE *prg_D800; + BYTE *prg_E000; + BYTE *prg_E800; + BYTE *prg_F000; + BYTE *prg_F800; +} ks7031tmp; void map_init_KS7031(void) { EXTCL_CPU_WR_MEM(KS7031); @@ -69,45 +74,45 @@ void extcl_cpu_wr_mem_KS7031(WORD addres BYTE extcl_cpu_rd_mem_KS7031(WORD address, BYTE openbus, UNUSED(BYTE before)) { switch (address & 0xF800) { case 0x6000: - return (ks7031_prg_6000[address & 0x07FF]); + return (ks7031tmp.prg_6000[address & 0x07FF]); case 0x6800: - return (ks7031_prg_6800[address & 0x07FF]); + return (ks7031tmp.prg_6800[address & 0x07FF]); case 0x7000: - return (ks7031_prg_7000[address & 0x07FF]); + return (ks7031tmp.prg_7000[address & 0x07FF]); case 0x7800: - return (ks7031_prg_7800[address & 0x07FF]); + return (ks7031tmp.prg_7800[address & 0x07FF]); case 0x8000: - return (ks7031_prg_8000[address & 0x07FF]); + return (ks7031tmp.prg_8000[address & 0x07FF]); case 0x8800: - return (ks7031_prg_8800[address & 0x07FF]); + return (ks7031tmp.prg_8800[address & 0x07FF]); case 0x9000: - return (ks7031_prg_9000[address & 0x07FF]); + return (ks7031tmp.prg_9000[address & 0x07FF]); case 0x9800: - return (ks7031_prg_9800[address & 0x07FF]); + return (ks7031tmp.prg_9800[address & 0x07FF]); case 0xA000: - return (ks7031_prg_A000[address & 0x07FF]); + return (ks7031tmp.prg_A000[address & 0x07FF]); case 0xA800: - return (ks7031_prg_A800[address & 0x07FF]); + return (ks7031tmp.prg_A800[address & 0x07FF]); case 0xB000: - return (ks7031_prg_B000[address & 0x07FF]); + return (ks7031tmp.prg_B000[address & 0x07FF]); case 0xB800: - return (ks7031_prg_B800[address & 0x07FF]); + return (ks7031tmp.prg_B800[address & 0x07FF]); case 0xC000: - return (ks7031_prg_C000[address & 0x07FF]); + return (ks7031tmp.prg_C000[address & 0x07FF]); case 0xC800: - return (ks7031_prg_C800[address & 0x07FF]); + return (ks7031tmp.prg_C800[address & 0x07FF]); case 0xD000: - return (ks7031_prg_D000[address & 0x07FF]); + return (ks7031tmp.prg_D000[address & 0x07FF]); case 0xD800: - return (ks7031_prg_D800[address & 0x07FF]); + return (ks7031tmp.prg_D800[address & 0x07FF]); case 0xE000: - return (ks7031_prg_E000[address & 0x07FF]); + return (ks7031tmp.prg_E000[address & 0x07FF]); case 0xE800: - return (ks7031_prg_E800[address & 0x07FF]); + return (ks7031tmp.prg_E800[address & 0x07FF]); case 0xF000: - return (ks7031_prg_F000[address & 0x07FF]); + return (ks7031tmp.prg_F000[address & 0x07FF]); case 0xF800: - return (ks7031_prg_F800[address & 0x07FF]); + return (ks7031tmp.prg_F800[address & 0x07FF]); } return (openbus); } @@ -128,74 +133,74 @@ INLINE static void ks7031_init_prg(void) // 0x8000 value = 15; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_8000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_8000 = prg_chip_byte_pnt(0, value << 11); // 0x8800 value = 14; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_8800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_8800 = prg_chip_byte_pnt(0, value << 11); // 0x9000 value = 13; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_9000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_9000 = prg_chip_byte_pnt(0, value << 11); // 0x9800 value = 12; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_9800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_9800 = prg_chip_byte_pnt(0, value << 11); // 0xA000 value = 11; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_A000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_A000 = prg_chip_byte_pnt(0, value << 11); // 0xA800 value = 10; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_A800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_A800 = prg_chip_byte_pnt(0, value << 11); // 0xB000 value = 9; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_B000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_B000 = prg_chip_byte_pnt(0, value << 11); // 0xB800 value = 8; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_B800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_B800 = prg_chip_byte_pnt(0, value << 11); // 0xC000 value = 7; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_C000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_C000 = prg_chip_byte_pnt(0, value << 11); // 0xC800 value = 6; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_C800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_C800 = prg_chip_byte_pnt(0, value << 11); // 0xD000 value = 5; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_D000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_D000 = prg_chip_byte_pnt(0, value << 11); // 0xD800 value = 4; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_D800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_D800 = prg_chip_byte_pnt(0, value << 11); // 0xE000 value = 3; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_E000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_E000 = prg_chip_byte_pnt(0, value << 11); // 0xE800 value = 2; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_E800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_E800 = prg_chip_byte_pnt(0, value << 11); // 0xF000 value = 1; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_F000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_F000 = prg_chip_byte_pnt(0, value << 11); // 0xF800 value = 0; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_F800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_F800 = prg_chip_byte_pnt(0, value << 11); } INLINE static void ks7031_update(void) { WORD value; @@ -203,18 +208,18 @@ INLINE static void ks7031_update(void) { // 0x6000 value = ks7031.reg[0]; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_6000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_6000 = prg_chip_byte_pnt(0, value << 11); // 0x6800 value = ks7031.reg[1]; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_6800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_6800 = prg_chip_byte_pnt(0, value << 11); // 0x7000 value = ks7031.reg[2]; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_7000 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_7000 = prg_chip_byte_pnt(0, value << 11); // 0x7800 value = ks7031.reg[3]; control_bank(info.prg.rom[0].max.banks_2k) - ks7031_prg_7800 = prg_chip_byte_pnt(0, value << 11); + ks7031tmp.prg_7800 = prg_chip_byte_pnt(0, value << 11); } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7031.h puNES-0.105.new/src/core/mappers/mapper_KS7031.h --- puNES-0.105.org/src/core/mappers/mapper_KS7031.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7031.h 2020-03-18 11:47:29.373142607 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _ks7031 { - BYTE reg[4]; -} ks7031; - void map_init_KS7031(void); void extcl_cpu_wr_mem_KS7031(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_KS7031(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7032.c puNES-0.105.new/src/core/mappers/mapper_KS7032.c --- puNES-0.105.org/src/core/mappers/mapper_KS7032.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7032.c 2020-03-18 11:47:29.373142607 +0100 @@ -25,7 +25,19 @@ INLINE static void ks7032_update(void); -BYTE *ks7032_prg_6000; +struct _ks7032 { + BYTE ind; + BYTE reg[8]; + struct _ks7032_irq { + BYTE used; + BYTE active; + WORD count; + WORD reload; + } irq; +} ks7032; +struct _ks7032tmp { + BYTE *prg_6000; +} ks7032tmp; void map_init_KS7032(void) { EXTCL_CPU_WR_MEM(KS7032); @@ -78,7 +90,7 @@ void extcl_cpu_wr_mem_KS7032(WORD addres } BYTE extcl_cpu_rd_mem_KS7032(WORD address, BYTE openbus, UNUSED(BYTE before)) { if ((address >= 0x6000) && (address <= 0x7FFF)) { - return (ks7032_prg_6000[address & 0x1FFF]); + return (ks7032tmp.prg_6000[address & 0x1FFF]); } return (openbus); } @@ -113,7 +125,7 @@ INLINE static void ks7032_update(void) { value = ks7032.reg[4]; control_bank(info.prg.rom[0].max.banks_8k) - ks7032_prg_6000 = prg_chip_byte_pnt(0, value << 13); + ks7032tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13); value = ks7032.reg[1]; control_bank(info.prg.rom[0].max.banks_8k) diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7032.c.orig puNES-0.105.new/src/core/mappers/mapper_KS7032.c.orig --- puNES-0.105.org/src/core/mappers/mapper_KS7032.c.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/mappers/mapper_KS7032.c.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include "mappers.h" +#include "info.h" +#include "mem_map.h" +#include "cpu.h" +#include "save_slot.h" + +INLINE static void ks7032_update(void); + +BYTE *ks7032_prg_6000; + +void map_init_KS7032(void) { + EXTCL_CPU_WR_MEM(KS7032); + EXTCL_CPU_RD_MEM(KS7032); + EXTCL_SAVE_MAPPER(KS7032); + EXTCL_CPU_EVERY_CYCLE(KS7032); + mapper.internal_struct[0] = (BYTE *) &ks7032; + mapper.internal_struct_size[0] = sizeof(ks7032); + + memset(&ks7032, 0x00, sizeof(ks7032)); + + ks7032_update(); +} +void extcl_cpu_wr_mem_KS7032(WORD address, BYTE value) { + switch (address & 0xF000) { + case 0x8000: + ks7032.irq.used = 1; + ks7032.irq.count = (ks7032.irq.count & 0x000F) | (value & 0x0F); + irq.high &= ~EXT_IRQ; + return; + case 0x9000: + ks7032.irq.used = 1; + ks7032.irq.count = (ks7032.irq.count & 0x00F0) | (value << 4); + irq.high &= ~EXT_IRQ; + return; + case 0xA000: + ks7032.irq.used = 1; + ks7032.irq.count = (ks7032.irq.count & 0x0F00) | (value << 8); + irq.high &= ~EXT_IRQ; + return; + case 0xB000: + ks7032.irq.used = 1; + ks7032.irq.count = (ks7032.irq.count & 0xF000) | (value << 12); + irq.high &= ~EXT_IRQ; + return; + case 0xC000: + if (ks7032.irq.used) { + ks7032.irq.active = 1; + irq.high &= ~EXT_IRQ; + } + return; + case 0xE000: + ks7032.ind = value & 0x07; + return; + case 0xF000: + ks7032.reg[ks7032.ind] = value; + ks7032_update(); + return; + } +} +BYTE extcl_cpu_rd_mem_KS7032(WORD address, BYTE openbus, UNUSED(BYTE before)) { + if ((address >= 0x6000) && (address <= 0x7FFF)) { + return (ks7032_prg_6000[address & 0x1FFF]); + } + return (openbus); +} +BYTE extcl_save_mapper_KS7032(BYTE mode, BYTE slot, FILE *fp) { + save_slot_ele(mode, slot, ks7032.ind); + save_slot_ele(mode, slot, ks7032.reg); + save_slot_ele(mode, slot, ks7032.irq.used); + save_slot_ele(mode, slot, ks7032.irq.active); + save_slot_ele(mode, slot, ks7032.irq.count); + save_slot_ele(mode, slot, ks7032.irq.reload); + + if (mode == SAVE_SLOT_READ) { + ks7032_update(); + } + + return (EXIT_OK); +} +void extcl_cpu_every_cycle_KS7032(void) { + if (!ks7032.irq.active) { + return; + } + + if (++ks7032.irq.count == 0xFFFF) { + ks7032.irq.active = ks7032.irq.count = 0; + irq.delay = TRUE; + irq.high |= EXT_IRQ; + } +} + +INLINE static void ks7032_update(void) { + WORD value; + + value = ks7032.reg[4]; + control_bank(info.prg.rom[0].max.banks_8k) + ks7032_prg_6000 = prg_chip_byte_pnt(0, value << 13); + + value = ks7032.reg[1]; + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 0, value); + + value = ks7032.reg[2]; + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 1, value); + + value = ks7032.reg[3]; + control_bank(info.prg.rom[0].max.banks_8k) + map_prg_rom_8k(1, 2, value); + + map_prg_rom_8k_update(); +} diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7032.h puNES-0.105.new/src/core/mappers/mapper_KS7032.h --- puNES-0.105.org/src/core/mappers/mapper_KS7032.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7032.h 2020-03-18 11:47:29.373142607 +0100 @@ -21,17 +21,6 @@ #include "common.h" -struct _ks7032 { - BYTE ind; - BYTE reg[8]; - struct _ks7032_irq { - BYTE used; - BYTE active; - WORD count; - WORD reload; - } irq; -} ks7032; - void map_init_KS7032(void); void extcl_cpu_wr_mem_KS7032(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_KS7032(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7037.c puNES-0.105.new/src/core/mappers/mapper_KS7037.c --- puNES-0.105.org/src/core/mappers/mapper_KS7037.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7037.c 2020-03-18 11:47:29.373142607 +0100 @@ -24,8 +24,14 @@ INLINE static void ks7037_update(void); -BYTE *ks7037_prg_7000; -BYTE *ks7037_prg_B000; +struct _ks7037 { + BYTE ind; + BYTE reg[8]; +} ks7037; +struct _ks7037tmp { + BYTE *prg_7000; + BYTE *prg_B000; +} ks7037tmp; void map_init_KS7037(void) { EXTCL_AFTER_MAPPER_INIT(KS7037); @@ -60,7 +66,7 @@ void extcl_cpu_wr_mem_KS7037(WORD addres return; case 0xB000: case 0xB001: - ks7037_prg_B000[address & 0x0FFF] = value; + ks7037tmp.prg_B000[address & 0x0FFF] = value; return; case 0x8000: case 0x9000: @@ -86,11 +92,11 @@ BYTE extcl_cpu_rd_mem_KS7037(WORD addres case 0x6000: return (prg.ram_plus_8k[address & 0x0FFF]); case 0x7000: - return (ks7037_prg_7000[address & 0x0FFF]); + return (ks7037tmp.prg_7000[address & 0x0FFF]); case 0xA000: return (prg.rom_8k[1][address & 0x0FFF]); case 0xB000: - return (ks7037_prg_B000[address & 0x0FFF]); + return (ks7037tmp.prg_B000[address & 0x0FFF]); } return (openbus); } @@ -111,7 +117,7 @@ INLINE static void ks7037_update(void) { // 0x7000 value = 0x0F; control_bank(info.prg.rom[0].max.banks_4k) - ks7037_prg_7000 = prg_chip_byte_pnt(0, value << 12); + ks7037tmp.prg_7000 = prg_chip_byte_pnt(0, value << 12); // 0x8000 - 0x9000 value = ks7037.reg[6]; @@ -125,7 +131,7 @@ INLINE static void ks7037_update(void) { prg.rom_8k[1] = prg_chip_byte_pnt(prg.rom_chip[0], value << 12); // 0xB000 - ks7037_prg_B000 = &prg.ram_plus_8k[1 << 12]; + ks7037tmp.prg_B000 = &prg.ram_plus_8k[1 << 12]; // 0xC000 - 0xD000 value = ks7037.reg[7]; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7037.h puNES-0.105.new/src/core/mappers/mapper_KS7037.h --- puNES-0.105.org/src/core/mappers/mapper_KS7037.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7037.h 2020-03-18 11:47:29.373142607 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _ks7037 { - BYTE ind; - BYTE reg[8]; -} ks7037; - void map_init_KS7037(void); void extcl_after_mapper_init_KS7037(void); void extcl_cpu_wr_mem_KS7037(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7057.c puNES-0.105.new/src/core/mappers/mapper_KS7057.c --- puNES-0.105.org/src/core/mappers/mapper_KS7057.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7057.c 2020-03-18 11:47:29.373142607 +0100 @@ -24,14 +24,19 @@ INLINE static void ks7057_update(void); -BYTE *ks7057_prg_6000; -BYTE *ks7057_prg_6800; -BYTE *ks7057_prg_7000; -BYTE *ks7057_prg_7800; -BYTE *ks7057_prg_8000; -BYTE *ks7057_prg_8800; -BYTE *ks7057_prg_9000; -BYTE *ks7057_prg_9800; +struct _ks7057 { + BYTE reg[8]; +} ks7057; +struct _ks7057tmp { + BYTE *prg_6000; + BYTE *prg_6800; + BYTE *prg_7000; + BYTE *prg_7800; + BYTE *prg_8000; + BYTE *prg_8800; + BYTE *prg_9000; + BYTE *prg_9800; +} ks7057tmp; void map_init_KS7057(void) { EXTCL_CPU_WR_MEM(KS7057); @@ -121,21 +126,21 @@ void extcl_cpu_wr_mem_KS7057(WORD addres BYTE extcl_cpu_rd_mem_KS7057(WORD address, BYTE openbus, UNUSED(BYTE before)) { switch (address & 0xF800) { case 0x6000: - return (ks7057_prg_6000[address & 0x07FF]); + return (ks7057tmp.prg_6000[address & 0x07FF]); case 0x6800: - return (ks7057_prg_6800[address & 0x07FF]); + return (ks7057tmp.prg_6800[address & 0x07FF]); case 0x7000: - return (ks7057_prg_7000[address & 0x07FF]); + return (ks7057tmp.prg_7000[address & 0x07FF]); case 0x7800: - return (ks7057_prg_7800[address & 0x07FF]); + return (ks7057tmp.prg_7800[address & 0x07FF]); case 0x8000: - return (ks7057_prg_8000[address & 0x07FF]); + return (ks7057tmp.prg_8000[address & 0x07FF]); case 0x8800: - return (ks7057_prg_8800[address & 0x07FF]); + return (ks7057tmp.prg_8800[address & 0x07FF]); case 0x9000: - return (ks7057_prg_9000[address & 0x07FF]); + return (ks7057tmp.prg_9000[address & 0x07FF]); case 0x9800: - return (ks7057_prg_9800[address & 0x07FF]); + return (ks7057tmp.prg_9800[address & 0x07FF]); } return (openbus); } @@ -155,38 +160,38 @@ INLINE static void ks7057_update(void) { // 0x6000 value = ks7057.reg[4]; control_bank(info.prg.rom[0].max.banks_2k) - ks7057_prg_6000 = prg_chip_byte_pnt(0, value << 11); + ks7057tmp.prg_6000 = prg_chip_byte_pnt(0, value << 11); // 0x6800 value = ks7057.reg[5]; control_bank(info.prg.rom[0].max.banks_2k) - ks7057_prg_6800 = prg_chip_byte_pnt(0, value << 11); + ks7057tmp.prg_6800 = prg_chip_byte_pnt(0, value << 11); // 0x7000 value = ks7057.reg[6]; control_bank(info.prg.rom[0].max.banks_2k) - ks7057_prg_7000 = prg_chip_byte_pnt(0, value << 11); + ks7057tmp.prg_7000 = prg_chip_byte_pnt(0, value << 11); // 0x7800 value = ks7057.reg[7]; control_bank(info.prg.rom[0].max.banks_2k) - ks7057_prg_7800 = prg_chip_byte_pnt(0, value << 11); + ks7057tmp.prg_7800 = prg_chip_byte_pnt(0, value << 11); // 0x8000 value = ks7057.reg[0]; control_bank(info.prg.rom[0].max.banks_2k) - ks7057_prg_8000 = prg_chip_byte_pnt(0, value << 11); + ks7057tmp.prg_8000 = prg_chip_byte_pnt(0, value << 11); // 0x8800 value = ks7057.reg[1]; control_bank(info.prg.rom[0].max.banks_2k) - ks7057_prg_8800 = prg_chip_byte_pnt(0, value << 11); + ks7057tmp.prg_8800 = prg_chip_byte_pnt(0, value << 11); // 0x9000 value = ks7057.reg[2]; control_bank(info.prg.rom[0].max.banks_2k) - ks7057_prg_9000 = prg_chip_byte_pnt(0, value << 11); + ks7057tmp.prg_9000 = prg_chip_byte_pnt(0, value << 11); // 0x9800 value = ks7057.reg[3]; control_bank(info.prg.rom[0].max.banks_2k) - ks7057_prg_9800 = prg_chip_byte_pnt(0, value << 11); + ks7057tmp.prg_9800 = prg_chip_byte_pnt(0, value << 11); // 0xA000 - 0xB000 value = 0x0D; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_KS7057.h puNES-0.105.new/src/core/mappers/mapper_KS7057.h --- puNES-0.105.org/src/core/mappers/mapper_KS7057.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_KS7057.h 2020-03-18 11:47:29.373142607 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _ks7057 { - BYTE reg[8]; -} ks7057; - void map_init_KS7057(void); void extcl_cpu_wr_mem_KS7057(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_KS7057(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_LH10.c puNES-0.105.new/src/core/mappers/mapper_LH10.c --- puNES-0.105.org/src/core/mappers/mapper_LH10.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_LH10.c 2020-03-18 11:47:29.373142607 +0100 @@ -24,8 +24,15 @@ INLINE static void lh10_update(void); -BYTE *lh10_prg_6000; -BYTE *lh10_prg_C000; +struct _lh10 { + BYTE ind; + BYTE reg[8]; +} lh10; +struct _lh10tmp { + BYTE *prg_6000; + BYTE *prg_C000; +} lh10tmp; + void map_init_LH10(void) { EXTCL_AFTER_MAPPER_INIT(LH10); @@ -58,7 +65,7 @@ void extcl_cpu_wr_mem_LH10(WORD address, case 0xC001: case 0xD000: case 0xD001: - lh10_prg_C000[address & 0x1FFF] = value; + lh10tmp.prg_C000[address & 0x1FFF] = value; return; case 0x8000: case 0x9000: @@ -83,10 +90,10 @@ BYTE extcl_cpu_rd_mem_LH10(WORD address, switch (address & 0xF000) { case 0x6000: case 0x7000: - return (lh10_prg_6000[address & 0x1FFF]); + return (lh10tmp.prg_6000[address & 0x1FFF]); case 0xC000: case 0xD000: - return (lh10_prg_C000[address & 0x1FFF]); + return (lh10tmp.prg_C000[address & 0x1FFF]); } return (openbus); } @@ -107,7 +114,7 @@ INLINE static void lh10_update(void) { // 0x6000 - 0x7000 value = 0xFE; control_bank(info.prg.rom[0].max.banks_8k) - lh10_prg_6000 = prg_chip_byte_pnt(0, value << 13); + lh10tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13); // 0x8000 - 0x9000 value = lh10.reg[6]; @@ -122,5 +129,5 @@ INLINE static void lh10_update(void) { prg.rom_8k[1] = prg_chip_byte_pnt(prg.rom_chip[0], mapper.rom_map_to[1] << 13); // 0xC000 - 0xD000 - lh10_prg_C000 = &prg.ram_plus_8k[0]; + lh10tmp.prg_C000 = &prg.ram_plus_8k[0]; } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_LH10.h puNES-0.105.new/src/core/mappers/mapper_LH10.h --- puNES-0.105.org/src/core/mappers/mapper_LH10.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_LH10.h 2020-03-18 11:47:29.373142607 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _lh10 { - BYTE ind; - BYTE reg[8]; -} lh10; - void map_init_LH10(void); void extcl_after_mapper_init_LH10(void); void extcl_cpu_wr_mem_LH10(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_LH32.c puNES-0.105.new/src/core/mappers/mapper_LH32.c --- puNES-0.105.org/src/core/mappers/mapper_LH32.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_LH32.c 2020-03-18 11:47:29.373142607 +0100 @@ -21,7 +21,12 @@ #include "info.h" #include "save_slot.h" -BYTE *lh32_prg_6000; +struct _lh32 { + BYTE reg; +} lh32; +struct _lh32tmp { + BYTE *prg_6000; +} lh32tmp; void map_init_LH32(void) { EXTCL_CPU_WR_MEM(LH32); @@ -50,7 +55,7 @@ void map_init_LH32(void) { map_prg_rom_8k_update(); } - lh32_prg_6000 = prg_chip_byte_pnt(0, lh32.reg << 13); + lh32tmp.prg_6000 = prg_chip_byte_pnt(0, lh32.reg << 13); info.prg.ram.banks_8k_plus = 1; @@ -61,7 +66,7 @@ void map_init_LH32(void) { void extcl_cpu_wr_mem_LH32(WORD address, BYTE value) { if (address == 0x6000) { control_bank(info.prg.rom[0].max.banks_8k) - lh32_prg_6000 = prg_chip_byte_pnt(0, value << 13); + lh32tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13); lh32.reg = value; return; } else if ((address & 0xE000) == 0xC000) { @@ -71,7 +76,7 @@ void extcl_cpu_wr_mem_LH32(WORD address, } BYTE extcl_cpu_rd_mem_LH32(WORD address, BYTE openbus, UNUSED(BYTE before)) { if ((address >= 0x6000) && (address <= 0x7FFF)) { - return (lh32_prg_6000[address & 0x1FFF]); + return (lh32tmp.prg_6000[address & 0x1FFF]); } else if ((address & 0xE000) == 0xC000) { return (prg.ram_plus_8k[address & 0x1FFF]); } @@ -81,7 +86,7 @@ BYTE extcl_save_mapper_LH32(BYTE mode, B save_slot_ele(mode, slot, lh32.reg); if (mode == SAVE_SLOT_READ) { - lh32_prg_6000 = prg_chip_byte_pnt(0, lh32.reg << 13); + lh32tmp.prg_6000 = prg_chip_byte_pnt(0, lh32.reg << 13); } return (EXIT_OK); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_LH32.h puNES-0.105.new/src/core/mappers/mapper_LH32.h --- puNES-0.105.org/src/core/mappers/mapper_LH32.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_LH32.h 2020-03-18 11:47:29.374142598 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _lh32 { - BYTE reg; -} lh32; - void map_init_LH32(void); void extcl_cpu_wr_mem_LH32(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_LH32(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MALISB.c puNES-0.105.new/src/core/mappers/mapper_MALISB.c --- puNES-0.105.org/src/core/mappers/mapper_MALISB.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MALISB.c 2020-03-18 11:47:29.374142598 +0100 @@ -81,6 +81,11 @@ INLINE static void malisb_update_chr(voi break;\ } +struct _malisb { + WORD prg_map[4]; + WORD chr_map[8]; +} malisb; + void map_init_MALISB(void) { EXTCL_CPU_WR_MEM(MALISB); EXTCL_SAVE_MAPPER(MALISB); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MALISB.h puNES-0.105.new/src/core/mappers/mapper_MALISB.h --- puNES-0.105.org/src/core/mappers/mapper_MALISB.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MALISB.h 2020-03-18 11:47:29.374142598 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _malisb { - WORD prg_map[4]; - WORD chr_map[8]; -} malisb; - void map_init_MALISB(void); void extcl_cpu_wr_mem_MALISB(WORD address, BYTE value); BYTE extcl_save_mapper_MALISB(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MMC1.c puNES-0.105.new/src/core/mappers/mapper_MMC1.c --- puNES-0.105.org/src/core/mappers/mapper_MMC1.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MMC1.c 2020-03-18 11:47:29.374142598 +0100 @@ -69,6 +69,19 @@ enum MMC1_regs { CTRL, CHR0, CHR1, PRG0 break;\ } +struct _mmc1 { + BYTE reg; + BYTE pos; + BYTE prg_mode; + BYTE chr_mode; + BYTE ctrl; + BYTE chr0; + BYTE chr1; + BYTE prg0; + BYTE reset; + BYTE prg_upper; +} mmc1; + void map_init_MMC1(void) { EXTCL_CPU_WR_MEM(MMC1); EXTCL_SAVE_MAPPER(MMC1); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MMC1.h puNES-0.105.new/src/core/mappers/mapper_MMC1.h --- puNES-0.105.org/src/core/mappers/mapper_MMC1.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MMC1.h 2020-03-18 11:47:29.374142598 +0100 @@ -23,19 +23,6 @@ enum MMC1_types { SNROM, SOROM, SUROM, SXROM, SEROM = 5, SKROM = 6, SJROM = 7, BAD_YOSHI_U = 20, MOWPC10 }; -struct _mmc1 { - BYTE reg; - BYTE pos; - BYTE prg_mode; - BYTE chr_mode; - BYTE ctrl; - BYTE chr0; - BYTE chr1; - BYTE prg0; - BYTE reset; - BYTE prg_upper; -} mmc1; - void map_init_MMC1(void); void extcl_cpu_wr_mem_MMC1(WORD address, BYTE value); BYTE extcl_save_mapper_MMC1(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MMC2andMMC4.c puNES-0.105.new/src/core/mappers/mapper_MMC2andMMC4.c --- puNES-0.105.org/src/core/mappers/mapper_MMC2andMMC4.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MMC2andMMC4.c 2020-03-18 11:47:29.374142598 +0100 @@ -22,6 +22,12 @@ #include "mem_map.h" #include "save_slot.h" +struct _mmc2and4 { + BYTE regs[4]; + BYTE latch0; + BYTE latch1; +} mmc2and4; + void map_init_MMC2and4(void) { EXTCL_CPU_WR_MEM(MMC2and4); EXTCL_SAVE_MAPPER(MMC2and4); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MMC2andMMC4.h puNES-0.105.new/src/core/mappers/mapper_MMC2andMMC4.h --- puNES-0.105.org/src/core/mappers/mapper_MMC2andMMC4.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MMC2andMMC4.h 2020-03-18 11:47:29.374142598 +0100 @@ -24,12 +24,6 @@ /* MMC4 */ enum { BAD_INES_FWJ }; -struct _mmc2and4 { - BYTE regs[4]; - BYTE latch0; - BYTE latch1; -} mmc2and4; - void map_init_MMC2and4(void); void extcl_cpu_wr_mem_MMC2and4(WORD address, BYTE value); BYTE extcl_save_mapper_MMC2and4(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MMC3.c puNES-0.105.new/src/core/mappers/mapper_MMC3.c --- puNES-0.105.org/src/core/mappers/mapper_MMC3.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MMC3.c 2020-03-18 11:47:29.374142598 +0100 @@ -33,6 +33,9 @@ mmc3.irq_reload = FALSE;\ } +_mmc3 mmc3; +_kt008 kt008; + void map_init_MMC3(void) { EXTCL_CPU_WR_MEM(MMC3); EXTCL_SAVE_MAPPER(MMC3); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MMC3.h puNES-0.105.new/src/core/mappers/mapper_MMC3.h --- puNES-0.105.org/src/core/mappers/mapper_MMC3.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MMC3.h 2020-03-18 11:47:29.374142598 +0100 @@ -44,15 +44,18 @@ enum { MMC6 }; -struct _mmc3 { +typedef struct _mmc3 { BYTE prg_ram_protect; BYTE bank_to_update; BYTE prg_rom_cfg; BYTE chr_rom_cfg; -} mmc3; -struct _kt008 { +} _mmc3; +typedef struct _kt008 { BYTE value; -} kt008; +} _kt008; + +extern _mmc3 mmc3; +extern _kt008 kt008; void map_init_MMC3(void); void extcl_cpu_wr_mem_MMC3(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MMC5.c puNES-0.105.new/src/core/mappers/mapper_MMC5.c --- puNES-0.105.org/src/core/mappers/mapper_MMC5.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MMC5.c 2020-03-18 11:47:29.374142598 +0100 @@ -20,7 +20,6 @@ #include "mappers.h" #include "info.h" #include "mem_map.h" -#include "apu.h" #include "ppu.h" #include "cpu.h" #include "irql2f.h" @@ -36,7 +35,7 @@ map_prg_rom_8k(1, slot, value);\ } else {\ /* modalita' ram */\ - BYTE bank = prg_ram_access[prg_ram_mode][value & 0x07];\ + BYTE bank = prg_ram_access[mmc5tmp.prg_ram_mode][value & 0x07];\ if (bank != INVALID) {\ mmc5.prg_ram_bank[slot][0] = TRUE;\ mmc5.prg_ram_bank[slot][1] = bank << 13;\ @@ -52,12 +51,12 @@ map_prg_rom_8k(2, 0, value);\ } else {\ /* modalita' ram */\ - BYTE bank = prg_ram_access[prg_ram_mode][value & 0x07];\ + BYTE bank = prg_ram_access[mmc5tmp.prg_ram_mode][value & 0x07];\ if (bank != INVALID) {\ mmc5.prg_ram_bank[0][0] = TRUE;\ mmc5.prg_ram_bank[0][1] = (value & 0x06) << 13;\ }\ - bank = prg_ram_access[prg_ram_mode][(value + 1) & 0x07];\ + bank = prg_ram_access[mmc5tmp.prg_ram_mode][(value + 1) & 0x07];\ if (bank != INVALID) {\ mmc5.prg_ram_bank[1][0] = TRUE;\ mmc5.prg_ram_bank[1][1] = (value & 0x07) << 13;\ @@ -163,7 +162,10 @@ static const BYTE prg_ram_access[6][8] = {0,1,2,3,4,4,4,4}, {0,1,2,3,4,5,6,7} }; -BYTE prg_ram_mode; +_mmc5 mmc5; +struct _mmc5tmp { + BYTE prg_ram_mode; +} mmc5tmp; void map_init_MMC5(void) { EXTCL_CPU_WR_MEM(MMC5); @@ -224,28 +226,28 @@ void map_init_MMC5(void) { case EKROM: info.prg.ram.banks_8k_plus = 1; info.prg.ram.bat.banks = 1; - prg_ram_mode = PRG_RAM_8K; + mmc5tmp.prg_ram_mode = PRG_RAM_8K; break; case ELROM: info.prg.ram.banks_8k_plus = FALSE; info.prg.ram.bat.banks = FALSE; - prg_ram_mode = PRG_RAM_NONE; + mmc5tmp.prg_ram_mode = PRG_RAM_NONE; break; case ETROM: info.prg.ram.banks_8k_plus = 2; info.prg.ram.bat.banks = 1; info.prg.ram.bat.start = 0; - prg_ram_mode = PRG_RAM_16K; + mmc5tmp.prg_ram_mode = PRG_RAM_16K; break; case EWROM: info.prg.ram.banks_8k_plus = 4; info.prg.ram.bat.banks = 4; - prg_ram_mode = PRG_RAM_32K; + mmc5tmp.prg_ram_mode = PRG_RAM_32K; break; default: info.prg.ram.banks_8k_plus = 8; info.prg.ram.bat.banks = FALSE; - prg_ram_mode = PRG_RAM_64K; + mmc5tmp.prg_ram_mode = PRG_RAM_64K; break; } } @@ -353,7 +355,7 @@ void extcl_cpu_wr_mem_MMC5(WORD address, memset(&mmc5.fill_table[0x3C0], filler_attrib[mmc5.fill_attr], 0x40); return; case 0x5113: { - BYTE bank = prg_ram_access[prg_ram_mode][value & 0x07]; + BYTE bank = prg_ram_access[mmc5tmp.prg_ram_mode][value & 0x07]; if (bank != INVALID) { prg.ram_plus_8k = &prg.ram_plus[bank * 0x2000]; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_MMC5.h puNES-0.105.new/src/core/mappers/mapper_MMC5.h --- puNES-0.105.org/src/core/mappers/mapper_MMC5.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_MMC5.h 2020-03-18 11:47:29.374142598 +0100 @@ -23,7 +23,7 @@ enum { EKROM, ELROM, ETROM, EWROM }; -struct _mmc5 { +typedef struct _mmc5 { BYTE prg_mode; BYTE chr_mode; BYTE ext_mode; @@ -63,7 +63,9 @@ struct _mmc5 { /* ------------------------------------------------------- */ /* */ BYTE clocked; /* */ /* ------------------------------------------------------- */ -} mmc5; +} _mmc5; + +extern _mmc5 mmc5; void map_init_MMC5(void); void map_init_NSF_MMC5(void); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Namco.c puNES-0.105.new/src/core/mappers/mapper_Namco.c --- puNES-0.105.org/src/core/mappers/mapper_Namco.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Namco.c 2020-03-18 11:47:29.374142598 +0100 @@ -21,7 +21,6 @@ #include "info.h" #include "mem_map.h" #include "cpu.h" -#include "apu.h" #include "save_slot.h" #define n163_prg_rom_8k_update(slot)\ @@ -31,7 +30,7 @@ #define _n163_nmt_update(slot)\ ntbl.bank_1k[slot] = chr_chip_byte_pnt(0, n163.nmt_bank[slot][1]) #define n163_nmt_update(slot)\ - if (hardwired) {\ + if (namcotmp.hardwired) {\ return;\ }\ if (value >= 0xE0) {\ @@ -63,11 +62,22 @@ _n163_ch_freq((n163.ch[channel].freq & 0x3FF00) | value, channel) #define n3425_nmt_update()\ - if (type == N3425) {\ + if (namcotmp.type == N3425) {\ ntbl.bank_1k[n3425.bank_to_update >> 1] = &ntbl.data[((value >> 5) & 0x01) << 10];\ } -BYTE hardwired, type; +struct _n3425 { + BYTE bank_to_update; +} n3425; +struct _n3446 { + BYTE bank_to_update; + BYTE prg_rom_mode; +} n3446; +_n163 n163; +struct _namcotmp { + BYTE hardwired; + BYTE type; +} namcotmp; void map_init_Namco(BYTE model) { switch (model) { @@ -95,15 +105,15 @@ void map_init_Namco(BYTE model) { } info.mapper.extend_wr = TRUE; - hardwired = FALSE; + namcotmp.hardwired = FALSE; switch (info.id) { case NAMCO_HARD_WIRED_V: - hardwired = TRUE; + namcotmp.hardwired = TRUE; mirroring_V(); break; case NAMCO_HARD_WIRED_H: - hardwired = TRUE; + namcotmp.hardwired = TRUE; mirroring_H(); break; case MINDSEEKER: @@ -143,7 +153,7 @@ void map_init_Namco(BYTE model) { break; } - type = model; + namcotmp.type = model; } void map_init_NSF_Namco(BYTE model) { memset(&n163, 0x00, sizeof(n163)); @@ -151,7 +161,7 @@ void map_init_NSF_Namco(BYTE model) { n163.snd_ch_start = 7; n163.snd_auto_inc = 1; - type = model; + namcotmp.type = model; } void extcl_cpu_wr_mem_Namco_163(WORD address, BYTE value) { @@ -365,7 +375,7 @@ void extcl_cpu_wr_mem_Namco_3425(WORD ad switch (address & 0xA001) { case 0x8000: n3425.bank_to_update = value & 0x07; - if (type == N3453) { + if (namcotmp.type == N3453) { if (value & 0x40) { mirroring_SCR1(); } else { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Namco.h puNES-0.105.new/src/core/mappers/mapper_Namco.h --- puNES-0.105.org/src/core/mappers/mapper_Namco.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Namco.h 2020-03-18 11:47:29.374142598 +0100 @@ -45,7 +45,7 @@ typedef struct _n163_snd_ch { WORD volume; SWORD output; } _n163_snd_ch; -struct _n163 { +typedef struct _n163 { uint32_t nmt_bank[4][2]; BYTE irq_delay; DBWORD irq_count; @@ -55,14 +55,9 @@ struct _n163 { BYTE snd_ch_start; BYTE snd_wave[0x100]; _n163_snd_ch ch[8]; -} n163; -struct _n3425 { - BYTE bank_to_update; -} n3425; -struct _n3446 { - BYTE bank_to_update; - BYTE prg_rom_mode; -} n3446; +} _n163; + +extern _n163 n163; void map_init_Namco(BYTE model); void map_init_NSF_Namco(BYTE model); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Ntdec.c puNES-0.105.new/src/core/mappers/mapper_Ntdec.c --- puNES-0.105.org/src/core/mappers/mapper_Ntdec.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Ntdec.c 2020-03-18 11:47:29.374142598 +0100 @@ -38,6 +38,11 @@ bank = new_value << 10;\ chr.bank_1k[slot] = chr_chip_byte_pnt(0, bank) +struct _asder { + BYTE address; + BYTE reg[8]; +} asder; + void map_init_Ntdec(BYTE model) { switch (model) { case ASDER: diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Ntdec.h puNES-0.105.new/src/core/mappers/mapper_Ntdec.h --- puNES-0.105.org/src/core/mappers/mapper_Ntdec.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Ntdec.h 2020-03-18 11:47:29.374142598 +0100 @@ -23,11 +23,6 @@ enum { ASDER, FHERO }; -struct _asder { - BYTE address; - BYTE reg[8]; -} asder; - void map_init_Ntdec(BYTE model); void extcl_cpu_wr_mem_Ntdec_asder(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Rcm.h puNES-0.105.new/src/core/mappers/mapper_Rcm.h --- puNES-0.105.org/src/core/mappers/mapper_Rcm.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Rcm.h 2020-03-18 11:47:29.374142598 +0100 @@ -24,7 +24,6 @@ enum { GS2015 }; void map_init_Rcm(BYTE type); - void extcl_cpu_wr_mem_GS2015(WORD address, BYTE value); #endif /* MAPPER_RCM_H_ */ diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Rex.c puNES-0.105.new/src/core/mappers/mapper_Rex.c --- puNES-0.105.org/src/core/mappers/mapper_Rex.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Rex.c 2020-03-18 11:47:29.375142590 +0100 @@ -48,6 +48,11 @@ }\ } +struct _rex_dbz { + WORD chr_rom_bank[8]; + BYTE chr_high; +} rex_dbz; + void map_init_Rex(BYTE model) { if (model == DBZ) { EXTCL_CPU_WR_MEM(Rex_dbz); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Rex.h puNES-0.105.new/src/core/mappers/mapper_Rex.h --- puNES-0.105.org/src/core/mappers/mapper_Rex.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Rex.h 2020-03-18 11:47:29.375142590 +0100 @@ -23,11 +23,6 @@ enum { DBZ }; -struct _rex_dbz { - WORD chr_rom_bank[8]; - BYTE chr_high; -} rex_dbz; - void map_init_Rex(BYTE model); void extcl_cpu_wr_mem_Rex_dbz(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_Rex_dbz(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_SA_9602B.c puNES-0.105.new/src/core/mappers/mapper_SA_9602B.c --- puNES-0.105.org/src/core/mappers/mapper_SA_9602B.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_SA_9602B.c 2020-03-18 11:47:29.375142590 +0100 @@ -59,6 +59,11 @@ INLINE static void sa9602b_update_prg(vo break;\ } +struct _sa9602b { + WORD prg_chip[4]; + WORD prg_map[4]; +} sa9602b; + void map_init_SA_9602B(void) { EXTCL_CPU_WR_MEM(SA_9602B); EXTCL_SAVE_MAPPER(SA_9602B); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_SA_9602B.h puNES-0.105.new/src/core/mappers/mapper_SA_9602B.h --- puNES-0.105.org/src/core/mappers/mapper_SA_9602B.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_SA_9602B.h 2020-03-18 11:47:29.375142590 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _sa9602b { - WORD prg_chip[4]; - WORD prg_map[4]; -} sa9602b; - void map_init_SA_9602B(void); void extcl_cpu_wr_mem_SA_9602B(WORD address, BYTE value); BYTE extcl_save_mapper_SA_9602B(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Sachen.c puNES-0.105.new/src/core/mappers/mapper_Sachen.c --- puNES-0.105.org/src/core/mappers/mapper_Sachen.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Sachen.c 2020-03-18 11:47:29.375142590 +0100 @@ -39,7 +39,22 @@ sa74374x.chr_rom_8k_bank = value;\ } -BYTE type, shift, ored[3]; +struct _sa8259 { + BYTE ctrl; + BYTE reg[8]; +} sa8259; +struct _tcu02 { + BYTE reg; +} tcu02; +struct _sa74374x { + BYTE reg; + BYTE chr_rom_8k_bank; +} sa74374x; +struct _sachentmp { + BYTE type; + BYTE shift; + BYTE ored[3]; +} sachentmp; void map_init_Sachen(BYTE model) { switch (model) { @@ -76,22 +91,22 @@ void map_init_Sachen(BYTE model) { switch (model) { case SA8259A: - shift = 1; - ored[0] = 1; - ored[1] = 0; - ored[2] = 1; + sachentmp.shift = 1; + sachentmp.ored[0] = 1; + sachentmp.ored[1] = 0; + sachentmp.ored[2] = 1; break; case SA8259B: - shift = 0; - ored[0] = 0; - ored[1] = 0; - ored[2] = 0; + sachentmp.shift = 0; + sachentmp.ored[0] = 0; + sachentmp.ored[1] = 0; + sachentmp.ored[2] = 0; break; case SA8259C: - shift = 2; - ored[0] = 1; - ored[1] = 2; - ored[2] = 3; + sachentmp.shift = 2; + sachentmp.ored[0] = 1; + sachentmp.ored[1] = 2; + sachentmp.ored[2] = 3; break; case SA8259D: if (!mapper.write_vram) { @@ -181,7 +196,7 @@ void map_init_Sachen(BYTE model) { } } - type = model; + sachentmp.type = model; } void extcl_cpu_wr_mem_Sachen_sa0036(UNUSED(WORD address), BYTE value) { @@ -270,7 +285,7 @@ void extcl_cpu_wr_mem_Sachen_sa8259x(WOR if (!mapper.write_vram) { DBWORD bank; - if (type == SA8259D) { + if (sachentmp.type == SA8259D) { value = sa8259.reg[0] & 0x07; control_bank(info.chr.rom[0].max.banks_1k) @@ -287,36 +302,35 @@ void extcl_cpu_wr_mem_Sachen_sa8259x(WOR bank = value << 10; chr.bank_1k[2] = chr_chip_byte_pnt(0, bank); - value = (sa8259.reg[3] & 0x07) | ((sa8259.reg[4] << 2) & 0x10) - | ((sa8259.reg[6] << 3) & 0x08); + value = (sa8259.reg[3] & 0x07) | ((sa8259.reg[4] << 2) & 0x10) | ((sa8259.reg[6] << 3) & 0x08); control_bank(info.chr.rom[0].max.banks_1k) bank = value << 10; chr.bank_1k[3] = chr_chip_byte_pnt(0, bank); } else { const BYTE high = (sa8259.reg[4] << 3) & 0x38; - value = (high | (sa8259.reg[0] & 0x07)) << shift; + value = (high | (sa8259.reg[0] & 0x07)) << sachentmp.shift; control_bank(info.chr.rom[0].max.banks_2k) bank = value << 11; chr.bank_1k[0] = chr_chip_byte_pnt(0, bank); chr.bank_1k[1] = chr_chip_byte_pnt(0, bank | 0x0400); value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 1] & 0x07)) - << shift) | ored[0]; + << sachentmp.shift) | sachentmp.ored[0]; control_bank(info.chr.rom[0].max.banks_2k) bank = value << 11; chr.bank_1k[2] = chr_chip_byte_pnt(0, bank); chr.bank_1k[3] = chr_chip_byte_pnt(0, bank | 0x0400); value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 2] & 0x07)) - << shift) | ored[1]; + << sachentmp.shift) | sachentmp.ored[1]; control_bank(info.chr.rom[0].max.banks_2k) bank = value << 11; chr.bank_1k[4] = chr_chip_byte_pnt(0, bank); chr.bank_1k[5] = chr_chip_byte_pnt(0, bank | 0x0400); value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 3] & 0x07)) - << shift) | ored[2]; + << sachentmp.shift) | sachentmp.ored[2]; control_bank(info.chr.rom[0].max.banks_2k) bank = value << 11; chr.bank_1k[6] = chr_chip_byte_pnt(0, bank); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Sachen.h puNES-0.105.new/src/core/mappers/mapper_Sachen.h --- puNES-0.105.org/src/core/mappers/mapper_Sachen.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Sachen.h 2020-03-18 11:47:29.375142590 +0100 @@ -37,18 +37,6 @@ enum { SA74374B, }; -struct _sa8259 { - BYTE ctrl; - BYTE reg[8]; -} sa8259; -struct _tcu02 { - BYTE reg; -} tcu02; -struct _sa74374x { - BYTE reg; - BYTE chr_rom_8k_bank; -} sa74374x; - static const char pokeriiichr[2][41] = { "5066c2d12ff2ac45ef395d3a4353e897fce19f78", "c6bf926ed14c21f1a5b64fbccf3288005ff54be5" diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_SC_127.c puNES-0.105.new/src/core/mappers/mapper_SC_127.c --- puNES-0.105.org/src/core/mappers/mapper_SC_127.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_SC_127.c 2020-03-18 11:47:29.375142590 +0100 @@ -24,6 +24,13 @@ #include "ppu.h" #include "save_slot.h" +struct _sc127 { + struct _sc127_irq { + BYTE active; + WORD count; + } irq; +} sc127; + void map_init_SC_127(void) { EXTCL_CPU_WR_MEM(SC_127); EXTCL_CPU_RD_MEM(SC_127); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_SC_127.h puNES-0.105.new/src/core/mappers/mapper_SC_127.h --- puNES-0.105.org/src/core/mappers/mapper_SC_127.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_SC_127.h 2020-03-18 11:47:29.375142590 +0100 @@ -21,13 +21,6 @@ #include "common.h" -struct _sc127 { - struct _sc127_irq { - BYTE active; - WORD count; - } irq; -} sc127; - void map_init_SC_127(void); void extcl_cpu_wr_mem_SC_127(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_SC_127(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_SHERO.c puNES-0.105.new/src/core/mappers/mapper_SHERO.c --- puNES-0.105.org/src/core/mappers/mapper_SHERO.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_SHERO.c 2020-03-18 11:47:29.375142590 +0100 @@ -63,7 +63,13 @@ INLINE static void shero_update_chr(void break;\ } -BYTE shero_reset; +struct _shero { + BYTE reg; + WORD chr_map[8]; +} shero; +struct _sherotmp { + BYTE reset; +} sherotmp; void map_init_SHERO(void) { EXTCL_CPU_WR_MEM(SHERO); @@ -86,9 +92,9 @@ void map_init_SHERO(void) { memset(&irqA12, 0x00, sizeof(irqA12)); if (info.reset >= HARD) { - shero_reset = 0; + sherotmp.reset = 0; } else if (info.reset == RESET) { - shero_reset ^= 0xFF; + sherotmp.reset ^= 0xFF; } map_chr_ram_extra_init(0x2000); @@ -137,7 +143,7 @@ void extcl_cpu_wr_mem_SHERO(WORD address } BYTE extcl_cpu_rd_mem_SHERO(WORD address, BYTE openbus, UNUSED(BYTE before)) { if (address == 0x4100) { - return (shero_reset); + return (sherotmp.reset); } return (openbus); } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_SHERO.h puNES-0.105.new/src/core/mappers/mapper_SHERO.h --- puNES-0.105.org/src/core/mappers/mapper_SHERO.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_SHERO.h 2020-03-18 11:47:29.375142590 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _shero { - BYTE reg; - WORD chr_map[8]; -} shero; - void map_init_SHERO(void); void extcl_cpu_wr_mem_SHERO(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_SHERO(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_SL1632.c puNES-0.105.new/src/core/mappers/mapper_SL1632.c --- puNES-0.105.org/src/core/mappers/mapper_SL1632.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_SL1632.c 2020-03-18 11:47:29.375142590 +0100 @@ -96,6 +96,18 @@ INLINE static void sl1632_update(void); mirroring_V();\ } +struct _sl1632 { + BYTE mode; + BYTE mirroring; + WORD prg_map[2]; + WORD chr_map[8]; + struct _sl1632_mmc3 { + BYTE mirroring; + WORD prg_map[4]; + WORD chr_map[8]; + } mmc3; +} sl1632; + void map_init_SL1632(void) { EXTCL_CPU_WR_MEM(SL1632); EXTCL_SAVE_MAPPER(SL1632); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_SL1632.h puNES-0.105.new/src/core/mappers/mapper_SL1632.h --- puNES-0.105.org/src/core/mappers/mapper_SL1632.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_SL1632.h 2020-03-18 11:47:29.375142590 +0100 @@ -21,18 +21,6 @@ #include "common.h" -struct _sl1632 { - BYTE mode; - BYTE mirroring; - WORD prg_map[2]; - WORD chr_map[8]; - struct _sl1632_mmc3 { - BYTE mirroring; - WORD prg_map[4]; - WORD chr_map[8]; - } mmc3; -} sl1632; - void map_init_SL1632(void); void extcl_cpu_wr_mem_SL1632(WORD address, BYTE value); BYTE extcl_save_mapper_SL1632(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Sunsoft.c puNES-0.105.new/src/core/mappers/mapper_Sunsoft.c --- puNES-0.105.org/src/core/mappers/mapper_Sunsoft.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Sunsoft.c 2020-03-18 11:47:29.375142590 +0100 @@ -94,7 +94,21 @@ fm7.square[sq].output = fm7.square[sq].volume * ((fm7.square[sq].step & 0x10) ? 1 : 0);\ } -BYTE type; +struct _sunsoft3 { + BYTE enable; + BYTE toggle; + WORD count; + BYTE delay; +} s3; +struct _sunsoft4 { + uint32_t chr_nmt[2]; + BYTE mode; + BYTE mirroring; +} s4; +_sunsoft_fm7 fm7; +struct _sunsofttmp { + BYTE type; +} sunsofttmp; void map_init_Sunsoft(BYTE model) { switch (model) { @@ -161,7 +175,7 @@ void map_init_Sunsoft(BYTE model) { break; } - type = model; + sunsofttmp.type = model; } void map_init_NSF_Sunsoft(BYTE model) { memset(&fm7, 0x00, sizeof(fm7)); @@ -170,7 +184,7 @@ void map_init_NSF_Sunsoft(BYTE model) { fm7.square[1].timer = 1; fm7.square[2].timer = 1; - type = model; + sunsofttmp.type = model; } void extcl_cpu_wr_mem_Sunsoft_S1(WORD address, BYTE value) { @@ -204,7 +218,7 @@ void extcl_cpu_wr_mem_Sunsoft_S2(UNUSED( const BYTE save = value; DBWORD bank; - if (type == SUN2B) { + if (sunsofttmp.type == SUN2B) { if (value & 0x08) { mirroring_SCR1(); } else { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Sunsoft.h puNES-0.105.new/src/core/mappers/mapper_Sunsoft.h --- puNES-0.105.org/src/core/mappers/mapper_Sunsoft.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Sunsoft.h 2020-03-18 11:47:29.375142590 +0100 @@ -41,19 +41,7 @@ typedef struct _square_fm7 { WORD volume; SWORD output; } _square_fm7; - -struct _sunsoft3 { - BYTE enable; - BYTE toggle; - WORD count; - BYTE delay; -} s3; -struct _sunsoft4 { - uint32_t chr_nmt[2]; - BYTE mode; - BYTE mirroring; -} s4; -struct _sunsoft_fm7 { +typedef struct _sunsoft_fm7 { BYTE address; BYTE prg_ram_enable; BYTE prg_ram_mode; @@ -70,7 +58,9 @@ struct _sunsoft_fm7 { /* ------------------------------------------------------- */ /* */ BYTE clocked; /* */ /* ------------------------------------------------------- */ -} fm7; +} _sunsoft_fm7; + +extern _sunsoft_fm7 fm7; void map_init_Sunsoft(BYTE model); void map_init_NSF_Sunsoft(BYTE model); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Super24in1.c puNES-0.105.new/src/core/mappers/mapper_Super24in1.c --- puNES-0.105.org/src/core/mappers/mapper_Super24in1.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Super24in1.c 2020-03-18 11:47:29.375142590 +0100 @@ -81,6 +81,12 @@ INLINE static void super24in1_update_chr static const BYTE super24in1_mask[8] = { 0x3F, 0x1F, 0x0F, 0x01, 0x03, 0x00, 0x00, 0x00 }; +struct _super24in1 { + BYTE reg[3]; + WORD prg_map[4]; + WORD chr_map[8]; +} super24in1; + void map_init_Super24in1(void) { EXTCL_CPU_WR_MEM(Super24in1); EXTCL_SAVE_MAPPER(Super24in1); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Super24in1.h puNES-0.105.new/src/core/mappers/mapper_Super24in1.h --- puNES-0.105.org/src/core/mappers/mapper_Super24in1.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Super24in1.h 2020-03-18 11:47:29.375142590 +0100 @@ -21,12 +21,6 @@ #include "common.h" -struct _super24in1 { - BYTE reg[3]; - WORD prg_map[4]; - WORD chr_map[8]; -} super24in1; - void map_init_Super24in1(void); void extcl_cpu_wr_mem_Super24in1(WORD address, BYTE value); BYTE extcl_save_mapper_Super24in1(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_T262.c puNES-0.105.new/src/core/mappers/mapper_T262.c --- puNES-0.105.org/src/core/mappers/mapper_T262.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_T262.c 2020-03-18 11:47:29.376142582 +0100 @@ -24,6 +24,10 @@ INLINE static void t262_update(BYTE value); +struct _t262 { + BYTE reg[5]; +} t262; + void map_init_T262(void) { EXTCL_CPU_WR_MEM(T262); EXTCL_SAVE_MAPPER(T262); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_T262.h puNES-0.105.new/src/core/mappers/mapper_T262.h --- puNES-0.105.org/src/core/mappers/mapper_T262.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_T262.h 2020-03-18 11:47:29.376142582 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _t262 { - BYTE reg[5]; -} t262; - void map_init_T262(void); void extcl_cpu_wr_mem_T262(WORD address, BYTE value); BYTE extcl_save_mapper_T262(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Taito.c puNES-0.105.new/src/core/mappers/mapper_Taito.c --- puNES-0.105.org/src/core/mappers/mapper_Taito.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Taito.c 2020-03-18 11:47:29.376142582 +0100 @@ -20,10 +20,22 @@ #include "mappers.h" #include "info.h" #include "mem_map.h" +#include "cpu.h" +#include "ppu.h" #include "irqA12.h" #include "save_slot.h" -BYTE type; +struct _taito_X1005 { + BYTE ram[0x80]; + BYTE enable; +} taito_X1005; +struct _taito_X1017 { + BYTE chr[6]; + BYTE control; +} taito_X1017; +struct _taitotmp { + BYTE type; +} taitotmp; void map_init_Taito(BYTE model) { switch (model) { @@ -96,7 +108,7 @@ void map_init_Taito(BYTE model) { break; } - type = model; + taitotmp.type = model; } void extcl_cpu_wr_mem_Taito_TC0190FMC(WORD address, BYTE value) { @@ -247,7 +259,7 @@ void extcl_cpu_wr_mem_Taito_X1005(WORD a const BYTE slot = (address & 0x0001) << 1; DBWORD bank; - if (type == X1005B) { + if (taitotmp.type == X1005B) { if (value & 0x80) { mirroring_SCR1(); } else { @@ -263,7 +275,7 @@ void extcl_cpu_wr_mem_Taito_X1005(WORD a } case 0x7EF2: case 0x7EF4: - if (type == X1005B) { + if (taitotmp.type == X1005B) { if (value & 0x80) { mirroring_SCR1(); } else { @@ -274,7 +286,7 @@ void extcl_cpu_wr_mem_Taito_X1005(WORD a chr.bank_1k[(address & 0x0007) + 2] = chr_chip_byte_pnt(0, value << 10); return; case 0x7EF6: - if (type == X1005A) { + if (taitotmp.type == X1005A) { if (value & 0x01) { mirroring_V(); } else { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Taito.h puNES-0.105.new/src/core/mappers/mapper_Taito.h --- puNES-0.105.org/src/core/mappers/mapper_Taito.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Taito.h 2020-03-18 11:47:29.376142582 +0100 @@ -31,15 +31,6 @@ enum { X1005_NO_BAT = 101 }; -struct _taito_X1005 { - BYTE ram[0x80]; - BYTE enable; -} taito_X1005; -struct _taito_X1017 { - BYTE chr[6]; - BYTE control; -} taito_X1017; - void map_init_Taito(BYTE model); void extcl_cpu_wr_mem_Taito_TC0190FMC(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Tengen.c puNES-0.105.new/src/core/mappers/mapper_Tengen.c --- puNES-0.105.org/src/core/mappers/mapper_Tengen.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Tengen.c 2020-03-18 11:47:29.376142582 +0100 @@ -103,7 +103,20 @@ enum { INLINE static void irq_clock_Tengen_Rambo(int delay); -BYTE type; +struct _tengen_rambo { + BYTE prg_mode; + BYTE chr_mode; + BYTE reg_index; + BYTE chr[8]; + BYTE prg[4]; + BYTE irq_mode; + BYTE irq_delay; + BYTE irq_prescaler; + BYTE irq_plus_clock; +} tengen_rambo; +struct _tengentmp { + BYTE type; +} tengentmp; void map_init_Tengen(BYTE model) { switch (model) { @@ -151,7 +164,7 @@ void map_init_Tengen(BYTE model) { break; } - type = model; + tengentmp.type = model; } void extcl_cpu_wr_mem_Tengen_Rambo(WORD address, BYTE value) { @@ -171,7 +184,7 @@ void extcl_cpu_wr_mem_Tengen_Rambo(WORD switch (tengen_rambo.reg_index) { case 0x00: case 0x01: - if ((type == T800037) && !(tengen_rambo.chr_mode & 0x80)) { + if ((tengentmp.type == T800037) && !(tengen_rambo.chr_mode & 0x80)) { const BYTE slot = tengen_rambo.reg_index << 1; ntbl.bank_1k[slot] = &ntbl.data[((value >> 7) ^ 0x01) << 10]; @@ -186,7 +199,7 @@ void extcl_cpu_wr_mem_Tengen_Rambo(WORD case 0x03: case 0x04: case 0x05: - if ((type == T800037) && (tengen_rambo.chr_mode & 0x80)) { + if ((tengentmp.type == T800037) && (tengen_rambo.chr_mode & 0x80)) { ntbl.bank_1k[tengen_rambo.reg_index - 2] = &ntbl.data[((value >> 7) ^ 0x01) << 10]; } @@ -229,7 +242,7 @@ void extcl_cpu_wr_mem_Tengen_Rambo(WORD return; } case 0xA000: - if (type == T800037) { + if (tengentmp.type == T800037) { return; } if (value & 0x01) { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Tengen.h puNES-0.105.new/src/core/mappers/mapper_Tengen.h --- puNES-0.105.org/src/core/mappers/mapper_Tengen.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Tengen.h 2020-03-18 11:47:29.376142582 +0100 @@ -23,18 +23,6 @@ enum { TRAMBO, T800037, NOCNTPLUS }; -struct _tengen_rambo { - BYTE prg_mode; - BYTE chr_mode; - BYTE reg_index; - BYTE chr[8]; - BYTE prg[4]; - BYTE irq_mode; - BYTE irq_delay; - BYTE irq_prescaler; - BYTE irq_plus_clock; -} tengen_rambo; - void map_init_Tengen(BYTE model); void extcl_cpu_wr_mem_Tengen_Rambo(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_TF1201.c puNES-0.105.new/src/core/mappers/mapper_TF1201.c --- puNES-0.105.org/src/core/mappers/mapper_TF1201.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_TF1201.c 2020-03-18 11:47:29.376142582 +0100 @@ -31,6 +31,11 @@ chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\ tf1201.chr_rom_bank[slot] = value +struct _tf1201 { + BYTE chr_rom_bank[8]; + BYTE swap_mode; +} tf1201; + void map_init_TF1201(void) { EXTCL_CPU_WR_MEM(TF1201); EXTCL_SAVE_MAPPER(TF1201); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_TF1201.h puNES-0.105.new/src/core/mappers/mapper_TF1201.h --- puNES-0.105.org/src/core/mappers/mapper_TF1201.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_TF1201.h 2020-03-18 11:47:29.376142582 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _tf1201 { - BYTE chr_rom_bank[8]; - BYTE swap_mode; -} tf1201; - void map_init_TF1201(void); void extcl_cpu_wr_mem_TF1201(WORD address, BYTE value); BYTE extcl_save_mapper_TF1201(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Txc.c puNES-0.105.new/src/core/mappers/mapper_Txc.c --- puNES-0.105.org/src/core/mappers/mapper_Txc.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Txc.c 2020-03-18 11:47:29.376142582 +0100 @@ -23,7 +23,12 @@ #include "irqA12.h" #include "save_slot.h" -BYTE type; +struct _t22211x { + BYTE reg[4]; +} t22211x; +struct _txctmp { + BYTE type; +} txctmp; void map_init_Txc(BYTE model) { switch (model) { @@ -73,7 +78,7 @@ void map_init_Txc(BYTE model) { break; } - type = model; + txctmp.type = model; } void extcl_cpu_wr_mem_Txc_tw(WORD address, BYTE value) { @@ -114,7 +119,7 @@ void extcl_cpu_wr_mem_Txc_t22211x(WORD a { DBWORD bank; - if (type == T22211B) { + if (txctmp.type == T22211B) { value = (((save ^ t22211x.reg[2]) >> 3) & 0x02) | (((save ^ t22211x.reg[2]) >> 5) & 0x01); } else { @@ -140,7 +145,7 @@ BYTE extcl_cpu_rd_mem_Txc_t22211x(WORD a return (openbus); } - if (type == T22211C) { + if (txctmp.type == T22211C) { return ((t22211x.reg[1] ^ t22211x.reg[2]) | 0x41); } else { return ((t22211x.reg[1] ^ t22211x.reg[2]) | 0x40); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Txc.h puNES-0.105.new/src/core/mappers/mapper_Txc.h --- puNES-0.105.org/src/core/mappers/mapper_Txc.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Txc.h 2020-03-18 11:47:29.376142582 +0100 @@ -23,10 +23,6 @@ enum { TXCTW, T22211A, T22211B, T22211C }; -struct _t22211x { - BYTE reg[4]; -} t22211x; - void map_init_Txc(BYTE model); void extcl_cpu_wr_mem_Txc_tw(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_TxROM.c puNES-0.105.new/src/core/mappers/mapper_TxROM.c --- puNES-0.105.org/src/core/mappers/mapper_TxROM.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_TxROM.c 2020-03-18 11:47:29.376142582 +0100 @@ -65,7 +65,13 @@ }\ } -BYTE type; +struct _txrom { + BYTE delay; + uint32_t chr[8][2]; +} txrom; +struct _txromtmp { + BYTE type; +} txromtmp; void map_init_TxROM(BYTE model) { switch (model) { @@ -117,7 +123,7 @@ void map_init_TxROM(BYTE model) { irqA12.present = TRUE; - type = model; + txromtmp.type = model; } void extcl_cpu_wr_mem_TKSROM(WORD address, BYTE value) { @@ -195,7 +201,7 @@ void extcl_wr_chr_TQROM(WORD address, BY BYTE extcl_save_mapper_TxROM(BYTE mode, BYTE slot, FILE *fp) { save_slot_ele(mode, slot, txrom.delay); - if (type == TQROM) { + if (txromtmp.type == TQROM) { save_slot_ele(mode, slot, txrom.chr); if (mode == SAVE_SLOT_READ) { BYTE i; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_TxROM.h puNES-0.105.new/src/core/mappers/mapper_TxROM.h --- puNES-0.105.org/src/core/mappers/mapper_TxROM.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_TxROM.h 2020-03-18 11:47:29.376142582 +0100 @@ -23,11 +23,6 @@ enum { TKSROM, TLSROM, TQROM }; -struct _txrom { - BYTE delay; - uint32_t chr[8][2]; -} txrom; - void map_init_TxROM(BYTE model); void extcl_cpu_wr_mem_TKSROM(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF158B.c puNES-0.105.new/src/core/mappers/mapper_UNIF158B.c --- puNES-0.105.org/src/core/mappers/mapper_UNIF158B.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF158B.c 2020-03-18 11:47:29.376142582 +0100 @@ -45,6 +45,11 @@ INLINE static void unif158b_update_prg(v static const BYTE unif158b_vlu[8] = { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0F, 0x00 }; +struct _unif158b { + BYTE reg[8]; + WORD prg_map[4]; +} unif158b; + void map_init_UNIF158B(void) { EXTCL_CPU_WR_MEM(UNIF158B); EXTCL_CPU_RD_MEM(UNIF158B); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF158B.h puNES-0.105.new/src/core/mappers/mapper_UNIF158B.h --- puNES-0.105.org/src/core/mappers/mapper_UNIF158B.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF158B.h 2020-03-18 11:47:29.376142582 +0100 @@ -21,11 +21,6 @@ #include "common.h" -struct _unif158b { - BYTE reg[8]; - WORD prg_map[4]; -} unif158b; - void map_init_UNIF158B(void); void extcl_cpu_wr_mem_UNIF158B(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_UNIF158B(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF43272.c puNES-0.105.new/src/core/mappers/mapper_UNIF43272.c --- puNES-0.105.org/src/core/mappers/mapper_UNIF43272.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF43272.c 2020-03-18 11:47:29.376142582 +0100 @@ -21,6 +21,10 @@ #include "mem_map.h" #include "save_slot.h" +struct _unif43272 { + WORD address; +} unif43272; + void map_init_UNIF43272(void) { EXTCL_CPU_WR_MEM(UNIF43272); EXTCL_CPU_RD_MEM(UNIF43272); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF43272.h puNES-0.105.new/src/core/mappers/mapper_UNIF43272.h --- puNES-0.105.org/src/core/mappers/mapper_UNIF43272.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF43272.h 2020-03-18 11:47:29.376142582 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _unif43272 { - WORD address; -} unif43272; - void map_init_UNIF43272(void); void extcl_cpu_wr_mem_UNIF43272(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_UNIF43272(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.c puNES-0.105.new/src/core/mappers/mapper_UNIF603_5052.c --- puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF603_5052.c 2020-03-18 11:50:06.431791564 +0100 @@ -1,70 +1,74 @@ -/* - * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include -#include "mappers.h" -#include "info.h" -#include "irqA12.h" -#include "save_slot.h" - -static const BYTE unif603_5052_vlu[4] = { 0x00, 0x02, 0x02, 0x03 }; - -void map_init_UNIF603_5052(void) { - EXTCL_CPU_WR_MEM(UNIF603_5052); - EXTCL_CPU_RD_MEM(UNIF603_5052); - EXTCL_SAVE_MAPPER(UNIF603_5052); - EXTCL_CPU_EVERY_CYCLE(MMC3); - EXTCL_PPU_000_TO_34X(MMC3); - EXTCL_PPU_000_TO_255(MMC3); - EXTCL_PPU_256_TO_319(MMC3); - EXTCL_PPU_320_TO_34X(MMC3); - EXTCL_UPDATE_R2006(MMC3); - mapper.internal_struct[1] = (BYTE *) &mmc3; - mapper.internal_struct_size[1] = sizeof(mmc3); - - memset(&mmc3, 0x00, sizeof(mmc3)); - memset(&irqA12, 0x00, sizeof(irqA12)); - - info.mapper.extend_wr = TRUE; - - irqA12.present = TRUE; - irqA12_delay = 1; -} -void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value) { - if (address >= 0x8000) { - extcl_cpu_wr_mem_MMC3(address, value); - return; - } - - if ((address >= 0x4020) && (address <= 0x7FFF)) { - unif603_5052.reg = unif603_5052_vlu[value & 0x03]; - return; - } -} -BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, UNUSED(BYTE before)) { - if ((address >= 0x4020) && (address <= 0x7FFF)) { - return (unif603_5052.reg); - } - return (openbus); -} -BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp) { - save_slot_ele(mode, slot, unif603_5052.reg); - extcl_save_mapper_MMC3(mode, slot, fp); - - return (EXIT_OK); -} +/* + * Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include "mappers.h" +#include "info.h" +#include "irqA12.h" +#include "save_slot.h" + +static const BYTE unif603_5052_vlu[4] = { 0x00, 0x02, 0x02, 0x03 }; + +struct _unif603_5052 { + BYTE reg; +} unif603_5052; + +void map_init_UNIF603_5052(void) { + EXTCL_CPU_WR_MEM(UNIF603_5052); + EXTCL_CPU_RD_MEM(UNIF603_5052); + EXTCL_SAVE_MAPPER(UNIF603_5052); + EXTCL_CPU_EVERY_CYCLE(MMC3); + EXTCL_PPU_000_TO_34X(MMC3); + EXTCL_PPU_000_TO_255(MMC3); + EXTCL_PPU_256_TO_319(MMC3); + EXTCL_PPU_320_TO_34X(MMC3); + EXTCL_UPDATE_R2006(MMC3); + mapper.internal_struct[1] = (BYTE *) &mmc3; + mapper.internal_struct_size[1] = sizeof(mmc3); + + memset(&mmc3, 0x00, sizeof(mmc3)); + memset(&irqA12, 0x00, sizeof(irqA12)); + + info.mapper.extend_wr = TRUE; + + irqA12.present = TRUE; + irqA12_delay = 1; +} +void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value) { + if (address >= 0x8000) { + extcl_cpu_wr_mem_MMC3(address, value); + return; + } + + if ((address >= 0x4020) && (address <= 0x7FFF)) { + unif603_5052.reg = unif603_5052_vlu[value & 0x03]; + return; + } +} +BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, UNUSED(BYTE before)) { + if ((address >= 0x4020) && (address <= 0x7FFF)) { + return (unif603_5052.reg); + } + return (openbus); +} +BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp) { + save_slot_ele(mode, slot, unif603_5052.reg); + extcl_save_mapper_MMC3(mode, slot, fp); + + return (EXIT_OK); +} diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.c.orig puNES-0.105.new/src/core/mappers/mapper_UNIF603_5052.c.orig --- puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.c.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF603_5052.c.orig 2020-03-18 11:47:29.376142582 +0100 @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include "mappers.h" +#include "info.h" +#include "irqA12.h" +#include "save_slot.h" + +static const BYTE unif603_5052_vlu[4] = { 0x00, 0x02, 0x02, 0x03 }; + +void map_init_UNIF603_5052(void) { + EXTCL_CPU_WR_MEM(UNIF603_5052); + EXTCL_CPU_RD_MEM(UNIF603_5052); + EXTCL_SAVE_MAPPER(UNIF603_5052); + EXTCL_CPU_EVERY_CYCLE(MMC3); + EXTCL_PPU_000_TO_34X(MMC3); + EXTCL_PPU_000_TO_255(MMC3); + EXTCL_PPU_256_TO_319(MMC3); + EXTCL_PPU_320_TO_34X(MMC3); + EXTCL_UPDATE_R2006(MMC3); + mapper.internal_struct[1] = (BYTE *) &mmc3; + mapper.internal_struct_size[1] = sizeof(mmc3); + + memset(&mmc3, 0x00, sizeof(mmc3)); + memset(&irqA12, 0x00, sizeof(irqA12)); + + info.mapper.extend_wr = TRUE; + + irqA12.present = TRUE; + irqA12_delay = 1; +} +void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value) { + if (address >= 0x8000) { + extcl_cpu_wr_mem_MMC3(address, value); + return; + } + + if ((address >= 0x4020) && (address <= 0x7FFF)) { + unif603_5052.reg = unif603_5052_vlu[value & 0x03]; + return; + } +} +BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, UNUSED(BYTE before)) { + if ((address >= 0x4020) && (address <= 0x7FFF)) { + return (unif603_5052.reg); + } + return (openbus); +} +BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp) { + save_slot_ele(mode, slot, unif603_5052.reg); + extcl_save_mapper_MMC3(mode, slot, fp); + + return (EXIT_OK); +} diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.h puNES-0.105.new/src/core/mappers/mapper_UNIF603_5052.h --- puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF603_5052.h 2020-03-18 11:50:06.431791564 +0100 @@ -1,33 +1,29 @@ -/* - * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef MAPPER_UNIF603_5052_H_ -#define MAPPER_UNIF603_5052_H_ - -#include "common.h" - -struct _unif603_5052 { - BYTE reg; -} unif603_5052; - -void map_init_UNIF603_5052(void); -void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value); -BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, BYTE before); -BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp); - -#endif /* MAPPER_UNIF603_5052_H_ */ +/* + * Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef MAPPER_UNIF603_5052_H_ +#define MAPPER_UNIF603_5052_H_ + +#include "common.h" + +void map_init_UNIF603_5052(void); +void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value); +BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, BYTE before); +BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp); + +#endif /* MAPPER_UNIF603_5052_H_ */ diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.h.orig puNES-0.105.new/src/core/mappers/mapper_UNIF603_5052.h.orig --- puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.h.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF603_5052.h.orig 2020-03-18 11:47:29.377142573 +0100 @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef MAPPER_UNIF603_5052_H_ +#define MAPPER_UNIF603_5052_H_ + +#include "common.h" + +struct _unif603_5052 { + BYTE reg; +} unif603_5052; + +void map_init_UNIF603_5052(void); +void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value); +BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, BYTE before); +BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp); + +#endif /* MAPPER_UNIF603_5052_H_ */ diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF8157.c puNES-0.105.new/src/core/mappers/mapper_UNIF8157.c --- puNES-0.105.org/src/core/mappers/mapper_UNIF8157.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF8157.c 2020-03-18 11:47:29.377142573 +0100 @@ -24,7 +24,12 @@ INLINE static void unif8157_update(BYTE value); -BYTE unif8157_reset; +struct _unif8157 { + WORD reg; +} unif8157; +struct _unif8157tmp { + BYTE reset; +} unif8157tmp; void map_init_UNIF8157(void) { EXTCL_CPU_WR_MEM(UNIF8157); @@ -36,10 +41,10 @@ void map_init_UNIF8157(void) { memset(&unif8157, 0x00, sizeof(unif8157)); if (info.reset >= HARD) { - unif8157_reset = 0; + unif8157tmp.reset = 0; } else if (info.reset == RESET) { - unif8157_reset++; - unif8157_reset = unif8157_reset & 0x01F; + unif8157tmp.reset++; + unif8157tmp.reset = unif8157tmp.reset & 0x01F; } info.mapper.extend_rd = TRUE; @@ -53,7 +58,7 @@ void extcl_cpu_wr_mem_UNIF8157(WORD addr BYTE extcl_cpu_rd_mem_UNIF8157(WORD address, BYTE openbus, UNUSED(BYTE before)) { if (address >= 0x8000) { if ((unif8157.reg & 0x0100) && (prg.chip[0].size < (1024 * 1024))) { - address = (address & 0xFFF0) + unif8157_reset; + address = (address & 0xFFF0) + unif8157tmp.reset; return (prg_rom_rd(address)); } } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF8157.h puNES-0.105.new/src/core/mappers/mapper_UNIF8157.h --- puNES-0.105.org/src/core/mappers/mapper_UNIF8157.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF8157.h 2020-03-18 11:47:29.377142573 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _unif8157 { - WORD reg; -} unif8157; - void map_init_UNIF8157(void); void extcl_cpu_wr_mem_UNIF8157(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_UNIF8157(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF8237.c puNES-0.105.new/src/core/mappers/mapper_UNIF8237.c --- puNES-0.105.org/src/core/mappers/mapper_UNIF8237.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF8237.c 2020-03-18 11:47:29.377142573 +0100 @@ -85,13 +85,13 @@ INLINE static void unif8237a_update_chr( break;\ } #define unif8237_updt_prg()\ - if (unif8237_model == U8237) {\ + if (unif8237tmp.model == U8237) {\ unif8237_update_prg();\ } else {\ unif8237a_update_prg();\ } #define unif8237_updt_prg_and_chr()\ - if (unif8237_model == U8237) {\ + if (unif8237tmp.model == U8237) {\ unif8237_update_prg();\ unif8237_update_chr();\ } else {\ @@ -119,7 +119,14 @@ static const BYTE unif8237_adr[8][8] = { { 0, 1, 2, 3, 4, 5, 6, 7 }, { 0, 1, 2, 3, 4, 5, 6, 7 }, }; -BYTE unif8237_model; +struct _unif8237 { + BYTE reg[4]; + WORD prg_map[4]; + WORD chr_map[8]; +} unif8237; +struct _unif8237tmp { + BYTE model; +} unif8237tmp; void map_init_UNIF8237(BYTE model) { EXTCL_CPU_WR_MEM(UNIF8237); @@ -139,7 +146,7 @@ void map_init_UNIF8237(BYTE model) { memset(&irqA12, 0x00, sizeof(irqA12)); memset(&unif8237, 0x00, sizeof(unif8237)); - unif8237_model = model; + unif8237tmp.model = model; { BYTE i; diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIF8237.h puNES-0.105.new/src/core/mappers/mapper_UNIF8237.h --- puNES-0.105.org/src/core/mappers/mapper_UNIF8237.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIF8237.h 2020-03-18 11:47:29.377142573 +0100 @@ -23,12 +23,6 @@ enum _unif8237_type { U8237, U8237A }; -struct _unif8237 { - BYTE reg[4]; - WORD prg_map[4]; - WORD chr_map[8]; -} unif8237; - void map_init_UNIF8237(BYTE model); void extcl_cpu_wr_mem_UNIF8237(WORD address, BYTE value); BYTE extcl_save_mapper_UNIF8237(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIFSMB2J.c puNES-0.105.new/src/core/mappers/mapper_UNIFSMB2J.c --- puNES-0.105.org/src/core/mappers/mapper_UNIFSMB2J.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIFSMB2J.c 2020-03-18 11:47:29.377142573 +0100 @@ -23,7 +23,16 @@ #include "cpu.h" #include "save_slot.h" -BYTE *unifsmb2j_prg_6000; +struct _unifsmb2j { + BYTE reg; + struct _unifsmb2j_irq { + BYTE active; + WORD count; + } irq; +} unifsmb2j; +struct _unifsmb2jtmp { + BYTE *prg_6000; +} unifsmb2jtmp; void map_init_UNIFSMB2J(void) { EXTCL_CPU_WR_MEM(UNIFSMB2J); @@ -36,7 +45,7 @@ void map_init_UNIFSMB2J(void) { memset(&unifsmb2j, 0x00, sizeof(unifsmb2j)); map_prg_rom_8k(4, 0, 0); - unifsmb2j_prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13); + unifsmb2jtmp.prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13); info.mapper.extend_wr = TRUE; } @@ -44,7 +53,7 @@ void extcl_cpu_wr_mem_UNIFSMB2J(WORD add if (address == 0x4027) { unifsmb2j.reg = value & 0x01; _control_bank(unifsmb2j.reg, info.prg.rom[1].max.banks_8k) - unifsmb2j_prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13); + unifsmb2jtmp.prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13); } else if (address == 0x4068) { unifsmb2j.irq.active = value & 0x01; unifsmb2j.irq.count = 0; @@ -55,7 +64,7 @@ BYTE extcl_cpu_rd_mem_UNIFSMB2J(WORD add if ((address >= 0x4042) && (address <= 0x4055)) { return (0xFF); } else if ((address >= 0x6000) && (address <= 0x7FFF)) { - return (unifsmb2j_prg_6000[address & 0x1FFF]); + return (unifsmb2jtmp.prg_6000[address & 0x1FFF]); } return (openbus); } @@ -65,7 +74,7 @@ BYTE extcl_save_mapper_UNIFSMB2J(BYTE mo save_slot_ele(mode, slot, unifsmb2j.irq.count); if (mode == SAVE_SLOT_READ) { - unifsmb2j_prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13); + unifsmb2jtmp.prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13); } return (EXIT_OK); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_UNIFSMB2J.h puNES-0.105.new/src/core/mappers/mapper_UNIFSMB2J.h --- puNES-0.105.org/src/core/mappers/mapper_UNIFSMB2J.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_UNIFSMB2J.h 2020-03-18 11:47:29.377142573 +0100 @@ -21,14 +21,6 @@ #include "common.h" -struct _unifsmb2j { - BYTE reg; - struct _unifsmb2j_irq { - BYTE active; - WORD count; - } irq; -} unifsmb2j; - void map_init_UNIFSMB2J(void); void extcl_cpu_wr_mem_UNIFSMB2J(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_UNIFSMB2J(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC2.c puNES-0.105.new/src/core/mappers/mapper_VRC2.c --- puNES-0.105.org/src/core/mappers/mapper_VRC2.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC2.c 2020-03-18 11:47:29.377142573 +0100 @@ -27,13 +27,18 @@ chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\ vrc2.chr_rom_bank[slot] = value #define chr_rom_1k_low_update(slot, mask, shift)\ - value = (vrc2.chr_rom_bank[slot] & mask) | (((value & 0x0F) >> type) << shift);\ + value = (vrc2.chr_rom_bank[slot] & mask) | (((value & 0x0F) >> vrc2tmp.type) << shift);\ _chr_rom_1k_update(slot) #define chr_rom_1k_high_update(slot, mask, shift)\ - value = (vrc2.chr_rom_bank[slot] & mask) | ((value & 0x0F) << (shift - type));\ + value = (vrc2.chr_rom_bank[slot] & mask) | ((value & 0x0F) << (shift - vrc2tmp.type));\ _chr_rom_1k_update(slot) -BYTE type; +struct _vrc2 { + BYTE chr_rom_bank[8]; +} vrc2; +struct _vrc2tmp { + BYTE type; +} vrc2tmp; const WORD shift_VRC2[2][4] = { {0x0000, 0x0001, 0x0002, 0x0003}, @@ -55,13 +60,13 @@ void map_init_VRC2(BYTE revision) { } } - type = revision; + vrc2tmp.type = revision; } void extcl_cpu_wr_mem_VRC2(WORD address, BYTE value) { if (address < 0xB000) { address &= 0xF000; } else { - address = (address & 0xF000) | shift_VRC2[type][address & 0x0003]; + address = (address & 0xF000) | shift_VRC2[vrc2tmp.type][address & 0x0003]; } switch (address) { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC2.h puNES-0.105.new/src/core/mappers/mapper_VRC2.h --- puNES-0.105.org/src/core/mappers/mapper_VRC2.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC2.h 2020-03-18 11:47:29.377142573 +0100 @@ -23,10 +23,6 @@ enum { VRC2B, VRC2A }; -struct _vrc2 { - BYTE chr_rom_bank[8]; -} vrc2; - void map_init_VRC2(BYTE revision); void extcl_cpu_wr_mem_VRC2(WORD address, BYTE value); BYTE extcl_save_mapper_VRC2(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC3.c puNES-0.105.new/src/core/mappers/mapper_VRC3.c --- puNES-0.105.org/src/core/mappers/mapper_VRC3.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC3.c 2020-03-18 11:47:29.377142573 +0100 @@ -23,6 +23,15 @@ #include "cpu.h" #include "save_slot.h" +struct _vrc3 { + BYTE enabled; + WORD reload; + BYTE mode; + BYTE acknowledge; + WORD mask; + WORD count; +} vrc3; + void map_init_VRC3(void) { EXTCL_CPU_WR_MEM(VRC3); EXTCL_SAVE_MAPPER(VRC3); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC3.h puNES-0.105.new/src/core/mappers/mapper_VRC3.h --- puNES-0.105.org/src/core/mappers/mapper_VRC3.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC3.h 2020-03-18 11:47:29.377142573 +0100 @@ -21,15 +21,6 @@ #include "common.h" -struct _vrc3 { - BYTE enabled; - WORD reload; - BYTE mode; - BYTE acknowledge; - WORD mask; - WORD count; -} vrc3; - void map_init_VRC3(void); void extcl_cpu_wr_mem_VRC3(WORD address, BYTE value); BYTE extcl_save_mapper_VRC3(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC4.c puNES-0.105.new/src/core/mappers/mapper_VRC4.c --- puNES-0.105.org/src/core/mappers/mapper_VRC4.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC4.c 2020-03-18 11:47:29.377142573 +0100 @@ -35,7 +35,20 @@ #define chr_rom_1k_update_low(slot)\ _chr_rom_1k_update(slot, 0xF0, 0) -BYTE type; +struct _vrc4 { + WORD chr_rom_high_bank[8]; + BYTE chr_rom_bank[8]; + BYTE swap_mode; + BYTE irq_enabled; + BYTE irq_reload; + BYTE irq_mode; + BYTE irq_acknowledge; + BYTE irq_count; + WORD irq_prescaler; +} vrc4; +struct _vrc4tmp { + BYTE type; +} vrc4tmp; const BYTE shift_VRC4[6] = { 0x01, 0x00, 0x06, 0x02, 0x02, 0x00 }; const WORD mask_VRC4[6] = { 0x0006, 0x0003, 0x00C0, 0x000C, 0x000C, 0x0003 }; @@ -72,7 +85,7 @@ void map_init_VRC4(BYTE revision) { vrc4.irq_prescaler = 0; } - type = revision; + vrc4tmp.type = revision; } void extcl_cpu_wr_mem_VRC4(WORD address, BYTE value) { WORD tmp = address & 0xF000; @@ -80,8 +93,7 @@ void extcl_cpu_wr_mem_VRC4(WORD address, if ((tmp == 0x8000) || (tmp == 0xA000)) { address &= 0xF000; } else { - address = (address & 0xF000) - | table_VRC4[type][(address & mask_VRC4[type]) >> shift_VRC4[type]]; + address = (address & 0xF000) | table_VRC4[vrc4tmp.type][(address & mask_VRC4[vrc4tmp.type]) >> shift_VRC4[vrc4tmp.type]]; } switch (address) { diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC4.h puNES-0.105.new/src/core/mappers/mapper_VRC4.h --- puNES-0.105.org/src/core/mappers/mapper_VRC4.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC4.h 2020-03-18 11:47:29.377142573 +0100 @@ -23,18 +23,6 @@ enum { VRC4A, VRC4B, VRC4C, VRC4D, VRC4E, VRC4UNL, VRC4BMC, VRC4T230 }; -struct _vrc4 { - WORD chr_rom_high_bank[8]; - BYTE chr_rom_bank[8]; - BYTE swap_mode; - BYTE irq_enabled; - BYTE irq_reload; - BYTE irq_mode; - BYTE irq_acknowledge; - BYTE irq_count; - WORD irq_prescaler; -} vrc4; - void map_init_VRC4(BYTE revision); void extcl_cpu_wr_mem_VRC4(WORD address, BYTE value); BYTE extcl_save_mapper_VRC4(BYTE mode, BYTE slot, FILE *fp); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC6.c puNES-0.105.new/src/core/mappers/mapper_VRC6.c --- puNES-0.105.org/src/core/mappers/mapper_VRC6.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC6.c 2020-03-18 11:47:29.377142573 +0100 @@ -54,7 +54,6 @@ INLINE static void vrc6_update_chr_and_m if (!vrc6.square.enabled) {\ vrc6.square.output = 0;\ } - #define vrc6_square_saveslot(square)\ save_slot_ele(mode, slot, square.enabled);\ save_slot_ele(mode, slot, square.duty);\ @@ -65,7 +64,11 @@ INLINE static void vrc6_update_chr_and_m save_slot_ele(mode, slot, square.frequency);\ save_slot_ele(mode, slot, square.output) -BYTE type, delay; +_vrc6 vrc6; +struct _vrc6tmp { + BYTE type; + BYTE delay; +} vrc6tmp; const WORD table_VRC6[2][4] = { {0x0000, 0x0001, 0x0002, 0x0003}, @@ -96,10 +99,11 @@ void map_init_VRC6(BYTE revision) { vrc6.S4.timer = 1; vrc6.S4.duty = 1; vrc6.saw.timer = 1; - delay = 1; + vrc6tmp.delay = 1; - type = revision; + vrc6tmp.type = revision; } + void map_init_NSF_VRC6(BYTE revision) { memset(&vrc6, 0x00, sizeof(vrc6)); @@ -109,10 +113,10 @@ void map_init_NSF_VRC6(BYTE revision) { vrc6.S4.duty = 1; vrc6.saw.timer = 1; - type = revision; + vrc6tmp.type = revision; } void extcl_cpu_wr_mem_VRC6(WORD address, BYTE value) { - address = (address & 0xF000) | table_VRC6[type][(address & 0x0003)]; + address = (address & 0xF000) | table_VRC6[vrc6tmp.type][(address & 0x0003)]; switch (address) { case 0x8000: @@ -276,7 +280,7 @@ void extcl_cpu_every_cycle_VRC6(void) { } vrc6.count = vrc6.reload; - vrc6.delay = delay; + vrc6.delay = vrc6tmp.delay; } void extcl_apu_tick_VRC6(void) { vcr6_square_tick(S3) diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC6.h puNES-0.105.new/src/core/mappers/mapper_VRC6.h --- puNES-0.105.org/src/core/mappers/mapper_VRC6.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC6.h 2020-03-18 11:47:29.378142565 +0100 @@ -42,8 +42,7 @@ typedef struct _vrc6_saw { WORD frequency; SWORD output; } _vrc6_saw; - -struct _vrc6 { +typedef struct _vrc6 { BYTE enabled; BYTE reload; BYTE mode; @@ -61,7 +60,9 @@ struct _vrc6 { /* ------------------------------------------------------- */ /* */ BYTE clocked; /* */ /* ------------------------------------------------------- */ -} vrc6; +} _vrc6; + +extern _vrc6 vrc6; void map_init_VRC6(BYTE revision); void map_init_NSF_VRC6(BYTE revision); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC7.c puNES-0.105.new/src/core/mappers/mapper_VRC7.c --- puNES-0.105.org/src/core/mappers/mapper_VRC7.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC7.c 2020-03-18 11:47:29.378142565 +0100 @@ -31,8 +31,12 @@ const WORD table_VRC7[2][4] = { {0x0000, 0x0001, 0x0002, 0x0003}, }; -WORD mask; -BYTE type, delay; +_vrc7 vrc7; +struct _vrc7tmp { + WORD mask; + BYTE type; + BYTE delay; +} vrc7tmp; void map_init_VRC7(BYTE revision) { EXTCL_CPU_WR_MEM(VRC7); @@ -53,27 +57,27 @@ void map_init_VRC7(BYTE revision) { vrc7.prescaler = 0; } - mask = 0xF000; + vrc7tmp.mask = 0xF000; if (revision == VRC7A) { - mask = 0xF020; + vrc7tmp.mask = 0xF020; } - delay = 1; + vrc7tmp.delay = 1; - type = revision; + vrc7tmp.type = revision; } void map_init_NSF_VRC7(BYTE revision) { memset(&vrc7, 0x00, sizeof(vrc7)); - mask = 0xF000; + vrc7tmp.mask = 0xF000; if (revision == VRC7A) { - mask = 0xF020; + vrc7tmp.mask = 0xF020; } - type = revision; + vrc7tmp.type = revision; } void extcl_cpu_wr_mem_VRC7(WORD address, BYTE value) { - address = (address & mask) | table_VRC7[type][(address & 0x0018) >> 3]; + address = (address & vrc7tmp.mask) | table_VRC7[vrc7tmp.type][(address & 0x0018) >> 3]; switch (address) { case 0x8000: @@ -206,7 +210,7 @@ void extcl_cpu_every_cycle_VRC7(void) { } vrc7.count = vrc7.reload; - vrc7.delay = delay; + vrc7.delay = vrc7tmp.delay; } void extcl_snd_playback_start_VRC7(WORD samplarate) { opll_reset(3579545, samplarate); @@ -230,7 +234,7 @@ void map_init_VRC7UNL(void) { vrc7.prescaler = 0; } - delay = 1; + vrc7tmp.delay = 1; } void extcl_cpu_wr_mem_VRC7UNL(WORD address, BYTE value) { switch (address & 0xF008) { @@ -358,5 +362,5 @@ void extcl_cpu_every_cycle_VRC7UNL(void) } vrc7.count = vrc7.reload; - vrc7.delay = delay; + vrc7.delay = vrc7tmp.delay; } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_VRC7.h puNES-0.105.new/src/core/mappers/mapper_VRC7.h --- puNES-0.105.org/src/core/mappers/mapper_VRC7.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_VRC7.h 2020-03-18 11:47:29.378142565 +0100 @@ -23,7 +23,7 @@ enum { VRC7A, VRC7B, VRC7UNL }; -struct _vrc7 { +typedef struct _vrc7 { BYTE reg; BYTE enabled; BYTE reload; @@ -32,7 +32,9 @@ struct _vrc7 { BYTE count; BYTE delay; WORD prescaler; -} vrc7; +} _vrc7; + +extern _vrc7 vrc7; void map_init_VRC7(BYTE revision); void map_init_NSF_VRC7(BYTE revision); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Waixing.c puNES-0.105.new/src/core/mappers/mapper_Waixing.c --- puNES-0.105.org/src/core/mappers/mapper_Waixing.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Waixing.c 2020-03-18 11:47:29.378142565 +0100 @@ -23,8 +23,6 @@ #include "irqA12.h" #include "save_slot.h" -BYTE min, max; - #define waixing_swap_chr_bank_1k(src, dst)\ {\ BYTE *chr_bank_1k = chr.bank_1k[src];\ @@ -67,8 +65,8 @@ BYTE min, max; } #define waixing_type_ACDE_chr_1k(a)\ - if ((value >= min) && (value <= max)) {\ - chr.bank_1k[a] = &chr.extra.data[(value - min) << 10];\ + if ((value >= waixingtmp.min) && (value <= waixingtmp.max)) {\ + chr.bank_1k[a] = &chr.extra.data[(value - waixingtmp.min) << 10];\ } else {\ chr.bank_1k[a] = chr_chip_byte_pnt(0, value << 10);\ } @@ -436,6 +434,17 @@ BYTE min, max; }\ } +struct _waixing { + WORD prg_map[4]; + WORD chr_map[8]; + BYTE reg; + WORD ctrl[8]; +} waixing; +struct _waixingtmp { + BYTE min; + BYTE max; +} waixingtmp; + void map_init_Waixing(BYTE model) { switch (model) { case WPSX: @@ -486,17 +495,17 @@ void map_init_Waixing(BYTE model) { case WTD: case WTE: if (model == WTA) { - min = 0x08; - max = 0x09; + waixingtmp.min = 0x08; + waixingtmp.max = 0x09; } else if (model == WTC) { - min = 0x08; - max = 0x0B; + waixingtmp.min = 0x08; + waixingtmp.max = 0x0B; } else if (model == WTD) { - min = 0x00; - max = 0x01; + waixingtmp.min = 0x00; + waixingtmp.max = 0x01; } else if (model == WTE) { - min = 0x00; - max = 0x03; + waixingtmp.min = 0x00; + waixingtmp.max = 0x03; } EXTCL_CPU_WR_MEM(Waixing_type_ACDE); EXTCL_SAVE_MAPPER(Waixing_type_ACDE); @@ -529,8 +538,8 @@ void map_init_Waixing(BYTE model) { for (i = 0; i < 8; i++) { waixing.chr_map[i] = i; - if ((waixing.chr_map[i] >= min) && (waixing.chr_map[i] <= max)) { - chr.bank_1k[i] = &chr.extra.data[(waixing.chr_map[i] - min) << 10]; + if ((waixing.chr_map[i] >= waixingtmp.min) && (waixing.chr_map[i] <= waixingtmp.max)) { + chr.bank_1k[i] = &chr.extra.data[(waixing.chr_map[i] - waixingtmp.min) << 10]; } } } @@ -757,8 +766,8 @@ BYTE extcl_save_mapper_Waixing_type_ACDE BYTE i; for (i = 0; i < 8; i++) { - if ((waixing.chr_map[i] >= min) && (waixing.chr_map[i] <= max)) { - chr.bank_1k[i] = &chr.extra.data[(waixing.chr_map[i] - min) << 10]; + if ((waixing.chr_map[i] >= waixingtmp.min) && (waixing.chr_map[i] <= waixingtmp.max)) { + chr.bank_1k[i] = &chr.extra.data[(waixing.chr_map[i] - waixingtmp.min) << 10]; } } } @@ -768,7 +777,7 @@ BYTE extcl_save_mapper_Waixing_type_ACDE void extcl_wr_chr_Waixing_type_ACDE(WORD address, BYTE value) { const BYTE slot = address >> 10; - if ((waixing.chr_map[slot] >= min) && (waixing.chr_map[slot] <= max)) { + if ((waixing.chr_map[slot] >= waixingtmp.min) && (waixing.chr_map[slot] <= waixingtmp.max)) { chr.bank_1k[slot][address & 0x3FF] = value; } } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Waixing.h puNES-0.105.new/src/core/mappers/mapper_Waixing.h --- puNES-0.105.org/src/core/mappers/mapper_Waixing.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Waixing.h 2020-03-18 11:47:29.378142565 +0100 @@ -34,13 +34,6 @@ enum { BAD_SUGOROQUEST }; -struct _waixing { - WORD prg_map[4]; - WORD chr_map[8]; - BYTE reg; - WORD ctrl[8]; -} waixing; - void map_init_Waixing(BYTE model); void extcl_cpu_wr_mem_Waixing_PSx(WORD address, BYTE value); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Whirlwind.c puNES-0.105.new/src/core/mappers/mapper_Whirlwind.c --- puNES-0.105.org/src/core/mappers/mapper_Whirlwind.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Whirlwind.c 2020-03-18 11:47:29.378142565 +0100 @@ -24,7 +24,12 @@ INLINE static void whirlwind_6000_update(void); -BYTE *whirlwind_prg_6000; +struct _whirlwind { + uint32_t reg; +} whirlwind; +struct _whirlwindtmp { + BYTE *prg_6000; +} whirlwindtmp; void map_init_Whirlwind(void) { EXTCL_CPU_WR_MEM(Whirlwind); @@ -56,7 +61,7 @@ BYTE extcl_cpu_rd_mem_Whirlwind(WORD add switch (address & 0xF000) { case 0x6000: case 0x7000: - return (whirlwind_prg_6000[address & 0x1FFF]); + return (whirlwindtmp.prg_6000[address & 0x1FFF]); } return (openbus); @@ -79,5 +84,5 @@ INLINE static void whirlwind_6000_update value = whirlwind.reg; control_bank(info.prg.rom[0].max.banks_8k) - whirlwind_prg_6000 = prg_chip_byte_pnt(0, value << 13); + whirlwindtmp.prg_6000 = prg_chip_byte_pnt(0, value << 13); } diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_Whirlwind.h puNES-0.105.new/src/core/mappers/mapper_Whirlwind.h --- puNES-0.105.org/src/core/mappers/mapper_Whirlwind.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_Whirlwind.h 2020-03-18 11:47:29.378142565 +0100 @@ -21,10 +21,6 @@ #include "common.h" -struct _whirlwind { - uint32_t reg; -} whirlwind; - void map_init_Whirlwind(void); void extcl_cpu_wr_mem_Whirlwind(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_Whirlwind(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_YOKO.c puNES-0.105.new/src/core/mappers/mapper_YOKO.c --- puNES-0.105.org/src/core/mappers/mapper_YOKO.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_YOKO.c 2020-03-18 11:47:29.378142565 +0100 @@ -25,6 +25,19 @@ INLINE static void yoko_update(void); +struct _yoko { + BYTE mode; + BYTE bank; + BYTE dip; + BYTE low[4]; + BYTE reg[7]; + + struct _yoko_irq { + BYTE active; + WORD count; + } irq; +} yoko; + void map_init_YOKO(void) { EXTCL_CPU_WR_MEM(YOKO); EXTCL_CPU_RD_MEM(YOKO); diff -upr --new-file puNES-0.105.org/src/core/mappers/mapper_YOKO.h puNES-0.105.new/src/core/mappers/mapper_YOKO.h --- puNES-0.105.org/src/core/mappers/mapper_YOKO.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers/mapper_YOKO.h 2020-03-18 11:47:29.378142565 +0100 @@ -21,19 +21,6 @@ #include "common.h" -struct _yoko { - BYTE mode; - BYTE bank; - BYTE dip; - BYTE low[4]; - BYTE reg[7]; - - struct _yoko_irq { - BYTE active; - WORD count; - } irq; -} yoko; - void map_init_YOKO(void); void extcl_cpu_wr_mem_YOKO(WORD address, BYTE value); BYTE extcl_cpu_rd_mem_YOKO(WORD address, BYTE openbus, BYTE before); diff -upr --new-file puNES-0.105.org/src/core/mappers.c puNES-0.105.new/src/core/mappers.c --- puNES-0.105.org/src/core/mappers.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers.c 2020-03-18 11:47:29.363142690 +0100 @@ -30,6 +30,9 @@ #include "unif.h" #include "gui.h" +_trainer trainer; +_mapper mapper; + BYTE map_init(void) { BYTE i; /* diff -upr --new-file puNES-0.105.org/src/core/mappers.h puNES-0.105.new/src/core/mappers.h --- puNES-0.105.org/src/core/mappers.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mappers.h 2020-03-18 11:47:29.363142690 +0100 @@ -263,12 +263,12 @@ typedef struct _mapper { BYTE *internal_struct[10]; WORD internal_struct_size[10]; } _mapper; - -struct _trainer { +typedef struct _trainer { BYTE data[512]; -} trainer; +} _trainer; -_mapper mapper; +extern _trainer trainer; +extern _mapper mapper; BYTE map_init(void); void map_quit(void); diff -upr --new-file puNES-0.105.org/src/core/mem_map.h puNES-0.105.new/src/core/mem_map.h --- puNES-0.105.org/src/core/mem_map.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/mem_map.h 2020-03-18 11:47:29.378142565 +0100 @@ -82,16 +82,10 @@ enum mirroring_type { #define chr_ram_size() info.chr.rom[0].banks_8k << 13 -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _mmcpu { +typedef struct _mmcpu { BYTE ram[0x800]; // Mirrored four times -} mmcpu; -EXTERNC struct _prg { +} _mmcpu; +typedef struct _prg { struct _prg_chip { size_t size; BYTE *rom; @@ -108,8 +102,8 @@ EXTERNC struct _prg { BYTE *ram_plus; // PRG Ram extra BYTE *ram_plus_8k; BYTE *ram_battery; // Battery RAM -} prg; -EXTERNC struct _chr { +} _prg; +typedef struct _chr { struct _chr_chip { size_t size; BYTE *rom; @@ -122,15 +116,15 @@ EXTERNC struct _chr { size_t size; BYTE *data; } extra; -} chr; -EXTERNC struct _nametables { +} _chr; +typedef struct _nametables { BYTE data[0x1000]; BYTE *bank_1k[4]; -} ntbl; -EXTERNC struct _mmap_palette { +} _nametables; +typedef struct _mmap_palette { BYTE color[0x20]; -} mmap_palette; -EXTERNC struct _oam { +} _mmap_palette; +typedef struct _oam { BYTE data[256]; BYTE *element[64]; BYTE plus[32]; @@ -138,8 +132,13 @@ EXTERNC struct _oam { // unlimited sprites BYTE plus_unl[224]; BYTE *ele_plus_unl[56]; -} oam; +} _oam; -#undef EXTERNC +extern _mmcpu mmcpu; +extern _prg prg; +extern _chr chr; +extern _nametables ntbl; +extern _mmap_palette mmap_palette; +extern _oam oam; #endif /* MEM_MAP_H_ */ diff -upr --new-file puNES-0.105.org/src/core/nsf.c puNES-0.105.new/src/core/nsf.c --- puNES-0.105.org/src/core/nsf.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/nsf.c 2020-03-18 11:47:29.378142565 +0100 @@ -33,12 +33,10 @@ #include "mappers/mapper_VRC7_snd.h" #include "emu.h" #include "video/gfx.h" -#include "conf.h" #include "clock.h" #include "info.h" #include "vs_system.h" #include "ppu.h" -#include "apu.h" #include "cpu.h" #include "fds.h" #include "conf.h" @@ -125,6 +123,8 @@ typedef struct _nsf_option_data { int x1, x2; } _nsf_option_data; +_nsf nsf; + extern void cpu_wr_mem(WORD address, BYTE value); static void nsf_effect_set_coords(_nsf_effect_coords *coords, int x, int y, int w, int h); static void nsf_effect_raw(BYTE solid); diff -upr --new-file puNES-0.105.org/src/core/nsfe.c puNES-0.105.new/src/core/nsfe.c --- puNES-0.105.org/src/core/nsfe.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/nsfe.c 2020-03-18 11:47:29.378142565 +0100 @@ -28,7 +28,6 @@ #include "gui.h" #include "audio/blipbuf.h" #include "patcher.h" -#include "external_calls.h" enum nsfe_phase_type { NSFE_COUNT, NSFE_READ }; enum nsfe_flags { diff -upr --new-file puNES-0.105.org/src/core/nsf.h puNES-0.105.new/src/core/nsf.h --- puNES-0.105.org/src/core/nsf.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/nsf.h 2020-03-18 11:47:29.378142565 +0100 @@ -113,14 +113,7 @@ typedef struct _nsf_effect_coords { int w, h; int y_center; } _nsf_effect_coords; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _nsf { +typedef struct _nsf { BYTE enabled; BYTE version; BYTE draw_mask_frames; @@ -212,11 +205,11 @@ EXTERNC struct _nsf { _nsf_text_scroll scroll_title_song; _nsf_text_curtain curtain_title_song; _nsf_text_curtain curtain_info; -} nsf; +} _nsf; #if defined (_NSF_STATIC_) -EXTERNC static char nsf_default_label[4] = {""}; -EXTERNC static const BYTE nsf_routine[17] = { +static char nsf_default_label[4] = {""}; +static const BYTE nsf_routine[17] = { // 0 1 0xA9, 0x00, // 0x2500 : LDA [current song] // 2 3 @@ -234,6 +227,14 @@ EXTERNC static const BYTE nsf_routine[17 }; #endif +extern _nsf nsf; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + EXTERNC void nsf_init(void); EXTERNC void nsf_quit(void); EXTERNC void nsf_reset(void); diff -upr --new-file puNES-0.105.org/src/core/overscan.c puNES-0.105.new/src/core/overscan.c --- puNES-0.105.org/src/core/overscan.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/overscan.c 2020-03-18 11:47:29.378142565 +0100 @@ -16,10 +16,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "common.h" #include "overscan.h" #include "video/gfx.h" +_overscan_borders overscan_borders[2]; +_overscan overscan; + BYTE overscan_set_mode(BYTE mode) { _overscan_borders save = (*overscan.borders); diff -upr --new-file puNES-0.105.org/src/core/overscan.h puNES-0.105.new/src/core/overscan.h --- puNES-0.105.org/src/core/overscan.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/overscan.h 2020-03-18 11:47:29.379142557 +0100 @@ -25,12 +25,19 @@ enum overscan_limit { OVERSCAN_BORDERS_MIN = 0, OVERSCAN_BORDERS_MAX = 17 }; -typedef struct { +typedef struct _overscan_borders { BYTE up; BYTE down; BYTE left; BYTE right; } _overscan_borders; +typedef struct _overscan { + BYTE enabled; + _overscan_borders *borders; +} _overscan; + +extern _overscan_borders overscan_borders[2]; +extern _overscan overscan; #if defined (__cplusplus) #define EXTERNC extern "C" @@ -38,13 +45,6 @@ typedef struct { #define EXTERNC #endif -EXTERNC struct overscan { - BYTE enabled; - _overscan_borders *borders; -} overscan; - -EXTERNC _overscan_borders overscan_borders[2]; - EXTERNC BYTE overscan_set_mode(BYTE mode); #undef EXTERNC diff -upr --new-file puNES-0.105.org/src/core/palette.c puNES-0.105.new/src/core/palette.c --- puNES-0.105.org/src/core/palette.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/palette.c 2020-03-18 11:47:29.379142557 +0100 @@ -18,9 +18,11 @@ #include #include -#include "common.h" #include "palette.h" +_color_RGB palette_base_file[64]; +_palette_RGB palette_RGB; + void palette_save_on_file(const uTCHAR *file) { FILE *fp; diff -upr --new-file puNES-0.105.org/src/core/palette.h puNES-0.105.new/src/core/palette.h --- puNES-0.105.org/src/core/palette.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/palette.h 2020-03-18 11:47:29.379142557 +0100 @@ -19,6 +19,8 @@ #ifndef PALETTE_H_ #define PALETTE_H_ +#include "common.h" + #define NUM_COLORS 512 enum palettes_types { @@ -37,6 +39,14 @@ typedef struct _color_RGB { BYTE g; BYTE b; } _color_RGB; +typedef struct _palette_RGB { + _color_RGB *in_use; + _color_RGB noswap[NUM_COLORS]; + _color_RGB swapped[NUM_COLORS]; +} _palette_RGB; + +extern _color_RGB palette_base_file[64]; +extern _palette_RGB palette_RGB; #if defined (__cplusplus) #define EXTERNC extern "C" @@ -44,13 +54,6 @@ typedef struct _color_RGB { #define EXTERNC #endif -EXTERNC _color_RGB palette_base_file[64]; -EXTERNC struct _palette_RGB { - _color_RGB *in_use; - _color_RGB noswap[NUM_COLORS]; - _color_RGB swapped[NUM_COLORS]; -} palette_RGB; - EXTERNC void palette_save_on_file(const uTCHAR *file); EXTERNC BYTE palette_load_from_file(const uTCHAR *file); diff -upr --new-file puNES-0.105.org/src/core/patcher.c puNES-0.105.new/src/core/patcher.c --- puNES-0.105.org/src/core/patcher.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/patcher.c 2020-03-18 11:47:29.379142557 +0100 @@ -26,7 +26,6 @@ #include "emu.h" #include "gui.h" #include "text.h" -#include "uncompress.h" #include "cheat.h" #include "conf.h" @@ -45,6 +44,8 @@ static BYTE patcher_ips(_rom_mem *patch, static BYTE patcher_bps_decode(_rom_mem *patch, size_t *size); static BYTE patcher_bps(_rom_mem *patch, _rom_mem *rom); +_patcher patcher; + void patcher_init(void) { memset(&patcher, 0x00, sizeof(patcher)); } diff -upr --new-file puNES-0.105.org/src/core/patcher.h puNES-0.105.new/src/core/patcher.h --- puNES-0.105.org/src/core/patcher.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/patcher.h 2020-03-18 11:47:29.379142557 +0100 @@ -21,17 +21,19 @@ #include "common.h" +typedef struct _patcher { + uTCHAR *file; + BYTE patched; +} _patcher; + +extern _patcher patcher; + #if defined (__cplusplus) #define EXTERNC extern "C" #else #define EXTERNC #endif -EXTERNC struct _patcher { - uTCHAR *file; - BYTE patched; -} patcher; - EXTERNC void patcher_init(void); EXTERNC void patcher_quit(void); EXTERNC BYTE patcher_ctrl_if_exist(uTCHAR *patch); diff -upr --new-file puNES-0.105.org/src/core/ppu.c puNES-0.105.new/src/core/ppu.c --- puNES-0.105.org/src/core/ppu.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/ppu.c 2020-03-18 11:47:29.379142557 +0100 @@ -170,6 +170,22 @@ static const BYTE palette_init[0x20] = { 0x08, 0x3A, 0x00, 0x02, 0x00, 0x20, 0x2C, 0x08 }; +_ppu ppu; +_screen screen; +_ppu_openbus ppu_openbus; +_r2000 r2000; +_r2001 r2001; +_r2002 r2002; +_r2006 r2006; +_r2xxx r2003, r2004, r2007; +_spr_evaluate spr_ev; +_spr sprite[8], sprite_plus[8]; +_spr_evaluate spr_ev_unl; +_spr sprite_unl[56], sprite_plus_unl[56]; +_tile tile_render, tile_fetch; +_ppu_sclines ppu_sclines; +_overclock overclock; + void ppu_init(void) { memset(&screen, 0x00, sizeof(screen)); } diff -upr --new-file puNES-0.105.org/src/core/ppu.h puNES-0.105.new/src/core/ppu.h --- puNES-0.105.org/src/core/ppu.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/ppu.h 2020-03-18 11:47:29.379142557 +0100 @@ -257,20 +257,13 @@ typedef struct _tile { WORD l_byte; DBWORD h_byte; } _tile; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _ppu_sclines { +typedef struct _ppu_sclines { WORD total; WORD frame; WORD vint; WORD vint_extra; -} ppu_sclines; -EXTERNC struct _overclock { +} _ppu_sclines; +typedef struct _overclock { BYTE in_extra_sclines; BYTE DMC_in_use; struct _extra_sclines { @@ -278,21 +271,29 @@ EXTERNC struct _overclock { WORD pr; WORD total; } sclines; -} overclock; +} _overclock; -EXTERNC _ppu ppu; -EXTERNC _screen screen; -EXTERNC _ppu_openbus ppu_openbus; -EXTERNC _r2000 r2000; -EXTERNC _r2001 r2001; -EXTERNC _r2002 r2002; -EXTERNC _r2006 r2006; -EXTERNC _r2xxx r2003, r2004, r2007; -EXTERNC _spr_evaluate spr_ev; -EXTERNC _spr sprite[8], sprite_plus[8]; -EXTERNC _spr_evaluate spr_ev_unl; -EXTERNC _spr sprite_unl[56], sprite_plus_unl[56]; -EXTERNC _tile tile_render, tile_fetch; +extern _ppu ppu; +extern _screen screen; +extern _ppu_openbus ppu_openbus; +extern _r2000 r2000; +extern _r2001 r2001; +extern _r2002 r2002; +extern _r2006 r2006; +extern _r2xxx r2003, r2004, r2007; +extern _spr_evaluate spr_ev; +extern _spr sprite[8], sprite_plus[8]; +extern _spr_evaluate spr_ev_unl; +extern _spr sprite_unl[56], sprite_plus_unl[56]; +extern _tile tile_render, tile_fetch; +extern _ppu_sclines ppu_sclines; +extern _overclock overclock; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void ppu_init(void); EXTERNC void ppu_quit(void); diff -upr --new-file puNES-0.105.org/src/core/rewind.c puNES-0.105.new/src/core/rewind.c --- puNES-0.105.org/src/core/rewind.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/rewind.c 2020-03-18 11:47:29.379142557 +0100 @@ -24,13 +24,11 @@ #include "mem_map.h" #include "cpu.h" #include "ppu.h" -#include "apu.h" #include "mappers.h" #include "irqA12.h" #include "irql2f.h" #include "fds.h" #include "gui.h" -#include "input.h" #include "clock.h" #include "tas.h" #include "emu_thread.h" @@ -138,6 +136,8 @@ struct _rewind_internal { } size; } rwint; +_rewind rwnd; + BYTE rewind_init(void) { // in caso di riavvio del rewind rewind_quit(); diff -upr --new-file puNES-0.105.org/src/core/rewind.c.orig puNES-0.105.new/src/core/rewind.c.orig --- puNES-0.105.org/src/core/rewind.c.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/rewind.c.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,707 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include "rewind.h" +#include "info.h" +#include "mem_map.h" +#include "cpu.h" +#include "ppu.h" +#include "apu.h" +#include "mappers.h" +#include "irqA12.h" +#include "irql2f.h" +#include "fds.h" +#include "gui.h" +#include "input.h" +#include "clock.h" +#include "tas.h" +#include "emu_thread.h" +#include "video/gfx_thread.h" +#include "clock.h" +#include "conf.h" +#include "audio/snd.h" + +enum rewind_misc { + REWIND_CHUNK_TYPE_SEGMENT, + REWIND_CHUNK_TYPE_CHUNK_BUFFER, + REWIND_SNAPS_FOR_CHUNK = 15, + REWIND_SNAPS_FOR_FACTOR = 4 +}; + +#define rewind_on_struct(_mode, _strct, _size_buff)\ + switch (_mode) {\ + case REWIND_OP_SAVE:\ + memcpy(snap->data + index, &_strct, sizeof(_strct));\ + index += sizeof(_strct);\ + break;\ + case REWIND_OP_READ:\ + memcpy(&_strct, snap->data + index, sizeof(_strct));\ + index += sizeof(_strct);\ + break;\ + case REWIND_OP_COUNT:\ + rwint.size._size_buff += sizeof(_strct);\ + break;\ + } +#define rewind_on_mem(_mode, _mem, _size, _size_buff)\ + switch (_mode) {\ + case REWIND_OP_SAVE:\ + memcpy(snap->data + index, _mem, _size);\ + index += _size;\ + break;\ + case REWIND_OP_READ:\ + memcpy(_mem, snap->data + index, _size);\ + index += _size;\ + break;\ + case REWIND_OP_COUNT:\ + rwint.size._size_buff += _size;\ + break;\ + } + +typedef struct _rewind_index { + int32_t segment; + int32_t chunk; + int32_t snap; +} _rewind_index; +typedef struct _rewind_snapshoot { + _rewind_index index; + BYTE *data; +} _rewind_snapshoot; +typedef struct _rewind_chunk { + BYTE type; + BYTE *data; + _rewind_snapshoot *snaps; +} _rewind_chunk; + +INLINE static BYTE rewind_is_disabled(void); +INLINE static void rewind_increment_count_chunks(void); +INLINE static void rewind_update_chunk_snaps( _rewind_chunk *chunk, int32_t chunk_index, BYTE *src); +INLINE static void rewind_operation(BYTE mode, BYTE save_input, _rewind_snapshoot *snap); +INLINE static void rewind_free_chunk(_rewind_chunk *chunk); +INLINE static void rewind_execute_frame(void); +INLINE static char *rewind_convert_time_in_text(char *txt, size_t size, char *color, int32_t counter); + +static BYTE _rewind_frames(int32_t frames_to_rewind, BYTE exec_last_frame); + +struct _rewind_internal { + uTCHAR file_name[LENGTH_FILE_NAME_LONG]; + FILE *file; + + int32_t chunks_for_segment; + int32_t first_valid_snap; + int32_t snap_cursor; + + _rewind_chunk segment; + _rewind_chunk cbuffer; + + _rewind_index index; + + struct _rewind_info_max_buffered { + int32_t segments; + int32_t snaps; + } max_buffered; + struct _rewind_info_range { + struct _rewind_info_cunk_range { + int32_t first; + int32_t last; + } chunk; + } range; + struct _rewind_info_count { + int32_t segments; + int32_t chunks; + int32_t snaps; + } count; + struct _rewind_info_size { + size_t keyframe; + size_t screen; + size_t input; + size_t chunk; + size_t first_chunk; + size_t total; + } size; +} rwint; + +BYTE rewind_init(void) { + // in caso di riavvio del rewind + rewind_quit(); + + memset(&rwnd, 0, sizeof(rwnd)); + memset(&rwint, 0, sizeof(rwint)); + + rwint.count.snaps = -1; + rwint.chunks_for_segment = (machine.fps * 60) / REWIND_SNAPS_FOR_CHUNK; + + { + size_t size = sizeof(_rewind_snapshoot) * REWIND_SNAPS_FOR_CHUNK; + + if (rewind_is_disabled() == FALSE) { + if ((rwint.segment.snaps = (_rewind_snapshoot *)malloc(size)) == NULL) { + fprintf(stderr, "rewind : Out of memory\n"); + return (EXIT_ERROR); + } + memset(rwint.segment.snaps, 0, size); + } + + if ((rwint.cbuffer.snaps = (_rewind_snapshoot *)malloc(size)) == NULL) { + fprintf(stderr, "rewind : Out of memory\n"); + return (EXIT_ERROR); + } + memset(rwint.cbuffer.snaps, 0, size); + } + + { + _rewind_snapshoot snap; + + snap.index.chunk = 0; + snap.index.snap = 0; + rewind_operation(REWIND_OP_COUNT, TRUE, &snap); + } + + rwint.size.chunk = rwint.size.keyframe + (rwint.size.input * REWIND_SNAPS_FOR_CHUNK); + rwint.size.first_chunk = rwint.size.screen + rwint.size.chunk; + rwint.size.total = rwint.size.screen + (rwint.size.chunk * rwint.chunks_for_segment); + + if (rewind_is_disabled() == FALSE) { + if ((rwint.segment.data = (BYTE *)malloc(rwint.size.total)) == NULL) { + fprintf(stderr, "rewind : Out of memory\n"); + return (EXIT_ERROR); + } + memset(rwint.segment.data, 0, rwint.size.chunk); + rwint.segment.type = REWIND_CHUNK_TYPE_SEGMENT; + rewind_update_chunk_snaps(&rwint.segment, 0, NULL); + } + if ((rwint.cbuffer.data = (BYTE *)malloc(rwint.size.first_chunk)) == NULL) { + fprintf(stderr, "rewind : Out of memory\n"); + return (EXIT_ERROR); + } + memset(rwint.cbuffer.data, 0, rwint.size.first_chunk); + rwint.cbuffer.type = REWIND_CHUNK_TYPE_CHUNK_BUFFER; + rewind_update_chunk_snaps(&rwint.cbuffer, 0, NULL); + + // (se non ho limiti allora devo impostare rwint.max_buffered.segments a 0) + // lo incremento di 1 perche' se, per esempio, sono 3 i segmenti che devono + // sempre essere bufferizzati, quando sto trattando il segmento 3 (cioe' il quarto), + // chunk 0, snap 15, per poter fare il rewindw completo di 3 segmenti devo caricare + // il segmento 0, chunk 0, snap 15 percio' devo sempre bufferizzarne 3 + 1. + switch (cfg->rewind_minutes) { + case RWND_0_MINUTES: + rwint.max_buffered.segments = 1; + break; + case RWND_2_MINUTES: + rwint.max_buffered.segments = 2 + 1; + break; + case RWND_5_MINUTES: + rwint.max_buffered.segments = 5 + 1; + break; + default: + case RWND_15_MINUTES: + rwint.max_buffered.segments = 15 + 1; + break; + case RWND_30_MINUTES: + rwint.max_buffered.segments = 30 + 1; + break; + case RWND_60_MINUTES: + rwint.max_buffered.segments = 60 + 1; + break; + case RWND_UNLIMITED_MINUTES: + rwint.max_buffered.segments = 0; + break; + } + + if (rwint.max_buffered.segments > 0) { + rwint.max_buffered.snaps = (rwint.max_buffered.segments - 1) * rwint.chunks_for_segment * REWIND_SNAPS_FOR_CHUNK; + } + + rwint.range.chunk.first = 0; + rwint.range.chunk.last = rwint.range.chunk.first + rwint.chunks_for_segment; + + rwint.index.segment = 0; + rwint.index.chunk = 0; + rwint.index.snap = -1; + + // creo il file temporaneo + if (rewind_is_disabled() == FALSE) { + uTCHAR basename[255], *last_dot;; + + gui_utf_basename(info.rom.file, basename, usizeof(basename)); + + // rintraccio l'ultimo '.' nel nome + if ((last_dot = ustrrchr(basename, uL('.')))) { + // elimino l'estensione + (*last_dot) = 0x00; + }; + +#if defined (__WIN32__) + usnprintf(rwint.file_name, usizeof(rwint.file_name), uL("" uPERCENTs uPERCENTs "_" uPERCENTs ".rwd"), gui.ostmp, + basename, emu_rand_str()); +#else + usnprintf(rwint.file_name, usizeof(rwint.file_name), uL("" uPERCENTs "/" uPERCENTs "_" uPERCENTs ".rwd"), gui.ostmp, + basename, emu_rand_str()); +#endif + + if ((rwint.file = ufopen(rwint.file_name, uL("w+b"))) == NULL) { + return (EXIT_ERROR); + } + } + + return (EXIT_OK); +} +void rewind_quit(void) { + rewind_free_chunk(&rwint.segment); + rewind_free_chunk(&rwint.cbuffer); + if (rwint.file) { + fclose(rwint.file); + rwint.file = NULL; + if (emu_file_exist(rwint.file_name) == EXIT_OK) { + uremove(rwint.file_name); + } + } +} +void rewind_snapshoot(void) { + _rewind_snapshoot *snap; + + // se non ci sono rom caricate, non faccio niente + if (rewind_is_disabled()) { + return; + } + + if (++rwint.index.snap == REWIND_SNAPS_FOR_CHUNK) { + rwint.index.snap = 0; + rewind_increment_count_chunks(); + } + + snap = rwint.segment.snaps + rwint.index.snap; + + snap->index.chunk = rwint.index.chunk; + snap->index.snap = rwint.index.snap; + + rewind_operation(REWIND_OP_SAVE, TRUE, snap); + + rwint.count.snaps++; + + if (rwint.max_buffered.segments > 0) { + int32_t first_valid_snap = rwint.count.snaps - rwint.max_buffered.snaps; + + if (first_valid_snap > rwint.first_valid_snap) { + rwint.first_valid_snap = first_valid_snap; + } + } +} +void rewind_frames(int32_t frames_to_rewind) { + if (_rewind_frames(frames_to_rewind, FALSE) == EXIT_OK) { + if (tas.type != NOTAS) { + tas_rewind(frames_to_rewind); + } + } +} + +void rewind_save_state_snap(BYTE mode) { + _rewind_snapshoot *snap = rwint.cbuffer.snaps; + + snap->index.segment = 0; + snap->index.chunk = 0; + snap->index.snap = 0; + + rewind_update_chunk_snaps(&rwint.cbuffer, 0, NULL); + + rewind_operation(mode, FALSE, snap); +} + +void rewind_init_operation(void) { + emu_thread_pause(); + gfx_thread_pause(); + ppu_draw_screen_pause(); + + snd_playback_stop(); + + rwint.snap_cursor = rwint.count.snaps; + + rwnd.active = TRUE; + emu_ctrl_doublebuffer(); + gui_update(); + + gfx_thread_continue(); +} +void rewind_close_operation(void) { + gfx_thread_pause(); + + rwint.count.snaps = rwint.snap_cursor; + rwint.count.segments = rwint.index.segment; + + rwnd.active = FALSE; + emu_ctrl_doublebuffer(); + gui_update(); + + snd_playback_start(); + + ppu_draw_screen_continue(); + gfx_thread_continue(); + emu_thread_continue(); +} + +BYTE rewind_is_first_snap(void) { + return (rwint.snap_cursor == 0); +} +BYTE rewind_is_last_snap(void) { + return ((rwint.snap_cursor + 1) > rwint.count.snaps); +} + +int32_t rewind_count_snaps(void) { + return (rwint.count.snaps); +} +int32_t rewind_snap_cursor(void) { + return (rwint.snap_cursor); +} +int32_t rewind_calculate_snap_cursor(int factor, BYTE direction) { + int32_t snaps = factor * REWIND_SNAPS_FOR_FACTOR; + + if (direction == RWND_BACKWARD) { + snaps = -snaps; + + if ((rwint.snap_cursor + snaps) < rwint.first_valid_snap) { + snaps = -rwint.snap_cursor; + } + } else { + if ((rwint.snap_cursor + snaps) > rwint.count.snaps) { + snaps = (rwint.count.snaps - rwint.snap_cursor); + } + } + + return (snaps); +} + +char *rewind_text_time_count_snaps(void) { + static char txt[100]; + + return (rewind_convert_time_in_text((char *)&txt, sizeof(txt), "[normal]", rwint.count.snaps)); +} +char *rewind_text_time_snap_cursor(void) { + static char txt[100]; + + return (rewind_convert_time_in_text((char *)&txt, sizeof(txt), "[yellow]", rwint.snap_cursor)); +} +char *rewind_text_time_backward(void) { + static char txt[100]; + + return (rewind_convert_time_in_text((char *)&txt, sizeof(txt), "[cyan]", rwint.count.snaps - rwint.snap_cursor)); +} + +INLINE static BYTE rewind_is_disabled(void) { + return((info.no_rom | info.turn_off) || (cfg->rewind_minutes == RWND_0_MINUTES)); +} +INLINE static void rewind_increment_count_chunks(void) { + if (++rwint.index.chunk == rwint.chunks_for_segment) { + int32_t segment_to_save = rwint.index.segment; + + if (rwint.max_buffered.segments > 0) { + segment_to_save = rwint.index.segment % rwint.max_buffered.segments; + } + + fseek(rwint.file, segment_to_save * rwint.size.total, SEEK_SET); + fwrite(rwint.segment.data, rwint.size.total, 1, rwint.file); + rwint.index.chunk = 0; + rwint.range.chunk.first = rwint.range.chunk.last; + rwint.range.chunk.last = rwint.range.chunk.first + rwint.chunks_for_segment; + rwint.index.segment = ++rwint.count.segments; + } + rewind_update_chunk_snaps(&rwint.segment, rwint.index.chunk, NULL); + rwint.count.chunks++; +} +INLINE static void rewind_update_chunk_snaps( _rewind_chunk *chunk, int32_t chunk_index, BYTE *src) { + BYTE *start; + uint32_t i; + + if (chunk_index == 0) { + start = chunk->data + rwint.size.screen + (rwint.size.chunk * chunk_index); + chunk->snaps->data = chunk->data; + } else { + if (chunk->type == REWIND_CHUNK_TYPE_SEGMENT) { + start = chunk->data + rwint.size.screen + (rwint.size.chunk * chunk_index); + } else { + start = chunk->data; + } + chunk->snaps->data = start; + } + + for (i = 1; i < REWIND_SNAPS_FOR_CHUNK; i++) { + (chunk->snaps + i)->data = (start + rwint.size.keyframe) + (rwint.size.input * i); + } + + if (src != NULL) { + if (chunk_index == 0) { + memcpy(chunk->data, src, rwint.size.first_chunk); + } else { + memcpy(start, src, rwint.size.chunk); + } + } +} +INLINE static void rewind_operation(BYTE mode, BYTE save_input, _rewind_snapshoot *snap) { + size_t index = 0; + BYTE i; + + if (snap->index.snap == 0) { + if (snap->index.chunk == 0) { + rewind_on_mem(mode, screen.rd->data, screen_size(), screen); + } + + // CPU + rewind_on_struct(mode, cpu, keyframe); + rewind_on_struct(mode, irq, keyframe); + rewind_on_struct(mode, nmi, keyframe); + + // PPU + rewind_on_struct(mode, ppu, keyframe); + rewind_on_struct(mode, ppu_openbus, keyframe); + rewind_on_struct(mode, r2000, keyframe); + rewind_on_struct(mode, r2001, keyframe); + rewind_on_struct(mode, r2002, keyframe); + rewind_on_struct(mode, r2003, keyframe); + rewind_on_struct(mode, r2004, keyframe); + rewind_on_struct(mode, r2006, keyframe); + rewind_on_struct(mode, r2007, keyframe); + rewind_on_struct(mode, spr_ev, keyframe); + rewind_on_struct(mode, sprite, keyframe); + rewind_on_struct(mode, sprite_plus, keyframe); + rewind_on_struct(mode, tile_render, keyframe); + rewind_on_struct(mode, tile_fetch, keyframe); + + // APU + rewind_on_struct(mode, apu, keyframe); + rewind_on_struct(mode, r4011, keyframe); + rewind_on_struct(mode, r4015, keyframe); + rewind_on_struct(mode, r4017, keyframe); + rewind_on_struct(mode, S1, keyframe); + rewind_on_struct(mode, S2, keyframe); + rewind_on_struct(mode, TR, keyframe); + rewind_on_struct(mode, NS, keyframe); + rewind_on_struct(mode, DMC, keyframe); + + // mem map + rewind_on_struct(mode, mmcpu, keyframe); + rewind_on_struct(mode, prg, keyframe); + rewind_on_mem(mode, prg.ram.data, prg.ram.size, keyframe); + if (prg.ram_plus) { + rewind_on_mem(mode, prg.ram_plus, prg_ram_plus_size(), keyframe); + } + rewind_on_struct(mode, chr, keyframe); + if (mapper.write_vram) { + rewind_on_mem(mode, chr_chip(0), chr_ram_size(), keyframe); + } + if (chr.extra.size) { + rewind_on_mem(mode, chr.extra.data, chr.extra.size, keyframe); + } + rewind_on_struct(mode, ntbl, keyframe); + rewind_on_struct(mode, mmap_palette, keyframe); + rewind_on_struct(mode, oam, keyframe); + + // mapper + rewind_on_struct(mode, mapper, keyframe); + for (i = 0; i < LENGTH(mapper.internal_struct); i++) { + if (mapper.internal_struct[i]) { + rewind_on_mem(mode, mapper.internal_struct[i], mapper.internal_struct_size[i], keyframe); + } + } + + // irqA12 + if (irqA12.present) { + rewind_on_struct(mode, irqA12, keyframe); + } + + // irql2f + if (irql2f.present) { + rewind_on_struct(mode, irql2f, keyframe); + } + + // FDS + if (fds.info.enabled) { + BYTE old_side_inserted = fds.drive.side_inserted; + + rewind_on_struct(mode, fds.drive, keyframe); + rewind_on_struct(mode, fds.snd, keyframe); + rewind_on_struct(mode, fds.info.last_operation, keyframe); + + // in caso di ripristino di una snapshot, se era caricato + // un'altro side del disco, devo ricaricarlo. + if ((mode == REWIND_OP_READ) && (old_side_inserted != fds.drive.side_inserted)) { + fds_disk_op(FDS_DISK_SELECT_FROM_REWIND, fds.drive.side_inserted); + gui_update(); + } + } + } + + // input + if (save_input == TRUE) { + // standard controller + for (i = PORT1; i < PORT_MAX; i++) { + rewind_on_struct(mode, port[i].type_pad, input); + rewind_on_struct(mode, port[i].index, input); + rewind_on_struct(mode, port[i].data, input); + rewind_on_struct(mode, port[i].input, input); + rewind_on_struct(mode, port[i].turbo, input); + } + + // zapper, mouse, arkanoid, oeka_kids_tablet + rewind_on_struct(mode, gmouse.x, input); + rewind_on_struct(mode, gmouse.y, input); + rewind_on_struct(mode, gmouse.left, input); + rewind_on_struct(mode, gmouse.right, input); + + rewind_on_struct(mode, tas.total_lag_frames, input); + } +} +INLINE static void rewind_free_chunk(_rewind_chunk *chunk) { + if (chunk->snaps) { + free(chunk->snaps); + chunk->snaps = NULL; + } + if (chunk->data) { + free(chunk->data); + chunk->data = NULL; + } +} +INLINE static void rewind_execute_frame(void) { + if (info.frame_status == FRAME_FINISHED) { + info.frame_status = FRAME_STARTED; + } + + while (info.frame_status == FRAME_STARTED) { + cpu_exe_op(); + } +} +INLINE static char *rewind_convert_time_in_text(char *txt, size_t size, char *color, int32_t counter) { + int32_t seconds, ms, s, m, h; + + seconds = counter / machine.fps; + h = (seconds / 3600); + m = (seconds -(3600 * h)) / 60; + s = (seconds -(3600 * h) - (m * 60)); + ms = (counter % machine.fps) * (1000 / machine.fps); + + memset(txt, 0, size); + snprintf(txt, size, "%s%d[normal]:%s%02d[normal]:%s%02d[normal].%s%03d[normal]", color, h, color, m, color, s, color, ms); + + return (txt); +} + +static BYTE _rewind_frames(int32_t frames_to_rewind, BYTE exec_last_frame) { + int32_t cursor, segment, chunk, snaps; + _rewind_snapshoot *snap = NULL; + _rewind_index index; + BYTE *src; + + cursor = rwint.snap_cursor + frames_to_rewind; + + if (frames_to_rewind < 0) { + // backward + if (cursor < rwint.first_valid_snap) { + return (EXIT_ERROR); + } + } else if (frames_to_rewind > 0) { + // forward + if (cursor > rwint.count.snaps) { + return (EXIT_ERROR); + } + } else { + return (EXIT_ERROR); + } + + chunk = cursor / REWIND_SNAPS_FOR_CHUNK; + snaps = cursor % REWIND_SNAPS_FOR_CHUNK; + segment = chunk / rwint.chunks_for_segment; + + index.chunk = chunk % rwint.chunks_for_segment; + index.snap = 0; + + rwint.snap_cursor = cursor; + + // se non sono nel segmento corrente carico da disco + if ((chunk < rwint.range.chunk.first) || (chunk >= rwint.range.chunk.last)) { + int32_t segment_to_load = segment, segment_to_save = rwint.index.segment; + + if (rwint.max_buffered.segments > 0) { + segment_to_load %= rwint.max_buffered.segments; + segment_to_save %= rwint.max_buffered.segments; + } + + if (rwint.index.segment == rwint.count.segments) { + fseek(rwint.file, segment_to_save * rwint.size.total, SEEK_SET); + fwrite(rwint.segment.data, rwint.size.total, 1, rwint.file); + } + + fseek(rwint.file, segment_to_load * rwint.size.total, SEEK_SET); + if (fread(rwint.segment.data, rwint.size.total, 1, rwint.file) < 1) { + return (EXIT_ERROR); + } + + rwint.index.segment = segment; + rwint.range.chunk.first = segment * rwint.chunks_for_segment; + rwint.range.chunk.last = rwint.range.chunk.first + rwint.chunks_for_segment; + } + + if (index.chunk == 0) { + src = rwint.segment.data; + } else { + src = rwint.segment.data + rwint.size.screen + (rwint.size.chunk * index.chunk); + } + + if (snaps == 0) { + if (index.chunk > 0) { + // visto che lo screen lo salvo solo per il primo chunk della serie + // se facessi solo il rewind_operation ripristinerei il keyframe ma + // non avrei lo screen aggiornato quindi sono costretto ad eseguire + // prima tutti gli snaps del chunk precedente compreso l'ultimo frame. + _rewind_frames(-1, TRUE); + } + + rewind_update_chunk_snaps(&rwint.cbuffer, index.chunk, src); + + snap = rwint.cbuffer.snaps; + snap->index.chunk = index.chunk; + snap->index.snap = index.snap; + + rewind_operation(REWIND_OP_READ, TRUE, rwint.cbuffer.snaps); + } else { + rewind_update_chunk_snaps(&rwint.cbuffer, index.chunk, src); + + while (index.snap <= snaps) { + snap = rwint.cbuffer.snaps + index.snap; + snap->index.chunk = index.chunk; + snap->index.snap = index.snap; + + rewind_operation(REWIND_OP_READ, TRUE, snap); + + if ((index.snap == snaps) && (exec_last_frame == FALSE)) { + break; + } + + rewind_execute_frame(); + index.snap++; + } + } + + rewind_update_chunk_snaps(&rwint.segment, index.chunk, rwint.cbuffer.data); + + rwint.index.chunk = index.chunk; + rwint.index.snap = index.snap; + + rwint.snap_cursor = cursor; + + return (EXIT_OK); +} diff -upr --new-file puNES-0.105.org/src/core/rewind.h puNES-0.105.new/src/core/rewind.h --- puNES-0.105.org/src/core/rewind.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/rewind.h 2020-03-18 11:47:29.379142557 +0100 @@ -48,13 +48,7 @@ enum rewind_action { RWND_ACT_FAST_FORWARD }; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _rewind { +typedef struct _rewind { BYTE active; BYTE direction; BYTE action; @@ -64,7 +58,15 @@ EXTERNC struct _rewind { int backward; int forward; } factor; -} rwnd; +} _rewind; + +extern _rewind rwnd; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC BYTE rewind_init(void); EXTERNC void rewind_quit(void); diff -upr --new-file puNES-0.105.org/src/core/rewind.h.orig puNES-0.105.new/src/core/rewind.h.orig --- puNES-0.105.org/src/core/rewind.h.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/rewind.h.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef REWIND_H_ +#define REWIND_H_ + +#include "common.h" + +enum rewind_operations_mode { + REWIND_OP_SAVE, + REWIND_OP_READ, + REWIND_OP_COUNT +}; +enum rewind_options { + RWND_0_MINUTES, + RWND_2_MINUTES, + RWND_5_MINUTES, + RWND_15_MINUTES, + RWND_30_MINUTES, + RWND_60_MINUTES, + RWND_UNLIMITED_MINUTES, +}; +enum rewind_directions { + RWND_BACKWARD, + RWND_FORWARD +}; +enum rewind_action { + RWND_ACT_PLAY, + RWND_ACT_PAUSE, + RWND_ACT_STEP_BACKWARD, + RWND_ACT_FAST_BACKWARD, + RWND_ACT_STEP_FORWARD, + RWND_ACT_FAST_FORWARD +}; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + +EXTERNC struct _rewind { + BYTE active; + BYTE direction; + BYTE action; + BYTE action_before_pause; + + struct _rewind_factor { + int backward; + int forward; + } factor; +} rwnd; + +EXTERNC BYTE rewind_init(void); +EXTERNC void rewind_quit(void); + +EXTERNC void rewind_snapshoot(void); +EXTERNC void rewind_frames(int32_t frames_to_rewind); + +EXTERNC void rewind_save_state_snap(BYTE mode); + +EXTERNC void rewind_init_operation(void); +EXTERNC void rewind_close_operation(void); + +EXTERNC BYTE rewind_is_first_snap(void); +EXTERNC BYTE rewind_is_last_snap(void); + +EXTERNC int32_t rewind_count_snaps(void); +EXTERNC int32_t rewind_snap_cursor(void); +EXTERNC int32_t rewind_calculate_snap_cursor(int factor, BYTE direction); + +EXTERNC char *rewind_text_time_count_snaps(void); +EXTERNC char *rewind_text_time_snap_cursor(void); +EXTERNC char *rewind_text_time_backward(void); + +#undef EXTERNC + +#endif /* REWIND_H_ */ diff -upr --new-file puNES-0.105.org/src/core/save_slot.c puNES-0.105.new/src/core/save_slot.c --- puNES-0.105.org/src/core/save_slot.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/save_slot.c 2020-03-18 11:47:29.379142557 +0100 @@ -25,7 +25,6 @@ #include "mem_map.h" #include "cpu.h" #include "ppu.h" -#include "apu.h" #include "mappers.h" #include "irqA12.h" #include "irql2f.h" @@ -37,13 +36,14 @@ #include "fds.h" #include "nsf.h" #include "cheat.h" -#include "info.h" #define SAVE_VERSION 22 static BYTE slot_operation(BYTE mode, BYTE slot, FILE *fp); static uTCHAR *name_slot_file(BYTE slot); +_save_slot save_slot; + BYTE save_slot_save(BYTE slot) { uTCHAR *file; FILE *fp; diff -upr --new-file puNES-0.105.org/src/core/save_slot.c.orig puNES-0.105.new/src/core/save_slot.c.orig --- puNES-0.105.org/src/core/save_slot.c.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/core/save_slot.c.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,793 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include +#include "save_slot.h" +#include "conf.h" +#include "mem_map.h" +#include "cpu.h" +#include "ppu.h" +#include "apu.h" +#include "mappers.h" +#include "irqA12.h" +#include "irql2f.h" +#include "rewind.h" +#include "video/gfx.h" +#include "gui.h" +#include "tas.h" +#include "text.h" +#include "fds.h" +#include "nsf.h" +#include "cheat.h" +#include "info.h" + +#define SAVE_VERSION 22 + +static BYTE slot_operation(BYTE mode, BYTE slot, FILE *fp); +static uTCHAR *name_slot_file(BYTE slot); + +BYTE save_slot_save(BYTE slot) { + uTCHAR *file; + FILE *fp; + + // game genie + if (info.mapper.id == GAMEGENIE_MAPPER) { + text_add_line_info(1, "[yellow]save is impossible in Game Genie menu"); + return (EXIT_ERROR); + } + + if (slot < SAVE_SLOT_FILE) { + if ((file = name_slot_file(slot)) == NULL) { + return (EXIT_ERROR); + } + } else { + file = cfg->save_file; + } + + if ((fp = ufopen(file, uL("wb"))) == NULL) { + fprintf(stderr, "error on write save state\n"); + return (EXIT_ERROR); + } + + slot_operation(SAVE_SLOT_SAVE, slot, fp); + + fflush(fp); + + // aggiorno la posizione della preview e il totalsize + slot_operation(SAVE_SLOT_COUNT, slot, fp); + + save_slot.state[slot] = TRUE; + + fclose(fp); + + if (slot < SAVE_SLOT_FILE) { + text_save_slot(SAVE_SLOT_SAVE); + } + + return (EXIT_OK); +} +BYTE save_slot_load(BYTE slot) { + uTCHAR *file; + FILE *fp; + + if (tas.type) { + text_add_line_info(1, "[yellow]movie playback interrupted[normal]"); + tas_quit(); + } + + // game genie + if (info.mapper.id == GAMEGENIE_MAPPER) { + gamegenie_reset(); + gamegenie.phase = GG_LOAD_ROM; + emu_reset(CHANGE_ROM); + gamegenie.phase = GG_FINISH; + } + + if (slot < SAVE_SLOT_FILE) { + if ((file = name_slot_file(slot)) == NULL) { + return (EXIT_ERROR); + } + } else { + file = cfg->save_file; + } + + if ((fp = ufopen(file, uL("rb"))) == NULL) { + text_add_line_info(1, "[red]error[normal] loading state"); + fprintf(stderr, "error loading state\n"); + return (EXIT_ERROR); + } + + // mi salvo lo stato attuale da ripristinare in caso + // di un file di salvataggio corrotto. + rewind_save_state_snap(REWIND_OP_SAVE); + + if (slot == SAVE_SLOT_FILE) { + slot_operation(SAVE_SLOT_COUNT, slot, fp); + + if (memcmp(info.sha1sum.prg.value, save_slot.sha1sum.prg.value, + sizeof(info.sha1sum.prg.value)) != 0) { + text_add_line_info(1, "[red]state file is not for this rom[normal]"); + fprintf(stderr, "state file is not for this rom.\n"); + rewind_save_state_snap(REWIND_OP_READ); + fclose(fp); + return (EXIT_ERROR); + } + } + + if (slot_operation(SAVE_SLOT_READ, slot, fp)) { + fprintf(stderr, "error loading state, corrupted file.\n"); + rewind_save_state_snap(REWIND_OP_READ); + fclose(fp); + return (EXIT_ERROR); + } + + fclose(fp); + + if (slot < SAVE_SLOT_FILE) { + text_save_slot(SAVE_SLOT_READ); + } + + //riavvio il rewind + rewind_init(); + + return (EXIT_OK); +} +void save_slot_count_load(void) { + uTCHAR *file; + BYTE i; + + for (i = 0; i < SAVE_SLOTS; i++) { + save_slot.tot_size[i] = 0; + + save_slot.state[i] = FALSE; + file = name_slot_file(i); + + if (emu_file_exist(file) == EXIT_OK) { + FILE *fp; + + save_slot.state[i] = TRUE; + + if ((fp = ufopen(file, uL("rb"))) == NULL) { + continue; + } + + slot_operation(SAVE_SLOT_COUNT, i, fp); + fclose(fp); + } + } + + if (!save_slot.state[save_slot.slot]) { + BYTE i; + + save_slot.slot = 0; + + for (i = 0; i < SAVE_SLOTS; i++) { + if (save_slot.state[i]) { + save_slot.slot = i; + } + } + } + + gui_save_slot(save_slot.slot); +} +BYTE save_slot_element_struct(BYTE mode, BYTE slot, uintptr_t *src, DBWORD size, FILE *fp, BYTE preview) { + DBWORD bytes; + + switch (mode) { + case SAVE_SLOT_SAVE: + bytes = fwrite(src, size, 1, fp); + save_slot.tot_size[slot] += size; + break; + case SAVE_SLOT_READ: + bytes = fread(src, size, 1, fp); + if ((bytes != 1) && (preview == FALSE)) { + return (EXIT_ERROR); + } + break; + case SAVE_SLOT_COUNT: + save_slot.tot_size[slot] += size; + break; + } + return (EXIT_OK); +} + +static BYTE slot_operation(BYTE mode, BYTE slot, FILE *fp) { + uint32_t tmp = 0; + WORD i = 0; + + fseek(fp, 0L, SEEK_SET); + + save_slot.version = SAVE_VERSION; + + if (mode == SAVE_SLOT_COUNT) { + save_slot.tot_size[slot] = 0; + // forzo la lettura perche' devo sapere la + // versione del file di salvataggio e le informazioni + // della rom. + save_slot_int(SAVE_SLOT_READ, slot, save_slot.version) + if (save_slot.version < 16) { + _save_slot_ele(SAVE_SLOT_READ, slot, save_slot.rom_file, 1024) + } else if (save_slot.version < 21) { + _save_slot_ele(SAVE_SLOT_READ, slot, save_slot.rom_file, (1024 * sizeof(uTCHAR))) + } else { + save_slot_ele(SAVE_SLOT_READ, slot, save_slot.rom_file) + } + save_slot_ele(SAVE_SLOT_READ, slot, save_slot.sha1sum.prg.value) + save_slot_ele(SAVE_SLOT_READ, slot, save_slot.sha1sum.prg.string) + if (save_slot.version >= 11) { + save_slot_ele(SAVE_SLOT_READ, slot, save_slot.sha1sum.chr.value) + save_slot_ele(SAVE_SLOT_READ, slot, save_slot.sha1sum.chr.string) + } + } else if (mode == SAVE_SLOT_READ) { + save_slot_int(mode, slot, save_slot.version) + if (save_slot.version < 16) { + _save_slot_ele(mode, slot, save_slot.rom_file, 1024) + } else if (save_slot.version < 21) { + _save_slot_ele(mode, slot, save_slot.rom_file, (1024 * sizeof(uTCHAR))) + } else { + save_slot_ele(mode, slot, save_slot.rom_file) + } + save_slot_ele(mode, slot, save_slot.sha1sum.prg.value) + save_slot_ele(mode, slot, save_slot.sha1sum.prg.string) + if (save_slot.version >= 11) { + save_slot_ele(mode, slot, save_slot.sha1sum.chr.value) + save_slot_ele(mode, slot, save_slot.sha1sum.chr.string) + } + } else { + save_slot_int(mode, slot, save_slot.version) + if (save_slot.version < 16) { + _save_slot_ele(mode, slot, info.rom.file, 1024) + } else if (save_slot.version < 21) { + _save_slot_ele(mode, slot, info.rom.file, (1024 * sizeof(uTCHAR))) + } else { + save_slot_ele(mode, slot, info.rom.file) + } + save_slot_ele(mode, slot, info.sha1sum.prg.value) + save_slot_ele(mode, slot, info.sha1sum.prg.string) + if (save_slot.version >= 11) { + save_slot_ele(mode, slot, info.sha1sum.chr.value) + save_slot_ele(mode, slot, info.sha1sum.chr.string) + } + } + + // cpu + save_slot_ele(mode, slot, cpu.PC) + save_slot_ele(mode, slot, cpu.SP) + save_slot_ele(mode, slot, cpu.AR) + save_slot_ele(mode, slot, cpu.XR) + save_slot_ele(mode, slot, cpu.YR) + save_slot_ele(mode, slot, cpu.SR) + save_slot_ele(mode, slot, cpu.cf) + save_slot_ele(mode, slot, cpu.zf) + save_slot_ele(mode, slot, cpu.im) + save_slot_ele(mode, slot, cpu.df) + save_slot_ele(mode, slot, cpu.bf) + save_slot_ele(mode, slot, cpu.of) + save_slot_ele(mode, slot, cpu.sf) + save_slot_ele(mode, slot, cpu.opcode) + save_slot_ele(mode, slot, cpu.opcode_PC) + save_slot_ele(mode, slot, cpu.odd_cycle) + save_slot_ele(mode, slot, cpu.openbus) + save_slot_ele(mode, slot, cpu.cycles) + save_slot_ele(mode, slot, cpu.opcode_cycle) + save_slot_ele(mode, slot, cpu.double_rd) + save_slot_ele(mode, slot, cpu.double_wr) + save_slot_ele(mode, slot, cpu.prg_ram_rd_active) + save_slot_ele(mode, slot, cpu.prg_ram_wr_active) + // questo dato e' stato aggiunto solo dalla versione 9 in poi + if (save_slot.version >= 9) { + save_slot_ele(mode, slot, cpu.base_opcode_cycles) + } + + // irq + save_slot_ele(mode, slot, irq.high) + save_slot_ele(mode, slot, irq.delay) + save_slot_ele(mode, slot, irq.before) + save_slot_ele(mode, slot, irq.inhibit) + // nmi + save_slot_ele(mode, slot, nmi.high) + save_slot_ele(mode, slot, nmi.delay) + save_slot_ele(mode, slot, nmi.before) + save_slot_ele(mode, slot, nmi.inhibit) + save_slot_ele(mode, slot, nmi.frame_x) + // questo dato e' stato aggiunto solo dalla versione 9 in poi + if (save_slot.version >= 9) { + save_slot_ele(mode, slot, nmi.cpu_cycles_from_last_nmi) + } + + // ppu + save_slot_ele(mode, slot, ppu.frame_x) + save_slot_ele(mode, slot, ppu.frame_y) + save_slot_ele(mode, slot, ppu.fine_x) + save_slot_ele(mode, slot, ppu.screen_y) + save_slot_ele(mode, slot, ppu.pixel_tile) + save_slot_ele(mode, slot, ppu.sline_cycles) + save_slot_ele(mode, slot, ppu.tmp_vram) + save_slot_ele(mode, slot, ppu.spr_adr) + save_slot_ele(mode, slot, ppu.bck_adr) + save_slot_ele(mode, slot, ppu.openbus) + save_slot_ele(mode, slot, ppu.odd_frame) + save_slot_ele(mode, slot, ppu.cycles) + save_slot_ele(mode, slot, ppu.frames) + if (save_slot.version >= 13) { + save_slot_ele(mode, slot, ppu.sf.actual) + save_slot_ele(mode, slot, ppu.sf.prev) + // questo byte ormai non serve piu' + save_slot_ele(mode, slot, ppu.sf.first_of_tick) + } + if (save_slot.version >= 14) { + save_slot_ele(mode, slot, ppu.rnd_adr) + } + // ppu_openbus + save_slot_ele(mode, slot, ppu_openbus.bit0) + save_slot_ele(mode, slot, ppu_openbus.bit1) + save_slot_ele(mode, slot, ppu_openbus.bit2) + save_slot_ele(mode, slot, ppu_openbus.bit3) + save_slot_ele(mode, slot, ppu_openbus.bit4) + save_slot_ele(mode, slot, ppu_openbus.bit5) + save_slot_ele(mode, slot, ppu_openbus.bit6) + save_slot_ele(mode, slot, ppu_openbus.bit7) + // r2000 + save_slot_ele(mode, slot, r2000.value) + save_slot_ele(mode, slot, r2000.nmi_enable) + save_slot_ele(mode, slot, r2000.size_spr) + save_slot_ele(mode, slot, r2000.r2006_inc) + save_slot_ele(mode, slot, r2000.spt_adr) + save_slot_ele(mode, slot, r2000.bpt_adr) + if (save_slot.version >= 13) { + save_slot_ele(mode, slot, r2000.race.ctrl) + save_slot_ele(mode, slot, r2000.race.value) + } + // r2001 + save_slot_ele(mode, slot, r2001.value) + save_slot_ele(mode, slot, r2001.emphasis) + save_slot_ele(mode, slot, r2001.visible) + save_slot_ele(mode, slot, r2001.bck_visible) + save_slot_ele(mode, slot, r2001.spr_visible) + save_slot_ele(mode, slot, r2001.bck_clipping) + save_slot_ele(mode, slot, r2001.spr_clipping) + save_slot_ele(mode, slot, r2001.color_mode) + if (save_slot.version >= 13) { + save_slot_ele(mode, slot, r2001.race.ctrl) + save_slot_ele(mode, slot, r2001.race.value) + } + // r2002 + save_slot_ele(mode, slot, r2002.vblank) + save_slot_ele(mode, slot, r2002.sprite0_hit) + save_slot_ele(mode, slot, r2002.sprite_overflow) + save_slot_ele(mode, slot, r2002.toggle) + if (save_slot.version >= 17) { + save_slot_ele(mode, slot, r2002.race.sprite_overflow) + } + // r2003 + save_slot_ele(mode, slot, r2003.value) + // r2004 + save_slot_ele(mode, slot, r2004.value) + // r2006 + save_slot_ele(mode, slot, r2006.value) + save_slot_ele(mode, slot, r2006.changed_from_op) + if (save_slot.version >= 12) { + save_slot_ele(mode, slot, r2006.race.ctrl) + save_slot_ele(mode, slot, r2006.race.value) + } + // r2007 + save_slot_ele(mode, slot, r2007.value) + // spr_ev + save_slot_ele(mode, slot, spr_ev.range) + save_slot_ele(mode, slot, spr_ev.count) + save_slot_ele(mode, slot, spr_ev.count_plus) + save_slot_ele(mode, slot, spr_ev.tmp_spr_plus) + save_slot_ele(mode, slot, spr_ev.evaluate) + save_slot_ele(mode, slot, spr_ev.byte_OAM) + save_slot_ele(mode, slot, spr_ev.index_plus) + save_slot_ele(mode, slot, spr_ev.index) + save_slot_ele(mode, slot, spr_ev.timing) + save_slot_ele(mode, slot, spr_ev.phase) + if (save_slot.version >= 13) { + save_slot_ele(mode, slot, spr_ev.real) + } + // sprite + for (i = 0; i < LENGTH(sprite); i++) { + save_slot_ele(mode, slot, sprite[i].y_C) + save_slot_ele(mode, slot, sprite[i].tile) + save_slot_ele(mode, slot, sprite[i].attrib) + save_slot_ele(mode, slot, sprite[i].x_C) + save_slot_ele(mode, slot, sprite[i].number) + save_slot_ele(mode, slot, sprite[i].flip_v) + save_slot_ele(mode, slot, sprite[i].l_byte) + save_slot_ele(mode, slot, sprite[i].h_byte) + } + // sprite_plus + for (i = 0; i < LENGTH(sprite_plus); i++) { + save_slot_ele(mode, slot, sprite_plus[i].y_C) + save_slot_ele(mode, slot, sprite_plus[i].tile) + save_slot_ele(mode, slot, sprite_plus[i].attrib) + save_slot_ele(mode, slot, sprite_plus[i].x_C) + save_slot_ele(mode, slot, sprite_plus[i].number) + save_slot_ele(mode, slot, sprite_plus[i].flip_v) + save_slot_ele(mode, slot, sprite_plus[i].l_byte) + save_slot_ele(mode, slot, sprite_plus[i].h_byte) + } + // tile_render + save_slot_ele(mode, slot, tile_render.attrib) + save_slot_ele(mode, slot, tile_render.l_byte) + save_slot_ele(mode, slot, tile_render.h_byte) + // tile_fetch + save_slot_ele(mode, slot, tile_fetch.attrib) + save_slot_ele(mode, slot, tile_fetch.l_byte) + save_slot_ele(mode, slot, tile_fetch.h_byte) + + // apu + save_slot_ele(mode, slot, apu.mode) + save_slot_ele(mode, slot, apu.type) + save_slot_ele(mode, slot, apu.step) + save_slot_ele(mode, slot, apu.length_clocked) + save_slot_ele(mode, slot, apu.DMC) + save_slot_ele(mode, slot, apu.cycles) + // r4015 + save_slot_ele(mode, slot, r4015.value) + // r4017 + save_slot_ele(mode, slot, r4017.value) + save_slot_ele(mode, slot, r4017.jitter.value) + save_slot_ele(mode, slot, r4017.jitter.delay) + if (save_slot.version >= 13) { + save_slot_ele(mode, slot, r4017.reset_frame_delay) + } + // S1 + save_slot_square(S1, slot) + // S2 + save_slot_square(S2, slot) + // TR + save_slot_ele(mode, slot, TR.timer) + save_slot_ele(mode, slot, TR.frequency) + save_slot_ele(mode, slot, TR.linear.value) + save_slot_ele(mode, slot, TR.linear.reload) + save_slot_ele(mode, slot, TR.linear.halt) + save_slot_ele(mode, slot, TR.length.value) + save_slot_ele(mode, slot, TR.length.enabled) + save_slot_ele(mode, slot, TR.length.halt) + save_slot_ele(mode, slot, TR.sequencer) + save_slot_ele(mode, slot, TR.output) + // NS + save_slot_ele(mode, slot, NS.timer) + save_slot_ele(mode, slot, NS.frequency) + save_slot_ele(mode, slot, NS.envelope.enabled) + save_slot_ele(mode, slot, NS.envelope.divider) + save_slot_ele(mode, slot, NS.envelope.counter) + save_slot_ele(mode, slot, NS.envelope.constant_volume) + save_slot_ele(mode, slot, NS.envelope.delay) + save_slot_ele(mode, slot, NS.mode) + save_slot_ele(mode, slot, NS.volume) + // ho portato da DBWORD a WORD NS.shift e per mantenere + // la compatibilita' con i vecchi salvataggi faccio questa + // conversione. + if (save_slot.version < 7) { + if (mode == SAVE_SLOT_READ) { + DBWORD old_nsshift; + + save_slot_ele(mode, slot, old_nsshift) + + NS.shift = old_nsshift; + } else if (mode == SAVE_SLOT_COUNT) { + save_slot.tot_size[slot] += sizeof(DBWORD); + } + } else { + save_slot_ele(mode, slot, NS.shift) + } + save_slot_ele(mode, slot, NS.length.value) + save_slot_ele(mode, slot, NS.length.enabled) + save_slot_ele(mode, slot, NS.length.halt) + save_slot_ele(mode, slot, NS.sequencer) + save_slot_ele(mode, slot, NS.output) + // DMC + save_slot_ele(mode, slot, DMC.frequency) + save_slot_ele(mode, slot, DMC.remain) + save_slot_ele(mode, slot, DMC.irq_enabled) + save_slot_ele(mode, slot, DMC.loop) + save_slot_ele(mode, slot, DMC.rate_index) + save_slot_ele(mode, slot, DMC.address_start) + save_slot_ele(mode, slot, DMC.address) + save_slot_ele(mode, slot, DMC.length) + save_slot_ele(mode, slot, DMC.counter) + save_slot_ele(mode, slot, DMC.empty) + save_slot_ele(mode, slot, DMC.buffer) + save_slot_ele(mode, slot, DMC.dma_cycle) + save_slot_ele(mode, slot, DMC.silence) + save_slot_ele(mode, slot, DMC.shift) + save_slot_ele(mode, slot, DMC.counter_out) + save_slot_ele(mode, slot, DMC.output) + save_slot_ele(mode, slot, DMC.tick_type) + + // mem map + save_slot_ele(mode, slot, mmcpu.ram) + save_slot_mem(mode, slot, prg.ram.data, prg.ram.size, FALSE) + if (mode == SAVE_SLOT_READ) { + save_slot_int(mode, slot, tmp) + if (tmp) { + save_slot_mem(mode, slot, prg.ram_plus, prg_ram_plus_size(), FALSE) + save_slot_pos(mode, slot, prg.ram_plus, prg.ram_plus_8k) + save_slot_int(mode, slot, tmp) + if (tmp) { + save_slot_pos(mode, slot, prg.ram_plus, prg.ram_battery) + } + } + } else { + if (prg.ram_plus) { + tmp = TRUE; + save_slot_int(mode, slot, tmp) + save_slot_mem(mode, slot, prg.ram_plus, prg_ram_plus_size(), FALSE) + save_slot_pos(mode, slot, prg.ram_plus, prg.ram_plus_8k) + if (prg.ram_battery) { + tmp = TRUE; + save_slot_int(mode, slot, tmp) + save_slot_pos(mode, slot, prg.ram_plus, prg.ram_battery) + } else { + tmp = FALSE; + save_slot_int(mode, slot, tmp) + } + } else { + tmp = FALSE; + save_slot_int(mode, slot, tmp) + } + } + + // e' fondamentale che il salvataggio avvenga qui + if (save_slot.version >= 14) { + save_slot_ele(mode, slot, prg.rom_chip) + } + for (i = 0; i < LENGTH(prg.rom_8k); i++) { + if (mode == SAVE_SLOT_SAVE) { + uint32_t bank = mapper.rom_map_to[i] << 13; + save_slot_int(mode, slot, bank) + } else { + if (save_slot.version >= 14) { + save_slot_pos(mode, slot, prg_chip(prg.rom_chip[i]), prg.rom_8k[i]) + } else { + save_slot_pos(mode, slot, prg_chip(0), prg.rom_8k[i]) + } + } + } + save_slot_int(mode, slot, mapper.write_vram) + if (mapper.write_vram) { + save_slot_mem(mode, slot, chr_chip(0), chr_ram_size(), FALSE) + } + if (save_slot.version >= 14) { + save_slot_ele(mode, slot, chr.rom_chip) + } + for (i = 0; i < LENGTH(chr.bank_1k); i++) { + if (save_slot.version >= 14) { + save_slot_pos(mode, slot, chr_chip(chr.rom_chip[i]), chr.bank_1k[i]) + } else { + save_slot_pos(mode, slot, chr_chip(0), chr.bank_1k[i]) + } + } + save_slot_ele(mode, slot, ntbl.data) + for (i = 0; i < LENGTH(ntbl.bank_1k); i++) { + if (mode == SAVE_SLOT_SAVE) { + uint32_t diff = ntbl.bank_1k[i] - ntbl.data; + if (diff > 0x1000) { + tmp = 0; + save_slot_int(mode, slot, tmp) + } else { + save_slot_pos(mode, slot, ntbl.data, ntbl.bank_1k[i]) + } + } else { + save_slot_pos(mode, slot, ntbl.data, ntbl.bank_1k[i]) + } + } + save_slot_ele(mode, slot, mmap_palette.color) + save_slot_ele(mode, slot, oam.data) + save_slot_ele(mode, slot, oam.plus) + for (i = 0; i < LENGTH(oam.ele_plus); i++) { + save_slot_pos(mode, slot, oam.plus, oam.ele_plus[i]) + } + + // mapper + save_slot_ele(mode, slot, mapper.mirroring) + // ho portato da BYTE a WORD mapper.rom_map_to e per mantenere + // la compatibilita' con i vecchi salvataggi faccio questa + // conversione. + if (save_slot.version < 2) { + if (mode == SAVE_SLOT_READ) { + BYTE old_romMapTo[4], i; + + save_slot_ele(mode, slot, old_romMapTo) + + for (i = 0; i < 4; i++) { + mapper.rom_map_to[i] = old_romMapTo[i]; + } + } else if (mode == SAVE_SLOT_COUNT) { + save_slot.tot_size[slot] += sizeof(BYTE) * 4; + } + } else { + save_slot_ele(mode, slot, mapper.rom_map_to) + } + + if (mapper.internal_struct[0]) { + extcl_save_mapper(mode, slot, fp); + } + + // irqA12 + if (irqA12.present) { + save_slot_ele(mode, slot, irqA12.present) + save_slot_ele(mode, slot, irqA12.delay) + save_slot_ele(mode, slot, irqA12.counter) + save_slot_ele(mode, slot, irqA12.latch) + save_slot_ele(mode, slot, irqA12.reload) + save_slot_ele(mode, slot, irqA12.enable) + save_slot_ele(mode, slot, irqA12.save_counter) + save_slot_ele(mode, slot, irqA12.a12BS) + save_slot_ele(mode, slot, irqA12.a12SB) + save_slot_ele(mode, slot, irqA12.b_adr_old) + save_slot_ele(mode, slot, irqA12.s_adr_old) + if (save_slot.version >= 10) { + save_slot_ele(mode, slot, irqA12.cycles) + } + if (save_slot.version >= 14) { + save_slot_ele(mode, slot, irqA12.race.C001) + save_slot_ele(mode, slot, irqA12.race.counter) + save_slot_ele(mode, slot, irqA12.race.reload) + } + } + + // irql2f + if (irql2f.present) { + save_slot_ele(mode, slot, irql2f.present) + save_slot_ele(mode, slot, irql2f.enable) + save_slot_ele(mode, slot, irql2f.counter) + save_slot_ele(mode, slot, irql2f.scanline) + save_slot_ele(mode, slot, irql2f.frame_x) + save_slot_ele(mode, slot, irql2f.delay) + save_slot_ele(mode, slot, irql2f.in_frame) + save_slot_ele(mode, slot, irql2f.pending) + } + + if (fds.info.enabled) { + // libero la zona di memoria gia' occupata + BYTE old_side_inserted = fds.drive.side_inserted; + + // salvo, leggo o conto quello che serve + save_slot_ele(mode, slot, fds.drive.disk_position) + save_slot_ele(mode, slot, fds.drive.delay) + save_slot_ele(mode, slot, fds.drive.disk_ejected) + save_slot_ele(mode, slot, fds.drive.side_inserted) + save_slot_ele(mode, slot, fds.drive.gap_ended) + save_slot_ele(mode, slot, fds.drive.scan) + save_slot_ele(mode, slot, fds.drive.crc_char) + save_slot_ele(mode, slot, fds.drive.enabled_dsk_reg) + save_slot_ele(mode, slot, fds.drive.enabled_snd_reg) + save_slot_ele(mode, slot, fds.drive.data_readed) + save_slot_ele(mode, slot, fds.drive.data_to_write) + save_slot_ele(mode, slot, fds.drive.transfer_flag) + save_slot_ele(mode, slot, fds.drive.motor_on) + save_slot_ele(mode, slot, fds.drive.transfer_reset) + save_slot_ele(mode, slot, fds.drive.read_mode) + save_slot_ele(mode, slot, fds.drive.mirroring) + save_slot_ele(mode, slot, fds.drive.crc_control) + save_slot_ele(mode, slot, fds.drive.unknow) + save_slot_ele(mode, slot, fds.drive.drive_ready) + save_slot_ele(mode, slot, fds.drive.irq_disk_enabled) + save_slot_ele(mode, slot, fds.drive.irq_disk_high) + save_slot_ele(mode, slot, fds.drive.irq_timer_enabled) + save_slot_ele(mode, slot, fds.drive.irq_timer_reload_enabled) + save_slot_ele(mode, slot, fds.drive.irq_timer_high) + save_slot_ele(mode, slot, fds.drive.irq_timer_reload) + save_slot_ele(mode, slot, fds.drive.irq_timer_counter) + save_slot_ele(mode, slot, fds.drive.irq_timer_delay) + save_slot_ele(mode, slot, fds.drive.data_external_connector) + save_slot_ele(mode, slot, fds.drive.filler) + + // l'fds drive l'ho aggiunto nella versione 3, mentre il + // sound dalla 4 in poi. + if (save_slot.version >= 4) { + save_slot_ele(mode, slot, fds.snd.wave.data) + save_slot_ele(mode, slot, fds.snd.wave.writable) + save_slot_ele(mode, slot, fds.snd.wave.volume) + save_slot_ele(mode, slot, fds.snd.wave.index) + save_slot_ele(mode, slot, fds.snd.wave.counter) + + save_slot_ele(mode, slot, fds.snd.envelope.speed) + save_slot_ele(mode, slot, fds.snd.envelope.disabled) + + save_slot_ele(mode, slot, fds.snd.main.silence) + save_slot_ele(mode, slot, fds.snd.main.frequency) + save_slot_ele(mode, slot, fds.snd.main.output) + + save_slot_ele(mode, slot, fds.snd.volume.speed) + save_slot_ele(mode, slot, fds.snd.volume.mode) + save_slot_ele(mode, slot, fds.snd.volume.increase) + save_slot_ele(mode, slot, fds.snd.volume.gain) + save_slot_ele(mode, slot, fds.snd.volume.counter) + + save_slot_ele(mode, slot, fds.snd.sweep.bias) + save_slot_ele(mode, slot, fds.snd.sweep.mode) + save_slot_ele(mode, slot, fds.snd.sweep.increase) + save_slot_ele(mode, slot, fds.snd.sweep.speed) + save_slot_ele(mode, slot, fds.snd.sweep.gain) + save_slot_ele(mode, slot, fds.snd.sweep.counter) + + save_slot_ele(mode, slot, fds.snd.modulation.data) + save_slot_ele(mode, slot, fds.snd.modulation.frequency) + save_slot_ele(mode, slot, fds.snd.modulation.disabled) + save_slot_ele(mode, slot, fds.snd.modulation.index) + save_slot_ele(mode, slot, fds.snd.modulation.counter) + save_slot_ele(mode, slot, fds.snd.modulation.mod) + } + + if (save_slot.version >= 19) { + save_slot_ele(mode, slot, r2006.second_write.delay) + save_slot_ele(mode, slot, r2006.second_write.value) + } + + if (save_slot.version >= 20) { + save_slot_ele(mode, slot, r2001.grayscale_bit.delay) + } + + // in caso di ripristino di una salvataggio, se era caricato + // un'altro side del disco, devo ricaricarlo. + if ((mode == SAVE_SLOT_READ) && (old_side_inserted != fds.drive.side_inserted)) { + fds_disk_op(FDS_DISK_SELECT_FROM_REWIND, fds.drive.side_inserted); + gui_update(); + } + } + + save_slot_mem(mode, slot, screen.rd->data, screen_size(), TRUE) + + return (EXIT_OK); +} +static uTCHAR *name_slot_file(BYTE slot) { + static uTCHAR file[LENGTH_FILE_NAME_LONG]; + uTCHAR ext[10], bname[255], *last_dot, *fl = NULL; + + umemset(file, 0x00, LENGTH_FILE_NAME_LONG); + + // game genie + if (info.mapper.id == GAMEGENIE_MAPPER) { + fl = gamegenie.rom; + } + + if (!fl) { + fl = info.rom.file; + } + + if (!fl[0]) { + return (NULL); + } + + gui_utf_basename(fl, bname, usizeof(bname)); + usnprintf(file, usizeof(file), uL("" uPERCENTs SAVE_FOLDER "/" uPERCENTs), info.base_folder, bname); + + if (nsf.enabled == TRUE) { + usnprintf(ext, usizeof(ext), uL(".n%02d"), slot); + } else { + usnprintf(ext, usizeof(ext), uL(".p%02d"), slot); + } + + // rintraccio l'ultimo '.' nel nome + if ((last_dot = ustrrchr(file, uL('.')))) { + // elimino l'estensione + *last_dot = 0x00; + } + // aggiungo l'estensione + ustrcat(file, ext); + + return (file); +} diff -upr --new-file puNES-0.105.org/src/core/save_slot.h puNES-0.105.new/src/core/save_slot.h --- puNES-0.105.org/src/core/save_slot.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/save_slot.h 2020-03-18 11:47:29.379142557 +0100 @@ -31,13 +31,13 @@ enum save_slot_misc { enum save_slot_mode { SAVE_SLOT_SAVE, SAVE_SLOT_READ, SAVE_SLOT_COUNT, SAVE_SLOT_INCDEC }; #define _save_slot_ele(mode, slot, src, size)\ - if (save_slot_element_struct(mode, slot, (uintptr_t *) &src, size, fp, FALSE)) {\ + if (save_slot_element_struct(mode, slot, (uintptr_t *)&src, size, fp, FALSE)) {\ return (EXIT_ERROR);\ } #define save_slot_ele(mode, slot, src)\ _save_slot_ele(mode, slot, src, sizeof(src)) #define save_slot_mem(mode, slot, src, size, preview)\ - if (save_slot_element_struct(mode, slot, (uintptr_t *) src, size, fp, preview)) {\ + if (save_slot_element_struct(mode, slot, (uintptr_t *)src, size, fp, preview)) {\ return (EXIT_ERROR);\ } #define save_slot_int(mode, slot, value)\ @@ -101,20 +101,22 @@ enum save_slot_mode { SAVE_SLOT_SAVE, SA save_slot_ele(mode, slot, square.length.halt);\ save_slot_ele(mode, slot, square.output) -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _save_slot { +typedef struct _save_slot { uint32_t version; DBWORD slot; BYTE state[SAVE_SLOTS_TOTAL]; DBWORD tot_size[SAVE_SLOTS_TOTAL]; uTCHAR rom_file[LENGTH_FILE_NAME_LONG]; _info_sh1sum sha1sum; -} save_slot; +} _save_slot; + +extern _save_slot save_slot; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC BYTE save_slot_save(BYTE slot); EXTERNC BYTE save_slot_load(BYTE slot); diff -upr --new-file puNES-0.105.org/src/core/text.c puNES-0.105.new/src/core/text.c --- puNES-0.105.org/src/core/text.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/text.c 2020-03-18 11:47:29.379142557 +0100 @@ -16,18 +16,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if defined (WITH_OPENGL) -#include -#endif #include #include #include -#include -#include "text.h" #include "video/gfx.h" #include "font.h" #include "tas.h" -#include "input.h" #include "fds.h" #include "fps.h" #include "conf.h" @@ -62,6 +56,12 @@ static char txt_tags[][10] = { "[floppy]" }; +_text text; +uint32_t txt_table[TXT_BLACK + 1]; + +void (*text_clear)(_txt_element *ele); +void (*text_blit)(_txt_element *ele, _txt_rect *rect); + void text_init(void) { _txt_element *ele; uint8_t i; diff -upr --new-file puNES-0.105.org/src/core/text.h puNES-0.105.new/src/core/text.h --- puNES-0.105.org/src/core/text.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/text.h 2020-03-18 11:47:29.380142548 +0100 @@ -91,14 +91,7 @@ typedef struct _txt_element { void *blank; #endif } _txt_element; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _text { +typedef struct _text { BYTE on_screen; uint32_t w; uint32_t h; @@ -124,9 +117,19 @@ EXTERNC struct _text { BYTE operation; _txt_element slot; } save_slot; -} text; +} _text; + +extern _text text; +extern uint32_t txt_table[TXT_BLACK + 1]; -EXTERNC uint32_t txt_table[TXT_BLACK + 1]; +extern void (*text_clear)(_txt_element *ele); +extern void (*text_blit)(_txt_element *ele, _txt_rect *rect); + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void text_init(void); EXTERNC void text_save_slot(BYTE operation); @@ -135,9 +138,6 @@ EXTERNC void text_rendering(BYTE render) EXTERNC void text_calculate_real_x_y(_txt_element *ele, int *x, int *y); EXTERNC void text_quit(void); -EXTERNC void (*text_clear)(_txt_element *ele); -EXTERNC void (*text_blit)(_txt_element *ele, _txt_rect *rect); - #undef EXTERNC #endif /* TEXT_H_ */ diff -upr --new-file puNES-0.105.org/src/core/uncompress.c puNES-0.105.new/src/core/uncompress.c --- puNES-0.105.org/src/core/uncompress.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/uncompress.c 2020-03-18 11:47:29.380142548 +0100 @@ -22,7 +22,6 @@ #if defined (__OpenBSD__) #include #endif -#include "uncompress.h" #include "info.h" #include "c++/l7zip/l7z.h" #include "gui.h" @@ -47,6 +46,8 @@ static BYTE mz_zip_extract_from_archive( static uTCHAR *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type); #endif +_uncompress_storage uncstorage; + BYTE uncompress_init(void) { l7z_init(); @@ -183,8 +184,7 @@ BYTE uncompress_archive_extract_file(_un return (rc); } -_uncompress_archive_item *uncompress_archive_find_item(_uncompress_archive *archive, - uint32_t selected, BYTE type) { +_uncompress_archive_item *uncompress_archive_find_item(_uncompress_archive *archive, uint32_t selected, BYTE type) { uint32_t i, index = 0; for (i = 0; i < archive->list.count; i++) { @@ -240,8 +240,7 @@ uTCHAR *uncompress_storage_archive_name( return (NULL); } -uint32_t uncompress_storage_add_to_list(_uncompress_archive *archive, - _uncompress_archive_item *aitem, uTCHAR *file) { +uint32_t uncompress_storage_add_to_list(_uncompress_archive *archive, _uncompress_archive_item *aitem, uTCHAR *file) { _uncompress_storage_item *sitem, *si = NULL; BYTE found = FALSE; uint32_t i; diff -upr --new-file puNES-0.105.org/src/core/uncompress.h puNES-0.105.new/src/core/uncompress.h --- puNES-0.105.org/src/core/uncompress.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/uncompress.h 2020-03-18 11:47:29.380142548 +0100 @@ -72,12 +72,6 @@ typedef struct _uncompress_storage { _uncompress_storage_item *item; } _uncompress_storage; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - static const _uncompress_extension uncompress_exts[] = { { UNCOMPRESS_TYPE_ROM, uL(".nes") }, { UNCOMPRESS_TYPE_ROM, uL(".fds") }, @@ -89,7 +83,14 @@ static const _uncompress_extension uncom { UNCOMPRESS_TYPE_PATCH, uL(".bps") }, { UNCOMPRESS_TYPE_PATCH, uL(".xdelta") } }; -EXTERNC _uncompress_storage uncstorage; + +extern _uncompress_storage uncstorage; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC BYTE uncompress_init(void); EXTERNC void uncompress_quit(void); @@ -98,14 +99,12 @@ EXTERNC _uncompress_archive *uncompress_ EXTERNC void uncompress_archive_free(_uncompress_archive *archive) ; EXTERNC uint32_t uncompress_archive_counter(_uncompress_archive *archive, BYTE type); EXTERNC BYTE uncompress_archive_extract_file(_uncompress_archive *archive, BYTE type); -EXTERNC _uncompress_archive_item *uncompress_archive_find_item(_uncompress_archive *archive, - uint32_t selected, BYTE type); +EXTERNC _uncompress_archive_item *uncompress_archive_find_item(_uncompress_archive *archive, uint32_t selected, BYTE type); EXTERNC uTCHAR *uncompress_archive_extracted_file_name(_uncompress_archive *archive, BYTE type); EXTERNC uTCHAR *uncompress_archive_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type); EXTERNC uTCHAR *uncompress_storage_archive_name(uTCHAR *file); -EXTERNC uint32_t uncompress_storage_add_to_list(_uncompress_archive *archive, - _uncompress_archive_item *aitem, uTCHAR *file); +EXTERNC uint32_t uncompress_storage_add_to_list(_uncompress_archive *archive, _uncompress_archive_item *aitem, uTCHAR *file); #undef EXTERNC diff -upr --new-file puNES-0.105.org/src/core/unif.c puNES-0.105.new/src/core/unif.c --- puNES-0.105.org/src/core/unif.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/unif.c 2020-03-18 11:47:29.380142548 +0100 @@ -51,6 +51,8 @@ typedef struct _unif_board { WORD extra; } _unif_board; +_unif unif; + static const _unif_board unif_boards[] = { {"NROM", 0 , NO_UNIF, DEFAULT, DEFAULT, NOEXTRA}, {"NROM-128", 0, NO_UNIF, DEFAULT, DEFAULT, NOEXTRA}, @@ -379,6 +381,7 @@ BYTE unif_load_rom(void) { free(rom.data); return (EXIT_OK); } + BYTE unif_NONE(_rom_mem *rom, BYTE phase) { if (phase == UNIF_COUNT) { if ((rom->position + unif.chunk.length) > rom->size) { diff -upr --new-file puNES-0.105.org/src/core/unif.h puNES-0.105.new/src/core/unif.h --- puNES-0.105.org/src/core/unif.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/unif.h 2020-03-18 11:47:29.380142548 +0100 @@ -23,7 +23,7 @@ enum { UNIF_MAPPER = 0x1002 }; -struct _unif { +typedef struct _unif { BYTE finded; WORD internal_mapper; char board[64]; @@ -46,7 +46,9 @@ struct _unif { char id[4]; uint32_t length; } chunk; -} unif; +} _unif; + +extern _unif unif; BYTE unif_load_rom(void); diff -upr --new-file puNES-0.105.org/src/core/vs_system.h puNES-0.105.new/src/core/vs_system.h --- puNES-0.105.org/src/core/vs_system.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/core/vs_system.h 2020-03-18 11:47:29.380142548 +0100 @@ -75,37 +75,7 @@ typedef struct _r4020_type { _r4020_base old; _r4020_base actual; } _r4020_type; - -static const BYTE vs_protection_data[2][32] = { - { - 0xFF, 0xBF, 0xB7, 0x97, - 0x97, 0x17, 0x57, 0x4F, - 0x6F, 0x6B, 0xEB, 0xA9, - 0xB1, 0x90, 0x94, 0x14, - 0x56, 0x4E, 0x6F, 0x6B, - 0xEB, 0xA9, 0xB1, 0x90, - 0xD4, 0x5C, 0x3E, 0x26, - 0x87, 0x83, 0x13, 0x00 - }, - { - 0x00, 0x00, 0x00, 0x00, - 0xB4, 0x00, 0x00, 0x00, - 0x00, 0x6F, 0x00, 0x00, - 0x00, 0x00, 0x94, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 - } -}; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _vs_system { +typedef struct _vs_system { BYTE enabled; BYTE ppu; BYTE shared_mem; @@ -133,8 +103,31 @@ EXTERNC struct _vs_system { DBWORD left; DBWORD right; } coins; -} vs_system; +} _vs_system; + +static const BYTE vs_protection_data[2][32] = { + { + 0xFF, 0xBF, 0xB7, 0x97, + 0x97, 0x17, 0x57, 0x4F, + 0x6F, 0x6B, 0xEB, 0xA9, + 0xB1, 0x90, 0x94, 0x14, + 0x56, 0x4E, 0x6F, 0x6B, + 0xEB, 0xA9, 0xB1, 0x90, + 0xD4, 0x5C, 0x3E, 0x26, + 0x87, 0x83, 0x13, 0x00 + }, + { + 0x00, 0x00, 0x00, 0x00, + 0xB4, 0x00, 0x00, 0x00, + 0x00, 0x6F, 0x00, 0x00, + 0x00, 0x00, 0x94, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + } +}; -#undef EXTERNC +extern _vs_system vs_system; #endif /* VS_SYSTEM_H_ */ diff -upr --new-file puNES-0.105.org/src/gui/cmd_line.cpp puNES-0.105.new/src/gui/cmd_line.cpp --- puNES-0.105.org/src/gui/cmd_line.cpp 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/cmd_line.cpp 2020-03-18 11:47:29.380142548 +0100 @@ -23,7 +23,6 @@ #include "cmd_line.h" #include "conf.h" #include "version.h" -#include "video/gfx.h" #include "gui.h" #define req_arg true diff -upr --new-file puNES-0.105.org/src/gui/dlgVsSystem.cpp puNES-0.105.new/src/gui/dlgVsSystem.cpp --- puNES-0.105.org/src/gui/dlgVsSystem.cpp 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/dlgVsSystem.cpp 2020-03-18 11:47:29.380142548 +0100 @@ -22,8 +22,6 @@ #include "mainWindow.hpp" #include "dlgSettings.hpp" #include "vs_system.h" -#include "conf.h" -#include "info.h" #include "clock.h" #include "gui.h" diff -upr --new-file puNES-0.105.org/src/gui/linux/jstick.c puNES-0.105.new/src/gui/linux/jstick.c --- puNES-0.105.org/src/gui/linux/jstick.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/linux/jstick.c 2020-03-18 11:47:29.380142548 +0100 @@ -24,8 +24,6 @@ #include #include #include -#include "jstick.h" -#include "input.h" #include "gui.h" #include "conf.h" @@ -80,6 +78,8 @@ static void js_open(_js *joy); static void js_close(_js *joy); +_js js[PORT_MAX], js_shcut; + void js_init(UNUSED(BYTE first_time)) { BYTE i; diff -upr --new-file puNES-0.105.org/src/gui/linux/jstick.h puNES-0.105.new/src/gui/linux/jstick.h --- puNES-0.105.org/src/gui/linux/jstick.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/linux/jstick.h 2020-03-18 11:47:29.380142548 +0100 @@ -61,12 +61,6 @@ typedef struct _js_sch { BYTE mode; } _js_sch; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - static const _js_element jsn_list[] = { { 0x0FF, uL("NULL") }, { 0x000, uL("JOYSTICKID1") }, @@ -100,7 +94,13 @@ static const _js_element jsv_list[] = { { 0x416, uL("JB22") }, { 0x417, uL("JB23") }, }; -EXTERNC _js js[PORT_MAX], js_shcut; +extern _js js[PORT_MAX], js_shcut; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void js_init(BYTE first_time); EXTERNC void js_quit(BYTE last_time); diff -upr --new-file puNES-0.105.org/src/gui/objSettings.cpp puNES-0.105.new/src/gui/objSettings.cpp --- puNES-0.105.org/src/gui/objSettings.cpp 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/objSettings.cpp 2020-03-18 11:47:29.380142548 +0100 @@ -22,7 +22,6 @@ #include "clock.h" #include "save_slot.h" #include "emu.h" -#include "jstick.h" #include "shaders.h" #if defined (__unix__) #define XK_MISCELLANY diff -upr --new-file puNES-0.105.org/src/gui/objSettings.hpp puNES-0.105.new/src/gui/objSettings.hpp --- puNES-0.105.org/src/gui/objSettings.hpp 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/objSettings.hpp 2020-03-18 11:47:29.380142548 +0100 @@ -19,14 +19,13 @@ #ifndef OBJSETTINGS_HPP_ #define OBJSETTINGS_HPP_ -#include "settings.h" #include #include #include #include #include +#include "settings.h" #include "conf.h" -#include "overscan.h" #include "gui.h" class objSettings : public QSettings { diff -upr --new-file puNES-0.105.org/src/gui/openbsd/jstick.c puNES-0.105.new/src/gui/openbsd/jstick.c --- puNES-0.105.org/src/gui/openbsd/jstick.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/openbsd/jstick.c 2020-03-18 11:47:29.381142540 +0100 @@ -24,10 +24,8 @@ #include #include #include -#include "jstick.h" -#include "input.h" -#include "conf.h" #include "gui.h" +#include "conf.h" #ifndef __FreeBSD_kernel_version #define __FreeBSD_kernel_version __FreeBSD_version @@ -236,6 +234,8 @@ static struct _jstick { } jdd; } jstick; +_js js[PORT_MAX], js_shcut; + void js_init(BYTE first_time) { int i; diff -upr --new-file puNES-0.105.org/src/gui/openbsd/jstick.h puNES-0.105.new/src/gui/openbsd/jstick.h --- puNES-0.105.org/src/gui/openbsd/jstick.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/openbsd/jstick.h 2020-03-18 11:47:29.381142540 +0100 @@ -45,12 +45,6 @@ typedef struct _js_sch { BYTE mode; } _js_sch; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - static const _js_element jsv_list[] = { { 0x000, uL("NULL") }, { 0x001, uL("JA0MIN") }, { 0x002, uL("JA0PLS") }, @@ -89,7 +83,13 @@ static const _js_element jsv_list[] = { { 0x422, uL("JB34") }, { 0x423, uL("JB35") }, }; -EXTERNC _js js[PORT_MAX], js_shcut; +extern _js js[PORT_MAX], js_shcut; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void js_init(BYTE first_time); EXTERNC void js_quit(BYTE last_time); diff -upr --new-file puNES-0.105.org/src/gui/qt.h puNES-0.105.new/src/gui/qt.h --- puNES-0.105.org/src/gui/qt.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/qt.h 2020-03-18 11:47:29.381142540 +0100 @@ -47,13 +47,7 @@ #define dlgsettings ((dlgSettings *)gui_dlgsettings_get_ptr()) #define objcheat ((objCheat *)gui_objcheat_get_ptr()) -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _gui { +typedef struct _gui { #if defined (_WIN32) uTCHAR home[MAX_PATH]; const uTCHAR *ostmp; @@ -78,8 +72,8 @@ EXTERNC struct _gui { uint8_t main_win_lfp; int dlg_rc; -} gui; -EXTERNC struct _gui_mouse { +} _gui; +typedef struct _gui_mouse { int x; int y; uint8_t left; @@ -88,10 +82,22 @@ EXTERNC struct _gui_mouse { uint8_t hidden; double timer; -} gmouse; -EXTERNC struct _external_windows { +} _gui_mouse; +typedef struct _external_windows { uint8_t vs_system; -} ext_win; +} _external_windows; + +extern _gui gui; +extern _gui_mouse gmouse; +extern _external_windows ext_win; + +extern double (*gui_get_ms)(void); + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void gui_quit(void); EXTERNC BYTE gui_create(void); @@ -165,8 +171,6 @@ EXTERNC void gui_utf_dirname(uTCHAR *pat EXTERNC void gui_utf_basename(uTCHAR *path, uTCHAR *dst, size_t len); EXTERNC int gui_utf_strcasecmp(uTCHAR *s0, uTCHAR *s1); -EXTERNC double (*gui_get_ms)(void); - EXTERNC void gui_init(int *argc, char **argv); EXTERNC void gui_sleep(double ms); #if defined (_WIN32) diff -upr --new-file puNES-0.105.org/src/gui/qt.h.orig puNES-0.105.new/src/gui/qt.h.orig --- puNES-0.105.org/src/gui/qt.h.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/gui/qt.h.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef QT_H_ +#define QT_H_ + +#if defined (_WIN32) +#include "win.h" +#else +#include +#endif +#include "common.h" +#include "emu.h" +#include "uncompress.h" +#include "jstick.h" + +#define tools_stylesheet()\ + "QGroupBox {"\ + " border-radius: 10px;"\ + " border: 1px solid black;"\ + " border: 2px groove gray;"\ + " font-weight: bold;"\ + "}"\ + "QGroupBox::title {"\ + " subcontrol-origin: margin;"\ + " subcontrol-position: top center;"\ + " padding: 0 0px;"\ + "}" + +#define mainwin ((mainWindow *)gui_mainwindow_get_ptr()) +#define wdgrewind ((wdgRewind *)gui_wdgrewind_get_ptr()) +#define dlgsettings ((dlgSettings *)gui_dlgsettings_get_ptr()) +#define objcheat ((objCheat *)gui_objcheat_get_ptr()) + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + +EXTERNC struct _gui { +#if defined (_WIN32) + uTCHAR home[MAX_PATH]; + const uTCHAR *ostmp; + DWORD version_os; + double frequency; + uint64_t counter_start; +#else + const uTCHAR *home; + const uTCHAR *ostmp; + struct timeval counterStart; +#endif + + uTCHAR last_open_path[LENGTH_FILE_NAME_MAX]; + uTCHAR last_open_patch_path[LENGTH_FILE_NAME_MAX]; + + //int8_t cpu_cores; + + uint8_t start; + uint8_t in_update; + + // lost focus pause + uint8_t main_win_lfp; + + int dlg_rc; +} gui; +EXTERNC struct _gui_mouse { + int x; + int y; + uint8_t left; + uint8_t right; + + uint8_t hidden; + + double timer; +} gmouse; +EXTERNC struct _external_windows { + uint8_t vs_system; +} ext_win; + +EXTERNC void gui_quit(void); +EXTERNC BYTE gui_create(void); +EXTERNC void gui_start(void); + +EXTERNC void gui_set_video_mode(void); + +EXTERNC void gui_update(void); +EXTERNC void gui_update_gps_settings(void); + +EXTERNC void gui_fullscreen(void); +EXTERNC void gui_save_slot(BYTE slot); + +EXTERNC void gui_print_usage(char *usage); +EXTERNC int gui_uncompress_selection_dialog(_uncompress_archive *archive, BYTE type); + +EXTERNC void gui_control_pause_bck(WORD event); + +EXTERNC void gui_active_window(void); +EXTERNC void gui_set_focus(void); + +EXTERNC void *gui_objcheat_get_ptr(void); +EXTERNC void gui_objcheat_init(void); +EXTERNC void gui_objcheat_read_game_cheats(void); + +EXTERNC void gui_cursor_init(void); +EXTERNC void gui_cursor_set(void); +EXTERNC void gui_cursor_hide(BYTE hide); +EXTERNC void gui_control_visible_cursor(void); + +EXTERNC void *gui_mainwindow_get_ptr(void); + +EXTERNC void *gui_wdgrewind_get_ptr(void); +EXTERNC void gui_wdgrewind_play(void); + +EXTERNC void gui_emit_et_gg_reset(void); +EXTERNC void gui_emit_et_vs_reset(void); +EXTERNC void gui_emit_et_external_control_windows_show(void); + +EXTERNC void gui_screen_update(void); + +EXTERNC void *gui_dlgsettings_get_ptr(void); + +EXTERNC void *gui_dlgdebugger_get_ptr(void); +EXTERNC void gui_dlgdebugger_click_step(void); + +EXTERNC void gui_external_control_windows_show(void); +EXTERNC void gui_external_control_windows_update_pos(void); + +EXTERNC void gui_vs_system_update_dialog(void); +EXTERNC void gui_vs_system_insert_coin(void); + +EXTERNC void gui_apu_channels_widgets_update(void); + +EXTERNC void gui_ppu_hacks_widgets_update(void); + +#if defined (WITH_OPENGL) +EXTERNC void gui_wdgopengl_make_current(void); +EXTERNC unsigned int gui_wdgopengl_framebuffer_id(void); + +EXTERNC void gui_screen_info(void); + +EXTERNC uint32_t gui_color(BYTE a, BYTE r, BYTE g, BYTE b); +#endif + +EXTERNC BYTE gui_load_lut(void *l, const uTCHAR *path); +EXTERNC void gui_save_screenshot(int w, int h, char *buffer, BYTE flip); + +EXTERNC void gui_utf_printf(const uTCHAR *fmt, ...); +EXTERNC void gui_utf_dirname(uTCHAR *path, uTCHAR *dst, size_t len); +EXTERNC void gui_utf_basename(uTCHAR *path, uTCHAR *dst, size_t len); +EXTERNC int gui_utf_strcasecmp(uTCHAR *s0, uTCHAR *s1); + +EXTERNC double (*gui_get_ms)(void); + +EXTERNC void gui_init(int *argc, char **argv); +EXTERNC void gui_sleep(double ms); +#if defined (_WIN32) +EXTERNC HWND gui_screen_id(void); +#else +EXTERNC int gui_screen_id(void); +#endif + +//EXTERNC void gui_add_event(void *funct, void *args); +//EXTERNC void gui_set_thread_affinity(uint8_t core); + +#undef EXTERNC + +#endif /* QT_H_ */ diff -upr --new-file puNES-0.105.org/src/gui/recent_roms.cpp puNES-0.105.new/src/gui/recent_roms.cpp --- puNES-0.105.org/src/gui/recent_roms.cpp 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/recent_roms.cpp 2020-03-18 11:47:29.381142540 +0100 @@ -23,10 +23,8 @@ #include "recent_roms.h" #include "info.h" #include "conf.h" -#include "cheat.h" #include "settings.h" #include "gui.h" -#include "uncompress.h" #define RECENT_ROMS_FILE "recent.cfg" diff -upr --new-file puNES-0.105.org/src/gui/settings.h puNES-0.105.new/src/gui/settings.h --- puNES-0.105.org/src/gui/settings.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/settings.h 2020-03-18 11:47:29.381142540 +0100 @@ -30,6 +30,7 @@ #include "input.h" #include "nsf.h" #include "rewind.h" +#include "palette.h" #if defined (_WIN32) #define NEWLINE "\r\n" diff -upr --new-file puNES-0.105.org/src/gui/tas.h puNES-0.105.new/src/gui/tas.h --- puNES-0.105.org/src/gui/tas.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/tas.h 2020-03-18 11:47:29.381142540 +0100 @@ -32,14 +32,7 @@ typedef struct _tas_input_log { BYTE state; BYTE port[PORT_MAX][8]; } _tas_input_log; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _tas { +typedef struct _tas { uTCHAR file[LENGTH_FILE_NAME_LONG]; FILE *fp; uint8_t emulator; @@ -54,7 +47,20 @@ EXTERNC struct _tas { int32_t frame; uint32_t total_lag_frames; _tas_input_log il[TAS_CACHE]; -} tas; +} _tas; + +extern _tas tas; + +extern void (*tas_header)(uTCHAR *file); +extern void (*tas_read)(void); +extern void (*tas_frame)(void); +extern void (*tas_rewind)(int32_t frames_to_rewind); + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC BYTE tas_file(uTCHAR *ext, uTCHAR *file); EXTERNC void tas_quit(void); @@ -64,11 +70,6 @@ EXTERNC void tas_read_FM2(void); EXTERNC void tas_frame_FM2(void); EXTERNC void tas_rewind_FM2(int32_t frames_to_rewind); -EXTERNC void (*tas_header)(uTCHAR *file); -EXTERNC void (*tas_read)(void); -EXTERNC void (*tas_frame)(void); -EXTERNC void (*tas_rewind)(int32_t frames_to_rewind); - #undef EXTERNC #endif /* TAS_H_ */ diff -upr --new-file puNES-0.105.org/src/gui/wdgOpenGL.hpp puNES-0.105.new/src/gui/wdgOpenGL.hpp --- puNES-0.105.org/src/gui/wdgOpenGL.hpp 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/wdgOpenGL.hpp 2020-03-18 11:47:29.381142540 +0100 @@ -19,11 +19,13 @@ #ifndef WDGOPENGL_HPP_ #define WDGOPENGL_HPP_ +#include +#if defined (_WIN32) // gui.h e' importante che stia in mezzo per non // avere problemi di compilazione legati ai vari // nested #include nella versione Windows -#include -#include "gui.h" +#include "win.h" +#endif #include #include diff -upr --new-file puNES-0.105.org/src/gui/wdgSettingsInput.cpp puNES-0.105.new/src/gui/wdgSettingsInput.cpp --- puNES-0.105.org/src/gui/wdgSettingsInput.cpp 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/wdgSettingsInput.cpp 2020-03-18 11:47:29.381142540 +0100 @@ -27,7 +27,6 @@ #include "dlgSettings.hpp" #include "dlgStdPad.hpp" #include "emu_thread.h" -#include "conf.h" typedef struct _cb_ports { QString desc; diff -upr --new-file puNES-0.105.org/src/gui/windows/jstick.c puNES-0.105.new/src/gui/windows/jstick.c --- puNES-0.105.org/src/gui/windows/jstick.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/windows/jstick.c 2020-03-18 11:47:29.381142540 +0100 @@ -325,6 +325,8 @@ struct _jstick { DWORD (WINAPI *XInputGetCapabilities_proc)(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES *pCapabilities); } jstick; +_js js[PORT_MAX], js_shcut; + void js_init(BYTE first_time) { int i; diff -upr --new-file puNES-0.105.org/src/gui/windows/jstick.h puNES-0.105.new/src/gui/windows/jstick.h --- puNES-0.105.org/src/gui/windows/jstick.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/gui/windows/jstick.h 2020-03-18 11:47:29.381142540 +0100 @@ -58,12 +58,6 @@ typedef struct _js_sch { BYTE mode; } _js_sch; -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - static const _js_element jsn_list[] = { { 0xFF, uL("NULL") } }; static const _js_element jsv_list[] = { { 0x000, uL("NULL") }, @@ -98,7 +92,13 @@ static const _js_element jsv_list[] = { { 0x41E, uL("JB30") }, { 0x41F, uL("JB31") } }; -EXTERNC _js js[PORT_MAX], js_shcut; +extern _js js[PORT_MAX], js_shcut; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void js_init(BYTE first_time); EXTERNC void js_quit(BYTE last_time); diff -upr --new-file puNES-0.105.org/src/video/d3d9/d3d9.c puNES-0.105.new/src/video/d3d9/d3d9.c --- puNES-0.105.org/src/video/d3d9/d3d9.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/d3d9/d3d9.c 2020-03-18 11:47:29.381142540 +0100 @@ -20,7 +20,6 @@ */ #include "d3d9.h" -#include "video/gfx_thread.h" #include "info.h" #include "gui.h" #include "conf.h" @@ -56,6 +55,8 @@ INLINE D3DTEXTUREFILTERTYPE d3d9_shader_ INLINE static void d3d9_shader_params_text_set(_shader *shd); INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount); +_d3d9 d3d9; + BYTE d3d9_init(void) { memset(&d3d9, 0x00, sizeof(d3d9)); diff -upr --new-file puNES-0.105.org/src/video/d3d9/d3d9.c.orig puNES-0.105.new/src/video/d3d9/d3d9.c.orig --- puNES-0.105.org/src/video/d3d9/d3d9.c.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/video/d3d9/d3d9.c.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,1899 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * for some codes : + * Copyright (C) 2010-2015 The RetroArch team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "d3d9.h" +#include "video/gfx_thread.h" +#include "info.h" +#include "gui.h" +#include "conf.h" +#include "ppu.h" +#include "overscan.h" + +#define _SCR_ROWS_BRD\ + ((float)(SCR_ROWS - (overscan.borders->left + overscan.borders->right)) * gfx.pixel_aspect_ratio) +#define _SCR_LINES_BRD\ + (float)(SCR_LINES - (overscan.borders->up + overscan.borders->down)) +#define _SCR_ROWS_NOBRD\ + ((float)SCR_ROWS * gfx.pixel_aspect_ratio) +#define _SCR_LINES_NOBRD\ + (float)SCR_LINES + +static void d3d9_shader_cg_error_handler(void); +static BYTE d3d9_device_create(UINT width, UINT height); +static void d3d9_context_delete(void); +static BYTE d3d9_texture_create(_texture *texture, UINT index); +static BYTE d3d9_texture_simple_create(_texture_simple *texture, UINT w, UINT h, BOOL text); +static BYTE d3d9_texture_lut_create(_lut *lut, UINT index); +static void d3d9_surface_clean(LPDIRECT3DSURFACE9 *surface, UINT width, UINT height); +static BYTE d3d9_shader_init(UINT pass, _shader *shd, const uTCHAR *path, const char *code); +static void d3d9_shader_delete(_shader *shd); +static void d3d9_shader_uniform_ctrl(CGparameter *dst, CGparameter *param, const char *semantic); +static void d3d9_shader_uni_texture_clear(_shader_uniforms_tex *sut); +static void d3d9_shader_uni_texture(_shader_uniforms_tex *sut, _shader_prg_cg *prg, char *fmt, ...); +static CGparameter d3d9_cg_find_param(CGparameter prm, const char *name); +static BYTE d3d9_vertex_declaration_create(_shader *shd); +static void d3d9_vertex_buffer_set(_shader *shd, _viewport *vp, _texture_rect *prev); +INLINE static void d3d9_viewport_set(DWORD x, DWORD y, DWORD w, DWORD h); +INLINE D3DTEXTUREFILTERTYPE d3d9_shader_filter(UINT type); +INLINE static void d3d9_shader_params_text_set(_shader *shd); +INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount); + +BYTE d3d9_init(void) { + memset(&d3d9, 0x00, sizeof(d3d9)); + + if ((d3d9.d3d = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) { + MessageBox(NULL, "Unable to create d3d object", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + // mi passo in rassegna tutti gli adapter presenti sul sistema + d3d9.adapters_on_system = IDirect3D9_GetAdapterCount(d3d9.d3d); + + if (!(d3d9.array = malloc(d3d9.adapters_on_system * sizeof(_d3d9_adapter)))) { + MessageBox(NULL, "Unable to create devices array", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + { + unsigned int adapt; + +#define dev_error(s) fprintf(stderr, "D3D9 adapter %d : "s, dev->id) +#define dev_info(s) printf("D3D9 adapter %d : "s, dev->id) +#define dev_info_args(s, ...) printf("D3D9 adapter %d : "s, dev->id, __VA_ARGS__) + + for (adapt = 0; adapt < d3d9.adapters_on_system; adapt++) { + _d3d9_adapter *dev = D3D9_ADAPTER(d3d9.adapters_in_use); + D3DADAPTER_IDENTIFIER9 info; + D3DCAPS9 d3dcaps; + + memset(dev, 0x00, sizeof(_d3d9_adapter)); + + dev->id = adapt; + + if (IDirect3D9_GetAdapterIdentifier(d3d9.d3d, dev->id, 0, &info)!= D3D_OK) { + dev_error("unable to get adapter display info\n"); + continue; + } + + dev_info_args("%s\n", info.Description); + + if (IDirect3D9_GetAdapterDisplayMode(d3d9.d3d, dev->id, &dev->display_mode) != D3D_OK) { + dev_error("unable to get adapter display mode\n"); + continue; + } + + if ((dev->display_mode.Format == D3DFMT_X8R8G8B8) || + (dev->display_mode.Format == D3DFMT_A8R8G8B8)) { + dev->bit_per_pixel = 32; + } + if (dev->bit_per_pixel < 32) { + dev_error("video mode < 32 bits are not supported\n"); + continue; + } + + // Check for hardware T&L + if (IDirect3D9_GetDeviceCaps(d3d9.d3d, dev->id, D3DDEVTYPE_HAL, &d3dcaps) != D3D_OK) { + dev_error("unable to get device caps\n"); + continue; + } + + if (d3dcaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) { + dev->dynamic_texture = TRUE; + } else { + dev->dynamic_texture = FALSE; + dev_info("don't support dynamic texture\n"); + } + + if (d3dcaps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) { + dev->texture_square_only = TRUE; + dev_info("support only square texture\n"); + } else { + dev->texture_square_only = FALSE; + } + + // Device can accelerate a memory copy from system memory to local video memory. + // This cap guarantees that UpdateSurface and UpdateTexture calls will be hardware + // accelerated. If this cap is absent, these calls will succeed but will be slower. + if (!(d3dcaps.Caps3 & D3DCAPS3_COPY_TO_VIDMEM)) { + dev_info("don't support accelerated texture update\n"); + } + + if (d3dcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { + dev->flags = D3DCREATE_HARDWARE_VERTEXPROCESSING; + // se abilito il PURE DEVICE, non posso utilizzare il + // IDirect3DDevice9_GetTransform quando uso le shaders. + if (d3dcaps.DevCaps & D3DDEVCAPS_PUREDEVICE) { + dev->flags |= D3DCREATE_PUREDEVICE; + } + } else { + dev_info("don't support hardware accelaration\n"); + dev->flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; + } + + if (!(d3dcaps.MaxSimultaneousTextures > 1)) { //number of textures + dev_info("single pass multitexturing not supported\n"); + } else { + dev_info_args("MaxSimultaneousTextures %ld\n", d3dcaps.MaxSimultaneousTextures); + } + + dev->number_of_monitors = d3dcaps.NumberOfAdaptersInGroup; + + //if (dev->number_of_monitors > 1) { + dev_info_args("MasterAdapterOrdinal %d\n", d3dcaps.MasterAdapterOrdinal); + dev_info_args("AdapterOrdinalInGroup %d\n", d3dcaps.AdapterOrdinalInGroup); + dev_info_args("NumberOfAdaptersInGroup %d\n", dev->number_of_monitors); + //dev->flags |= D3DCREATE_ADAPTERGROUP_DEVICE; + //} + + { + d3d9.adapter = dev; + + // per poter verificare se le shaders sono utilizzabili devo creare il dev d3d + if (d3d9_device_create(1, 1) != EXIT_OK) { + continue; + } + + dev->hlsl_compliant = FALSE; + + if (d3dcaps.PixelShaderVersion < D3DPS_VERSION(2, 0) || + (d3dcaps.VertexShaderVersion < D3DVS_VERSION(2, 0))) { + dev_info("don't support shaders >= 2.0\n"); + } else { + dev->hlsl_compliant = TRUE; + } + + if (dev->hlsl_compliant == FALSE) { + dev_info("shaders are not supported\n"); + } + + d3d9.adapter = NULL; + } + + d3d9.adapters_in_use++; + } + +#undef dev_error +#undef dev_info +#undef dev_info_args + } + + if (d3d9.adapters_in_use == 0) { + MessageBox(NULL, "Unable find usable adapter", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + d3d9.adapter = D3D9_ADAPTER(0); + if (d3d9.adapter->hlsl_compliant == FALSE) { + MessageBox(NULL, "Adapter is not hlsl compliant", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + gfx.bit_per_pixel = d3d9.adapter->bit_per_pixel; + + return (EXIT_OK); +} +BYTE d3d9_context_create(void) { + D3DXMATRIX identity; + WORD w, h; + UINT i; + + d3d9_context_delete(); + + if (overscan.enabled && (!cfg->oscan_black_borders && !cfg->fullscreen)) { + // visto che lavorero' con texture piu' grandi del video mode + // setto un backbuffer piu' grande. + w = gfx.w[VIDEO_MODE] * 2; + h = gfx.h[VIDEO_MODE] * 2; + } else { + w = gfx.w[VIDEO_MODE]; + h = gfx.h[VIDEO_MODE]; + } + + if (d3d9_device_create(w, h) == EXIT_ERROR) { + d3d9_context_delete(); + return (EXIT_ERROR); + } + + if ((d3d9.cgctx = cgCreateContext()) == NULL) { + d3d9_context_delete(); + return (EXIT_ERROR); + } + + cgSetErrorCallback(d3d9_shader_cg_error_handler); + + cgD3D9SetDevice(d3d9.adapter->dev); + + w = gfx.w[PASS0]; + h = gfx.h[PASS0]; + + D3DXMatrixIdentity(&identity); + IDirect3DDevice9_SetTransform(d3d9.adapter->dev, D3DTS_WORLD, &identity); + IDirect3DDevice9_SetTransform(d3d9.adapter->dev, D3DTS_VIEW, &identity); + + // screen + d3d9_texture_simple_create(&d3d9.screen.tex[0], w, h, FALSE); + + // lut (devo farlo prima di elaborare le shaders) + for (i = 0; i < shader_effect.luts; i++) { + if (d3d9_texture_lut_create(&d3d9.lut[i], i) == EXIT_ERROR) { + d3d9_context_delete(); + return (EXIT_ERROR_SHADER); + } + } + + // devo precalcolarmi il viewport finale + { + _viewport *vp = &gfx.vp; + + vp->x = 0; + vp->y = 0; + vp->w = gfx.w[VIDEO_MODE]; + vp->h = gfx.h[VIDEO_MODE]; + + if (overscan.enabled && (!cfg->oscan_black_borders && !cfg->fullscreen)) { + vp->x = (-overscan.borders->left * gfx.width_pixel) * gfx.pixel_aspect_ratio; + vp->y = (-overscan.borders->up * cfg->scale); + vp->w = gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio; + vp->h = gfx.h[NO_OVERSCAN]; + } + + // configuro l'aspect ratio del fullscreen + if (cfg->fullscreen) { + if (!cfg->stretch) { + if (cfg->integer_scaling) { + int mw = _SCR_ROWS_NOBRD; + int mh = _SCR_LINES_NOBRD; + int mul = gfx.w[VIDEO_MODE] > gfx.h[VIDEO_MODE] ? + (gfx.h[VIDEO_MODE] - (gfx.h[VIDEO_MODE] % mh)) / mh : + (gfx.w[VIDEO_MODE] - (gfx.w[VIDEO_MODE] % mw)) / mw; + + vp->w = mw * mul; + vp->h = mh * mul; + } else { + float mw = _SCR_ROWS_NOBRD; + float mh = _SCR_LINES_NOBRD; + float mul = mw / mh ; + + if (gfx.w[VIDEO_MODE] > gfx.h[VIDEO_MODE]) { + vp->w = (int)((float)gfx.h[VIDEO_MODE] * mul); + } else { + vp->h = (int)((float)gfx.w[VIDEO_MODE] / mul); + } + } + vp->x = (gfx.w[VIDEO_MODE] - vp->w) >> 1; + vp->y = (gfx.h[VIDEO_MODE] - vp->h) >> 1; + } + + if (overscan.enabled && (cfg->oscan_black_borders_fscr == FALSE)) { + float brd_l_x, brd_r_x, brd_u_y, brd_d_y; + float ratio_x, ratio_y; + + ratio_x = (float)vp->w / _SCR_ROWS_NOBRD; + ratio_y = (float)vp->h / _SCR_LINES_NOBRD; + brd_l_x = (float)overscan.borders->left * ratio_x; + brd_r_x = (float)overscan.borders->right * ratio_x; + brd_u_y = (float)overscan.borders->up * ratio_y; + brd_d_y = (float)overscan.borders->down * ratio_y; + + d3d9.viewp.left = brd_l_x; + d3d9.viewp.top = brd_u_y; + d3d9.viewp.right = gfx.w[VIDEO_MODE] - brd_r_x; + d3d9.viewp.bottom = gfx.h[VIDEO_MODE] - brd_d_y; + } else { + d3d9.viewp.left = 0; + d3d9.viewp.top = 0; + d3d9.viewp.right = gfx.w[VIDEO_MODE]; + d3d9.viewp.bottom = gfx.h[VIDEO_MODE]; + } + } else { + d3d9.viewp.left = -vp->x; + d3d9.viewp.top = -vp->y; + d3d9.viewp.right = gfx.w[VIDEO_MODE] + d3d9.viewp.left; + d3d9.viewp.bottom = gfx.h[VIDEO_MODE] + d3d9.viewp.top; + } + } + + // texture + for (i = 0; i < shader_effect.pass; i++) { + fprintf(stderr, "D3D9: Setting pass %d.\n", i); + + if (d3d9_texture_create(&d3d9.texture[i], i) == EXIT_ERROR) { + d3d9_context_delete(); + return (EXIT_ERROR); + } + + if (d3d9_shader_init(i, &d3d9.texture[i].shader, shader_effect.sp[i].path, shader_effect.sp[i].code) == EXIT_ERROR) { + d3d9_context_delete(); + return (EXIT_ERROR_SHADER); + } + } + + // PREV (calcolo il numero di screen da utilizzare) + // deve essere fatto dopo il d3d9_shader_init(). + for (i = 0; i < shader_effect.pass; i++) { + UINT a; + + for (a = 0; a < LENGTH(d3d9.texture[i].shader.uni.prev); a++) { + if (d3d9.texture[i].shader.uni.prev[a].f.texture) { + if (d3d9.screen.in_use < (a + 1)) { + d3d9.screen.in_use = (a + 1); + } + } + } + } + + d3d9.screen.in_use++; + + // PREV + for (i = 1; i < d3d9.screen.in_use; i++) { + d3d9_texture_simple_create(&d3d9.screen.tex[i], w, h, FALSE); + } + + // FEEDBACK + if ((shader_effect.feedback_pass >= 0) && (shader_effect.feedback_pass < shader_effect.pass)) { + d3d9.feedback.in_use = TRUE; + + if (d3d9_texture_create(&d3d9.feedback.tex, shader_effect.feedback_pass) == EXIT_ERROR) { + d3d9_context_delete(); + return (EXIT_ERROR); + } + } + + // testo + { + int tw, th; + + // setto il necessario per il blending + IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_BLENDOP, D3DBLENDOP_ADD); + IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); + IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); + + if (cfg->fullscreen) { + float div = (float)gfx.w[VIDEO_MODE] / 1024.0f; + + if (div < 1.0f) { + div = 1.0f; + } + + tw = gfx.w[VIDEO_MODE] / div; + th = gfx.h[VIDEO_MODE] / div; + } else if (cfg->scale == 1) { + tw = gfx.w[VIDEO_MODE]; + th = gfx.h[VIDEO_MODE]; + } else { + tw = _SCR_ROWS_NOBRD * 2; + th = _SCR_LINES_NOBRD * 2; + } + + d3d9_texture_simple_create(&d3d9.text, tw, th, TRUE); + + text.w = d3d9.text.rect.w; + text.h = d3d9.text.rect.h; + + gfx_text_reset(); + + fprintf(stderr, "D3D9: Setting text pass.\n"); + + if (d3d9_shader_init(0, &d3d9.text.shader, NULL, shader_code_blend()) == EXIT_ERROR) { + d3d9_context_delete(); + return (EXIT_ERROR); + } + } + + // setto tutto quello che mi serve per il rendering + for (i = 0; i < shader_effect.pass; i++) { + _texture *texture = &d3d9.texture[i]; + _shader *shd = &texture->shader; + _texture_rect *prev = NULL; + + if (i == 0) { + prev = &d3d9.screen.tex[0].rect; + } else { + prev = &d3d9.texture[i - 1].rect; + } + + shd->info.video_size.x = (FLOAT)prev->base.w; + shd->info.video_size.y = (FLOAT)prev->base.h; + shd->info.texture_size.x = prev->w, + shd->info.texture_size.y = prev->h; + shd->info.output_size.x = (FLOAT)texture->vp.w; + shd->info.output_size.y = (FLOAT)texture->vp.h; + + d3d9_vertex_buffer_set(shd, &texture->vp, prev); + } + + umemcpy(gfx.last_shader_file, cfg->shader_file, usizeof(gfx.last_shader_file)); + + return (EXIT_OK); +} +void d3d9_draw_scene(void) { + const _texture_simple *scrtex = &d3d9.screen.tex[d3d9.screen.index]; + LPDIRECT3DSURFACE9 back_buffer; + UINT i; + + if (gui.start == FALSE) { + return; + } + + IDirect3DDevice9_GetRenderTarget(d3d9.adapter->dev, 0, &back_buffer); + + // texture + for (i = 0; i < shader_effect.pass; i++) { + const _texture *texture = &d3d9.texture[i]; + const _shader_pass *sp = &shader_effect.sp[i]; + D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(sp->linear); + + shader_effect.running_pass = i; + + if (i == shader_effect.last_pass) { + IDirect3DDevice9_SetRenderTarget(d3d9.adapter->dev, 0, back_buffer); + // pulisco l'intero schermo + d3d9_viewport_set(0, 0, gfx.w[VIDEO_MODE], gfx.h[VIDEO_MODE]); + } else { + IDirect3DDevice9_SetRenderTarget(d3d9.adapter->dev, 0, texture->map0); + // pulisco l'fbo + d3d9_viewport_set(0, 0, texture->rect.w, texture->rect.h); + } + IDirect3DDevice9_Clear(d3d9.adapter->dev, 0, NULL, D3DCLEAR_TARGET, + D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0); + + // ora setto il viewport corretto + if (cfg->fullscreen) { + d3d9_viewport_set(texture->vp.x, texture->vp.y, texture->vp.w, texture->vp.h); + } else { + d3d9_viewport_set(0, 0, texture->vp.w, texture->vp.h); + } + + cgD3D9BindProgram(texture->shader.prg.f); + cgD3D9BindProgram(texture->shader.prg.v); + + if (i == 0) { + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 * )scrtex->data); + } else { + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 * )d3d9.texture[i - 1].data); + } + + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, filter); + + IDirect3DDevice9_SetVertexDeclaration(d3d9.adapter->dev, texture->shader.vd); + + d3d9_shader_param_set(texture, sp->frame_count_mod, ppu.frames); + + IDirect3DDevice9_BeginScene(d3d9.adapter->dev); + IDirect3DDevice9_DrawPrimitive(d3d9.adapter->dev, D3DPT_TRIANGLESTRIP, 0, 2); + IDirect3DDevice9_EndScene(d3d9.adapter->dev); + } + + IDirect3DSurface9_Release(back_buffer); + + d3d9.screen.index = ((d3d9.screen.index + 1) % d3d9.screen.in_use); + + if (d3d9.feedback.in_use) { + LPDIRECT3DTEXTURE9 data = d3d9.feedback.tex.data; + LPDIRECT3DSURFACE9 map0 = d3d9.feedback.tex.map0; + + d3d9.feedback.tex.data = d3d9.texture[shader_effect.feedback_pass].data; + d3d9.feedback.tex.map0 = d3d9.texture[shader_effect.feedback_pass].map0; + d3d9.texture[shader_effect.feedback_pass].data = data; + d3d9.texture[shader_effect.feedback_pass].map0 = map0; + } + + // rendering del testo + text_rendering(TRUE); + + // text + if (cfg->txt_on_screen && text.on_screen) { + float vpx, vpy, vpw, vph; + + // aggiorno la texture del testo + IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, d3d9.text.offscreen, NULL, d3d9.text.map0, NULL); + + vpx = d3d9.viewp.left * gfx.device_pixel_ratio; + vpy = d3d9.viewp.top * gfx.device_pixel_ratio; + vpw = (d3d9.viewp.right - d3d9.viewp.left) * gfx.device_pixel_ratio; + vph = (d3d9.viewp.bottom - d3d9.viewp.top) * gfx.device_pixel_ratio; + + d3d9_viewport_set(vpx, vpy, vpw, vph); + + cgD3D9BindProgram(d3d9.text.shader.prg.f); + cgD3D9BindProgram(d3d9.text.shader.prg.v); + + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *)d3d9.text.data); + + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + + IDirect3DDevice9_SetVertexDeclaration(d3d9.adapter->dev, d3d9.text.shader.vd); + + d3d9_shader_params_text_set(&d3d9.text.shader); + + IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_ALPHABLENDENABLE, TRUE); + IDirect3DDevice9_BeginScene(d3d9.adapter->dev); + IDirect3DDevice9_DrawPrimitive(d3d9.adapter->dev, D3DPT_TRIANGLESTRIP, 0, 2); + IDirect3DDevice9_EndScene(d3d9.adapter->dev); + IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_ALPHABLENDENABLE, FALSE); + } + + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL); + + // swap buffers + { + if (IDirect3DDevice9_Present(d3d9.adapter->dev, &d3d9.viewp, NULL, NULL, NULL) == D3DERR_DEVICELOST) { + if (IDirect3DDevice9_TestCooperativeLevel(d3d9.adapter->dev) == D3DERR_DEVICENOTRESET) { + emu_pause(TRUE); + + if (d3d9_context_create() == EXIT_ERROR) { + fprintf(stderr, "D3D9 : Unable to initialize d3d context\n"); + } + + emu_pause(FALSE); + } + } + + // screenshot + if (gfx.save_screenshot == TRUE) { + IDirect3DSurface9 *back_buffer, *surface; + + if (IDirect3DDevice9_GetBackBuffer(d3d9.adapter->dev, 0, 0, D3DBACKBUFFER_TYPE_MONO, &back_buffer) == D3D_OK) { + D3DSURFACE_DESC sd; + + IDirect3DSurface9_GetDesc(back_buffer, &sd); + + if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, sd.Width, + sd.Height, sd.Format, D3DPOOL_SYSTEMMEM, &surface, NULL) == D3D_OK) { + if (IDirect3DDevice9_GetRenderTargetData(d3d9.adapter->dev, back_buffer, surface) == D3D_OK) { + D3DLOCKED_RECT lrect; + + if (overscan.enabled && ((!cfg->fullscreen && !cfg->oscan_black_borders) || + (cfg->fullscreen && !cfg->oscan_black_borders_fscr))) { + int w = d3d9.viewp.right - d3d9.viewp.left; + int h = d3d9.viewp.bottom - d3d9.viewp.top; + IDirect3DSurface9 *zone; + + if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, + w, h, sd.Format, D3DPOOL_DEFAULT, &zone, NULL) == D3D_OK) { + if (IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, surface, &d3d9.viewp, zone, NULL) == D3D_OK) { + IDirect3DSurface9_LockRect(zone, &lrect, NULL, 0); + gui_save_screenshot(w, h, lrect.pBits, FALSE); + IDirect3DSurface9_UnlockRect(zone); + } + IDirect3DSurface9_Release(zone); + } + } else { + IDirect3DSurface9_LockRect(surface, &lrect, NULL, 0); + gui_save_screenshot(sd.Width, sd.Height, lrect.pBits, FALSE); + IDirect3DSurface9_UnlockRect(surface); + } + } + IDirect3DSurface9_Release(surface); + } + IDirect3DSurface9_Release(back_buffer); + } + gfx.save_screenshot = FALSE; + } + } +} +void d3d9_quit(void) { + d3d9_context_delete(); + + { + UINT i; + + for (i = 0; i < d3d9.adapters_in_use; i++) { + _d3d9_adapter *dev = D3D9_ADAPTER(i); + + if (dev->dev) { + IDirect3DDevice9_Release(dev->dev); + dev->dev = NULL; + } + + } + } + + if (d3d9.d3d) { + IDirect3D9_Release(d3d9.d3d); + d3d9.d3d = NULL; + } + + if (d3d9.array) { + free(d3d9.array); + d3d9.array = d3d9.adapter = NULL; + } +} + +static void d3d9_shader_cg_error_handler(void) { + CGerror error = cgGetError(); + + if (error == (CGerror) cgD3D9Failed) { + fprintf(stderr, "D3D9: Error '%s' occurred.\n", cgD3D9TranslateHRESULT(cgD3D9GetLastError())); + } else { + fprintf(stderr, "CG: Error '%s' occurred.\n", cgD3D9TranslateCGerror(error)); + } +} +static BYTE d3d9_device_create(UINT width, UINT height) { + D3DPRESENT_PARAMETERS d3dpp; + + if (d3d9.adapter->dev) { + IDirect3DDevice9_Release(d3d9.adapter->dev); + d3d9.adapter->dev = NULL; + } + + ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); + d3dpp.Windowed = TRUE; + d3dpp.SwapEffect = D3DSWAPEFFECT_COPY; + d3dpp.hDeviceWindow = gui_screen_id(); + d3dpp.BackBufferCount = 1; + d3dpp.BackBufferFormat = d3d9.adapter->display_mode.Format; + d3dpp.BackBufferWidth = width; + d3dpp.BackBufferHeight = height; + if (cfg->vsync == TRUE) { + //d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + } else { + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + } + + if (IDirect3D9_CreateDevice(d3d9.d3d, + d3d9.adapter->id, + D3DDEVTYPE_HAL, + gui_screen_id(), + d3d9.adapter->flags | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, + &d3dpp, + &d3d9.adapter->dev) != D3D_OK) { + MessageBox(NULL, "Unable to create d3d device", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + return (EXIT_OK); +} +static void d3d9_context_delete(void) { + UINT i; + + d3d9.screen.in_use = 0; + d3d9.screen.index = 0; + + for (i = 0; i < LENGTH(d3d9.screen.tex); i++) { + _texture_simple *texture = &d3d9.screen.tex[i]; + if (texture->offscreen) { + IDirect3DSurface9_Release(texture->offscreen); + texture->offscreen = NULL; + } + if (texture->map0) { + IDirect3DSurface9_Release(texture->map0); + texture->map0 = NULL; + } + if (texture->data) { + IDirect3DTexture9_Release(texture->data); + texture->data = NULL; + } + if (texture->shader.vd) { + IDirect3DVertexDeclaration9_Release(texture->shader.vd); + texture->shader.vd = NULL; + } + if (texture->shader.quad) { + IDirect3DVertexBuffer9_Release(texture->shader.quad); + texture->shader.quad = NULL; + } + } + + { + if (d3d9.text.offscreen) { + IDirect3DSurface9_Release(d3d9.text.offscreen); + d3d9.text.offscreen = NULL; + } + if (d3d9.text.map0) { + IDirect3DSurface9_Release(d3d9.text.map0); + d3d9.text.map0 = NULL; + } + if (d3d9.text.data) { + IDirect3DTexture9_Release(d3d9.text.data); + d3d9.text.data = NULL; + } + if (d3d9.text.shader.vd) { + IDirect3DVertexDeclaration9_Release(d3d9.text.shader.vd); + d3d9.text.shader.vd = NULL; + } + if (d3d9.text.shader.quad) { + IDirect3DVertexBuffer9_Release(d3d9.text.shader.quad); + d3d9.text.shader.quad = NULL; + } + d3d9_shader_delete(&d3d9.text.shader); + } + + { + d3d9.feedback.in_use = FALSE; + + if (d3d9.feedback.tex.map0) { + IDirect3DSurface9_Release(d3d9.feedback.tex.map0); + d3d9.feedback.tex.map0 = NULL; + } + if (d3d9.feedback.tex.data) { + IDirect3DTexture9_Release(d3d9.feedback.tex.data); + d3d9.feedback.tex.data = NULL; + } + if (d3d9.feedback.tex.shader.quad) { + IDirect3DVertexBuffer9_Release(d3d9.feedback.tex.shader.quad); + d3d9.feedback.tex.shader.quad = NULL; + } + if (d3d9.feedback.tex.shader.vd) { + IDirect3DVertexDeclaration9_Release(d3d9.feedback.tex.shader.vd); + d3d9.feedback.tex.shader.vd = NULL; + } + d3d9_shader_delete(&d3d9.feedback.tex.shader); + } + + for (i = 0; i < LENGTH(d3d9.texture); i++) { + _texture *texture = &d3d9.texture[i]; + + if (texture->map0) { + IDirect3DSurface9_Release(texture->map0); + texture->map0 = NULL; + } + if (texture->data) { + IDirect3DTexture9_Release(texture->data); + texture->data = NULL; + } + if (texture->shader.quad) { + IDirect3DVertexBuffer9_Release(texture->shader.quad); + texture->shader.quad = NULL; + } + if (texture->shader.vd) { + IDirect3DVertexDeclaration9_Release(texture->shader.vd); + texture->shader.vd = NULL; + } + d3d9_shader_delete(&d3d9.texture[i].shader); + } + + for (i = 0; i < LENGTH(d3d9.lut); i++) { + if (d3d9.lut[i].data) { + IDirect3DTexture9_Release(d3d9.lut[i].data); + d3d9.lut[i].data = NULL; + } + } + + if (d3d9.cgctx) { + cgD3D9UnloadAllPrograms(); + cgD3D9SetDevice(NULL); + cgDestroyContext(d3d9.cgctx); + d3d9.cgctx = NULL; + } + + if (d3d9.adapter && d3d9.adapter->dev) { + IDirect3DDevice9_Release(d3d9.adapter->dev); + d3d9.adapter->dev = NULL; + } +} +static BYTE d3d9_texture_create(_texture *texture, UINT index) { + _shader_pass *sp = &shader_effect.sp[index]; + _shader_scale *sc = &sp->sc; + const _texture_rect *prev; + _texture_rect *rect = &texture->rect; + _viewport *vp = &texture->vp; + + if (index == 0) { + prev = &d3d9.screen.tex[0].rect; + } else { + prev = &d3d9.texture[index - 1].rect; + } + + if (index == shader_effect.last_pass) { + sc->scale.x = 1.0f; + sc->scale.y = 1.0f; + sc->type.x = SHADER_SCALE_VIEWPORT; + sc->type.y = SHADER_SCALE_VIEWPORT; + } + +#if defined (FH_SHADERS_GEST) + switch (sc->type.x) { + case SHADER_SCALE_DEFAULT: + case SHADER_SCALE_INPUT: + rect->base.w = (FLOAT)prev->base.w * sc->scale.x; + break; + case SHADER_SCALE_ABSOLUTE: + rect->base.w = sc->abs.x; + break; + case SHADER_SCALE_VIEWPORT: + rect->base.w = (FLOAT)gfx.vp.w * sc->scale.x; + break; + } + switch (sc->type.y) { + case SHADER_SCALE_DEFAULT: + case SHADER_SCALE_INPUT: + rect->base.h = (FLOAT)prev->base.h * sc->scale.y; + break; + case SHADER_SCALE_ABSOLUTE: + rect->base.h = sc->abs.y; + break; + case SHADER_SCALE_VIEWPORT: + rect->base.h = (FLOAT)gfx.vp.h * sc->scale.y; + break; + } + + rect->w = emu_power_of_two(rect->base.w); + rect->h = emu_power_of_two(rect->base.h); +#else + switch (sc->type.x) { + case SHADER_SCALE_DEFAULT: + case SHADER_SCALE_INPUT: + rect->w = (FLOAT)prev->w * sc->scale.x; + rect->base.w = (FLOAT)prev->base.w * sc->scale.x; + break; + case SHADER_SCALE_ABSOLUTE: + rect->w = rect->base.w = sc->abs.x; + break; + case SHADER_SCALE_VIEWPORT: + rect->w = rect->base.w = (FLOAT)gfx.vp.w * sc->scale.x; + break; + } + switch (sc->type.y) { + case SHADER_SCALE_DEFAULT: + case SHADER_SCALE_INPUT: + rect->h = (FLOAT)prev->h * sc->scale.y; + rect->base.h = (FLOAT)prev->base.h * sc->scale.y; + break; + case SHADER_SCALE_ABSOLUTE: + rect->h = rect->base.h = sc->abs.y; + break; + case SHADER_SCALE_VIEWPORT: + rect->h = rect->base.h = (FLOAT)gfx.vp.h * sc->scale.y; + break; + } + + rect->w = emu_power_of_two(rect->w); + rect->h = emu_power_of_two(rect->h); +#endif + + // se la scheda video supporta solo texture quadre allore devo crearle quadre + if (d3d9.adapter->texture_square_only == TRUE) { + if (rect->w < rect->h) { + rect->w = rect->h; + } else { + rect->h = rect->w; + } + } + + if (index == shader_effect.last_pass) { + vp->x = gfx.vp.x * gfx.device_pixel_ratio; + vp->y = gfx.vp.y * gfx.device_pixel_ratio; + vp->w = gfx.vp.w * gfx.device_pixel_ratio; + vp->h = gfx.vp.h * gfx.device_pixel_ratio; + } else { + vp->x = 0; + vp->y = 0; + vp->w = rect->base.w; + vp->h = rect->base.h; + } + + if (IDirect3DDevice9_CreateVertexBuffer(d3d9.adapter->dev, sizeof(_vertex_buffer) * 4, 0, 0, + D3DPOOL_DEFAULT, &texture->shader.quad, NULL) != D3D_OK) { + MessageBox(NULL, "Unable to create the vertex buffer", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev, + (UINT)rect->w, (UINT)rect->h, 1, + D3DUSAGE_RENDERTARGET, + sp->fbo_flt ? D3DFMT_A32B32G32R32F : D3DFMT_A8R8G8B8, + D3DPOOL_DEFAULT, + &texture->data, + NULL) != D3D_OK) { + MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + IDirect3DTexture9_GetSurfaceLevel(texture->data, 0, &texture->map0); + // cancello la superficie map0 perche' alcuni driver (tipo intel) nella + // versione per windows XP non mi passano una superficia "pulita". + d3d9_surface_clean(&texture->map0, rect->w, rect->h); + + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *) texture->data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL); + + return (EXIT_OK); +} +static BYTE d3d9_texture_simple_create(_texture_simple *texture, UINT w, UINT h, BOOL text) { + _texture_rect *rect = &texture->rect; + _shader *shd = &texture->shader; + _viewport vp = { 0, 0, w, h }; + UINT flt; + + rect->base.w = w; + rect->base.h = h; + + if (!text) { +#if defined (FH_SHADERS_GEST) + rect->w = emu_power_of_two(rect->base.w); + rect->h = emu_power_of_two(rect->base.h); +#else + // rect->w = 1024 e rect->h = 1024 sono + // le dimensioni che imposta retroarch + // ma su alcune shader l'effetto e' piu' + // sgranato ("mudlord/emboss.h" e + // "antialiasing/fx-aa.h" sono un esempio) + rect->w = 1024; + rect->h = 1024; +#endif + flt = (cfg->interpolation || gfx.PSS) ? D3DTEXF_LINEAR : D3DTEXF_POINT; + } else { + rect->w = rect->base.w; + rect->h = rect->base.h; + flt = D3DTEXF_POINT; + } + + // se la scheda video supporta solo texture quadre allore devo crearle quadre + if (d3d9.adapter->texture_square_only == TRUE) { + if (rect->w < rect->h) { + rect->w = rect->h; + } else { + rect->h = rect->w; + } + } + + shd->info.video_size.x = (FLOAT)rect->base.w; + shd->info.video_size.y = (FLOAT)rect->base.h; + shd->info.texture_size.x = rect->w; + shd->info.texture_size.y = rect->h; + + if (IDirect3DDevice9_CreateVertexBuffer(d3d9.adapter->dev, + sizeof(_vertex_buffer) * 4, + D3DUSAGE_WRITEONLY, + 0, + D3DPOOL_DEFAULT, + &texture->shader.quad, + NULL) != D3D_OK) { + MessageBox(NULL, "Unable to create the vertex buffer", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev, + (UINT)rect->w, (UINT)rect->h, 1, + d3d9.adapter->dynamic_texture ? D3DUSAGE_DYNAMIC : 0, + D3DFMT_A8R8G8B8, + D3DPOOL_DEFAULT, + &texture->data, + NULL) != D3D_OK) { + MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + IDirect3DTexture9_GetSurfaceLevel(texture->data, 0, &texture->map0); + // cancello la superficie map0 perche' alcuni driver (tipo intel) nella + // versione per windows XP non mi passano una superficia "pulita". + d3d9_surface_clean(&texture->map0, rect->w, rect->h); + + // creo la superficie temporanea le cui dimensioni non devono essere "POWerate" + if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, + rect->base.w, + rect->base.h, + D3DFMT_A8R8G8B8, + D3DPOOL_SYSTEMMEM, + &texture->offscreen, + NULL) != D3D_OK) { + MessageBox(NULL, "Unable to create the memory surface", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + // cancello la superficie + d3d9_surface_clean(&texture->offscreen, rect->base.w, rect->base.h); + + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *) texture->data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, flt); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, flt); + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL); + + d3d9_vertex_buffer_set(shd, &vp, rect); + + return (EXIT_OK); +} +static BYTE d3d9_texture_lut_create(_lut *lut, UINT index) { + _lut_pass *lp = &shader_effect.lp[index]; + LPDIRECT3DSURFACE9 map0, offscreen; + D3DLOCKED_RECT lrect; + UINT width, height; + + if (gui_load_lut(lut, lp->path) == EXIT_ERROR) { + return (EXIT_ERROR); + } + + width = lut->w; + height = lut->h; + + lut->name = lp->name; + lut->filter = d3d9_shader_filter(lp->linear); + + if (d3d9.adapter->texture_square_only == TRUE) { + if (width < height) { + width = height; + } else { + height = width; + } + } + + if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev, + width, height, 1, + 0, + D3DFMT_A8R8G8B8, + D3DPOOL_DEFAULT, + &lut->data, + NULL) != D3D_OK) { + MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, + lut->w, lut->h, + D3DFMT_A8R8G8B8, + D3DPOOL_SYSTEMMEM, + &offscreen, + NULL) != D3D_OK) { + MessageBox(NULL, "Unable to create the memory surface", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + IDirect3DTexture9_GetSurfaceLevel(lut->data, 0, &map0); + + if (IDirect3DSurface9_LockRect(offscreen, &lrect, NULL, D3DLOCK_DISCARD) != D3D_OK) { + if (map0) { + IDirect3DSurface9_Release(map0); + } + if (offscreen) { + IDirect3DSurface9_Release(offscreen); + } + return (EXIT_ERROR); + } else { + UINT w = 0, h = 0; + uint32_t *sbits = (uint32_t *)lut->bits; + uint32_t *dbits = (uint32_t *)lrect.pBits; + + for (h = 0; h < lut->h; h++) { + for (w = 0; w < lut->w; w++) { + (*(dbits + w)) = (*(sbits + w)); + } + sbits += lrect.Pitch / (gfx.bit_per_pixel / 8); + dbits += lrect.Pitch / (gfx.bit_per_pixel / 8); + } + + IDirect3DSurface9_UnlockRect(offscreen); + IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, offscreen, NULL, map0, NULL); + + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *)lut->data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL); + + IDirect3DSurface9_Release(map0); + IDirect3DSurface9_Release(offscreen); + } + + return (EXIT_OK); +} +static void d3d9_surface_clean(LPDIRECT3DSURFACE9 *surface, UINT width, UINT height) { + D3DLOCKED_RECT lock_dst; + + if (IDirect3DSurface9_LockRect((*surface), &lock_dst, NULL, D3DLOCK_DISCARD) == D3D_OK) { + uint32_t *pbits; + UINT w, h; + + pbits = (uint32_t *)lock_dst.pBits; + + for (h = 0; h < height; h++) { + for (w = 0; w < width; w++) { + (*(pbits + w)) = 0; + } + pbits += lock_dst.Pitch / (gfx.bit_per_pixel / 8); + } + + IDirect3DSurface9_UnlockRect((*surface)); + } +} +static BYTE d3d9_shader_init(UINT pass, _shader *shd, const uTCHAR *path, const char *code) { + const char *list; + const char *argv[128]; + const char **fopts = cgD3D9GetOptimalOptions(cgD3D9GetLatestPixelProfile()); + const char **vopts = cgD3D9GetOptimalOptions(cgD3D9GetLatestVertexProfile()); + char alias[MAX_PASS][128]; + uTCHAR base[LENGTH_FILE_NAME_MID]; + uTCHAR dname[LENGTH_FILE_NAME_MID]; + char bname[LENGTH_FILE_NAME_MID]; + UINT i, argc; + + if ((path != NULL) && path[0]) { + uTCHAR buffer[LENGTH_FILE_NAME_MID]; + + umemset(base, 0x00, usizeof(base)); + if (ugetcwd(base, usizeof(base)) == NULL) { ; }; + + umemset(dname, 0x00, usizeof(dname)); + gui_utf_dirname((uTCHAR *) path, dname, usizeof(buffer) - 1); + + umemset(buffer, 0x00, usizeof(buffer)); + gui_utf_basename((uTCHAR *) path, buffer, usizeof(buffer) - 1); + memset(bname, 0x00, sizeof(bname)); + wcstombs(bname, buffer, sizeof(bname) - 1); + } + + // fragment + { + memset(alias, 0x00, sizeof(alias)); + memset(argv, 0x00, sizeof(argv)); + + argc = 0; + argv[argc++] = "-DPARAMETER_UNIFORM"; + for (i = 0; i < pass; i++) { + _shader_pass *sp = &shader_effect.sp[i]; + + if (sp->alias[0]) { + snprintf(alias[i], 128, "-D%s_ALIAS", sp->alias); + argv[argc++] = alias[i]; + } + } + for (i = 0; i < 128; i++) { + if (!fopts[i]) { + break; + } + argv[argc] = fopts[i]; + + if (argc++ == 126) { + break; + } + } + argv[argc] = NULL; + + if ((path == NULL) || !path[0]) { + shd->prg.f = cgCreateProgram(d3d9.cgctx, CG_SOURCE, code, cgD3D9GetLatestPixelProfile(), "main_fragment", argv); + } else { + if (uchdir(dname) == -1) { ; } + shd->prg.f = cgCreateProgramFromFile(d3d9.cgctx, CG_SOURCE, bname, cgD3D9GetLatestPixelProfile(), "main_fragment", argv); + if (uchdir(base) == -1) { ; } + } + if (!shd->prg.f && (list = cgGetLastListing(d3d9.cgctx))) { + printf("CG: fragment program errors :\n%s\n", list); + } + } + + // vertex + { + memset(alias, 0x00, sizeof(alias)); + memset(argv, 0x00, sizeof(argv)); + + argc = 0; + argv[argc++] = "-DPARAMETER_UNIFORM"; + for (i = 0; i < pass; i++) { + _shader_pass *sp = &shader_effect.sp[i]; + + if (sp->alias[0]) { + snprintf(alias[i], 128, "-D%s_ALIAS", sp->alias); + argv[argc++] = alias[i]; + } + } + for (i = 0; i < 128; i++) { + if (!vopts[i]) { + break; + } + argv[argc] = vopts[i]; + + if (argc++ == 126) { + break; + } + } + argv[argc] = NULL; + + if ((path == NULL) || !path[0]) { + shd->prg.v = cgCreateProgram(d3d9.cgctx, CG_SOURCE, code, cgD3D9GetLatestVertexProfile(), "main_vertex", argv); + } else { + if (uchdir(dname) == -1) { ; } + shd->prg.v = cgCreateProgramFromFile(d3d9.cgctx, CG_SOURCE, bname, cgD3D9GetLatestVertexProfile(), "main_vertex", argv); + if (uchdir(base) == -1) { ; } + } + if (!shd->prg.v && (list = cgGetLastListing(d3d9.cgctx))) { + printf("CG: vertex program errors :\n%s\n", list); + } + } + + if (!shd->prg.f || !shd->prg.v) { + fprintf(stderr, "CG: %s\n", cgGetErrorString(cgGetError())); + return (EXIT_ERROR); + } + + if (cgD3D9LoadProgram(shd->prg.f, TRUE, 0) != D3D_OK) { + fprintf(stderr, "CG: Error on loading fragment program\n"); + return (EXIT_ERROR); + } + if (cgD3D9LoadProgram(shd->prg.v, TRUE, 0) != D3D_OK) { + fprintf(stderr, "CG: Error on loading vertex program\n"); + return (EXIT_ERROR); + } + + shd->uni.mvp = cgGetNamedParameter(shd->prg.v, "modelViewProj"); + if (!shd->uni.mvp) { + shd->uni.mvp = cgGetNamedParameter(shd->prg.v, "IN.mvp_matrix"); + } + + shd->uni.v.video_size = cgGetNamedParameter(shd->prg.v, "IN.video_size"); + shd->uni.f.video_size = cgGetNamedParameter(shd->prg.f, "IN.video_size"); + shd->uni.v.texture_size = cgGetNamedParameter(shd->prg.v, "IN.texture_size"); + shd->uni.f.texture_size = cgGetNamedParameter(shd->prg.f, "IN.texture_size"); + shd->uni.v.output_size = cgGetNamedParameter(shd->prg.v, "IN.output_size"); + shd->uni.f.output_size = cgGetNamedParameter(shd->prg.f, "IN.output_size"); + + shd->uni.v.frame_count = cgGetNamedParameter(shd->prg.v, "IN.frame_count"); + shd->uni.f.frame_count = cgGetNamedParameter(shd->prg.f, "IN.frame_count"); + + shd->uni.v.frame_direction = cgGetNamedParameter(shd->prg.v, "IN.frame_direction"); + shd->uni.f.frame_direction = cgGetNamedParameter(shd->prg.f, "IN.frame_direction"); + + if (d3d9_vertex_declaration_create(shd) == EXIT_ERROR) { + return (EXIT_ERROR); + } + + for (i = 0; i < shader_effect.luts; i++) { + shd->uni.v.lut[i] = cgGetNamedParameter(shd->prg.v, d3d9.lut[i].name); + shd->uni.f.lut[i] = cgGetNamedParameter(shd->prg.f, d3d9.lut[i].name); + } + + for (i = 0; i < shader_effect.params; i++) { + shd->uni.v.param[i] = cgGetNamedParameter(shd->prg.v, shader_effect.param[i].name); + shd->uni.f.param[i] = cgGetNamedParameter(shd->prg.f, shader_effect.param[i].name); + } + + d3d9_shader_uni_texture_clear(&shd->uni.orig); + d3d9_shader_uni_texture(&shd->uni.orig, &shd->prg, "ORIG"); + d3d9_shader_uni_texture(&shd->uni.orig, &shd->prg, "PASSPREV%u", pass + 1); + + d3d9_shader_uni_texture_clear(&shd->uni.feedback); + d3d9_shader_uni_texture(&shd->uni.feedback, &shd->prg, "FEEDBACK"); + + for (i = 0; i < pass; i++) { + d3d9_shader_uni_texture_clear(&shd->uni.passprev[i]); + + d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, "PASS%u", i + 1); + d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, "PASSPREV%u", pass - i); + + if (shader_effect.sp[i].alias[0]) { + d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, shader_effect.sp[i].alias); + } + } + + d3d9_shader_uni_texture_clear(&shd->uni.prev[0]); + d3d9_shader_uni_texture(&shd->uni.prev[0], &shd->prg, "PREV"); + + for (i = 1; i < LENGTH(shd->uni.prev); i++) { + d3d9_shader_uni_texture_clear(&shd->uni.prev[i]); + d3d9_shader_uni_texture(&shd->uni.prev[i], &shd->prg, "PREV%u", i); + } + + return (EXIT_OK); +} +static void d3d9_shader_delete(_shader *shd) { + if (shd->prg.f) { + cgDestroyProgram(shd->prg.f); + shd->prg.f = NULL; + } + if (shd->prg.v) { + cgDestroyProgram(shd->prg.v); + shd->prg.v = NULL; + } +} +static void d3d9_shader_uniform_ctrl(CGparameter *dst, CGparameter *param, const char *semantic) { + static const FLOAT f2[2] = {1.0f, 1.0f}; + + if (!(*param)) { + return; + } + + if (cgD3D9SetUniform((*param), &f2) != D3D_OK) { + (*dst) = 0; + fprintf(stderr, "CG: Parameter \"%s\" disabled.\n", semantic); + } else { + (*dst) = (*param); + } +} +static void d3d9_shader_uni_texture_clear(_shader_uniforms_tex *sut) { + sut->f.texture = NULL; + sut->v.video_size = NULL; + sut->f.video_size = NULL; + sut->v.texture_size = NULL; + sut->f.texture_size = NULL; + sut->v.tex_coord = NULL; +} +static void d3d9_shader_uni_texture(_shader_uniforms_tex *sut, _shader_prg_cg *prg, char *fmt, ...) { + CGparameter param; + char type[50], buff[100]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(type, sizeof(type), fmt, ap); + va_end(ap); + + snprintf(buff, sizeof(buff), "%s%s", type, ".texture"); + if (!sut->f.texture) { + sut->f.texture = cgGetNamedParameter(prg->f, buff); + } + snprintf(buff, sizeof(buff), "%s%s", type, ".video_size"); + if (!sut->v.video_size) { + param = cgGetNamedParameter(prg->v, buff); + d3d9_shader_uniform_ctrl(&sut->v.video_size, ¶m, buff); + } + if (!sut->f.video_size) { + param = cgGetNamedParameter(prg->f, buff); + d3d9_shader_uniform_ctrl(&sut->f.video_size, ¶m, buff); + } + snprintf(buff, sizeof(buff), "%s%s", type, ".texture_size"); + if (!sut->v.texture_size) { + param = cgGetNamedParameter(prg->v, buff); + d3d9_shader_uniform_ctrl(&sut->v.texture_size, ¶m, buff); + } + if (!sut->f.texture_size) { + param = cgGetNamedParameter(prg->f, buff); + d3d9_shader_uniform_ctrl(&sut->f.texture_size, ¶m, buff); + } + snprintf(buff, sizeof(buff), "%s%s", type, ".tex_coord"); + if (!sut->v.tex_coord) { + sut->v.tex_coord = cgGetNamedParameter(prg->v, buff); + } +} +static BYTE d3d9_vertex_declaration_create(_shader *shd) { + UINT i, count, index, tex_index = 0; + CGparameter param; + BYTE texcoord[2] = { FALSE }; + BYTE stream[4] = { FALSE }; + BYTE indices[LENGTH(shd->attribs.attrib)] = { FALSE }; + static const D3DVERTEXELEMENT9 end = D3DDECL_END(); + D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH]; + + if (cgD3D9GetVertexDeclaration(shd->prg.v, decl) == CG_FALSE) { + return (EXIT_ERROR); + } + + for (count = 0; count < MAXD3DDECLLENGTH; count++) { + if (memcmp(&end, &decl[count], sizeof(end)) == 0) { + break; + } + } + + if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "POSITION"))) { + param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "POSITION0"); + } + if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) { + stream[0] = TRUE; + index = cgGetParameterResourceIndex(param); + indices[index] = TRUE; + decl[index] = (D3DVERTEXELEMENT9) { + 0, 0, + D3DDECLTYPE_FLOAT3, + D3DDECLMETHOD_DEFAULT, + D3DDECLUSAGE_POSITION, 0 + }; + + fprintf(stderr, "CG: semantic POSITION found (%d)\n", index); + } + + if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD"))) { + param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD0"); + } + if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) { + stream[1] = TRUE; + texcoord[0] = TRUE; + index = cgGetParameterResourceIndex(param); + indices[index] = TRUE; + decl[index] = (D3DVERTEXELEMENT9) { + 1, sizeof(float) * 3, + D3DDECLTYPE_FLOAT2, + D3DDECLMETHOD_DEFAULT, + D3DDECLUSAGE_TEXCOORD, 0 + }; + + fprintf(stderr, "CG: semantic TEXCOORD0 found (%d)\n", index); + } + + param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD1"); + if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) { + stream[2] = TRUE; + texcoord[1] = TRUE; + index = cgGetParameterResourceIndex(param); + indices[index] = TRUE; + decl[index] = (D3DVERTEXELEMENT9) { + 2, sizeof(float) * 5, + D3DDECLTYPE_FLOAT2, + D3DDECLMETHOD_DEFAULT, + D3DDECLUSAGE_TEXCOORD, 1 + }; + + fprintf(stderr, "CG: semantic TEXCOORD1 found (%d)\n", index); + } + + if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "COLOR"))) { + param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "COLOR0"); + } + if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) { + stream[3] = TRUE; + index = cgGetParameterResourceIndex(param); + indices[index] = TRUE; + decl[index] = (D3DVERTEXELEMENT9) { + 3, sizeof(float) * 7, + D3DDECLTYPE_FLOAT4, + D3DDECLMETHOD_DEFAULT, + D3DDECLUSAGE_COLOR, 0 + }; + + fprintf(stderr, "CG: semantic COLOR found (%d)\n", index); + } + + // Stream {0, 1, 2, 3} might be already taken. Find first vacant stream + for (index = 0; index < 4; index++) { + if (stream[index] == FALSE) { + break; + } + } + + // Find first vacant texcoord declaration + if (texcoord[0] && texcoord[1]) { + tex_index = 2; + } else if (texcoord[1] && !texcoord[0]) { + tex_index = 0; + } else if (texcoord[0] && !texcoord[1]) { + tex_index = 1; + } + + shd->attribs.count = 0; + + for (i = 0; i < count; i++) { + if (indices[i]) { + shd->attribs.attrib[shd->attribs.count++] = 0; + } else { + fprintf(stderr, "CG: attrib found (%d %d %d %d)\n", i, shd->attribs.count, index, tex_index); + + shd->attribs.attrib[shd->attribs.count++] = index; + decl[i] = (D3DVERTEXELEMENT9) { + index, sizeof(float) * 3, + D3DDECLTYPE_FLOAT2, + D3DDECLMETHOD_DEFAULT, + D3DDECLUSAGE_TEXCOORD, tex_index + }; + while ((++index < 4) && stream[index]) { + index++; + } + if ((++tex_index == 1) && texcoord[1]) { + tex_index++; + } + } + } + + if (IDirect3DDevice9_CreateVertexDeclaration(d3d9.adapter->dev, decl, &shd->vd)) { + return (EXIT_ERROR); + } + + return (EXIT_OK); +} +static void d3d9_vertex_buffer_set(_shader *shd, _viewport *vp, _texture_rect *prev) { + D3DXMATRIX proj, ortho, rot; + FLOAT u = (FLOAT)prev->base.w / prev->w; + FLOAT v = (FLOAT)prev->base.h / prev->h; + void *buffer; + const UINT rotation = 0; + UINT i; + + shd->vb[0].x = 0.0f; + shd->vb[0].y = vp->h; + shd->vb[0].z = 0.5f; + shd->vb[0].u = 0.0f; + shd->vb[0].v = 0.0f; + shd->vb[0].lut_u = 0.0f; + shd->vb[0].lut_v = 0.0f; + shd->vb[0].r = 1.0f; + shd->vb[0].g = 1.0f; + shd->vb[0].b = 1.0f; + shd->vb[0].a = 1.0f; + + shd->vb[1].x = vp->w; + shd->vb[1].y = vp->h; + shd->vb[1].z = 0.5f; + shd->vb[1].u = u; + shd->vb[1].v = 0.0f; + shd->vb[1].lut_u = 1.0f; + shd->vb[1].lut_v = 0.0f; + shd->vb[1].r = 1.0f; + shd->vb[1].g = 1.0f; + shd->vb[1].b = 1.0f; + shd->vb[1].a = 1.0f; + + shd->vb[2].x = 0.0f; + shd->vb[2].y = 0.0f; + shd->vb[2].z = 0.5f; + shd->vb[2].u = 0.0f; + shd->vb[2].v = v; + shd->vb[2].lut_u = 0.0f; + shd->vb[2].lut_v = 1.0f; + shd->vb[2].r = 1.0f; + shd->vb[2].g = 1.0f; + shd->vb[2].b = 1.0f; + shd->vb[2].a = 1.0f; + + shd->vb[3].x = vp->w; + shd->vb[3].y = 0.0f; + shd->vb[3].z = 0.5f; + shd->vb[3].u = u; + shd->vb[3].v = v; + shd->vb[3].lut_u = 1.0f; + shd->vb[3].lut_v = 1.0f; + shd->vb[3].r = 1.0f; + shd->vb[3].g = 1.0f; + shd->vb[3].b = 1.0f; + shd->vb[3].a = 1.0f; + + // problema dell'infamous half-texel offset of D3D9 (corretto dalle D3D10 in poi) : + // http://msdn.microsoft.com/en-us/library/bb219690%28VS.85%29.aspx. + for (i = 0; i < 4; i++) { + shd->vb[i].x -= 0.5f; + shd->vb[i].y += 0.5f; + } + + IDirect3DVertexBuffer9_Lock(shd->quad, 0, 0, (void**) &buffer, 0); + memcpy(buffer, shd->vb, sizeof(shd->vb)); + IDirect3DVertexBuffer9_Unlock(shd->quad); + + D3DXMatrixOrthoOffCenterLH(&ortho, 0, vp->w, 0, vp->h, 0, 1); + D3DXMatrixIdentity(&rot); + D3DXMatrixRotationZ(&rot, rotation * (M_PI / 2.0)); + + D3DXMatrixMultiply(&proj, &ortho, &rot); + D3DXMatrixTranspose(&shd->mvp, &proj); +} +static CGparameter d3d9_cg_find_param(CGparameter prm, const char *name) { + UINT i; + static const char *illegal[] = { + "IN.", + "ORIG.", + "PASS", + "PREV.", + "PREV1.", "PREV2.", + "PREV3.", "PREV4.", + "PREV5.", "PREV6.", + }; + + for (; prm; prm = cgGetNextParameter(prm)) { + const char *semantic = NULL; + + if (cgGetParameterType(prm) == CG_STRUCT) { + CGparameter ret; + + if ((ret = d3d9_cg_find_param(cgGetFirstStructParameter(prm), name))) { + return (ret); + } + } + if (cgGetParameterDirection(prm) != CG_IN || cgGetParameterVariability(prm) != CG_VARYING) { + continue; + } + if (!(semantic = cgGetParameterSemantic(prm))) { + continue; + } + if (strcmp(name, semantic) == 0) { + const char *pname = cgGetParameterName(prm); + + if (!pname) { + return (NULL); + } + + for (i = 0; i < LENGTH(illegal); i++) { + if (strstr(pname, illegal[i]) == pname) { + return (NULL); + } + } + + return (prm); + } + } + return (NULL); +} +INLINE static void d3d9_viewport_set(DWORD x, DWORD y, DWORD w, DWORD h) { + static D3DVIEWPORT9 vp; + + vp.X = x; + vp.Y = y; + vp.Width = w; + vp.Height = h; + vp.MinZ = 0.0f; + vp.MaxZ = 1.0f; + IDirect3DDevice9_SetViewport(d3d9.adapter->dev, &vp); +} +INLINE D3DTEXTUREFILTERTYPE d3d9_shader_filter(UINT type) { + switch (type) { + case TEXTURE_LINEAR_ENAB: + return D3DTEXF_LINEAR; + case TEXTURE_LINEAR_DISAB: + return D3DTEXF_POINT; + default: + if (cfg->interpolation || gfx.PSS) { + return D3DTEXF_LINEAR; + } + return D3DTEXF_POINT; + } +} +INLINE static void d3d9_shader_params_text_set(_shader *shd) { + UINT i; + + if (shd->uni.mvp) { + // posso tranquillamente utilizzare l'mvp dell'ultimo pass + cgD3D9SetUniformMatrix(shd->uni.mvp, &shd->mvp); + } + + for (i = 0; i < 4; i++) { + IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, i, shd->quad, 0, sizeof(_vertex_buffer)); + } +} +INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount) { + const _shader *shd = &texture->shader; + UINT i, index; + + if (shd->uni.mvp) { + cgD3D9SetUniformMatrix(shd->uni.mvp, &shd->mvp); + } + + for (i = 0; i < 4; i++) { + IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, i, shd->quad, 0, sizeof(_vertex_buffer)); + } + + // IN + { + // IN.video_size + if (shd->uni.v.video_size) { + cgD3D9SetUniform(shd->uni.v.video_size, &shd->info.video_size); + } + if (shd->uni.f.video_size) { + cgD3D9SetUniform(shd->uni.f.video_size, &shd->info.video_size); + } + // IN.texture_size + if (shd->uni.v.texture_size) { + cgD3D9SetUniform(shd->uni.v.texture_size, &shd->info.texture_size); + } + if (shd->uni.f.texture_size) { + cgD3D9SetUniform(shd->uni.f.texture_size, &shd->info.texture_size); + } + // IN.output_size + if (shd->uni.v.output_size) { + cgD3D9SetUniform(shd->uni.v.output_size, &shd->info.output_size); + } + if (shd->uni.f.output_size) { + cgD3D9SetUniform(shd->uni.f.output_size, &shd->info.output_size); + } + // IN.frame_count + { + FLOAT fc = (FLOAT)fcount; + + if (fcountmod) { + fc = (FLOAT)(fcount % fcountmod); + } + + if (shd->uni.v.frame_count) { + cgD3D9SetUniform(shd->uni.v.frame_count, &fc); + } + if (shd->uni.f.frame_count) { + cgD3D9SetUniform(shd->uni.f.frame_count, &fc); + } + } + // IN.frame_direction + { + FLOAT frame_direction = -1; + + if (shd->uni.v.frame_direction) { + cgD3D9SetUniform(shd->uni.v.frame_direction, &frame_direction); + } + if (shd->uni.f.frame_direction) { + cgD3D9SetUniform(shd->uni.f.frame_direction, &frame_direction); + } + } + } + + // param + for (i = 0; i < shader_effect.params; i++) { + if (shd->uni.v.param[i]) { + cgD3D9SetUniform(shd->uni.v.param[i], &shader_effect.param[i].value); + } + if (shd->uni.f.param[i]) { + cgD3D9SetUniform(shd->uni.f.param[i], &shader_effect.param[i].value); + } + } + + // lut + for (i = 0; i < shader_effect.luts; i++) { + _lut *lut = &d3d9.lut[i]; + UINT bound_index = (UINT)-1; + + if (shd->uni.v.lut[i]) { + index = cgGetParameterResourceIndex(shd->uni.v.lut[i]); + bound_index = index; + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )lut->data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, lut->filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, lut->filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + } + if (shd->uni.f.lut[i]) { + index = cgGetParameterResourceIndex(shd->uni.f.lut[i]); + if (index == bound_index) { + continue; + } + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )lut->data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, lut->filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, lut->filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + } + } + + // ORIG + { + // ORIG.texture + if (shd->uni.orig.f.texture) { + index = cgGetParameterResourceIndex(shd->uni.orig.f.texture); + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )d3d9.screen.tex[d3d9.screen.index].data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, D3DTEXF_POINT); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + } + // ORIG.video_size + if (shd->uni.orig.v.video_size) { + cgD3D9SetUniform(shd->uni.orig.v.video_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.video_size); + } + if (shd->uni.orig.f.video_size) { + cgD3D9SetUniform(shd->uni.orig.f.video_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.video_size); + } + // ORIG.texture_size + if (shd->uni.orig.v.texture_size) { + cgD3D9SetUniform(shd->uni.orig.v.texture_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.texture_size); + } + if (shd->uni.orig.f.texture_size) { + cgD3D9SetUniform(shd->uni.orig.f.texture_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.texture_size); + } + // ORIG.tex_coord + if (shd->uni.orig.v.tex_coord) { + IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, + shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.orig.v.tex_coord)], + d3d9.screen.tex[d3d9.screen.index].shader.quad, 0, sizeof(_vertex_buffer)); + } + } + + // FEEDBACK + if (d3d9.feedback.in_use) { + // FEEDBACK.texture + if (shd->uni.feedback.f.texture) { + D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(shader_effect.sp[shader_effect.feedback_pass].linear); + + index = cgGetParameterResourceIndex(shd->uni.feedback.f.texture); + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )d3d9.feedback.tex.data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + } + // FEEDBACK.video_size + if (shd->uni.feedback.v.video_size) { + cgD3D9SetUniform(shd->uni.feedback.v.video_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.video_size); + } + if (shd->uni.feedback.f.video_size) { + cgD3D9SetUniform(shd->uni.feedback.f.video_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.video_size); + } + // FEEDBACK.texture_size + if (shd->uni.feedback.v.texture_size) { + cgD3D9SetUniform(shd->uni.feedback.v.texture_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.texture_size); + } + if (shd->uni.feedback.f.texture_size) { + cgD3D9SetUniform(shd->uni.feedback.f.texture_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.texture_size); + } + // FEEDBACK.tex_coord + if (shd->uni.feedback.v.tex_coord) { + IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, + shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.feedback.v.tex_coord)], + d3d9.texture[shader_effect.feedback_pass].shader.quad, 0, + sizeof(_vertex_buffer)); + } + } + + // PREV + { + INT circle_index = d3d9.screen.index - 1; + + for (i = 0; i < (d3d9.screen.in_use - 1); i++) { + if (circle_index < 0) { + circle_index = d3d9.screen.in_use - 1; + } + // PREV[x].texture + if (shd->uni.prev[i].f.texture) { + index = cgGetParameterResourceIndex(shd->uni.prev[i].f.texture); + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 *)d3d9.screen.tex[circle_index].data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, D3DTEXF_POINT); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, D3DTEXF_POINT); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + } + // PREV[x].tex_coord + if (shd->uni.prev[i].v.tex_coord) { + IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, + shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.prev[i].v.tex_coord)], + d3d9.screen.tex[circle_index].shader.quad, 0, sizeof(_vertex_buffer)); + } + circle_index--; + } + } + + // PASS + for (i = 0; i < shader_effect.running_pass; i++) { + UINT next = i + 1; + + // PASS[x].texture + if (shd->uni.passprev[i].f.texture) { + D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(shader_effect.sp[i].linear); + UINT resind = cgGetParameterResourceIndex(shd->uni.passprev[i].f.texture); + + IDirect3DDevice9_SetTexture(d3d9.adapter->dev, resind, (IDirect3DBaseTexture9 *)d3d9.texture[i].data); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_MAGFILTER, filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_MINFILTER, filter); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + } + // PASS[x].video_size + if (shd->uni.passprev[i].v.video_size) { + cgD3D9SetUniform(shd->uni.passprev[i].v.video_size, &d3d9.texture[next].shader.info.video_size); + } + if (shd->uni.passprev[i].f.video_size) { + cgD3D9SetUniform(shd->uni.passprev[i].f.video_size, &d3d9.texture[next].shader.info.video_size); + } + // PASS[x].texture_size + if (shd->uni.passprev[i].v.texture_size) { + cgD3D9SetUniform(shd->uni.passprev[i].v.texture_size, &d3d9.texture[next].shader.info.texture_size); + } + if (shd->uni.passprev[i].f.texture_size) { + cgD3D9SetUniform(shd->uni.passprev[i].f.texture_size, &d3d9.texture[next].shader.info.texture_size); + } + // PASS[x].tex_coord + if (shd->uni.passprev[i].v.tex_coord) { + IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, + shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.passprev[i].v.tex_coord)], + d3d9.texture[next].shader.quad, 0, sizeof(_vertex_buffer)); + } + } +} diff -upr --new-file puNES-0.105.org/src/video/d3d9/d3d9.h puNES-0.105.new/src/video/d3d9/d3d9.h --- puNES-0.105.org/src/video/d3d9/d3d9.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/d3d9/d3d9.h 2020-03-18 11:47:29.382142532 +0100 @@ -167,14 +167,14 @@ typedef struct _d3d9 { _lut lut[MAX_PASS]; } _d3d9; +extern _d3d9 d3d9; + #if defined (__cplusplus) #define EXTERNC extern "C" #else #define EXTERNC #endif -EXTERNC _d3d9 d3d9; - EXTERNC BYTE d3d9_init(void); EXTERNC BYTE d3d9_context_create(void); EXTERNC void d3d9_draw_scene(void); diff -upr --new-file puNES-0.105.org/src/video/d3d9/gfx.c puNES-0.105.new/src/video/d3d9/gfx.c --- puNES-0.105.org/src/video/d3d9/gfx.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/d3d9/gfx.c 2020-03-18 11:47:29.382142532 +0100 @@ -21,9 +21,7 @@ #include "d3d9.h" #include "video/gfx_thread.h" -#include "fps.h" #include "gui.h" -#include "info.h" #include "conf.h" #include "ppu.h" #include "clock.h" @@ -34,6 +32,8 @@ #include "video/effects/pause.h" #include "video/effects/tv_noise.h" +_gfx gfx; + BYTE gfx_init(void) { gfx.save_screenshot = FALSE; @@ -109,8 +109,7 @@ void gfx_quit(void) { d3d9_quit(); } -void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, - BYTE force_scale, BYTE force_palette) { +void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, BYTE force_scale, BYTE force_palette) { BYTE set_mode; WORD width, height; DBWORD old_shader = cfg->shader; diff -upr --new-file puNES-0.105.org/src/video/d3d9/gfx.c.orig puNES-0.105.new/src/video/d3d9/gfx.c.orig --- puNES-0.105.org/src/video/d3d9/gfx.c.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/video/d3d9/gfx.c.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,697 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * for some codes : + * Copyright (C) 2010-2015 The RetroArch team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "d3d9.h" +#include "video/gfx_thread.h" +#include "fps.h" +#include "gui.h" +#include "info.h" +#include "conf.h" +#include "ppu.h" +#include "clock.h" +#include "palette.h" +#include "paldef.h" +#include "vs_system.h" +#include "settings.h" +#include "video/effects/pause.h" +#include "video/effects/tv_noise.h" + +BYTE gfx_init(void) { + gfx.save_screenshot = FALSE; + + if (gui_create() == EXIT_ERROR) { + MessageBox(NULL, "Gui initialization failed", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + if (gfx_thread_init() == EXIT_ERROR) { + MessageBox(NULL, "Unable to allocate the gfx thread", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + if (d3d9_init() == EXIT_ERROR) { + MessageBox(NULL, "Unable to initiliazed d3d9", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + // inizializzo l'ntsc che utilizzero' non solo + // come filtro ma anche nel gfx_set_screen() per + // generare la paletta dei colori. + if (ntsc_init(0, 0, 0, 0, 0) == EXIT_ERROR) { + MessageBox(NULL, "Unable to initialize palette", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + // mi alloco una zona di memoria dove conservare la + // paletta nel formato di visualizzazione. + if (!(gfx.palette = malloc(NUM_COLORS * sizeof(uint32_t)))) { + MessageBox(NULL, "Unable to allocate the palette", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + if (pause_init() == EXIT_ERROR) { + MessageBox(NULL, "pause initialization failed", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + if (tv_noise_init() == EXIT_ERROR) { + MessageBox(NULL, "tv_noise initialization failed", "Error!", MB_ICONEXCLAMATION | MB_OK); + return (EXIT_ERROR); + } + + // casi particolari provenienti dal settings_file_parse() e cmd_line_parse() + if (cfg->fullscreen == FULLSCR) { + gfx.scale_before_fscreen = cfg->scale; + } + + if (cfg->fullscreen) { + gfx_set_screen(cfg->scale, cfg->filter, cfg->shader, NO_FULLSCR, cfg->palette, FALSE, FALSE); + cfg->fullscreen = NO_FULLSCR; + cfg->scale = gfx.scale_before_fscreen; + gui_fullscreen(); + } else { + gfx_set_screen(cfg->scale, cfg->filter, cfg->shader, NO_FULLSCR, cfg->palette, FALSE, FALSE); + } + + return (EXIT_OK); +} +void gfx_quit(void) { + gfx_thread_quit(); + + pause_quit(); + tv_noise_quit(); + + ntsc_quit(); + text_quit(); + + if (gfx.palette) { + free(gfx.palette); + gfx.palette = NULL; + } + + d3d9_quit(); +} +void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, + BYTE force_scale, BYTE force_palette) { + BYTE set_mode; + WORD width, height; + DBWORD old_shader = cfg->shader; + + gfx_thread_pause(); + + if (shader_effect.params > 0) { + settings_shp_save(); + } + + gfx_set_screen_start: + set_mode = FALSE; + width = 0, height = 0; + + // l'ordine dei vari controlli non deve essere cambiato: + // 0) overscan + // 1) filtro + // 2) fullscreen + // 3) fattore di scala + // 4) tipo di paletta + + // overscan + { + overscan.enabled = cfg->oscan; + + gfx.rows = SCR_ROWS; + gfx.lines = SCR_LINES; + + if (overscan.enabled == OSCAN_DEFAULT) { + overscan.enabled = cfg->oscan_default; + } + + if (overscan.enabled) { + gfx.rows -= (overscan.borders->left + overscan.borders->right); + gfx.lines -= (overscan.borders->up + overscan.borders->down); + } + } + + // filtro + if (filter == NO_CHANGE) { + filter = cfg->filter; + } + + if ((filter != cfg->filter) || info.on_cfg || force_scale) { + switch (filter) { + case NO_FILTER: + default: + gfx.filter.func = scale_surface; + gfx.filter.factor = X1; + break; + case SCALE2X: + case SCALE3X: + case SCALE4X: + gfx.filter.func = scaleNx; + gfx.filter.factor = filter + 1; + break; + case HQ2X: + case HQ3X: + case HQ4X: + gfx.filter.func = hqNx; + gfx.filter.factor = filter - 2; + break; + case XBRZ2X: + case XBRZ3X: + case XBRZ4X: + case XBRZ5X: + case XBRZ6X: + gfx.filter.func = xBRZ; + gfx.filter.factor = filter - 6; + break; + case XBRZ2XMT: + case XBRZ3XMT: + case XBRZ4XMT: + case XBRZ5XMT: + case XBRZ6XMT: + gfx.filter.func = xBRZ_mt; + gfx.filter.factor = filter - 11; + break; + case NTSC_FILTER: + gfx.filter.func = ntsc_surface; + gfx.filter.factor = X2; + break; + } + // forzo il controllo del fattore di scale + force_scale = TRUE; + // indico che devo cambiare il video mode + set_mode = TRUE; + } + + /* shader */ + if (shader == NO_CHANGE) { + shader = cfg->shader; + } + + // fullscreen + if (fullscreen == NO_CHANGE) { + fullscreen = cfg->fullscreen; + } + if ((fullscreen != cfg->fullscreen) || info.on_cfg) { + // forzo il controllo del fattore di scale + force_scale = TRUE; + // indico che devo cambiare il video mode + set_mode = TRUE; + } + + // fattore di scala + if (scale == NO_CHANGE) { + scale = cfg->scale; + } + if ((scale != cfg->scale) || info.on_cfg || force_scale) { + if (filter == NTSC_FILTER) { + width = gfx.w[PASS0] = gfx.w[NO_OVERSCAN] = NES_NTSC_OUT_WIDTH(SCR_ROWS); + gfx.filter.width_pixel = (float)nes_ntsc_out_chunk / (float)nes_ntsc_in_chunk; + if (overscan.enabled) { + width -= ((float)(overscan.borders->left + overscan.borders->right) * gfx.filter.width_pixel); + } + switch (scale) { + case X2: + gfx.width_pixel = gfx.filter.width_pixel; + break; + default: + width = ((float)width / 2.0f) * (float)scale; + gfx.w[NO_OVERSCAN] = ((float)gfx.w[NO_OVERSCAN] / 2.0f) * (float)scale; + gfx.width_pixel = (gfx.filter.width_pixel / 2.0f) * (float)scale; + break; + } + } else { + width = gfx.rows * scale; + gfx.w[NO_OVERSCAN] = SCR_ROWS * scale; + gfx.w[PASS0] = SCR_ROWS * gfx.filter.factor; + gfx.filter.width_pixel = gfx.filter.factor; + gfx.width_pixel = scale; + } + gfx.w[CURRENT] = width; + + height = gfx.lines * scale; + gfx.h[CURRENT] = height; + gfx.h[NO_OVERSCAN] = SCR_LINES * scale; + gfx.h[PASS0] = SCR_LINES * gfx.filter.factor; + + set_mode = TRUE; + } + + // paletta + if (palette == NO_CHANGE) { + palette = cfg->palette; + } + if ((palette != cfg->palette) || info.on_cfg || force_palette) { + if (palette == PALETTE_FILE) { + if (ustrlen(cfg->palette_file) != 0) { + if (palette_load_from_file(cfg->palette_file) == EXIT_ERROR) { + umemset(cfg->palette_file, 0x00, usizeof(cfg->palette_file)); + text_add_line_info(1, "[red]error on palette file"); + if (cfg->palette != PALETTE_FILE) { + palette = cfg->palette; + } else if (machine.type == NTSC) { + palette = PALETTE_NTSC; + } else { + palette = PALETTE_SONY; + } + } else { + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_base_file, 0, (BYTE *)palette_RGB.noswap); + } + } + } + + switch (palette) { + case PALETTE_PAL: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_base_pal, 0, (BYTE *)palette_RGB.noswap); + break; + case PALETTE_NTSC: + ntsc_set(NULL, cfg->ntsc_format, FALSE, 0, 0, (BYTE *)palette_RGB.noswap); + break; + case PALETTE_FRBX_NOSTALGIA: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_firebrandx_nostalgia_FBX, 0, (BYTE *)palette_RGB.noswap); + break; + case PALETTE_FRBX_YUV: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_firebrandx_YUV_v3, 0, (BYTE *)palette_RGB.noswap); + break; + case PALETTE_GREEN: + rgb_modifier(NULL, palette_RGB.noswap, 0x00, -0x20, 0x20, -0x20); + break; + case PALETTE_FILE: + break; + default: + ntsc_set(NULL, cfg->ntsc_format, palette, 0, 0, (BYTE *)palette_RGB.noswap); + break; + } + + if (vs_system.enabled) { + switch (vs_system.ppu) { + case RP2C03B: + case RP2C03G: + break; + case RP2C04: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0001, 0, (BYTE *)palette_RGB.noswap); + break; + case RP2C04_0002: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0002, 0, (BYTE *)palette_RGB.noswap); + break; + case RP2C04_0003: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0003, 0, (BYTE *)palette_RGB.noswap); + break; + case RP2C04_0004: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0004, 0, (BYTE *)palette_RGB.noswap); + break; + case RC2C03B: + case RC2C03C: + case RC2C05_01: + case RC2C05_02: + case RC2C05_03: + case RC2C05_04: + case RC2C05_05: + default: + break; + } + } + } + + gfx_palette_update(); + + // salvo il nuovo fattore di scala + cfg->scale = scale; + // salvo il nuovo filtro + cfg->filter = filter; + // salvo la nuova shader + cfg->shader = shader; + // salvo il nuovo stato del fullscreen + cfg->fullscreen = fullscreen; + // salvo il nuovo tipo di paletta + cfg->palette = palette; + + // Pixel Aspect Ratio + if (cfg->filter == NTSC_FILTER) { + gfx.pixel_aspect_ratio = 1.0f; + } else { + switch (cfg->pixel_aspect_ratio) { + default: + case PAR11: + gfx.pixel_aspect_ratio = 1.0f; + break; + case PAR54: + gfx.pixel_aspect_ratio = 5.0f / 4.0f; + break; + case PAR87: + gfx.pixel_aspect_ratio = 8.0f / 7.0f; + break; + case PAR118: + gfx.pixel_aspect_ratio = 2950000.0f / 2128137.0f; + break; + } + } + + { + gfx.PSS = ((cfg->pixel_aspect_ratio != PAR11) && cfg->PAR_soft_stretch) ? TRUE : FALSE; + + if (shaders_set(shader) == EXIT_ERROR) { + umemcpy(cfg->shader_file, gfx.last_shader_file, usizeof(cfg->shader_file)); + if (old_shader == shader) { + shader = NO_SHADER; + } else { + shader = old_shader; + } + goto gfx_set_screen_start; + } + + if (shader_effect.params > 0) { + settings_shp_parse(); + } + + if (set_mode) { + if (fullscreen == TRUE) { + gfx.w[VIDEO_MODE] = gfx.w[MONITOR]; + gfx.h[VIDEO_MODE] = gfx.h[MONITOR]; + } else if (cfg->oscan_black_borders) { + gfx.w[VIDEO_MODE] = gfx.w[NO_OVERSCAN]; + gfx.h[VIDEO_MODE] = gfx.h[NO_OVERSCAN]; + } else { + gfx.w[VIDEO_MODE] = width; + gfx.h[VIDEO_MODE] = height; + } + + // Pixel Aspect Ratio + if (cfg->pixel_aspect_ratio && !fullscreen) { + gfx.w[VIDEO_MODE] = (gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio); + + if (overscan.enabled && !cfg->oscan_black_borders) { + float brd = 0; + + brd = (float)gfx.w[VIDEO_MODE] / (float)SCR_ROWS; + brd *= (overscan.borders->right + overscan.borders->left); + + gfx.w[VIDEO_MODE] -= brd; + } + } + + // faccio quello che serve prima del setvideo + gui_set_video_mode(); + } + + switch (d3d9_context_create()) { + case EXIT_ERROR: + fprintf(stderr, "D3D9: Unable to initialize d3d context\n"); + gfx_thread_continue(); + return; + case EXIT_ERROR_SHADER: + text_add_line_info(1, "[red]errors[normal] on shader, use [green]'No shader'"); + fprintf(stderr, "CG: Error on loading the shaders, switch to \"No shader\"\n"); + umemcpy(cfg->shader_file, gfx.last_shader_file, usizeof(cfg->shader_file)); + shader = NO_SHADER; + goto gfx_set_screen_start; + } + } + + // calcolo le proporzioni tra il disegnato a video (overscan e schermo + // con le dimensioni per il filtro NTSC compresi) e quello che dovrebbe + // essere (256 x 240). Mi serve per calcolarmi la posizione del puntatore + // dello zapper. + if (cfg->fullscreen) { + gfx.w_pr = (float)gfx.vp.w / (float)SCR_ROWS; + gfx.h_pr = (float)gfx.vp.h / (float)SCR_LINES; + } else { + gfx.w_pr = (float)(gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio) / (float)SCR_ROWS; + gfx.h_pr = (float)gfx.h[NO_OVERSCAN] / (float)SCR_LINES; + } + + gfx_thread_continue(); + + // setto il titolo della finestra + gui_update(); + + if (info.on_cfg == TRUE) { + info.on_cfg = FALSE; + } +} +void gfx_draw_screen(void) { + if (gfx_thread_public.filtering == TRUE) { + fps.frames_skipped++; + return; + } + + screen.rd = screen.wr; + + if (info.doublebuffer == TRUE) { + screen.index = !screen.index; + screen.last_completed_wr = screen.wr; + screen.wr = &screen.buff[screen.index]; + } else { + screen.rd = screen.wr = screen.last_completed_wr; + } + + if (screen.rd->ready == FALSE) { + screen.rd->ready = TRUE; + } +} + +void gfx_control_changed_adapter(void *monitor) { + _d3d9_adapter *old_adapter = d3d9.adapter; + HMONITOR *in_use = monitor; + unsigned int i; + + if ((*in_use) == IDirect3D9_GetAdapterMonitor(d3d9.d3d, d3d9.adapter->id)) { + return; + } + + for (i = 0; i < d3d9.adapters_in_use; i++) { + _d3d9_adapter *adapter = D3D9_ADAPTER(i); + + if ((*in_use) == IDirect3D9_GetAdapterMonitor(d3d9.d3d, adapter->id)) { + d3d9.adapter = adapter; + if (d3d9_context_create() == EXIT_OK) { + return; + } + fprintf(stderr, "D3D9 : Unable to initialize new d3d context\n"); + + d3d9.adapter = old_adapter; + if (d3d9_context_create() == EXIT_OK) { + return; + } + fprintf(stderr, "D3D9 : Unable to initialize old d3d context\n"); + break; + } + } +} + +uint32_t gfx_color(BYTE a, BYTE r, BYTE g, BYTE b) { + return (D3DCOLOR_ARGB(a, r, g, b)); +} +void gfx_palette_update(void) { + WORD i; + + if ((cfg->disable_swap_emphasis_pal == FALSE) && ((machine.type == PAL) || (machine.type == DENDY))) { + palette_RGB.in_use = &palette_RGB.swapped[0]; + } else { + palette_RGB.in_use = &palette_RGB.noswap[0]; + } + + // inizializzo in ogni caso la tabella YUV dell'hqx + hqx_init(); + + // memorizzo i colori della paletta nel formato di visualizzazione + for (i = 0; i < NUM_COLORS; i++) { + gfx.palette[i] = gfx_os_color(palette_RGB.in_use[i].r, palette_RGB.in_use[i].g, palette_RGB.in_use[i].b); + } +} + +void gfx_cursor_init(void) { + gui_cursor_init(); + gui_cursor_set(); +}; +void gfx_cursor_set(void) { + gui_cursor_set(); +}; + +void gfx_text_create_surface(_txt_element *ele) { + size_t size = (ele->h * ele->w) * (gfx.bit_per_pixel / 8); + + ele->surface = malloc(size); + memset(ele->surface, 0x00, size); +} +void gfx_text_release_surface(_txt_element *ele) { + if (ele->surface) { + free(ele->surface); + ele->surface = NULL; + } +} +void gfx_text_rect_fill(_txt_element *ele, _txt_rect *rect, uint32_t color) { + uint32_t *pbits; + LONG pitch; + int w, h; + + pitch = ele->w; + pbits = (uint32_t *)ele->surface; + pbits += (rect->y * ele->w) + rect->x; + + for (h = 0; h < rect->h; h++) { + for (w = 0; w < rect->w; w++) { + (*(pbits + w)) = color; + } + pbits += pitch; + } +} +void gfx_text_reset(void) { + txt_table[TXT_NORMAL] = D3DCOLOR_ARGB(0, 0xFF, 0xFF, 0xFF); + txt_table[TXT_RED] = D3DCOLOR_ARGB(0, 0xFF, 0x4C, 0x3E); + txt_table[TXT_YELLOW] = D3DCOLOR_ARGB(0, 0xFF, 0xFF, 0 ); + txt_table[TXT_GREEN] = D3DCOLOR_ARGB(0, 0 , 0xFF, 0 ); + txt_table[TXT_CYAN] = D3DCOLOR_ARGB(0, 0 , 0xFF, 0xFF); + txt_table[TXT_BROWN] = D3DCOLOR_ARGB(0, 0xEB, 0x89, 0x31); + txt_table[TXT_BLUE] = D3DCOLOR_ARGB(0, 0x2D, 0x8D, 0xBD); + txt_table[TXT_GRAY] = D3DCOLOR_ARGB(0, 0xA0, 0xA0, 0xA0); + txt_table[TXT_BLACK] = D3DCOLOR_ARGB(0, 0 , 0 , 0 ); +} +void gfx_text_clear(_txt_element *ele) { + D3DLOCKED_RECT lock_dst; + RECT dst; + uint32_t *pbits; + int w, h, x, y; + + if (!d3d9.text.data) { + return; + } + + text_calculate_real_x_y(ele, &x, &y); + + dst.left = x; + dst.top = y; + dst.right = x + ele->w; + dst.bottom = y + ele->h; + + if (IDirect3DSurface9_LockRect(d3d9.text.offscreen, &lock_dst, &dst, D3DLOCK_DISCARD) != D3D_OK) { + printf("D3D9 : LockRect text surface error\n"); + return; + } + + pbits = (uint32_t *)lock_dst.pBits; + + for (h = 0; h < ele->h; h++) { + for (w = 0; w < ele->w; w++) { + (*(pbits + w)) = 0; + } + pbits += lock_dst.Pitch / (gfx.bit_per_pixel / 8); + } + + IDirect3DSurface9_UnlockRect(d3d9.text.offscreen); +} +void gfx_text_blit(_txt_element *ele, _txt_rect *rect) { + D3DLOCKED_RECT lock_dst; + RECT dst; + LONG pitch; + unsigned char *psrc, *pdst; + int h; + + if (!cfg->txt_on_screen) { + return; + } + + dst.left = rect->x; + dst.top = rect->y; + dst.right = rect->x + rect->w; + dst.bottom = rect->y + rect->h; + + if (IDirect3DSurface9_LockRect(d3d9.text.offscreen, &lock_dst, &dst, D3DLOCK_DISCARD) != D3D_OK) { + printf("D3D9 : LockRect text surface error\n"); + return; + } + + pitch = rect->w * (gfx.bit_per_pixel / 8); + psrc = (unsigned char *)ele->surface; + pdst = (unsigned char *)lock_dst.pBits; + + for (h = 0; h < rect->h; h++) { + memcpy(pdst, psrc, pitch); + psrc += pitch; + pdst += lock_dst.Pitch; + } + + IDirect3DSurface9_UnlockRect(d3d9.text.offscreen); +} + +void gfx_apply_filter(void) { + gfx.filter.data.palette = (void *)gfx.palette; + + //applico la paletta adeguata. + if (cfg->filter == NTSC_FILTER) { + gfx.filter.data.palette = NULL; + } + if (info.no_rom | info.turn_off) { + if (cfg->filter == NTSC_FILTER) { + gfx.filter.data.palette = turn_off_effect.ntsc; + } else { + gfx.filter.data.palette = (void *)turn_off_effect.palette; + } + } else if (info.pause) { + if (!cfg->disable_sepia_color) { + if (cfg->filter == NTSC_FILTER) { + gfx.filter.data.palette = pause_effect.ntsc; + } else { + gfx.filter.data.palette = pause_effect.palette; + } + } + } + + gfx_thread_lock(); + + { + const _texture_simple *scrtex = &d3d9.screen.tex[d3d9.screen.index]; + D3DLOCKED_RECT lrect; + + // lock della surface in memoria + IDirect3DSurface9_LockRect(scrtex->offscreen, &lrect, NULL, D3DLOCK_DISCARD); + // applico l'effetto + gfx.filter.data.pitch = lrect.Pitch; + gfx.filter.data.pix = lrect.pBits; + gfx.filter.data.width = scrtex->rect.base.w; + gfx.filter.data.height = scrtex->rect.base.h; + gfx.filter.func(); + // unlock della surface in memoria + IDirect3DSurface9_UnlockRect(scrtex->offscreen); + + // aggiorno la texture dello schermo + if (overscan.enabled) { + POINT point; + RECT rect; + + rect.left = overscan.borders->left * gfx.filter.width_pixel; + rect.top = overscan.borders->up * gfx.filter.factor; + rect.right = scrtex->rect.base.w - (overscan.borders->right * gfx.filter.width_pixel); + rect.bottom = scrtex->rect.base.h - (overscan.borders->down * gfx.filter.factor); + + point.x = rect.left; + point.y = rect.top; + + IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, scrtex->offscreen, &rect, scrtex->map0, &point); + } else { + IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, scrtex->offscreen, NULL, scrtex->map0, NULL); + } + } + + gfx_thread_unlock(); + gui_screen_update(); + + return; +} diff -upr --new-file puNES-0.105.org/src/video/effects/pause.c puNES-0.105.new/src/video/effects/pause.c --- puNES-0.105.org/src/video/effects/pause.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/effects/pause.c 2020-03-18 11:47:29.382142532 +0100 @@ -21,7 +21,9 @@ #include "pause.h" #include "conf.h" #include "video/gfx.h" -#include "video/filters/ntsc.h" +#include "palette.h" + +_pause_effect pause_effect; BYTE pause_init(void) { uint32_t *palette; diff -upr --new-file puNES-0.105.org/src/video/effects/pause.h puNES-0.105.new/src/video/effects/pause.h --- puNES-0.105.org/src/video/effects/pause.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/effects/pause.h 2020-03-18 11:47:29.382142532 +0100 @@ -21,17 +21,19 @@ #include "common.h" +typedef struct _pause_effect { + void *palette; + void *ntsc; +} _pause_effect; + +extern _pause_effect pause_effect; + #if defined (__cplusplus) #define EXTERNC extern "C" #else #define EXTERNC #endif -EXTERNC struct _pause_effect { - void *palette; - void *ntsc; -} pause_effect; - EXTERNC BYTE pause_init(void); EXTERNC void pause_quit(void); diff -upr --new-file puNES-0.105.org/src/video/effects/tv_noise.c puNES-0.105.new/src/video/effects/tv_noise.c --- puNES-0.105.org/src/video/effects/tv_noise.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/effects/tv_noise.c 2020-03-18 11:47:29.382142532 +0100 @@ -23,7 +23,9 @@ #include "conf.h" #include "video/gfx.h" #include "emu.h" -#include "video/filters/ntsc.h" +#include "palette.h" + +_turn_off_effect turn_off_effect; BYTE tv_noise_init(void) { uint32_t *palette; diff -upr --new-file puNES-0.105.org/src/video/effects/tv_noise.h puNES-0.105.new/src/video/effects/tv_noise.h --- puNES-0.105.org/src/video/effects/tv_noise.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/effects/tv_noise.h 2020-03-18 11:47:29.382142532 +0100 @@ -21,17 +21,19 @@ #include "common.h" +typedef struct _turn_off_effect { + void *palette; + void *ntsc; +} _turn_off_effect; + +extern _turn_off_effect turn_off_effect; + #if defined (__cplusplus) #define EXTERNC extern "C" #else #define EXTERNC #endif -EXTERNC struct _turn_off_effect { - void *palette; - void *ntsc; -} turn_off_effect; - EXTERNC BYTE tv_noise_init(void); EXTERNC void tv_noise_quit(void); EXTERNC void tv_noise_effect(void); diff -upr --new-file puNES-0.105.org/src/video/filters/hq2x.c puNES-0.105.new/src/video/filters/hq2x.c --- puNES-0.105.org/src/video/filters/hq2x.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/hq2x.c 2020-03-18 11:47:29.382142532 +0100 @@ -19,6 +19,7 @@ */ #include "video/filters/hqx.h" +#include "palette.h" #define _HQ2X_ #include "video/filters/hqx_inline.h" #undef _HQ2X_ diff -upr --new-file puNES-0.105.org/src/video/filters/hq3x.c puNES-0.105.new/src/video/filters/hq3x.c --- puNES-0.105.org/src/video/filters/hq3x.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/hq3x.c 2020-03-18 11:47:29.382142532 +0100 @@ -19,6 +19,7 @@ */ #include "video/filters/hqx.h" +#include "palette.h" #define _HQ3X_ #include "video/filters/hqx_inline.h" #undef _HQ3X_ diff -upr --new-file puNES-0.105.org/src/video/filters/hq4x.c puNES-0.105.new/src/video/filters/hq4x.c --- puNES-0.105.org/src/video/filters/hq4x.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/hq4x.c 2020-03-18 11:47:29.382142532 +0100 @@ -19,6 +19,7 @@ */ #include "video/filters/hqx.h" +#include "palette.h" #define _HQ4X_ #include "video/filters/hqx_inline.h" #undef _HQ4X_ diff -upr --new-file puNES-0.105.org/src/video/filters/hqx.c puNES-0.105.new/src/video/filters/hqx.c --- puNES-0.105.org/src/video/filters/hqx.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/hqx.c 2020-03-18 11:47:29.382142532 +0100 @@ -16,12 +16,15 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "video/filters/hqx.h" +#include "video/gfx.h" +#include "palette.h" #include "ppu.h" uint32_t RGBtoYUV[NUM_COLORS]; uint32_t YUV1, YUV2; +_hqnx hqnx; + void hqx_init(void) { /* Initalize RGB to YUV lookup table */ uint32_t i, r, g, b, y, u, v; diff -upr --new-file puNES-0.105.org/src/video/filters/hqx.h puNES-0.105.new/src/video/filters/hqx.h --- puNES-0.105.org/src/video/filters/hqx.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/hqx.h 2020-03-18 11:47:29.383142523 +0100 @@ -23,23 +23,23 @@ #define __HQX_H_ #include "common.h" -#include "video/gfx.h" -#include "palette.h" -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _hqx { +typedef struct _hqnx { WORD sx; WORD sy; WORD startx; WORD rows; WORD lines; WORD dst_rows; -} hqnx; +} _hqnx; + +extern _hqnx hqnx; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC void hqx_init(void); EXTERNC void hqNx(void); diff -upr --new-file puNES-0.105.org/src/video/filters/nes_ntsc.c puNES-0.105.new/src/video/filters/nes_ntsc.c --- puNES-0.105.org/src/video/filters/nes_ntsc.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/nes_ntsc.c 2020-03-18 11:47:29.383142523 +0100 @@ -1,6 +1,5 @@ /* nes_ntsc 0.2.2. http://www.slack.net/~ant/ */ -#include "video/filters/nes_ntsc.h" #include "video/gfx.h" #include "conf.h" #include "clock.h" diff -upr --new-file puNES-0.105.org/src/video/filters/ntsc.c puNES-0.105.new/src/video/filters/ntsc.c --- puNES-0.105.org/src/video/filters/ntsc.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/ntsc.c 2020-03-18 11:47:29.383142523 +0100 @@ -18,9 +18,10 @@ #include #include -#include "video/filters/ntsc.h" +#include "video/gfx.h" #include "ppu.h" #include "overscan.h" +#include "palette.h" nes_ntsc_t *ntsc; nes_ntsc_setup_t format[3]; diff -upr --new-file puNES-0.105.org/src/video/filters/ntsc.h puNES-0.105.new/src/video/filters/ntsc.h --- puNES-0.105.org/src/video/filters/ntsc.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/ntsc.h 2020-03-18 11:47:29.383142523 +0100 @@ -21,8 +21,6 @@ #include "video/filters/nes_ntsc.h" #include "common.h" -#include "video/gfx.h" -#include "palette.h" enum ntsc_mode { COMPOSITE, SVIDEO, RGBMODE }; diff -upr --new-file puNES-0.105.org/src/video/filters/scale2x.c puNES-0.105.new/src/video/filters/scale2x.c --- puNES-0.105.org/src/video/filters/scale2x.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/scale2x.c 2020-03-18 11:47:29.383142523 +0100 @@ -18,7 +18,7 @@ #include #include -#include "video/filters/scale2x.h" +#include "video/gfx.h" #include "ppu.h" #define MAX(a, b) (((a) > (b)) ? (a) : (b)) diff -upr --new-file puNES-0.105.org/src/video/filters/scale2x.h puNES-0.105.new/src/video/filters/scale2x.h --- puNES-0.105.org/src/video/filters/scale2x.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/scale2x.h 2020-03-18 11:47:29.383142523 +0100 @@ -20,8 +20,6 @@ #define SCALE2X_H_ #include "common.h" -#include "video/gfx.h" -#include "palette.h" void scaleNx(void); diff -upr --new-file puNES-0.105.org/src/video/filters/scale.c puNES-0.105.new/src/video/filters/scale.c --- puNES-0.105.org/src/video/filters/scale.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/scale.c 2020-03-18 11:47:29.383142523 +0100 @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "video/filters/scale.h" +#include "video/gfx.h" #include "ppu.h" #define put_pixel(type, p0, p1)\ diff -upr --new-file puNES-0.105.org/src/video/filters/scale.h puNES-0.105.new/src/video/filters/scale.h --- puNES-0.105.org/src/video/filters/scale.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/scale.h 2020-03-18 11:47:29.383142523 +0100 @@ -20,8 +20,6 @@ #define SCALE_H_ #include "common.h" -#include "video/gfx.h" -#include "palette.h" void scale_surface(void); diff -upr --new-file puNES-0.105.org/src/video/filters/xBRZ.c puNES-0.105.new/src/video/filters/xBRZ.c --- puNES-0.105.org/src/video/filters/xBRZ.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/xBRZ.c 2020-03-18 11:47:29.383142523 +0100 @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "video/filters/xBRZ.h" +#include "video/gfx.h" #include "ppu.h" void xBRZ_init(void) {} diff -upr --new-file puNES-0.105.org/src/video/filters/xBRZ.h puNES-0.105.new/src/video/filters/xBRZ.h --- puNES-0.105.org/src/video/filters/xBRZ.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/filters/xBRZ.h 2020-03-18 11:47:29.383142523 +0100 @@ -20,7 +20,10 @@ #define XBRZ_H_ #include "common.h" -#include "video/gfx.h" + +void xBRZ_init(void); +void xBRZ(void); +void xBRZ_mt(void); #if defined (__cplusplus) #define EXTERNC extern "C" @@ -28,10 +31,6 @@ #define EXTERNC #endif -void xBRZ_init(void); -void xBRZ(void); -void xBRZ_mt(void); - EXTERNC void xbrz_scale(BYTE factor, const WORD *src, uint32_t *trg, uint32_t *palette, int width, int height); EXTERNC void xbrz_scale_mt(BYTE factor, const WORD *src, uint32_t *trg, uint32_t *palette, int width, int height); diff -upr --new-file puNES-0.105.org/src/video/gfx.h puNES-0.105.new/src/video/gfx.h --- puNES-0.105.org/src/video/gfx.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/gfx.h 2020-03-18 11:47:29.383142523 +0100 @@ -98,14 +98,7 @@ typedef struct _viewport { int x, y; int w, h; } _viewport; - -#if defined (__cplusplus) -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -EXTERNC struct _gfx { +typedef struct _gfx { BYTE PSS; BYTE save_screenshot; BYTE scale_before_fscreen; @@ -134,12 +127,19 @@ EXTERNC struct _gfx { WORD height; } data; } filter; -} gfx; +} _gfx; + +extern _gfx gfx; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif EXTERNC BYTE gfx_init(void); EXTERNC void gfx_quit(void); -EXTERNC void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, - BYTE force_scale, BYTE force_palette); +EXTERNC void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, BYTE force_scale, BYTE force_palette); EXTERNC void gfx_draw_screen(void); #if defined (WITH_D3D9) diff -upr --new-file puNES-0.105.org/src/video/gfx.h.orig puNES-0.105.new/src/video/gfx.h.orig --- puNES-0.105.org/src/video/gfx.h.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/video/gfx.h.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef GFX_H_ +#define GFX_H_ + +#include "common.h" +#include "text.h" +#include "video/filters/scale.h" +#include "video/filters/scale2x.h" +#include "video/filters/hqx.h" +#include "video/filters/ntsc.h" +#include "video/filters/xBRZ.h" + +#define FH_SHADERS_GEST +#define change_color(plt, blck, index, color, operation)\ + tmp = plt[index].color + operation;\ + plt[index].color = (tmp < 0 ? blck : (tmp > 0xFF ? 0xFF : tmp)) +#define rgb_modifier(ntscin, plt, blck, red, green, blue)\ + /* prima ottengo la paletta monocromatica */\ + ntsc_set(ntscin, cfg->ntsc_format, PALETTE_MONO, 0, 0, (BYTE *)plt);\ + /* quindi la modifico */\ + {\ + WORD i;\ + SWORD tmp;\ + for (i = 0; i < NUM_COLORS; i++) {\ + /* rosso */\ + change_color(plt, blck, i, r, red);\ + /* green */\ + change_color(plt, blck, i, g, green);\ + /* blue */\ + change_color(plt, blck, i, b, blue);\ + }\ + }\ + /* ed infine utilizzo la nuova */\ + ntsc_set(ntscin, cfg->ntsc_format, FALSE, 0, (BYTE *)plt,(BYTE *)plt) +#if defined (__unix__) +#define gfx_os_color(r, g, b) gfx_color(0, r, g, b); +#else +#define gfx_os_color(r, g, b) gfx_color(255, r, g, b); +#endif + +enum fullscreen_type { NO_FULLSCR, FULLSCR, FULLSCR_IN_WINDOW }; +enum scale_type { X1 = 1, X2, X3, X4, X5, X6 }; +enum par_type { PAR11, PAR54, PAR87, PAR118 }; +enum filters_type { + NO_FILTER, + SCALE2X, + SCALE3X, + SCALE4X, + HQ2X, + HQ3X, + HQ4X, + NTSC_FILTER, + XBRZ2X, + XBRZ3X, + XBRZ4X, + XBRZ5X, + XBRZ6X, + XBRZ2XMT, + XBRZ3XMT, + XBRZ4XMT, + XBRZ5XMT, + XBRZ6XMT +}; +enum shader_type { + NO_SHADER, + SHADER_CRTDOTMASK, + SHADER_CRTSCANLINES, + SHADER_CRTWITHCURVE, + SHADER_EMBOSS, + SHADER_NOISE, + SHADER_NTSC2PHASECOMPOSITE, + SHADER_OLDTV, + SHADER_FILE, + SHADER_LAST = SHADER_FILE, +}; +enum overcan_type { OSCAN_OFF, OSCAN_ON, OSCAN_DEFAULT }; +enum gfx_info_type { CURRENT, NO_OVERSCAN, MONITOR, VIDEO_MODE, PASS0 }; +enum no_change { NO_CHANGE = 255 }; + +typedef struct _viewport { + int x, y; + int w, h; +} _viewport; + +#if defined (__cplusplus) +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + +EXTERNC struct _gfx { + BYTE PSS; + BYTE save_screenshot; + BYTE scale_before_fscreen; + BYTE type_of_fscreen_in_use; + BYTE bit_per_pixel; + float width_pixel; + WORD rows, lines; + SDBWORD w[5], h[5]; + float w_pr, h_pr; + float pixel_aspect_ratio; + float device_pixel_ratio; + uint32_t *palette; + uTCHAR last_shader_file[LENGTH_FILE_NAME_LONG]; + _viewport vp; + struct _gfx_filter { + void (*func)(void); + + float width_pixel; + BYTE factor; + + struct _gfx_filter_data { + void *palette; + uint32_t pitch; + void *pix; + WORD width; + WORD height; + } data; + } filter; +} gfx; + +EXTERNC BYTE gfx_init(void); +EXTERNC void gfx_quit(void); +EXTERNC void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, + BYTE force_scale, BYTE force_palette); +EXTERNC void gfx_draw_screen(void); + +#if defined (WITH_D3D9) +EXTERNC void gfx_control_changed_adapter(void *monitor); +#endif + +EXTERNC uint32_t gfx_color(BYTE alpha, BYTE r, BYTE g, BYTE b); +EXTERNC void gfx_palette_update(void); + +EXTERNC void gfx_cursor_init(void); +EXTERNC void gfx_cursor_set(void); + +EXTERNC void gfx_text_create_surface(_txt_element *ele); +EXTERNC void gfx_text_release_surface(_txt_element *ele); +EXTERNC void gfx_text_rect_fill(_txt_element *ele, _txt_rect *rect, uint32_t color); +EXTERNC void gfx_text_reset(void); +EXTERNC void gfx_text_clear(_txt_element *ele); +EXTERNC void gfx_text_blit(_txt_element *ele, _txt_rect *rect); + +EXTERNC void gfx_apply_filter(void); + +#undef EXTERNC + +#endif /* GFX_H_ */ diff -upr --new-file puNES-0.105.org/src/video/gfx_thread.c puNES-0.105.new/src/video/gfx_thread.c --- puNES-0.105.org/src/video/gfx_thread.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/gfx_thread.c 2020-03-18 11:47:29.383142523 +0100 @@ -54,6 +54,8 @@ struct _gfx_thread { int pause_calls; } gfx_thread; +_gfx_thread_public gfx_thread_public; + BYTE gfx_thread_init(void) { memset(&gfx_thread_public, 0x00, sizeof(gfx_thread_public)); memset(&gfx_thread, 0x00, sizeof(gfx_thread)); diff -upr --new-file puNES-0.105.org/src/video/gfx_thread.h puNES-0.105.new/src/video/gfx_thread.h --- puNES-0.105.org/src/video/gfx_thread.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/gfx_thread.h 2020-03-18 11:47:29.383142523 +0100 @@ -21,16 +21,18 @@ #include "common.h" +typedef struct _gfx_thread_public { + BYTE filtering; +} _gfx_thread_public; + +extern _gfx_thread_public gfx_thread_public; + #if defined (__cplusplus) #define EXTERNC extern "C" #else #define EXTERNC #endif -EXTERNC struct _gfx_thread_public { - BYTE filtering; -} gfx_thread_public; - EXTERNC BYTE gfx_thread_init(void); EXTERNC void gfx_thread_quit(void); diff -upr --new-file puNES-0.105.org/src/video/opengl/gfx.c puNES-0.105.new/src/video/opengl/gfx.c --- puNES-0.105.org/src/video/opengl/gfx.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/opengl/gfx.c 2020-03-18 11:47:29.383142523 +0100 @@ -22,12 +22,10 @@ #include #include #include -#include "video/gfx.h" +#include "opengl.h" #include "video/gfx_thread.h" -#include "fps.h" #include "info.h" #include "conf.h" -#include "opengl.h" #include "clock.h" #include "ppu.h" #include "gui.h" @@ -38,6 +36,8 @@ #include "video/effects/pause.h" #include "video/effects/tv_noise.h" +_gfx gfx; + BYTE gfx_init(void) { gfx.save_screenshot = FALSE; @@ -113,8 +113,7 @@ void gfx_quit(void) { ntsc_quit(); text_quit(); } -void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, - BYTE force_scale, BYTE force_palette) { +void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, BYTE force_scale, BYTE force_palette) { BYTE set_mode; WORD width, height; DBWORD old_shader = cfg->shader; diff -upr --new-file puNES-0.105.org/src/video/opengl/gfx.c.orig puNES-0.105.new/src/video/opengl/gfx.c.orig --- puNES-0.105.org/src/video/opengl/gfx.c.orig 1970-01-01 01:00:00.000000000 +0100 +++ puNES-0.105.new/src/video/opengl/gfx.c.orig 2019-07-30 12:43:09.000000000 +0200 @@ -0,0 +1,605 @@ +/* + * Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#if defined (__unix__) +#include +#endif +#include +#include +#include +#include "video/gfx.h" +#include "video/gfx_thread.h" +#include "fps.h" +#include "info.h" +#include "conf.h" +#include "opengl.h" +#include "clock.h" +#include "ppu.h" +#include "gui.h" +#include "palette.h" +#include "paldef.h" +#include "vs_system.h" +#include "settings.h" +#include "video/effects/pause.h" +#include "video/effects/tv_noise.h" + +BYTE gfx_init(void) { + gfx.save_screenshot = FALSE; + + gui_screen_info(); + + if (gui_create() == EXIT_ERROR) { + fprintf(stderr, "gui initialization failed\n"); + return (EXIT_ERROR); + } + + if (gfx_thread_init() == EXIT_ERROR) { + fprintf(stderr, "Unable to allocate the gfx thread\n"); + return (EXIT_ERROR); + } + + if (opengl_init() == EXIT_ERROR) { + fprintf(stderr, "OpenGL not supported.\n"); + return (EXIT_ERROR); + } + + // inizializzo l'ntsc che utilizzero' non solo + // come filtro ma anche nel gfx_set_screen() per + // generare la paletta dei colori. + if (ntsc_init(0, 0, 0, 0, 0) == EXIT_ERROR) { + return (EXIT_ERROR); + } + + // mi alloco una zona di memoria dove conservare la + // paletta nel formato di visualizzazione. + if (!(gfx.palette = (uint32_t *) malloc(NUM_COLORS * sizeof(uint32_t)))) { + fprintf(stderr, "Unable to allocate the palette\n"); + return (EXIT_ERROR); + } + + if (pause_init() == EXIT_ERROR) { + fprintf(stderr, "pause initialization failed\n"); + return (EXIT_ERROR); + } + + if (tv_noise_init() == EXIT_ERROR) { + fprintf(stderr, "tv_noise initialization failed\n"); + return (EXIT_ERROR); + } + + // casi particolari provenienti dal settings_file_parse() e cmd_line_parse() + if (cfg->fullscreen == FULLSCR) { + gfx.scale_before_fscreen = cfg->scale; + } + + if (cfg->fullscreen) { + gfx_set_screen(cfg->scale, cfg->filter, cfg->shader, NO_FULLSCR, cfg->palette, FALSE, FALSE); + cfg->fullscreen = NO_FULLSCR; + cfg->scale = gfx.scale_before_fscreen; + gui_fullscreen(); + } else { + gfx_set_screen(cfg->scale, cfg->filter, cfg->shader, NO_FULLSCR, cfg->palette, FALSE, FALSE); + } + + return (EXIT_OK); +} +void gfx_quit(void) { + gfx_thread_quit(); + + if (gfx.palette) { + free(gfx.palette); + gfx.palette = NULL; + } + + pause_quit(); + tv_noise_quit(); + + opengl_quit(); + ntsc_quit(); + text_quit(); +} +void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, + BYTE force_scale, BYTE force_palette) { + BYTE set_mode; + WORD width, height; + DBWORD old_shader = cfg->shader; + + gfx_thread_pause(); + + if (shader_effect.params > 0) { + settings_shp_save(); + } + + gfx_set_screen_start: + set_mode = FALSE; + width = 0, height = 0; + + // l'ordine dei vari controlli non deve essere cambiato: + // 0) overscan + // 1) filtro + // 2) fullscreen + // 3) fattore di scala + // 4) tipo di paletta + + // overscan + { + overscan.enabled = cfg->oscan; + + gfx.rows = SCR_ROWS; + gfx.lines = SCR_LINES; + + if (overscan.enabled == OSCAN_DEFAULT) { + overscan.enabled = cfg->oscan_default; + } + if (overscan.enabled) { + gfx.rows -= (overscan.borders->left + overscan.borders->right); + gfx.lines -= (overscan.borders->up + overscan.borders->down); + } + } + + // filtro + if (filter == NO_CHANGE) { + filter = cfg->filter; + } + if ((filter != cfg->filter) || info.on_cfg || force_scale) { + switch (filter) { + default: + case NO_FILTER: + gfx.filter.func = scale_surface; + gfx.filter.factor = X1; + break; + case SCALE2X: + case SCALE3X: + case SCALE4X: + gfx.filter.func = scaleNx; + gfx.filter.factor = filter + 1; + break; + case HQ2X: + case HQ3X: + case HQ4X: + gfx.filter.func = hqNx; + gfx.filter.factor = filter - 2; + break; + case XBRZ2X: + case XBRZ3X: + case XBRZ4X: + case XBRZ5X: + case XBRZ6X: + gfx.filter.func = xBRZ; + gfx.filter.factor = filter - 6; + break; + case XBRZ2XMT: + case XBRZ3XMT: + case XBRZ4XMT: + case XBRZ5XMT: + case XBRZ6XMT: + gfx.filter.func = xBRZ_mt; + gfx.filter.factor = filter - 11; + break; + case NTSC_FILTER: + gfx.filter.func = ntsc_surface; + gfx.filter.factor = X2; + break; + } + // forzo il controllo del fattore di scale + force_scale = TRUE; + // indico che devo cambiare il video mode + set_mode = TRUE; + } + + // shader + if (shader == NO_CHANGE) { + shader = cfg->shader; + } + + // fullscreen + if (fullscreen == NO_CHANGE) { + fullscreen = cfg->fullscreen; + } + if ((fullscreen != cfg->fullscreen) || info.on_cfg) { + // forzo il controllo del fattore di scale + force_scale = TRUE; + // indico che devo cambiare il video mode + set_mode = TRUE; + } + + // fattore di scala + if (scale == NO_CHANGE) { + scale = cfg->scale; + } + if ((scale != cfg->scale) || info.on_cfg || force_scale) { + if (filter == NTSC_FILTER) { + width = gfx.w[PASS0] = gfx.w[NO_OVERSCAN] = NES_NTSC_OUT_WIDTH(SCR_ROWS); + gfx.filter.width_pixel = (float)nes_ntsc_out_chunk / (float)nes_ntsc_in_chunk; + if (overscan.enabled) { + width -= ((float)(overscan.borders->left + overscan.borders->right) * gfx.filter.width_pixel); + } + switch (scale) { + case X2: + gfx.width_pixel = gfx.filter.width_pixel; + break; + default: + width = ((float)width / 2.0f) * (float)scale; + gfx.w[NO_OVERSCAN] = ((float)gfx.w[NO_OVERSCAN] / 2.0f) * (float)scale; + gfx.width_pixel = (gfx.filter.width_pixel / 2.0f) * (float)scale; + break; + } + } else { + width = gfx.rows * scale; + gfx.w[NO_OVERSCAN] = SCR_ROWS * scale; + gfx.w[PASS0] = SCR_ROWS * gfx.filter.factor; + gfx.filter.width_pixel = gfx.filter.factor; + gfx.width_pixel = scale; + } + gfx.w[CURRENT] = width; + + height = gfx.lines * scale; + gfx.h[CURRENT] = height; + gfx.h[NO_OVERSCAN] = SCR_LINES * scale; + gfx.h[PASS0] = SCR_LINES * gfx.filter.factor; + + set_mode = TRUE; + } + + // paletta + if (palette == NO_CHANGE) { + palette = cfg->palette; + } + if ((palette != cfg->palette) || info.on_cfg || force_palette) { + if (palette == PALETTE_FILE) { + if (ustrlen(cfg->palette_file) != 0) { + if (palette_load_from_file(cfg->palette_file) == EXIT_ERROR) { + umemset(cfg->palette_file, 0x00, usizeof(cfg->palette_file)); + text_add_line_info(1, "[red]error on palette file"); + if (cfg->palette != PALETTE_FILE) { + palette = cfg->palette; + } else if (machine.type == NTSC) { + palette = PALETTE_NTSC; + } else { + palette = PALETTE_SONY; + } + } else { + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_base_file, 0, (BYTE *)palette_RGB.noswap); + } + } + } + + switch (palette) { + case PALETTE_PAL: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_base_pal, 0, (BYTE *)palette_RGB.noswap); + break; + case PALETTE_NTSC: + ntsc_set(NULL, cfg->ntsc_format, FALSE, 0, 0, (BYTE *)palette_RGB.noswap); + break; + case PALETTE_FRBX_NOSTALGIA: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_firebrandx_nostalgia_FBX, 0, (BYTE *)palette_RGB.noswap); + break; + case PALETTE_FRBX_YUV: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_firebrandx_YUV_v3, 0, (BYTE *)palette_RGB.noswap); + break; + case PALETTE_GREEN: + rgb_modifier(NULL, palette_RGB.noswap, 0x00, -0x20, 0x20, -0x20); + break; + case PALETTE_FILE: + break; + default: + ntsc_set(NULL, cfg->ntsc_format, palette, 0, 0, (BYTE *)palette_RGB.noswap); + break; + } + + if (vs_system.enabled) { + switch (vs_system.ppu) { + case RP2C03B: + case RP2C03G: + break; + case RP2C04: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0001, 0, (BYTE *)palette_RGB.noswap); + break; + case RP2C04_0002: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0002, 0, (BYTE *)palette_RGB.noswap); + break; + case RP2C04_0003: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0003, 0, (BYTE *)palette_RGB.noswap); + break; + case RP2C04_0004: + ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0004, 0, (BYTE *)palette_RGB.noswap); + break; + case RC2C03B: + case RC2C03C: + case RC2C05_01: + case RC2C05_02: + case RC2C05_03: + case RC2C05_04: + case RC2C05_05: + default: + break; + } + } + } + + gfx_palette_update(); + + // salvo il nuovo fattore di scala + cfg->scale = scale; + // salvo il nuovo filtro + cfg->filter = filter; + // salvo la nuova shader + cfg->shader = shader; + // salvo il nuovo stato del fullscreen + cfg->fullscreen = fullscreen; + // salvo il nuovo tipo di paletta + cfg->palette = palette; + + // Pixel Aspect Ratio + if (cfg->filter == NTSC_FILTER) { + gfx.pixel_aspect_ratio = 1.0f; + } else { + switch (cfg->pixel_aspect_ratio) { + default: + case PAR11: + gfx.pixel_aspect_ratio = 1.0f; + break; + case PAR54: + gfx.pixel_aspect_ratio = 5.0f / 4.0f; + break; + case PAR87: + gfx.pixel_aspect_ratio = 8.0f / 7.0f; + break; + case PAR118: + gfx.pixel_aspect_ratio = 2950000.0f / 2128137.0f; + break; + } + } + + { + gfx.PSS = ((cfg->pixel_aspect_ratio != PAR11) && cfg->PAR_soft_stretch) ? TRUE : FALSE; + + if (shaders_set(shader) == EXIT_ERROR) { + umemcpy(cfg->shader_file, gfx.last_shader_file, usizeof(cfg->shader_file)); + if (old_shader == shader) { + shader = NO_SHADER; + } else { + shader = old_shader; + } + goto gfx_set_screen_start; + } + + if (shader_effect.params > 0) { + settings_shp_parse(); + } + + if (set_mode) { + if (fullscreen == TRUE) { + gfx.w[VIDEO_MODE] = gfx.w[MONITOR]; + gfx.h[VIDEO_MODE] = gfx.h[MONITOR]; + } else if (cfg->oscan_black_borders) { + gfx.w[VIDEO_MODE] = gfx.w[NO_OVERSCAN]; + gfx.h[VIDEO_MODE] = gfx.h[NO_OVERSCAN]; + } else { + gfx.w[VIDEO_MODE] = width; + gfx.h[VIDEO_MODE] = height; + } + + // Pixel Aspect Ratio + if (cfg->pixel_aspect_ratio && !fullscreen) { + gfx.w[VIDEO_MODE] = (gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio); + + if (overscan.enabled && !cfg->oscan_black_borders) { + float brd = 0; + + brd = (float)gfx.w[VIDEO_MODE] / (float)SCR_ROWS; + brd *= (overscan.borders->right + overscan.borders->left); + + gfx.w[VIDEO_MODE] -= brd; + } + } + + // faccio quello che serve prima del setvideo + gui_set_video_mode(); + } + + switch (opengl_context_create()) { + case EXIT_ERROR: + fprintf(stderr, "OPENGL: Unable to initialize opengl context\n"); + break; + case EXIT_ERROR_SHADER: + text_add_line_info(1, "[red]errors[normal] on shader, use [green]'No shader'"); + fprintf(stderr, "OPENGL: Error on loading the shaders, switch to \"No shader\"\n"); + umemcpy(cfg->shader_file, gfx.last_shader_file, usizeof(cfg->shader_file)); + shader = NO_SHADER; + goto gfx_set_screen_start; + } + + } + + // calcolo le proporzioni tra il disegnato a video (overscan e schermo + // con le dimensioni per il filtro NTSC compresi) e quello che dovrebbe + // essere (256 x 240). Mi serve per calcolarmi la posizione del puntatore + // dello zapper. + if (cfg->fullscreen) { + gfx.w_pr = (float)gfx.vp.w / (float)SCR_ROWS; + gfx.h_pr = (float)gfx.vp.h / (float)SCR_LINES; + } else { + gfx.w_pr = (float)(gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio) / (float)SCR_ROWS; + gfx.h_pr = (float)gfx.h[NO_OVERSCAN] / (float)SCR_LINES; + } + + gfx_thread_continue(); + + // setto il titolo della finestra + gui_update(); + + if (info.on_cfg == TRUE) { + info.on_cfg = FALSE; + } +} +void gfx_draw_screen(void) { + if (gfx_thread_public.filtering == TRUE) { + fps.frames_skipped++; + return; + } + + screen.rd = screen.wr; + + if (info.doublebuffer == TRUE) { + screen.index = !screen.index; + screen.last_completed_wr = screen.wr; + screen.wr = &screen.buff[screen.index]; + } else { + screen.rd = screen.wr = screen.last_completed_wr; + } + + if (screen.rd->ready == FALSE) { + screen.rd->ready = TRUE; + } +} + +uint32_t gfx_color(BYTE a, BYTE r, BYTE g, BYTE b) { + return (gui_color(a, r, g, b)); +} +void gfx_palette_update(void) { + WORD i; + + if ((cfg->disable_swap_emphasis_pal == FALSE) && ((machine.type == PAL) || (machine.type == DENDY))) { + palette_RGB.in_use = &palette_RGB.swapped[0]; + } else { + palette_RGB.in_use = &palette_RGB.noswap[0]; + } + + // inizializzo in ogni caso la tabella YUV dell'hqx + hqx_init(); + + // memorizzo i colori della paletta nel formato di visualizzazione + for (i = 0; i < NUM_COLORS; i++) { + gfx.palette[i] = gfx_os_color(palette_RGB.in_use[i].r, palette_RGB.in_use[i].g, palette_RGB.in_use[i].b); + } +} + +void gfx_cursor_init(void) { + gui_cursor_init(); + gui_cursor_set(); +} +void gfx_cursor_set(void) { + gui_cursor_set(); +} + +void gfx_text_create_surface(_txt_element *ele) { + uint32_t size = (ele->h * ele->w) * sizeof(uint32_t); + + ele->surface = malloc(size); + memset(ele->surface, 0x00, size); + + ele->blank = malloc(size); + memset(ele->blank, 0x00, size); +} +void gfx_text_release_surface(_txt_element *ele) { + if (ele->surface) { + free(ele->surface); + ele->surface = NULL; + } + if (ele->blank) { + free(ele->blank); + ele->blank = NULL; + } +} +void gfx_text_rect_fill(_txt_element *ele, _txt_rect *rect, uint32_t color) { + uint32_t *pbits; + uint32_t pitch; + int w, h; + + pitch = ele->w; + pbits = (uint32_t *)ele->surface; + pbits += (rect->y * ele->w) + rect->x; + + for (h = 0; h < rect->h; h++) { + for (w = 0; w < rect->w; w++) { + (*(pbits + w)) = color; + } + pbits += pitch; + } +} +void gfx_text_reset(void) { + txt_table[TXT_NORMAL] = gfx_color(0, 0xFF, 0xFF, 0xFF); + txt_table[TXT_RED] = gfx_color(0, 0xFF, 0x4C, 0x3E); + txt_table[TXT_YELLOW] = gfx_color(0, 0xFF, 0xFF, 0 ); + txt_table[TXT_GREEN] = gfx_color(0, 0 , 0xFF, 0 ); + txt_table[TXT_CYAN] = gfx_color(0, 0 , 0xFF, 0xFF); + txt_table[TXT_BROWN] = gfx_color(0, 0xEB, 0x89, 0x31); + txt_table[TXT_BLUE] = gfx_color(0, 0x2D, 0x8D, 0xBD); + txt_table[TXT_GRAY] = gfx_color(0, 0xA0, 0xA0, 0xA0); + txt_table[TXT_BLACK] = gfx_color(0, 0 , 0 , 0 ); +} +void gfx_text_clear(_txt_element *ele) { + int x, y; + + if (!ele->blank) { + return; + } + + text_calculate_real_x_y(ele, &x, &y); + + glBindTexture(GL_TEXTURE_2D, opengl.text.id); + glPixelStorei(GL_UNPACK_ROW_LENGTH, ele->w); + glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, ele->w, ele->h, TI_FRM, TI_TYPE, ele->blank); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); +} +void gfx_text_blit(_txt_element *ele, _txt_rect *rect) { + if (!cfg->txt_on_screen) { + return; + } + glBindTexture(GL_TEXTURE_2D, opengl.text.id); + glPixelStorei(GL_UNPACK_ROW_LENGTH, rect->w); + glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, TI_FRM, TI_TYPE, ele->surface); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); +} + +void gfx_apply_filter(void) { + gfx.filter.data.palette = (void *)gfx.palette; + + //applico la paletta adeguata. + if (cfg->filter == NTSC_FILTER) { + gfx.filter.data.palette = NULL; + } + if (info.no_rom | info.turn_off) { + if (cfg->filter == NTSC_FILTER) { + gfx.filter.data.palette = turn_off_effect.ntsc; + } else { + gfx.filter.data.palette = (void *)turn_off_effect.palette; + } + } else if (info.pause) { + if (!cfg->disable_sepia_color) { + if (cfg->filter == NTSC_FILTER) { + gfx.filter.data.palette = pause_effect.ntsc; + } else { + gfx.filter.data.palette = pause_effect.palette; + } + } + } + + gfx_thread_lock(); + + // applico l'effetto desiderato + gfx.filter.data.pitch = opengl.surface.pitch; + gfx.filter.data.pix = opengl.surface.pixels; + gfx.filter.data.width = opengl.surface.w; + gfx.filter.data.height = opengl.surface.h; + gfx.filter.func(); + + gfx_thread_unlock(); + gui_screen_update(); +} diff -upr --new-file puNES-0.105.org/src/video/opengl/opengl.c puNES-0.105.new/src/video/opengl/opengl.c --- puNES-0.105.org/src/video/opengl/opengl.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/opengl/opengl.c 2020-03-18 11:47:29.384142515 +0100 @@ -23,6 +23,7 @@ #include #include "opengl.h" #include "video/gfx_thread.h" +#include "overscan.h" #include "info.h" #include "conf.h" #include "emu.h" @@ -42,6 +43,8 @@ #define _SCR_LINES_NOBRD\ (float)SCR_LINES +_opengl opengl; + static void opengl_context_delete(void); static void opengl_screenshot(void); diff -upr --new-file puNES-0.105.org/src/video/opengl/opengl.h puNES-0.105.new/src/video/opengl/opengl.h --- puNES-0.105.org/src/video/opengl/opengl.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/opengl/opengl.h 2020-03-18 11:47:29.384142515 +0100 @@ -28,6 +28,16 @@ #include "common.h" #include "video/gfx.h" +enum _opengl_texture_format { + TI_INTFRM = GL_RGBA8, + TI_FRM = GL_BGRA, + TI_TYPE = GL_UNSIGNED_BYTE, + TI_F_INTFRM = GL_RGBA32F, + TI_F_TYPE = GL_FLOAT, + TI_S_INTFRM = GL_SRGB8_ALPHA8, + TI_S_TYPE = GL_UNSIGNED_BYTE +}; + #if defined (WITH_OPENGL_CG) typedef struct _shader_prg_cg { CGprogram v, f; @@ -219,15 +229,7 @@ typedef struct _opengl { #endif } _opengl; -enum _opengl_texture_format { - TI_INTFRM = GL_RGBA8, - TI_FRM = GL_BGRA, - TI_TYPE = GL_UNSIGNED_BYTE, - TI_F_INTFRM = GL_RGBA32F, - TI_F_TYPE = GL_FLOAT, - TI_S_INTFRM = GL_SRGB8_ALPHA8, - TI_S_TYPE = GL_UNSIGNED_BYTE -}; +extern _opengl opengl; #if defined (__cplusplus) #define EXTERNC extern "C" @@ -235,8 +237,6 @@ enum _opengl_texture_format { #define EXTERNC #endif -EXTERNC _opengl opengl; - EXTERNC BYTE opengl_init(void); EXTERNC void opengl_quit(void); EXTERNC BYTE opengl_context_create(void); diff -upr --new-file puNES-0.105.org/src/video/shaders/shaders.c puNES-0.105.new/src/video/shaders/shaders.c --- puNES-0.105.org/src/video/shaders/shaders.c 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/shaders/shaders.c 2020-03-18 11:47:29.384142515 +0100 @@ -40,6 +40,8 @@ static void lp_set_default(_lut_pass *lp static void ps_set_default(_param_shd *ps); static void se_soft_stretch(void); +_shader_effect shader_effect; + BYTE shaders_set(int shader) { _shader_effect *se = &shader_effect; _shader_pass *sp = NULL; diff -upr --new-file puNES-0.105.org/src/video/shaders/shaders.h puNES-0.105.new/src/video/shaders/shaders.h --- puNES-0.105.org/src/video/shaders/shaders.h 2019-07-30 12:43:09.000000000 +0200 +++ puNES-0.105.new/src/video/shaders/shaders.h 2020-03-18 11:47:29.384142515 +0100 @@ -109,14 +109,14 @@ typedef struct _shader_effect { int8_t feedback_pass; } _shader_effect; +extern _shader_effect shader_effect; + #if defined (__cplusplus) #define EXTERNC extern "C" #else #define EXTERNC #endif -EXTERNC _shader_effect shader_effect; - EXTERNC BYTE shaders_set(int shader); EXTERNC void shader_se_set_default(_shader_effect *se); EXTERNC char *shader_code_blend(void);