home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / ATTIBM.ZIP / G-CLOCK$.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-02-07  |  9.4 KB  |  302 lines

  1. page 55,132
  2. title G-CLOCK$ -- Generic CLOCK$ Device Driver   RKB    86/02/05.
  3. ;
  4. ;    Written by Robert K. Blaine/ECONO-SOFT; CompuServe [73267,1664].
  5. ;               5 February 1986.
  6. ;    This driver is not copyrighted and may be freely copied and distributed.
  7. ;
  8. ;    Install a generic CLOCK$ driver to allow DATE and TIME to work normally
  9. ;    on DOS implementations that depend on a specific clock/calendar chip
  10. ;    being present in the hardware. Most notably, AT&T DOS 2.0 (an
  11. ;    implementation of MS-DOS 2.11).
  12. ;
  13. ;    Assemble (MASM v3.0), LINK, and EXE2BIN => G-CLOCK$.DEV
  14. ;
  15. ;    (I apologize for the bulk of this code being uncommented.)
  16. ;
  17. ;    Modification History:
  18. ;    ============ =======
  19. ;    Date      Name            Description
  20. ;    ----      ----            -----------
  21. ;    86/02/05  Robert Blaine   Initial version.
  22. ;
  23. cseg          segment para public 'CODE'
  24. ;
  25. ;
  26. ;               macro definitions
  27. ;
  28. status        macro    state,err,rc
  29.               ifidn    <state>,<done>
  30.                 or     es:word ptr rh_status[bx],0100h
  31.               endif
  32.               ifidn    <state>,<busy>
  33.                 or     es:word ptr rh_status[bx],0200h
  34.               endif
  35.               ifidn    <err>,<error>
  36.                 or     es:word ptr rh_status[bx],1000h
  37.               endif
  38.               ifnb     <rc>
  39.                 or     es:word ptr rh_status[bx],rc
  40.               endif
  41.               endm
  42. ;
  43. ; request header definitions
  44. ;
  45. rh_len        equ      0                    ;length
  46. rh_unit_code  equ      1
  47. rh_command    equ      2
  48. rh_status     equ      3
  49.  
  50. rh_n_units    equ      13                   ;*init* only
  51. rh_end_ofs    equ      14                   ; "
  52. rh_end_seg    equ      16                   ; "
  53. rh_bpb_addr   equ      18                   ; "
  54.  
  55. rh_md         equ      13
  56. rh_media_rtn  equ      14                   ;*media check* only
  57.  
  58. rh_dta        equ      14
  59.  
  60. rh_byte_sect  equ      18                   ;*input*/*output*
  61. rh_start_sect equ      19
  62.  
  63. rh_byte_rtn   equ      13                   ;*non-destructive input* only
  64.  
  65. ;
  66. g_clock       proc     far
  67.               assume   cs:cseg,es:cseg,ds:cseg
  68. begin:
  69. ;
  70. ; special device header
  71. ;
  72. next_dev      dd       -1          ;pointer to next device
  73. attribute     dw       8008h       ;character device: CLOCK$
  74. stategy       dw       dev_strat   ;pointer to device stategy
  75. interrupt     dw       dev_int     ;pointer to device interrupt handler
  76. dev_name      db       'CLOCK$  '  ;name of device
  77. rh_off        dw       0           ;request header offset
  78. rh_seg        dw       0           ;request header segment
  79. days_past     dw       0           ;number of days since 1-1-1980
  80. err_return    db       0           ;error return flag
  81. ;
  82. ; function table
  83. ;
  84. funtab        label    byte
  85.               dw       init        ;initialization
  86.               dw       media_check ;media check (block only)
  87.               dw       build_bpb   ;build bpb
  88.               dw       ioctl_in    ;ioctl input
  89.               dw       input       ;input (read)
  90.               dw       nd_input    ;non destructive input no wait (ch only)
  91.               dw       in_stat     ;input status
  92.               dw       in_flush    ;input flush
  93.               dw       output      ;output (write)
  94.               dw       out_verify  ;output (write) with verify
  95.               dw       out_stat    ;output status
  96.               dw       out_flush   ;output flush
  97.               dw       ioctl_out   ;ioctl output
  98.  
  99. ;
  100. ; the following functions are not supported by this device
  101. ;
  102. media_check:
  103. build_bpb:
  104. ioctl_in:
  105. ioctl_out:
  106. nd_input:                          ;non destructive input no wait (ch only)
  107. in_stat:                           ;input status      "     "
  108. in_flush:                          ;input flush
  109. out_stat:                          ;output status
  110. out_flush:                         ;output flush
  111.               mov      err_return,1
  112.               status   0,error,3
  113.               jmp      exit
  114.  
  115. ;
  116. ; device strategy
  117. ;
  118. dev_strat:    mov      cs:rh_seg,es ;save segment of request header ptr
  119.               mov      cs:rh_off,bx ;save offset of     "      "     "
  120.               ret                   ;only one request allowed at a time
  121. ;
  122. ; device interrupt handler
  123. ;
  124. dev_int:      cld
  125. ;
  126. ; save state of machine
  127. ;
  128.               push     ds
  129.               push     es
  130.               push     ax
  131.               push     bx
  132.               push     cx
  133.               push     dx
  134.               push     di
  135.               push     si
  136. ;
  137. ; do branch according to function passed
  138. ;
  139.               push     cs
  140.               pop      ds
  141.               les      bx,dword ptr rh_off   ;ES:BX has request header
  142.  
  143.               mov      err_return,0          ;1 iff error detected
  144.  
  145.               mov      al,es:rh_command[bx]  ;get function byte
  146.               rol      al,1                  ;get offset into table
  147.               lea      di,funtab             ;get address of function table
  148.               xor      ah,ah
  149.               add      di,ax
  150.               jmp      word ptr[di]
  151.  
  152. ;
  153. ; CLOCK$ read
  154. ;
  155. input:
  156.               xor      ah,ah
  157.               int      1Ah                  ;get BIOS time: AL=wrap flag;
  158. ;                                           ;CX=clock high (HC);
  159. ;                                           ;DX=clock low (LC)
  160.               cmp      al,0
  161.                 jz       no_wrap            ;if day has not wrapped
  162.               inc      days_past
  163. no_wrap:
  164.               mov      ax,cx                ;HC
  165.               mov      bx,dx                ;LC
  166.               shl      dx,1                 ;LC * 2
  167.               rcl      cx,1                 ;HC rot 1
  168.               shl      dx,1                 ;LC * 4
  169.               rcl      cx,1                 ;HC rot 2
  170.               add      dx,bx                ;LC * 5
  171.               adc      ax,cx                ;
  172.               xchg     dx,ax
  173.               mov      cx,0E90Bh
  174.               div      cx
  175.               mov      bx,ax
  176.               xor      ax,ax
  177.               div      cx
  178.               mov      dx,bx
  179.               mov      cx,0C8h
  180.               div      cx
  181.               cmp      dl,100
  182.                 jb       l1
  183.               sub      dl,100
  184. l1:
  185.               cmc
  186.               mov      bl,dl
  187.               rcl      ax,1
  188.               mov      dl,0
  189.               rcl      dx,1
  190.               mov      cx,60
  191.               div      cx
  192.               mov      bh,dl
  193.               div      cl
  194.               xchg     ah,al
  195.               push     bx
  196.               push     ax
  197.  
  198.               les      bx,dword ptr rh_off  ;ES:BX has request header
  199.               les      di,es:rh_dta[bx]     ;ES:DI has user DTA
  200.               mov      ax,days_past
  201.               stosw
  202.               pop      ax
  203.               stosw
  204.               pop      ax
  205.               stosw
  206.               jmp      exit
  207.  
  208. ;
  209. ; CLOCK$ write
  210. ;
  211. output:
  212. out_verify:
  213.               lds      si,es:rh_dta[bx]     ;DS:SI has user DTA
  214.               lodsw
  215.               push     ax
  216.               lodsw
  217.               mov      cx,ax
  218.               lodsw
  219.               mov      dx,ax
  220.               push     cs
  221.               pop      ds
  222.  
  223.               mov      al,60
  224.               mul      ch
  225.               mov      ch,0
  226.               add      ax,cx
  227.               mov      cx,6000
  228.               mov      bx,dx
  229.               mul      cx
  230.               mov      cx,ax
  231.               mov      al,100
  232.               mul      bh
  233.               add      cx,ax
  234.               adc      dx,0
  235.               mov      bh,0
  236.               add      cx,bx
  237.               adc      dx,0
  238.               xchg     dx,ax
  239.               xchg     cx,ax
  240.               mov      bx,0E90Bh
  241.               mul      bx
  242.               xchg     cx,dx
  243.               xchg     dx,ax
  244.               mul      bx
  245.               add      ax,cx
  246.               adc      dx,0
  247.               xchg     dx,ax
  248.               mov      bx,5
  249.               div      bl
  250.               mov      cl,al
  251.               mov      ch,0
  252.               mov      al,ah
  253.               cbw
  254.               xchg     dx,ax
  255.               div      bx
  256.               mov      dx,ax
  257.               cli
  258.               mov      ah,1
  259.               int      1Ah
  260.               pop      days_past
  261.               sti
  262.  
  263. ;             jmp      exit                 ;*** enable jump if code added ***
  264. ;
  265. ; common exit
  266. ;
  267. exit:
  268.               les      bx,dword ptr cs:rh_off ;restore ES:BX to req header
  269.               cmp      cs:err_return,0
  270.                 jne      exit_0               ;if error return
  271.  
  272.               status   done,noerror           ;set status done (noerror)
  273.  
  274. exit_0:                                       ;enter here if error return
  275.               pop      si
  276.               pop      di
  277.               pop      dx
  278.               pop      cx
  279.               pop      bx
  280.               pop      ax
  281.               pop      es
  282.               pop      ds
  283.               ret
  284. ;
  285. ; the end of the resident portion -- remainder will be overlaid.
  286. ;
  287. res_end:
  288. ;
  289. ; CLOCK$ init -- set resident size and return
  290. ;
  291. init:
  292.               mov      word ptr es:rh_end_ofs [bx],offset res_end
  293.               mov      word ptr es:rh_end_seg [bx],cs
  294.               jmp      exit
  295.  
  296.               db       'Written by Robert K. Blaine/ECONO-SOFT.'
  297.               db       'CompuServe [73267,1664]'
  298.  
  299. g_clock       endp
  300. cseg          ends
  301.               end      begin
  302.