diff --git a/src/acpi.c b/src/acpi.c index d8e6a12aa..d83b087bc 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -642,6 +642,7 @@ acpi_reg_write_common_regs(int size, uint16_t addr, uint8_t val, void *p) break; case 0x04: case 0x05: /* PMCNTRL - Power Management Control Register (IO) */ + pclog("addr = %02X, val = %02X\n", addr, val); if ((addr == 0x05) && (val & 0x20)) { sus_typ = (val >> 2) & 7; switch (sus_typ) { diff --git a/src/include/86box/pit.h b/src/include/86box/pit.h index 93f6c594e..bf8d71048 100644 --- a/src/include/86box/pit.h +++ b/src/include/86box/pit.h @@ -18,34 +18,33 @@ # define EMU_PIT_H -typedef struct ctr_s { +typedef struct { uint8_t m, ctrl, read_status, latch, s1_det, l_det, - bcd, flag_64k; + bcd, pad; - uint16_t l, 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; - }; - }; + uint16_t rl; int rm, wm, gate, out, 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 (*out_func)(int new_out, int old_out); - - struct PIT *pit; } ctr_t; diff --git a/src/machine/m_at_386dx_486.c b/src/machine/m_at_386dx_486.c index eb6efeb96..93d5d9499 100644 --- a/src/machine/m_at_386dx_486.c +++ b/src/machine/m_at_386dx_486.c @@ -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(0x11, PCI_CARD_NORMAL, 4, 1, 2, 3); - // device_add(&w83787f_device); - device_add(&prime3b_device); - // device_add(&keyboard_ps2_pci_device); - device_add(&keyboard_ps2_ami_pci_device); + device_add(&w83787f_device); + device_add(&keyboard_ps2_pci_device); - // device_add(&intel_flash_bxt_device); - device_add(&sst_flash_29ee010_device); + device_add(&intel_flash_bxt_device); return ret; } diff --git a/src/pit.c b/src/pit.c index fc1e91927..9db4c45dd 100644 --- a/src/pit.c +++ b/src/pit.c @@ -64,7 +64,6 @@ int64_t firsttime = 1; #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_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 { @@ -93,214 +92,67 @@ pit_log(const char *fmt, ...) #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 -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) - ctr->out_func(1, ctr->out); - ctr->out = 1; - } - } - 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; - } + if (ctr->out_func != NULL) + ctr->out_func(out, ctr->out); + ctr->out = out; } static void -ctr_tick_mode_2_and_6(ctr_t *ctr) +ctr_decrease_count(ctr_t *ctr) { - uint8_t state = ctr->state; - - switch (state) { - case 1: case 3: - /* Load count. */ - ctr->count = ctr->l; - ctr->null_count = 0; - if (ctr->state == 3) { - /* Set output high. */ - if (ctr->out_func != NULL) - ctr->out_func(1, ctr->out); - ctr->out = 1; - } - /* Switch to next state. */ - ctr->state = 2; - break; - 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; + if (ctr->bcd) { + ctr->units--; + if (ctr->units == 0xff) { + ctr->units = 9; + ctr->tens--; + if (ctr->tens == 0xff) { + ctr->tens = 9; + ctr->hundreds--; + if (ctr->hundreds == 0xff) { + ctr->hundreds = 9; + ctr->thousands--; + if (ctr->thousands == 0xff) { + ctr->thousands = 9; + ctr->myriads--; + if (ctr->myriads == 0xff) + ctr->myriads = 0; /* 0 - 1 should wrap around to 9999. */ + } } } - break; - } -} - - -static void -ctr_tick_mode_3_and_7(ctr_t *ctr) -{ - uint8_t state = ctr->state; - uint16_t old_count = ctr->count; - - switch (state) { - case 1: - /* 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 = 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 + ctr->count = (ctr->count - 1) & 0xffff; } -#else + + +static void +ctr_load_count(ctr_t *ctr) +{ + int l = ctr->l ? ctr->l : 0x10000; + + ctr->count = l; + pit_log("ctr->count = %i\n", l); + ctr->null_count = 0; + ctr->newcount = !!(l & 1); +} + + static void ctr_tick(ctr_t *ctr) { uint8_t state = ctr->state; - uint16_t old_count = ctr->count; if (state == 1) { /* This is true for all modes */ - ctr->count = ctr->l; - ctr->null_count = 0; - 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; - } + ctr_load_count(ctr); + ctr->state = 2; return; } @@ -309,35 +161,38 @@ ctr_tick(ctr_t *ctr) /* Interrupt on terminal count */ switch (state) { case 2: - if (ctr->gate) { - ctr->count--; + if (ctr->gate && (ctr->count >= 1)) { + ctr_decrease_count(ctr); if (ctr->count < 1) { - ctr->state++; - if (ctr->out_func != NULL) - ctr->out_func(1, ctr->out); - ctr->out = 1; + ctr->state = 3; + ctr_set_out(ctr, 1); } } break; case 3: - ctr->count--; + ctr_decrease_count(ctr); break; } break; case 1: /* Hardware retriggerable one-shot */ switch (state) { + case 1: + ctr_load_count(ctr); + ctr->state = 2; + ctr_set_out(ctr, 0); + break; case 2: - ctr->count--; - if (ctr->count < 1) { - ctr->state++; - if (ctr->out_func != NULL) - ctr->out_func(1, ctr->out); - ctr->out = 1; + if (ctr->count >= 1) { + ctr_decrease_count(ctr); + if (ctr->count < 1) { + ctr->state = 3; + ctr_set_out(ctr, 1); + } } break; case 3: - ctr->count--; + ctr_decrease_count(ctr); break; } break; @@ -345,40 +200,59 @@ ctr_tick(ctr_t *ctr) /* Rate generator */ switch (state) { case 3: - ctr->count = ctr->l; - ctr->null_count = 0; - ctr->state ^= 1; - if (ctr->out_func != NULL) - ctr->out_func(1, ctr->out); - ctr->out = 1; + ctr_load_count(ctr); + ctr->state = 2; + ctr_set_out(ctr, 1); break; case 2: - // if (ctr->gate) { - ctr->count--; + if (ctr->gate == 0) + break; + else if (ctr->count >= 2) { + ctr_decrease_count(ctr); if (ctr->count < 2) { - ctr->state ^= 1; - if (ctr->out_func != NULL) - ctr->out_func(0, ctr->out); - ctr->out = 0; + ctr->state = 3; + ctr_set_out(ctr, 0); } - // } + } break; } break; case 3: case 7: /* Square wave mode */ switch (state) { - case 2: case 3: - if (ctr->gate != 0) { - ctr->count -= (ctr->newcount ? ((state & 1) ? 3 : 1) : 2); - if (ctr->count > old_count) { - ctr->count = ctr->l; - ctr->null_count = 0; - ctr->newcount = !!(ctr->count & 1); - ctr->state ^= 1; - if (ctr->out_func != NULL) - ctr->out_func(0, ctr->out); - ctr->out = 0; + case 2: + if (ctr->gate == 0) + break; + else if (ctr->count >= 0) { + if (ctr->bcd) { + ctr_decrease_count(ctr); + if (!ctr->newcount) + ctr_decrease_count(ctr); + } else + ctr->count -= (ctr->newcount ? 1 : 2); + 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) ctr->newcount = 0; } @@ -390,20 +264,21 @@ ctr_tick(ctr_t *ctr) /* Hardware triggered strobe */ if ((ctr->gate != 0) || (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; + case 0: + ctr_decrease_count(ctr); + break; + case 2: + if (ctr->count >= 1) { + ctr_decrease_count(ctr); + if (ctr->count < 1) { + ctr->state = 3; + ctr_set_out(ctr, 0); + } } break; case 3: ctr->state = 0; - if (ctr->out_func != NULL) - ctr->out_func(1, ctr->out); - ctr->out = 1; + ctr_set_out(ctr, 1); break; } } @@ -412,24 +287,19 @@ ctr_tick(ctr_t *ctr) break; } } -#endif static void ctr_clock(ctr_t *ctr) { - /* FIXME: Is this even needed? */ + /* FIXME: Is this even needed? */ if ((ctr->state == 3) && (ctr->m != 2) && (ctr->m != 3)) return; if (ctr->using_timer) return; -#ifdef NEW_PIT_CODE - ctr->tick_func(ctr); -#else 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; - // 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) { case 0x00: /* This should never happen. */ @@ -550,21 +415,15 @@ pit_ctr_set_gate(ctr_t *ctr, int gate) if (!old && gate) { /* Here we handle the rising edges. */ if (mode & 1) { - if (mode != 1) { - if (ctr->out_func != NULL) - ctr->out_func(1, ctr->out); - ctr->out = 1; - } + if (mode != 1) + ctr_set_out(ctr, 1); ctr->state = 1; } else if (mode == 2) ctr->state = 3; } else if (old && !gate) { /* Here we handle the lowering edges. */ - if (mode & 2) { - if (ctr->out_func != NULL) - ctr->out_func(1, ctr->out); - ctr->out = 1; - } + if (mode & 2) + ctr_set_out(ctr, 1); } break; } @@ -578,27 +437,12 @@ pit_ctr_set_clock_common(ctr_t *ctr, int clock) ctr->clock = clock; - if (!ctr->using_timer) - 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 (ctr->using_timer && ctr->latch) { if (old && !ctr->clock) { ctr_set_state_1(ctr); ctr->latch = 0; } - } else if (!ctr->latch) { + } else if (ctr->using_timer && !ctr->latch) { if (ctr->state == 1) { if (!old && ctr->clock) 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. */ if (ctr->s1_det >= 2) { ctr->s1_det = 0; -#ifdef NEW_PIT_CODE - ctr->tick_func(ctr); -#else ctr_tick(ctr); -#endif } } } else if (old && !ctr->clock) -#ifdef NEW_PIT_CODE - ctr->tick_func(ctr); -#else ctr_tick(ctr); -#endif } } @@ -702,14 +538,9 @@ pit_write(uint16_t addr, uint8_t val, void *priv) ctr->m = (val >> 1) & 7; if (ctr->m > 5) ctr->m &= 3; -#ifdef NEW_PIT_CODE - ctr->tick_func = ctr_tick_funcs[ctr->m]; -#endif ctr->null_count = 1; ctr->bcd = (ctr->ctrl & 0x01); - if (ctr->out_func != NULL) - ctr->out_func(!!ctr->m, ctr->out); - ctr->out = !!ctr->m; + ctr_set_out(ctr, !!ctr->m); ctr->state = 0; if (ctr->latched) { 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; case 1: ctr->l = val; - if (ctr->m == 0) { - if (ctr->out_func != NULL) - ctr->out_func(0, ctr->out); - ctr->out = 0; - } - if (dev->flags & PIT_OLIVETTI) - ctr->do_load = 1; - else - ctr_load(ctr); + if (ctr->m == 0) + ctr_set_out(ctr, 0); + ctr_load(ctr); break; case 2: ctr->l = (val << 8); - if (ctr->m == 0) { - if (ctr->out_func != NULL) - ctr->out_func(0, ctr->out); - ctr->out = 0; - } - if (dev->flags & PIT_OLIVETTI) - ctr->do_load = 1; - else - ctr_load(ctr); + if (ctr->m == 0) + ctr_set_out(ctr, 0); + ctr_load(ctr); break; case 3: case 0x83: if (ctr->wm & 0x80) { ctr->l = (ctr->l & 0x00ff) | (val << 8); 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 { ctr->l = (ctr->l & 0xff00) | val; pit_log("PIT %i: Written low byte %02X, latch now %04X\n", t, val, ctr->l); if (ctr->m == 0) { ctr->state = 0; - if (ctr->out_func != NULL) - ctr->out_func(0, ctr->out); - ctr->out = 0; + ctr_set_out(ctr, 0); } } @@ -943,7 +757,7 @@ pit_nmi_timer_ps2(int new_out, int old_out) static void -ctr_reset(pit_t *dev, ctr_t *ctr) +ctr_reset(ctr_t *ctr) { ctr->ctrl = 0; ctr->m = 0; @@ -957,8 +771,6 @@ ctr_reset(pit_t *dev, ctr_t *ctr) ctr->s1_det = 0; ctr->l_det = 0; - - ctr->pit = dev; } @@ -972,15 +784,10 @@ pit_reset(pit_t *dev) dev->clock = 0; for (i = 0; i < 3; i++) - ctr_reset(dev, &dev->counters[i]); + ctr_reset(&dev->counters[i]); /* Disable speaker gate. */ 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 = { "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: pit = device_add(&i8254_device); break; - case (PIT_8254 | PIT_OLIVETTI): - pit = device_add(&i8254_olivetti_device); - break; } for (i = 0; i < 3; i++) {