home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CTASK22.ZIP / TSKBIOS.ASM < prev    next >
Assembly Source File  |  1990-10-12  |  6KB  |  267 lines

  1. ;
  2. ;    --- Version 2.2 90-10-12 10:37 ---
  3. ;
  4. ;    CTask - BIOS INT 15 interrupt handler (IBM AT specific)
  5. ;
  6. ;    Public Domain Software written by
  7. ;        Thomas Wagner
  8. ;        Ferrari electronic Gmbh
  9. ;        Beusselstrasse 27
  10. ;        D-1000 Berlin 21
  11. ;        Germany
  12. ;
  13. ;    NOTE:   Support for printer output busy has been dropped in
  14. ;        version 1.2. Depending on the speed of the driving
  15. ;        program, the old algorithm (which used a timed delay)
  16. ;        could cause the printer to slow down to an unbearable
  17. ;        crawl, and there is little chance for a clean solution
  18. ;        here, since there is not enough info on the printer
  19. ;        passed to INT 15.
  20. ;        Instead, an INT 17 replacement that schedules while 
  21. ;        waiting on the printer has been added (module tskint17.asm).
  22. ;
  23. ;    CAUTION: This module can only be installed in the primary kernel.
  24. ;         It is not ROMable.
  25. ;
  26.     name    tskbios
  27. ;
  28.     include    tsk.mac
  29. ;
  30.     .tsk_model
  31. ;
  32.     Pubfunc    tsk_install_bios
  33.     Pubfunc    tsk_remove_bios
  34. ;
  35.     Globext    clear_flag
  36.     Globext    wait_flag_set
  37.     Globext    set_flag
  38.         Globext    create_flag
  39.         Globext    delete_flag
  40.         Globext    t_delay
  41.     Locext    tsk_switch_stack
  42. ;
  43.     extrn    tsk_glob_rec: word    ; global_rec
  44. ;
  45. ;
  46. intseg    segment at 0
  47. ;
  48.         org    15h*4
  49. pintofs        dw    ?        ; interrupt entry
  50. pintseg        dw    ?
  51.  
  52. intseg    ends
  53. ;
  54. ;
  55.     .tsk_data
  56. ;
  57. floppy  flag    <>
  58. fdisk   flag    <>
  59. kbd     flag    <>
  60. ;
  61. flag_tab    label    word
  62.     dw    offset fdisk
  63.     dw    offset floppy
  64.     dw    offset kbd
  65. ;
  66.     IF    TSK_NAMEPAR
  67. fflname    db    "WFLEXDSK",0
  68. ffdname    db    "WHARDDSK",0
  69. fkbname    db    "WKBDPOST",0
  70.     ENDIF
  71. ;
  72.     .tsk_edata
  73.     .tsk_code
  74. ;
  75. ;
  76. post_save    label    dword        ; in CSEG to allow addressing
  77. psofs        dw    ?
  78. psseg        dw    ?
  79. ;
  80. ;----------------------------------------------------------------------
  81. ;
  82. ;    interrupt handler
  83. ;
  84. @bios_int    proc    far
  85.         pushf
  86.     sti
  87.         cmp     ah,90h            ; WAIT
  88.         jb      bios_pass
  89.         cmp     ah,91h            ; POST
  90.         ja    bios_pass
  91.     cmp    al,2            ; fdisk/floppy/keyboard
  92.         jbe    process_bios
  93.     cmp    al,0fdh            ; floppy motor
  94.         je    process_bios
  95. ;
  96. bios_pass:
  97.     popf
  98.     jmp    cs:post_save
  99. ;
  100. ;
  101. process_bios:
  102.     popf
  103.     call    tsk_switch_stack
  104.     stc_saved            ; Carry set on return
  105. ;
  106.     cmp    al,2
  107.     jbe    flag_ops
  108. ;
  109. ;    Wait for diskette motor start (1 sec.)
  110. ;
  111. wait_motor:
  112.     IF    CLOCK_MSEC
  113.     callp    t_delay,<<0,1000>>
  114.     ELSE
  115.     callp    t_delay,<<0,tsk_glob_rec.ticks_per_sec>>
  116.     ENDIF
  117.     iret
  118. ;
  119. ;    Floppy/Fdisk/Keyboard wait/post
  120. ;
  121. flag_ops:
  122.     xor    bh,bh
  123.     mov    bl,al    
  124.     add    bx,bx
  125.     mov    bx,flag_tab[bx]        ; load appropriate flag
  126.     cmp    ah,90h
  127.     je    fl_wait            ; jump if wait op
  128.     callp    set_flag,<<ds,bx>>    ; set flag: complete
  129.     clc_saved            ; carry clear on return
  130.     iret
  131. ;
  132. ; Note: Version 2.1 includes the following fix provided by S. Worthington:
  133. ;
  134. ; When using a very fast hard disk controller (especially one with
  135. ; onboard cache or the new AT bus type controllers), it is possible to
  136. ; get the hard disk ready interrupt "posted" BEFORE the call to "wait"
  137. ; reaches the "call clear_flag_wait_set"  instruction.  This results in
  138. ; a long disk timeout and an error return.  The fix is to use a
  139. ; "wait_flag_set" followed by a "clear_flag" to replace the
  140. ; "clear_flag_wait_set".  Even though there is still a gap between the
  141. ; wait and clear, it is not possible to get a "post" in this gap since
  142. ; "upper_dos" is still locked, preventing the start of a new disk I/O.
  143. ;    
  144. fl_wait:
  145.     xor    dx,dx
  146.     cmp    al,2
  147.     je    fl_dowait        ; no timeout if AL=2 (Keyboard)
  148.     IF    CLOCK_MSEC
  149.     mov    dx,1000
  150.     ELSE
  151.     mov    dx,tsk_glob_rec.ticks_per_sec
  152.     ENDIF
  153.     add    dx,dx            ; two seconds
  154.     cmp    al,1
  155.     je    fl_dowait        ; 2 sec timeout if AL=1 (Diskette)
  156.     mov    cx,dx
  157.     add    dx,cx
  158.     add    dx,cx            ; 6 sec timeout for Harddisk
  159. fl_dowait:
  160.     push    bx
  161.     callp    wait_flag_set,<<ds,bx>,<0,dx>> ; Wait for event
  162.     or    ax,ax
  163.     jnz    flw_ret            ; keep carry set if timeout
  164.     clc_saved            ; else return with carry clear
  165. flw_ret:
  166.     pop    bx
  167.     callp    clear_flag,<<ds,bx>>
  168.     iret
  169. ;
  170. @bios_int       endp
  171. ;
  172. ;------------------------------------------------------------------------
  173. ;
  174. ;    void far tsk_remove_bios (void)
  175. ;
  176. ;    This routine un-installs the int handler.
  177. ;
  178. Localfunc tsk_remove_bios
  179. ;
  180.     IFDEF    LOAD_DS
  181.     push    ds
  182.     mov    ax,@CTASK_DATA
  183.     mov    ds,ax
  184.     ENDIF
  185. ;
  186.     push    es
  187.     xor    ax,ax
  188.     mov    es,ax
  189.     assume    es:intseg
  190.         cli
  191.     mov    ax,cs:psofs        ; restore vector
  192.     mov    pintofs,ax
  193.     mov    ax,cs:psseg
  194.     mov    pintseg,ax
  195.         sti
  196.     assume    es:nothing
  197.     pop    es
  198. ;
  199.         callp   delete_flag,<<ds,#floppy>>
  200.         callp   delete_flag,<<ds,#fdisk>>
  201.         callp   delete_flag,<<ds,#kbd>>
  202. ;
  203.     IFDEF    LOAD_DS
  204.     pop    ds
  205.     ENDIF
  206.         ret
  207. ;
  208. tsk_remove_bios    endp
  209. ;
  210. ;----------------------------------------------------------------------
  211. ;
  212. ;    void far tsk_install_bios (void)
  213. ;
  214. ;    This routine installs the int handler.
  215. ;
  216. Localfunc tsk_install_bios
  217. ;
  218.     IFDEF    LOAD_DS
  219.     push    ds
  220.     mov    ax,@CTASK_DATA
  221.     mov    ds,ax
  222.     ENDIF
  223. ;
  224.     IF    TSK_NAMEPAR
  225.         callp   create_flag,<<ds,#floppy>,<ds,#fflname>>
  226.     ELSE
  227.         callp   create_flag,<<ds,#floppy>>
  228.     ENDIF
  229. ;
  230.     IF    TSK_NAMEPAR
  231.         callp   create_flag,<<ds,#fdisk>,<ds,#ffdname>>
  232.     ELSE
  233.         callp   create_flag,<<ds,#fdisk>>
  234.     ENDIF
  235. ;
  236.     IF    TSK_NAMEPAR
  237.         callp   create_flag,<<ds,#kbd>,<ds,#fkbname>>
  238.     ELSE
  239.         callp   create_flag,<<ds,#kbd>>
  240.     ENDIF
  241. ;
  242.         push    es
  243.     xor    ax,ax
  244.     mov    es,ax            ; establish addressing for intseg
  245.     assume    es:intseg
  246. ;
  247.     mov    ax,pintofs        ; save old timer int addr
  248.     mov    psofs,ax
  249.     mov    ax,pintseg
  250.     mov    psseg,ax
  251.     cli
  252.     mov    pintofs,offset @bios_int ; set new timer int addr
  253.     mov    pintseg,cs
  254.     sti
  255.     assume    es:nothing
  256.         pop     es
  257.     IFDEF    LOAD_DS
  258.     pop    ds
  259.     ENDIF
  260.     ret
  261. ;
  262. tsk_install_bios    endp
  263. ;
  264.     .tsk_ecode
  265.     end
  266.  
  267.