Re: [hatari-devel] Switching from SDL_types.h to inttypes.h ? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
Hi,
On 29.9.2022 23.56, Nicolas Pomarède wrote:
in tos.c, I see that some variables are still using SDL types Sint16 :
typedef struct
{
uint16_t Version;
Sint16 Country;
const char *pszName;
int Flags;
uint32_t Address;
uint32_t OldData;
uint32_t Size;
const void *pNewData;
} TOS_PATCH;
any reason for that, or is it sthg you forgot to change ?
It's not the only place earlier type conversions missed in the files
they touched. Attached patch lists rest of them.
I'll push it unless there's a good reason not to...
- Eero
From ea0f84282c8407230a5e9d152df5626cd3752875 Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Thu, 29 Sep 2022 00:32:51 +0300
Subject: [PATCH] Complete earlier SDL_types.h independence commit
Earlier commits missed some of the SDL types in the files.
Remaining ones were converted with:
for x in 8 16 32 64; do
sed -i \
-e "s/\bUint${x}\b/uint${x}_t/g" \
-e "s/\bSint${x}\b/int${x}_t/g" \
<files>;
done
Fixes: 887c862e446
Fixes: 842d4bb32a8
Fixes: b29bcad91c4
---
src/floppy_ipf.c | 2 +-
src/gemdos.c | 22 ++++-----
src/ikbd.c | 4 +-
src/sound.c | 88 ++++++++++++++++-----------------
src/tos.c | 2 +-
tests/debugger/test-breakcond.c | 12 ++---
tests/debugger/test-dummies.c | 4 +-
7 files changed, 67 insertions(+), 67 deletions(-)
diff --git a/src/floppy_ipf.c b/src/floppy_ipf.c
index c5e39c87..ec23e0ab 100644
--- a/src/floppy_ipf.c
+++ b/src/floppy_ipf.c
@@ -70,7 +70,7 @@ typedef struct
bool DoubleSided[ MAX_FLOPPYDRIVES ];/* Is drive double sided or not */
#endif
- Sint64 FdcClock; /* Current value of CyclesGlobalClockCounter */
+ int64_t FdcClock; /* Current value of CyclesGlobalClockCounter */
} IPF_STRUCT;
diff --git a/src/gemdos.c b/src/gemdos.c
index 66211adf..04ae1bd0 100644
--- a/src/gemdos.c
+++ b/src/gemdos.c
@@ -89,15 +89,15 @@ EMULATEDDRIVE **emudrives = NULL;
typedef struct {
/* GEMDOS internals */
- Uint8 index[2];
- Uint8 magic[4];
+ uint8_t index[2];
+ uint8_t magic[4];
char dta_pat[TOS_NAMELEN]; /* unused */
char dta_sattrib; /* unused */
/* TOS API */
char dta_attrib;
- Uint8 dta_time[2];
- Uint8 dta_date[2];
- Uint8 dta_size[4];
+ uint8_t dta_time[2];
+ uint8_t dta_date[2];
+ uint8_t dta_size[4];
char dta_name[TOS_NAMELEN];
} DTA;
@@ -272,9 +272,9 @@ static bool GemDOS_SetFileInformation(int Handle, DATETIME *DateTime)
/**
* Convert from FindFirstFile/FindNextFile attribute to GemDOS format
*/
-static Uint8 GemDOS_ConvertAttribute(mode_t mode)
+static uint8_t GemDOS_ConvertAttribute(mode_t mode)
{
- Uint8 Attrib = 0;
+ uint8_t Attrib = 0;
/* Directory attribute */
if (S_ISDIR(mode))
@@ -2334,7 +2334,7 @@ static bool GemDOS_Read(uint32_t Params)
}
/* Limit to size of file to prevent errors */
- if (Size > (Uint32)nBytesLeft)
+ if (Size > (uint32_t)nBytesLeft)
Size = nBytesLeft;
/* Check that read is to valid memory area */
@@ -2377,7 +2377,7 @@ static bool GemDOS_Write(uint32_t Params)
char *pBuffer;
long nBytesWritten;
uint32_t Addr;
- Sint32 Size;
+ int32_t Size;
int Handle, fh_idx;
FILE *fp;
@@ -2514,7 +2514,7 @@ static bool GemDOS_LSeek(uint32_t Params)
FILE *fhndl;
/* Read details from stack */
- Offset = (Sint32)STMemory_ReadLong(Params);
+ Offset = (int32_t)STMemory_ReadLong(Params);
Handle = STMemory_ReadWord(Params+SIZE_LONG);
Mode = STMemory_ReadWord(Params+SIZE_LONG+SIZE_WORD);
@@ -3332,7 +3332,7 @@ static bool GemDOS_Pterm0(uint32_t Params)
static bool GemDOS_Ptermres(uint32_t Params)
{
LOG_TRACE(TRACE_OS_GEMDOS|TRACE_OS_BASE, "GEMDOS 0x31 Ptermres(0x%X, %hd) at PC 0x%X\n",
- STMemory_ReadLong(Params), (Sint16)STMemory_ReadWord(Params+SIZE_WORD),
+ STMemory_ReadLong(Params), (int16_t)STMemory_ReadWord(Params+SIZE_WORD),
CallingPC);
GemDOS_TerminateClose();
return false;
diff --git a/src/ikbd.c b/src/ikbd.c
index 6646f444..a1dfed43 100644
--- a/src/ikbd.c
+++ b/src/ikbd.c
@@ -318,7 +318,7 @@ typedef struct {
/* Clock is cleared on cold reset, but keeps its values on warm reset */
/* Original RAM location : $82=year $83=month $84=day $85=hour $86=minute $87=second */
uint8_t Clock[ 6 ];
- Sint64 Clock_micro; /* Incremented every VBL to update Clock[] every second */
+ int64_t Clock_micro; /* Incremented every VBL to update Clock[] every second */
} IKBD_STRUCT;
@@ -1117,7 +1117,7 @@ static uint8_t IKBD_BCD_Adjust ( uint8_t val )
*/
void IKBD_UpdateClockOnVBL ( void )
{
- Sint64 FrameDuration_micro;
+ int64_t FrameDuration_micro;
int i;
uint8_t val;
uint8_t max;
diff --git a/src/sound.c b/src/sound.c
index 78a85c90..6ce935e0 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -317,8 +317,8 @@ ymsample YM_Buffer_250[ YM_BUFFER_250_SIZE ]; /* Ring buffer to store YM samples
static int YM_Buffer_250_pos_write; /* Current writing position into above buffer */
static int YM_Buffer_250_pos_read; /* Current reading position into above buffer */
-static Uint64 YM2149_Clock_250; /* 250 kHz counter */
-static Uint64 YM2149_Clock_250_CpuClock; /* Corresponding value of CyclesGlobalClockCounter at the time YM2149_Clock_250 was updated */
+static uint64_t YM2149_Clock_250; /* 250 kHz counter */
+static uint64_t YM2149_Clock_250_CpuClock; /* Corresponding value of CyclesGlobalClockCounter at the time YM2149_Clock_250 was updated */
@@ -347,7 +347,7 @@ static void YM2149_Normalise_5bit_Table(ymu16 *in_5bit , yms16 *out_5bit, unsign
static void YM2149_EnvBuild (void);
static void Ym2149_BuildVolumeTable (void);
-static void YM2149_UpdateClock_250 ( Uint64 CpuClock );
+static void YM2149_UpdateClock_250 ( uint64_t CpuClock );
static void Ym2149_Init (void);
static void Ym2149_Reset (void);
@@ -356,8 +356,8 @@ static ymu16 YM2149_TonePer (ymu8 rHigh , ymu8 rLow);
static ymu16 YM2149_NoisePer (ymu8 rNoise);
static ymu16 YM2149_EnvPer (ymu8 rHigh , ymu8 rLow);
-static void YM2149_Run ( Uint64 CPU_Clock );
-static int Sound_GenerateSamples ( Uint64 CPU_Clock);
+static void YM2149_Run ( uint64_t CPU_Clock );
+static int Sound_GenerateSamples ( uint64_t CPU_Clock);
static void YM2149_DoSamples_250 ( int SamplesToGenerate_250 );
#ifdef YM_250_DEBUG
static void YM2149_DoSamples_250_Debug ( int SamplesToGenerate , int pos );
@@ -800,11 +800,11 @@ static void Ym2149_BuildVolumeTable(void)
#if 0
/* integer version : use it when YM2149's clock is the same as CPU's clock (eg STF) */
-static void YM2149_UpdateClock_250_int ( Uint64 CpuClock )
+static void YM2149_UpdateClock_250_int ( uint64_t CpuClock )
{
- Uint64 CpuClockDiff;
- Uint64 YM_Div;
- Uint64 YM_Inc;
+ uint64_t CpuClockDiff;
+ uint64_t YM_Div;
+ uint64_t YM_Inc;
/* We divide CpuClockDiff by YM_Div to get a 250 Hz YM clock increment (YM_Div=32 for an STF with a 8 MHz CPU) */
YM_Div = 32 << nCpuFreqShift;
@@ -828,11 +828,11 @@ static void YM2149_UpdateClock_250_int ( Uint64 CpuClock )
/* floating point version : use it when YM2149's clock is different from CPU's clock (eg STE) */
-static void YM2149_UpdateClock_250_float ( Uint64 CpuClock )
+static void YM2149_UpdateClock_250_float ( uint64_t CpuClock )
{
- Uint64 CpuClockDiff;
+ uint64_t CpuClockDiff;
double YM_Div;
- Uint64 YM_Inc;
+ uint64_t YM_Inc;
/* We divide CpuClockDiff by YM_Div to get a 250 Hz YM clock increment (YM_Div=32.0425 for an STE with a 8 MHz CPU) */
YM_Div = ((double)MachineClocks.CPU_Freq_Emul) / YM_ATARI_CLOCK_COUNTER;
@@ -842,7 +842,7 @@ static void YM2149_UpdateClock_250_float ( Uint64 CpuClock )
CpuClockDiff = CpuClock - YM2149_Clock_250_CpuClock;
if ( CpuClockDiff >= YM_Div )
{
- YM_Inc = CpuClockDiff / YM_Div; /* will truncate to lower integer when casting to Uint64 */
+ YM_Inc = CpuClockDiff / YM_Div; /* will truncate to lower integer when casting to uint64_t */
//fprintf ( stderr , "update_250 in div=%f clock_cpu=%lu cpu_diff=%lu inc=%lu clock_250_in=%lu\n" , YM_Div, CpuClock, CpuClockDiff, YM_Inc, YM2149_Clock_250 );
YM2149_Clock_250 += YM_Inc;
YM2149_Clock_250_CpuClock = CpuClock - round ( fmod ( CpuClockDiff , YM_Div ) );
@@ -854,9 +854,9 @@ static void YM2149_UpdateClock_250_float ( Uint64 CpuClock )
#endif
-static void YM2149_UpdateClock_250_int_new ( Uint64 CpuClock )
+static void YM2149_UpdateClock_250_int_new ( uint64_t CpuClock )
{
- Uint64 CpuClockDiff;
+ uint64_t CpuClockDiff;
CpuClockDiff = CpuClock - YM2149_Clock_250_CpuClock;
@@ -880,7 +880,7 @@ static void YM2149_UpdateClock_250_int_new ( Uint64 CpuClock )
* In the end, 'integer' and 'floating point' versions will sound the same because
* floating point precision should be good enough to avoid rounding errors.
*/
-static void YM2149_UpdateClock_250 ( Uint64 CpuClock )
+static void YM2149_UpdateClock_250 ( uint64_t CpuClock )
{
if ( ConfigureParams.System.nMachineType == MACHINE_ST || ConfigureParams.System.nMachineType == MACHINE_MEGA_ST )
{
@@ -1138,7 +1138,7 @@ static void YM2149_DoSamples_250 ( int SamplesToGenerate_250 )
*/
static void YM2149_DoSamples_250_Debug ( int SamplesToGenerate , int pos )
{
- static Uint8 WavHeader[] =
+ static uint8_t WavHeader[] =
{
/* RIFF chunk */
'R', 'I', 'F', 'F', /* "RIFF" (ASCII Characters) */
@@ -1173,21 +1173,21 @@ static void YM2149_DoSamples_250_Debug ( int SamplesToGenerate , int pos )
{
file_ptr = fopen( "hatari_250.wav", "wb");
/* Patch mono, 2 bytes per sample */
- WavHeader[22] = (Uint8)0x01;
- WavHeader[32] = (Uint8)0x02;
+ WavHeader[22] = (uint8_t)0x01;
+ WavHeader[32] = (uint8_t)0x02;
/* Patch sample frequency in header structure */
val = 250000;
- WavHeader[24] = (Uint8)val;
- WavHeader[25] = (Uint8)(val >> 8);
- WavHeader[26] = (Uint8)(val >> 16);
- WavHeader[27] = (Uint8)(val >> 24);
+ WavHeader[24] = (uint8_t)val;
+ WavHeader[25] = (uint8_t)(val >> 8);
+ WavHeader[26] = (uint8_t)(val >> 16);
+ WavHeader[27] = (uint8_t)(val >> 24);
/* Patch bytes per second in header structure */
val = 250000 * 2;
- WavHeader[28] = (Uint8)val;
- WavHeader[29] = (Uint8)(val >> 8);
- WavHeader[30] = (Uint8)(val >> 16);
- WavHeader[31] = (Uint8)(val >> 24);
+ WavHeader[28] = (uint8_t)val;
+ WavHeader[29] = (uint8_t)(val >> 8);
+ WavHeader[30] = (uint8_t)(val >> 16);
+ WavHeader[31] = (uint8_t)(val >> 24);
fwrite ( &WavHeader, sizeof(WavHeader), 1, file_ptr );
}
@@ -1202,15 +1202,15 @@ static void YM2149_DoSamples_250_Debug ( int SamplesToGenerate , int pos )
/* Update sizes in header */
val = 12+24+8+wav_size-8; /* RIFF size */
- WavHeader[4] = (Uint8)val;
- WavHeader[5] = (Uint8)(val >> 8);
- WavHeader[6] = (Uint8)(val >> 16);
- WavHeader[7] = (Uint8)(val >> 24);
+ WavHeader[4] = (uint8_t)val;
+ WavHeader[5] = (uint8_t)(val >> 8);
+ WavHeader[6] = (uint8_t)(val >> 16);
+ WavHeader[7] = (uint8_t)(val >> 24);
val = wav_size; /* data size */
- WavHeader[40] = (Uint8)val;
- WavHeader[41] = (Uint8)(val >> 8);
- WavHeader[42] = (Uint8)(val >> 16);
- WavHeader[43] = (Uint8)(val >> 24);
+ WavHeader[40] = (uint8_t)val;
+ WavHeader[41] = (uint8_t)(val >> 8);
+ WavHeader[42] = (uint8_t)(val >> 16);
+ WavHeader[43] = (uint8_t)(val >> 24);
rewind ( file_ptr );
fwrite ( &WavHeader, sizeof(WavHeader), 1, file_ptr );
@@ -1234,9 +1234,9 @@ static void YM2149_DoSamples_250_Debug ( int SamplesToGenerate , int pos )
* On each call, we consider samples were already generated up to (and including) counter value
* YM2149_Clock_250_prev. We must generate as many samples to reach (and include) YM2149_Clock_250.
*/
-static void YM2149_Run ( Uint64 CPU_Clock )
+static void YM2149_Run ( uint64_t CPU_Clock )
{
- Uint64 YM2149_Clock_250_prev;
+ uint64_t YM2149_Clock_250_prev;
int YM2149_Nb_Updates_250;
@@ -1344,9 +1344,9 @@ static ymsample YM2149_Next_Resample_Weighted_Average_2 ( void )
*/
static ymsample YM2149_Next_Resample_Weighted_Average_N ( void )
{
- static Uint32 pos_fract = 0;
- Uint32 interval_fract;
- Sint64 total;
+ static uint32_t pos_fract = 0;
+ uint32_t interval_fract;
+ int64_t total;
ymsample sample;
@@ -1357,7 +1357,7 @@ static ymsample YM2149_Next_Resample_Weighted_Average_2 ( void )
if ( pos_fract ) /* start position : 0xffff <= pos_fract <= 0 */
{
- total += ((Sint64)YM_Buffer_250[ YM_Buffer_250_pos_read ]) * ( 0x10000 - pos_fract );
+ total += ((int64_t)YM_Buffer_250[ YM_Buffer_250_pos_read ]) * ( 0x10000 - pos_fract );
YM_Buffer_250_pos_read = ( YM_Buffer_250_pos_read + 1 ) & YM_BUFFER_250_SIZE_MASK;
pos_fract -= 0x10000; /* next sample */
}
@@ -1366,14 +1366,14 @@ static ymsample YM2149_Next_Resample_Weighted_Average_2 ( void )
while ( pos_fract & 0xffff0000 ) /* check integer part */
{
- total += ((Sint64)YM_Buffer_250[ YM_Buffer_250_pos_read ]) * 0x10000;
+ total += ((int64_t)YM_Buffer_250[ YM_Buffer_250_pos_read ]) * 0x10000;
YM_Buffer_250_pos_read = ( YM_Buffer_250_pos_read + 1 ) & YM_BUFFER_250_SIZE_MASK;
pos_fract -= 0x10000; /* next sample */
}
if ( pos_fract ) /* partial end sample if 0xffff <= pos_fract < 0 */
{
- total += ((Sint64)YM_Buffer_250[ YM_Buffer_250_pos_read ]) * pos_fract;
+ total += ((int64_t)YM_Buffer_250[ YM_Buffer_250_pos_read ]) * pos_fract;
}
//fprintf ( stderr , "next 2 %d\n" , YM_Buffer_250_pos_read );
@@ -1690,7 +1690,7 @@ void Sound_Stats_Show ( void )
/**
* Generate output samples for all channels (YM2149, DMA or crossbar) during this time-frame
*/
-static int Sound_GenerateSamples(Uint64 CPU_Clock)
+static int Sound_GenerateSamples(uint64_t CPU_Clock)
{
int idx;
int ym_margin;
diff --git a/src/tos.c b/src/tos.c
index b2f9be59..8d3d1bdc 100644
--- a/src/tos.c
+++ b/src/tos.c
@@ -82,7 +82,7 @@ enum
typedef struct
{
uint16_t Version; /* TOS version number */
- Sint16 Country; /* TOS country code: -1 if it does not matter, 0=US, 1=Germany, 2=France, etc. */
+ int16_t Country; /* TOS country code: -1 if it does not matter, 0=US, 1=Germany, 2=France, etc. */
const char *pszName; /* Name of the patch */
int Flags; /* When should the patch be applied? (see enum above) */
uint32_t Address; /* Where the patch should be applied */
diff --git a/tests/debugger/test-breakcond.c b/tests/debugger/test-breakcond.c
index 51ebfe2c..6320c36b 100644
--- a/tests/debugger/test-breakcond.c
+++ b/tests/debugger/test-breakcond.c
@@ -16,16 +16,16 @@
#define CMD_REMOVE_ALL "all"
-static bool SetCpuRegister(const char *regname, Uint32 value)
+static bool SetCpuRegister(const char *regname, uint32_t value)
{
- Uint32 *addr;
+ uint32_t *addr;
switch (DebugCpu_GetRegisterAddress(regname, &addr)) {
case 32:
*addr = value;
break;
case 16:
- *(Uint16*)addr = value;
+ *(uint16_t*)addr = value;
break;
default:
fprintf(stderr, "SETUP ERROR: Register '%s' to set (to %x) is unrecognized!\n", regname, value);
@@ -35,16 +35,16 @@ static bool SetCpuRegister(const char *regname, Uint32 value)
}
#if 0
-static bool SetDspRegister(const char *regname, Uint32 value)
+static bool SetDspRegister(const char *regname, uint32_t value)
{
- Uint32 *addr, mask;
+ uint32_t *addr, mask;
switch (DSP_GetRegisterAddress(regname, &addr, &mask)) {
case 32:
*addr = value & mask;
break;
case 16:
- *(Uint16*)addr = value & mask;
+ *(uint16_t*)addr = value & mask;
break;
default:
return false;
diff --git a/tests/debugger/test-dummies.c b/tests/debugger/test-dummies.c
index 8a1ca709..e52adc43 100644
--- a/tests/debugger/test-dummies.c
+++ b/tests/debugger/test-dummies.c
@@ -50,11 +50,11 @@ uint16_t STMemory_ReadWord(uint32_t addr) {
val = (STRam[addr] << 8) | STRam[addr+1];
return val;
}
-Uint8 STMemory_ReadByte(uint32_t addr) {
+uint8_t STMemory_ReadByte(uint32_t addr) {
if (addr >= STRamEnd) return 0;
return STRam[addr];
}
-void STMemory_WriteByte(uint32_t addr, Uint8 val) {
+void STMemory_WriteByte(uint32_t addr, uint8_t val) {
if (addr < STRamEnd)
STRam[addr] = val;
}
--
2.30.2