home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / FILE / XLAT11.ZIP / XLATR.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-13  |  14.4 KB  |  345 lines

  1.          Title Resident printer translator
  2.  
  3. ;   XLATR.ASM  --  configurable resident char-to-char print converter
  4. ;                  see usage text below on how to use it
  5. ;
  6. ;   Freeware by TapirSoft Gisbert W.Selke, Aug 90
  7. ;
  8.  
  9. ;   TASM       xlatr
  10. ;   TLINK  /T  xlatr
  11.  
  12. ; DOS interrupt calls:
  13. Printer         Equ     17h                     ; printer interrupt
  14. DOSCall         Equ     21h                     ; DOS interrupt
  15. DOSTSR          Equ     3100h                   ; TSR interrupt
  16.  
  17. ; DOS function numbers:
  18. PrintString     Equ     09h                     ; output string to StdOut
  19. GetPrinterVec   Equ     3517h                   ; get address of printer vector
  20. SetPrinterVec   Equ     2517h                   ; set address of printer vector
  21. FreeMemory      Equ     49h                     ; free memory
  22. Finish          Equ     4C00h                   ; return to DOS
  23.  
  24. ; our call number:
  25. SpecialFunc     Equ     02Ah                    ; marker for special services
  26.  
  27. ; some special characters:
  28. Tab             Equ     09h
  29. LineFeed        Equ     0Ah
  30. Return          Equ     0Dh
  31. CtrlZ           Equ     1Ah
  32.  
  33. CSeg            Segment
  34.                 Assume  CS:CSeg, DS:CSeg
  35.  
  36.                 Org     0080h
  37. CmdLine         Label   Byte                    ; pointer to command line
  38. XMainTable2     Label   Byte                    ; - will be overwritten by
  39.                 Org     $ + 2                   ; translation table
  40. MainTable2      Label   Byte
  41.  
  42.                 Org     100h
  43.  
  44. Start:          Jmp     Transient               ; Go to transient code
  45.  
  46. ;
  47. ; Informational data:
  48. ;
  49.  
  50. ProgInfo        db      Low(Offset ProgVersion) ; file offset of patch info
  51. ProgName        db      Return, 'Configurable resident printer driver'
  52. CopyRight       db      Return, LineFeed
  53.                 db      'FreeWare by TapirSoft Gisbert W.Selke, Aug 1990'
  54.                 db      Return, LineFeed
  55. Marker1         db      '<<<< '                 ; marker for patches
  56. Description     db      'Identity mapping as a starting point    '
  57. ; the length of the preceding string should always remain 40!
  58. Marker2         db      ' >>>>', CtrlZ          ; marker for patches
  59. EndHeader       Label   Byte
  60.  
  61. ProgVersion     db      'XLAT11'                ; standard name and version
  62. DescOff         db      Low(Offset Description) ; file offset of descr. text
  63. DescLength      db      Marker2-Description     ; length of description text
  64. InterNameOff    dw      (Offset InterName)-100h ; file offset of usage text
  65. MainTableOff    dw      MainTable-100h          ; file offset of main table
  66.  
  67.                 Org     $ - 5                   ; overwrite unneeded data
  68.  
  69. OldPI           Label   DWord                   ; old printer interrupt:
  70. OldPIOfs        Label   Word                    ; first offset,
  71.                 Org     $ + 2
  72. OldPISeg        Label   Word                    ; then seg
  73.                 Org     $ + 2
  74. ActFlag         Label   Byte                    ; 0 = is active
  75.                 Org     $ + 1
  76.  
  77. CheckStart      Equ     $                       ; resident code starts here
  78.  
  79. Printerceptor   Proc    Far
  80.                 Assume  CS:CSeg, DS:CSeg
  81.  
  82.                 Sti                             ; Turn interrupts back on
  83.                 Cmp     ah, SpecialFunc         ; check for special codes
  84.                 Jne     GoOn                    ; if none, process normally
  85.                 Cmp     al, 'u'                 ; unloading requested?
  86.                 Jne     CheckDes                ; if not, try more
  87.                 Mov     dx, cs:OldPIOfs         ; otherwise start removal
  88.                 Mov     ax, cs:OldPISeg
  89.                 Mov     ds, ax
  90.                 Mov     ax, SetPrinterVec       ; Reestablish old INT 17h handler
  91.                 Int     DOSCall
  92.                 Mov     ax, cs                  ; Return our segment
  93.                 IRet
  94.  
  95. CheckDes:       Cmp     al, 'd'                 ; desactivation requested?
  96.                 Je      SetFlag                 ; yes -> fill in flag
  97.                 Cmp     al, 'a'                 ; activation requested?
  98.                 Je      ClrFlag                 ; yes -> fill in flag
  99.                 Or      al, al                  ; toggle requested?
  100.                 Jne     GoOn                    ; no -> process normally
  101.                 Mov     al, 'd'
  102.                 Sub     al, cs:ActFlag
  103.                 Jmp Short SetFlag
  104. ClrFlag:        Xor     al, al                  ; set to 0
  105. SetFlag:        Mov     cs:ActFlag, al
  106.                 IRet
  107.  
  108. GoOn:           Or      ah, ah                  ; is it print char call?
  109.                 Jnz     PassIt                  ; no -> ordinary call
  110.                 Cmp     cs:ActFlag, 0           ; are we active?
  111.                 Jne     PassIt                  ; if not -> don't touch
  112.                 Push    bx                      ; preserve old BX
  113.                 Mov     bx, Offset MainTable2   ; point to xlation table
  114.                 Xlat    cs:MainTable2           ; translate
  115.                 Pop     bx                      ; restore old bx
  116. PassIt:         PushF                           ; Push flags to...
  117.  
  118.                 Assume  ds:Nothing              ; ... simulate ...
  119.                 Call    OldPi                   ; ... interrupt call
  120.                 IRet
  121.  
  122. CheckLength = $ - CheckStart
  123.  
  124. Printerceptor   EndP
  125.  
  126. PrinterceptorEnd Label Byte
  127.  
  128. Transient:      Cld                             ; all string intructions forward
  129.                 Mov     dx, Offset InterName    ; show our name
  130.                 Mov     ah, PrintString         ;
  131.                 Int     DOSCall
  132.                 Mov     dx, Offset Predicate    ; ... and first part of
  133.                 Mov     ah, PrintString         ; completion message
  134.                 Int     DOSCall
  135.                 Call    ParseArgs
  136.                 Cmp     ah, 'h'                 ; show usage screen?
  137.                 Je      Usage
  138.                 Call    CheckPresence           ; Check if we are already there
  139.                 Cmp     ah, 'l'                 ; load request?
  140.                 Je      Install
  141.  
  142.                 Cmp     ah, 'u'                 ; unload request?
  143.                 Je      Unload
  144.  
  145.                 Or      cx, cx                  ; are we already loaded?
  146.                 Jnz     DoInstall               ; if not, load.
  147.  
  148.                 XChg    ah, al                  ; function code into al
  149.                 Mov     ah, SpecialFunc         ; special code into ah
  150.                 Int     Printer                 ; must be 'a', 'd', 0
  151.                 Or      al, al                  ; return code?
  152.                 Jz      Activated               ; if 0: is now activated
  153.                 Mov     dx, Offset DesactivateMsg
  154.                 Jmp Short ShowMsg
  155.  
  156. Activated:      Mov     dx, Offset ActivateMsg
  157.                 Jmp Short ShowMsg
  158.  
  159. Unload:         Or      cx, cx                  ; are we already loaded?
  160.                 Jz      DoUnload                ; if so, do the unloading
  161.                 Mov     dx, Offset UnloadedMsg
  162.                 Jmp Short ShowMsg
  163.  
  164. DoUnload:       XChg    ah, al
  165.                 Mov     ah, SpecialFunc
  166.                 Push    ds                      ; save our data segment address
  167.                 Int     Printer                 ; routine's seg returned in ax
  168.                 Pop     ds                      ; retrieve data segment address
  169.                 Mov     es, ax                  ; memory of routine:
  170.                 Mov     ah, FreeMemory          ; free it!
  171.                 Int     DOSCall
  172.                 Mov     dx, Offset UnloadMsg    ; report unloading
  173.                 Jmp Short ShowMsg
  174.  
  175. ;
  176. ; show usage screen:
  177. ;
  178.  
  179. Usage:          Mov     dx, Offset ProgName     ; display programme header
  180.                 Mov     cx, ProgName-EndHeader
  181.                 Mov     ah, 40h                 ; output message to stdout
  182.                 Mov     bx, 1
  183.                 Int     DOSCall
  184.  
  185.                 Mov     dx, Offset UsageText    ; display usage screen, part 1
  186.                 Mov     ah, PrintString         ; output message
  187.                 Int     DOSCall
  188.                 Mov     dx, Offset UsageText2   ; display usage screen, part 2
  189.  
  190. ShowMsg:        Mov     ah, PrintString         ; output message
  191.                 Int     DOSCall
  192.  
  193.                 Mov     ax, Finish              ; terminate without error
  194.                 Int     DOSCall
  195.  
  196. ;
  197. ; the following is the installation code:
  198. ;
  199.  
  200. Install:        Or      cx, cx                  ; are we already there?
  201.                 Jnz     DoInstall
  202.  
  203.                 Mov     dx, Offset LoadedMsg    ; if so, say so; do nothing else
  204.                 Jmp Short ShowMsg
  205.  
  206. DoInstall:      Mov     ax, GetPrinterVec       ; Get address of old INT 17h
  207.                 Int     DOSCall                 ; handler...
  208.                 Mov     OldPIOfs, bx            ;    and save it
  209.                 Mov     OldPISeg, es
  210.  
  211.                 Mov     dx, Offset Printerceptor; Replace old handler pointer
  212.                 Mov     ax, SetPrinterVec       ; with one pointing to ourselves
  213.                 Int     DOSCall
  214.  
  215.                 Xor     al, al                  ; mark active
  216.                 Mov     ActFlag, al
  217.  
  218.                 Mov     si, Offset XMainTable   ; the dirty bits: relocate
  219.                 Mov     di, Offset XMainTable2  ; translation table over
  220.                 Push    ds                      ; cmd line in PSP
  221.                 Pop     es
  222.                 Mov     cx, MainTableEnd - XMainTable
  223.                 Rep MovsB
  224.  
  225.                 Mov     dx, Offset LoadMsg      ; boast success
  226.                 Mov     ah, PrintString
  227.                 Int     DOSCall
  228.  
  229.                 Mov     es, ds:[2Ch]            ; environment segment:
  230.                 Mov     ah, FreeMemory          ; free it!
  231.                 Int     DOSCall
  232.  
  233.                 Mov     dx, Offset PrinterceptorEnd ; calculate our resident
  234.                 Mov     cx, 4                   ; length
  235.                 ShR     dx, cl
  236.                 Inc     dx
  237.                 Mov     ax, DOSTSR
  238.                 Int     DOSCall                 ; Terminate and stay resident
  239.  
  240.  
  241. ParseArgs       Proc    Near
  242. ;
  243. ; scan command line for arguments; only arguments supported:
  244. ;   /l            : load into memory
  245. ;   /u            : unload
  246. ;   /d            : desactivate
  247. ;   /a            : activate
  248. ;   nothing       : load or toggle
  249. ;   anything else : usage screen
  250. ; return cmd letter (lower case) in ah; 0 if no arg, 'h' if illegal args
  251. ;
  252.  
  253.                 Mov     si, Offset CmdLine + 1  ; point to command line
  254.                 Xor     ah, ah                  ; init cmd marker
  255.  
  256. PANext:         Lodsb                           ; get next char
  257.                 Cmp     al, Return              ; at end?
  258.                 Je      PADone                  ; if so, finish
  259.                 Cmp     al, ' '                 ; ignore this?
  260.                 Je      PANext
  261.                 Cmp     al, ','                 ; ignore this?
  262.                 Je      PANext
  263.                 Cmp     al, Tab                 ; ignore this?
  264.                 Je      PANext
  265.                 Cmp     al, '/'                 ; switch char?
  266.                 Je      PASwitch                ; skip if so
  267.                 Cmp     al, '-'                 ; switch char?
  268.                 Jne     PAUsage                 ; skip if not
  269.  
  270. PASwitch:       Or      ah, ah                  ; cmd already found?
  271.                 Jnz     PAUsage                 ; illegal if so!
  272.                 Lodsb                           ; which switch?
  273.                 Or      al, 20h                 ; convert to lower case
  274.                 Cmp     al, 'l'                 ; request loading?
  275.                 Je      PAOK                    ; skip if so
  276.                 Cmp     al, 'u'                 ; request unloading?
  277.                 Je      PAOK                    ; skip if so
  278.                 Cmp     al, 'd'                 ; request desactivation?
  279.                 Je      PAOK                    ; skip if so
  280.                 Cmp     al, 'a'                 ; request for activation?
  281.                 Jne     PAUsage                 ; skip if not
  282. PAOK:           XChg    ah, al                  ; store cmd
  283.                 Jmp Short PANext                ; and scan on
  284.  
  285. PAUsage:        Mov     ah, 'h'                 ; otherwise illegal arg
  286.  
  287. PADone:         Ret
  288.                 EndP    ParseArgs
  289.  
  290. CheckPresence   Proc    Near
  291. ;
  292. ; Check whether we are already in memory.
  293. ; Iff so, CX = 0.
  294. ; Modifies si, di, cx
  295. ;
  296.                 Push    ax                      ; save ax on stack
  297.                 Mov     ax,GetPrinterVec        ; get pointer to Int 17h handler
  298.                 Int     DOSCall                 ; in ES:BX
  299.                 Mov     di, bx                  ; move offset into DI
  300.                 Mov     si, Offset Printerceptor ; our address in DS:SI
  301.                 Mov     cx, CheckLength         ; length to check
  302.                 Rep     Cmpsb                   ; check all those bytes
  303.                 Pop     ax                      ; restore ax
  304.                 Ret                             ; result code is in cx
  305. CheckPresence   EndP
  306.  
  307. ;
  308. ; Usage info:
  309. ;
  310.  
  311. UsageText       db      Return, LineFeed, 'Usage: '
  312. InterName       db      'xlatr    $'
  313. UsageText2      db      '[/x]', Return, LineFeed, 'where', Return, LineFeed
  314.                 db      'x=L to load into memory', Return, LineFeed
  315.                 db      'x=U to unload', Return, LineFeed
  316.                 db      'x=D to desactivate', Return, LineFeed
  317.                 db      'x=A to activate', Return, LineFeed
  318.                 db      'no argument loads or toggles status', Return, LineFeed
  319.                 db      Return, LineFeed, '$'
  320.  
  321. Predicate       db      'has been $'            ; miserly storing activity info
  322. UnloadMsg       db      'un'
  323. LoadMsg         db      'loaded.$'
  324. DesactivateMsg  db      'des'
  325. ActivateMsg     db      'activated.$'
  326. UnloadedMsg     db      'un'
  327. LoadedMsg       db      'loaded already.$'
  328.  
  329.  
  330. XMainTable      db      0, Return               ; to keep memory mappers happy
  331.                                                 ; (after relocation over PSP)
  332.  
  333. ; the next few lines fill the 'default' translation table with the identity
  334. ; mapping:
  335. MainTable       Label   Byte
  336.                 outcode = 0
  337. Rept 256
  338.                 db      outcode
  339.                 outcode = outcode + 1
  340. EndM
  341. MainTableEnd    Label   Byte
  342.  
  343. CSeg            EndS
  344.                 End     Start
  345.