At the moment I want my OS to show the time, so i do this:
1. first check if the CMOS is making a update
2. if so, go to step 1
3. if not, read the 'b register' and print it (so i can see it)
4. read the current day of the week and print it
5. read the current hour, if the CMOS uses 12 hour mode, add 12 to the current hour and print it
the only strange thing i'm facing is the following. the result is always the following and i've tested it today and yesterday:
format: 00000010b
day of the week: 00000100b
hour: 0010000b
from what I understand this means:
binary format is enabled
24 hour mode is disabled
i'm using bochs 2.4.2
Code: Select all
;time.asm
; time functions
%DEFINE _CMOS_RTC_OUT 0x70
%DEFINE _CMOS_RTC_IN 0x71
get_time_format:
mov al, 10
out _CMOS_RTC_OUT,al
in al, _CMOS_RTC_IN
test al,0x80 ;if a update is in progress redo it all
jne get_time_format
mov al, 0x0b
out _CMOS_RTC_OUT, al
in al, _CMOS_RTC_IN
mov ah, 0x0
cmp al, 00000100b
je .no24_isbin
cmp al, 00000110b
je .is24_isbin
cmp al, 00000010b
je .is24_nobin
mov byte [__time__binary_mode_enabled], 0x0
mov byte [__time__24hour_mode_enabled], 0x0
ret
.no24_isbin:
mov byte [__time__binary_mode_enabled], 0x1
mov byte [__time__24hour_mode_enabled], 0x0
ret
.is24_isbin:
mov byte [__time__binary_mode_enabled], 0x1
mov byte [__time__24hour_mode_enabled], 0x1
ret
.is24_nobin:
mov byte [__time__binary_mode_enabled], 0x0
mov byte [__time__24hour_mode_enabled], 0x1
ret
get_time_year:
mov al, 10
out _CMOS_RTC_OUT,al
in al, _CMOS_RTC_IN
test al,0x80 ;if a update is in progress redo it all
jne get_time_year
mov al, 0x09
out _CMOS_RTC_OUT,al
in al, _CMOS_RTC_IN
mov ah, 0x0
ret
get_time_weekday:
mov al, 10
out _CMOS_RTC_OUT,al
in al, _CMOS_RTC_IN
test al,0x80 ;if a update is in progress redo it all
jne get_time_hour
mov al, 0x06
out _CMOS_RTC_OUT,al
in al, _CMOS_RTC_IN
mov ah, 0x0
ret
get_time_hour:
mov al, 10
out _CMOS_RTC_OUT,al
in al, _CMOS_RTC_IN
test al,0x80 ;if a update is in progress redo it all
jne get_time_hour
mov al, 0x09
out _CMOS_RTC_OUT,al
in al, _CMOS_RTC_IN
mov ah, 0x0
cmp [__time__24hour_mode_enabled], 0x0
je .done
add al, 0x0c
.done:
ret
__time__binary_mode_enabled db 0xFF
__time__24hour_mode_enabled db 0xFF