93 lines
3.2 KiB
C
93 lines
3.2 KiB
C
#include <system.h>
|
|
#include <time.h>
|
|
#include "cmos.h"
|
|
|
|
volatile byte i86_cmos_data[128];
|
|
|
|
void i86_cmos_write ()
|
|
{
|
|
byte i;
|
|
for (i = 0; i < 128; i++) {
|
|
//asm volatile ("cli");
|
|
outportb(0x70, i);
|
|
iowait();
|
|
outportb(0x71, i86_cmos_data[i]);
|
|
//asm volatile ("sti");
|
|
}
|
|
}
|
|
|
|
void i86_cmos_read ()
|
|
{
|
|
byte i;
|
|
for (i = 0; i < 128; i++) {
|
|
//asm volatile ("cli");
|
|
outportb(0x70, i);
|
|
iowait();
|
|
i86_cmos_data[i] = inportb(0x71);
|
|
//asm volatile ("sti");
|
|
}
|
|
}
|
|
|
|
void i86_cmos_read_clock(TIME* tim)
|
|
{
|
|
i86_cmos_read();
|
|
|
|
if ((i86_cmos_data[0x0b]&4)==0) // BCD = true;
|
|
{
|
|
tim->seconds = (i86_cmos_data[0x00]%16) + 10*(i86_cmos_data[0x00]/16);
|
|
tim->minutes = (i86_cmos_data[0x02]%16) + 10*(i86_cmos_data[0x02]/16);
|
|
if ((i86_cmos_data[0x0b]&2)==0) { // AM/PM
|
|
if (i86_cmos_data[0x04]&80) { // pm
|
|
tim->hours = ((i86_cmos_data[0x04]-0x80)%16) + 10*((i86_cmos_data[0x04]-0x80)/16);
|
|
tim->am_pm = 1;
|
|
}
|
|
else { // am
|
|
tim->hours = (i86_cmos_data[0x04]%16) + 10*(i86_cmos_data[0x04]/16);
|
|
tim->am_pm = 0;
|
|
}
|
|
}
|
|
else { // 24 hours
|
|
tim->hours = (i86_cmos_data[0x04]%16) + 10*(i86_cmos_data[0x04]/16);
|
|
if (tim->hours > 12) {
|
|
tim->am_pm = 1;
|
|
tim->hours -= 12;
|
|
}
|
|
else tim->am_pm = 0;
|
|
}
|
|
|
|
tim->weekday = (i86_cmos_data[0x06]%16) + 10*(i86_cmos_data[0x06]/16);
|
|
tim->day = (i86_cmos_data[0x07]%16) + 10*(i86_cmos_data[0x07]/16);
|
|
tim->month = (i86_cmos_data[0x08]%16) + 10*(i86_cmos_data[0x08]/16);
|
|
tim->year = (i86_cmos_data[0x09]%16) + 10*(i86_cmos_data[0x09]/16);
|
|
tim->century = (i86_cmos_data[0x32]%16) + 10*(i86_cmos_data[0x32]/16);
|
|
}
|
|
|
|
else {//BCD = false;
|
|
tim->seconds = i86_cmos_data[0x00];
|
|
tim->minutes = i86_cmos_data[0x02];
|
|
if ((i86_cmos_data[0x0b]&2)==0) { // AM/PM
|
|
if (i86_cmos_data[0x04]&80) { // pm
|
|
tim->hours = i86_cmos_data[0x04]-0x80;
|
|
tim->am_pm = 1;
|
|
}
|
|
else { // am
|
|
tim->hours = i86_cmos_data[0x04];
|
|
tim->am_pm = 0;
|
|
}
|
|
}
|
|
else { // 24 hours
|
|
tim->hours = i86_cmos_data[0x02];
|
|
if (tim->hours > 12) {
|
|
tim->am_pm = 1;
|
|
tim->hours -= 12;
|
|
}
|
|
else tim->am_pm = 0;
|
|
}
|
|
tim->weekday = i86_cmos_data[0x06];
|
|
tim->day = i86_cmos_data[0x07];
|
|
tim->month = i86_cmos_data[0x08];
|
|
tim->year = i86_cmos_data[0x09];
|
|
tim->century = i86_cmos_data[0x32];
|
|
}
|
|
}
|