aboutsummaryrefslogtreecommitdiff
path: root/sys_sppt.c
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2015-04-01 20:29:53 -0400
committerBen Burwell <ben@benburwell.com>2015-04-01 20:29:53 -0400
commit2b30f30a330ee9bc9feb9ec4e55c8b6f3e6eb8fe (patch)
tree08d7be1d815e1ae676eab5c734438ba048b854d1 /sys_sppt.c
parente282a861d5868868940b449681f2ee5da3e439e8 (diff)
as of 2013-11-182013-11-18
Diffstat (limited to 'sys_sppt.c')
-rw-r--r--sys_sppt.c148
1 files changed, 143 insertions, 5 deletions
diff --git a/sys_sppt.c b/sys_sppt.c
index 80ae62d..7facead 100644
--- a/sys_sppt.c
+++ b/sys_sppt.c
@@ -20,23 +20,31 @@
#include "mpx.h"
void interrupt (*vect60)(); /* Storage for DOS int 60h */
- /* interrupt vector. */
+ /* interrupt vector. */
+void interrupt (*vect08)(); /* Storage for DOS int 08h */
+ /* interrupt vector. */
+unsigned long clock; /* The clock counter */
void sys_init()
{
/* set up interrupt vector for MPX sys_calls */
-
vect60 = getvect(0x60);
setvect(0x60,&sys_call);
+
+ // set up the clock
+ clock_open();
}
void sys_exit()
{
- /* restore interrupt vector 60 and exit */
+ // restore the clock
+ clock_close();
- setvect(0x60,vect60);
- exit();
+ /* restore interrupt vector 60 and exit */
+ setvect(0x60,vect60);
+
+ exit();
}
@@ -83,3 +91,133 @@ void interrupt sys_call()
dispatch();
}
+
+/*
+ * Set up MXP clock
+ */
+void clock_open() {
+ unsigned char imr;
+
+ disable();
+ /* set up interrupt vector for timer interrupts */
+ vect08 = getvect(0x08);
+ setvect(0x08,&clock_int);
+
+ // set the timer mode
+ outportb(CMR, 0x36);
+ outportb(0x40, 0);
+ outportb(0x40, 0);
+
+ // set the count clock
+ clock = 0L;
+
+ // enable timer interrupts
+ imr = inportb(IMR); // Get current IMR
+ imr = imr & CLOCK_ENABLE; // Clear timer bit
+ outportb(IMR, imr); // Set new IMR
+
+ enable();
+}
+
+/*
+ * Restore the MS DOS clock
+ */
+void clock_close() {
+ disable();
+ setvect(0x08,vect08);
+ enable();
+}
+
+void interrupt clock_int() {
+ disable();
+ // if it's been 24 hours, reset clock to 0
+ if (clock >= 1572462L) {
+ clock = 0L;
+ } else {
+ clock++;
+ }
+ outportb(0x20, 0x20);
+ enable();
+}
+
+void stop_clock() {
+ unsigned char imr;
+ disable();
+
+ imr = inportb(IMR); // Get the old imr
+ imr = imr | CLOCK_DISABLE; // Disable timer interrupts
+ outportb(IMR, imr); // Set the new imr
+
+ enable();
+}
+
+/*
+ * Enables the timer interrupt
+ */
+void start_clock() {
+ unsigned char imr;
+ disable();
+
+ imr = inportb(IMR); // Get the old imr
+ imr = imr & CLOCK_ENABLE; // Enable timer interrupts
+ outportb(IMR, imr); // Set the new imr
+
+ enable();
+}
+
+/*
+ * Sets the value of the clock
+ */
+int set_clock(int hr, int m, int s) {
+ unsigned long ticks;
+
+ // Validate input
+ if (hr > 23 || hr < 0 || m > 59 || m < 0 || s > 59 || s < 0) {
+ return -1;
+ }
+
+ // set clock
+ ticks = 0L;
+ ticks = ((unsigned long)hr * 3600L * 91L / 5L);
+ ticks += ((unsigned long)m * 60L * 91L / 5L);
+ ticks += ((unsigned long)s * 91L / 5L);
+
+ disable();
+ clock = ticks;
+ enable();
+
+ return 0;
+}
+
+/*
+ * Gets the value of the clock
+ */
+void read_clock(int *hr, int *m, int *s) {
+ unsigned long ticks;
+ long total_seconds = 0L;
+ int l_hr = 0;
+ int l_m = 0; //local vars for hr, m
+
+ disable();
+ ticks = clock;
+ enable();
+
+ total_seconds = ticks * 10L;
+ total_seconds = total_seconds / 182L;
+
+ //count the whole hours
+ while (total_seconds >= 3600L) {
+ l_hr++;
+ total_seconds = total_seconds - 3600L;
+ }
+
+ //count the whole minutes
+ while (total_seconds >= 60L) {
+ l_m++;
+ total_seconds = total_seconds - 60L;
+ }
+
+ *hr = l_hr;
+ *m = l_m;
+ *s = total_seconds;
+}