Skip to content

Commit

Permalink
use double for timestamps, just to be safe
Browse files Browse the repository at this point in the history
should not cost anything in practice in this case
  • Loading branch information
toxieainc committed Oct 30, 2024
1 parent 1560c54 commit 66b7953
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/wpc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2626,7 +2626,7 @@ void core_update_pwm_outputs(const int startIndex, const int count)
// Write binary state of outputs, taking care of PWM integration based on physical model of the connected device
void core_write_pwm_output(int index, int count, UINT8 bitStates)
{
const float now = (float) timer_get_time();
const double now = timer_get_time();
core_tPhysicOutput* output = &coreGlobals.physicOutputState[index];
for (int i = 0; i < count; i++, bitStates = bitStates >> 1, index++, output++) {
const int pos = index >> 3, ofs = index & 7;
Expand All @@ -2645,7 +2645,7 @@ void core_write_pwm_output_8b(int index, UINT8 bitStates)
UINT8 changeMask = coreGlobals.binaryOutputState[index >> 3] ^ bitStates;
if (!changeMask)
return;
const float now = (float) timer_get_time();
const double now = timer_get_time();
for (core_tPhysicOutput* output = &coreGlobals.physicOutputState[index]; changeMask; changeMask >>= 1, output++)
if (changeMask & 1)
{
Expand All @@ -2662,7 +2662,7 @@ void core_write_masked_pwm_output_8b(int index, UINT8 bitStates, UINT8 bitMask)
UINT8 changeMask = bitMask & (coreGlobals.binaryOutputState[index >> 3] ^ bitStates); // Identify differences
if (!changeMask)
return;
const float now = (float) timer_get_time();
const double now = timer_get_time();
for (core_tPhysicOutput* output = &coreGlobals.physicOutputState[index]; changeMask; changeMask >>= 1, output++)
if (changeMask & 1)
{
Expand Down
9 changes: 4 additions & 5 deletions src/wpc/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ typedef struct {
float switchDownLatency;
} sol; // Physical model of a solenoid
} state;
float flipTimeStamps[FLIP_BUFFER_SIZE];
double flipTimeStamps[FLIP_BUFFER_SIZE];
unsigned int flipBufferPos;
unsigned int lastIntegrationFlipPos;
} core_tPhysicOutput;
Expand Down Expand Up @@ -654,12 +654,11 @@ extern void core_nvram(void *file, int write, void *mem, size_t length, UINT8 in

/* makes it easier to swap bits */
extern const UINT8 core_swapNyb[16];
INLINE UINT8 core_revbyte(UINT8 x) { return (core_swapNyb[x & 0xf]<<4)|(core_swapNyb[x>>4]); }
INLINE UINT8 core_revbyte(UINT8 x) { return (core_swapNyb[x & 0xf] << 4)|(core_swapNyb[x >> 4]); }
INLINE UINT8 core_revnyb(UINT8 x) { return core_swapNyb[x]; }
INLINE UINT16 core_revword(UINT16 x) {
UINT8 lo,hi;
lo = core_revbyte(x & 0x00ff);
hi = core_revbyte((x & 0xff00)>>8);
UINT8 lo = core_revbyte(x & 0x00ff);
UINT8 hi = core_revbyte((x >> 8) & 0x00ff);
return ((lo<<8) | hi);
}

Expand Down

0 comments on commit 66b7953

Please sign in to comment.