home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / ct22d / tskint17.asm < prev    next >
Encoding:
Assembly Source File  |  1991-05-02  |  4.4 KB  |  283 lines

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