Page 1 of 1
Using interrupts to display the system time
Posted: Sat Dec 11, 2004 6:36 am
by Metallic-Red
How do I use interrupt 1A to display the system time on screen? I had a go but it didn't seem to work, but then again, I could be using the wrong sub object. Below is a sample from my OS:
strHour RESB 0
strMinute RESB 0
strSecond RESB 0
CLC
MOV AH, 0x02
INT 0x1A
MOV BYTE [strHour], CH
MOV BYTE [strMinute], CL
MOV BYTE [strSecond], DL
MOV SI, strHour
CALL DRAWTEXT ; This function will correctly display the text stored in the SI register
Re:Using interrupts to display the system time
Posted: Sat Dec 11, 2004 7:28 am
by IRBMe
I've never actually used this interrupt, and so perhaps the answer is glaringly obvious and I just don't know it, but it may help others answer your question if you're a little more specific about exactly what you mean by "doesn't work"? For example, does it print out seemingly garbage characters on the screen? Perhaps it causes bochs to crash or something?
At a guess, I'd say that you're printing out not the actual number of hours, but the character represented by the ASCII code corresponding to the number of hours, and so need some kind of itoa (integer to ascii) function.
Re:Using interrupts to display the system time
Posted: Sat Dec 11, 2004 11:33 am
by ASHLEY4
This nasm code works
Code: Select all
;**************************************
;\\\\||////
;(@@)
;ASHLEY4.
; displays time until a key is pressed
; nasm -f bin -o time.com time.asm
; by (ASHLEY4) to use no dos int's
;
;**************************************
org 100h
segment .text
mov ah,01h
mov cx,2000h
int 10h
m0:
mov ah,2
int 1ah ; time in BCD , dl=0
push cx
push dx
pop eax
m1:
mov al,163
sub dl,160
ja $+3
rol eax,4
push ax
mov ah,0eh
int 10h
pop ax
jne m1
mov al,13
mov ah,0eh
int 10h
mov ah,1 ; until key is pressed
int 16h
jz m0
mov ah,01h
mov cx,0d0eh
int 10h
ret
Its in BCD and needed converting.
\\\\||////
(@@)
ASHLEY4.
Batteries not included, Some assembly required.
Re:Using interrupts to display the system time
Posted: Sat Dec 11, 2004 11:43 am
by ASHLEY4
PS: Just ask if you need the Date function.
\\\\||////
(@@)
ASHLEY4.
Batteries not included, Some assembly required.
Re:Using interrupts to display the system time
Posted: Sun Dec 12, 2004 6:24 am
by Metallic-Red
Thanks for that code! It worked perfectly! Though the format is HH:MM:SS. How do I make it HH:MM:SS:Hundredtha? So and example would be 17:23:10.56
Oh and I would like to see the DATE functions as well.
Re:Using interrupts to display the system time
Posted: Sun Dec 12, 2004 9:59 am
by ASHLEY4
Date code:
Code: Select all
;**********************************
; \||/
; (@@)
; ASHLEY4.
; nasm -f bin -o date.com date.asm
;*********************************
org 100h
segment .text
call getdate ; getdate
xor ah,ah
int 16h
ret
getdate: ;start of getdate
mov ah,04h ;get date from CMOS
int 1ah ;invoke interrupt to get date
push cx
push dx
mov al,dl ;get day
call convert ;convert day BCD to ASCII
call display_date ;display day
pop dx
mov al,dh ;get month
call convert ;convert month BCD to ASCII
call display_date ;display mouth
pop cx
mov al,cl ;get year
call convert ;convert year BCD to ASCII
mov si, val
call putstr ;invoke print proc to display
ret
convert: ;start of convert
mov ah,al ;copy AL to AH
and ax,0f00fh ;mask bits
mov cl,4 ;CL=04 for shift
shr ah,cl ;shift right AH to get unpacked BCD
or ax, 3030h ;combine with 30 to get ASCII
xchg ah,al ;swap for ASCII storage convention
mov [val],ax ;store the ASCII value in VAL
ret
display_date: ;start of display_date
mov si,val
call putstr
mov ah,0eh ;display / to seperate months, days, and years
mov al,'/'
int 10h
ret
putstr: ; SI = address of string to display
lodsb
or al,al ;
jz putstrd
mov ah,0eh
mov bx,0007h
int 10h ; print char
jmp putstr
putstrd:
ret
segment .data
val dw 0,0
Time Lol.
\\\\||////
(@@)
ASHLEY4.
Batteries not included, Some assembly required.