aboutsummaryrefslogtreecommitdiff
path: root/mirai/asm/cmos.zig
diff options
context:
space:
mode:
Diffstat (limited to 'mirai/asm/cmos.zig')
-rw-r--r--mirai/asm/cmos.zig56
1 files changed, 56 insertions, 0 deletions
diff --git a/mirai/asm/cmos.zig b/mirai/asm/cmos.zig
new file mode 100644
index 0000000..ba4005b
--- /dev/null
+++ b/mirai/asm/cmos.zig
@@ -0,0 +1,56 @@
+//! CMOS/RTC Operations
+
+const io = @import("io.zig");
+const ports = @import("../common/constants/ports.zig");
+
+/// Read a CMOS register
+pub inline fn read_register(reg: u8) u8 {
+ io.out_byte(ports.CMOS_ADDRESS, reg);
+ return io.in_byte(ports.CMOS_DATA);
+}
+
+/// Write to a CMOS register
+pub inline fn write_register(reg: u8, value: u8) void {
+ io.out_byte(ports.CMOS_ADDRESS, reg);
+ io.out_byte(ports.CMOS_DATA, value);
+}
+
+/// Read RTC seconds (BCD)
+pub inline fn read_seconds() u8 {
+ return read_register(0x00);
+}
+
+/// Read RTC minutes (BCD)
+pub inline fn read_minutes() u8 {
+ return read_register(0x02);
+}
+
+/// Read RTC hours (BCD)
+pub inline fn read_hours() u8 {
+ return read_register(0x04);
+}
+
+/// Read RTC day of month (BCD)
+pub inline fn read_day() u8 {
+ return read_register(0x07);
+}
+
+/// Read RTC month (BCD)
+pub inline fn read_month() u8 {
+ return read_register(0x08);
+}
+
+/// Read RTC year (BCD, 00-99)
+pub inline fn read_year() u8 {
+ return read_register(0x09);
+}
+
+/// Read RTC century (BCD)
+pub inline fn read_century() u8 {
+ return read_register(0x32);
+}
+
+/// Convert BCD to binary
+pub inline fn bcd_to_bin(bcd: u8) u8 {
+ return (bcd & 0x0F) + ((bcd >> 4) * 10);
+}