.MODEL TINY .CODE ORG 100H ;from realdate.com ;v1.0 1999.03.14 realdate 1st version. No command line switches ;v1.1 2004.07.19-21 added switches and their features ;v1.11 2004.07.26 corrected help start: call startsrchpars_new ;see switches mov al,[swall] and al,00111100b or al,al ;if no text, no format, no time, no date specified jne start1 or [swall],8 ;set default to print or [swall],64 ;set default to eol mov ax,offset t_str mov [text],ax start1: test [swall],2 jz getdate mov dx,OFFSET help call print jmp vege getdate:test [swall],1 jz getdos call gd_cmos ;get date from cmos jmp fformat getdos: call gd_dos ;get date from dos fformat:mov si,offset f_full test [swall],4 jz chk_16 mov si,[f_format] chk_16: test [swall],16 jz chk_32 mov si,offset f_date chk_32: test [swall],32 jz chk_doformat mov si,offset f_time chk_doformat: mov [f_format],si dec si subs: inc si cmp [si],"CC" jne subs_y mov ax,[date_y1] mov [si],ax subs_y: cmp [si],"YY" jne subs_m mov ax,[date_y2] mov [si],ax subs_m: cmp [si],"MM" jne subs_d mov ax,[date_mm] mov [si],ax subs_d: cmp [si],"DD" jne subs_h mov ax,[date_dd] mov [si],ax subs_h: cmp [si],"hh" jne subs_p mov ax,[time_hh] mov [si],ax subs_p: cmp [si],"mm" jne subs_s mov ax,[time_mm] mov [si],ax subs_s: cmp [si],"ss" jne subs_0 mov ax,[time_ss] mov [si],ax subs_0: cmp byte ptr [si],0 jne subs ;Display text if needed test [swall],8 jz chk_format mov si,[text] call writesi0 ;display date format chk_format: mov si,[f_format] call writesi0 test [swall],64 jz chk_end mov dx,offset t_eol call print chk_end:ret ;------------- gd_cmos:call check or al,al jne error2 ;CMOS UIP in Process ; mov dx,OFFSET prt ; call prn ;year mov al,32h call read mov [date_y1],ax mov al,9 call read mov [date_y2],ax mov al,8 call read mov [date_mm],ax mov al,7 call read mov [date_dd],ax ;time mov al,4 call read mov [time_hh],ax mov al,2 call read mov [time_mm],ax mov al,0 call read mov [time_ss],ax ret error2: jmp error1 ;--- DOSGetDate: ;INT 21,2A - Get Date ; AL = day of the week (0=Sunday) ; CX = year (1980-2099) ; DH = month (1-12) ; DL = day (1-31) gd_dos: mov ah,2ah int 21h push dx push dx push cx pop ax call hex2bcd push ax xchg ah,al call conval mov [date_y1],ax pop ax call conval mov [date_y2],ax pop ax xchg al,ah xor ah,ah call hex2bcd call conval mov [date_mm],ax pop ax xor ah,ah call hex2bcd call conval mov [date_dd],ax mov ah,2ch int 21h push dx push cx push cx pop ax xchg al,ah xor ah,ah call hex2bcd call conval mov [time_hh],ax pop ax xor ah,ah call hex2bcd call conval mov [time_mm],ax pop ax xchg al,ah xor ah,ah call hex2bcd call conval mov [time_ss],ax ret ; ;INT 21,2C - Get Time ; CH = hour (0-23) ; CL = minutes (0-59) ; DH = seconds (0-59) ; DL = hundredths (0-99) ;--- check: mov cx,1168h nop nop nop chk: cli jmp $+2 mov al,0ah out 70h,al jmp $+2 jmp $+2 jmp $+2 in al,71h jmp $+2 and al,80h je elore loop chk elore: ret read: out 70h,al jmp $+2 jmp $+2 jmp $+2 in al,71h call conval ret conval: mov ah,al mov cl,4 sar al,cl and ax,0F0Fh cmp al,0Ah jb c1 add al,7 c1: cmp ah,0Ah jb c2 add ah,7 c2: add ax,3030h ret ;Converts ax to BCD ; eg: ax=07C4 => ax=1988 ;----------------------------------------- hex2bcd:push cx push dx mov si,OFFSET stbuff mov cx,1000 ;alap st16_2: xor dx,dx div cx ;ax/4096 mov [si],al inc si push dx xor dx,dx mov ax,cx mov cx,10 ;oszto div cx mov cx,ax pop ax or cx,cx jnz st16_2 mov ax,[stbuff] mov cx,4 shl al,cl or ah,al mov bx,[stbuff+2] shl bl,cl or bl,bh mov al,bl pop dx pop cx ret stbuff dw 0,0 ;---------------------------------- writesi0: mov al,[si] cmp al,0 je wr_end call write inc si jmp writesi0 write: mov ah,06h mov dl,al int 21h ;DOS output 1 char wr_end: ret error1: mov dx,OFFSET uip print: mov ax,0900h int 21h ret vege: int 20h f_full db 'CCYY.MM.DD hh:mm:ss',0 f_date db 'CCYYMMDD',0 f_time db 'hhmmss',0 t_str db 'Current date/time: ',0 t_eol db 13,10,'$' uip db 'CMOS Error',13,10,'$' help db 'REALDATE v1.11 - (c) 2004 MAQUES Software Ltd.',13,10 db ' http://www.huweb.hu/maques/realdate.htm',13,10 db 'usage: realdate [/s="string to display first" [/f | /d | /t] /c /e /?]',13,10 db ' /s - string within two separators (avoid "/"-s...)',13,10 db ' /f - format string: default /f="CCYY.MM.DD hh:mm:ss"',13,10 db ' /d - date only = /f="CCYYMMDD" and /s="" if not specified',13,10 db ' /t - time only = /f="hhmmss" and /s="" if not specified',13,10 db ' /c - use CMOS to get date and time (default: use DOS)',13,10 db ' /e - add CR/LF (default: no EOL if /d, /t, /s or /f specified)',13,10 db ' /? - display this help',13,10 db 'defaults: /s="Current date/time: " /f="CCYY.MM.DD hh:mm:ss" /e',13,10,'$' ;--- startsrchpars_new: ;parameter kollektor xor cx,cx mov si,OFFSET param1 mov di,81h srchp2: mov al,[di] cmp al,13 je srchpv cmp al,32 je srchp1 mov [si],di inc cx inc si inc si srchp3: inc di mov al,[di] cmp al,13 je srchpv cmp al,32 jne srchp3 srchp1: ; mov byte ptr [di],0 inc di jmp srchp2 srchpv: mov byte ptr [di],0 mov [params],cx or cx,cx ;zero param line? jne srcev1 ret srcev2: mov si,OFFSET param1 mov cx,[params] srcev2a:mov di,[si] cmp [di],ax je srcev2y inc si inc si loop srcev2a clc ret srcev2y:add di,2 stc ret ;------------------------ srcev1: mov ax,'c/' ;/c - use CMOS call srcev2 jnc sr2 ;fatal, no serial or [swall],1 sr2: mov ax,'f/' ;format string call srcev2 jnc sr3 inc di mov al,[di] inc di mov [f_format],di dec di or [swall],4 sr2a: inc di cmp [di],al je sr2e cmp byte ptr [di],0 jne sr2a sr2e: mov byte ptr [di],0 ;asciiz sr3: mov ax,'s/' ;display text before call srcev2 jnc sr4 inc di mov al,[di] inc di mov [text],di dec di or [swall],8 sr3a: inc di cmp [di],al je sr3e cmp byte ptr [di],0 jne sr3a sr3e: mov byte ptr [di],0 ;asciiz sr4: mov ax,'d/' ;/d - simple date format call srcev2 jnc sr5 or [swall],16 sr5: mov ax,'t/' ;/t - simple time format call srcev2 jnc sr6 or [swall],32 sr6: mov ax,'e/' ;/e - display eol too call srcev2 jnc sr7 or [swall],64 sr7: mov ax,'?/' ;/? - display help call srcev2 jnc sr8 or [swall],2 sr8: ret date_y1 dw 0 date_y2 dw 0 date_mm dw 0 date_dd dw 0 time_hh dw 0 time_mm dw 0 time_ss dw 0 ;0000tphc swall db 0 ; 1=cmos, 2=help, 4=format, 8=text before, 16=simple date, 32=simple time, 64=eol f_format dw 0 ; format text dw OFFSET t_str ; text params dw 0 ; params at command line param1 dw 0 ; END start