home *** CD-ROM | disk | FTP | other *** search
- page 55,132
- title G-CLOCK$ -- Generic CLOCK$ Device Driver RKB 86/02/05.
- ;
- ; Written by Robert K. Blaine/ECONO-SOFT; CompuServe [73267,1664].
- ; 5 February 1986.
- ; This driver is not copyrighted and may be freely copied and distributed.
- ;
- ; Install a generic CLOCK$ driver to allow DATE and TIME to work normally
- ; on DOS implementations that depend on a specific clock/calendar chip
- ; being present in the hardware. Most notably, AT&T DOS 2.0 (an
- ; implementation of MS-DOS 2.11).
- ;
- ; Assemble (MASM v3.0), LINK, and EXE2BIN => G-CLOCK$.DEV
- ;
- ; (I apologize for the bulk of this code being uncommented.)
- ;
- ; Modification History:
- ; ============ =======
- ; Date Name Description
- ; ---- ---- -----------
- ; 86/02/05 Robert Blaine Initial version.
- ;
- cseg segment para public 'CODE'
- ;
- ;
- ; macro definitions
- ;
- status macro state,err,rc
- ifidn <state>,<done>
- or es:word ptr rh_status[bx],0100h
- endif
- ifidn <state>,<busy>
- or es:word ptr rh_status[bx],0200h
- endif
- ifidn <err>,<error>
- or es:word ptr rh_status[bx],1000h
- endif
- ifnb <rc>
- or es:word ptr rh_status[bx],rc
- endif
- endm
- ;
- ; request header definitions
- ;
- rh_len equ 0 ;length
- rh_unit_code equ 1
- rh_command equ 2
- rh_status equ 3
-
- rh_n_units equ 13 ;*init* only
- rh_end_ofs equ 14 ; "
- rh_end_seg equ 16 ; "
- rh_bpb_addr equ 18 ; "
-
- rh_md equ 13
- rh_media_rtn equ 14 ;*media check* only
-
- rh_dta equ 14
-
- rh_byte_sect equ 18 ;*input*/*output*
- rh_start_sect equ 19
-
- rh_byte_rtn equ 13 ;*non-destructive input* only
-
- ;
- g_clock proc far
- assume cs:cseg,es:cseg,ds:cseg
- begin:
- ;
- ; special device header
- ;
- next_dev dd -1 ;pointer to next device
- attribute dw 8008h ;character device: CLOCK$
- stategy dw dev_strat ;pointer to device stategy
- interrupt dw dev_int ;pointer to device interrupt handler
- dev_name db 'CLOCK$ ' ;name of device
- rh_off dw 0 ;request header offset
- rh_seg dw 0 ;request header segment
- days_past dw 0 ;number of days since 1-1-1980
- err_return db 0 ;error return flag
- ;
- ; function table
- ;
- funtab label byte
- dw init ;initialization
- dw media_check ;media check (block only)
- dw build_bpb ;build bpb
- dw ioctl_in ;ioctl input
- dw input ;input (read)
- dw nd_input ;non destructive input no wait (ch only)
- dw in_stat ;input status
- dw in_flush ;input flush
- dw output ;output (write)
- dw out_verify ;output (write) with verify
- dw out_stat ;output status
- dw out_flush ;output flush
- dw ioctl_out ;ioctl output
-
- ;
- ; the following functions are not supported by this device
- ;
- media_check:
- build_bpb:
- ioctl_in:
- ioctl_out:
- nd_input: ;non destructive input no wait (ch only)
- in_stat: ;input status " "
- in_flush: ;input flush
- out_stat: ;output status
- out_flush: ;output flush
- mov err_return,1
- status 0,error,3
- jmp exit
-
- ;
- ; device strategy
- ;
- dev_strat: mov cs:rh_seg,es ;save segment of request header ptr
- mov cs:rh_off,bx ;save offset of " " "
- ret ;only one request allowed at a time
- ;
- ; device interrupt handler
- ;
- dev_int: cld
- ;
- ; save state of machine
- ;
- push ds
- push es
- push ax
- push bx
- push cx
- push dx
- push di
- push si
- ;
- ; do branch according to function passed
- ;
- push cs
- pop ds
- les bx,dword ptr rh_off ;ES:BX has request header
-
- mov err_return,0 ;1 iff error detected
-
- mov al,es:rh_command[bx] ;get function byte
- rol al,1 ;get offset into table
- lea di,funtab ;get address of function table
- xor ah,ah
- add di,ax
- jmp word ptr[di]
-
- ;
- ; CLOCK$ read
- ;
- input:
- xor ah,ah
- int 1Ah ;get BIOS time: AL=wrap flag;
- ; ;CX=clock high (HC);
- ; ;DX=clock low (LC)
- cmp al,0
- jz no_wrap ;if day has not wrapped
- inc days_past
- no_wrap:
- mov ax,cx ;HC
- mov bx,dx ;LC
- shl dx,1 ;LC * 2
- rcl cx,1 ;HC rot 1
- shl dx,1 ;LC * 4
- rcl cx,1 ;HC rot 2
- add dx,bx ;LC * 5
- adc ax,cx ;
- xchg dx,ax
- mov cx,0E90Bh
- div cx
- mov bx,ax
- xor ax,ax
- div cx
- mov dx,bx
- mov cx,0C8h
- div cx
- cmp dl,100
- jb l1
- sub dl,100
- l1:
- cmc
- mov bl,dl
- rcl ax,1
- mov dl,0
- rcl dx,1
- mov cx,60
- div cx
- mov bh,dl
- div cl
- xchg ah,al
- push bx
- push ax
-
- les bx,dword ptr rh_off ;ES:BX has request header
- les di,es:rh_dta[bx] ;ES:DI has user DTA
- mov ax,days_past
- stosw
- pop ax
- stosw
- pop ax
- stosw
- jmp exit
-
- ;
- ; CLOCK$ write
- ;
- output:
- out_verify:
- lds si,es:rh_dta[bx] ;DS:SI has user DTA
- lodsw
- push ax
- lodsw
- mov cx,ax
- lodsw
- mov dx,ax
- push cs
- pop ds
-
- mov al,60
- mul ch
- mov ch,0
- add ax,cx
- mov cx,6000
- mov bx,dx
- mul cx
- mov cx,ax
- mov al,100
- mul bh
- add cx,ax
- adc dx,0
- mov bh,0
- add cx,bx
- adc dx,0
- xchg dx,ax
- xchg cx,ax
- mov bx,0E90Bh
- mul bx
- xchg cx,dx
- xchg dx,ax
- mul bx
- add ax,cx
- adc dx,0
- xchg dx,ax
- mov bx,5
- div bl
- mov cl,al
- mov ch,0
- mov al,ah
- cbw
- xchg dx,ax
- div bx
- mov dx,ax
- cli
- mov ah,1
- int 1Ah
- pop days_past
- sti
-
- ; jmp exit ;*** enable jump if code added ***
- ;
- ; common exit
- ;
- exit:
- les bx,dword ptr cs:rh_off ;restore ES:BX to req header
- cmp cs:err_return,0
- jne exit_0 ;if error return
-
- status done,noerror ;set status done (noerror)
-
- exit_0: ;enter here if error return
- pop si
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- pop es
- pop ds
- ret
- ;
- ; the end of the resident portion -- remainder will be overlaid.
- ;
- res_end:
- ;
- ; CLOCK$ init -- set resident size and return
- ;
- init:
- mov word ptr es:rh_end_ofs [bx],offset res_end
- mov word ptr es:rh_end_seg [bx],cs
- jmp exit
-
- db 'Written by Robert K. Blaine/ECONO-SOFT.'
- db 'CompuServe [73267,1664]'
-
- g_clock endp
- cseg ends
- end begin