; *****************************************************************************
;
; CDT.ASM (Continuous Date And Time Output)
;
; Copyright (C) 2000  Erdogan TAN  [ 30/04/2000 ] (2)
;
; INT 1Ah - Date and Time Outputs
;
; INT 1Ah Function 04h = Return Current Date  (ROM-BIOS Interrupt/Function)
;
; Input:  AH = 04h
; Output: CF = 0 Succesfull
;            = 1 Clock has stopped running
;         CH = Century (in BCD)
;         CL = Year (in BCD)
;         DH = Month (in BCD)
;         DL = Day (in BCD)
;
; Description:
;
; Function 04h reads the current date from Real Time Clock CMOS RAM.
;
; INT 1Ah Function 02h = Return Current Time  (ROM-BIOS Interrupt/Function)
;
; Input:  AH = 02h
; Output: CF = 0 Succesfull
;            = 1 Clock has stopped running
;         CH = Number of Hours in binary coded decimal (BCD)
;         CL = Number of Minutes (in BCD)
;         DH = Number of Seconds (in BCD)
;         DL = 00h Standard time
;            = 01h Daylight savings time
;
; Description:
;
; Function 02h reads the current time from Real Time Clock CMOS RAM.
; [ Above information derived from American Megatrends Inc.'s Official
; AMIBIOS Programming Guide (1993). ]
;
; *****************************************************************************
Present segment Para 'code'
		assume CS:Present, DS:Present, ES:Present, SS:Present
                org 100h
;北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北
;
;              PROCEDURE proc_start
;
;北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北
proc_start      proc    near
start:                                         
                mov si, offset Msg_Copyrights
                call proc_printmsg
                mov ah, 03h
                int 10h                 ; Return Cursor Position
                mov word ptr [CursorTyp], cx
                dec dh
                dec dh
                dec dh
                mov word ptr [CursorPos], dx
                mov ah, 01h            ; Set Cursor Type
                mov ch, 20h            ; Hide Cursor
                int 10h
repeat_time:
                mov ah, 04h
                int 1Ah
                mov al, ch
                call proc_hex
                mov word ptr [Century], ax
                mov al, cl
                call proc_hex
                mov word ptr [Year], ax
                mov al, dh
                call proc_hex
                mov word ptr [Month], ax
                mov al, dl
                call proc_hex
                mov word ptr [Day], ax
                mov ah, 02h
                int 1Ah
                mov al, ch
                call proc_hex
                mov word ptr [Hour], ax
                mov al, cl
                call proc_hex
                mov word ptr [Minute], ax
                mov al, dh
                call proc_hex
                mov word ptr [Second], ax
                mov dx, word ptr [CursorPos]
                mov ah, 02h
                mov bx, 07h
                int 10h                 ; Set Cursor Position
                mov si, offset Msg_Date
                call proc_printmsg
                mov ah, 01h             ; Return Keyboard Status
                int 16h
                jz short repeat_time    ; No Character Waiting
                xor ah, ah              ; Remove Char From Keyboard Buffer
                int 16h
                mov ah, 01h             ; Set Cursor Type
                mov cx, word ptr [CursorTyp]
                int 10h
                int 20h
proc_start      endp
proc_printmsg   proc near
loc_print:          
		lodsb                           ; Load byte at DS:SI to AL
		and     AL,AL            
		je      short loc_return        ; If AL = 00h then return
		mov     AH,0Eh                  
		mov     BX,07h             
		int     10h                     ; BIOS Service func ( ah ) = 0Eh
						; Write char as TTY
						;AL-char BH-page BL-color
		jmp     short loc_print           
loc_return:
		retn
proc_printmsg   endp
;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; From binary (byte) to hexadecimal (character) converter    ;
;                                                            ;
; input -> AL = byte (binary number) to be converted         ;
; output -> AH = First character of hexadecimal number       ;
; output -> AL = Second character of hexadecimal number      ;
;                                                            ;
; (c) Erdogan TAN  1998 - 1999                               ;
;............................................................;
; 1998
proc_hex        proc    near
		db 0D4h,10h                     ; Undocumented inst. AAM
						; AH = AL / 10h
						; AL = AL MOD 10h
		or AX,'00'                      ; Make it ZERO (ASCII) based
		xchg AH,AL
; 1999
		cmp AL,'9'
		jna pass_cc_al
		add AL,7
pass_cc_al:
		cmp AH,'9'
		jna pass_cc_ah
		add AH,7
pass_cc_ah:
; 1998
		retn
proc_hex        endp
Msg_Copyrights:
                db   0Dh, 0Ah
                db   "INT 1Ah FUNCTION 04h DATE AND 02h TIME OUTPUTS"
                db   0Dh, 0Ah
                db   "(c) Erdogan Tan  [ 2000 ]"
                db   0Dh, 0Ah
                db   0Dh, 0Ah
                db   0Dh, 0Ah
                db   0Dh, 0Ah
                db   0Dh, 0Ah, 0
Msg_Date:       db   "Date : "
Day:            db   '0'
		db   '0'
                db   '/'
Month:          db   '0'
		db   '0'
                db   '/'
Century:        db   '0'
                db   '0'
Year:           db   '0'
		db   '0'
                db   0Dh, 0Ah
                db   0Dh, 0Ah
                db   'Time : '
Hour:           db   '0'
		db   '0'
                db   ':'
Minute:         db   '0'
		db   '0'
                db   ':'
Second:         db   '0'
		db   '0'
                db   0Dh, 0Ah
                db   0
CursorTyp:      dw   0
CursorPos:      dw   0
Present         ends
                end  start