From 864362a2a67c0777b76bcb071573e2b9d85f4cc1 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Tue, 6 Nov 2018 15:20:38 -0800 Subject: [PATCH] Convert to C89 pass 1 --- libretroBuildSystem/Makefile.libretro | 2 +- libretroBuildSystem/build/Makefile.common | 2 +- libretroBuildSystem/cursors.h | 5 ++++- libretroBuildSystem/libretro.c | 14 ++++++++++---- qtBuildSystem/Mu/Mu.pro | 1 - src/ads7846.c | 2 +- src/ads7846.h | 5 ++++- src/audio/inductor.c | 1 - src/audio/inductor.h | 1 - src/flx68000.c | 2 +- src/hardwareRegisters.c | 12 ++++++------ src/hardwareRegistersAccessors.c.h | 6 +++--- src/portability.h | 9 ++++----- 13 files changed, 35 insertions(+), 27 deletions(-) diff --git a/libretroBuildSystem/Makefile.libretro b/libretroBuildSystem/Makefile.libretro index 0a20f1e..c82d26e 100644 --- a/libretroBuildSystem/Makefile.libretro +++ b/libretroBuildSystem/Makefile.libretro @@ -227,7 +227,7 @@ else ifeq ($(platform), psp1) TARGET := $(TARGET_NAME)_libretro_$(platform).$(EXT) CC = psp-gcc$(EXE_EXT) AR = psp-ar$(EXE_EXT) - CFLAGS += -std=c99 -DPSP -G0 + CFLAGS += -DPSP -G0 STATIC_LINKING=1 STATIC_LINKING_LINK=1 diff --git a/libretroBuildSystem/build/Makefile.common b/libretroBuildSystem/build/Makefile.common index 112f819..ad9ee8a 100644 --- a/libretroBuildSystem/build/Makefile.common +++ b/libretroBuildSystem/build/Makefile.common @@ -10,7 +10,7 @@ else COREDEFINES += -DEMU_NO_SAFETY endif -ifneq (,$(findstring msvc2003,$(platform))) +ifneq (,$(findstring msvc200,$(platform))) INCFLAGS += -I$(LIBRETRO_COMM_DIR)/include/compat/msvc endif diff --git a/libretroBuildSystem/cursors.h b/libretroBuildSystem/cursors.h index 22d0e7e..142c878 100644 --- a/libretroBuildSystem/cursors.h +++ b/libretroBuildSystem/cursors.h @@ -1,4 +1,7 @@ -#pragma once +#ifndef CURSORS_H +#define CURSORS_H extern const unsigned char cursor16x16[]; extern const unsigned char cursor32x32[]; + +#endif diff --git a/libretroBuildSystem/libretro.c b/libretroBuildSystem/libretro.c index 21f1151..101827b 100644 --- a/libretroBuildSystem/libretro.c +++ b/libretroBuildSystem/libretro.c @@ -44,21 +44,27 @@ static void renderMouseCursor(int16_t screenX, int16_t screenY){ static const uint16_t* joystickCursor32 = cursor32x32; if(screenHires){ + int8_t x; + int8_t y; + //align cursor to side of image screenX -= 6; - for(int8_t y = 0; y < 32; y++) - for(int8_t x = 6; x < 26; x++) + for(y = 0; y < 32; y++) + for(x = 6; x < 26; x++) if(screenX + x >= 0 && screenY + y >= 0 && screenX + x < 320 && screenY + y < 440) if(joystickCursor32[y * 32 + x] != 0x0000) screenData[(screenY + y) * 320 + screenX + x] = joystickCursor32[y * 32 + x]; } else{ + int8_t x; + int8_t y; + //align cursor to side of image screenX -= 3; - for(int8_t y = 0; y < 16; y++) - for(int8_t x = 3; x < 13; x++) + for(y = 0; y < 16; y++) + for(x = 3; x < 13; x++) if(screenX + x >= 0 && screenY + y >= 0 && screenX + x < 160 && screenY + y < 220) if(joystickCursor16[y * 16 + x] != 0x0000) screenData[(screenY + y) * 160 + screenX + x] = joystickCursor16[y * 16 + x]; diff --git a/qtBuildSystem/Mu/Mu.pro b/qtBuildSystem/Mu/Mu.pro index e371008..496fb87 100644 --- a/qtBuildSystem/Mu/Mu.pro +++ b/qtBuildSystem/Mu/Mu.pro @@ -78,7 +78,6 @@ CONFIG(debug, debug|release){ DEFINES += EMU_NO_SAFETY } -QMAKE_CFLAGS += -std=c99 CONFIG += c++11 INCLUDEPATH += $$PWD/qt-common/include diff --git a/src/ads7846.c b/src/ads7846.c index 2b0af6e..9d2b709 100644 --- a/src/ads7846.c +++ b/src/ads7846.c @@ -20,7 +20,7 @@ static double ads7846RangeMap(double oldMin, double oldMax, double value, double } static bool ads7846GetAdcBit(){ - bool bit = ads7846OutputValue & 0x8000; + bool bit = !!(ads7846OutputValue & 0x8000); ads7846OutputValue <<= 1; return bit; } diff --git a/src/ads7846.h b/src/ads7846.h index 682d0fd..fda5d8a 100644 --- a/src/ads7846.h +++ b/src/ads7846.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef ADS7846_H +#define ADS7846_H #include #include @@ -13,3 +14,5 @@ void ads7846LoadState(uint8_t* data); void ads7846SetChipSelect(bool value); bool ads7846ExchangeBit(bool bitIn); bool ads7846Busy(); + +#endif diff --git a/src/audio/inductor.c b/src/audio/inductor.c index 899b784..7ca31a7 100644 --- a/src/audio/inductor.c +++ b/src/audio/inductor.c @@ -1,5 +1,4 @@ #include -#include #include "../portability.h" #include "../emulator.h" diff --git a/src/audio/inductor.h b/src/audio/inductor.h index 78a1eeb..2dcd7aa 100644 --- a/src/audio/inductor.h +++ b/src/audio/inductor.h @@ -1,7 +1,6 @@ #pragma once #include -#include extern double inductorCurrentCharge; extern double inductorChargeAtLastSample; diff --git a/src/flx68000.c b/src/flx68000.c index f9e0d0b..b2bd448 100755 --- a/src/flx68000.c +++ b/src/flx68000.c @@ -295,7 +295,7 @@ bool flx68000IsSupervisor(){ #if defined(EMU_OPTIMIZE_FOR_ARM) return CycloneGetSr(&cycloneCpu) & 0x2000; #else - return m68k_get_reg(NULL, M68K_REG_SR) & 0x2000; + return !!(m68k_get_reg(NULL, M68K_REG_SR) & 0x2000); #endif } diff --git a/src/hardwareRegisters.c b/src/hardwareRegisters.c index ddbc37d..060de41 100644 --- a/src/hardwareRegisters.c +++ b/src/hardwareRegisters.c @@ -51,11 +51,11 @@ bool pllIsOn(){ } bool backlightAmplifierState(){ - return getPortKValue() & 0x02; + return !!(getPortKValue() & 0x02); } bool registersAreXXFFMapped(){ - return registerArrayRead8(SCR) & 0x04; + return !!(registerArrayRead8(SCR) & 0x04); } bool sed1376ClockConnected(){ @@ -281,7 +281,7 @@ static void checkPortDInterrupts(){ */ //IRQ1, polarity set in ICR - if(portDIrqPins & ~portDDir & 0x10 && (bool)(portDInputValues & 0x10) == (bool)(interruptControlRegister & 0x8000)){ + if(portDIrqPins & ~portDDir & 0x10 && !!(portDInputValues & 0x10) == !!(interruptControlRegister & 0x8000)){ if(!(interruptControlRegister & 0x0800) || !(interruptEdgeTriggered & INT_IRQ1)) setIprIsrBit(INT_IRQ1); interruptEdgeTriggered |= INT_IRQ1; @@ -293,7 +293,7 @@ static void checkPortDInterrupts(){ } //IRQ2, polarity set in ICR - if(portDIrqPins & ~portDDir & 0x20 && (bool)(portDInputValues & 0x20) == (bool)(interruptControlRegister & 0x4000)){ + if(portDIrqPins & ~portDDir & 0x20 && !!(portDInputValues & 0x20) == !!(interruptControlRegister & 0x4000)){ if(!(interruptControlRegister & 0x0400) || !(interruptEdgeTriggered & INT_IRQ2)) setIprIsrBit(INT_IRQ2); interruptEdgeTriggered |= INT_IRQ2; @@ -305,7 +305,7 @@ static void checkPortDInterrupts(){ } //IRQ3, polarity set in ICR - if(portDIrqPins & ~portDDir & 0x40 && (bool)(portDInputValues & 0x40) == (bool)(interruptControlRegister & 0x2000)){ + if(portDIrqPins & ~portDDir & 0x40 && !!(portDInputValues & 0x40) == !!(interruptControlRegister & 0x2000)){ if(!(interruptControlRegister & 0x0200) || !(interruptEdgeTriggered & INT_IRQ3)) setIprIsrBit(INT_IRQ3); interruptEdgeTriggered |= INT_IRQ3; @@ -317,7 +317,7 @@ static void checkPortDInterrupts(){ } //IRQ6, polarity set in ICR - if(portDIrqPins & ~portDDir & 0x80 && (bool)(portDInputValues & 0x80) == (bool)(interruptControlRegister & 0x1000)){ + if(portDIrqPins & ~portDDir & 0x80 && !!(portDInputValues & 0x80) == !!(interruptControlRegister & 0x1000)){ if(!(interruptControlRegister & 0x0100) || !(interruptEdgeTriggered & INT_IRQ6)) setIprIsrBit(INT_IRQ6); interruptEdgeTriggered |= INT_IRQ6; diff --git a/src/hardwareRegistersAccessors.c.h b/src/hardwareRegistersAccessors.c.h index 7ea358f..adb05a7 100644 --- a/src/hardwareRegistersAccessors.c.h +++ b/src/hardwareRegistersAccessors.c.h @@ -81,7 +81,7 @@ int32_t pwm1FifoRunSample(int32_t now, int32_t clockOffset){ uint8_t sample = pwm1Fifo[pwm1ReadPosition]; uint16_t period = registerArrayRead8(PWMP1) + 2; uint16_t pwmc1 = registerArrayRead16(PWMC1); - bool usingClk32 = pwmc1 & 0x8000; + bool usingClk32 = !!(pwmc1 & 0x8000); uint8_t prescaler = (pwmc1 >> 8 & 0x7F) + 1; uint8_t clockDivider = 2 << (pwmc1 & 0x03); uint8_t repeat = 1 << (pwmc1 >> 2 & 0x03); @@ -619,7 +619,7 @@ static void samplePwm1(bool forClk32, double sysclks){ int32_t audioClocks; //check if enabled and validate clock mode, CLK32 is used if PLL is disabled as the inductor still needs to settle - if(forClk32 != (bool)(pwmc1 & 0x8000) && !(forClk32 && palmSysclksPerClk32 < 1.0)) + if(forClk32 != !!(pwmc1 & 0x8000) && !(forClk32 && palmSysclksPerClk32 < 1.0)) return; //these calculations are fairly heavy, only do them after we know the clock mode is valid @@ -667,7 +667,7 @@ static uint16_t getPwmc1(){ //updaters static void updatePowerButtonLedStatus(){ - palmMisc.powerButtonLed = (bool)(getPortBValue() & 0x40) != palmMisc.batteryCharging; + palmMisc.powerButtonLed = !!(getPortBValue() & 0x40) != palmMisc.batteryCharging; } static void updateVibratorStatus(){ diff --git a/src/portability.h b/src/portability.h index 6720427..d84c8b4 100644 --- a/src/portability.h +++ b/src/portability.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef PORTABILITY_H +#define PORTABILITY_H #include #include @@ -25,10 +26,6 @@ static inline void swap16BufferIfLittle(uint8_t* buffer, uint64_t count){ #define MULTITHREAD_DOUBLE_LOOP #endif -static inline const char* boolString(bool boo){ - return boo ? "true" : "false"; -} - static inline uint64_t uMin(uint64_t x, uint64_t y){ return x < y ? x : y; } @@ -157,3 +154,5 @@ static inline bool readStateValueBool(uint8_t* where){ static inline void writeStateValueBool(uint8_t* where, bool value){ where[0] = value; } + +#endif