⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timedate.inc

📁 TestOS - 带简单GUI的DOS扩展OS// 源代码// ASM// 英文
💻 INC
字号:
;=========================================================;
; TimeDate                                       11/12/03 ;
;---------------------------------------------------------;
; DOS EXTREME OS V0.01                                    ;
; by Craig Bamford.                                       ;
;                                                         ;
; Time and date functions for uses in text mode programs. ;                          
;=========================================================;
 ;----------------------------------------------------;
 ; date                   ; fills vals with bcd date  ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          none.                                     ;
 ;  Output:                                           ;
 ;          Puts bcd date in vals:                    ;
 ;          century, year, month, day.                ;
 ;                                             (100%) ;
 ;....................................................;

date:
        push  ds es
	pusha
        cli
	mov   al,32h			                 ; RTC 32h
	out   70h,al
	in    al,71h			                 ; read century
	mov   [century],al
	mov   al,9			                 ; RTC 09h
	out   70h,al
	in    al,71h			                 ; read year
	mov   [year],al
	mov   al,8			                 ; RTC 08h
	out   70h,al
	in    al,71h			                 ; read month
	mov   [month],al
	mov   al,7			                 ; RTC 07h
	out   70h,al
	in    al,71h			                 ; read day
	mov   [day],al
        sti
        popa
        pop   es ds

        ret

 ;----------------------------------------------------;
 ; prints date        ; prints the date in text mode  ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          none.                                     ;
 ;  Output:                                           ;
 ;          prints the date in text mode.             ;
 ;                                             (100%) ;
 ;....................................................;	

print_date:
        push  esi
        pusha
        mov   esi,date_lable
        call  print_string
        call  date
        mov   al,[day]
        call  bcd_to_ASCII
        mov   bx,[val]
        mov   al,bl
        call  print_char
        mov   al,bh
        call  print_char
       
        mov   al,":"
        call  print_char
  
        mov   al,[month]
        call  bcd_to_ASCII
        mov   bx,[val]
        mov   al,bl
        call  print_char
        mov   al,bh
        call  print_char

        mov   al,":"
        call  print_char
   
        mov   al,[century]
        call  bcd_to_ASCII
        mov   bx,[val]
        mov   al,bl
        call  print_char
        mov   al,bh
        call  print_char
        mov   al,[year]
        call  bcd_to_ASCII
        mov   bx,[val]
        mov   al,bl
        call  print_char
        mov   al,bh
        call  print_char
        popa
        pop   esi
        ret


 ;----------------------------------------------------;
 ; time                  ; fills vals with bcd time   ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          none.                                     ;
 ;  Output:                                           ;
 ;          Puts bcd time in vals:                    ;
 ;          hour, minute, second.                     ;
 ;                                             (100%) ;
 ;....................................................;	
time:
        push  ds es
	pusha
        cli
	mov   al,4			                 ; RTC  04h
	out   70h,al
	in    al,71h			                 ; read hour
	mov   [hour],al
	mov   al,2			                 ; RTC  02h
	out   70h,al
	in    al,71h			                 ; read minute
	mov   [minute],al
	xor   al,al			                 ; RTC  00h
	out   70h,al
	in    al,71h			                 ; read second
	mov   [second],al
        sti
        popa
        pop   es ds

        ret

 ;----------------------------------------------------;
 ; prints time        ; prints the time in text mode  ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          none.                                     ;
 ;  Output:                                           ;
 ;          prints the time in text mode.             ;
 ;                                             (100%) ;
 ;....................................................;	

