Reverted the PIT and Soyo 4SA2 changes.

This commit is contained in:
OBattler
2021-07-09 04:46:08 +02:00
parent 99b9174e02
commit 9cba2a91dc
4 changed files with 152 additions and 362 deletions

View File

@@ -642,6 +642,7 @@ acpi_reg_write_common_regs(int size, uint16_t addr, uint8_t val, void *p)
break; break;
case 0x04: case 0x05: case 0x04: case 0x05:
/* PMCNTRL - Power Management Control Register (IO) */ /* PMCNTRL - Power Management Control Register (IO) */
pclog("addr = %02X, val = %02X\n", addr, val);
if ((addr == 0x05) && (val & 0x20)) { if ((addr == 0x05) && (val & 0x20)) {
sus_typ = (val >> 2) & 7; sus_typ = (val >> 2) & 7;
switch (sus_typ) { switch (sus_typ) {

View File

@@ -18,34 +18,33 @@
# define EMU_PIT_H # define EMU_PIT_H
typedef struct ctr_s { typedef struct {
uint8_t m, ctrl, uint8_t m, ctrl,
read_status, latch, read_status, latch,
s1_det, l_det, s1_det, l_det,
bcd, flag_64k; bcd, pad;
uint16_t l, rl; uint16_t rl;
union {
uint16_t count;
struct {
uint16_t units :4;
uint16_t tens :4;
uint16_t hundreds :4;
uint16_t thousands :4;
uint16_t myriads :4;
};
};
int rm, wm, gate, out, int rm, wm, gate, out,
newcount, clock, using_timer, latched, newcount, clock, using_timer, latched,
state, null_count, do_read_status, do_load; state, null_count, do_read_status;
union {
int count;
struct {
int units :4;
int tens :4;
int hundreds :4;
int thousands :4;
int myriads :4;
};
};
uint32_t l;
void (*tick_func)(struct ctr_s *ctr);
void (*load_func)(uint8_t new_m, int new_count); void (*load_func)(uint8_t new_m, int new_count);
void (*out_func)(int new_out, int old_out); void (*out_func)(int new_out, int old_out);
struct PIT *pit;
} ctr_t; } ctr_t;

View File

@@ -990,13 +990,10 @@ machine_at_4sa2_init(const machine_t *model)
pci_register_slot(0x0F, PCI_CARD_NORMAL, 3, 4, 1, 2); pci_register_slot(0x0F, PCI_CARD_NORMAL, 3, 4, 1, 2);
pci_register_slot(0x11, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x11, PCI_CARD_NORMAL, 4, 1, 2, 3);
// device_add(&w83787f_device); device_add(&w83787f_device);
device_add(&prime3b_device); device_add(&keyboard_ps2_pci_device);
// device_add(&keyboard_ps2_pci_device);
device_add(&keyboard_ps2_ami_pci_device);
// device_add(&intel_flash_bxt_device); device_add(&intel_flash_bxt_device);
device_add(&sst_flash_29ee010_device);
return ret; return ret;
} }

439
src/pit.c
View File

@@ -64,7 +64,6 @@ int64_t firsttime = 1;
#define PIT_EXT_IO 32 /* The PIT has externally specified port I/O. */ #define PIT_EXT_IO 32 /* The PIT has externally specified port I/O. */
#define PIT_CUSTOM_CLOCK 64 /* The PIT uses custom clock inputs provided by another provider. */ #define PIT_CUSTOM_CLOCK 64 /* The PIT uses custom clock inputs provided by another provider. */
#define PIT_SECONDARY 128 /* The PIT is secondary (ports 0048-004B). */ #define PIT_SECONDARY 128 /* The PIT is secondary (ports 0048-004B). */
#define PIT_OLIVETTI 256 /* The PIT is that of the Olivetti 486 (has slight timing differences). */
enum { enum {
@@ -93,214 +92,67 @@ pit_log(const char *fmt, ...)
#endif #endif
#define NEW_PIT_CODE 1
#ifdef NEW_PIT_CODE
typedef void (*tf_t)(ctr_t *ctr);
static void ctr_tick_mode_0(ctr_t *ctr);
static void ctr_tick_mode_1(ctr_t *ctr);
static void ctr_tick_mode_2_and_6(ctr_t *ctr);
static void ctr_tick_mode_3_and_7(ctr_t *ctr);
static void ctr_tick_mode_4_and_5(ctr_t *ctr);
static tf_t ctr_tick_funcs[8] = { ctr_tick_mode_0, ctr_tick_mode_1, ctr_tick_mode_2_and_6,
ctr_tick_mode_3_and_7, ctr_tick_mode_4_and_5, ctr_tick_mode_4_and_5,
ctr_tick_mode_2_and_6, ctr_tick_mode_3_and_7 };
/* MODE 0: Interrupt on Terminal Count. */
static void static void
ctr_tick_mode_0(ctr_t *ctr) ctr_set_out(ctr_t *ctr, int out)
{ {
uint8_t state = ctr->state; if (ctr == NULL)
return;
switch (state) {
case 1:
/* Load count. */
ctr->count = ctr->l;
ctr->null_count = 0;
/* Switch to next state. */
ctr->state++;
case 2: case 3:
if (ctr->gate) {
/* Decrease counter. */
if ((state == 3) || ctr->gate)
ctr->count--;
if ((state == 2) && ctr->gate && (ctr->count == 0)) {
/* Terminal count reached, switch to next state. */
ctr->state++;
/* Set output high. */
if (ctr->out_func != NULL) if (ctr->out_func != NULL)
ctr->out_func(1, ctr->out); ctr->out_func(out, ctr->out);
ctr->out = 1; ctr->out = out;
}
}
break;
}
}
/* MODE 1: Programmale One-Shoft. */
static void
ctr_tick_mode_1(ctr_t *ctr)
{
uint8_t state = ctr->state;
switch (state) {
case 1:
/* Load count. */
ctr->count = ctr->l;
ctr->null_count = 0;
/* Switch to next state. */
ctr->state++;
/* Set output low. */
if (ctr->out_func != NULL)
ctr->out_func(0, ctr->out);
ctr->out = 0;
break;
case 2: case 3:
/* Decrease counter. */
ctr->count--;
if ((state == 2) && (ctr->count == 0)) {
/* Terminal count reached, switch to next state. */
ctr->state++;
/* Set output high. */
if (ctr->out_func != NULL)
ctr->out_func(1, ctr->out);
ctr->out = 1;
}
break;
}
} }
static void static void
ctr_tick_mode_2_and_6(ctr_t *ctr) ctr_decrease_count(ctr_t *ctr)
{ {
uint8_t state = ctr->state; if (ctr->bcd) {
ctr->units--;
switch (state) { if (ctr->units == 0xff) {
case 1: case 3: ctr->units = 9;
/* Load count. */ ctr->tens--;
ctr->count = ctr->l; if (ctr->tens == 0xff) {
ctr->null_count = 0; ctr->tens = 9;
if (ctr->state == 3) { ctr->hundreds--;
/* Set output high. */ if (ctr->hundreds == 0xff) {
if (ctr->out_func != NULL) ctr->hundreds = 9;
ctr->out_func(1, ctr->out); ctr->thousands--;
ctr->out = 1; if (ctr->thousands == 0xff) {
} ctr->thousands = 9;
/* Switch to next state. */ ctr->myriads--;
ctr->state = 2; if (ctr->myriads == 0xff)
break; ctr->myriads = 0; /* 0 - 1 should wrap around to 9999. */
case 2:
/* Decrease counter. */
if (ctr->gate) {
ctr->count--;
if (ctr->count == 1) {
/* Terminal count reached, switch to previous state. */
ctr->state = 3;
/* Set output low. */
if (ctr->out_func != NULL)
ctr->out_func(0, ctr->out);
ctr->out = 0;
} }
} }
break;
} }
} }
} else
ctr->count = (ctr->count - 1) & 0xffff;
}
static void static void
ctr_tick_mode_3_and_7(ctr_t *ctr) ctr_load_count(ctr_t *ctr)
{ {
uint8_t state = ctr->state; int l = ctr->l ? ctr->l : 0x10000;
uint16_t old_count = ctr->count;
switch (state) { ctr->count = l;
case 1: pit_log("ctr->count = %i\n", l);
/* Load count. */
ctr->count = ctr->l;
ctr->flag_64k = !ctr->count;
ctr->null_count = 0; ctr->null_count = 0;
ctr->newcount = ctr->count & 1; ctr->newcount = !!(l & 1);
/* Switch to next state. */
ctr->state = 2;
case 2: case 3:
if (ctr->gate) {
ctr->count -= (ctr->newcount ? ((ctr->state == 3) ? 3 : 1) : 2);
if (!ctr->flag_64k && (ctr->count > old_count)) {
/* Load count. */
ctr->count = ctr->l;
ctr->flag_64k = !ctr->count;
ctr->null_count = 0;
ctr->newcount = ctr->count & 1;
/* Switch to next state. */
ctr->state ^= 1;
/* Set output low. */
if (ctr->out_func != NULL)
ctr->out_func(state & 1, ctr->out);
ctr->out = state & 1;
} else {
if (ctr->newcount)
ctr->newcount = 0;
ctr->flag_64k = 0;
}
}
break;
}
} }
static void
ctr_tick_mode_4_and_5(ctr_t *ctr)
{
uint8_t state = ctr->state;
/* Software triggered strobe */
/* Hardware triggered strobe */
if (ctr->gate || (ctr->m != 4)) {
switch(state) {
case 0: case 2:
ctr->count--;
if ((state == 2) && (ctr->count < 1)) {
ctr->state++;
if (ctr->out_func != NULL)
ctr->out_func(0, ctr->out);
ctr->out = 0;
}
break;
case 3:
ctr->state = 0;
if (ctr->out_func != NULL)
ctr->out_func(1, ctr->out);
ctr->out = 1;
break;
}
}
}
#else
static void static void
ctr_tick(ctr_t *ctr) ctr_tick(ctr_t *ctr)
{ {
uint8_t state = ctr->state; uint8_t state = ctr->state;
uint16_t old_count = ctr->count;
if (state == 1) { if (state == 1) {
/* This is true for all modes */ /* This is true for all modes */
ctr->count = ctr->l; ctr_load_count(ctr);
ctr->null_count = 0; ctr->state = 2;
ctr->newcount = !!(ctr->count & 1);
ctr->state++;
if ((ctr->m & 0x07) == 1) {
if (ctr->out_func != NULL)
ctr->out_func(0, ctr->out);
ctr->out = 0;
}
return; return;
} }
@@ -309,35 +161,38 @@ ctr_tick(ctr_t *ctr)
/* Interrupt on terminal count */ /* Interrupt on terminal count */
switch (state) { switch (state) {
case 2: case 2:
if (ctr->gate) { if (ctr->gate && (ctr->count >= 1)) {
ctr->count--; ctr_decrease_count(ctr);
if (ctr->count < 1) { if (ctr->count < 1) {
ctr->state++; ctr->state = 3;
if (ctr->out_func != NULL) ctr_set_out(ctr, 1);
ctr->out_func(1, ctr->out);
ctr->out = 1;
} }
} }
break; break;
case 3: case 3:
ctr->count--; ctr_decrease_count(ctr);
break; break;
} }
break; break;
case 1: case 1:
/* Hardware retriggerable one-shot */ /* Hardware retriggerable one-shot */
switch (state) { switch (state) {
case 1:
ctr_load_count(ctr);
ctr->state = 2;
ctr_set_out(ctr, 0);
break;
case 2: case 2:
ctr->count--; if (ctr->count >= 1) {
ctr_decrease_count(ctr);
if (ctr->count < 1) { if (ctr->count < 1) {
ctr->state++; ctr->state = 3;
if (ctr->out_func != NULL) ctr_set_out(ctr, 1);
ctr->out_func(1, ctr->out); }
ctr->out = 1;
} }
break; break;
case 3: case 3:
ctr->count--; ctr_decrease_count(ctr);
break; break;
} }
break; break;
@@ -345,40 +200,59 @@ ctr_tick(ctr_t *ctr)
/* Rate generator */ /* Rate generator */
switch (state) { switch (state) {
case 3: case 3:
ctr->count = ctr->l; ctr_load_count(ctr);
ctr->null_count = 0; ctr->state = 2;
ctr->state ^= 1; ctr_set_out(ctr, 1);
if (ctr->out_func != NULL)
ctr->out_func(1, ctr->out);
ctr->out = 1;
break; break;
case 2: case 2:
// if (ctr->gate) { if (ctr->gate == 0)
ctr->count--; break;
else if (ctr->count >= 2) {
ctr_decrease_count(ctr);
if (ctr->count < 2) { if (ctr->count < 2) {
ctr->state ^= 1; ctr->state = 3;
if (ctr->out_func != NULL) ctr_set_out(ctr, 0);
ctr->out_func(0, ctr->out); }
ctr->out = 0;
} }
// }
break; break;
} }
break; break;
case 3: case 7: case 3: case 7:
/* Square wave mode */ /* Square wave mode */
switch (state) { switch (state) {
case 2: case 3: case 2:
if (ctr->gate != 0) { if (ctr->gate == 0)
ctr->count -= (ctr->newcount ? ((state & 1) ? 3 : 1) : 2); break;
if (ctr->count > old_count) { else if (ctr->count >= 0) {
ctr->count = ctr->l; if (ctr->bcd) {
ctr->null_count = 0; ctr_decrease_count(ctr);
ctr->newcount = !!(ctr->count & 1); if (!ctr->newcount)
ctr->state ^= 1; ctr_decrease_count(ctr);
if (ctr->out_func != NULL) } else
ctr->out_func(0, ctr->out); ctr->count -= (ctr->newcount ? 1 : 2);
ctr->out = 0; if (ctr->count < 0) {
ctr_load_count(ctr);
ctr->state = 3;
ctr_set_out(ctr, 0);
} else if (ctr->newcount)
ctr->newcount = 0;
}
break;
case 3:
if (ctr->gate == 0)
break;
else if (ctr->count >= 0) {
if (ctr->bcd) {
ctr_decrease_count(ctr);
ctr_decrease_count(ctr);
if (ctr->newcount)
ctr_decrease_count(ctr);
} else
ctr->count -= (ctr->newcount ? 3 : 2);
if (ctr->count < 0) {
ctr_load_count(ctr);
ctr->state = 2;
ctr_set_out(ctr, 1);
} else if (ctr->newcount) } else if (ctr->newcount)
ctr->newcount = 0; ctr->newcount = 0;
} }
@@ -390,20 +264,21 @@ ctr_tick(ctr_t *ctr)
/* Hardware triggered strobe */ /* Hardware triggered strobe */
if ((ctr->gate != 0) || (ctr->m != 4)) { if ((ctr->gate != 0) || (ctr->m != 4)) {
switch(state) { switch(state) {
case 0: case 2: case 0:
ctr->count--; ctr_decrease_count(ctr);
if ((state == 2) && (ctr->count < 1)) { break;
ctr->state++; case 2:
if (ctr->out_func != NULL) if (ctr->count >= 1) {
ctr->out_func(0, ctr->out); ctr_decrease_count(ctr);
ctr->out = 0; if (ctr->count < 1) {
ctr->state = 3;
ctr_set_out(ctr, 0);
}
} }
break; break;
case 3: case 3:
ctr->state = 0; ctr->state = 0;
if (ctr->out_func != NULL) ctr_set_out(ctr, 1);
ctr->out_func(1, ctr->out);
ctr->out = 1;
break; break;
} }
} }
@@ -412,7 +287,6 @@ ctr_tick(ctr_t *ctr)
break; break;
} }
} }
#endif
static void static void
@@ -425,11 +299,7 @@ ctr_clock(ctr_t *ctr)
if (ctr->using_timer) if (ctr->using_timer)
return; return;
#ifdef NEW_PIT_CODE
ctr->tick_func(ctr);
#else
ctr_tick(ctr); ctr_tick(ctr);
#endif
} }
@@ -480,11 +350,6 @@ ctr_latch_count(ctr_t *ctr)
{ {
int count = (ctr->latch || (ctr->state == 1)) ? ctr->l : ctr->count; int count = (ctr->latch || (ctr->state == 1)) ? ctr->l : ctr->count;
// if ((ctr->pit->flags & PIT_OLIVETTI) && (ctr->state == 0))
// count--;
pit_log("PIT latch count with state %i (%i)\n", ctr->state, ctr->latch);
switch (ctr->rm & 0x03) { switch (ctr->rm & 0x03) {
case 0x00: case 0x00:
/* This should never happen. */ /* This should never happen. */
@@ -550,21 +415,15 @@ pit_ctr_set_gate(ctr_t *ctr, int gate)
if (!old && gate) { if (!old && gate) {
/* Here we handle the rising edges. */ /* Here we handle the rising edges. */
if (mode & 1) { if (mode & 1) {
if (mode != 1) { if (mode != 1)
if (ctr->out_func != NULL) ctr_set_out(ctr, 1);
ctr->out_func(1, ctr->out);
ctr->out = 1;
}
ctr->state = 1; ctr->state = 1;
} else if (mode == 2) } else if (mode == 2)
ctr->state = 3; ctr->state = 3;
} else if (old && !gate) { } else if (old && !gate) {
/* Here we handle the lowering edges. */ /* Here we handle the lowering edges. */
if (mode & 2) { if (mode & 2)
if (ctr->out_func != NULL) ctr_set_out(ctr, 1);
ctr->out_func(1, ctr->out);
ctr->out = 1;
}
} }
break; break;
} }
@@ -578,27 +437,12 @@ pit_ctr_set_clock_common(ctr_t *ctr, int clock)
ctr->clock = clock; ctr->clock = clock;
if (!ctr->using_timer) if (ctr->using_timer && ctr->latch) {
return;
#if 0
if ((ctr->pit->flags & PIT_OLIVETTI) && !old && ctr->clock) {
if (ctr->do_load) {
if (ctr->do_load == 3)
ctr_load(ctr);
ctr->do_load++;
if (ctr->do_load == 4)
ctr->do_load = 0;
}
}
#endif
if (ctr->latch) {
if (old && !ctr->clock) { if (old && !ctr->clock) {
ctr_set_state_1(ctr); ctr_set_state_1(ctr);
ctr->latch = 0; ctr->latch = 0;
} }
} else if (!ctr->latch) { } else if (ctr->using_timer && !ctr->latch) {
if (ctr->state == 1) { if (ctr->state == 1) {
if (!old && ctr->clock) if (!old && ctr->clock)
ctr->s1_det = 1; /* Rising edge. */ ctr->s1_det = 1; /* Rising edge. */
@@ -606,19 +450,11 @@ pit_ctr_set_clock_common(ctr_t *ctr, int clock)
ctr->s1_det++; /* Falling edge. */ ctr->s1_det++; /* Falling edge. */
if (ctr->s1_det >= 2) { if (ctr->s1_det >= 2) {
ctr->s1_det = 0; ctr->s1_det = 0;
#ifdef NEW_PIT_CODE
ctr->tick_func(ctr);
#else
ctr_tick(ctr); ctr_tick(ctr);
#endif
} }
} }
} else if (old && !ctr->clock) } else if (old && !ctr->clock)
#ifdef NEW_PIT_CODE
ctr->tick_func(ctr);
#else
ctr_tick(ctr); ctr_tick(ctr);
#endif
} }
} }
@@ -702,14 +538,9 @@ pit_write(uint16_t addr, uint8_t val, void *priv)
ctr->m = (val >> 1) & 7; ctr->m = (val >> 1) & 7;
if (ctr->m > 5) if (ctr->m > 5)
ctr->m &= 3; ctr->m &= 3;
#ifdef NEW_PIT_CODE
ctr->tick_func = ctr_tick_funcs[ctr->m];
#endif
ctr->null_count = 1; ctr->null_count = 1;
ctr->bcd = (ctr->ctrl & 0x01); ctr->bcd = (ctr->ctrl & 0x01);
if (ctr->out_func != NULL) ctr_set_out(ctr, !!ctr->m);
ctr->out_func(!!ctr->m, ctr->out);
ctr->out = !!ctr->m;
ctr->state = 0; ctr->state = 0;
if (ctr->latched) { if (ctr->latched) {
pit_log("PIT %i: Reload while counter is latched\n", t); pit_log("PIT %i: Reload while counter is latched\n", t);
@@ -732,44 +563,27 @@ pit_write(uint16_t addr, uint8_t val, void *priv)
break; break;
case 1: case 1:
ctr->l = val; ctr->l = val;
if (ctr->m == 0) { if (ctr->m == 0)
if (ctr->out_func != NULL) ctr_set_out(ctr, 0);
ctr->out_func(0, ctr->out);
ctr->out = 0;
}
if (dev->flags & PIT_OLIVETTI)
ctr->do_load = 1;
else
ctr_load(ctr); ctr_load(ctr);
break; break;
case 2: case 2:
ctr->l = (val << 8); ctr->l = (val << 8);
if (ctr->m == 0) { if (ctr->m == 0)
if (ctr->out_func != NULL) ctr_set_out(ctr, 0);
ctr->out_func(0, ctr->out);
ctr->out = 0;
}
if (dev->flags & PIT_OLIVETTI)
ctr->do_load = 1;
else
ctr_load(ctr); ctr_load(ctr);
break; break;
case 3: case 0x83: case 3: case 0x83:
if (ctr->wm & 0x80) { if (ctr->wm & 0x80) {
ctr->l = (ctr->l & 0x00ff) | (val << 8); ctr->l = (ctr->l & 0x00ff) | (val << 8);
pit_log("PIT %i: Written high byte %02X, latch now %04X\n", t, val, ctr->l); pit_log("PIT %i: Written high byte %02X, latch now %04X\n", t, val, ctr->l);
if (dev->flags & PIT_OLIVETTI)
ctr->do_load = 1;
else
ctr_load(ctr); ctr_load(ctr);
} else { } else {
ctr->l = (ctr->l & 0xff00) | val; ctr->l = (ctr->l & 0xff00) | val;
pit_log("PIT %i: Written low byte %02X, latch now %04X\n", t, val, ctr->l); pit_log("PIT %i: Written low byte %02X, latch now %04X\n", t, val, ctr->l);
if (ctr->m == 0) { if (ctr->m == 0) {
ctr->state = 0; ctr->state = 0;
if (ctr->out_func != NULL) ctr_set_out(ctr, 0);
ctr->out_func(0, ctr->out);
ctr->out = 0;
} }
} }
@@ -943,7 +757,7 @@ pit_nmi_timer_ps2(int new_out, int old_out)
static void static void
ctr_reset(pit_t *dev, ctr_t *ctr) ctr_reset(ctr_t *ctr)
{ {
ctr->ctrl = 0; ctr->ctrl = 0;
ctr->m = 0; ctr->m = 0;
@@ -957,8 +771,6 @@ ctr_reset(pit_t *dev, ctr_t *ctr)
ctr->s1_det = 0; ctr->s1_det = 0;
ctr->l_det = 0; ctr->l_det = 0;
ctr->pit = dev;
} }
@@ -972,15 +784,10 @@ pit_reset(pit_t *dev)
dev->clock = 0; dev->clock = 0;
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
ctr_reset(dev, &dev->counters[i]); ctr_reset(&dev->counters[i]);
/* Disable speaker gate. */ /* Disable speaker gate. */
dev->counters[2].gate = 0; dev->counters[2].gate = 0;
#ifdef NEW_PIT_CODE
dev->counters[0].tick_func = dev->counters[1].tick_func =
dev->counters[2].tick_func = ctr_tick_funcs[0];
#endif
} }
@@ -1051,17 +858,6 @@ const device_t i8254_device =
}; };
const device_t i8254_olivetti_device =
{
"Intel 8254 Programmable Interval Timer (Olivetti)",
DEVICE_ISA,
PIT_8254 | PIT_OLIVETTI,
pit_init, pit_close, NULL,
{ NULL }, NULL, NULL,
NULL
};
const device_t i8254_sec_device = const device_t i8254_sec_device =
{ {
"Intel 8254 Programmable Interval Timer (Secondary)", "Intel 8254 Programmable Interval Timer (Secondary)",
@@ -1108,9 +904,6 @@ pit_common_init(int type, void (*out0)(int new_out, int old_out), void (*out1)(i
case PIT_8254: case PIT_8254:
pit = device_add(&i8254_device); pit = device_add(&i8254_device);
break; break;
case (PIT_8254 | PIT_OLIVETTI):
pit = device_add(&i8254_olivetti_device);
break;
} }
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {