CTAOS v3
This commit is contained in:
92
SysCore/hal/cmos/cmos.c
Normal file
92
SysCore/hal/cmos/cmos.c
Normal file
@ -0,0 +1,92 @@
|
||||
#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];
|
||||
}
|
||||
}
|
10
SysCore/hal/cmos/cmos.h
Normal file
10
SysCore/hal/cmos/cmos.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef __CMOS_H
|
||||
#define __CMOS_H
|
||||
|
||||
extern volatile byte i86_cmos_data[128];
|
||||
|
||||
extern void i86_cmos_write ();
|
||||
extern void i86_cmos_read ();
|
||||
extern void i86_cmos_read_clock (TIME *tim);
|
||||
|
||||
#endif
|
18
SysCore/hal/cmos/compile.bat
Normal file
18
SysCore/hal/cmos/compile.bat
Normal file
@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
rem The name of the loader assembly file (without extension, must be .asm):
|
||||
set loader_name=loader
|
||||
|
||||
rem NASM and DJGPP executable paths:
|
||||
set nasm_path=C:\nasm
|
||||
set djgpp_path=C:\DJGPP\bin
|
||||
set objpath=../../objects
|
||||
set incpath=../../include
|
||||
|
||||
@echo on
|
||||
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/cmos.o cmos.c
|
||||
|
||||
@echo off
|
||||
@echo .
|
||||
@echo Done!
|
||||
|
||||
@pause
|
Reference in New Issue
Block a user