Changed pit.c/h to only use int64_t's where really needed.

This commit is contained in:
OBattler
2018-03-28 06:57:26 +02:00
parent 450169b168
commit 4f026e748b
2 changed files with 65 additions and 65 deletions

View File

@@ -59,7 +59,7 @@ void setpitclock(float clock)
void pit_reset(PIT *pit) void pit_reset(PIT *pit)
{ {
void (*old_set_out_funcs[3])(int64_t new_out, int64_t old_out); void (*old_set_out_funcs[3])(int new_out, int old_out);
PIT_nr old_pit_nr[3]; PIT_nr old_pit_nr[3];
memcpy(old_set_out_funcs, pit->set_out_funcs, 3 * sizeof(void *)); memcpy(old_set_out_funcs, pit->set_out_funcs, 3 * sizeof(void *));
@@ -92,15 +92,15 @@ float pit_timer0_freq()
return (1193181.0 + (2.0 / 3.0))/(float)0x10000; return (1193181.0 + (2.0 / 3.0))/(float)0x10000;
} }
static void pit_set_out(PIT *pit, int64_t t, int64_t out) static void pit_set_out(PIT *pit, int t, int out)
{ {
pit->set_out_funcs[t](out, pit->out[t]); pit->set_out_funcs[t](out, pit->out[t]);
pit->out[t] = out; pit->out[t] = out;
} }
static void pit_load(PIT *pit, int64_t t) static void pit_load(PIT *pit, int t)
{ {
int64_t l = pit->l[t] ? pit->l[t] : 0x10000LL; int l = pit->l[t] ? pit->l[t] : 0x10000LL;
timer_clock(); timer_clock();
pit->newcount[t] = 0; pit->newcount[t] = 0;
pit->disabled[t] = 0; pit->disabled[t] = 0;
@@ -108,7 +108,7 @@ static void pit_load(PIT *pit, int64_t t)
{ {
case 0: /*Interrupt on terminal count*/ case 0: /*Interrupt on terminal count*/
pit->count[t] = l; pit->count[t] = l;
pit->c[t] = (int64_t)((l << TIMER_SHIFT) * PITCONST); pit->c[t] = (int64_t)((((int64_t) l) << TIMER_SHIFT) * PITCONST);
pit_set_out(pit, t, 0); pit_set_out(pit, t, 0);
pit->thit[t] = 0; pit->thit[t] = 0;
pit->enabled[t] = pit->gate[t]; pit->enabled[t] = pit->gate[t];
@@ -120,7 +120,7 @@ static void pit_load(PIT *pit, int64_t t)
if (pit->initial[t]) if (pit->initial[t])
{ {
pit->count[t] = l - 1; pit->count[t] = l - 1;
pit->c[t] = (int64_t)(((l - 1) << TIMER_SHIFT) * PITCONST); pit->c[t] = (int64_t)(((((int64_t) l) - 1LL) << TIMER_SHIFT) * PITCONST);
pit_set_out(pit, t, 1); pit_set_out(pit, t, 1);
pit->thit[t] = 0; pit->thit[t] = 0;
} }
@@ -130,7 +130,7 @@ static void pit_load(PIT *pit, int64_t t)
if (pit->initial[t]) if (pit->initial[t])
{ {
pit->count[t] = l; pit->count[t] = l;
pit->c[t] = (int64_t)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST); pit->c[t] = (int64_t)((((((int64_t) l) + 1LL) >> 1) << TIMER_SHIFT) * PITCONST);
pit_set_out(pit, t, 1); pit_set_out(pit, t, 1);
pit->thit[t] = 0; pit->thit[t] = 0;
} }
@@ -157,7 +157,7 @@ static void pit_load(PIT *pit, int64_t t)
timer_update_outstanding(); timer_update_outstanding();
} }
void pit_set_gate_no_timer(PIT *pit, int64_t t, int64_t gate) void pit_set_gate_no_timer(PIT *pit, int t, int gate)
{ {
int64_t l = pit->l[t] ? pit->l[t] : 0x10000LL; int64_t l = pit->l[t] ? pit->l[t] : 0x10000LL;
@@ -178,7 +178,7 @@ void pit_set_gate_no_timer(PIT *pit, int64_t t, int64_t gate)
if (gate && !pit->gate[t]) if (gate && !pit->gate[t])
{ {
pit->count[t] = l; pit->count[t] = l;
pit->c[t] = (int64_t)((l << TIMER_SHIFT) * PITCONST); pit->c[t] = (int64_t)((((int64_t) l) << TIMER_SHIFT) * PITCONST);
pit_set_out(pit, t, 0); pit_set_out(pit, t, 0);
pit->thit[t] = 0; pit->thit[t] = 0;
pit->enabled[t] = 1; pit->enabled[t] = 1;
@@ -188,7 +188,7 @@ void pit_set_gate_no_timer(PIT *pit, int64_t t, int64_t gate)
if (gate && !pit->gate[t]) if (gate && !pit->gate[t])
{ {
pit->count[t] = l - 1; pit->count[t] = l - 1;
pit->c[t] = (int64_t)(((l - 1) << TIMER_SHIFT) * PITCONST); pit->c[t] = (int64_t)(((((int64_t) l) - 1LL) << TIMER_SHIFT) * PITCONST);
pit_set_out(pit, t, 1); pit_set_out(pit, t, 1);
pit->thit[t] = 0; pit->thit[t] = 0;
} }
@@ -198,7 +198,7 @@ void pit_set_gate_no_timer(PIT *pit, int64_t t, int64_t gate)
if (gate && !pit->gate[t]) if (gate && !pit->gate[t])
{ {
pit->count[t] = l; pit->count[t] = l;
pit->c[t] = (int64_t)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST); pit->c[t] = (int64_t)((((((int64_t) l) + 1LL) >> 1) << TIMER_SHIFT) * PITCONST);
pit_set_out(pit, t, 1); pit_set_out(pit, t, 1);
pit->thit[t] = 0; pit->thit[t] = 0;
} }
@@ -209,7 +209,7 @@ void pit_set_gate_no_timer(PIT *pit, int64_t t, int64_t gate)
pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t]; pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t];
} }
void pit_set_gate(PIT *pit, int64_t t, int64_t gate) void pit_set_gate(PIT *pit, int t, int gate)
{ {
if (pit->disabled[t]) if (pit->disabled[t])
{ {
@@ -224,13 +224,13 @@ void pit_set_gate(PIT *pit, int64_t t, int64_t gate)
timer_update_outstanding(); timer_update_outstanding();
} }
static void pit_over(PIT *pit, int64_t t) static void pit_over(PIT *pit, int t)
{ {
int64_t l = pit->l[t] ? pit->l[t] : 0x10000LL; int64_t l = pit->l[t] ? pit->l[t] : 0x10000LL;
if (pit->disabled[t]) if (pit->disabled[t])
{ {
pit->count[t] += 0xffff; pit->count[t] += 0xffff;
pit->c[t] += (int64_t)((0xffff << TIMER_SHIFT) * PITCONST); pit->c[t] += (int64_t)((0xffffLL << TIMER_SHIFT) * PITCONST);
return; return;
} }
@@ -242,11 +242,11 @@ static void pit_over(PIT *pit, int64_t t)
pit_set_out(pit, t, 1); pit_set_out(pit, t, 1);
pit->thit[t] = 1; pit->thit[t] = 1;
pit->count[t] += 0xffff; pit->count[t] += 0xffff;
pit->c[t] += (int64_t)((0xffff << TIMER_SHIFT) * PITCONST); pit->c[t] += (int64_t)((0xffffLL << TIMER_SHIFT) * PITCONST);
break; break;
case 2: /*Rate generator*/ case 2: /*Rate generator*/
pit->count[t] += l; pit->count[t] += l;
pit->c[t] += (int64_t)((l << TIMER_SHIFT) * PITCONST); pit->c[t] += (int64_t)((((int64_t) l) << TIMER_SHIFT) * PITCONST);
pit_set_out(pit, t, 0); pit_set_out(pit, t, 0);
pit_set_out(pit, t, 1); pit_set_out(pit, t, 1);
break; break;
@@ -255,13 +255,13 @@ static void pit_over(PIT *pit, int64_t t)
{ {
pit_set_out(pit, t, 0); pit_set_out(pit, t, 0);
pit->count[t] += (l >> 1); pit->count[t] += (l >> 1);
pit->c[t] += (int64_t)(((l >> 1) << TIMER_SHIFT) * PITCONST); pit->c[t] += (int64_t)(((((int64_t) l) >> 1) << TIMER_SHIFT) * PITCONST);
} }
else else
{ {
pit_set_out(pit, t, 1); pit_set_out(pit, t, 1);
pit->count[t] += ((l + 1) >> 1); pit->count[t] += ((l + 1) >> 1);
pit->c[t] = (int64_t)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST); pit->c[t] = (int64_t)((((((int64_t) l) + 1LL) >> 1) << TIMER_SHIFT) * PITCONST);
} }
break; break;
case 4: /*Software triggered strove*/ case 4: /*Software triggered strove*/
@@ -274,13 +274,13 @@ static void pit_over(PIT *pit, int64_t t)
{ {
pit->newcount[t] = 0; pit->newcount[t] = 0;
pit->count[t] += l; pit->count[t] += l;
pit->c[t] += (int64_t)((l << TIMER_SHIFT) * PITCONST); pit->c[t] += (int64_t)((((int64_t) l) << TIMER_SHIFT) * PITCONST);
} }
else else
{ {
pit->thit[t] = 1; pit->thit[t] = 1;
pit->count[t] += 0xffff; pit->count[t] += 0xffff;
pit->c[t] += (int64_t)((0xffff << TIMER_SHIFT) * PITCONST); pit->c[t] += (int64_t)((0xffffLL << TIMER_SHIFT) * PITCONST);
} }
break; break;
case 5: /*Hardware triggered strove*/ case 5: /*Hardware triggered strove*/
@@ -291,15 +291,15 @@ static void pit_over(PIT *pit, int64_t t)
} }
pit->thit[t] = 1; pit->thit[t] = 1;
pit->count[t] += 0xffff; pit->count[t] += 0xffff;
pit->c[t] += (int64_t)((0xffff << TIMER_SHIFT) * PITCONST); pit->c[t] += (int64_t)((0xffffLL << TIMER_SHIFT) * PITCONST);
break; break;
} }
pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t]; pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t];
} }
int64_t pit_get_timer_0() int pit_get_timer_0()
{ {
int64_t read = (int64_t)((pit.c[0] + ((1 << TIMER_SHIFT) - 1)) / PITCONST) >> TIMER_SHIFT; int read = (int)((int64_t)((pit.c[0] + ((1LL << TIMER_SHIFT) - 1)) / PITCONST) >> TIMER_SHIFT);
if (pit.m[0] == 2) if (pit.m[0] == 2)
read++; read++;
if (read < 0LL) if (read < 0LL)
@@ -311,12 +311,12 @@ int64_t pit_get_timer_0()
return read; return read;
} }
static int64_t pit_read_timer(PIT *pit, int64_t t) static int pit_read_timer(PIT *pit, int t)
{ {
timer_clock(); timer_clock();
if (pit->using_timer[t] && !(pit->m[t] == 3 && !pit->gate[t])) if (pit->using_timer[t] && !(pit->m[t] == 3 && !pit->gate[t]))
{ {
int64_t read = (int64_t)((pit->c[t] + ((1 << TIMER_SHIFT) - 1)) / PITCONST) >> TIMER_SHIFT; int read = (int)((int64_t)((pit->c[t] + ((1 << TIMER_SHIFT) - 1)) / PITCONST) >> TIMER_SHIFT);
if (pit->m[t] == 2) if (pit->m[t] == 2)
read++; read++;
if (read < 0LL) if (read < 0LL)
@@ -335,8 +335,8 @@ static int64_t pit_read_timer(PIT *pit, int64_t t)
void pit_write(uint16_t addr, uint8_t val, void *p) void pit_write(uint16_t addr, uint8_t val, void *p)
{ {
PIT *pit = (PIT *)p; PIT *pit = (PIT *)p;
int64_t t; int t;
cycles -= (int64_t)PITCONST; cycles -= (int)PITCONST;
switch (addr&3) switch (addr&3)
{ {
@@ -444,7 +444,7 @@ uint8_t pit_read(uint16_t addr, void *p)
PIT *pit = (PIT *)p; PIT *pit = (PIT *)p;
int64_t t; int64_t t;
uint8_t temp = 0xff; uint8_t temp = 0xff;
cycles -= (int64_t)PITCONST; cycles -= (int)PITCONST;
switch (addr&3) switch (addr&3)
{ {
case 0: case 1: case 2: /*Timers*/ case 0: case 1: case 2: /*Timers*/
@@ -503,7 +503,7 @@ void pit_timer_over(void *p)
pit_over(pit, timer); pit_over(pit, timer);
} }
void pit_clock(PIT *pit, int64_t t) void pit_clock(PIT *pit, int t)
{ {
if (pit->thit[t] || !pit->enabled[t]) if (pit->thit[t] || !pit->enabled[t])
return; return;
@@ -516,28 +516,28 @@ void pit_clock(PIT *pit, int64_t t)
pit_over(pit, t); pit_over(pit, t);
} }
void pit_set_using_timer(PIT *pit, int64_t t, int64_t using_timer) void pit_set_using_timer(PIT *pit, int t, int using_timer)
{ {
timer_process(); timer_process();
if (pit->using_timer[t] && !using_timer) if (pit->using_timer[t] && !using_timer)
pit->count[t] = pit_read_timer(pit, t); pit->count[t] = pit_read_timer(pit, t);
if (!pit->using_timer[t] && using_timer) if (!pit->using_timer[t] && using_timer)
pit->c[t] = (int64_t)((pit->count[t] << TIMER_SHIFT) * PITCONST); pit->c[t] = (int64_t)((((int64_t) pit->count[t]) << TIMER_SHIFT) * PITCONST);
pit->using_timer[t] = using_timer; pit->using_timer[t] = using_timer;
pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t]; pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t];
timer_update_outstanding(); timer_update_outstanding();
} }
void pit_set_out_func(PIT *pit, int64_t t, void (*func)(int64_t new_out, int64_t old_out)) void pit_set_out_func(PIT *pit, int t, void (*func)(int new_out, int old_out))
{ {
pit->set_out_funcs[t] = func; pit->set_out_funcs[t] = func;
} }
void pit_null_timer(int64_t new_out, int64_t old_out) void pit_null_timer(int new_out, int old_out)
{ {
} }
void pit_irq0_timer(int64_t new_out, int64_t old_out) void pit_irq0_timer(int new_out, int old_out)
{ {
if (new_out && !old_out) if (new_out && !old_out)
picint(1); picint(1);
@@ -545,7 +545,7 @@ void pit_irq0_timer(int64_t new_out, int64_t old_out)
picintc(1); picintc(1);
} }
void pit_irq0_timer_pcjr(int64_t new_out, int64_t old_out) void pit_irq0_timer_pcjr(int new_out, int old_out)
{ {
if (new_out && !old_out) if (new_out && !old_out)
{ {
@@ -556,7 +556,7 @@ void pit_irq0_timer_pcjr(int64_t new_out, int64_t old_out)
picintc(1); picintc(1);
} }
void pit_irq0_ps2(int64_t new_out, int64_t old_out) void pit_irq0_ps2(int new_out, int old_out)
{ {
if (new_out && !old_out) if (new_out && !old_out)
{ {
@@ -569,19 +569,19 @@ void pit_irq0_ps2(int64_t new_out, int64_t old_out)
pit_clock(&pit2, 0); pit_clock(&pit2, 0);
} }
void pit_refresh_timer_xt(int64_t new_out, int64_t old_out) void pit_refresh_timer_xt(int new_out, int old_out)
{ {
if (new_out && !old_out) if (new_out && !old_out)
dma_channel_read(0); dma_channel_read(0);
} }
void pit_refresh_timer_at(int64_t new_out, int64_t old_out) void pit_refresh_timer_at(int new_out, int old_out)
{ {
if (new_out && !old_out) if (new_out && !old_out)
ppi.pb ^= 0x10; ppi.pb ^= 0x10;
} }
void pit_speaker_timer(int64_t new_out, int64_t old_out) void pit_speaker_timer(int new_out, int old_out)
{ {
int64_t l; int64_t l;
@@ -596,7 +596,7 @@ void pit_speaker_timer(int64_t new_out, int64_t old_out)
} }
void pit_nmi_ps2(int64_t new_out, int64_t old_out) void pit_nmi_ps2(int new_out, int old_out)
{ {
nmi = new_out; nmi = new_out;
if (nmi) if (nmi)

View File

@@ -13,30 +13,30 @@ typedef struct PIT {
uint8_t m[3]; uint8_t m[3];
uint8_t ctrl, uint8_t ctrl,
ctrls[3]; ctrls[3];
int64_t wp, int wp,
rm[3], rm[3],
wm[3]; wm[3];
uint16_t rl[3]; uint16_t rl[3];
int64_t thit[3]; int thit[3];
int64_t delay[3]; int delay[3];
int64_t rereadlatch[3]; int rereadlatch[3];
int64_t gate[3]; int gate[3];
int64_t out[3]; int out[3];
int64_t running[3]; int64_t running[3];
int64_t enabled[3]; int enabled[3];
int64_t newcount[3]; int newcount[3];
int64_t count[3]; int count[3];
int64_t using_timer[3]; int using_timer[3];
int64_t initial[3]; int initial[3];
int64_t latched[3]; int latched[3];
int64_t disabled[3]; int disabled[3];
uint8_t read_status[3]; uint8_t read_status[3];
int64_t do_read_status[3]; int do_read_status[3];
PIT_nr pit_nr[3]; PIT_nr pit_nr[3];
void (*set_out_funcs[3])(int64_t new_out, int64_t old_out); void (*set_out_funcs[3])(int new_out, int old_out);
} PIT; } PIT;
@@ -53,20 +53,20 @@ extern float CGACONST,
extern void pit_init(void); extern void pit_init(void);
extern void pit_ps2_init(void); extern void pit_ps2_init(void);
extern void pit_reset(PIT *pit); extern void pit_reset(PIT *pit);
extern void pit_set_gate(PIT *pit, int64_t channel, int64_t gate); extern void pit_set_gate(PIT *pit, int channel, int gate);
extern void pit_set_using_timer(PIT *pit, int64_t t, int64_t using_timer); extern void pit_set_using_timer(PIT *pit, int t, int using_timer);
extern void pit_set_out_func(PIT *pit, int64_t t, void (*func)(int64_t new_out, int64_t old_out)); extern void pit_set_out_func(PIT *pit, int t, void (*func)(int new_out, int old_out));
extern void pit_clock(PIT *pit, int64_t t); extern void pit_clock(PIT *pit, int t);
extern void setpitclock(float clock); extern void setpitclock(float clock);
extern float pit_timer0_freq(void); extern float pit_timer0_freq(void);
extern void pit_null_timer(int64_t new_out, int64_t old_out); extern void pit_null_timer(int new_out, int old_out);
extern void pit_irq0_timer(int64_t new_out, int64_t old_out); extern void pit_irq0_timer(int new_out, int old_out);
extern void pit_irq0_timer_pcjr(int64_t new_out, int64_t old_out); extern void pit_irq0_timer_pcjr(int new_out, int old_out);
extern void pit_refresh_timer_xt(int64_t new_out, int64_t old_out); extern void pit_refresh_timer_xt(int new_out, int old_out);
extern void pit_refresh_timer_at(int64_t new_out, int64_t old_out); extern void pit_refresh_timer_at(int new_out, int old_out);
extern void pit_speaker_timer(int64_t new_out, int64_t old_out); extern void pit_speaker_timer(int new_out, int old_out);
#endif /*EMU_PIT_H*/ #endif /*EMU_PIT_H*/