diff --git a/Makefile.libretro b/Makefile.libretro index 44b600e..6a5cf0b 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 +WARNING_DEFINES = -Wno-write-strings -Wsign-compare endif CFLAGS += $(fpic) $(WARNING_DEFINES) $(DEFINES) $(ENDIANNESS_DEFINES) diff --git a/src/boards/121.c b/src/boards/121.c index 48cdd0a..140655a 100644 --- a/src/boards/121.c +++ b/src/boards/121.c @@ -91,7 +91,7 @@ static DECLFW(M121Write) { } } -static uint8_t prot_array[16] = { 0x83, 0x83, 0x42, 0x00 }; +static const uint8_t prot_array[16] = { 0x83, 0x83, 0x42, 0x00 }; static DECLFW(M121LoWrite) { EXPREGS[4] = prot_array[V & 3]; /* 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter) */ if ((A & 0x5180) == 0x5180) { /* A9713 multigame extension */ diff --git a/src/boards/178.c b/src/boards/178.c index d113a2f..0a64f88 100644 --- a/src/boards/178.c +++ b/src/boards/178.c @@ -45,14 +45,14 @@ static SFORMAT StateRegs[] = { 0 } }; -static int16_t step_size[49] = { +static const int16_t step_size[49] = { 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552 }; /* 49 items */ -static int32_t step_adj[16] = { -1, -1, -1, -1, 2, 5, 7, 9, -1, -1, -1, -1, 2, 5, 7, 9 }; +static const int32_t step_adj[16] = { -1, -1, -1, -1, 2, 5, 7, 9, -1, -1, -1, -1, 2, 5, 7, 9 }; /* decode stuff */ static int32_t jedi_table[16 * 49]; diff --git a/src/boards/187.c b/src/boards/187.c index 2b6d430..156fa60 100644 --- a/src/boards/187.c +++ b/src/boards/187.c @@ -65,7 +65,7 @@ static DECLFW(M187WriteLo) { } } -static uint8_t prot_data[4] = { 0x83, 0x83, 0x42, 0x00 }; +static const uint8_t prot_data[4] = { 0x83, 0x83, 0x42, 0x00 }; static DECLFR(M187Read) { return prot_data[EXPREGS[1] & 3]; } diff --git a/src/boards/244.c b/src/boards/244.c index 8c5ef4b..42d0cff 100644 --- a/src/boards/244.c +++ b/src/boards/244.c @@ -28,14 +28,14 @@ static SFORMAT StateRegs[] = { 0 } }; -static uint8_t prg_perm[4][4] = { +static const uint8_t prg_perm[4][4] = { { 0, 1, 2, 3, }, { 3, 2, 1, 0, }, { 0, 2, 1, 3, }, { 3, 1, 2, 0, }, }; -static uint8_t chr_perm[8][8] = { +static const uint8_t chr_perm[8][8] = { { 0, 1, 2, 3, 4, 5, 6, 7, }, { 0, 2, 1, 3, 4, 6, 5, 7, }, { 0, 1, 4, 5, 2, 3, 6, 7, }, diff --git a/src/boards/594.c b/src/boards/594.c index 151c8ee..d6d38d5 100644 --- a/src/boards/594.c +++ b/src/boards/594.c @@ -95,7 +95,7 @@ static void mapperSound_fillBufferLow (int count) { } static void mapperSound_fillBufferHigh () { - int i; + uint32_t i; for (i = soundOffset; i < SOUNDTS; i++) { MSM6585_run(&adpcm); WaveHi[i] += MSM6585_getOutput(&adpcm)*8 +16384; diff --git a/src/boards/6_8_12_17_561_562.c b/src/boards/6_8_12_17_561_562.c index 1f6243b..0b384d6 100644 --- a/src/boards/6_8_12_17_561_562.c +++ b/src/boards/6_8_12_17_561_562.c @@ -386,7 +386,7 @@ static DECLFR(redirectReset) { } static void power(void) { - int i; + uint32_t i; writePPU =GetWriteHandler(0x2007); GetWriteHandler(0x4017)(0x4017, 0x40); /* Disable Frame IRQ */ mc1Mode =mc1ModeInitial; diff --git a/src/boards/8237.c b/src/boards/8237.c index 067d18c..003f579 100644 --- a/src/boards/8237.c +++ b/src/boards/8237.c @@ -39,7 +39,7 @@ static uint8_t submapper; -static uint8_t regperm[8][8] = +static const uint8_t regperm[8][8] = { { 0, 1, 2, 3, 4, 5, 6, 7 }, { 0, 2, 6, 1, 7, 3, 4, 5 }, @@ -51,7 +51,7 @@ static uint8_t regperm[8][8] = { 0, 1, 2, 3, 4, 5, 6, 7 }, /* empty */ }; -static uint8_t adrperm[8][8] = +static const uint8_t adrperm[8][8] = { { 0, 1, 2, 3, 4, 5, 6, 7 }, { 3, 2, 0, 4, 1, 5, 6, 7 }, @@ -63,7 +63,7 @@ static uint8_t adrperm[8][8] = { 0, 1, 2, 3, 4, 5, 6, 7 }, /* empty */ }; -static uint8_t protarray[8][8] = { +static const uint8_t protarray[8][8] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* 0 Super Hang-On */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00 }, /* 1 Monkey King */ { 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00, 0x00 }, /* 2 Super Hang-On/Monkey King */ diff --git a/src/boards/bmc42in1r.c b/src/boards/bmc42in1r.c index da0fb6e..caa94b4 100644 --- a/src/boards/bmc42in1r.c +++ b/src/boards/bmc42in1r.c @@ -29,7 +29,7 @@ static uint8_t reorder_banks = 0; static uint8_t latche[2], reset; -static uint8_t banks[4] = { 0, 0, 1, 2 }; +static const uint8_t banks[4] = { 0, 0, 1, 2 }; static SFORMAT StateRegs[] = { { &reset, 1, "RST" }, diff --git a/src/boards/bonza.c b/src/boards/bonza.c index a869273..e5a3ffe 100644 --- a/src/boards/bonza.c +++ b/src/boards/bonza.c @@ -85,7 +85,7 @@ byte_8CC6: .BYTE 0,$78, 0, 0,$12 #endif #if 0 /* Silenced since unused */ -static uint8_t sim0reset[0x1F] = { +static const uint8_t sim0reset[0x1F] = { 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE, 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53, 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10, diff --git a/src/boards/cartram.c b/src/boards/cartram.c index fb8e194..befdcb3 100644 --- a/src/boards/cartram.c +++ b/src/boards/cartram.c @@ -45,7 +45,7 @@ void CartRAM_init (CartInfo *info, uint8_t defaultWRAMSizeKiB, uint8_t defaultCH AddExState(WRAMData, WRAMSize, 0, "WRAM"); if (info->battery && (info->PRGRamSaveSize || !info->iNES2)) { info->SaveGame[0] = WRAMData; - info->SaveGameLen[0] = info->iNES2? info->PRGRamSaveSize: WRAMSize; + info->SaveGameLen[0] = info->iNES2? (uint32_t)info->PRGRamSaveSize: WRAMSize; } } CHRRAMSize = info->iNES2? (info->CHRRamSize +info->CHRRamSaveSize): (defaultCHRRAMSizeKiB *1024); @@ -56,7 +56,7 @@ void CartRAM_init (CartInfo *info, uint8_t defaultWRAMSizeKiB, uint8_t defaultCH AddExState(CHRRAMData, CHRRAMSize, 0, "CRAM"); if (info->battery && (info->CHRRamSaveSize || !info->iNES2)) { info->SaveGame[info->SaveGameLen[0]? 1: 0] = CHRRAMData; - info->SaveGameLen[info->SaveGameLen[0]? 1: 0] = info->iNES2? info->CHRRamSaveSize: CHRRAMSize; + info->SaveGameLen[info->SaveGameLen[0]? 1: 0] = info->iNES2? (uint32_t)info->CHRRamSaveSize: CHRRAMSize; } } if (WRAMSize || CHRRAMSize) info->Close = CartRAM_close; diff --git a/src/boards/datalatch.c b/src/boards/datalatch.c index fd4c14c..a8c50b4 100644 --- a/src/boards/datalatch.c +++ b/src/boards/datalatch.c @@ -85,13 +85,6 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), uint8_t init, uint16_ /*------------------ Map 0 ---------------------------*/ -#ifdef DEBUG_MAPPER -static DECLFW(NROMWrite) { - FCEU_printf("bs %04x %02x\n", A, V); - CartBW(A, V); -} -#endif - static void NROMPower(void) { setprg8r(0x10, 0x6000, 0); /* Famili BASIC (v3.0) need it (uses only 4KB), FP-BASIC uses 8KB */ setprg16(0x8000, 0); @@ -103,10 +96,6 @@ static void NROMPower(void) { SetReadHandler(0x8000, 0xFFFF, CartBR); FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - - #ifdef DEBUG_MAPPER - SetWriteHandler(0x4020, 0xFFFF, NROMWrite); - #endif } void NROM_Init(CartInfo *info) { @@ -486,7 +475,7 @@ void Mapper381_Init(CartInfo *info) { * bootleg cartridge conversion named Super Soccer Champion * of the Konami FDS game Exciting Soccer. */ -static uint8_t M538Banks[16] = { 0, 1, 2, 1, 3, 1, 4, 1, 5, 5, 1, 1, 6, 6, 7, 7 }; +static const uint8_t M538Banks[16] = { 0, 1, 2, 1, 3, 1, 4, 1, 5, 5, 1, 1, 6, 6, 7, 7 }; static void M538Sync(void) { setprg8(0x6000, (latche >> 1) | 8); setprg8(0x8000, M538Banks[latche & 15]); diff --git a/src/boards/eeprom_93Cx6.c b/src/boards/eeprom_93Cx6.c index b3ae0ae..de2b8ff 100644 --- a/src/boards/eeprom_93Cx6.c +++ b/src/boards/eeprom_93Cx6.c @@ -93,7 +93,7 @@ void eeprom_93Cx6_write (uint8_t CS, uint8_t CLK, uint8_t DAT) { break; case OPCODE_ERASEALL: if (eeprom_93Cx6_writeEnabled) { - int i; + size_t i; for (i =0; i slot[(x) << 1]) #define CAR(o, x) (&(o)->slot[((x) << 1) | 1]) @@ -693,7 +693,7 @@ INLINE static void calc_phase(OPLL_SLOT * slot, int32_t lfo) { static void calc_envelope(OPLL_SLOT * slot, int32_t lfo) { #define S2E(x) (SL2EG((int32_t)(x / SL_STEP)) << (EG_DP_BITS - EG_BITS)) - static uint32_t SL[16] = { + static const uint32_t SL[16] = { S2E(0.0), S2E(3.0), S2E(6.0), S2E(9.0), S2E(12.0), S2E(15.0), S2E(18.0), S2E(21.0), S2E(24.0), S2E(27.0), S2E(30.0), S2E(33.0), S2E(36.0), S2E(39.0), S2E(42.0), S2E(48.0) }; diff --git a/src/boards/n625092.c b/src/boards/n625092.c index 15bdbd4..ec73935 100644 --- a/src/boards/n625092.c +++ b/src/boards/n625092.c @@ -38,7 +38,7 @@ static DECLFR(Mapper221_ReadOB) static void sync(void) { uint8_t prg =reg[0] >>(submapper ==1? 2: 3) &0x40 | reg[0] >>2 &0x38 | reg[1] &0x07; - SetReadHandler(0x8000, 0xFFFF, prg <<14 >=PRGsize[0]? Mapper221_ReadOB: CartBR); /* Selecting unpopulated banks results in open bus */ + SetReadHandler(0x8000, 0xFFFF, (uint32_t)(prg <<14) >=PRGsize[0]? Mapper221_ReadOB: CartBR); /* Selecting unpopulated banks results in open bus */ if (reg[0] &(submapper ==1? 0x200: 0x100)) { /* UNROM */ setprg16(0x8000, prg); setprg16(0xC000, prg |7); diff --git a/src/boards/pec-586.c b/src/boards/pec-586.c index 21d466d..b19b10c 100644 --- a/src/boards/pec-586.c +++ b/src/boards/pec-586.c @@ -32,7 +32,7 @@ static SFORMAT StateRegs[] = { 0 } }; -static uint8_t bs_tbl[128] = { +static const uint8_t bs_tbl[128] = { 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, /* 00 */ 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, /* 10 */ 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, /* 20 */ @@ -43,7 +43,7 @@ static uint8_t bs_tbl[128] = { 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, /* 70 */ }; -static uint8_t br_tbl[16] = { +static const uint8_t br_tbl[16] = { 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, }; diff --git a/src/driver.h b/src/driver.h index b577266..55e921e 100644 --- a/src/driver.h +++ b/src/driver.h @@ -27,15 +27,15 @@ extern "C" { #define FCEUNPCMD_TEXT 0x90 /* This makes me feel dirty for some reason. */ -void FCEU_printf(char *format, ...); +void FCEU_printf(const char *format, ...); #define FCEUI_printf FCEU_printf /* Video interface */ void FCEUD_SetPalette(uint16_t index, uint8_t r, uint8_t g, uint8_t b); /* Displays an error. Can block or not. */ -void FCEUD_PrintError(char *s); -void FCEUD_Message(char *s); +void FCEUD_PrintError(const char *s); +void FCEUD_Message(const char *s); void FCEUD_DispMessage(enum retro_log_level level, unsigned duration, const char *str); void FCEU_DispMessage(enum retro_log_level level, unsigned duration, const char *format, ...); @@ -117,14 +117,6 @@ void FCEUI_SetVidSystem(int a); /* Convenience function; returns currently emulated video system(0=NTSC, 1=PAL). */ int FCEUI_GetCurrentVidSystem(int *slstart, int *slend); -#ifdef FRAMESKIP -/* Should be called from FCEUD_BlitScreen(). Specifies how many frames - to skip until FCEUD_BlitScreen() is called. FCEUD_BlitScreenDummy() - will be called instead of FCEUD_BlitScreen() when when a frame is skipped. -*/ -void FCEUI_FrameSkip(int x); -#endif - /* First and last scanlines to render, for ntsc and pal emulation. */ void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall); diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index a228f6b..41241c6 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -346,12 +346,12 @@ static struct retro_log_callback log_cb; static void default_logger(enum retro_log_level level, const char *fmt, ...) {} -void FCEUD_PrintError(char *c) +void FCEUD_PrintError(const char *c) { log_cb.log(RETRO_LOG_WARN, "%s", c); } -void FCEUD_Message(char *s) +void FCEUD_Message(const char *s) { log_cb.log(RETRO_LOG_INFO, "%s", s); } @@ -2291,7 +2291,7 @@ static void check_variables(bool startup) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - unsigned oldval = aspect_ratio_par; + int oldval = aspect_ratio_par; if (!strcmp(var.value, "8:7 PAR")) { aspect_ratio_par = 1; } else if (!strcmp(var.value, "4:3")) { @@ -2443,7 +2443,10 @@ static void check_variables(bool startup) strlcpy(key, "fceumm_apu_x", sizeof(key)); for (i = 0; i < 5; i++) { - key[strlen("fceumm_apu_")] = '1' + i; + /* Replace the trailing 'x' with '1'..'5'. The literal length is + * known at compile time so use sizeof-1 to avoid the strlen call + * inside the loop. */ + key[sizeof("fceumm_apu_") - 1] = '1' + i; var.value = NULL; if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && !strcmp(var.value, "disabled")) enable_apu &= ~(1 << i); @@ -2890,7 +2893,7 @@ static void FCEUD_UpdateInput(void) } else /* palette_next */ { - if (new_palette_index < PAL_TOTAL - 1) + if ((unsigned long)new_palette_index < PAL_TOTAL - 1) new_palette_index++; else new_palette_index = 0; @@ -3094,7 +3097,7 @@ bool retro_serialize(void *data, size_t size) if (geniestage == 1) return false; - if (size != retro_serialize_size()) + if (!data || size != retro_serialize_size()) return false; memstream_set_buffer((uint8_t*)data, size); @@ -3109,7 +3112,7 @@ bool retro_unserialize(const void * data, size_t size) if (geniestage == 1) return false; - if (size != retro_serialize_size()) + if (!data || size != retro_serialize_size()) return false; memstream_set_buffer((uint8_t*)data, size); diff --git a/src/fceu-memory.c b/src/fceu-memory.c index 394a025..b20bd5e 100644 --- a/src/fceu-memory.c +++ b/src/fceu-memory.c @@ -31,8 +31,13 @@ void *FCEU_gmalloc(uint32_t size) void *ret = malloc(size); if (!ret) { - FCEU_PrintError("Error allocating memory! Doing a hard exit."); - exit(1); + /* Returning NULL is a behaviour change from the old exit(1) + * semantics, but a libretro core must not exit() because that + * tears down the entire frontend. All FCEU_gmalloc call sites + * are now NULL-aware - they propagate the failure up to the + * loader which logs an error and refuses to load the cart. */ + FCEU_PrintError("Error allocating memory!"); + return NULL; } memset(ret, 0, size); return ret; diff --git a/src/fceu.c b/src/fceu.c index 16887ab..b467491 100644 --- a/src/fceu.c +++ b/src/fceu.c @@ -503,7 +503,7 @@ void FCEU_ResetVidSys(void) FCEUS FSettings; -void FCEU_printf(char *format, ...) +void FCEU_printf(const char *format, ...) { char temp[2048]; @@ -519,7 +519,7 @@ void FCEU_printf(char *format, ...) va_end(ap); } -void FCEU_PrintError(char *format, ...) +void FCEU_PrintError(const char *format, ...) { char temp[2048]; diff --git a/src/fceu.h b/src/fceu.h index 2a4a613..74c9026 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -98,15 +98,12 @@ typedef struct { extern FCEUS FSettings; -void FCEU_PrintError(char *format, ...); -void FCEU_printf(char *format, ...); +void FCEU_PrintError(const char *format, ...); +void FCEU_printf(const char *format, ...); void SetNESDeemph(uint8_t d, int force); void DrawTextTrans(uint8_t *dest, uint32_t width, uint8_t *textmsg, uint8_t fgcolor); void FCEU_PutImage(void); -#ifdef FRAMESKIP -void FCEU_PutImageDummy(void); -#endif extern uint8_t Exit; extern uint8_t default_palette_selected; diff --git a/src/fds.c b/src/fds.c index 5e4161d..a613801 100644 --- a/src/fds.c +++ b/src/fds.c @@ -118,7 +118,7 @@ void FDSGI(int h) { } static void FDSStateRestore(int version) { - int x; + uint32_t x; /* Sanity-check disk indices and block parameters. A malicious * savestate could otherwise: @@ -605,7 +605,7 @@ static void FreeFDSMemory(void) { static int SubLoad(FCEUFILE *fp) { struct md5_context md5; uint8_t header[16]; - int x; + uint32_t x; uint64_t fsize = FCEU_fgetsize(fp); /* Reject files too short to contain a 16-byte header. Otherwise the @@ -653,7 +653,7 @@ static int SubLoad(FCEUFILE *fp) { } static void PreSave(void) { - int x; + uint32_t x; for (x = 0; x < TotalSides; x++) { int b; for (b = 0; b < 65500; b++) @@ -662,7 +662,7 @@ static void PreSave(void) { } static void PostSave(void) { - int x; + uint32_t x; for (x = 0; x < TotalSides; x++) { int b; for (b = 0; b < 65500; b++) @@ -672,7 +672,7 @@ static void PostSave(void) { int FDSLoad(const char *name, FCEUFILE *fp) { FCEUFILE *zp; - int x; + uint32_t x; char *fn = FCEU_MakeFName(FCEUMKF_FDSROM, 0, 0); @@ -691,6 +691,10 @@ int FDSLoad(const char *name, FCEUFILE *fp) { FDSBIOSsize = 8192; FDSBIOS = (uint8_t*)FCEU_gmalloc(FDSBIOSsize); + if (!FDSBIOS) { + FCEU_fclose(zp); + return 0; + } SetupCartPRGMapping(0, FDSBIOS, FDSBIOSsize, 0); if (FCEU_fread(FDSBIOS, 1, FDSBIOSsize, zp) != FDSBIOSsize) { @@ -717,7 +721,7 @@ int FDSLoad(const char *name, FCEUFILE *fp) { for (x = 0; x < TotalSides; x++) { diskdatao[x] = (uint8_t*)FCEU_malloc(65500); if (!diskdatao[x]) { - int y; + uint32_t y; for (y = 0; y < x; y++) { free(diskdatao[y]); diskdatao[y] = NULL; @@ -775,11 +779,15 @@ int FDSLoad(const char *name, FCEUFILE *fp) { CHRRAMSize = 8192; CHRRAM = (uint8_t*)FCEU_gmalloc(CHRRAMSize); + if (!CHRRAM) + return 0; SetupCartCHRMapping(0, CHRRAM, CHRRAMSize, 1); AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); FDSRAMSize = 32768; FDSRAM = (uint8_t*)FCEU_gmalloc(FDSRAMSize); + if (!FDSRAM) + return 0; SetupCartPRGMapping(1, FDSRAM, FDSRAMSize, 1); AddExState(FDSRAM, FDSRAMSize, 0, "FDSR"); @@ -796,7 +804,7 @@ int FDSLoad(const char *name, FCEUFILE *fp) { } void FDSClose(void) { - int x; + uint32_t x; if (!DiskWritten) return; diff --git a/src/general.c b/src/general.c index 79c5c8b..3fb7476 100644 --- a/src/general.c +++ b/src/general.c @@ -50,7 +50,7 @@ void FCEUI_SetBaseDirectory(const char *dir) strlcpy(BaseDirectory, dir, sizeof(BaseDirectory)); } -char *FCEU_MakeFName(int type, int id1, char *cd1) +char *FCEU_MakeFName(int type, int id1, const char *cd1) { char tmp[4096 + 512] = {0}; /* +512 for no reason :D */ char *ret = 0; diff --git a/src/general.h b/src/general.h index 05878af..a659a53 100644 --- a/src/general.h +++ b/src/general.h @@ -3,7 +3,7 @@ extern uint32_t uppow2(uint32_t n); -char *FCEU_MakeFName(int type, int id1, char *cd1); +char *FCEU_MakeFName(int type, int id1, const char *cd1); enum FILE_TYPES { diff --git a/src/ines.c b/src/ines.c index 31cb803..563f631 100644 --- a/src/ines.c +++ b/src/ines.c @@ -1209,6 +1209,8 @@ int iNESLoad(const char *name, FCEUFILE *fp) if (head.ROM_type & 4) { trainerpoo = (uint8_t*)FCEU_gmalloc(512); + if (!trainerpoo) + return 0; FCEU_fread(trainerpoo, 512, 1, fp); filesize -= 512; } @@ -1377,6 +1379,8 @@ int iNESLoad(const char *name, FCEUFILE *fp) if (iNESCart.mirror == 2) { ExtraNTARAM = (uint8_t*)FCEU_gmalloc(2048); + if (!ExtraNTARAM) + return 0; SetupCartMirroring(4, 1, ExtraNTARAM); } else if (iNESCart.mirror >= 0x10) diff --git a/src/input/cursor.c b/src/input/cursor.c index 8384d36..5c9b7cb 100644 --- a/src/input/cursor.c +++ b/src/input/cursor.c @@ -1,6 +1,6 @@ #include "share.h" -static uint8_t GunSight[] = { +static const uint8_t GunSight[] = { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, @@ -15,7 +15,7 @@ static uint8_t GunSight[] = { 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, }; -static uint8_t FCEUcursor[11 * 19] = +static const uint8_t FCEUcursor[11 * 19] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/src/input/fkb.c b/src/input/fkb.c index dcafd15..32e63ad 100644 --- a/src/input/fkb.c +++ b/src/input/fkb.c @@ -27,7 +27,7 @@ static uint8_t bufit[0x49]; static uint8_t ksmode; static uint8_t ksindex; -static uint16_t matrix[9][2][4] = +static const uint16_t matrix[9][2][4] = { { { AK(F8), AK(RETURN), AK(BRACKETLEFT), AK(BRACKETRIGHT) }, { AK(KANA), AK(RIGHTSHIFT), AK(BACKSLASH), AK(STOP) } }, diff --git a/src/input/pec586kb.c b/src/input/pec586kb.c index fb4cc6a..2fb4c3b 100644 --- a/src/input/pec586kb.c +++ b/src/input/pec586kb.c @@ -30,7 +30,7 @@ static uint8_t ksindex; /* TODO: check all keys, some of the are wrong */ -static uint16_t matrix[13][8] = +static const uint16_t matrix[13][8] = { { AK(ESCAPE),AK(SPACE),AK(LMENU),AK(LCONTROL),AK(LSHIFT),AK(GRAVE),AK(TAB),AK(CAPITAL) }, { AK(F6),AK(F7),AK(F5),AK(F4),AK(F8),AK(F2),AK(F1),AK(F3) }, diff --git a/src/input/suborkb.c b/src/input/suborkb.c index 787be41..0b33603 100644 --- a/src/input/suborkb.c +++ b/src/input/suborkb.c @@ -27,7 +27,7 @@ static uint8_t bufit[0x66]; static uint8_t ksmode; static uint8_t ksindex; -static uint16_t matrix[13][2][4] = +static const uint16_t matrix[13][2][4] = { { { AK(4), AK(G), AK(F), AK(C) }, { AK(F2), AK(E), AK(5), AK(V) } }, { { AK(2), AK(D), AK(S), AK(END) }, { AK(F1), AK(W), AK(3), AK(X) } }, diff --git a/src/input/zapper.c b/src/input/zapper.c index 54e2ac0..b121c3c 100644 --- a/src/input/zapper.c +++ b/src/input/zapper.c @@ -63,7 +63,7 @@ static void FP_FASTAPASS(3) ZapperFrapper(int w, uint8_t * bg, uint8_t * spr, ui if (xe > 256) xe = 256; - if (scanline >= (zy - tolerance) && scanline <= (zy + tolerance)) { + if (scanline >= (zy - (int)tolerance) && scanline <= (zy + (int)tolerance)) { #ifdef ROUNDED_TARGET int spread; int dy = scanline - zy; diff --git a/src/md5.c b/src/md5.c index d933e98..c6ae07b 100644 --- a/src/md5.c +++ b/src/md5.c @@ -40,7 +40,7 @@ void md5_starts(struct md5_context *ctx) { ctx->state[3] = 0x10325476; } -void md5_process(struct md5_context *ctx, uint8_t data[64]) { +static void md5_process(struct md5_context *ctx, const uint8_t data[64]) { uint32_t A, B, C, D, X[16]; GET_UINT32(X[0], data, 0); @@ -162,7 +162,7 @@ void md5_process(struct md5_context *ctx, uint8_t data[64]) { ctx->state[3] += D; } -void md5_update(struct md5_context *ctx, uint8_t *input, uint32_t length) { +void md5_update(struct md5_context *ctx, const uint8_t *input, uint32_t length) { uint32_t left, fill; if (!length) return; @@ -195,7 +195,7 @@ void md5_update(struct md5_context *ctx, uint8_t *input, uint32_t length) { } } -static uint8_t md5_padding[64] = +static const uint8_t md5_padding[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/src/md5.h b/src/md5.h index f32a5f4..0909658 100644 --- a/src/md5.h +++ b/src/md5.h @@ -8,7 +8,7 @@ struct md5_context { }; void md5_starts(struct md5_context *ctx); -void md5_update(struct md5_context *ctx, uint8_t *input, uint32_t length); +void md5_update(struct md5_context *ctx, const uint8_t *input, uint32_t length); void md5_finish(struct md5_context *ctx, uint8_t digest[16]); /* Uses a static buffer, so beware of how it's used. */ diff --git a/src/nsf.c b/src/nsf.c index f1f4b72..f20b1c8 100644 --- a/src/nsf.c +++ b/src/nsf.c @@ -173,7 +173,7 @@ int NSFLoad(FCEUFILE *fp) { } NSFSize = fsize - 0x80; /* Ceiling: 16 MiB of song data is far beyond reality */ - if (NSFSize > (16u << 20)) { + if ((unsigned)NSFSize > (16u << 20)) { FCEUD_PrintError("NSF song data unreasonably large."); return(0); } @@ -184,7 +184,7 @@ int NSFLoad(FCEUFILE *fp) { * of NSFMaxBank). 2^19 * 4096 = 2 GiB which is already absurd for * an NSF file; the previous cap of 2^20 produced 4 GiB which * overflows signed int and is undefined behaviour. */ - if (!NSFMaxBank || NSFMaxBank > (1u << 19)) { + if (!NSFMaxBank || (unsigned)NSFMaxBank > (1u << 19)) { FCEUD_PrintError("NSF bank count out of range."); return(0); } @@ -245,6 +245,8 @@ int NSFLoad(FCEUFILE *fp) { ExWRAM = FCEU_gmalloc(32768 + 8192); else ExWRAM = FCEU_gmalloc(8192); + if (!ExWRAM) + return 0; return 1; } @@ -481,7 +483,7 @@ void DrawNSF(uint8_t *XBuf) { DrawTextTrans(XBuf + 26 * 256 + 4 + (((31 - strlen((char*)NSFHeader.Artist)) << 2)), 256, NSFHeader.Artist, 6); DrawTextTrans(XBuf + 42 * 256 + 4 + (((31 - strlen((char*)NSFHeader.Copyright)) << 2)), 256, NSFHeader.Copyright, 6); - DrawTextTrans(XBuf + 70 * 256 + 4 + (((31 - strlen("Song:")) << 2)), 256, (uint8_t*)"Song:", 6); + DrawTextTrans(XBuf + 70 * 256 + 4 + (((31 - (sizeof("Song:") - 1)) << 2)), 256, (uint8_t*)"Song:", 6); snprintf(snbuf, sizeof(snbuf), "<%d/%d>", CurrentSong, NSFHeader.TotalSongs); DrawTextTrans(XBuf + 82 * 256 + 4 + (((31 - strlen(snbuf)) << 2)), 256, (uint8_t*)snbuf, 6); diff --git a/src/palette.c b/src/palette.c index cef3b19..ac15ee3 100644 --- a/src/palette.c +++ b/src/palette.c @@ -113,9 +113,9 @@ void FCEUI_SetPaletteArray(uint8_t *pal, int nEntries) { static uint8_t lastd = 0; void SetNESDeemph(uint8_t d, int force) { - static uint16_t rtmul[7] = { 32768 * 1.239, 32768 * .794, 32768 * 1.019, 32768 * .905, 32768 * 1.023, 32768 * .741, 32768 * .75 }; - static uint16_t gtmul[7] = { 32768 * .915, 32768 * 1.086, 32768 * .98, 32768 * 1.026, 32768 * .908, 32768 * .987, 32768 * .75 }; - static uint16_t btmul[7] = { 32768 * .743, 32768 * .882, 32768 * .653, 32768 * 1.277, 32768 * .979, 32768 * .101, 32768 * .75 }; + static const uint16_t rtmul[7] = { 32768 * 1.239, 32768 * .794, 32768 * 1.019, 32768 * .905, 32768 * 1.023, 32768 * .741, 32768 * .75 }; + static const uint16_t gtmul[7] = { 32768 * .915, 32768 * 1.086, 32768 * .98, 32768 * 1.026, 32768 * .908, 32768 * .987, 32768 * .75 }; + static const uint16_t btmul[7] = { 32768 * .743, 32768 * .882, 32768 * .653, 32768 * 1.277, 32768 * .979, 32768 * .101, 32768 * .75 }; uint32_t r, g, b; int x; diff --git a/src/ppu.c b/src/ppu.c index c6b0c1b..debd5e2 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -637,7 +637,7 @@ static void DoLine(void) uint8_t *target = NULL; uint8_t *dtarget = NULL; - if (scanline >= 240 && scanline != totalscanlines) + if (scanline >= 240 && (unsigned)scanline != totalscanlines) { X6502_Run(256 + 69); scanline++; @@ -1166,30 +1166,6 @@ int FCEUPPU_Loop(int skip) { } if (GameInfo->type == GIT_NSF) X6502_Run((256 + 85) * normal_scanlines); - #ifdef FRAMESKIP - else if (skip) { - int y; - - y = SPRAM[0]; - y++; - - PPU_status |= 0x20; /* Fixes "Bee 52". Does it break anything? */ - if (GameHBIRQHook) { - X6502_Run(256); - for (scanline = 0; scanline < 240; scanline++) { - if (ScreenON || SpriteON) - GameHBIRQHook(); - if (scanline == y && SpriteON) PPU_status |= 0x40; - X6502_Run((scanline == 239) ? 85 : (256 + 85)); - } - } else if (y < 240) { - X6502_Run((256 + 85) * y); - if (SpriteON) PPU_status |= 0x40; /* Quick and very dirty hack. */ - X6502_Run((256 + 85) * (240 - y)); - } else - X6502_Run((256 + 85) * 240); - } - #endif else { int x, max, maxref; @@ -1201,10 +1177,10 @@ int FCEUPPU_Loop(int skip) { else totalscanlines = normal_scanlines + (overclock_enabled ? extrascanlines : 0); - for (scanline = 0; scanline < totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */ + for (scanline = 0; (unsigned)scanline < totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */ deempcnt[deemp]++; DoLine(); - if (scanline < normal_scanlines || scanline == totalscanlines) + if ((unsigned)scanline < normal_scanlines || (unsigned)scanline == totalscanlines) overclocked = 0; else { if (DMC_7bit && skip_7bit_overclocking) /* 7bit sample started after 240th line */ @@ -1226,12 +1202,6 @@ int FCEUPPU_Loop(int skip) { } } - #ifdef FRAMESKIP - if (skip) { - FCEU_PutImageDummy(); - return(0); - } else - #endif { FCEU_PutImage(); return(1); diff --git a/src/sound.c b/src/sound.c index fe4ff83..b4ae9c5 100644 --- a/src/sound.c +++ b/src/sound.c @@ -687,7 +687,7 @@ static void RDoSQLQ(void) { } static void RDoTriangle(void) { - int32_t V; + uint32_t V; int32_t tcout = (tristep & 0xF); if (!(tristep & 0x10)) tcout ^= 0xF; tcout = (tcout * 3) << 16; /* (tcout<<1); */ diff --git a/src/vsuni.c b/src/vsuni.c index 93dcacb..d6d823e 100644 --- a/src/vsuni.c +++ b/src/vsuni.c @@ -64,7 +64,7 @@ uint8_t FCEUI_VSUniGetDIPs(void) { return(vsdip); } -static uint8_t secdata[2][32] = { +static const uint8_t secdata[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, @@ -75,7 +75,7 @@ static uint8_t secdata[2][32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; -static uint8_t *secptr; +static const uint8_t *secptr; static uint8_t VSindex; diff --git a/src/x6502.c b/src/x6502.c index da318d8..61b83e0 100644 --- a/src/x6502.c +++ b/src/x6502.c @@ -312,7 +312,7 @@ redundant) on the variable "x". #define ST_IX(r) { uint32_t A; GetIX(A); WrMem(A, r); break; } #define ST_IY(r) { uint32_t A; GetIYWR(A); WrMem(A, r); break; } -static uint8_t CycTable[256] = +static const uint8_t CycTable[256] = { /*0x00*/ 7, 6, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 4, 4, 6, 6, /*0x10*/ 2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,