home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / DSUTIL11 / TRANSPRN / TRANSPRN.PAS < prev   
Pascal/Delphi Source File  |  1993-09-20  |  12KB  |  373 lines

  1. {-----------------------------------------------------------------------}
  2. { PROJECT        NON-PROFIT HIGH QUALITY PROFESSIONAL SOFTWARE,  }
  3. {            AVAILABLE FOR ALL WORLD                }
  4. { LIBRARY        SYSTEM UTILITIES                                }
  5. { MODULE        PRINT_UTILITIES                                 }
  6. { FILE NAME        TRANSPRN.PAS                    }
  7. { PURPOSE        Translate input character stream for standard   }
  8. {                       DOS print device                                }
  9. { VERSION        1.00                        }
  10. { DATE            01-Sep-93                    }
  11. { DESIGN        Dmitry Stefankov                }
  12. { IMPLEMENTATION    Dmitry Stefankov                 }
  13. { COMPANY        Freelance Software Engineer            }
  14. { ADDRESS        Isakowskogo str, 4-2-30                }
  15. {            Moscow, 123181                    }
  16. {            USSR                        }
  17. {            Tel. 007 (095) 944-6304                }
  18. { COPYRIGHT NOTICE    Copyright (C) 1987-1993, Dmitry Stefankov    }
  19. { RESTRICTED RIGHTS    AVAILABLE ONLY FOR FREE DISTRIBUTION,           }
  20. {            NOT FOR COMMERCIAL PURPOSE            }
  21. { COMPUTER        IBM PC or compatible                }
  22. { OPERATING SYSTEM    MS/PC-DOS Version 3.30 or higher        }
  23. { COMPILER        Turbo Pascal Version 6.0            }
  24. {                       (Borland International Inc.)  or compatible     }
  25. { ASSEMBLY LANGUAGE    Microsoft MASM 5.10 or compatible               }
  26. { LINKER        Turbo Pascal internal                           }
  27. { ARGUMENTS        None                                            }
  28. { RETURN        See error return codes definitions        }
  29. { REQUIRES        Source Code Files                               }
  30. {                       NONE                                            }
  31. {                       External Object Files                           }
  32. {                       NONE                                            }
  33. {            Maintence Project Files                }
  34. {            NONE                        }
  35. { NATURAL LANGUAGE      English Language                                 }
  36. { SPECIAL        None                        }
  37. { DESCRIPTION           None
  38. { REVISION HISTORY    Dima Stefankov (DS)                }
  39. {               1.00   01-Sep-93  DS  initial release        }
  40. {-----------------------------------------------------------------------}
  41.  
  42.  
  43. {**======================== PROGRAM HEADER PART ========================*}
  44. PROGRAM   TRANSLATE_PRINT_STREAM;
  45.  
  46.  
  47. {*** other modules ***}
  48. USES
  49.      Dos;
  50.  
  51. {** switches for compilation *}
  52. {$S-}        {*  stack checking   *}
  53. {$R-}           {*  range checking   *}
  54.  
  55. {* generate version for debugging practice *}
  56. {***$DEFINE  DebugVersion}
  57.  
  58.  
  59. {**======================== CONSTANTS DEFINITIONS PART ================**}
  60.  
  61. CONST
  62.  
  63.     { program definitions }
  64.      asPurpose                  =       'Print Stream Translator';
  65.      asVersion                  =       '1.00';
  66.      asAuthor                   =       'Dima Stefankov';
  67.      asCopyright                =       'Copyright (c) 1987, 1993';
  68.      asProgram                  =       'TransPRN';
  69.      asProgramPrompt            =       asProgram+': ';
  70.      asUProgram                 =       'TRANSPRN';
  71.  
  72.     { exit codes }
  73.       errTerminateOK            =     0;
  74.       errNoParmsDispHelp        =     1;
  75.  
  76.     { miscellaneous }
  77.       asBlank                   =     '';
  78.       achHexPrefix              =     '$';
  79.       aBytesPerPara             =     16;
  80.       aPSP_Size                 =     256;
  81.  
  82.     { ASCII codes }
  83.       achNULL                   =     00;
  84.       achLF                     =     10;
  85.       achCR                     =     13;
  86.  
  87.    { MS-DOS functions }
  88.      aDosFunctionsCall          =     $21;
  89.      aTerminateAndStay          =     $31;
  90.      aFreeMemoryBlock           =     $49;
  91.  
  92.    { iAPX86 opcode }
  93.      aFarJumpOpCode             =     $EA;      
  94.  
  95.    { IBM PC BIOS functions }
  96.      aRomPrintDriver            =     $17;      
  97.      aRomPrintChar              =     $00;
  98.      aRomInitPrinter            =     $01;
  99.      aRomGetPrinerStatus        =     $02;
  100.      aRomAvailFuncMax           =     aRomGetPrinerStatus;
  101.  
  102.      aLPT1                      =     $00;
  103.      aLPT2                      =     $01;
  104.      aLPT3                      =     $02;
  105.      aLPT4                      =     $03;      { may not work for most machines }
  106.      aMaxLPT                    =     aLPT4;
  107.  
  108.    { new print driver functions }
  109.      aBasePrintDriverFn         =    $04;
  110.      aInstallCheck              =    aBasePrintDriverFn+$00;
  111.      aGetResidentInfo           =    aBasePrintDriverFn+$01;
  112.      aNewFuncMaxNum             =    aBasePrintDriverFn+$01;
  113.  
  114.    { driver state flags }
  115.      aFullWordMask              =    $FFFF;
  116.      aTransModeON               =    $0001;
  117.  
  118.    { driver identification values }
  119.     aFunctionOK                 =    $0000;
  120.     aDriverID                   =    $4453;    {'DS'}
  121.  
  122.    { ATTENTION!!! hard-coded values }
  123.     adwPutOldIntVec             =    $0004;
  124.  
  125.  
  126. {**======================== TYPES DEFINITIONS PART ====================**}
  127.  
  128. TYPE
  129.  
  130.   {* strings *}
  131.        STR2                     =     STRING[2];
  132.        STR4                     =     STRING[4];
  133.        STR8                     =     STRING[8];
  134.  
  135.  
  136. {**======================== VARIABLES DEFINITIONS PART ====================**}
  137.  
  138. VAR
  139.  
  140.    gsTempInput          :   STRING;
  141.    glpPrintDevIntVec    :   System.Pointer;
  142.    dwTSRPartSize        :   System.Word;
  143.  
  144.  
  145.  
  146. {**============== ASSEMBLY FUNCTIONS/PROCEDURES PART ==================**}
  147.  
  148.  
  149. PROCEDURE  _lpNewPrintStreamDriver;  FAR;  ASSEMBLER;
  150. {* Interrupt handler for print device driver. *}
  151. asm
  152. {$IFDEF  DebugVersion}
  153. {$ENDIF}
  154. {offset = $00}
  155.         jmp     @SkipDataSection
  156.  
  157. {offset = $03}
  158.  
  159.   @JumpToOldPrintDriver:
  160.         DB      aFarJumpOpCode
  161.   @ddOldPrintDriverAddress:
  162.         DW      0                       { offset  part }
  163.         DW      0                       { segment part }
  164.  
  165. {offset = $08}
  166.   @dwPspSegment:
  167.         DW      0
  168.  
  169. {offset = $0A}
  170.   @dwPrintPort:
  171.         DW      aLPT1
  172.  
  173. {offset = $0C}
  174.   @dwStateFlags:
  175.         DW     aTransModeON
  176.  
  177. {offset = $0E}
  178. {  SOURCE FILE:  ASCII.BIN                                               }
  179. {  Created by Bin2asm utility, Copyright (c) 1987, 1993  Dima Stefankov  }
  180.  
  181.  @dwCharacterStreamTranslateTable:
  182.     DB    000h,001h,002h,003h,004h,005h,006h,007h        {........}
  183.     DB    008h,009h,00Ah,00Bh,00Ch,00Dh,00Eh,00Fh        {........}
  184.     DB    010h,011h,012h,013h,014h,015h,016h,017h        {........}
  185.     DB    018h,019h,01Ah,01Bh,01Ch,01Dh,01Eh,01Fh        {........}
  186.     DB    020h,021h,022h,023h,024h,025h,026h,027h        { !"#$%&'}
  187.     DB    028h,029h,02Ah,02Bh,02Ch,02Dh,02Eh,02Fh        {()*+,-./}
  188.     DB    030h,031h,032h,033h,034h,035h,036h,037h        {01234567}
  189.     DB    038h,039h,03Ah,03Bh,03Ch,03Dh,03Eh,03Fh        {89:;<=>?}
  190.     DB    040h,041h,042h,043h,044h,045h,046h,047h        {@ABCDEFG}
  191.     DB    048h,049h,04Ah,04Bh,04Ch,04Dh,04Eh,04Fh        {HIJKLMNO}
  192.     DB    050h,051h,052h,053h,054h,055h,056h,057h        {PQRSTUVW}
  193.     DB    058h,059h,05Ah,05Bh,05Ch,05Dh,05Eh,05Fh        {XYZ[\]^_}
  194.     DB    060h,061h,062h,063h,064h,065h,066h,067h        {`abcdefg}
  195.     DB    068h,069h,06Ah,06Bh,06Ch,06Dh,06Eh,06Fh        {hijklmno}
  196.     DB    070h,071h,072h,073h,074h,075h,076h,077h        {pqrstuvw}
  197.     DB    078h,079h,07Ah,07Bh,07Ch,07Dh,07Eh,07Fh        {xyz.|.~.}
  198.     DB    080h,081h,082h,083h,084h,085h,086h,087h        {Çüéâäàåç}
  199.     DB    088h,089h,08Ah,08Bh,08Ch,08Dh,08Eh,08Fh        {êëèïîìÄÅ}
  200.     DB    090h,091h,092h,093h,094h,095h,096h,097h        {ÉæÆôöòûù}
  201.     DB    098h,099h,09Ah,09Bh,09Ch,09Dh,09Eh,09Fh        {ÿÖÜ¢£¥₧ƒ}
  202.     DB    0A0h,0A1h,0A2h,0A3h,0A4h,0A5h,0A6h,0A7h        {áíóúñѪº}
  203.     DB    0A8h,0A9h,0AAh,0ABh,0ACh,0ADh,0AEh,0AFh        {¿⌐¬½¼¡«»}
  204.     DB    0B0h,0B1h,0B2h,0B3h,0B4h,0B5h,0B6h,0B7h        {░▒▓│┤╡╢╖}
  205.     DB    0B8h,0B9h,0BAh,0BBh,0BCh,0BDh,0BEh,0BFh        {╕╣║╗╝╜╛┐}
  206.     DB    0C0h,0C1h,0C2h,0C3h,0C4h,0C5h,0C6h,0C7h        {└┴┬├─┼╞╟}
  207.     DB    0C8h,0C9h,0CAh,0CBh,0CCh,0CDh,0CEh,0CFh        {╚╔╩╦╠═╬╧}
  208.     DB    0D0h,0D1h,0D2h,0D3h,0D4h,0D5h,0D6h,0D7h        {╨╤╥╙╘╒╓╫}
  209.     DB    0D8h,0D9h,0DAh,0DBh,0DCh,0DDh,0DEh,0DFh        {╪┘┌█▄▌▐▀}
  210.     DB    0E0h,0E1h,0E2h,0E3h,0E4h,0E5h,0E6h,0E7h        {αßΓπΣσµτ}
  211.     DB    0E8h,0E9h,0EAh,0EBh,0ECh,0EDh,0EEh,0EFh        {ΦΘΩδ∞φε∩}
  212.     DB    0F0h,0F1h,0F2h,0F3h,0F4h,0F5h,0F6h,0F7h        {≡±≥≤⌠⌡÷≈}
  213.     DB    0F8h,0F9h,0FAh,0FBh,0FCh,0FDh,0FEh,0FFh        {°∙·√ⁿ²■ }
  214.  
  215. @dwFunctionsJumpTable:
  216.         DW      OFFSET    @InstallationCheck
  217.         DW      OFFSET    @GetInfoAboutTSR
  218.  
  219. { use as return point to original ROM driver }
  220. @JumpBack:
  221.                  popf
  222.                  jmp    @JumpToOldPrintDriver
  223.  
  224. @SkipDataSection:
  225.                  pushf
  226.  
  227. @CheckPortToPrint:
  228.                  cmp     dx, cs:[OFFSET @dwPrintPort]
  229.                  jne    @JumpBack
  230.  
  231. @CheckFuncToPrint:
  232.                  cmp     ah, aRomPrintChar
  233.                  jne    @CheckOtherROMFunctions
  234.  
  235. @CheckTransModeState:
  236.                  test    WORD PTR cs:[OFFSET @dwStateFlags], aTransModeON
  237.                  jz     @JumpBack
  238.  
  239. @DoCharacterTranslation:
  240.                  push    bx
  241.  
  242.                  xor     bx, bx
  243.                  mov     bl, al
  244.                  mov     al, BYTE PTR cs:[bx.@dwCharacterStreamTranslateTable]
  245.  
  246.                  pop     bx
  247.                  jmp    @JumpBack
  248.  
  249. @CheckOtherROMFunctions:
  250.                  cmp     ah, aRomAvailFuncMax
  251.                  jbe     @JumpBack
  252.  
  253. @CheckNewFunctions:
  254.                  cmp     ah, aBasePrintDriverFn
  255.                  jb     @JumpBack
  256.  
  257.                  cmp     ah, aNewFuncMaxNum
  258.                  ja     @JumpBack
  259.  
  260. @JumpToDispatchTable:
  261.                  sub    ah, aBasePrintDriverFn
  262.                  mov    al, ah
  263.                  sub    ah, ah
  264.                  shl    ax, 1
  265.                  add    ax, OFFSET  @dwFunctionsJumpTable
  266.                  jmp    ax
  267.  
  268.  
  269. @InstallationCheck:
  270.                  mov    bx, aDriverID
  271.                  jmp   @ExitFromDriver
  272.  
  273.  
  274. @GetInfoAboutTSR:
  275.                  mov    bx, cs:[OFFSET @dwPspSegment]
  276.                  mov    cx, cs:[OFFSET @dwStateFlags]
  277.                  mov    dx, cs:[OFFSET @dwPrintPort]
  278.                  mov    es, cs:[(OFFSET @ddOldPrintDriverAddress)+$02]
  279.                  mov    di, cs:[(OFFSET @ddOldPrintDriverAddress)+$00]
  280.                  jmp   @ExitFromDriver
  281.  
  282.  
  283. @ExitFromDriver:
  284.                  mov    ax, aFunctionOK
  285.  
  286.                  popf
  287.                  iret
  288. END; {end-asm}
  289. { _lpNewPrintStreamDriver }
  290.  
  291.  
  292.  
  293. {**========================= PROCEDURES PART ==========================**}
  294.  
  295. PROCEDURE    _DummyProc;
  296. {* It is used for reference only. Don't remove this code!!! *}
  297. BEGIN
  298.   {** nothing!!! *}
  299. END;
  300. { _DummyProc }
  301.  
  302.  
  303.  
  304. {**========================== FUNCTIONS PART ==========================**}
  305.  
  306. FUNCTION   _fnchGetFirstChar(sInput : STRING) : System.Char;
  307. {* Returns a first char from string. *}
  308. VAR
  309.   chTemp  :  System.Char;
  310.  
  311. BEGIN
  312.    IF (System.Length(sInput) <> 0)
  313.      THEN  chTemp := sInput[1]
  314.      ELSE  chTemp := System.Char(achNULL);
  315.    {if-then-else}
  316.   _fnchGetFirstChar := chTemp;
  317. END;
  318. { _fnchGetFirstChar }
  319.  
  320.  
  321.  
  322. {**========================= PROCEDURES PART ==========================**}
  323.  
  324.  
  325. PROCEDURE    _CopyrightDisplay;
  326. {* Outputs the copyright notice. *}
  327. BEGIN
  328.      System.WriteLn(asPurpose+
  329.                     '  Version '+
  330.                     asVersion+
  331.                     ',  '+
  332.                     asCopyright+
  333.                     '  '+
  334.                     asAuthor);
  335. END;  { _CopyrightDisplay }
  336.  
  337.  
  338.  
  339. {**======================= MAIN STATEMENTS PART =======================**}
  340.  
  341. BEGIN
  342.  
  343.   {* copyright message *}
  344.     _CopyrightDisplay;
  345.  
  346.  
  347.   {* install driver *}
  348.      Dos.GetIntVec(aRomPrintDriver,glpPrintDevIntVec);
  349.      System.Move(glpPrintDevIntVec,
  350.                  System.Mem[System.Seg(_lpNewPrintStreamDriver):System.Ofs(_lpNewPrintStreamDriver)+adwPutOldIntVec],
  351.                  System.SizeOf(System.Pointer));
  352.      Dos.SetIntVec(aRomPrintDriver,@_lpNewPrintStreamDriver);
  353.  
  354.   {* say to DOS that we ready to use *}
  355.      dwTSRPartSize := (aPSP_Size +
  356.                        (System.Ofs(_DummyProc)) +
  357.                       aBytesPerPara) DIV aBytesPerPara;
  358.  
  359.      ASM
  360.            mov      dx, dwTSRPartSize
  361.            mov      ah, aTerminateAndStay
  362.            int      aDosFunctionsCall
  363.      END;
  364.      {asm-end}
  365.  
  366.  
  367.   {* terminate message *}
  368.     System.WriteLn(asProgramPrompt+'Done.');
  369.  
  370.  
  371.   {* System.Halt(errTerminateOk); *}
  372. END.
  373.