From 311b8afc8309ad807095927c57cd0ae949e85a8f Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 26 Jan 2004 22:00:00 -0500 Subject: [PATCH] Import backup from 2004-01-26 --- Functions.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ functions.h | 15 +++++++++- kernel.c | 5 +++- 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/Functions.c b/Functions.c index 84e6799..470f97b 100644 --- a/Functions.c +++ b/Functions.c @@ -45,6 +45,18 @@ char *strcat(char *dest, char *src) } +//converts a binary-coded-decimal byte to its decimal equivalent +inline byte bcd2byte(byte bcd) +{ + return (10* ((bcd & 0xF0) >> 4)) + (bcd & 0x0F); +} + +//converts a binary-coded-decimal byte to its decimal equivalent +inline byte byte2bcd(byte bite) +{ + return ((bite / 10) << 4) | (bite % 10); +} + void rtrim(char *str) { str += strlen(str); //now points to the null character at the end of the string @@ -182,6 +194,79 @@ inline dword kernel_size() } +//These functions are for reading and writing various values stored on the CMOS Real Time Clock +byte rtc_readDay() +{ + outportb(0x70, 7); + return bcd2byte(inportb(0x71)); +} + +byte rtc_readMonth() +{ + outportb(0x70, 8); + return bcd2byte(inportb(0x71)); +} + +byte rtc_readYear() +{ + outportb(0x70, 9); + return bcd2byte(inportb(0x71)); +} + +byte rtc_readSecond() +{ + outportb(0x70, 0); + return bcd2byte(inportb(0x71)); +} + +byte rtc_readMinute() +{ + outportb(0x70, 2); + return bcd2byte(inportb(0x71)); +} + +byte rtc_readHour() +{ + outportb(0x70, 4); + return bcd2byte(inportb(0x71)); +} + +void rtc_setDay(byte day) +{ + outportb(0x70, 7); + outportb(0x71, byte2bcd(day)); +} + +void rtc_setMonth(byte month) +{ + outportb(0x70, 8); + outportb(0x71, byte2bcd(month)); +} + +void rtc_setYear(byte year) +{ + outportb(0x70, 9); + outportb(0x71, byte2bcd(year)); +} + +void rtc_setSecond(byte second) +{ + outportb(0x70, 0); + outportb(0x71, byte2bcd(second)); +} + +void rtc_setMinute(byte minute) +{ + outportb(0x70, 2); + outportb(0x71, byte2bcd(minute)); +} + +void rtc_setHour(byte hour) +{ + outportb(0x70, 4); + outportb(0x71, byte2bcd(hour)); +} + diff --git a/functions.h b/functions.h index e8649dd..497fe8a 100644 --- a/functions.h +++ b/functions.h @@ -25,7 +25,20 @@ char *strcat(char *dest, char *src); void rtrim(char *str); char *ucase(char *str); char *lcase(char *str); - +inline byte bcd2byte(byte bcd); +inline byte byte2bcd(byte bite); +byte rtc_readDay(); +byte rtc_readMonth(); +byte rtc_readYear(); +byte rtc_readSecond(); +byte rtc_readMinute(); +byte rtc_readHour(); +void rtc_setDay(byte dat); +void rtc_setMonth(byte month); +void rtc_setYear(byte year); +void rtc_setSecond(byte second); +void rtc_setMinute(byte minute); +void rtc_setHour(byte hour); diff --git a/kernel.c b/kernel.c index 2d3d90c..01a783a 100644 --- a/kernel.c +++ b/kernel.c @@ -82,9 +82,11 @@ void k_init() printf("HOS 0.13 - Kernel File Size: %u kb\tData Size: %u bytes\n", kernel_size()>>10, (dword)(&_end)-(dword)(&_code)); printf("Memory available to OS: %u MB (%u bytes)\n", mm_megabytes, mm_totalmem); printf("Free memory: %u bytes (%u pages)\n", mm_freemem(), mm_freemem()>>12); + printf("%d/%d/%d\t%d:%d:%d\n", rtc_readMonth(), rtc_readDay(), rtc_readYear(), rtc_readHour(), rtc_readMinute(), rtc_readSecond()); printf("Root Directory: %s/\n", rootDevice->id); - int a; + +/* int a; byte *addr = 0; for (a = 0; a < 5; a++) { @@ -97,6 +99,7 @@ void k_init() memcpy(0, addr, 4192); asm("call 0"); free(addr); +*/ dword key = 0; for (;;)