home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 330_03 / tskint17.asm < prev    next >
Assembly Source File  |  1990-10-12  |  4KB  |  284 lines

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