home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DOOG / CTASK.ZIP / TSKINT17.ASM < prev    next >
Assembly Source File  |  1989-12-29  |  4KB  |  259 lines

  1. ;
  2. ;    --- Version 2.0 89-12-29 12:20 ---
  3. ;
  4. ;    CTask - BIOS INT 17 (Printer support) interrupt handler
  5. ;
  6. ;    Public Domain Software written by
  7. ;        Thomas Wagner
  8. ;        Patschkauer Weg 31
  9. ;        D-1000 Berlin 33
  10. ;        West Germany
  11. ;
  12. ;    This file is new with version 1.2.
  13. ;
  14. ;    This interrupt handler completely replaces the standard BIOS
  15. ;    printer output driver. It assumes full IBM compatibility.
  16. ;    The advantage of this driver is that it schedules while waiting
  17. ;    for the printer to get ready, so other tasks are not 
  18. ;    unnecessarily delayed.
  19. ;
  20.     name    tskint17
  21.     .model    large,c
  22. ;
  23.     public    tsk_install_int17
  24.     public    tsk_remove_int17
  25. ;
  26.     include    tsk.mac
  27. ;
  28.     extrn    yield: far
  29.     extrn    create_ticker: far
  30.     extrn    delete_ticker: far
  31. ;
  32.     extrn    tsk_dgroup: word
  33. ;
  34. intseg    segment at 0
  35. ;
  36.         org    17h*4
  37. prnoff        dw    ?        ; interrupt entry
  38. prnseg        dw    ?
  39.  
  40. intseg    ends
  41. ;
  42. biosdata     segment at 40h
  43. ;
  44.         org    8h
  45. pr_base        dw    4 dup(?)
  46.         org    78h
  47. pr_timeout    db    4 dup(?)
  48. ;
  49. biosdata    ends
  50. ;
  51.     .tsk_data
  52. ;
  53. psav_off    dw    ?
  54. psav_seg    dw    ?
  55. ;
  56. ticker        tick_rec    <>
  57. ;
  58.     .tsk_edata
  59.     .tsk_code
  60. ;
  61. ;------------------------------------------------------------------------
  62. ;
  63. ;    void near tsk_remove_int17 (void)
  64. ;
  65. ;    This routine un-installs the int handler.
  66. ;
  67. tsk_remove_int17    proc    near uses ds
  68. ;
  69.     mov    ds,cs:tsk_dgroup
  70. ;
  71.     push    ds
  72.     mov    ax,offset ticker
  73.     push    ax
  74.     call    delete_ticker
  75.     add    sp,4
  76.     xor    ax,ax
  77.     mov    es,ax
  78.     assume    es:intseg
  79.         cli
  80.     mov    ax,psav_off        ; restore vector
  81.     mov    prnoff,ax
  82.     mov    ax,psav_seg
  83.     mov    prnseg,ax
  84.         sti
  85.     assume    es:nothing
  86. ;
  87.         ret
  88. ;
  89. tsk_remove_int17    endp
  90. ;
  91. ;----------------------------------------------------------------------
  92. ;
  93. ;    void near tsk_install_int17 (void)
  94. ;
  95. ;    This routine installs the int handler.
  96. ;
  97. tsk_install_int17    proc    near uses ds
  98. ;
  99.     mov    ds,cs:tsk_dgroup
  100. ;
  101.     xor    ax,ax
  102.     mov    es,ax            ; establish addressing for intseg
  103.     assume    es:intseg
  104. ;
  105.     mov    ax,prnoff        ; save old int addr
  106.     mov    psav_off,ax
  107.     mov    ax,prnseg
  108.     mov    psav_seg,ax
  109.     cli
  110.     mov    prnoff,offset prn_int     ; set new int addr
  111.     mov    prnseg,cs
  112.     sti
  113.     assume    es:nothing
  114.     xor    ax,ax
  115.     push    ax
  116.     push    ax
  117.     push    ds
  118.     mov    ax,offset ticker
  119.     push    ax
  120.     call    create_ticker
  121.     add    sp,8
  122.     ret
  123. ;
  124. tsk_install_int17    endp
  125. ;
  126. ;----------------------------------------------------------------------
  127. ;
  128.     assume    ss:nothing
  129. ;
  130. ;    Interrupt handler
  131. ;
  132. prn_int        proc    far
  133. ;
  134.     sti
  135.     push    ds
  136.     push    es
  137.     push    si
  138.     push    dx
  139.     push    cx
  140.     mov    cx,SEG biosdata
  141.     mov    es,cx
  142.     mov    ds,cs:tsk_dgroup
  143. ;
  144.     assume    es:biosdata
  145.     mov    si,dx            ; printer number
  146.     shl    si,1
  147.     mov    dx,pr_base[si]        ; load port
  148.     or    dx,dx
  149.     jz    prn_ret            ; return if no printer
  150. ;
  151.     or    ah,ah            ; fn 0 = output
  152.     jz    prn_output
  153.     dec    ah            ; fn 1 = init
  154.     jz    prn_init
  155.     dec    ah            ; fn 2 = status
  156.     jz    prn_status
  157. ;
  158. prn_ret:
  159.     pop    cx
  160.     pop    dx
  161.     pop    si
  162.     pop    es
  163.     pop    ds
  164.     iret
  165. ;
  166. ;    AH = 2: Return printer Status
  167. ;
  168. prn_status:
  169.     inc    dx            ; status port
  170. prn_st2:
  171.     mov    cl,al            ; save al
  172.     in    al,dx
  173.     mov    ah,al
  174.     and    ah,0f8h
  175.     xor    ah,048h
  176.     mov    al,cl            ; restore al
  177.     jmp    prn_ret
  178. ;
  179. ;    AH = 1: Initialize printer
  180. ;
  181. prn_init:
  182.     push    ax
  183.     inc    dx
  184.     inc    dx
  185.     mov    al,8
  186.     out    dx,al
  187.     mov    ticker.ticklo,2        ; 2 ticks (min. 55 ms)
  188.     push    bx
  189. ;
  190. ;    Wait for 2 ticks. Busy waiting loop with scheduling here to 
  191. ;    avoid compatibility problems and stack overruns.
  192. ;
  193. prini_loop:
  194.     call    yield
  195.     cmp    ticker.ticklo,0
  196.     jnz    prini_loop
  197. ;
  198.     pop    bx
  199.     mov    al,0ch
  200.     out    dx,al
  201.     dec    dx
  202.     pop    ax
  203.     jmp    prn_st2
  204. ;
  205. ;    AH = 0: Output character in AL
  206. ;
  207. prn_output:
  208.     push    ax
  209.     out    dx,al
  210.     inc    dx
  211.     shr    si,1
  212.     mov    al,18
  213.     mul    pr_timeout[si]
  214.     mov    ticker.ticklo,ax
  215. ;
  216. prout_wait:
  217.     mov    cx,10
  218. prout_1:
  219.     in    al,dx
  220.     test    al,80h
  221.     jnz    prout_2
  222.     loop    prout_1
  223.     cmp    ticker.ticklo,0
  224.     jz    prout_timeout
  225. ;
  226. ;    printer is busy, yield and try again later.
  227. ;
  228.     push    bx
  229.     call    yield
  230.     pop    bx
  231.     jmp    prout_wait
  232. ;
  233. prout_2:
  234.     inc    dx
  235.     mov    al,0dh
  236.     out    dx,al
  237.     mov    al,0ch
  238.     jmp    short $+2
  239.     jmp    short $+2
  240.     out    dx,al
  241.     dec    dx
  242.     pop    ax
  243.     jmp    prn_st2
  244. ;
  245. prout_timeout:
  246.     mov    cl,al
  247.     pop    ax
  248.     mov    ah,cl
  249.     and    ah,0f9h
  250.     or    ah,1
  251.     xor    ah,048h
  252.     jmp    prn_ret
  253. ;
  254. prn_int    endp
  255. ;
  256.     .tsk_ecode
  257.     end
  258.  
  259.