Add bios time module

This commit is contained in:
2025-11-20 16:24:39 +01:00
parent 2e29342c83
commit bc674eb4eb
7 changed files with 123 additions and 1 deletions

View File

@@ -0,0 +1 @@
export * from "./time"

View File

@@ -0,0 +1,2 @@
export const CFG_KMOD_BIOS_TIME_CMOS_ADDR = 0x70;
export const CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR = 0x71;

View File

@@ -0,0 +1,96 @@
import { portin, portout } from "../../../lib/libts/port";
import { padStart } from "../../../lib/libts/string";
import {
CFG_KMOD_BIOS_TIME_CMOS_ADDR,
CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR,
} from "./config";
export function kmod_bios_time_getCentury(): number {
const val = 0x32;
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
}
export function kmod_bios_time_getYear(): number {
const val = 0x09;
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
}
export function kmod_bios_time_getMonth(): number {
const val = 0x08;
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
}
export function kmod_bios_time_getDay(): number {
const val = 0x07;
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
}
export function kmod_bios_time_getHours(): number {
const val = 0x04;
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
}
export function kmod_bios_time_getMinutes(): number {
const val = 0x02;
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
}
export function kmod_bios_time_getSeconds(): number {
const val = 0x00;
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
}
export function kmod_bios_time_getTimestamp(): string {
const century = kmod_bios_time_getCentury();
const year = kmod_bios_time_getYear();
const month = kmod_bios_time_getMonth();
const day = kmod_bios_time_getDay();
const hours = kmod_bios_time_getHours();
const minutes = kmod_bios_time_getMinutes();
const seconds = kmod_bios_time_getSeconds();
return (
century.toString() +
year.toString() +
"-" +
padStart(month.toString(), 2, "0") +
"-" +
padStart(day.toString(), 2, "0") +
"T" +
padStart(hours.toString(), 2, "0") +
":" +
padStart(minutes.toString(), 2, "0") +
":" +
padStart(seconds.toString(), 2, "0") +
+".000" +
"Z"
);
}

View File

@@ -1,7 +1,7 @@
import { import {
kmod_graphics_vga_clear, kmod_graphics_vga_clear,
kmod_graphics_vga_writeChar, kmod_graphics_vga_writeChar,
} from "./modules/graphics/vga"; } from "./modules/graphics/graphics.kmod";
export function kpanic(reason?: string) { export function kpanic(reason?: string) {
kmod_graphics_vga_clear(); kmod_graphics_vga_clear();

View File

@@ -0,0 +1,7 @@
export function portin(port: number): number {
return $ptin(port);
}
export function portout(port: number, value: number): void {
$ptout(port, value);
}

View File

@@ -0,0 +1,11 @@
export function padStart(
str: string,
targetLength: number,
padString: string
): string {
while (str.length < targetLength) {
str = padString + str;
}
return str;
}

View File

@@ -0,0 +1,5 @@
import { kmod_bios_time_getTimestamp } from "../../kernel/modules/bios/time";
export function getDate(): Date {
return new Date(kmod_bios_time_getTimestamp());
}