print_time:
        push  esi
        pusha
        mov   esi,time_lable
        call  print_string
        call  time
        mov   al,[hour]
        call  bcd_to_ASCII
        mov   bx,[val]
        mov   al,bl
        call  print_char
        mov   al,bh
        call  print_char
       
        mov   al,":"
        call  print_char
  
        mov   al,[minute]
        call  bcd_to_ASCII
        mov   bx,[val]
        mov   al,bl
        call  print_char
        mov   al,bh
        call  print_char

        mov   al,":"
        call  print_char
   
        mov   al,[second]
        call  bcd_to_ASCII
        mov   bx,[val]
        mov   al,bl
        call  print_char
        mov   al,bh
        call  print_char
        popa
        pop   esi
        ret

 ;----------------------------------------------------;
 ; set time                    ; set's time from vals ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;         Bcd time in vals.                          ;
 ;  Output:                                           ;
 ;         Prints ERROR msg on error.                 ;
 ;                                              (70%) ;
 ;....................................................;		
set_time:			                
        push  ds es
	pusha
        cli
	mov   bl,59h
        mov   al,[second]
	call  check_bcd_time		                 ; check second number
        mov   al,[minute]
	call  check_bcd_time		                 ; check minute number
	mov   bl,23h
        mov   al,[hour]
	call  check_bcd_time		                 ; check hour number
        xor   al,al			                 ; RTC 00h
	out   70h,al
	mov   al,[second]
	out   71h,al			                 ; write second
	mov   al,2			                 ; RTC 02h
	out   70h,al
	mov   al,[minute]
	out   71h,al			                 ; write minute
	mov   al,4			                 ; RTC 04h
	out   70h,al
	mov   al,[hour]
	out   71h,al			                 ; write hour
        jmp   leave1
time_error:
        mov   esi,time_error_msg
        call  print_string
leave1:
        sti
        popa
        pop   es ds

        ret

 ;----------------------------------------------------;
 ; set date                    ; set's date from vals ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;         Bcd date in vals.                          ;
 ;  Output:                                           ;
 ;         Prints ERROR msg on error.                 ;
 ;                                              (70%) ;
 ;....................................................;		
set_date:
        push  ds es
	pusha
        cli
        mov   al,[day]	
	mov   bl,31h
	or    al,al			                 ; day cannot be 0
	jz    date_error
	call  check_bcd_date		                 ; check day number
	mov   bl,12h
        mov   al,[month]
	or    al,al			                 ; month cannot be 0
	jz    date_error
	call  check_bcd_date		                 ; check month number
	mov   bl,99h
        mov   al,[year]
	call  check_bcd_date		                 ; check year number
        mov   al,[century]
	call  check_bcd_date		                 ; check century number
        mov   al,7			                 ; RTC 07h
	out   70h,al
	mov   al,[day]
	out   71h,al			                 ; write day
	mov   al,8			                 ; RTC 08h
	out   70h,al
	mov   al,[month]
	out   71h,al			                 ; write month
	mov   al,9			                 ; RTC 09h
	out   70h,al
	mov   al,[year]
	out   71h,al			                 ; write year
	mov   al,32h			                 ; RTC 32h
	out   70h,al
	mov   al,[century]
	out   71h,al			                 ; write century
        jmp   leave2
date_error:
        mov   esi,date_error_msg
        call  print_string
leave2:
        sti
        popa
        pop   es ds

        ret

 ;----------------------------------------------------;
 ; bcd_to_ASCII         ;converts bcd number to ASCII ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;         Bcd number in al.                          ;
 ;  Output:                                           ;
 ;         ASCII number in val.                       ;
 ;                                             (100%) ;
 ;....................................................;
		
bcd_to_ASCII:
       pusha                                            ;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
       popa 

       ret

	
 ;----------------------------------------------------;
 ; checks it a bcd number date                        ;
 ;----------------------------------------------------;
	
check_bcd_date:
	cmp   al,bl
	ja    date_error
	and   al,0Fh
	cmp   al,9
	ja    date_error
	ret
 ;----------------------------------------------------;
 ; checks it a bcd number time                        ;
 ;----------------------------------------------------;

check_bcd_time:
        cmp   al,bl
	ja    time_error
	and   al,0Fh
	cmp   al,9
	ja    time_error
	ret

val:       dw 0,0

hour:      db 0
minute:    db 0
second:    db 0

century:   db 0
year:      db 0
month:     db 0
day:       db 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -