aboutsummaryrefslogtreecommitdiff
path: root/mirai.old/asm/cmos.zig
blob: ba4005b6bb6e72931a47f0c7c44a2bc47fd1a01b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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);
}