Timers are now 64-bit.
This commit is contained in:
140
src/pit.c
140
src/pit.c
@@ -21,7 +21,7 @@
|
||||
|
||||
/*B0 to 40, two writes to 43, then two reads - value does not change!*/
|
||||
/*B4 to 40, two writes to 43, then two reads - value _does_ change!*/
|
||||
int displine;
|
||||
int64_t displine;
|
||||
|
||||
double PITCONST;
|
||||
float cpuclock;
|
||||
@@ -32,7 +32,7 @@ float MDACONST;
|
||||
float VGACONST1,VGACONST2;
|
||||
float RTCCONST;
|
||||
|
||||
int firsttime=1;
|
||||
int64_t firsttime=1;
|
||||
void setpitclock(float clock)
|
||||
{
|
||||
cpuclock=clock;
|
||||
@@ -45,15 +45,15 @@ void setpitclock(float clock)
|
||||
bus_timing = clock/(double)cpu_busspeed;
|
||||
video_updatetiming();
|
||||
|
||||
xt_cpu_multi = (int)((14318184.0*(double)(1 << TIMER_SHIFT)) / (double)machines[machine].cpu[cpu_manufacturer].cpus[cpu].rspeed);
|
||||
xt_cpu_multi = (int64_t)((14318184.0*(double)(1 << TIMER_SHIFT)) / (double)machines[machine].cpu[cpu_manufacturer].cpus[cpu].rspeed);
|
||||
RTCCONST=clock/32768.0;
|
||||
TIMER_USEC = (int)((clock / 1000000.0f) * (float)(1 << TIMER_SHIFT));
|
||||
TIMER_USEC = (int64_t)((clock / 1000000.0f) * (float)(1 << TIMER_SHIFT));
|
||||
device_speed_changed();
|
||||
}
|
||||
|
||||
void pit_reset(PIT *pit)
|
||||
{
|
||||
void (*old_set_out_funcs[3])(int new_out, int old_out);
|
||||
void (*old_set_out_funcs[3])(int64_t new_out, int64_t old_out);
|
||||
PIT_nr old_pit_nr[3];
|
||||
|
||||
memcpy(old_set_out_funcs, pit->set_out_funcs, 3 * sizeof(void *));
|
||||
@@ -62,9 +62,9 @@ void pit_reset(PIT *pit)
|
||||
memcpy(pit->set_out_funcs, old_set_out_funcs, 3 * sizeof(void *));
|
||||
memcpy(pit->pit_nr, old_pit_nr, 3 * sizeof(PIT_nr));
|
||||
|
||||
pit->l[0] = 0xFFFF; pit->c[0] = 0xFFFF*PITCONST;
|
||||
pit->l[1] = 0xFFFF; pit->c[1] = 0xFFFF*PITCONST;
|
||||
pit->l[2] = 0xFFFF; pit->c[2] = 0xFFFF*PITCONST;
|
||||
pit->l[0] = 0xFFFF; pit->c[0] = 0xFFFFLL*PITCONST;
|
||||
pit->l[1] = 0xFFFF; pit->c[1] = 0xFFFFLL*PITCONST;
|
||||
pit->l[2] = 0xFFFF; pit->c[2] = 0xFFFFLL*PITCONST;
|
||||
pit->m[0] = pit->m[1] = pit->m[2] = 0;
|
||||
pit->ctrls[0] = pit->ctrls[1] = pit->ctrls[2] = 0;
|
||||
pit->thit[0]=1;
|
||||
@@ -86,15 +86,15 @@ float pit_timer0_freq()
|
||||
return (1193181.0 + (2.0 / 3.0))/(float)0x10000;
|
||||
}
|
||||
|
||||
static void pit_set_out(PIT *pit, int t, int out)
|
||||
static void pit_set_out(PIT *pit, int64_t t, int64_t out)
|
||||
{
|
||||
pit->set_out_funcs[t](out, pit->out[t]);
|
||||
pit->out[t] = out;
|
||||
}
|
||||
|
||||
static void pit_load(PIT *pit, int t)
|
||||
static void pit_load(PIT *pit, int64_t t)
|
||||
{
|
||||
int l = pit->l[t] ? pit->l[t] : 0x10000;
|
||||
int64_t l = pit->l[t] ? pit->l[t] : 0x10000LL;
|
||||
timer_process();
|
||||
pit->newcount[t] = 0;
|
||||
pit->disabled[t] = 0;
|
||||
@@ -102,7 +102,7 @@ static void pit_load(PIT *pit, int t)
|
||||
{
|
||||
case 0: /*Interrupt on terminal count*/
|
||||
pit->count[t] = l;
|
||||
pit->c[t] = (int)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit_set_out(pit, t, 0);
|
||||
pit->thit[t] = 0;
|
||||
pit->enabled[t] = pit->gate[t];
|
||||
@@ -114,7 +114,7 @@ static void pit_load(PIT *pit, int t)
|
||||
if (pit->initial[t])
|
||||
{
|
||||
pit->count[t] = l - 1;
|
||||
pit->c[t] = (int)(((l - 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)(((l - 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit_set_out(pit, t, 1);
|
||||
pit->thit[t] = 0;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ static void pit_load(PIT *pit, int t)
|
||||
if (pit->initial[t])
|
||||
{
|
||||
pit->count[t] = l;
|
||||
pit->c[t] = (int)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit_set_out(pit, t, 1);
|
||||
pit->thit[t] = 0;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ static void pit_load(PIT *pit, int t)
|
||||
else
|
||||
{
|
||||
pit->count[t] = l;
|
||||
pit->c[t] = (int)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit_set_out(pit, t, 0);
|
||||
pit->thit[t] = 0;
|
||||
}
|
||||
@@ -151,9 +151,9 @@ static void pit_load(PIT *pit, int t)
|
||||
timer_update_outstanding();
|
||||
}
|
||||
|
||||
void pit_set_gate_no_timer(PIT *pit, int t, int gate)
|
||||
void pit_set_gate_no_timer(PIT *pit, int64_t t, int64_t gate)
|
||||
{
|
||||
int l = pit->l[t] ? pit->l[t] : 0x10000;
|
||||
int64_t l = pit->l[t] ? pit->l[t] : 0x10000LL;
|
||||
|
||||
if (pit->disabled[t])
|
||||
{
|
||||
@@ -172,7 +172,7 @@ void pit_set_gate_no_timer(PIT *pit, int t, int gate)
|
||||
if (gate && !pit->gate[t])
|
||||
{
|
||||
pit->count[t] = l;
|
||||
pit->c[t] = (int)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit_set_out(pit, t, 0);
|
||||
pit->thit[t] = 0;
|
||||
pit->enabled[t] = 1;
|
||||
@@ -182,7 +182,7 @@ void pit_set_gate_no_timer(PIT *pit, int t, int gate)
|
||||
if (gate && !pit->gate[t])
|
||||
{
|
||||
pit->count[t] = l - 1;
|
||||
pit->c[t] = (int)(((l - 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)(((l - 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit_set_out(pit, t, 1);
|
||||
pit->thit[t] = 0;
|
||||
}
|
||||
@@ -192,7 +192,7 @@ void pit_set_gate_no_timer(PIT *pit, int t, int gate)
|
||||
if (gate && !pit->gate[t])
|
||||
{
|
||||
pit->count[t] = l;
|
||||
pit->c[t] = (int)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit_set_out(pit, t, 1);
|
||||
pit->thit[t] = 0;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ void pit_set_gate_no_timer(PIT *pit, int t, int gate)
|
||||
pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t];
|
||||
}
|
||||
|
||||
void pit_set_gate(PIT *pit, int t, int gate)
|
||||
void pit_set_gate(PIT *pit, int64_t t, int64_t gate)
|
||||
{
|
||||
if (pit->disabled[t])
|
||||
{
|
||||
@@ -218,13 +218,13 @@ void pit_set_gate(PIT *pit, int t, int gate)
|
||||
timer_update_outstanding();
|
||||
}
|
||||
|
||||
static void pit_over(PIT *pit, int t)
|
||||
static void pit_over(PIT *pit, int64_t t)
|
||||
{
|
||||
int l = pit->l[t] ? pit->l[t] : 0x10000;
|
||||
int64_t l = pit->l[t] ? pit->l[t] : 0x10000LL;
|
||||
if (pit->disabled[t])
|
||||
{
|
||||
pit->count[t] += 0xffff;
|
||||
pit->c[t] += (int)((0xffff << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] += (int64_t)((0xffff << TIMER_SHIFT) * PITCONST);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -236,11 +236,11 @@ static void pit_over(PIT *pit, int t)
|
||||
pit_set_out(pit, t, 1);
|
||||
pit->thit[t] = 1;
|
||||
pit->count[t] += 0xffff;
|
||||
pit->c[t] += (int)((0xffff << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] += (int64_t)((0xffff << TIMER_SHIFT) * PITCONST);
|
||||
break;
|
||||
case 2: /*Rate generator*/
|
||||
pit->count[t] += l;
|
||||
pit->c[t] += (int)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] += (int64_t)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit_set_out(pit, t, 0);
|
||||
pit_set_out(pit, t, 1);
|
||||
break;
|
||||
@@ -249,13 +249,13 @@ static void pit_over(PIT *pit, int t)
|
||||
{
|
||||
pit_set_out(pit, t, 0);
|
||||
pit->count[t] += (l >> 1);
|
||||
pit->c[t] += (int)(((l >> 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] += (int64_t)(((l >> 1) << TIMER_SHIFT) * PITCONST);
|
||||
}
|
||||
else
|
||||
{
|
||||
pit_set_out(pit, t, 1);
|
||||
pit->count[t] += ((l + 1) >> 1);
|
||||
pit->c[t] = (int)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)((((l + 1) >> 1) << TIMER_SHIFT) * PITCONST);
|
||||
}
|
||||
break;
|
||||
case 4: /*Software triggered strove*/
|
||||
@@ -268,13 +268,13 @@ static void pit_over(PIT *pit, int t)
|
||||
{
|
||||
pit->newcount[t] = 0;
|
||||
pit->count[t] += l;
|
||||
pit->c[t] += (int)((l << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] += (int64_t)((l << TIMER_SHIFT) * PITCONST);
|
||||
}
|
||||
else
|
||||
{
|
||||
pit->thit[t] = 1;
|
||||
pit->count[t] += 0xffff;
|
||||
pit->c[t] += (int)((0xffff << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] += (int64_t)((0xffff << TIMER_SHIFT) * PITCONST);
|
||||
}
|
||||
break;
|
||||
case 5: /*Hardware triggered strove*/
|
||||
@@ -285,52 +285,52 @@ static void pit_over(PIT *pit, int t)
|
||||
}
|
||||
pit->thit[t] = 1;
|
||||
pit->count[t] += 0xffff;
|
||||
pit->c[t] += (int)((0xffff << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] += (int64_t)((0xffff << TIMER_SHIFT) * PITCONST);
|
||||
break;
|
||||
}
|
||||
pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t];
|
||||
}
|
||||
|
||||
int pit_get_timer_0()
|
||||
int64_t pit_get_timer_0()
|
||||
{
|
||||
int read = (int)((pit.c[0] + ((1 << TIMER_SHIFT) - 1)) / PITCONST) >> TIMER_SHIFT;
|
||||
int64_t read = (int64_t)((pit.c[0] + ((1 << TIMER_SHIFT) - 1)) / PITCONST) >> TIMER_SHIFT;
|
||||
if (pit.m[0] == 2)
|
||||
read++;
|
||||
if (read < 0)
|
||||
read = 0;
|
||||
if (read > 0x10000)
|
||||
read = 0x10000;
|
||||
if (pit.m[0] == 3)
|
||||
read <<= 1;
|
||||
if (read < 0LL)
|
||||
read = 0LL;
|
||||
if (read > 0x10000LL)
|
||||
read = 0x10000LL;
|
||||
if (pit.m[0] == 3LL)
|
||||
read <<= 1LL;
|
||||
return read;
|
||||
}
|
||||
|
||||
static int pit_read_timer(PIT *pit, int t)
|
||||
static int64_t pit_read_timer(PIT *pit, int64_t t)
|
||||
{
|
||||
timer_clock();
|
||||
if (pit->using_timer[t])
|
||||
{
|
||||
int read = (int)((pit->c[t] + ((1 << TIMER_SHIFT) - 1)) / PITCONST) >> TIMER_SHIFT;
|
||||
int64_t read = (int64_t)((pit->c[t] + ((1 << TIMER_SHIFT) - 1)) / PITCONST) >> TIMER_SHIFT;
|
||||
if (pit->m[t] == 2)
|
||||
read++;
|
||||
if (read < 0)
|
||||
read = 0;
|
||||
if (read > 0x10000)
|
||||
read = 0x10000;
|
||||
if (pit->m[t] == 3)
|
||||
read <<= 1;
|
||||
if (read < 0LL)
|
||||
read = 0LL;
|
||||
if (read > 0x10000LL)
|
||||
read = 0x10000LL;
|
||||
if (pit->m[t] == 3LL)
|
||||
read <<= 1LL;
|
||||
return read;
|
||||
}
|
||||
if (pit->m[t] == 2)
|
||||
return pit->count[t] + 1;
|
||||
if (pit->m[t] == 2LL)
|
||||
return pit->count[t] + 1LL;
|
||||
return pit->count[t];
|
||||
}
|
||||
|
||||
void pit_write(uint16_t addr, uint8_t val, void *p)
|
||||
{
|
||||
PIT *pit = (PIT *)p;
|
||||
int t;
|
||||
cycles -= (int)PITCONST;
|
||||
int64_t t;
|
||||
cycles -= (int64_t)PITCONST;
|
||||
|
||||
switch (addr&3)
|
||||
{
|
||||
@@ -340,11 +340,11 @@ void pit_write(uint16_t addr, uint8_t val, void *p)
|
||||
if (!(val&0x20))
|
||||
{
|
||||
if (val & 2)
|
||||
pit->rl[0] = pit->using_timer[0] ? ((int)(pit->c[0] / PITCONST) >> TIMER_SHIFT) : pit->count[0];
|
||||
pit->rl[0] = pit->using_timer[0] ? ((int64_t)(pit->c[0] / PITCONST) >> TIMER_SHIFT) : pit->count[0];
|
||||
if (val & 4)
|
||||
pit->rl[1] = pit->using_timer[1] ? ((int)(pit->c[1] / PITCONST) >> TIMER_SHIFT) : pit->count[1];
|
||||
pit->rl[1] = pit->using_timer[1] ? ((int64_t)(pit->c[1] / PITCONST) >> TIMER_SHIFT) : pit->count[1];
|
||||
if (val & 8)
|
||||
pit->rl[2] = pit->using_timer[2] ? ((int)(pit->c[2] / PITCONST) >> TIMER_SHIFT) : pit->count[2];
|
||||
pit->rl[2] = pit->using_timer[2] ? ((int64_t)(pit->c[2] / PITCONST) >> TIMER_SHIFT) : pit->count[2];
|
||||
}
|
||||
if (!(val & 0x10))
|
||||
{
|
||||
@@ -437,9 +437,9 @@ void pit_write(uint16_t addr, uint8_t val, void *p)
|
||||
uint8_t pit_read(uint16_t addr, void *p)
|
||||
{
|
||||
PIT *pit = (PIT *)p;
|
||||
int t;
|
||||
int64_t t;
|
||||
uint8_t temp = 0xff;
|
||||
cycles -= (int)PITCONST;
|
||||
cycles -= (int64_t)PITCONST;
|
||||
switch (addr&3)
|
||||
{
|
||||
case 0: case 1: case 2: /*Timers*/
|
||||
@@ -493,12 +493,12 @@ void pit_timer_over(void *p)
|
||||
{
|
||||
PIT_nr *pit_nr = (PIT_nr *)p;
|
||||
PIT *pit = pit_nr->pit;
|
||||
int timer = pit_nr->nr;
|
||||
int64_t timer = pit_nr->nr;
|
||||
|
||||
pit_over(pit, timer);
|
||||
}
|
||||
|
||||
void pit_clock(PIT *pit, int t)
|
||||
void pit_clock(PIT *pit, int64_t t)
|
||||
{
|
||||
if (pit->thit[t] || !pit->enabled[t])
|
||||
return;
|
||||
@@ -511,28 +511,28 @@ void pit_clock(PIT *pit, int t)
|
||||
pit_over(pit, t);
|
||||
}
|
||||
|
||||
void pit_set_using_timer(PIT *pit, int t, int using_timer)
|
||||
void pit_set_using_timer(PIT *pit, int64_t t, int64_t using_timer)
|
||||
{
|
||||
timer_process();
|
||||
if (pit->using_timer[t] && !using_timer)
|
||||
pit->count[t] = pit_read_timer(pit, t);
|
||||
if (!pit->using_timer[t] && using_timer)
|
||||
pit->c[t] = (int)((pit->count[t] << TIMER_SHIFT) * PITCONST);
|
||||
pit->c[t] = (int64_t)((pit->count[t] << TIMER_SHIFT) * PITCONST);
|
||||
pit->using_timer[t] = using_timer;
|
||||
pit->running[t] = pit->enabled[t] && pit->using_timer[t] && !pit->disabled[t];
|
||||
timer_update_outstanding();
|
||||
}
|
||||
|
||||
void pit_set_out_func(PIT *pit, int t, void (*func)(int new_out, int old_out))
|
||||
void pit_set_out_func(PIT *pit, int64_t t, void (*func)(int64_t new_out, int64_t old_out))
|
||||
{
|
||||
pit->set_out_funcs[t] = func;
|
||||
}
|
||||
|
||||
void pit_null_timer(int new_out, int old_out)
|
||||
void pit_null_timer(int64_t new_out, int64_t old_out)
|
||||
{
|
||||
}
|
||||
|
||||
void pit_irq0_timer(int new_out, int old_out)
|
||||
void pit_irq0_timer(int64_t new_out, int64_t old_out)
|
||||
{
|
||||
if (new_out && !old_out)
|
||||
picint(1);
|
||||
@@ -540,7 +540,7 @@ void pit_irq0_timer(int new_out, int old_out)
|
||||
picintc(1);
|
||||
}
|
||||
|
||||
void pit_irq0_timer_pcjr(int new_out, int old_out)
|
||||
void pit_irq0_timer_pcjr(int64_t new_out, int64_t old_out)
|
||||
{
|
||||
if (new_out && !old_out)
|
||||
{
|
||||
@@ -551,7 +551,7 @@ void pit_irq0_timer_pcjr(int new_out, int old_out)
|
||||
picintc(1);
|
||||
}
|
||||
|
||||
void pit_irq0_ps2(int new_out, int old_out)
|
||||
void pit_irq0_ps2(int64_t new_out, int64_t old_out)
|
||||
{
|
||||
if (new_out && !old_out)
|
||||
{
|
||||
@@ -564,21 +564,21 @@ void pit_irq0_ps2(int new_out, int old_out)
|
||||
pit_clock(&pit2, 0);
|
||||
}
|
||||
|
||||
void pit_refresh_timer_xt(int new_out, int old_out)
|
||||
void pit_refresh_timer_xt(int64_t new_out, int64_t old_out)
|
||||
{
|
||||
if (new_out && !old_out)
|
||||
dma_channel_read(0);
|
||||
}
|
||||
|
||||
void pit_refresh_timer_at(int new_out, int old_out)
|
||||
void pit_refresh_timer_at(int64_t new_out, int64_t old_out)
|
||||
{
|
||||
if (new_out && !old_out)
|
||||
ppi.pb ^= 0x10;
|
||||
}
|
||||
|
||||
void pit_speaker_timer(int new_out, int old_out)
|
||||
void pit_speaker_timer(int64_t new_out, int64_t old_out)
|
||||
{
|
||||
int l;
|
||||
int64_t l;
|
||||
|
||||
speaker_update();
|
||||
|
||||
@@ -591,7 +591,7 @@ void pit_speaker_timer(int new_out, int old_out)
|
||||
}
|
||||
|
||||
|
||||
void pit_nmi_ps2(int new_out, int old_out)
|
||||
void pit_nmi_ps2(int64_t new_out, int64_t old_out)
|
||||
{
|
||||
nmi = new_out;
|
||||
if (nmi)
|
||||
|
||||
Reference in New Issue
Block a user