home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_07 / 1n07008b < prev    next >
Text File  |  1990-10-02  |  3KB  |  148 lines

  1.  
  2. page ,132
  3. title CPLP122.asm
  4. comment \
  5.  
  6.  
  7.   CPLP122.asm        Aug 15, 1990   Joe Felton
  8.  
  9.   This TSR program redirects characters printed by the BIOS from lptl to lpt2.
  10.   Assuming that lpt3 does not physically exist, it uses the lpt3 port for its
  11.   own purposes, i.e. a command channel.     Commands are sent by a batch file.
  12.   To set redirection on, execute the following batch command:
  13.  
  14.                 @echo <esc>rl >lpt3
  15.  
  16.   To remove redirection, execute the following batch file command:
  17.  
  18.                 @echo <esc>r0 >lpt3
  19.  
  20.   Assemble with Masm 5.1 or Tasm 1.0, link with MS Link, or Tlink.    The
  21.   executable must be converted to a .com file with exe2bin before loading.
  22. \
  23.  
  24. CSEG    segment
  25.         assume cs: CSEG, ds: nothing
  26.  
  27. LPTl = 0  ; parallel printer port 1
  28. LPT2 = 1  ; parallel printer port 2
  29. LPT3 = 2  ; cplp122 command interface
  30.  
  31. LF = 10
  32. CR = 13
  33. ESCAPE = 27
  34.  
  35. ; cplp 3 byte command sequence: Escape, command, value.
  36.  
  37. CP_RDR = 'r'    ; command byte: redirect lptl to lpt2 or cancel redirect
  38.  
  39.                 org        100h
  40.  
  41. ;----------------------------------------------------------
  42. startup:     jmp init_iv
  43.  
  44.                   ; data area
  45. old17iv              dd ?              ; bios int 17 entry
  46. cmd_mode          db 0              ; cplp command byte sequence state
  47. redir              db 0              ; if nonzero, redirect lpt1 to lpt2
  48.  
  49.  
  50. ;----------------------------------------------------------
  51. ; cplpl22 int 17 handler
  52. ;
  53.  
  54. cp_main:                          ; int 17h entry
  55.           cmp      ah, 0              ; print character request?
  56.           jne      prt_char          ; ignore status and init calls
  57.  
  58.           cmp      dx, LPTl
  59.           je      lpt1_char
  60.  
  61.           cmp      dx, LPT3
  62.           jne      prt_char
  63.  
  64.           call      cp_cmd_proc      ; LPT3 is our command port
  65.           iret                      ; end of interrupt
  66.  
  67. lpt1_char:
  68.  
  69.         cmp        cs:[redir], 0    ; redirect lptl to lpt2?
  70.         je        prt_char
  71.         inc        dx                ; yes
  72.  
  73. prt_char:
  74.  
  75.         jmp        cs:[old17iv]    ; jump to bios print service
  76.  
  77.  
  78. ;-------------------------------------------------------------------
  79. cp_cmd_proc:                    ; char in al for lpt3
  80.  
  81.         cmp        cs:[cmd_mode], 0    ; in commmand sequence?
  82.         jne        cpc_cmode            ; yes..continue
  83.  
  84.         cmp        al, ESCAPE        ; begin command sequence?
  85.         je        cpc_ret            ; yes
  86.         jmp        cpc_cancel
  87.  
  88. cpc_cmode:
  89.  
  90.         cmp cs:[cmd_mode], ESCAPE    ; command byte in al?
  91.         jne        cpc_val                ; no
  92.  
  93.         cmp        al, CP_RDR        ; redirect on/off cmd?
  94.         je        cpc_ret            ; yes
  95.         jmp        cpc_cancel
  96.  
  97. cpc_val:
  98.  
  99.         cmp cs:[cmd_mode], CP_RDR     ; redirect value byte?
  100.         jne        cpc_cancel
  101.         mov        cs:[redir], al        ; yes - set redirect flag
  102.  
  103. cpc_cancel:
  104.  
  105.         xor        al, al                ; end command mode
  106.  
  107. cpc_ret:
  108.  
  109.         mov        cs:[cmd_mode], al    ; set next command state
  110.         ret
  111.  
  112. ; end of resident code
  113. ;-----------------------------------------------------------------
  114. ; Take over interrupt vector 17h - BIOS print service
  115.  
  116. usermsg db        CR,LF,'Print Redirector Installed',CR,LF,'$'
  117.  
  118. init_iv:
  119.  
  120.         mov        ax, 3517h
  121.         int        21h            ; save existing vector
  122.         mov        word ptr cs:[old17iv], bx
  123.         mov        word ptr cs:[old17iv][2], es
  124.  
  125.         lea        dx, cp_main
  126.         push    cs
  127.         pop        ds
  128.         mov        ax, 2517h
  129.         int        21h                    ; install our vector
  130.  
  131.         mov        ah, 9
  132.         lea        dx, usermsg
  133.         int        21h                    ; print "installed" message
  134.  
  135.         ; calculate number of paragraphs to keep resident
  136.  
  137.         lea        ax, usermsg
  138.         xor        dx, dx
  139.         mov        cx, 16
  140.         div        cx
  141.         inc        ax
  142.         mov        dx, ax
  143.         mov        ax, 3100h
  144.         int        21h                    ; terminate & stay resident
  145.  
  146. CSEG    ends
  147.         end        startup
  148.