]> wirehaze git hosting - BOS.git/blob - kernel/init/cmos.asm

wirehaze git hosting

Added Gitter badge
[BOS.git] / kernel / init / cmos.asm
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2005. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; To get stuff ( time & date ) from CMOS memory. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9
10 ;-----------------------------------;
11 ; variables containing CMOS data ;
12 ;-----------------------------------;
13 century db 0 ; latest century,
14 year db 0 ; year,
15 month db 0 ; month,
16 day db 0 ; day (1 = sunday),
17 hour db 0 ; hour,
18 minute db 0 ; minute and
19 second db 0 ; second read in from CMOS.
20
21
22 ;-------------------------;
23 ; save info from CMOS ;
24 ;-------------------------;
25 get_cmos_data:
26 push ax
27
28 mov al, 0x00 ; get the "second" byte
29 out 0x70, al
30 in al, 0x71
31 mov [second], al ; save it.
32
33 mov al, 0x02 ; get the "minute" byte
34 out 0x70, al
35 in al, 0x71
36 mov [minute], al
37
38 mov al, 0x04 ; get the "hour" byte
39 out 0x70, al
40 in al, 0x71
41 mov [hour], al
42
43 mov al, 0x07 ; get the "day" byte
44 out 0x70, al
45 in al, 0x71
46 mov [day], al
47
48 mov al, 0x08 ; get the "month" byte
49 out 0x70, al
50 in al, 0x71
51 mov [month], al
52
53 mov al, 0x09 ; get the "year" byte
54 out 0x70, al
55 in al, 0x71
56 mov [year], al
57
58 mov al, 0x32 ; get the "century" byte
59 out 0x70, al
60 in al, 0x71
61 mov [century], al
62
63 pop ax
64 ret
65
66 ;------------------------------------------------;
67 ; calculate binary from BCD ;
68 ; in: al = BCD ;
69 ; out: al = bin ;
70 ;------------------------------------------------;
71 BCD2bin:
72 push ebx
73 mov bl, al ; bl = al mod 16
74 and bl, 0x0F
75 shr al, 4 ; al = al / 16
76 mov bh, 10
77 mul bh ; multiply by 10
78 add al, bl ; add in low nib
79 pop ebx
80 ret
81
82
83 ;------------------------------------------------;
84 ; calculate ASCII from BCD ;
85 ; in: al = BCD ;
86 ; out: ax = ASCII ;
87 ;------------------------------------------------;
88 BCD2ascii:
89 push ecx
90 mov ah, al
91 and ax, 0xF00F ; mask bits
92 shr ah, 4 ; right shift ah to get unpacked BCD
93 or ax, 0x3030 ; combine with 30 to get ASCII
94 xchg ah, al ; swap for ASCII storage convention
95 pop ecx
96 ret