home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / CTASK11.ZIP / TSKBIOS.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-07-01  |  4.7 KB  |  302 lines

  1. ;
  2. ;    CTask - BIOS INT 15 interrupt handler (IBM AT specific)
  3. ;
  4. ;    Public Domain Software written by
  5. ;        Thomas Wagner
  6. ;        Patschkauer Weg 31
  7. ;        D-1000 Berlin 33
  8. ;        West Germany
  9. ;
  10.     name    tskbios
  11.     .model    large
  12. ;
  13.     public    _tsk_install_bios
  14.     public    _tsk_remove_bios
  15. ;
  16.     include    tsk.mac
  17. ;
  18. intseg    segment at 0
  19. ;
  20.         org    15h*4
  21. pintofs        dw    ?        ; interrupt entry
  22. pintseg        dw    ?
  23.  
  24. intseg    ends
  25. ;
  26. ;
  27.     .data?
  28. ;
  29.     extrn    _ticks_per_sec: word
  30. ;
  31. floppy  flag    <>
  32. fdisk   flag    <>
  33. kbd     flag    <>
  34. ;
  35.     .data
  36. ;
  37. flag_tab    label    word
  38.     dw    offset fdisk
  39.     dw    offset floppy
  40.     dw    offset kbd
  41. ;
  42.     IF    TSK_NAMEPAR
  43. fflname    db    "FLOPPY",0
  44. ffdname    db    "HARDDISK",0
  45. fkbname    db    "KBDPOST",0
  46.     ENDIF
  47. ;
  48.     .code
  49. ;
  50.     extrn    _clear_flag_wait_set: far
  51.     extrn    _set_flag: far
  52.         extrn   _create_flag: far
  53.         extrn   _delete_flag: far
  54.         extrn   _t_delay: far
  55. ;
  56. post_save    label    dword        ; in CSEG to allow addressing
  57. psofs        dw    ?
  58. psseg        dw    ?
  59. ;
  60. ;----------------------------------------------------------------------
  61. ;
  62. ;    interrupt handler
  63. ;
  64. bios_int    proc    far
  65.         pushf
  66.     sti
  67.         cmp     ah,90h            ; WAIT
  68.         jb      bios_pass
  69.         cmp     ah,91h            ; POST
  70.         ja    bios_pass
  71.     cmp    al,2            ; fdisk/floppy/keyboard
  72.         jbe    process_bios
  73.     cmp    ah,91h
  74.     je    bios_pass
  75.     cmp    al,0fdh            ; floppy motor
  76.     jb    bios_pass
  77.     cmp    al,0feh            ; printer
  78.         jbe    process_bios
  79. ;
  80. bios_pass:
  81.     popf
  82.     jmp    cs:post_save
  83. ;
  84. process_bios:
  85.     popf
  86.     sti
  87.     push    es
  88.     push    ds
  89.     push    dx
  90.     push    cx
  91.     push    bx
  92.     push    ax
  93.     mov    bx,SEG dgroup
  94.     mov    ds,bx
  95.     mov    es,bx
  96. ;
  97.     cmp    al,2
  98.     jbe    flag_ops
  99. ;
  100.     cmp    al,0fdh
  101.     je    wait_motor
  102. ;
  103. ;    wait for printer ready.
  104. ;    delay for some ticks, then check printer.
  105. ;    CAUTION: this assumes the BIOS is *truly* AT compatible,
  106. ;         with the printer port address in DX on entry to INT15.
  107. ;
  108. wait_prn:
  109.     push    dx
  110.     mov    ax,3
  111.     push    ax
  112.     xor    ax,ax
  113.     push    ax
  114.     call    _t_delay
  115.     add    sp,4
  116.     pop    dx    
  117.     in    al,dx
  118.     test    al,80h
  119.     jz    wait_prn
  120.     stc
  121. ;
  122. bios_ret:
  123.     pop    ax
  124.     pop    bx
  125.     pop    cx
  126.     pop    dx
  127.     pop    ds
  128.     pop    es
  129.     ret    2
  130. ;
  131. ;    Wait for diskette motor start (1 sec.)
  132. ;
  133. wait_motor:
  134.     xor    ax,ax
  135.     push    ax
  136.     mov    ax,_ticks_per_sec
  137.     push    ax
  138.     call    _t_delay
  139.     add    sp,4
  140.     stc
  141.     jmp    bios_ret
  142. ;
  143. ;    Floppy/Fdisk/Keyboard wait/post
  144. ;
  145. flag_ops:
  146.     xor    bh,bh
  147.     mov    bl,al    
  148.     add    bx,bx
  149.     mov    bx,flag_tab[bx]
  150.     cmp    ah,90h
  151.     je    fl_wait
  152.     push    ds
  153.     push    bx
  154.     call    _set_flag
  155.     add    sp,4
  156.     clc
  157.     jmp    bios_ret
  158. ;
  159. fl_wait:
  160.     xor    dx,dx
  161.     cmp    al,2
  162.     je    fl_dowait
  163.     mov    dx,_ticks_per_sec
  164.     add    dx,dx
  165.     cmp    al,1
  166.     je    fl_dowait
  167.     mov    cx,dx
  168.     add    dx,cx
  169.     add    dx,cx
  170. fl_dowait:
  171.     xor    ax,ax
  172.     push    ax
  173.     push    dx
  174.     push    ds
  175.     push    bx
  176.     call    _clear_flag_wait_set
  177.     add    sp,8
  178.     cmp    ax,0
  179.     je    bios_ret
  180.     stc
  181.     jmp    bios_ret
  182. ;
  183. bios_int       endp
  184. ;
  185. ;------------------------------------------------------------------------
  186. ;
  187. ;    void far _tsk_remove_bios (void)
  188. ;
  189. ;    This routine un-installs the int handler.
  190. ;
  191. _tsk_remove_bios    proc    far
  192. ;
  193.     push    es
  194.     xor    ax,ax
  195.     mov    es,ax
  196.     assume    es:intseg
  197.         cli
  198.     mov    ax,cs:psofs        ; restore vector
  199.     mov    pintofs,ax
  200.     mov    ax,cs:psseg
  201.     mov    pintseg,ax
  202.         sti
  203.     assume    es:nothing
  204.     pop    es
  205. ;
  206.         mov     ax,offset floppy
  207.         push    ds
  208.         push    ax
  209.         call    _delete_flag
  210.         add     sp,4
  211. ;
  212.         mov     ax,offset fdisk
  213.         push    ds
  214.         push    ax
  215.         call    _delete_flag
  216.         add     sp,4
  217. ;
  218.         mov     ax,offset kbd
  219.         push    ds
  220.         push    ax
  221.         call    _delete_flag
  222.         add     sp,4
  223. ;
  224.         ret
  225. ;
  226. _tsk_remove_bios    endp
  227. ;
  228. ;----------------------------------------------------------------------
  229. ;
  230. ;    void far _tsk_install_bios (void)
  231. ;
  232. ;    This routine installs the int handler.
  233. ;
  234. _tsk_install_bios    proc    far
  235. ;
  236.     IF    TSK_NAMEPAR
  237.     mov    ax,offset fflname
  238.     push    ds
  239.     push    ax
  240.     ENDIF
  241.         mov     ax,offset floppy
  242.         push    ds
  243.         push    ax
  244.         call    _create_flag
  245.     IF    TSK_NAMEPAR
  246.     add    sp,8
  247.     ELSE
  248.         add     sp,4
  249.     ENDIF
  250. ;
  251.     IF    TSK_NAMEPAR
  252.     mov    ax,offset ffdname
  253.     push    ds
  254.     push    ax
  255.     ENDIF
  256.         mov     ax,offset fdisk
  257.         push    ds
  258.         push    ax
  259.         call    _create_flag
  260.     IF    TSK_NAMEPAR
  261.     add    sp,8
  262.     ELSE
  263.         add     sp,4
  264.     ENDIF
  265. ;
  266.     IF    TSK_NAMEPAR
  267.     mov    ax,offset fkbname
  268.     push    ds
  269.     push    ax
  270.     ENDIF
  271.         mov     ax,offset kbd
  272.         push    ds
  273.         push    ax
  274.         call    _create_flag
  275.     IF    TSK_NAMEPAR
  276.     add    sp,8
  277.     ELSE
  278.         add     sp,4
  279.     ENDIF
  280. ;
  281.         push    es
  282.     xor    ax,ax
  283.     mov    es,ax            ; establish addressing for intseg
  284.     assume    es:intseg
  285. ;
  286.     mov    ax,pintofs        ; save old timer int addr
  287.     mov    psofs,ax
  288.     mov    ax,pintseg
  289.     mov    psseg,ax
  290.     cli
  291.     mov    pintofs,offset bios_int ; set new timer int addr
  292.     mov    pintseg,cs
  293.     sti
  294.     assume    es:nothing
  295.         pop     es
  296.     ret
  297. ;
  298. _tsk_install_bios    endp
  299. ;
  300.     end
  301.  
  302.