From 36cdd540b26c6f9aa62765118cdfaf2022f7e520 Mon Sep 17 00:00:00 2001 From: TomW Date: Fri, 8 Nov 2013 22:32:34 +0000 Subject: [PATCH] PIT timers can now be restarted using GATE input - CPU speed detection on SiS496/497 now works. Added missing port 0x61 to Olivetti M24 - PC speaker now works on that machine. Some code tidying. --- src/386.c | 9 +++++---- src/808x.c | 2 +- src/ibm.h | 1 + src/keyboard_amstrad.c | 17 ++++++----------- src/keyboard_at.c | 9 ++++++--- src/keyboard_olim24.c | 17 +++++++++++++++-- src/keyboard_xt.c | 8 +++----- src/pit.c | 19 +++++++++++++++++++ src/pit.h | 1 + 9 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/386.c b/src/386.c index bedc69a..2fd5f78 100644 --- a/src/386.c +++ b/src/386.c @@ -1418,10 +1418,11 @@ opcodestart: keyboard_at_poll(); }*/ - pit.c[0]-=cycdiff; - pit.c[1]-=cycdiff; - if (ppi.pb&1) pit.c[2]-=cycdiff; - if ((pit.c[0]<1)||(pit.c[1]<1)||(pit.c[2]<1)) pit_poll(); + pit.c[0] -= cycdiff; + pit.c[1] -= cycdiff; + if (pit.gate[2]) pit.c[2] -= cycdiff; + if ((pit.c[0] < 1) || (pit.c[1] < 1) || (pit.c[2] < 1)) pit_poll(); + timer_clock(cycdiff); } } diff --git a/src/808x.c b/src/808x.c index 04a6a9a..e52fd90 100644 --- a/src/808x.c +++ b/src/808x.c @@ -819,7 +819,7 @@ void clockhardware() current_diff += diff; pit.c[0] -= diff; pit.c[1] -= diff; - if (ppi.pb & 1) pit.c[2] -= diff; + if (pit.gate[2]) pit.c[2] -= diff; if ((pit.c[0] < 1) || (pit.c[1] < 1) || (pit.c[2] < 1)) pit_poll(); timer_clock(diff); diff --git a/src/ibm.h b/src/ibm.h index eb8c2a9..203a0c2 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -198,6 +198,7 @@ typedef struct PIT int thit[3]; int delay[3]; int rereadlatch[3]; + int gate[3]; } PIT; PIT pit; diff --git a/src/keyboard_amstrad.c b/src/keyboard_amstrad.c index 62f6193..b40c019 100644 --- a/src/keyboard_amstrad.c +++ b/src/keyboard_amstrad.c @@ -2,6 +2,7 @@ #include "io.h" #include "mem.h" #include "pic.h" +#include "pit.h" #include "sound.h" #include "timer.h" @@ -59,10 +60,7 @@ void keyboard_amstrad_adddata(uint8_t val) void keyboard_amstrad_write(uint16_t port, uint8_t val, void *priv) { pclog("keyboard_amstrad : write %04X %02X %02X\n", port, val, keyboard_amstrad.pb); -/* if (ram[8] == 0xc3) - { - output = 3; - }*/ + switch (port) { case 0x61: @@ -75,16 +73,13 @@ void keyboard_amstrad_write(uint16_t port, uint8_t val, void *priv) keyboard_amstrad.pb = val; ppi.pb = val; -/* if (AMSTRADIO) - keyboard_amstrad.s2 = val & 4; - else - keyboard_amstrad.s2 = val & 8;*/ gated = ((val & 3) == 3); if (gated) - wasgated = 1; - + wasgated = 1; + pit_set_gate(2, val & 1); + if (val & 0x80) - keyboard_amstrad.pa = 0; + keyboard_amstrad.pa = 0; break; case 0x63: diff --git a/src/keyboard_at.c b/src/keyboard_at.c index 1115909..75fb462 100644 --- a/src/keyboard_at.c +++ b/src/keyboard_at.c @@ -2,6 +2,7 @@ #include "io.h" #include "mem.h" #include "pic.h" +#include "pit.h" #include "sound.h" #include "timer.h" @@ -268,9 +269,11 @@ void keyboard_at_write(uint16_t port, uint8_t val, void *priv) break; case 0x61: - ppi.pb=val; - gated=((val&3)==3); - if (gated) wasgated=1; + ppi.pb = val; + gated = ((val & 3) == 3); + if (gated) + wasgated = 1; + pit_set_gate(2, val & 1); break; case 0x64: diff --git a/src/keyboard_olim24.c b/src/keyboard_olim24.c index 141be39..3324ca1 100644 --- a/src/keyboard_olim24.c +++ b/src/keyboard_olim24.c @@ -3,6 +3,7 @@ #include "mem.h" #include "mouse.h" #include "pic.h" +#include "sound.h" #include "timer.h" #include "keyboard.h" @@ -137,7 +138,16 @@ void keyboard_olim24_write(uint16_t port, uint8_t val, void *priv) } } - break; + break; + + case 0x61: + ppi.pb = val; + + gated = ((val & 3) == 3); + if (gated) + wasgated = 1; + pit_set_gate(2, val & 1); + break; } } @@ -164,6 +174,9 @@ uint8_t keyboard_olim24_read(uint16_t port, void *priv) } break; + case 0x61: + return ppi.pb; + case 0x64: temp = keyboard_olim24.status; keyboard_olim24.status &= ~(STAT_RTIMEOUT | STAT_TTIMEOUT); @@ -279,7 +292,7 @@ void mouse_olim24_poll(int x, int y, int b) void keyboard_olim24_init() { //return; - io_sethandler(0x0060, 0x0001, keyboard_olim24_read, NULL, NULL, keyboard_olim24_write, NULL, NULL, NULL); + io_sethandler(0x0060, 0x0002, keyboard_olim24_read, NULL, NULL, keyboard_olim24_write, NULL, NULL, NULL); io_sethandler(0x0064, 0x0001, keyboard_olim24_read, NULL, NULL, keyboard_olim24_write, NULL, NULL, NULL); keyboard_olim24_reset(); keyboard_send = keyboard_olim24_adddata; diff --git a/src/keyboard_xt.c b/src/keyboard_xt.c index a098098..cd45d5c 100644 --- a/src/keyboard_xt.c +++ b/src/keyboard_xt.c @@ -72,13 +72,11 @@ void keyboard_xt_write(uint16_t port, uint8_t val, void *priv) } keyboard_xt.pb = val; ppi.pb = val; -/* if (AMSTRADIO) - keyboard_xt.s2 = val & 4; - else - keyboard_xt.s2 = val & 8;*/ + gated = ((val & 3) == 3); if (gated) - wasgated = 1; + wasgated = 1; + pit_set_gate(2, val & 1); if (val & 0x80) { diff --git a/src/pit.c b/src/pit.c index 77151b5..446c6d2 100644 --- a/src/pit.c +++ b/src/pit.c @@ -302,7 +302,26 @@ void pit_poll() } } +void pit_set_gate(int channel, int gate) +{ + if (gate && !pit.gate[channel]) + { + switch (pit.m[channel]) + { + case 1: /*Hardware retriggerable one-shot*/ + case 2: /*Rate generator*/ + case 3: /*Square wave mode*/ + case 5: /*Hardware triggered strobe (retriggerable)*/ + pit.c[channel] = pit.l[2] * PITCONST; + break; + } + } + pit.gate[channel] = gate; +} + void pit_init() { io_sethandler(0x0040, 0x0004, pit_read, NULL, NULL, pit_write, NULL, NULL, NULL); + pit.gate[0] = pit.gate[1] = 1; + pit.gate[2] = 0; } diff --git a/src/pit.h b/src/pit.h index 9ea790d..79a0790 100644 --- a/src/pit.h +++ b/src/pit.h @@ -1,3 +1,4 @@ extern double PITCONST; void pit_init(); void pit_reset(); +void pit_set_gate(int channel, int gate);