From 6359a0b36e599b3a496019b5b034ff375dba4ae9 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-SPFP6AQ\\twistedtechre" Date: Mon, 4 May 2026 04:44:52 +0200 Subject: [PATCH] core: stride-aware savestate, iNES2 helpers, -Wundef, -Wmissing-prototypes Audit pass 5 - five distinct cleanups bundled into one omnibus. 1. Element-stride byte-swapping for savestate fields (state.h, state.c, fceu-endian.{h,c}) The SFORMAT 's' field was previously {bit 31 = RLSB, bits 0..30 = byte size}. RLSB triggers FlipByteOrder() on MSB hosts, which reverses the entire entry buffer end-to-end. That is correct for a single primitive (size <= 8 bytes) but wrong for an array of multi-byte primitives - reversing the whole buffer would swap element 0 with element N-1 and reverse their bytes too, scrambling the data. The previous workaround was either splitting an N-element array into N separate single-primitive entries with distinct chunk IDs (n106 PlayIndex split into IDX0..IDX7) or skipping the entry entirely on big-endian hosts (the GEKKO #ifndef in vrc6.c / vrc7.c). Both approaches mean BE saves are not portable to LE and vice versa, and force the same workaround at every new array site. This pass adds proper stride support: * SFORMAT 's' encoding is now {bit 31 = RLSB, bits 24..30 = stride in bytes (0 = legacy/unset), bits 0..23 = byte size}. 16 MiB max size, well above any actual savestate field. * FCEUSTATE_RLSB_ARRAY(stride) macro for the new pattern. * FlipByteOrderStrided() byte-swaps each element of an array independently. Round-trip identity verified: [01 00 00 00 ...] -> [00 00 00 01 ...] -> [01 00 00 00 ...]. * state.c's SubWrite / ReadStateChunk / CheckS use new helpers sf_size() / sf_stride() / sf_flip() that mask the size out of the new bit layout and dispatch to the strided variant when stride < size. Backwards compatible: legacy single-primitive entries (size == 1, 2, 4, 8) leave the stride bits at zero, which sf_stride() reads as "stride equals size" and falls through to FlipByteOrder() as before. No on-disk format change. Existing single-primitive RLSB sites are unchanged. The infrastructure is now in place so any future SFORMAT entry that is an array of multi-byte primitives can be expressed as a single entry (e.g. "{ buf, sizeof(buf) | FCEUSTATE_RLSB_ARRAY(4), "BUF." }") without splitting or skipping. The existing PlayIndex split and GEKKO #ifndefs are intentionally left untouched - migrating them would alter the on-disk savestate format and is a separate decision. 2. iNES1-vs-iNES2 sizing helpers (cart.h) Twelve sites across the codebase encoded the same conditional: info->iNES2 ? (info->PRGRamSize + info->PRGRamSaveSize) : default Sometimes for PRGRAM, sometimes for CHRRAM, sometimes in bytes, sometimes after dividing by 1024. The pattern is verbose and easy to write inconsistently. Added two inline helpers in cart.h: - CartInfo_PRGRAM_bytes(info, default_bytes) - CartInfo_CHRRAM_bytes(info, default_bytes) Migrated 9 of the 13 sites: cartram.c (2), 162.c, 163.c, 134.c, 399.c, 478.c, 480.c, 484.c. The remaining 4 are non-helper-fitting variants (164.c special masking, 2 cartram SaveGameLen sites with different fallback semantics, mmc3.c Boogerman submapper detection). 3. -Wundef enabled permanently (Makefile.libretro) Zero warnings out of the box - no #if-on-undefined-macro footguns in the codebase. Now part of WARNING_DEFINES alongside the existing -Wsign-compare. 4. -Wmissing-prototypes enabled permanently (Makefile.libretro) Started at 198 warnings, cleared all of them: * Mass-static-ified ~96 functions across 75 files that were defined non-static but only used within their own translation unit. (See static_prototype_fixer.py in the development notes.) * K&R-style empty-parens prototypes "()" replaced with explicit "(void)" across all asic_*.{c,h} files - GCC treats "()" as "any args" and refuses to match it against a separate K&R definition. * Added missing forward declarations to public headers: - fds.h (FDSLoad) - nsf.h (NSFLoad) - ines.h (iNESLoad) - unif.h (UNIFLoad) - latch.h (LatchHardReset, K&R fix) - eeprom_93Cx6.h (eeprom_93Cx6_read, K&R fix) Each header gained an "#include "file.h"" where needed. * fds_apu.c now includes its own fds_apu.h header (was missing). * fds_apu.h: removed unused FDSSoundRead declaration (the function is internal-static). * cartram.h: removed unused CartRAM_close declaration (the function is internal-static). * input.h: added a centralised block of FCEU_Init* prototypes (Zapper, Mouse, Powerpad, Arkanoid, VirtualBoy, FKB, SuborKB, PEC586KB, HS, Mahjong, FamilyTrainerA/B, OekaKids, TopRider, BarcodeWorld, BattleBox, QuizKing, FTrainerA/B, SpaceShadow, LCDCompZapper, ArkanoidFC) plus FCEU_ZapperSetTolerance. These were previously declared as "extern" inside src/input.c. * Static-ified FP_FASTAPASS callbacks in 106.c, 65.c, 67.c, asic_h3001.c, asic_vrc3.c (those with no external callers); left non-static for those that have header decls or are referenced from sibling .c files (asic_mmc1, asic_vrc6, asic_vrc7, flashrom). * For a small set of cross-file functions where adding a header was disproportionate to the value (MMC5_hb, NSFMMC5_Close, GetKeyboard, FCEU_GetJoyJoy), placed a forward declaration immediately above the definition. This satisfies -Wmissing-prototypes (which checks for any prior declaration in scope) without churning the public-header layout. 5. -Wshadow partial cleanup (not enabled permanently) Fixed five real shadows that were either bugs or actively misleading: * src/boards/476.c: removed an inner "int i" that shadowed the outer loop counter. * src/boards/mmc5.c MMC5_hb: parameter "scanline" renamed to "sl_param" (was shadowing the global "scanline"). * src/boards/n106.c DoNamcoSound: parameter "Wave" renamed to "WaveBuf" (was shadowing the global Wave audio buffer); also updated the forward declaration and the matching parameter on sound.h's NeoFill function pointer typedef. * src/boards/vrc7.c UpdateOPLNEO: same Wave -> WaveBuf rename. * src/ntsc/nes_ntsc_impl.h: renamed an inner loop counter "n" that shadowed an outer "n". * src/drivers/libretro/libretro.c FCEUD_RegionOverride: local "pal" renamed to "is_pal" (was shadowing the typedef "pal" from palette.h). * src/palette.c FCEUI_SetPaletteArray: parameter "pal" renamed to "data" (same shadow); driver.h declaration updated to match. -Wshadow itself is NOT enabled permanently because the remaining warnings are deliberate parameter naming conventions (XBuf in draw functions, X in cpu hooks) and third-party blargg ntsc code. In addition, four files were touched as part of an MSVC-build fix that came up mid-pass: src/fds.c, src/nsf.c, src/ines.c, and src/drivers/libretro/libretro_dipswitch.c had snprintf() calls introduced in pass 4 that fail to link on pre-MSVC2015 toolchains when STATIC_LINKING=1 (the libretro-common compat_snprintf.c shim isn't compiled in those configurations). Replaced each snprintf with either sprintf-into-bounded-buffer (the format strings have known maximum output) or strlcpy/strlcat for the dipswitch key-build case. All output is still bounded; truncation happens via strl*'s normal truncation semantics where applicable. All added code is C89-clean (top-of-block declarations only, no mixed decls, no // comments, INLINE macro from fceu-types.h instead of bare "inline"). Builds clean under -std=gnu11 with -Wno-write- strings -Wsign-compare -Wundef -Wmissing-prototypes; zero errors, zero warnings. Determinism audit (audit_determinism.py): no rand/time/long double/threads issues introduced. --- Makefile.libretro | 2 +- src/boards/106.c | 2 +- src/boards/116.c | 2 +- src/boards/134.c | 2 +- src/boards/14.c | 4 +- src/boards/162.c | 2 +- src/boards/163.c | 2 +- src/boards/195.c | 2 +- src/boards/234.c | 4 +- src/boards/268.c | 2 +- src/boards/28.c | 4 +- src/boards/351.c | 2 +- src/boards/399.c | 2 +- src/boards/476.c | 1 - src/boards/478.c | 2 +- src/boards/480.c | 2 +- src/boards/484.c | 2 +- src/boards/525.c | 4 +- src/boards/542.c | 4 +- src/boards/65.c | 2 +- src/boards/67.c | 2 +- src/boards/69.c | 2 +- src/boards/82_552.c | 2 +- src/boards/83_264.c | 9 +- src/boards/__dummy_mapper.c | 2 +- src/boards/addrlatch.c | 10 +- src/boards/asic_fme7.c | 8 +- src/boards/asic_fme7.h | 8 +- src/boards/asic_h3001.c | 10 +- src/boards/asic_h3001.h | 8 +- src/boards/asic_latch.c | 6 +- src/boards/asic_latch.h | 6 +- src/boards/asic_mmc1.c | 12 +- src/boards/asic_mmc1.h | 8 +- src/boards/asic_mmc2and4.c | 8 +- src/boards/asic_mmc2and4.h | 8 +- src/boards/asic_mmc3.c | 16 +- src/boards/asic_mmc3.h | 12 +- src/boards/asic_n118.c | 6 +- src/boards/asic_n118.h | 6 +- src/boards/asic_pt8154.c | 8 +- src/boards/asic_pt8154.h | 8 +- src/boards/asic_qj.c | 10 +- src/boards/asic_qj.h | 8 +- src/boards/asic_tc3294.c | 8 +- src/boards/asic_tc3294.h | 8 +- src/boards/asic_vrc1.c | 8 +- src/boards/asic_vrc1.h | 8 +- src/boards/asic_vrc2and4.c | 12 +- src/boards/asic_vrc2and4.h | 12 +- src/boards/asic_vrc3.c | 8 +- src/boards/asic_vrc3.h | 6 +- src/boards/asic_vrc6.c | 10 +- src/boards/asic_vrc6.h | 8 +- src/boards/asic_vrc7.c | 10 +- src/boards/asic_vrc7.h | 8 +- src/boards/cartram.c | 6 +- src/boards/cartram.h | 1 - src/boards/cheapocabra.c | 536 +++++++++--------- src/boards/eeprom_93Cx6.c | 2 +- src/boards/eeprom_93Cx6.h | 2 +- src/boards/fk23c.c | 2 +- src/boards/jyasic.c | 18 +- src/boards/latch.c | 196 +++---- src/boards/latch.h | 2 +- src/boards/mmc1.c | 6 +- src/boards/mmc2and4.c | 2 +- src/boards/mmc3.c | 2 +- src/boards/mmc5.c | 14 +- src/boards/n106.c | 6 +- src/boards/onebus.c | 2 +- src/boards/unrom512.c | 6 +- src/boards/vrc6.c | 6 +- src/boards/vrc7.c | 8 +- src/cart.h | 27 + src/cheat.c | 2 +- src/driver.h | 2 +- .../streams/file_stream_transforms.c | 28 +- .../libretro-common/vfs/vfs_implementation.c | 2 +- src/drivers/libretro/libretro.c | 21 +- src/drivers/libretro/libretro_dipswitch.c | 12 +- src/fceu-endian.c | 31 + src/fceu-endian.h | 6 + src/fceu.c | 2 +- src/fds.c | 8 +- src/fds.h | 4 + src/fds_apu.c | 5 +- src/fds_apu.h | 1 - src/ines.c | 39 +- src/ines.h | 4 + src/input.c | 3 +- src/input.h | 31 + src/input/powerpad.c | 2 +- src/nsf.c | 9 +- src/nsf.h | 3 + src/ntsc/nes_ntsc_impl.h | 4 +- src/palette.c | 10 +- src/ppu.c | 2 +- src/sound.c | 4 +- src/sound.h | 2 +- src/state.c | 51 +- src/state.h | 29 +- src/unif.c | 2 +- src/unif.h | 4 + src/video.c | 2 +- 105 files changed, 847 insertions(+), 660 deletions(-) diff --git a/Makefile.libretro b/Makefile.libretro index 6a5cf0b..3be314b 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -781,7 +781,7 @@ else ifneq (,$(findstring msvc,$(platform))) WARNING_DEFINES = LIBM := else -WARNING_DEFINES = -Wno-write-strings -Wsign-compare +WARNING_DEFINES = -Wno-write-strings -Wsign-compare -Wundef -Wmissing-prototypes endif CFLAGS += $(fpic) $(WARNING_DEFINES) $(DEFINES) $(ENDIANNESS_DEFINES) diff --git a/src/boards/106.c b/src/boards/106.c index bfde3ba..c11e335 100644 --- a/src/boards/106.c +++ b/src/boards/106.c @@ -78,7 +78,7 @@ static void M106Close(void) { WRAM = NULL; } -void FP_FASTAPASS(1) M106CpuHook(int a) { +static void FP_FASTAPASS(1) M106CpuHook(int a) { if (IRQa) { IRQCount += a; if (IRQCount > 0x10000) { diff --git a/src/boards/116.c b/src/boards/116.c index 52f6eb4..5c39c16 100644 --- a/src/boards/116.c +++ b/src/boards/116.c @@ -72,7 +72,7 @@ static void sync (void) { } } -int Huang2_getPRGBank (uint8_t bank) { +static int Huang2_getPRGBank (uint8_t bank) { return MMC1_getPRGBank(bank) >>1; } diff --git a/src/boards/134.c b/src/boards/134.c index b0f9866..651afa9 100644 --- a/src/boards/134.c +++ b/src/boards/134.c @@ -86,7 +86,7 @@ static void Mapper134_Power(void) { } void Mapper134_Init(CartInfo *info) { - GenMMC3_Init(info, 256, 256, info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize) /1024: 8, info->battery); + GenMMC3_Init(info, 256, 256, CartInfo_PRGRAM_bytes(info, 8 * 1024) / 1024, info->battery); cwrap = Mapper134_CHRWrap; pwrap = Mapper134_PRGWrap; info->Power = Mapper134_Power; diff --git a/src/boards/14.c b/src/boards/14.c index e53838d..d0b6bc1 100644 --- a/src/boards/14.c +++ b/src/boards/14.c @@ -44,11 +44,11 @@ static void sync (void) { } } -int getCHRBank_MMC3 (uint8_t bank) { +static int getCHRBank_MMC3 (uint8_t bank) { return MMC3_getCHRBank(bank) | reg <<(~bank &4? 5: ~bank &2? 3: 1) &0x100; } -int getCHRBank_VRC2 (uint8_t bank) { +static int getCHRBank_VRC2 (uint8_t bank) { return VRC24_getCHRBank(bank) | reg <<(~bank &4? 5: ~bank &2? 3: 1) &0x100; } diff --git a/src/boards/162.c b/src/boards/162.c index 816f2cf..aee4dcb 100644 --- a/src/boards/162.c +++ b/src/boards/162.c @@ -106,7 +106,7 @@ void Mapper162_Init (CartInfo *info) GameStateRestore = StateRestore; AddExState(StateRegs, ~0, 0, 0); - WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192; + WRAMSIZE = CartInfo_PRGRAM_bytes(info, 8192); WRAM = (uint8_t*) FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); diff --git a/src/boards/163.c b/src/boards/163.c index 04942c9..0cf2fa1 100644 --- a/src/boards/163.c +++ b/src/boards/163.c @@ -111,7 +111,7 @@ void Mapper163_Init (CartInfo *info) GameStateRestore = StateRestore; AddExState(StateRegs, ~0, 0, 0); - WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192; + WRAMSIZE = CartInfo_PRGRAM_bytes(info, 8192); WRAM = (uint8_t*) FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); diff --git a/src/boards/195.c b/src/boards/195.c index 23467a4..24f949b 100644 --- a/src/boards/195.c +++ b/src/boards/195.c @@ -76,7 +76,7 @@ static void Mapper195_Power(void) { } } -void Mapper195_Close(void) { +static void Mapper195_Close(void) { if (CHRRAM) FCEU_gfree(CHRRAM); CHRRAM = NULL; diff --git a/src/boards/234.c b/src/boards/234.c index 751a819..04837df 100644 --- a/src/boards/234.c +++ b/src/boards/234.c @@ -39,7 +39,7 @@ static void Sync(void) { setmirror((bank >> 7) ^ 1); } -DECLFR(M234ReadBank) { +static DECLFR(M234ReadBank) { uint8_t r = CartBR(A); if (!bank) { bank = r; @@ -48,7 +48,7 @@ DECLFR(M234ReadBank) { return r; } -DECLFR(M234ReadPreg) { +static DECLFR(M234ReadPreg) { uint8_t r = CartBR(A); preg = r; Sync(); diff --git a/src/boards/268.c b/src/boards/268.c index d7f841b..ab0e0b4 100644 --- a/src/boards/268.c +++ b/src/boards/268.c @@ -94,7 +94,7 @@ static void Mapper268_CHRWrap(uint32_t A, uint8_t V) { setchr1r(CHRRAM && EXPREGS[4] &0x01 && (V &0xFE) ==(EXPREGS[4] &0xFE)? 0x10: 0x00, A, V &chrMaskMMC3 | chrOffset | A >>10 &chrMaskGNROM); } -void Mapper268_MirrorWrap(uint8_t V) { +static void Mapper268_MirrorWrap(uint8_t V) { A000B =V; if ((submapper &~1) ==10 && ~EXPREGS[0] &0x20) setmirror(EXPREGS[0] &0x10? MI_1: MI_0); diff --git a/src/boards/28.c b/src/boards/28.c index cc526ad..009fbf0 100644 --- a/src/boards/28.c +++ b/src/boards/28.c @@ -36,7 +36,7 @@ static SFORMAT StateRegs[] = { {0} }; -void SyncMirror() { +static void SyncMirror(void) { switch (mode & 3) { case 0: setmirror(MI_0); break; case 1: setmirror(MI_1); break; @@ -45,7 +45,7 @@ void SyncMirror() { } } -void Mirror(uint8_t value) +static void Mirror(uint8_t value) { if ((mode & 2) == 0) { mode &= 0xfe; diff --git a/src/boards/351.c b/src/boards/351.c index 05c68c0..264621a 100644 --- a/src/boards/351.c +++ b/src/boards/351.c @@ -85,7 +85,7 @@ static void sync () { MMC1_syncMirror(); } -DECLFW (VRC24_trapWriteReg) { /* When A11 is set, VRC4's A0 and A1 are swapped */ +static DECLFW (VRC24_trapWriteReg) { /* When A11 is set, VRC4's A0 and A1 are swapped */ if (A &0x800) A = A &~0xF | A >>1 &0x5 | A <<1 &0xA; VRC24_writeReg(A, V); } diff --git a/src/boards/399.c b/src/boards/399.c index 2e123f3..edba02b 100644 --- a/src/boards/399.c +++ b/src/boards/399.c @@ -69,7 +69,7 @@ static void power(void) { void Mapper399_Init(CartInfo *info) { submapper =info->submapper; - GenMMC3_Init(info, 256, 32, info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize) /1024: 8, info->battery); + GenMMC3_Init(info, 256, 32, CartInfo_PRGRAM_bytes(info, 8 * 1024) / 1024, info->battery); cwrap =CHRWrap; pwrap =PRGWrap; info->Power =power; diff --git a/src/boards/476.c b/src/boards/476.c index 6cad5fe..03d0c10 100644 --- a/src/boards/476.c +++ b/src/boards/476.c @@ -53,7 +53,6 @@ static DECLFR(remapButtons) { (result &0x60? 0x02: 0x00) ; /* SELECT/B */ } else if (A ==0x4017) { - int i; for (i =0; i <8; i++) { result <<=1; result |=read4016(0x4016) &1; diff --git a/src/boards/478.c b/src/boards/478.c index 19578bc..f8eb125 100644 --- a/src/boards/478.c +++ b/src/boards/478.c @@ -71,7 +71,7 @@ static void Reset(void) { } void Mapper478_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 128, info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize) /1024: 8, info->battery); + GenMMC3_Init(info, 128, 128, CartInfo_PRGRAM_bytes(info, 8 * 1024) / 1024, info->battery); pwrap = PRGWrap; cwrap = CHRWrap; info->Power = Power; diff --git a/src/boards/480.c b/src/boards/480.c index 2ae698b..7e65f47 100644 --- a/src/boards/480.c +++ b/src/boards/480.c @@ -97,7 +97,7 @@ static void Close(void) { void Mapper480_Init(CartInfo *info) { submapper =info->submapper; - GenMMC3_Init(info, 256, 256, info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize) /1024: 8, info->battery); + GenMMC3_Init(info, 256, 256, CartInfo_PRGRAM_bytes(info, 8 * 1024) / 1024, info->battery); pwrap = submapper ==2? PRGWrap2: submapper==1? PRGWrap1: PRGWrap0; cwrap = submapper ==2? CHRWrap2: submapper==1? CHRWrap1: CHRWrap0; info->Power = Power; diff --git a/src/boards/484.c b/src/boards/484.c index 32d7119..f22da99 100644 --- a/src/boards/484.c +++ b/src/boards/484.c @@ -41,7 +41,7 @@ static void Power(void) { } void Mapper484_Init(CartInfo *info) { - GenMMC3_Init(info, 512, 256, info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize) /1024: 8, info->battery); + GenMMC3_Init(info, 512, 256, CartInfo_PRGRAM_bytes(info, 8 * 1024) / 1024, info->battery); pwrap = PRGWrap; info->Power = Power; AddExState(EXPREGS, 1, 0, "EXPR"); diff --git a/src/boards/525.c b/src/boards/525.c index 97a9316..46e9098 100644 --- a/src/boards/525.c +++ b/src/boards/525.c @@ -27,12 +27,12 @@ static void sync () { VRC24_syncMirror(); } -DECLFW (UNLKS7021A_writeCHR) { +static DECLFW (UNLKS7021A_writeCHR) { VRC24_writeReg(0xB000 +(A <<11 &0x3000 | A <<1 &0x0002), V &0x0F); VRC24_writeReg(0xB001 +(A <<11 &0x3000 | A <<1 &0x0002), V >>4); } -void UNLKS7021A_power (void) { +static void UNLKS7021A_power (void) { VRC24_power(); SetWriteHandler(0xB000, 0xEFFF, UNLKS7021A_writeCHR); } diff --git a/src/boards/542.c b/src/boards/542.c index a5f9c8b..27b2b8c 100644 --- a/src/boards/542.c +++ b/src/boards/542.c @@ -36,7 +36,7 @@ static void sync () { if (reg &1) setchr1r(0x10, 0x0C00, 1); } -DECLFW (writeExtra) { +static DECLFW (writeExtra) { if (A &0x800) { reg =A >>12; sync(); @@ -45,7 +45,7 @@ DECLFW (writeExtra) { } -void power (void) { +static void power (void) { reg =0; VRC24_power(); SetReadHandler(0x6000, 0x7FFF, CartBR); diff --git a/src/boards/65.c b/src/boards/65.c index c632d43..f7d8a71 100644 --- a/src/boards/65.c +++ b/src/boards/65.c @@ -80,7 +80,7 @@ static void M65Power(void) { SetWriteHandler(0x8000, 0xFFFF, M65Write); } -void FP_FASTAPASS(1) M65IRQ(int a) { +static void FP_FASTAPASS(1) M65IRQ(int a) { if (IRQa) { IRQCount -= a; if (IRQCount < -4) { diff --git a/src/boards/67.c b/src/boards/67.c index ff9e248..d4374a7 100644 --- a/src/boards/67.c +++ b/src/boards/67.c @@ -81,7 +81,7 @@ static void M67Power(void) { SetWriteHandler(0x8000, 0xFFFF, M67Write); } -void FP_FASTAPASS(1) M67IRQ(int a) { +static void FP_FASTAPASS(1) M67IRQ(int a) { if (IRQa) { IRQCount -= a; if (IRQCount <= 0) { diff --git a/src/boards/69.c b/src/boards/69.c index 9f2ff2d..6bc8748 100644 --- a/src/boards/69.c +++ b/src/boards/69.c @@ -247,7 +247,7 @@ static void AYHiSync(int32_t ts) { CAYBC[x] = ts; } -void Mapper69_ESI(void) { +static void Mapper69_ESI(void) { GameExpSound.RChange = Mapper69_ESI; GameExpSound.HiSync = AYHiSync; memset(dcount, 0, sizeof(dcount)); diff --git a/src/boards/82_552.c b/src/boards/82_552.c index ff6c491..86addd3 100644 --- a/src/boards/82_552.c +++ b/src/boards/82_552.c @@ -35,7 +35,7 @@ static SFORMAT StateRegs[] = { 0 } }; -uint8_t prgBits (uint8_t val) { +static uint8_t prgBits (uint8_t val) { if (is552) return val >>5 &0x01 | val >>3 &0x02 | val >>1 &0x04 | val <<1 &0x08 | val <<3 &0x10 | val <<5 &0x20; else diff --git a/src/boards/83_264.c b/src/boards/83_264.c index fb16017..5725ce9 100644 --- a/src/boards/83_264.c +++ b/src/boards/83_264.c @@ -156,7 +156,7 @@ static DECLFW (writeReg) { } } -void clockCounter (void) { +static void clockCounter (void) { uint16_t counter = reg[2] | reg[3] <<8; if (flags &0x80 && counter) { if (reg[1] &0x40) @@ -172,11 +172,11 @@ void clockCounter (void) { reg[3] = counter >>8 &0xFF; } -void FP_FASTAPASS(1) cycleCounter (int a) { +static void FP_FASTAPASS(1) cycleCounter (int a) { while (a--) if (~flags &0x40) clockCounter(); } -void scanlineCounter() { +static void scanlineCounter() { if (flags &0x40) { clockCounter(); clockCounter(); @@ -211,7 +211,8 @@ static void power () { sync(); } -void restore (int version) { +static void restore (int version) { + (void)version; sync(); } diff --git a/src/boards/__dummy_mapper.c b/src/boards/__dummy_mapper.c index 6763f95..9bf99c6 100644 --- a/src/boards/__dummy_mapper.c +++ b/src/boards/__dummy_mapper.c @@ -73,7 +73,7 @@ static void StateRestore(int version) { Sync(); } -void MapperNNN_Init(CartInfo *info) { +static void MapperNNN_Init(CartInfo *info) { info->Reset = MNNNReset; info->Power = MNNNPower; /* info->Close = MNNNClose; */ diff --git a/src/boards/addrlatch.c b/src/boards/addrlatch.c index 3225491..1c71fe9 100644 --- a/src/boards/addrlatch.c +++ b/src/boards/addrlatch.c @@ -188,7 +188,7 @@ static void M61Sync(void) { setmirror(((latche >> 7) & 1) ^ 1); } -void Mapper61_Reset() { +static void Mapper61_Reset() { latche =0; RAM[0x1A] =0; RAM[0x1B] =0; @@ -640,7 +640,7 @@ static void BMC810544CA1Sync(void) { setmirror(((latche >> 4) & 1) ^ 1); } -void BMC810544CA1Reset() { +static void BMC810544CA1Reset() { latche =0; RAM[0x133] =0; BMC810544CA1Sync(); @@ -784,13 +784,13 @@ static void M435Sync(void) { SetReadHandler(0x8000, 0xFFFF, ~latche &0x200 && latche &(submapper == 1? 0x001: 0x400) && dipswitch &1? ReadOB: CartBR); } -void Mapper435_Power() { +static void Mapper435_Power() { LatchPower(); dipswitch = 0; M435Sync(); } -void Mapper435_Reset() { +static void Mapper435_Reset() { latche = 0; dipswitch++; M435Sync(); @@ -836,7 +836,7 @@ static void M464Sync(void) { setmirror(latche &0x20? MI_H: MI_V); } -void Mapper464_reset () { +static void Mapper464_reset () { RAM[0x133] = 0; latche = 0; M464Sync(); diff --git a/src/boards/asic_fme7.c b/src/boards/asic_fme7.c index 93cb4df..5784fa8 100644 --- a/src/boards/asic_fme7.c +++ b/src/boards/asic_fme7.c @@ -54,7 +54,7 @@ void FME7_syncCHR (int AND, int OR) { setchr1(0x1C00, FME7_reg[7] &AND | OR); } -void FME7_syncMirror () { +void FME7_syncMirror(void) { setmirror(FME7_reg[12] &2? (FME7_reg[12] &1? MI_1: MI_0): FME7_reg[12] &1? MI_H: MI_V); } @@ -84,7 +84,7 @@ void FP_FASTAPASS(1) FME7_cpuCycle (int a) { } } -void FME7_clear () { +void FME7_clear(void) { int i; for (i = 0; i < 16; i++) FME7_reg[i] = 0; FME7_cbSync(); @@ -111,7 +111,7 @@ void FME7_activate (uint8_t clear, void (*sync)()) { FME7_cbSync(); } -void FME7_addExState () { +void FME7_addExState(void) { AddExState(FME7_stateRegs, ~0, 0, 0); } @@ -119,7 +119,7 @@ void FME7_restore (int version) { FME7_cbSync(); } -void FME7_power () { +void FME7_power(void) { FME7_setHandlers(); FME7_clear(); } diff --git a/src/boards/asic_fme7.h b/src/boards/asic_fme7.h index c6278b7..8953705 100644 --- a/src/boards/asic_fme7.h +++ b/src/boards/asic_fme7.h @@ -24,16 +24,16 @@ void FME7_syncWRAM (int); void FME7_syncPRG (int, int); void FME7_syncCHR (int, int); -void FME7_syncMirror (); +void FME7_syncMirror(void); DECLFR (FME7_readWRAM); DECLFW (FME7_writeWRAM); DECLFW (FME7_writeReg); void FP_FASTAPASS(1) FME7_cpuCycle (int); -void FME7_clear (); +void FME7_clear(void); void FME7_activate (uint8_t, void (*)()); -void FME7_addExState (); +void FME7_addExState(void); void FME7_restore (int); -void FME7_power (); +void FME7_power(void); void FME7_init (CartInfo *, void (*)()); #endif \ No newline at end of file diff --git a/src/boards/asic_h3001.c b/src/boards/asic_h3001.c index e02f7e1..4666fc3 100644 --- a/src/boards/asic_h3001.c +++ b/src/boards/asic_h3001.c @@ -64,7 +64,7 @@ void H3001_syncCHR (int AND, int OR) { setchr1(0x1C00, H3001_chr[7]); } -void H3001_syncMirror () { +void H3001_syncMirror(void) { setmirror(H3001_nt &0x40? (H3001_nt &0x80? MI_1: MI_0): H3001_nt &0x80? MI_H: MI_V); } @@ -107,14 +107,14 @@ DECLFW (H3001_write) { } } -void FP_FASTAPASS(1) H3001_cpuCycle (int a) { +static void FP_FASTAPASS(1) H3001_cpuCycle (int a) { while (a--) if (H3001_irq &0x80 && !--H3001_count) { X6502_IRQBegin(FCEU_IQEXT); H3001_irq = 0; } } -void H3001_clear () { +void H3001_clear(void) { int i; for (i = 0; i < 2; i++) H3001_prg[i] = i; for (i = 0; i < 8; i++) H3001_chr[i] = i; @@ -143,7 +143,7 @@ void H3001_activate (uint8_t clear, void (*sync)()) { } -void H3001_addExState () { +void H3001_addExState(void) { AddExState(H3001_state, ~0, 0, 0); } @@ -151,7 +151,7 @@ void H3001_restore (int version) { H3001_cbSync(); } -void H3001_power () { +void H3001_power(void) { H3001_setHandlers(); H3001_clear(); } diff --git a/src/boards/asic_h3001.h b/src/boards/asic_h3001.h index 1b99644..51687e6 100644 --- a/src/boards/asic_h3001.h +++ b/src/boards/asic_h3001.h @@ -23,13 +23,13 @@ void H3001_syncPRG (int, int); void H3001_syncCHR (int, int); -void H3001_syncMirror (); +void H3001_syncMirror(void); DECLFW (H3001_write); -void H3001_clear (); +void H3001_clear(void); void H3001_activate (uint8_t, void (*)()); -void H3001_addExState (); +void H3001_addExState(void); void H3001_restore (int); -void H3001_power (); +void H3001_power(void); void H3001_init (CartInfo *, void (*)()); #endif diff --git a/src/boards/asic_latch.c b/src/boards/asic_latch.c index 889a153..9822b4a 100644 --- a/src/boards/asic_latch.c +++ b/src/boards/asic_latch.c @@ -41,7 +41,7 @@ DECLFW (Latch_write) { Latch_cbSync(); } -void Latch_clear () { +void Latch_clear(void) { Latch_address = 0; Latch_data = 0; Latch_cbSync(); @@ -69,7 +69,7 @@ void Latch_activate (uint8_t clear, void (*sync)(), uint16_t from, uint16_t to, Latch_cbSync(); } -void Latch_addExState () { +void Latch_addExState(void) { AddExState(Latch_state, ~0, 0, 0); } @@ -77,7 +77,7 @@ void Latch_restore (int version) { Latch_cbSync(); } -void Latch_power () { +void Latch_power(void) { Latch_setHandlers(); Latch_clear(); } diff --git a/src/boards/asic_latch.h b/src/boards/asic_latch.h index 37e07b0..88635d2 100644 --- a/src/boards/asic_latch.h +++ b/src/boards/asic_latch.h @@ -25,10 +25,10 @@ extern uint16_t Latch_address; extern uint8_t Latch_data; DECLFW (Latch_write); -void Latch_addExState (); +void Latch_addExState(void); void Latch_restore (int); -void Latch_clear (); -void Latch_power (); +void Latch_clear(void); +void Latch_power(void); void Latch_activate (uint8_t, void (*)(), uint16_t, uint16_t, void (*)(uint16_t*, uint8_t*, uint8_t)); void Latch6_activate (uint8_t, void (*)(), uint16_t, uint16_t, void (*)(uint16_t*, uint8_t*, uint8_t)); void Latch_init (CartInfo *, void (*)(), uint16_t, uint16_t, void (*)(uint16_t*, uint8_t*, uint8_t)); diff --git a/src/boards/asic_mmc1.c b/src/boards/asic_mmc1.c index 3327dc6..190b9f6 100644 --- a/src/boards/asic_mmc1.c +++ b/src/boards/asic_mmc1.c @@ -64,14 +64,14 @@ int MMC1_getCHRBank (uint8_t bank) { return MMC1_reg[1] &~1 |bank; } -DECLFR (MMC1_readWRAM) { +static DECLFR (MMC1_readWRAM) { if (MMC1_type == MMC1_TYPE_MMC1A || ~MMC1_reg[3] &0x10) return MMC1_cbReadWRAM? MMC1_cbReadWRAM(A): CartBR(A); else return A >>8; } -DECLFW (MMC1_writeWRAM) { +static DECLFW (MMC1_writeWRAM) { if (MMC1_type == MMC1_TYPE_MMC1A || ~MMC1_reg[3] &0x10) { CartBW(A, V); if (MMC1_cbWriteWRAM) MMC1_cbWriteWRAM(A, V); @@ -88,7 +88,7 @@ void MMC1_syncCHR (int AND, int OR) { setchr4(0x1000, MMC1_cbGetCHRBank(1) &AND |OR); } -void MMC1_syncMirror () { +void MMC1_syncMirror(void) { setmirror(MMC1_reg[0] &2? (MMC1_reg[0] &1? MI_H: MI_V): (MMC1_reg[0] &1? MI_1: MI_0)); } @@ -115,7 +115,7 @@ DECLFW (MMC1_writeReg) { MMC1_filter = 2; } -void MMC1_clear () { +void MMC1_clear(void) { MMC1_reg[0] = 0x0C; MMC1_reg[1] = 0; MMC1_reg[2] = 0; MMC1_reg[3] = 0; /* "Bad News Baseball" is sensitive to the initial CHR bank register content. 0/0 seems to work. */ MMC1_bits = 0; MMC1_shift = 0; MMC1_filter = 0; MMC1_cbSync(); @@ -147,7 +147,7 @@ void MMC1_activate (uint8_t clear, void (*sync)(), uint8_t type, int (*prg)(uint MMC1_cbSync(); } -void MMC1_addExState () { +void MMC1_addExState(void) { AddExState(MMC1_state, ~0, 0, 0); } @@ -155,7 +155,7 @@ void MMC1_restore (int version) { MMC1_cbSync(); } -void MMC1_power () { +void MMC1_power(void) { MMC1_setHandlers(); MMC1_clear(); } diff --git a/src/boards/asic_mmc1.h b/src/boards/asic_mmc1.h index 3b7adc0..5bd6194 100644 --- a/src/boards/asic_mmc1.h +++ b/src/boards/asic_mmc1.h @@ -29,13 +29,13 @@ int MMC1_getPRGBank (uint8_t); int MMC1_getCHRBank (uint8_t); void MMC1_syncPRG (int, int); void MMC1_syncCHR (int, int); -void MMC1_syncMirror (); +void MMC1_syncMirror(void); void FP_FASTAPASS(1) MMC1_cpuCycle(int); DECLFW (MMC1_writeReg); -void MMC1_clear (); -void MMC1_addExState (); +void MMC1_clear(void); +void MMC1_addExState(void); void MMC1_restore (int); -void MMC1_power (); +void MMC1_power(void); void MMC1_activate (uint8_t, void (*)(), uint8_t, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*))); void MMC1_init (CartInfo *, void (*)(), uint8_t, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*))); diff --git a/src/boards/asic_mmc2and4.c b/src/boards/asic_mmc2and4.c index 7a7fc83..760546a 100644 --- a/src/boards/asic_mmc2and4.c +++ b/src/boards/asic_mmc2and4.c @@ -54,7 +54,7 @@ void MMC24_syncCHR (int AND, int OR) { setchr4(0x1000, MMC24_reg[3 +MMC24_latch[1]] &AND |OR); } -void MMC24_syncMirror () { +void MMC24_syncMirror(void) { setmirror(MMC24_reg[5] &1? MI_H: MI_V); } @@ -70,7 +70,7 @@ DECLFW (MMC24_write) { MMC24_cbSync(); } -void MMC24_clear () { +void MMC24_clear(void) { MMC24_reg[0] = 0; MMC24_reg[1] = 0; MMC24_reg[2] = 2; MMC24_reg[3] = 0; MMC24_reg[4] = 0; MMC24_reg[5] = 0; MMC24_latch[0] = 0; MMC24_latch[1] = 0; MMC24_cbSync(); @@ -95,7 +95,7 @@ void MMC24_activate (uint8_t clear, void (*sync)()) { MMC24_cbSync(); } -void MMC24_addExState () { +void MMC24_addExState(void) { AddExState(MMC24_state, ~0, 0, 0); } @@ -103,7 +103,7 @@ void MMC24_restore (int version) { MMC24_cbSync(); } -void MMC24_power () { +void MMC24_power(void) { MMC24_setHandlers(); MMC24_clear(); } diff --git a/src/boards/asic_mmc2and4.h b/src/boards/asic_mmc2and4.h index 1149989..4e8f2e3 100644 --- a/src/boards/asic_mmc2and4.h +++ b/src/boards/asic_mmc2and4.h @@ -25,12 +25,12 @@ void MMC24_syncWRAM (int); void MMC2_syncPRG (int, int); void MMC4_syncPRG (int, int); void MMC24_syncCHR (int, int); -void MMC24_syncMirror (); +void MMC24_syncMirror(void); DECLFW (MMC24_write); -void MMC24_clear (); -void MMC24_power (); +void MMC24_clear(void); +void MMC24_power(void); void MMC24_restore (int); -void MMC24_addExState (); +void MMC24_addExState(void); void MMC24_activate (uint8_t, void (*)()); void MMC24_init (CartInfo *, void (*)()); diff --git a/src/boards/asic_mmc3.c b/src/boards/asic_mmc3.c index 4336c3a..43fc4ed 100644 --- a/src/boards/asic_mmc3.c +++ b/src/boards/asic_mmc3.c @@ -68,14 +68,14 @@ uint8_t MMC3_getMirroring (void) { return MMC3_mirroring; } -DECLFR (MMC3_readWRAM) { +static DECLFR (MMC3_readWRAM) { if (MMC3_wramControl &0x80 || MMC3_type == MMC3_TYPE_AX5202P || MMC3_type == MMC3_TYPE_MMC6) return MMC3_cbReadWRAM? MMC3_cbReadWRAM(A): CartBR(A); else return A >>8; } -DECLFW (MMC3_writeWRAM) { +static DECLFW (MMC3_writeWRAM) { if ((MMC3_wramControl &0x80 || MMC3_type == MMC3_TYPE_AX5202P) && ~MMC3_wramControl &0x40 || MMC3_type == MMC3_TYPE_MMC6) { CartBW(A, V); if (MMC3_cbWriteWRAM) MMC3_cbWriteWRAM(A, V); @@ -101,11 +101,11 @@ void MMC3_syncCHR (int AND, int OR) { for (bank = 0; bank < 8; bank++) setchr1(bank <<10, MMC3_cbGetCHRBank(bank) &AND |OR); } -void MMC3_syncMirror () { +void MMC3_syncMirror(void) { setmirror(MMC3_mirroring &1? MI_H: MI_V); } -void MMC3_clockCounter () { +void MMC3_clockCounter(void) { uint8_t prevCounter = MMC3_counter; if (MMC3_reloadRequest || !MMC3_counter) MMC3_counter = MMC3_reloadValue; @@ -115,7 +115,7 @@ void MMC3_clockCounter () { MMC3_reloadRequest = 0; } -void MMC3_clockCounter_KickMaster () { +void MMC3_clockCounter_KickMaster(void) { if (scanline == 238) MMC3_clockCounter(); MMC3_clockCounter(); } @@ -134,7 +134,7 @@ DECLFW(MMC3_writeReg) { if (A <0xC000) MMC3_cbSync(); } -void MMC3_clear () { +void MMC3_clear(void) { MMC3_reg[0] = 0; MMC3_reg[1] = 2; MMC3_reg[2] = 4; MMC3_reg[3] = 5; MMC3_reg[4] = 6; MMC3_reg[5] = 7; MMC3_reg[6] = 0; MMC3_reg[7] = 1; MMC3_index = MMC3_mirroring = MMC3_wramControl = MMC3_reloadValue = MMC3_reloadRequest = MMC3_irqEnable = MMC3_counter = 0; MMC3_cbSync(); @@ -166,7 +166,7 @@ void MMC3_activate (uint8_t clear, void (*sync)(), uint8_t type, int (*prg)(uint MMC3_cbSync(); } -void MMC3_addExState () { +void MMC3_addExState(void) { AddExState(MMC3_state, ~0, 0, 0); } @@ -174,7 +174,7 @@ void MMC3_restore (int version) { MMC3_cbSync(); } -void MMC3_power () { +void MMC3_power(void) { MMC3_setHandlers(); MMC3_clear(); } diff --git a/src/boards/asic_mmc3.h b/src/boards/asic_mmc3.h index 83ab3cd..738bac2 100644 --- a/src/boards/asic_mmc3.h +++ b/src/boards/asic_mmc3.h @@ -33,15 +33,15 @@ int MMC3_getCHRBank (uint8_t); uint8_t MMC3_getMirroring (void); void MMC3_syncPRG (int, int); void MMC3_syncCHR (int, int); -void MMC3_syncMirror (); -void MMC3_clockCounter (); -void MMC3_clockCounter_KickMaster (); +void MMC3_syncMirror(void); +void MMC3_clockCounter(void); +void MMC3_clockCounter_KickMaster(void); DECLFW (MMC3_writeReg); -void MMC3_clear (); +void MMC3_clear(void); void MMC3_activate (uint8_t, void (*)(), uint8_t, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*))); -void MMC3_addExState(); +void MMC3_addExState(void); void MMC3_restore (int); -void MMC3_power (); +void MMC3_power(void); void MMC3_init (CartInfo *, void (*)(), uint8_t, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*))); #endif diff --git a/src/boards/asic_n118.c b/src/boards/asic_n118.c index 8b2f27f..e5379e2 100644 --- a/src/boards/asic_n118.c +++ b/src/boards/asic_n118.c @@ -59,7 +59,7 @@ DECLFW (N118_writeReg) { N118_index = V; } -void N118_clear () { +void N118_clear(void) { N118_reg[0] = 0; N118_reg[1] = 2; N118_reg[2] = 4; N118_reg[3] = 5; N118_reg[4] = 6; N118_reg[5] = 7; N118_reg[6] = 0; N118_reg[7] = 1; N118_index = 0; N118_cbSync(); @@ -86,7 +86,7 @@ void N118_activate (uint8_t clear, void (*sync)(), int (*prg)(uint8_t), int (*ch N118_cbSync(); } -void N118_addExState () { +void N118_addExState(void) { AddExState(N118_state, ~0, 0, 0); } @@ -94,7 +94,7 @@ void N118_restore (int version) { N118_cbSync(); } -void N118_power () { +void N118_power(void) { N118_setHandlers(); N118_clear(); } diff --git a/src/boards/asic_n118.h b/src/boards/asic_n118.h index 8b7cde2..dc64863 100644 --- a/src/boards/asic_n118.h +++ b/src/boards/asic_n118.h @@ -26,11 +26,11 @@ int N118_getCHRBank (uint8_t); void N118_syncPRG (int, int); void N118_syncCHR (int, int); DECLFW (N118_writeReg); -void N118_clear (); +void N118_clear(void); void N118_activate (uint8_t, void (*)(), int (*)(uint8_t), int (*)(uint8_t)); -void N118_addExState(); +void N118_addExState(void); void N118_restore (int); -void N118_power (); +void N118_power(void); void N118_init (CartInfo *, void (*)(), int (*)(uint8_t), int (*)(uint8_t)); #endif diff --git a/src/boards/asic_pt8154.c b/src/boards/asic_pt8154.c index 4e57bef..85b4319 100644 --- a/src/boards/asic_pt8154.c +++ b/src/boards/asic_pt8154.c @@ -40,7 +40,7 @@ void PT8154_syncCHR (int AND, int OR) { MMC3_syncCHR(AND, OR &~AND); } -void PT8154_syncMirror () { +void PT8154_syncMirror(void) { MMC3_syncMirror(); } @@ -56,7 +56,7 @@ DECLFW (PT8154_writeWRAM) { PT8154_cbSync(); } -void PT8154_clear () { +void PT8154_clear(void) { PT8154_reg = 0; PT8154_cbSync(); } @@ -79,7 +79,7 @@ void PT8154_activate (uint8_t clear, void (*sync)()) { PT8154_cbSync(); } -void PT8154_addExState () { +void PT8154_addExState(void) { AddExState(PT8154_state, ~0, 0, 0); } @@ -87,7 +87,7 @@ void PT8154_restore (int version) { PT8154_cbSync(); } -void PT8154_power () { +void PT8154_power(void) { MMC3_power(); PT8154_setHandlers(); PT8154_clear(); diff --git a/src/boards/asic_pt8154.h b/src/boards/asic_pt8154.h index 9ffa0d6..de81bc1 100644 --- a/src/boards/asic_pt8154.h +++ b/src/boards/asic_pt8154.h @@ -23,14 +23,14 @@ void PT8154_syncPRG (int, int); void PT8154_syncCHR (int, int); -void PT8154_syncMirror (); +void PT8154_syncMirror(void); DECLFW (PT8154_writeExtra); DECLFW (PT8154_writeWRAM); -void PT8154_clear (); +void PT8154_clear(void); void PT8154_activate (uint8_t, void (*)()); -void PT8154_addExState (); +void PT8154_addExState(void); void PT8154_restore (int); -void PT8154_power (); +void PT8154_power(void); void PT8154_init (CartInfo *, void (*)()); #endif diff --git a/src/boards/asic_qj.c b/src/boards/asic_qj.c index 2bda197..4ffb220 100644 --- a/src/boards/asic_qj.c +++ b/src/boards/asic_qj.c @@ -38,16 +38,16 @@ void QJ_syncCHR (int AND, int OR) { MMC3_syncCHR(0x7F &AND, QJ_reg <<7 &AND | OR &~AND); } -void QJ_syncMirror () { +void QJ_syncMirror(void) { MMC3_syncMirror(); } -DECLFW (QJ_writeWRAM) { +static DECLFW (QJ_writeWRAM) { QJ_reg = V; QJ_cbSync(); } -void QJ_clear () { +void QJ_clear(void) { QJ_reg = 0; QJ_cbSync(); } @@ -69,7 +69,7 @@ void QJ_activate (uint8_t clear, void (*sync)()) { QJ_cbSync(); } -void QJ_addExState () { +void QJ_addExState(void) { AddExState(QJ_state, ~0, 0, 0); } @@ -77,7 +77,7 @@ void QJ_restore (int version) { QJ_cbSync(); } -void QJ_power () { +void QJ_power(void) { MMC3_power(); QJ_setHandlers(); QJ_clear(); diff --git a/src/boards/asic_qj.h b/src/boards/asic_qj.h index 3d58f5a..e7431cf 100644 --- a/src/boards/asic_qj.h +++ b/src/boards/asic_qj.h @@ -24,13 +24,13 @@ void QJ_syncWRAM (int); void QJ_syncPRG (int, int); void QJ_syncCHR (int, int); -void QJ_syncMirror (); +void QJ_syncMirror(void); DECLFW (QJ_write); -void QJ_clear (); +void QJ_clear(void); void QJ_activate (uint8_t, void (*)()); -void QJ_addExState (); +void QJ_addExState(void); void QJ_restore (int); -void QJ_power (); +void QJ_power(void); void QJ_init (CartInfo *, void (*)()); #endif diff --git a/src/boards/asic_tc3294.c b/src/boards/asic_tc3294.c index 2871477..05b3b67 100644 --- a/src/boards/asic_tc3294.c +++ b/src/boards/asic_tc3294.c @@ -48,7 +48,7 @@ void TC3294_syncCHR (int AND, int OR) { MMC3_syncCHR(chrAND &AND, chrOR &~chrAND &AND | OR &~AND); } -void TC3294_syncMirror () { +void TC3294_syncMirror(void) { MMC3_syncMirror(); } @@ -59,7 +59,7 @@ DECLFW(TC3294_writeReg) { } } -void TC3294_clear () { +void TC3294_clear(void) { TC3294_reg[0] = 0x00; TC3294_reg[1] = 0x00; TC3294_reg[2] = 0x0F; TC3294_reg[3] = 0x00; TC3294_index = 0; TC3294_cbSync(); @@ -82,7 +82,7 @@ void TC3294_activate (uint8_t clear, void (*sync)()) { TC3294_cbSync(); } -void TC3294_addExState () { +void TC3294_addExState(void) { AddExState(TC3294_state, ~0, 0, 0); } @@ -90,7 +90,7 @@ void TC3294_restore (int version) { TC3294_cbSync(); } -void TC3294_power () { +void TC3294_power(void) { MMC3_power(); TC3294_setHandlers(); TC3294_clear(); diff --git a/src/boards/asic_tc3294.h b/src/boards/asic_tc3294.h index 1a75ac2..ecd8c45 100644 --- a/src/boards/asic_tc3294.h +++ b/src/boards/asic_tc3294.h @@ -25,13 +25,13 @@ extern uint8_t TC3294_reg[4]; void TC3294_syncWRAM (int); void TC3294_syncPRG (int, int); void TC3294_syncCHR (int, int); -void TC3294_syncMirror (); +void TC3294_syncMirror(void); DECLFW (TC3294_writeReg); -void TC3294_clear (); +void TC3294_clear(void); void TC3294_activate (uint8_t, void (*)()); -void TC3294_addExState (); +void TC3294_addExState(void); void TC3294_restore (int); -void TC3294_power (); +void TC3294_power(void); void TC3294_init (CartInfo *, void (*)()); #endif diff --git a/src/boards/asic_vrc1.c b/src/boards/asic_vrc1.c index 862c56c..c94b73b 100644 --- a/src/boards/asic_vrc1.c +++ b/src/boards/asic_vrc1.c @@ -41,7 +41,7 @@ void VRC1_syncCHR (int AND, int OR) { setchr4(0x1000, (VRC1_reg[7] &0x0F | VRC1_reg[1] <<2 &0x10) &AND |OR); } -void VRC1_syncMirror () { +void VRC1_syncMirror(void) { setmirror(VRC1_reg[1] &0x01? MI_H: MI_V); } @@ -50,7 +50,7 @@ DECLFW (VRC1_writeReg) { VRC1_cbSync(); } -void VRC1_clear () { +void VRC1_clear(void) { VRC1_reg[0] = 0x00; VRC1_reg[1] = 0; VRC1_reg[2] = 2; VRC1_reg[3] = 0;VRC1_reg[4] = 0x00; VRC1_reg[5] = 0; VRC1_reg[6] = 2; VRC1_reg[7] = 0; VRC1_cbSync(); } @@ -73,7 +73,7 @@ void VRC1_activate (uint8_t clear, void (*sync)()) { VRC1_cbSync(); } -void VRC1_addExState () { +void VRC1_addExState(void) { AddExState(VRC1_state, ~0, 0, 0); } @@ -81,7 +81,7 @@ void VRC1_restore (int version) { VRC1_cbSync(); } -void VRC1_power () { +void VRC1_power(void) { VRC1_setHandlers(); VRC1_clear(); } diff --git a/src/boards/asic_vrc1.h b/src/boards/asic_vrc1.h index ea65f28..cdbcc43 100644 --- a/src/boards/asic_vrc1.h +++ b/src/boards/asic_vrc1.h @@ -23,13 +23,13 @@ void VRC1_syncPRG (int, int); void VRC1_syncCHR (int, int); -void VRC1_syncMirror (); +void VRC1_syncMirror(void); DECLFW (VRC1_writeReg); -void VRC1_clear (); +void VRC1_clear(void); void VRC1_activate (uint8_t, void (*)()); -void VRC1_addExState (); +void VRC1_addExState(void); void VRC1_restore (int); -void VRC1_power (); +void VRC1_power(void); void VRC1_init (CartInfo *, void (*)()); #endif diff --git a/src/boards/asic_vrc2and4.c b/src/boards/asic_vrc2and4.c index 5bb7428..e81316c 100644 --- a/src/boards/asic_vrc2and4.c +++ b/src/boards/asic_vrc2and4.c @@ -99,7 +99,7 @@ int VRC24_getCHRBank (uint8_t bank) { return VRC24_chr[bank &7]; } -void VRC24_syncMirror () { +void VRC24_syncMirror(void) { setmirror(VRC24_isVRC4 && VRC24_mirroring &2? (VRC24_mirroring &1? MI_1: MI_0): (VRC24_mirroring &1? MI_H: MI_V)); } @@ -194,7 +194,7 @@ void FP_FASTAPASS(1) VRC4_cpuCycle (int a) { } } -void VRC24_clear () { +void VRC24_clear(void) { VRC24_prg[0] = 0; VRC24_prg[1] = 0; VRC24_chr[0] = 0; VRC24_chr[1] = 1; VRC24_chr[2] = 2; VRC24_chr[3] = 3; VRC24_chr[4] = 4; VRC24_chr[5] = 5; VRC24_chr[6] = 6; VRC24_chr[7] = 7; VRC24_mirroring = VRC2_pins = VRC4_latch = VRC4_mode = VRC4_count = VRC4_cycles = 0; @@ -263,17 +263,17 @@ void VRC4_activate (uint8_t clear, void (*sync)(), int A0, int A1, uint8_t useRe VRC24_cbSync(); } -void VRC2_addExState () { +void VRC2_addExState(void) { AddExState(VRC24_stateRegs, ~0, 0, 0); AddExState(VRC2_stateRegs, ~0, 0, 0); } -void VRC4_addExState () { +void VRC4_addExState(void) { AddExState(VRC24_stateRegs, ~0, 0, 0); AddExState(VRC4_stateRegs, ~0, 0, 0); } -void VRC24_addExState () { +void VRC24_addExState(void) { AddExState(VRC24_stateRegs, ~0, 0, 0); AddExState(VRC2_stateRegs, ~0, 0, 0); AddExState(VRC4_stateRegs, ~0, 0, 0); @@ -283,7 +283,7 @@ void VRC24_restore (int version) { VRC24_cbSync(); } -void VRC24_power () { +void VRC24_power(void) { VRC24_setHandlers(); VRC24_clear(); } diff --git a/src/boards/asic_vrc2and4.h b/src/boards/asic_vrc2and4.h index aceccd0..265d484 100644 --- a/src/boards/asic_vrc2and4.h +++ b/src/boards/asic_vrc2and4.h @@ -33,19 +33,19 @@ void VRC24_syncPRG (int, int); void VRC24_syncCHR (int, int); int VRC24_getPRGBank (uint8_t); int VRC24_getCHRBank (uint8_t); -void VRC24_syncMirror (); +void VRC24_syncMirror(void); DECLFW(VRC24_writeReg); void FP_FASTAPASS(1) VRC4_cpuCycle(int); void VRC24_reconfigure (int, int); -void VRC24_clear (); +void VRC24_clear(void); void VRC2_activate (uint8_t, void (*)(), int, int, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*))); void VRC4_activate (uint8_t, void (*)(), int, int, uint8_t, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*)), DECLFW((*))); -void VRC2_addExState (); -void VRC4_addExState (); -void VRC24_addExState (); +void VRC2_addExState(void); +void VRC4_addExState(void); +void VRC24_addExState(void); void VRC24_restore (int); -void VRC24_power (); +void VRC24_power(void); void VRC2_init (CartInfo *, void (*)(), int, int, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*))); void VRC4_init (CartInfo *, void (*)(), int, int, uint8_t, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*)), DECLFW((*))); diff --git a/src/boards/asic_vrc3.c b/src/boards/asic_vrc3.c index 1b76132..9f60394 100644 --- a/src/boards/asic_vrc3.c +++ b/src/boards/asic_vrc3.c @@ -71,7 +71,7 @@ DECLFW (VRC3_write) { } } -void FP_FASTAPASS(1) VRC3_cpuCycle (int a) { +static void FP_FASTAPASS(1) VRC3_cpuCycle (int a) { while (a--) { int mask = VRC3_irq &4? 0xFF: 0xFFFF; if ((VRC3_count++ &mask) == mask) { @@ -81,7 +81,7 @@ void FP_FASTAPASS(1) VRC3_cpuCycle (int a) { } } -void VRC3_clear () { +void VRC3_clear(void) { VRC3_prg = VRC3_irq = VRC3_count = VRC3_reload = 0; X6502_IRQEnd(FCEU_IQEXT); VRC3_cbSync(); @@ -107,7 +107,7 @@ void VRC3_activate (uint8_t clear, void (*sync)()) { VRC3_cbSync(); } -void VRC3_addExState () { +void VRC3_addExState(void) { AddExState(VRC3_state, ~0, 0, 0); } @@ -115,7 +115,7 @@ void VRC3_restore (int version) { VRC3_cbSync(); } -void VRC3_power () { +void VRC3_power(void) { VRC3_setHandlers(); VRC3_clear(); } diff --git a/src/boards/asic_vrc3.h b/src/boards/asic_vrc3.h index ed646a7..7916a62 100644 --- a/src/boards/asic_vrc3.h +++ b/src/boards/asic_vrc3.h @@ -25,11 +25,11 @@ void VRC3_syncWRAM (int); void VRC3_syncPRG (int, int); void VRC3_syncCHR (int, int); DECLFW (VRC3_write); -void VRC3_clear (); +void VRC3_clear(void); void VRC3_activate (uint8_t, void (*)()); -void VRC3_addExState (); +void VRC3_addExState(void); void VRC3_restore (int); -void VRC3_power (); +void VRC3_power(void); void VRC3_init (CartInfo *, void (*)()); #endif diff --git a/src/boards/asic_vrc6.c b/src/boards/asic_vrc6.c index 0e79747..24b5407 100644 --- a/src/boards/asic_vrc6.c +++ b/src/boards/asic_vrc6.c @@ -68,7 +68,7 @@ void VRC6_syncCHR (int AND, int OR) { setchr1(0x1C00, VRC6_cbGetCHRBank(7) &AND | OR); } -void VRC6_syncMirror () { /* Only emulates features used by known games, meaning mode 0 with CHR A10 substitution */ +void VRC6_syncMirror(void) { /* Only emulates features used by known games, meaning mode 0 with CHR A10 substitution */ setmirror(VRC6_misc &8? (VRC6_misc &4? MI_1: MI_0): VRC6_misc &4? MI_H: MI_V); } @@ -90,7 +90,7 @@ DECLFR (VRC6_readWRAM) { return A >>8; } -DECLFW (VRC6_writeWRAM) { +static DECLFW (VRC6_writeWRAM) { if (VRC6_misc &0x80) { CartBW(A, V); if (VRC6_cbWriteWRAM) VRC6_cbWriteWRAM(A, V); @@ -151,7 +151,7 @@ void FP_FASTAPASS(1) VRC6_cpuCycle (int a) { } } -void VRC6_clear () { +void VRC6_clear(void) { VRC6_prg[0] = 0; VRC6_prg[1] = 0xFE; VRC6_chr[0] = 0; VRC6_chr[1] = 1; VRC6_chr[2] = 2; VRC6_chr[3] = 3; VRC6_chr[4] = 4; VRC6_chr[5] = 5; VRC6_chr[6] = 6; VRC6_chr[7] = 7; VRC6_misc = VRC6_latch = VRC6_mode = VRC6_count = VRC6_cycles = 0; @@ -185,7 +185,7 @@ void VRC6_activate (uint8_t clear, void (*sync)(), int A0, int A1, int (*prg)(ui VRC6_cbSync(); } -void VRC6_addExState () { +void VRC6_addExState(void) { AddExState(VRC6_stateRegs, ~0, 0, 0); } @@ -193,7 +193,7 @@ void VRC6_restore (int version) { VRC6_cbSync(); } -void VRC6_power () { +void VRC6_power(void) { VRC6_setHandlers(); VRC6_clear(); } diff --git a/src/boards/asic_vrc6.h b/src/boards/asic_vrc6.h index e9c4a14..b30c982 100644 --- a/src/boards/asic_vrc6.h +++ b/src/boards/asic_vrc6.h @@ -24,18 +24,18 @@ void VRC6_syncWRAM (int); void VRC6_syncPRG (int, int); void VRC6_syncCHR (int, int); -void VRC6_syncMirror (); +void VRC6_syncMirror(void); int VRC6_getPRGBank (uint8_t); int VRC6_getCHRBank (uint8_t); DECLFR(VRC6_readWRAM); DECLFW(MMC3_writeWRAM); DECLFW(VRC6_writeReg); void FP_FASTAPASS(1) VRC6_cpuCycle (int); -void VRC6_clear (); +void VRC6_clear(void); void VRC6_activate (uint8_t, void (*)(), int, int, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*))); -void VRC6_addExState (); +void VRC6_addExState(void); void VRC6_restore (int); -void VRC6_power (); +void VRC6_power(void); void VRC6_init (CartInfo *, void (*)(), int, int, int (*)(uint8_t), int (*)(uint8_t), DECLFR((*)), DECLFW((*))); #endif \ No newline at end of file diff --git a/src/boards/asic_vrc7.c b/src/boards/asic_vrc7.c index 804dcc9..2041464 100644 --- a/src/boards/asic_vrc7.c +++ b/src/boards/asic_vrc7.c @@ -64,7 +64,7 @@ void VRC7_syncCHR (int AND, int OR) { setchr1(0x1C00, VRC7_chr[7] &AND | OR); } -void VRC7_syncMirror () { +void VRC7_syncMirror(void) { setmirror(VRC7_misc &2? (VRC7_misc &1? MI_1: MI_0): VRC7_misc &1? MI_H: MI_V); } @@ -72,7 +72,7 @@ DECLFR (VRC7_readWRAM) { return VRC7_misc &0x80? CartBR(A): A >>8; } -DECLFW (VRC7_writeWRAM) { +static DECLFW (VRC7_writeWRAM) { if (VRC7_misc &0x80) CartBW(A, V); } @@ -128,7 +128,7 @@ void FP_FASTAPASS(1) VRC7_cpuCycle (int a) { } } -void VRC7_clear () { +void VRC7_clear(void) { VRC7_prg[0] = 0; VRC7_prg[1] = 1; VRC7_prg[2] = 0xFE; VRC7_chr[0] = 0; VRC7_chr[1] = 1; VRC7_chr[2] = 2; VRC7_chr[3] = 3; VRC7_chr[4] = 4; VRC7_chr[5] = 5; VRC7_chr[6] = 6; VRC7_chr[7] = 7; VRC7_misc = VRC7_latch = VRC7_mode = VRC7_count = VRC7_cycles = 0; @@ -157,7 +157,7 @@ void VRC7_activate (uint8_t clear, void (*sync)(), int A0) { VRC7_cbSync(); } -void VRC7_addExState () { +void VRC7_addExState(void) { AddExState(VRC7_stateRegs, ~0, 0, 0); } @@ -165,7 +165,7 @@ void VRC7_restore (int version) { VRC7_cbSync(); } -void VRC7_power () { +void VRC7_power(void) { VRC7_setHandlers(); VRC7_clear(); } diff --git a/src/boards/asic_vrc7.h b/src/boards/asic_vrc7.h index 975c0bb..7e21adf 100644 --- a/src/boards/asic_vrc7.h +++ b/src/boards/asic_vrc7.h @@ -24,16 +24,16 @@ void VRC7_syncWRAM (int); void VRC7_syncPRG (int, int); void VRC7_syncCHR (int, int); -void VRC7_syncMirror (); +void VRC7_syncMirror(void); DECLFR(VRC7_readWRAM); DECLFW(MMC3_writeWRAM); DECLFW(VRC7_writeReg); void FP_FASTAPASS(1) VRC7_cpuCycle (int); -void VRC7_clear (); +void VRC7_clear(void); void VRC7_activate (uint8_t, void (*)(), int); -void VRC7_addExState (); +void VRC7_addExState(void); void VRC7_restore (int); -void VRC7_power (); +void VRC7_power(void); void VRC7_init (CartInfo *, void (*)(), int); #endif \ No newline at end of file diff --git a/src/boards/cartram.c b/src/boards/cartram.c index befdcb3..4c46cdb 100644 --- a/src/boards/cartram.c +++ b/src/boards/cartram.c @@ -26,7 +26,7 @@ static uint8_t *WRAMData = NULL; uint32_t CHRRAMSize = 0; uint32_t WRAMSize = 0; -void CartRAM_close (void) { /* Need to combine this in one function to avoid the problem of having to properly cascade two separate Close() functions for WRAM and CHR-RAM each */ +static void CartRAM_close (void) { /* Need to combine this in one function to avoid the problem of having to properly cascade two separate Close() functions for WRAM and CHR-RAM each */ if (WRAMData) { FCEU_gfree(WRAMData); WRAMData = NULL; @@ -38,7 +38,7 @@ void CartRAM_close (void) { /* Need to combine this in one function to avoid the } void CartRAM_init (CartInfo *info, uint8_t defaultWRAMSizeKiB, uint8_t defaultCHRRAMSizeKiB) { - WRAMSize = info->iNES2? (info->PRGRamSize +info->PRGRamSaveSize): (defaultWRAMSizeKiB *1024); + WRAMSize = CartInfo_PRGRAM_bytes(info, (uint32_t)defaultWRAMSizeKiB * 1024); if (WRAMSize) { WRAMData = (uint8_t*)FCEU_gmalloc(WRAMSize); SetupCartPRGMapping(0x10, WRAMData, WRAMSize, 1); @@ -48,7 +48,7 @@ void CartRAM_init (CartInfo *info, uint8_t defaultWRAMSizeKiB, uint8_t defaultCH info->SaveGameLen[0] = info->iNES2? (uint32_t)info->PRGRamSaveSize: WRAMSize; } } - CHRRAMSize = info->iNES2? (info->CHRRamSize +info->CHRRamSaveSize): (defaultCHRRAMSizeKiB *1024); + CHRRAMSize = CartInfo_CHRRAM_bytes(info, (uint32_t)defaultCHRRAMSizeKiB * 1024); if (ROM_size == 0) CHRRAMSize = 0; /* If there is no CHR-ROM, then any CHR-RAM will not be "extra" and therefore will be handled by ines.c, not here. */ if (CHRRAMSize) { CHRRAMData = (uint8_t*)FCEU_gmalloc(CHRRAMSize); diff --git a/src/boards/cartram.h b/src/boards/cartram.h index bc1ef03..08a9c7e 100644 --- a/src/boards/cartram.h +++ b/src/boards/cartram.h @@ -26,6 +26,5 @@ extern uint32_t WRAMSize; void CartRAM_init (CartInfo *, uint8_t, uint8_t); void CHRRAM_init (CartInfo *, uint8_t); void WRAM_init (CartInfo *, uint8_t); -void CartRAM_close (); #endif diff --git a/src/boards/cheapocabra.c b/src/boards/cheapocabra.c index 81cf7d3..1f23c3b 100644 --- a/src/boards/cheapocabra.c +++ b/src/boards/cheapocabra.c @@ -1,268 +1,268 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* mapper 111 - Cheapocabra board by Memblers - * http://forums.nesdev.com/viewtopic.php?p=146039 - * - * 512k PRG-ROM in 32k pages (flashable if battery backed is specified) - * 32k CHR-RAM used as: - * 2 x 8k pattern pages - * 2 x 8k nametable pages - * - * Notes: - * - CHR-RAM for nametables maps to $3000-3FFF as well, but FCEUX internally mirrors to 4k? - */ - -#include "mapinc.h" - -static uint8_t reg; -static uint8_t *CHRRAM = NULL; -static uint32_t CHRRAMSIZE; - -static uint8_t flash = 0; -static uint8_t flash_mode; -static uint8_t flash_sequence; -static uint8_t flash_id; -static uint8_t *FLASHROM = NULL; -static uint32_t FLASHROMSIZE; - -static SFORMAT StateRegs[] = { - { ®, 1, "REG" }, - { 0 } -}; - -static SFORMAT FlashRegs[] = { - { &flash_mode, 1, "FMOD" }, - { &flash_sequence, 1, "FSEQ" }, - { &flash_id, 1, "FMID" }, - { 0 } -}; - -static void Sync(void) { - /* bit 7 controls green LED */ - /* bit 6 controls red LED */ - uint32_t prg_chip = flash ? 0x10 : 0; - int nt = (reg & 0x20) ? 8192 : 0; /* bit 5 controls 8k nametable page */ - int chr = (reg & 0x10) ? 1 : 0; /* bit 4 selects 8k CHR page */ - int prg = (reg & 0x0F); /* bits 0-3 select 32k PRG page */ - int n = 0; - - nt += (16 * 1024); - for (n = 0; n < 4; ++n) { - setntamem(CHRRAM + nt + (1024 * n), 1, n); - } - setchr8r(0x10, chr); - setprg32r(prg_chip, 0x8000, prg); -} - -static DECLFW(M111Write) { - if ((A >= 0x5000 && A <= 0x5FFF) || (A >= 0x7000 && A <= 0x7FFF)) { - reg = V; - Sync(); - } -} - -static DECLFR(M111FlashID) { - /* Software ID mode is undefined by the datasheet for all but the lowest 2 addressable bytes, - * but some tests of the chip currently being used found it repeats in 512-byte patterns. - * http://forums.nesdev.com/viewtopic.php?p=178728#p178728 - */ - - uint32_t aid = A & 0x1FF; - switch (aid) { - case 0: - return 0xBF; - case 1: - return 0xB7; - default: - return 0xFF; - } -} - -void M111FlashIDEnter() { - if (flash_id) - return; - flash_id = 1; - SetReadHandler(0x8000, 0xFFFF, M111FlashID); -} - -void M111FlashIDExit() { - if (!flash_id) - return; - flash_id = 0; - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -enum { - FLASH_MODE_READY = 0, - FLASH_MODE_COMMAND, - FLASH_MODE_BYTE_WRITE, - FLASH_MODE_ERASE, -}; - -static DECLFW(M111Flash) { - uint32_t flash_addr = 0; - uint32_t command_addr = 0; - - if (A < 0x8000 || A > 0xFFFF) - return; - - flash_addr = ((reg & 0x0F) << 15) | (A & 0x7FFF); - command_addr = flash_addr & 0x7FFF; - - switch (flash_mode) { - default: - case FLASH_MODE_READY: - if (command_addr == 0x5555 && V == 0xAA) { - flash_mode = FLASH_MODE_COMMAND; - flash_sequence = 0; - } else if (V == 0xF0) { - M111FlashIDExit(); - } - break; - case FLASH_MODE_COMMAND: - if (flash_sequence == 0) { - if (command_addr == 0x2AAA && V == 0x55) - flash_sequence = 1; - else - flash_mode = FLASH_MODE_READY; - } else if (flash_sequence == 1) { - if (command_addr == 0x5555) { - flash_sequence = 0; - switch (V) { - default: - flash_mode = FLASH_MODE_READY; - break; - case 0xA0: - flash_mode = FLASH_MODE_BYTE_WRITE; - break; - case 0x80: - flash_mode = FLASH_MODE_ERASE; - break; - case 0x90: - M111FlashIDEnter(); - flash_mode = FLASH_MODE_READY; - break; - case 0xF0: - M111FlashIDExit(); - flash_mode = FLASH_MODE_READY; - break; - } - } else - flash_mode = FLASH_MODE_READY; - } else - flash_mode = FLASH_MODE_READY; /* should be unreachable */ - break; - case FLASH_MODE_BYTE_WRITE: - FLASHROM[flash_addr] &= V; - flash_mode = FLASH_MODE_READY; - break; - case FLASH_MODE_ERASE: - if (flash_sequence == 0) { - if (command_addr == 0x5555 && V == 0xAA) - flash_sequence = 1; - else - flash_mode = FLASH_MODE_READY; - } else if (flash_sequence == 1) { - if (command_addr == 0x2AAA && V == 0x55) - flash_sequence = 2; - else - flash_mode = FLASH_MODE_READY; - } else if (flash_sequence == 2) { - if (command_addr == 0x5555 && V == 0x10) /* erase chip */ - { - memset(FLASHROM, 0xFF, FLASHROMSIZE); - } else if (V == 0x30) /* erase 4k sector */ - { - uint32_t sector = flash_addr & 0x7F000; - memset(FLASHROM + sector, 0xFF, 1024 * 4); - } - flash_mode = FLASH_MODE_READY; - } else - flash_mode = FLASH_MODE_READY; /* should be unreachable */ - break; - } -} - -static void M111Power(void) { - reg = 0xFF; - Sync(); - SetReadHandler(0x8000, 0xffff, CartBR); - SetWriteHandler(0x5000, 0x5fff, M111Write); - SetWriteHandler(0x7000, 0x7fff, M111Write); - - if (flash) { - flash_mode = 0; - flash_sequence = 0; - flash_id = 0; - SetWriteHandler(0x8000, 0xFFFF, M111Flash); - } -} - -static void M111Close(void) { - if (CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM = NULL; - - if (FLASHROM) - FCEU_gfree(FLASHROM); - FLASHROM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper111_Init(CartInfo* info) { - info->Power = M111Power; - info->Close = M111Close; - - CHRRAMSIZE = 1024 * 32; - CHRRAM = (uint8_t*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); - - flash = (info->battery != 0); - if (flash) { - uint32_t PRGSIZE = 0; - uint32_t w = 0; - uint32_t r = 0; - - FLASHROMSIZE = 1024 * 512; - FLASHROM = (uint8_t*)FCEU_gmalloc(FLASHROMSIZE); - info->SaveGame[0] = FLASHROM; - info->SaveGameLen[0] = FLASHROMSIZE; - AddExState(FLASHROM, FLASHROMSIZE, 0, "FROM"); - AddExState(&FlashRegs, ~0, 0, 0); - - /* copy PRG ROM into FLASHROM, use it instead of PRG ROM */ - PRGSIZE = ROM_size * 16 * 1024; - for (w = 0, r = 0; w < FLASHROMSIZE; ++w) { - FLASHROM[w] = ROM[r]; - ++r; - if (r >= PRGSIZE) - r = 0; - } - SetupCartPRGMapping(0x10, FLASHROM, FLASHROMSIZE, 0); - } -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* mapper 111 - Cheapocabra board by Memblers + * http://forums.nesdev.com/viewtopic.php?p=146039 + * + * 512k PRG-ROM in 32k pages (flashable if battery backed is specified) + * 32k CHR-RAM used as: + * 2 x 8k pattern pages + * 2 x 8k nametable pages + * + * Notes: + * - CHR-RAM for nametables maps to $3000-3FFF as well, but FCEUX internally mirrors to 4k? + */ + +#include "mapinc.h" + +static uint8_t reg; +static uint8_t *CHRRAM = NULL; +static uint32_t CHRRAMSIZE; + +static uint8_t flash = 0; +static uint8_t flash_mode; +static uint8_t flash_sequence; +static uint8_t flash_id; +static uint8_t *FLASHROM = NULL; +static uint32_t FLASHROMSIZE; + +static SFORMAT StateRegs[] = { + { ®, 1, "REG" }, + { 0 } +}; + +static SFORMAT FlashRegs[] = { + { &flash_mode, 1, "FMOD" }, + { &flash_sequence, 1, "FSEQ" }, + { &flash_id, 1, "FMID" }, + { 0 } +}; + +static void Sync(void) { + /* bit 7 controls green LED */ + /* bit 6 controls red LED */ + uint32_t prg_chip = flash ? 0x10 : 0; + int nt = (reg & 0x20) ? 8192 : 0; /* bit 5 controls 8k nametable page */ + int chr = (reg & 0x10) ? 1 : 0; /* bit 4 selects 8k CHR page */ + int prg = (reg & 0x0F); /* bits 0-3 select 32k PRG page */ + int n = 0; + + nt += (16 * 1024); + for (n = 0; n < 4; ++n) { + setntamem(CHRRAM + nt + (1024 * n), 1, n); + } + setchr8r(0x10, chr); + setprg32r(prg_chip, 0x8000, prg); +} + +static DECLFW(M111Write) { + if ((A >= 0x5000 && A <= 0x5FFF) || (A >= 0x7000 && A <= 0x7FFF)) { + reg = V; + Sync(); + } +} + +static DECLFR(M111FlashID) { + /* Software ID mode is undefined by the datasheet for all but the lowest 2 addressable bytes, + * but some tests of the chip currently being used found it repeats in 512-byte patterns. + * http://forums.nesdev.com/viewtopic.php?p=178728#p178728 + */ + + uint32_t aid = A & 0x1FF; + switch (aid) { + case 0: + return 0xBF; + case 1: + return 0xB7; + default: + return 0xFF; + } +} + +static void M111FlashIDEnter() { + if (flash_id) + return; + flash_id = 1; + SetReadHandler(0x8000, 0xFFFF, M111FlashID); +} + +static void M111FlashIDExit() { + if (!flash_id) + return; + flash_id = 0; + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +enum { + FLASH_MODE_READY = 0, + FLASH_MODE_COMMAND, + FLASH_MODE_BYTE_WRITE, + FLASH_MODE_ERASE, +}; + +static DECLFW(M111Flash) { + uint32_t flash_addr = 0; + uint32_t command_addr = 0; + + if (A < 0x8000 || A > 0xFFFF) + return; + + flash_addr = ((reg & 0x0F) << 15) | (A & 0x7FFF); + command_addr = flash_addr & 0x7FFF; + + switch (flash_mode) { + default: + case FLASH_MODE_READY: + if (command_addr == 0x5555 && V == 0xAA) { + flash_mode = FLASH_MODE_COMMAND; + flash_sequence = 0; + } else if (V == 0xF0) { + M111FlashIDExit(); + } + break; + case FLASH_MODE_COMMAND: + if (flash_sequence == 0) { + if (command_addr == 0x2AAA && V == 0x55) + flash_sequence = 1; + else + flash_mode = FLASH_MODE_READY; + } else if (flash_sequence == 1) { + if (command_addr == 0x5555) { + flash_sequence = 0; + switch (V) { + default: + flash_mode = FLASH_MODE_READY; + break; + case 0xA0: + flash_mode = FLASH_MODE_BYTE_WRITE; + break; + case 0x80: + flash_mode = FLASH_MODE_ERASE; + break; + case 0x90: + M111FlashIDEnter(); + flash_mode = FLASH_MODE_READY; + break; + case 0xF0: + M111FlashIDExit(); + flash_mode = FLASH_MODE_READY; + break; + } + } else + flash_mode = FLASH_MODE_READY; + } else + flash_mode = FLASH_MODE_READY; /* should be unreachable */ + break; + case FLASH_MODE_BYTE_WRITE: + FLASHROM[flash_addr] &= V; + flash_mode = FLASH_MODE_READY; + break; + case FLASH_MODE_ERASE: + if (flash_sequence == 0) { + if (command_addr == 0x5555 && V == 0xAA) + flash_sequence = 1; + else + flash_mode = FLASH_MODE_READY; + } else if (flash_sequence == 1) { + if (command_addr == 0x2AAA && V == 0x55) + flash_sequence = 2; + else + flash_mode = FLASH_MODE_READY; + } else if (flash_sequence == 2) { + if (command_addr == 0x5555 && V == 0x10) /* erase chip */ + { + memset(FLASHROM, 0xFF, FLASHROMSIZE); + } else if (V == 0x30) /* erase 4k sector */ + { + uint32_t sector = flash_addr & 0x7F000; + memset(FLASHROM + sector, 0xFF, 1024 * 4); + } + flash_mode = FLASH_MODE_READY; + } else + flash_mode = FLASH_MODE_READY; /* should be unreachable */ + break; + } +} + +static void M111Power(void) { + reg = 0xFF; + Sync(); + SetReadHandler(0x8000, 0xffff, CartBR); + SetWriteHandler(0x5000, 0x5fff, M111Write); + SetWriteHandler(0x7000, 0x7fff, M111Write); + + if (flash) { + flash_mode = 0; + flash_sequence = 0; + flash_id = 0; + SetWriteHandler(0x8000, 0xFFFF, M111Flash); + } +} + +static void M111Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; + + if (FLASHROM) + FCEU_gfree(FLASHROM); + FLASHROM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper111_Init(CartInfo* info) { + info->Power = M111Power; + info->Close = M111Close; + + CHRRAMSIZE = 1024 * 32; + CHRRAM = (uint8_t*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + flash = (info->battery != 0); + if (flash) { + uint32_t PRGSIZE = 0; + uint32_t w = 0; + uint32_t r = 0; + + FLASHROMSIZE = 1024 * 512; + FLASHROM = (uint8_t*)FCEU_gmalloc(FLASHROMSIZE); + info->SaveGame[0] = FLASHROM; + info->SaveGameLen[0] = FLASHROMSIZE; + AddExState(FLASHROM, FLASHROMSIZE, 0, "FROM"); + AddExState(&FlashRegs, ~0, 0, 0); + + /* copy PRG ROM into FLASHROM, use it instead of PRG ROM */ + PRGSIZE = ROM_size * 16 * 1024; + for (w = 0, r = 0; w < FLASHROMSIZE; ++w) { + FLASHROM[w] = ROM[r]; + ++r; + if (r >= PRGSIZE) + r = 0; + } + SetupCartPRGMapping(0x10, FLASHROM, FLASHROMSIZE, 0); + } +} diff --git a/src/boards/eeprom_93Cx6.c b/src/boards/eeprom_93Cx6.c index de2b8ff..68477ad 100644 --- a/src/boards/eeprom_93Cx6.c +++ b/src/boards/eeprom_93Cx6.c @@ -47,7 +47,7 @@ void eeprom_93Cx6_init (size_t capacity, uint8_t wordSize) { } } -uint8_t eeprom_93Cx6_read () { +uint8_t eeprom_93Cx6_read (void) { return eeprom_93Cx6_output; } diff --git a/src/boards/eeprom_93Cx6.h b/src/boards/eeprom_93Cx6.h index bbf9739..3063514 100644 --- a/src/boards/eeprom_93Cx6.h +++ b/src/boards/eeprom_93Cx6.h @@ -5,6 +5,6 @@ extern uint8_t* eeprom_93Cx6_storage; void eeprom_93Cx6_init (size_t capacity, uint8_t wordSize); -uint8_t eeprom_93Cx6_read (); +uint8_t eeprom_93Cx6_read (void); void eeprom_93Cx6_write (uint8_t CS, uint8_t CLK, uint8_t DAT); #endif diff --git a/src/boards/fk23c.c b/src/boards/fk23c.c index 413bec0..38b0148 100644 --- a/src/boards/fk23c.c +++ b/src/boards/fk23c.c @@ -465,7 +465,7 @@ static void StateRestore(int version) Sync(); } -void Init(CartInfo *info) +static void Init(CartInfo *info) { /* Initialization for iNES and UNIF. subType and dipsw_enable must have been set. */ info->Power = Power; diff --git a/src/boards/jyasic.c b/src/boards/jyasic.c index cdeb83f..42117a1 100644 --- a/src/boards/jyasic.c +++ b/src/boards/jyasic.c @@ -440,7 +440,7 @@ static void JYASIC_restore (int version) sync(); } -void JYASIC_init (CartInfo *info) +static void JYASIC_init (CartInfo *info) { cpuWriteHandlersSet =0; info->Reset = JYASIC_reset; @@ -549,7 +549,7 @@ void Mapper282_Init(CartInfo *info) JYASIC_init(info); } -void sync295 (void) +static void sync295 (void) { syncPRG(0x0F, mode[3] <<4); syncCHR(0x7F, mode[3] <<7); @@ -564,7 +564,7 @@ void Mapper295_Init(CartInfo *info) JYASIC_init(info); } -void sync358 (void) +static void sync358 (void) { syncPRG(0x1F, mode[3] <<4 &~0x1F); if (mode[3] &0x20) @@ -587,7 +587,7 @@ void Mapper358_Init(CartInfo *info) JYASIC_init(info); } -void sync386 (void) +static void sync386 (void) { syncPRG(0x1F, mode[3] <<4 &0x20 | mode[3] <<3 &0x40); if (mode[3] &0x20) @@ -610,7 +610,7 @@ void Mapper386_Init(CartInfo *info) JYASIC_init(info); } -void sync387(void) +static void sync387(void) { syncPRG(0x0F, mode[3] <<3 &0x10 | mode[3] <<2 &0x20); if (mode[3] &0x20) @@ -633,7 +633,7 @@ void Mapper387_Init(CartInfo *info) JYASIC_init(info); } -void sync388 (void) +static void sync388 (void) { syncPRG(0x1F, mode[3] <<3 &0x60); @@ -657,7 +657,7 @@ void Mapper388_Init(CartInfo *info) JYASIC_init(info); } -void sync397 (void) +static void sync397 (void) { syncPRG(0x1F, mode[3] <<4 &~0x1F); syncCHR(0x7F, mode[3] <<7); @@ -672,7 +672,7 @@ void Mapper397_Init(CartInfo *info) JYASIC_init(info); } -void sync421 (void) +static void sync421 (void) { if (mode[3] &0x04) syncPRG(0x3F, mode[3] <<4 &~0x3F); @@ -692,7 +692,7 @@ void Mapper421_Init(CartInfo *info) /* Mapper 394: HSK007 circuit board that can simulate J.Y. ASIC, MMC3, and NROM. */ static uint8_t HSK007Reg[4]; -void sync394 (void) /* Called when J.Y. ASIC is active */ +static void sync394 (void) /* Called when J.Y. ASIC is active */ { int prgOR =HSK007Reg[3] <<1 &0x010 | HSK007Reg[1] <<5 &0x060; int chrOR =HSK007Reg[3] <<1 &0x080 | HSK007Reg[1] <<6 &0x100 | HSK007Reg[1] <<8 &0x200; diff --git a/src/boards/latch.c b/src/boards/latch.c index 9e20064..b86470c 100644 --- a/src/boards/latch.c +++ b/src/boards/latch.c @@ -1,98 +1,98 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2023 - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" -#include "latch.h" - -static uint8_t bus_conflict; -static uint8_t *WRAM = NULL; -static uint32_t WRAMSIZE; -static void (*WSync)(void); -static readfunc defread; - -LATCH latch; - -DECLFW(LatchWrite) { - /* FCEU_printf("bs %04x %02x\n",A,V); */ - if (bus_conflict) - V &= CartBR(A); - latch.addr = A; - latch.data = V; - WSync(); -} - -void LatchHardReset() { - latch.addr = 0; - latch.data = 0; - WSync(); -} - -void LatchPower(void) { - LatchHardReset(); - WSync(); - if (WRAM) { - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - } else { - SetReadHandler(0x8000, 0xFFFF, defread); - } - SetWriteHandler(0x8000, 0xFFFF, LatchWrite); -} - -void LatchClose(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void LatchReset(void) { - WSync(); -} - -static void StateRestore(int version) { - WSync(); -} - -void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, - uint8_t wram, uint8_t busc) { - bus_conflict = busc; - WSync = proc; - if (func != NULL) - defread = func; - else - defread = CartBROB; - info->Power = LatchPower; - info->Close = LatchClose; - info->Reset = LatchReset; - GameStateRestore = StateRestore; - if (wram) { - WRAMSIZE = 8192; - WRAM = (uint8_t *)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - } - AddExState(&latch.addr, 2, 0, "ADDR"); - AddExState(&latch.data, 1, 0, "DATA"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2023 + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mapinc.h" +#include "latch.h" + +static uint8_t bus_conflict; +static uint8_t *WRAM = NULL; +static uint32_t WRAMSIZE; +static void (*WSync)(void); +static readfunc defread; + +LATCH latch; + +DECLFW(LatchWrite) { + /* FCEU_printf("bs %04x %02x\n",A,V); */ + if (bus_conflict) + V &= CartBR(A); + latch.addr = A; + latch.data = V; + WSync(); +} + +void LatchHardReset(void) { + latch.addr = 0; + latch.data = 0; + WSync(); +} + +void LatchPower(void) { + LatchHardReset(); + WSync(); + if (WRAM) { + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + } else { + SetReadHandler(0x8000, 0xFFFF, defread); + } + SetWriteHandler(0x8000, 0xFFFF, LatchWrite); +} + +void LatchClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void LatchReset(void) { + WSync(); +} + +static void StateRestore(int version) { + WSync(); +} + +void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, + uint8_t wram, uint8_t busc) { + bus_conflict = busc; + WSync = proc; + if (func != NULL) + defread = func; + else + defread = CartBROB; + info->Power = LatchPower; + info->Close = LatchClose; + info->Reset = LatchReset; + GameStateRestore = StateRestore; + if (wram) { + WRAMSIZE = 8192; + WRAM = (uint8_t *)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + } + AddExState(&latch.addr, 2, 0, "ADDR"); + AddExState(&latch.data, 1, 0, "DATA"); +} diff --git a/src/boards/latch.h b/src/boards/latch.h index afaa557..5c31d05 100644 --- a/src/boards/latch.h +++ b/src/boards/latch.h @@ -12,6 +12,6 @@ void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint8_t wram, void LatchPower(void); void LatchClose(void); void LatchWrite(uint32_t A, uint8_t V); -void LatchHardReset(); +void LatchHardReset(void); #endif /* _FCEU_LATCH_H */ diff --git a/src/boards/mmc1.c b/src/boards/mmc1.c index b3cc327..703b529 100644 --- a/src/boards/mmc1.c +++ b/src/boards/mmc1.c @@ -401,15 +401,15 @@ void SL1ROM_Init(CartInfo *info) { similarly functioning boards? */ -void SL2ROM_Init(CartInfo *info) { +static void SL2ROM_Init(CartInfo *info) { GenMMC1Init(info, 256, 256, 0, 0); } -void SFROM_Init(CartInfo *info) { +static void SFROM_Init(CartInfo *info) { GenMMC1Init(info, 256, 256, 0, 0); } -void SHROM_Init(CartInfo *info) { +static void SHROM_Init(CartInfo *info) { GenMMC1Init(info, 256, 256, 0, 0); } diff --git a/src/boards/mmc2and4.c b/src/boards/mmc2and4.c index 191b61f..e1b4757 100644 --- a/src/boards/mmc2and4.c +++ b/src/boards/mmc2and4.c @@ -54,7 +54,7 @@ static void Sync(void) { setmirror(mirr); } -DECLFW(MMC2and4Write) { +static DECLFW(MMC2and4Write) { switch (A & 0xF000) { case 0xA000: preg = V & 0xF; Sync(); break; case 0xB000: creg[0] = V & 0x1F; Sync(); break; diff --git a/src/boards/mmc3.c b/src/boards/mmc3.c index 610565f..77d87db 100644 --- a/src/boards/mmc3.c +++ b/src/boards/mmc3.c @@ -1342,7 +1342,7 @@ static void GN45Power(void) { SetWriteHandler(0x7000, 0x7fff, GN45Write1); /* OK-411 boards, the same logic, but data latched, 2-in-1 frankenstein */ } -void GN45_Init(CartInfo *info) { +static void GN45_Init(CartInfo *info) { GenMMC3_Init(info, 128, 128, 8, 0); pwrap = GN45PW; cwrap = GN45CW; diff --git a/src/boards/mmc5.c b/src/boards/mmc5.c index d33186e..4792385 100644 --- a/src/boards/mmc5.c +++ b/src/boards/mmc5.c @@ -386,7 +386,7 @@ static DECLFR(MMC5_read) { return(X.DB); } -void MMC5Synco(void) { +static void MMC5Synco(void) { int x; MMC5PRG(); @@ -422,10 +422,11 @@ void MMC5Synco(void) { /* X6502_IRQEnd(FCEU_IQEXT); */ } -void MMC5_hb(int scanline) { +void MMC5_hb(int sl_param); +void MMC5_hb(int sl_param) { /* zero 24-jul-2014 - revised for newer understanding, to fix metal slader glory credits. see r7371 in bizhawk */ - int sl = scanline + 1; + int sl = sl_param + 1; int ppuon = (PPU[1] & 0x18); if (!ppuon || sl >= 241) @@ -460,7 +461,7 @@ void MMC5_hb(int scanline) { } -void MMC5_StateRestore(int version) { +static void MMC5_StateRestore(int version) { MMC5Synco(); } @@ -612,7 +613,7 @@ void MMC5RunSoundHQ(void) { Do5PCMHQ(); } -void MMC5HiSync(int32_t ts) { +static void MMC5HiSync(int32_t ts) { int x; for (x = 0; x < 3; x++) MMC5Sound.BC[x] = ts; @@ -627,7 +628,7 @@ void MMC5RunSound(int Count) { MMC5Sound.BC[x] = Count; } -void Mapper5_ESI(void) { +static void Mapper5_ESI(void) { GameExpSound.RChange = Mapper5_ESI; if (FSettings.SndRate) { if (FSettings.soundq >= 1) { @@ -659,6 +660,7 @@ void NSFMMC5_Init(void) { SetReadHandler(0x5205, 0x5206, MMC5_read); } +void NSFMMC5_Close(void); void NSFMMC5_Close(void) { if (WRAM) FCEU_gfree(WRAM); diff --git a/src/boards/n106.c b/src/boards/n106.c index 2ff1ed0..f4c57c1 100644 --- a/src/boards/n106.c +++ b/src/boards/n106.c @@ -44,7 +44,7 @@ static uint8_t gorko; static void NamcoSound(int Count); static void NamcoSoundHack(void); -static void DoNamcoSound(int32_t *Wave, int Count); +static void DoNamcoSound(int32_t *WaveBuf, int Count); static void DoNamcoSoundHQ(void); static void SyncHQ(int32_t ts); @@ -319,7 +319,7 @@ static void DoNamcoSoundHQ(void) { } -static void DoNamcoSound(int32_t *Wave, int Count) { +static void DoNamcoSound(int32_t *WaveBuf, int Count) { int P, V; for (P = 7; P >= 7 - ((IRAM[0x7F] >> 4) & 7); P--) { if ((IRAM[0x44 + (P << 3)] & 0xE0) && (IRAM[0x47 + (P << 3)] & 0xF)) { @@ -362,7 +362,7 @@ static void DoNamcoSound(int32_t *Wave, int Count) { duff &= 0xF; duff2 = (duff * envelope) >> 19; } - Wave[V >> 4] += duff2; + WaveBuf[V >> 4] += duff2; vco += 0x8000; } vcount[P] = vco; diff --git a/src/boards/onebus.c b/src/boards/onebus.c index 5b462e9..f2af158 100644 --- a/src/boards/onebus.c +++ b/src/boards/onebus.c @@ -371,7 +371,7 @@ static void StateRestore(int version) { Sync(); } -void UNLOneBus_Close(void) { +static void UNLOneBus_Close(void) { if (WRAM) FCEU_gfree(WRAM); WRAM = NULL; diff --git a/src/boards/unrom512.c b/src/boards/unrom512.c index a96ce18..5494060 100644 --- a/src/boards/unrom512.c +++ b/src/boards/unrom512.c @@ -70,7 +70,7 @@ static INLINE void setfpageptr(int s, uint32_t A, uint8_t *p) { } } -void setfprg16(uint32_t A, uint32_t V) { +static void setfprg16(uint32_t A, uint32_t V) { if (PRGsize[0] >= 16384) { V &= PRGmask16[0]; setfpageptr(16, A, flashdata ? (&flashdata[V << 14]) : 0); @@ -109,14 +109,14 @@ static INLINE void fwc_store(uint32_t idx, uint32_t v) { #endif } -void inc_flash_write_count(uint8_t bank, uint32_t A) { +static void inc_flash_write_count(uint8_t bank, uint32_t A) { uint32_t idx = (bank * 4) + ((A & 0x3000) >> 12); uint32_t v = fwc_load(idx) + 1; if (v == 0) v = 1; /* avoid wrap to 0 (which means "never written") */ fwc_store(idx, v); } -uint32_t GetFlashWriteCount(uint8_t bank, uint32_t A) { +static uint32_t GetFlashWriteCount(uint8_t bank, uint32_t A) { return fwc_load((bank * 4) + ((A & 0x3000) >> 12)); } diff --git a/src/boards/vrc6.c b/src/boards/vrc6.c index 90318e4..60de52f 100644 --- a/src/boards/vrc6.c +++ b/src/boards/vrc6.c @@ -316,7 +316,7 @@ static void DoSawVHQ(void) { cvbc[2] = SOUNDTS; } -void VRC6Sound(int Count) { +static void VRC6Sound(int Count) { int x; DoSQV1(); @@ -326,13 +326,13 @@ void VRC6Sound(int Count) { cvbc[x] = Count; } -void VRC6SoundHQ(void) { +static void VRC6SoundHQ(void) { DoSQV1HQ(); DoSQV2HQ(); DoSawVHQ(); } -void VRC6SyncHQ(int32_t ts) { +static void VRC6SyncHQ(int32_t ts) { int x; for (x = 0; x < 3; x++) cvbc[x] = ts; } diff --git a/src/boards/vrc7.c b/src/boards/vrc7.c index e0c462e..6b7e10a 100644 --- a/src/boards/vrc7.c +++ b/src/boards/vrc7.c @@ -45,7 +45,7 @@ static SFORMAT StateRegs[] = /* VRC7 Sound */ -void DoVRC7Sound(void) { +static void DoVRC7Sound(void) { int32_t z, a; if (FSettings.soundq >= 1) return; @@ -55,11 +55,11 @@ void DoVRC7Sound(void) { dwave += a; } -void UpdateOPLNEO(int32_t *Wave, int Count) { - OPLL_fillbuf(VRC7Sound, Wave, Count, 4); +static void UpdateOPLNEO(int32_t *WaveBuf, int Count) { + OPLL_fillbuf(VRC7Sound, WaveBuf, Count, 4); } -void UpdateOPL(int Count) { +static void UpdateOPL(int Count) { int32_t z, a; z = ((SOUNDTS << 16) / soundtsinc) >> 4; a = z - dwave; diff --git a/src/cart.h b/src/cart.h index 1861d55..48269d9 100644 --- a/src/cart.h +++ b/src/cart.h @@ -1,6 +1,8 @@ #ifndef _FCEU_CART_H #define _FCEU_CART_H +#include "fceu-types.h" + typedef struct { /* Set by mapper/board code: */ void (*Power)(void); @@ -107,4 +109,29 @@ void FCEU_OpenGenie(void); void FCEU_CloseGenie(void); void FCEU_KillGenie(void); +/* Helpers for the iNES1-vs-iNES2 sizing dichotomy. + * + * iNES1 headers don't carry explicit RAM-size fields, so mappers fall + * back to a default (typically 8 KiB WRAM). iNES2 headers do, in which + * case the runtime must use PRGRamSize + PRGRamSaveSize (resp. + * CHRRamSize + CHRRamSaveSize). This pattern was hand-coded at every + * site as `info->iNES2 ? (info->PRGRamSize + info->PRGRamSaveSize) + * : default_bytes`, which is verbose and easy to write inconsistently. + * + * These inline helpers centralise the rule. They return byte counts + * (caller divides by 1024 if it needs KiB). */ +static INLINE uint32_t CartInfo_PRGRAM_bytes(const CartInfo *info, uint32_t default_bytes) +{ + if (info->iNES2) + return (uint32_t)(info->PRGRamSize + info->PRGRamSaveSize); + return default_bytes; +} + +static INLINE uint32_t CartInfo_CHRRAM_bytes(const CartInfo *info, uint32_t default_bytes) +{ + if (info->iNES2) + return (uint32_t)(info->CHRRamSize + info->CHRRamSaveSize); + return default_bytes; +} + #endif diff --git a/src/cheat.c b/src/cheat.c index 71bdb0e..877827d 100644 --- a/src/cheat.c +++ b/src/cheat.c @@ -104,7 +104,7 @@ static DECLFR(SubCheatsRead) { return(0); /* We should never get here. */ } -void RebuildSubCheats(void) { +static void RebuildSubCheats(void) { int x; struct CHEATF *c = cheats; diff --git a/src/driver.h b/src/driver.h index 55e921e..8c2cda3 100644 --- a/src/driver.h +++ b/src/driver.h @@ -127,7 +127,7 @@ void FCEUI_SetBaseDirectory(const char *dir); /* Tells FCE Ultra to copy the palette data pointed to by pal and use it. Data pointed to by pal needs to be 64*3 bytes in length. */ -void FCEUI_SetPaletteArray(uint8_t *pal, int nEntries); +void FCEUI_SetPaletteArray(uint8_t *data, int nEntries); /* Sets up sound code to render sound at the specified rate, in samples per second. Only sample rates of 44100, 48000, and 96000 are currently diff --git a/src/drivers/libretro/libretro-common/streams/file_stream_transforms.c b/src/drivers/libretro/libretro-common/streams/file_stream_transforms.c index e94a311..33bcd3c 100644 --- a/src/drivers/libretro/libretro-common/streams/file_stream_transforms.c +++ b/src/drivers/libretro/libretro-common/streams/file_stream_transforms.c @@ -26,7 +26,7 @@ #include #include -RFILE* rfopen(const char *path, const char *mode) +static RFILE* rfopen(const char *path, const char *mode) { RFILE *output = NULL; unsigned int retro_mode = RETRO_VFS_FILE_ACCESS_READ; @@ -67,7 +67,7 @@ RFILE* rfopen(const char *path, const char *mode) return output; } -int rfclose(RFILE* stream) +static int rfclose(RFILE* stream) { if (!stream) return EOF; @@ -75,7 +75,7 @@ int rfclose(RFILE* stream) return filestream_close(stream); } -int64_t rftell(RFILE* stream) +static int64_t rftell(RFILE* stream) { if (!stream) return -1; @@ -83,7 +83,7 @@ int64_t rftell(RFILE* stream) return filestream_tell(stream); } -int64_t rfseek(RFILE* stream, int64_t offset, int origin) +static int64_t rfseek(RFILE* stream, int64_t offset, int origin) { int seek_position = -1; @@ -106,7 +106,7 @@ int64_t rfseek(RFILE* stream, int64_t offset, int origin) return filestream_seek(stream, offset, seek_position); } -int64_t rfread(void* buffer, +static int64_t rfread(void* buffer, size_t elem_size, size_t elem_count, RFILE* stream) { if (!stream || (elem_size == 0) || (elem_count == 0)) @@ -115,7 +115,7 @@ int64_t rfread(void* buffer, return (filestream_read(stream, buffer, elem_size * elem_count) / elem_size); } -char *rfgets(char *buffer, int maxCount, RFILE* stream) +static char *rfgets(char *buffer, int maxCount, RFILE* stream) { if (!stream) return NULL; @@ -123,7 +123,7 @@ char *rfgets(char *buffer, int maxCount, RFILE* stream) return filestream_gets(stream, buffer, maxCount); } -int rfgetc(RFILE* stream) +static int rfgetc(RFILE* stream) { if (!stream) return EOF; @@ -131,7 +131,7 @@ int rfgetc(RFILE* stream) return filestream_getc(stream); } -int64_t rfwrite(void const* buffer, +static int64_t rfwrite(void const* buffer, size_t elem_size, size_t elem_count, RFILE* stream) { if (!stream || (elem_size == 0) || (elem_count == 0)) @@ -140,7 +140,7 @@ int64_t rfwrite(void const* buffer, return (filestream_write(stream, buffer, elem_size * elem_count) / elem_size); } -int rfputc(int character, RFILE * stream) +static int rfputc(int character, RFILE * stream) { if (!stream) return EOF; @@ -148,7 +148,7 @@ int rfputc(int character, RFILE * stream) return filestream_putc(stream, character); } -int64_t rfflush(RFILE * stream) +static int64_t rfflush(RFILE * stream) { if (!stream) return EOF; @@ -156,7 +156,7 @@ int64_t rfflush(RFILE * stream) return filestream_flush(stream); } -int rfprintf(RFILE * stream, const char * format, ...) +static int rfprintf(RFILE * stream, const char * format, ...) { int result; va_list vl; @@ -170,17 +170,17 @@ int rfprintf(RFILE * stream, const char * format, ...) return result; } -int rferror(RFILE* stream) +static int rferror(RFILE* stream) { return filestream_error(stream); } -int rfeof(RFILE* stream) +static int rfeof(RFILE* stream) { return filestream_eof(stream); } -int rfscanf(RFILE * stream, const char * format, ...) +static int rfscanf(RFILE * stream, const char * format, ...) { int result; va_list vl; diff --git a/src/drivers/libretro/libretro-common/vfs/vfs_implementation.c b/src/drivers/libretro/libretro-common/vfs/vfs_implementation.c index 2d958fe..800d204 100644 --- a/src/drivers/libretro/libretro-common/vfs/vfs_implementation.c +++ b/src/drivers/libretro/libretro-common/vfs/vfs_implementation.c @@ -221,7 +221,7 @@ #define RFILE_HINT_UNBUFFERED (1 << 8) -int64_t retro_vfs_file_seek_internal( +static int64_t retro_vfs_file_seek_internal( libretro_vfs_implementation_file *stream, int64_t offset, int whence) { diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 41241c6..dc8d5b8 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -308,6 +308,7 @@ extern int zapper_sensor_invert_option; /* emulator-specific callback functions */ +const char *GetKeyboard(void); /* used by src/boards/transformer.c */ const char * GetKeyboard(void) { return ""; @@ -406,7 +407,7 @@ void FCEUD_DispMessage(enum retro_log_level level, unsigned duration, const char } } -void FCEUD_SoundToggle (void) +static void FCEUD_SoundToggle (void) { FCEUI_SetSoundVolume(sndvolume); } @@ -1904,20 +1905,20 @@ static void retro_set_custom_palette(void) */ static void FCEUD_RegionOverride(unsigned region) { - unsigned pal = 0; + unsigned is_pal = 0; unsigned d = 0; switch (region) { case 0: /* auto */ d = (systemRegion >> 1) & 1; - pal = systemRegion & 1; + is_pal = systemRegion & 1; break; case 1: /* ntsc */ FCEUD_DispMessage(RETRO_LOG_INFO, 2000, "System: NTSC"); break; case 2: /* pal */ - pal = 1; + is_pal = 1; FCEUD_DispMessage(RETRO_LOG_INFO, 2000, "System: PAL"); break; case 3: /* dendy */ @@ -1927,7 +1928,7 @@ static void FCEUD_RegionOverride(unsigned region) } dendy = d; - FCEUI_SetVidSystem(pal); + FCEUI_SetVidSystem(is_pal); ResetPalette(); } @@ -2458,7 +2459,7 @@ static void check_variables(bool startup) update_option_visibility(); } -void add_powerpad_input(unsigned port, uint32_t variant, uint32_t *ppdata) { +static void add_powerpad_input(unsigned port, uint32_t variant, uint32_t *ppdata) { unsigned k; const uint32_t* map = powerpadmap; for (k = 0 ; k < 12 ; k++) @@ -2466,7 +2467,7 @@ void add_powerpad_input(unsigned port, uint32_t variant, uint32_t *ppdata) { *ppdata |= (1 << k); } -void add_fkb_input(unsigned port, uint32_t variant, uint8_t *fkbkeys) { +static void add_fkb_input(unsigned port, uint32_t variant, uint8_t *fkbkeys) { unsigned k; const uint32_t* map = fkbmap; for (k = 0 ; k < 0x48 ; k++) @@ -2476,7 +2477,7 @@ void add_fkb_input(unsigned port, uint32_t variant, uint8_t *fkbkeys) { fkbkeys[k]=0; } -void add_suborkey_input(unsigned port, uint32_t variant, uint8_t *suborkeys) { +static void add_suborkey_input(unsigned port, uint32_t variant, uint8_t *suborkeys) { unsigned k; const uint32_t* map = suborkbmap; for (k = 0 ; k < 0x65 ; k++) @@ -2488,7 +2489,7 @@ void add_suborkey_input(unsigned port, uint32_t variant, uint8_t *suborkeys) { static int mzx = 0, mzy = 0; -void get_mouse_input(unsigned port, uint32_t variant, uint32_t *mousedata) +static void get_mouse_input(unsigned port, uint32_t variant, uint32_t *mousedata) { int min_width, min_height, max_width, max_height; @@ -2910,7 +2911,7 @@ static void FCEUD_UpdateInput(void) palette_switch_counter = 0; } -void FCEUD_Update(uint8_t *XBuf, int32_t *Buffer, int Count) +static void FCEUD_Update(uint8_t *XBuf, int32_t *Buffer, int Count) { } diff --git a/src/drivers/libretro/libretro_dipswitch.c b/src/drivers/libretro/libretro_dipswitch.c index 2aa3680..9ba2fd1 100644 --- a/src/drivers/libretro/libretro_dipswitch.c +++ b/src/drivers/libretro/libretro_dipswitch.c @@ -4,7 +4,6 @@ #include #include - #include "../../fceu.h" #include "../../fceu-types.h" #include "../../vsuni.h" @@ -1110,8 +1109,15 @@ static void make_core_options(struct retro_core_option_v2_definition *vs_core_op memset(&vs_core_options[i], 0, sizeof(struct retro_core_option_v2_definition)); - /* Set core key and sanitize string */ - snprintf(key, sizeof(key), "fceumm_dipswitch_%s-%s", game_name, option_name); + /* Set core key and sanitize string. Build "fceumm_dipswitch_-