home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1998 July / pcx23_9807.iso / PC-XUSER / PC-XUSER.17 / OOP / PCX_UTIL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-01-01  |  9.4 KB  |  450 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {   PC-X User utility for Turbo Vision                  }
  4. {   Copyright (c) 1997 By PC-X User and Bérczi László   }
  5. {                                                       }
  6. {   Portions Copyright (c) 1990 by Borland Int.         }
  7. {*******************************************************}
  8. {Last Edit: 1997 II 15. 21:00}
  9. {$X+,V-,F+,O-,S+,Q-,G+}
  10.  
  11. unit PCX_Util;
  12.  
  13. INTERFACE
  14. type
  15.   PScreen = ^TScreen;                                      {  For Video   }
  16.   TScreen = Array[1..25,1..80,1..2] of Byte;
  17.  
  18.   PChrData = ^TChrData;                                    {For NewCharsOn}
  19.   TChrData = Array[0..4095] of Byte;
  20.  
  21.   PChrData16 = ^TChrData16;
  22.   TChrData16 = Array[0..15] of Byte;
  23.  
  24. const
  25.   IsPCXGraphCharsOn: Boolean = False;
  26.  
  27. var
  28.   Screen: PScreen;
  29.  
  30.  
  31.  
  32. function  GetPrimaryAdapterType: Byte;
  33. function  UCaseString(const S: String): String;
  34. function  SearchForParameter(S: String): Boolean;
  35.  
  36. {Screen}
  37. procedure SetXY(Col, Row: Byte); {asm}
  38. procedure GetXY(var Col, Row: Byte); {asm}
  39.  
  40. procedure SetBackGroundIntensity(On: Boolean);
  41. function  IsBackGroundIntensityOn: Boolean;
  42.  
  43. procedure GetScreen(var Kepernyo: TScreen);
  44. procedure PutScreen(Kepernyo: TScreen);
  45.  
  46. {Char edit}
  47. procedure NewCharOn(Dat: Pointer; Car, Fm: Word); {asm}
  48. procedure NewCharsOn(CharSet: TChrData; Car, Fm, Count: Word);
  49. procedure GetChar(Dat: Pointer; Car, Fm: Word); {asm}
  50. procedure GetChars(var CharSets: TChrData; Car, FM , Count: Word);
  51.  
  52. procedure GetSaveableChars;
  53. procedure PutSavedChars;
  54.  
  55. procedure PCX_Font; {Fonttable}
  56. procedure SetPCXGraphChars(State: Boolean);
  57.  
  58. {Key}
  59. procedure KeyStrokeToKeyboardBuffer(ASCII, ScanC: Byte); {asm} {ScanC: 0 if you don't care}
  60.  
  61. {Byte}
  62. function  SwapHighAndLowAreaOfByte(BByte: Byte): Byte;
  63.  
  64. IMPLEMENTATION
  65.  
  66. var
  67.   Temp2     : TChrData16;
  68.   SavedFont : TChrData; { For NewCharsOn }
  69.   Charset   : TChrData; {For external NewCharsOn()}
  70.  { TempScreen: PScreen;
  71.   TX, TY    : Byte;}
  72.  
  73.  
  74. function  GetPrimaryAdapterType: Byte; Assembler;
  75. asm
  76.   mov ax,  1A00h
  77.   int 10h
  78.   mov al,  bl
  79. end;
  80.  
  81. function  UCaseString(const S: String): String; Assembler;
  82. asm
  83.   push es
  84.   push ds
  85.   push di
  86.   push si
  87.   lds  si, S
  88.   les  di, @Result
  89.   mov  dl, Byte Ptr ds:[si]
  90.   mov  Byte Ptr es:[di], dl
  91.   xor  dh, dh
  92.   xor  bx, bx
  93. @Loop:
  94.   inc  bx
  95.   mov  al, Byte Ptr ds:[si+bx]
  96.   cmp  al, 'a'
  97.   jb   @Cont
  98.   cmp  al, 'z'
  99.   ja   @Cont
  100.   sub  al, 'a' - 'A'
  101. @Cont:
  102.   mov  Byte Ptr es:[di+bx], al
  103.   cmp  bx, dx
  104.   jb   @Loop
  105.   pop  si
  106.   pop  di
  107.   pop  ds
  108.   pop  es
  109. end;
  110.  
  111. function  SearchForParameter(S: String): Boolean;
  112. var
  113.   i    : Word;
  114.   Found: Boolean;
  115. begin
  116.   i:=0;
  117.   Found:=False;
  118.   if ParamCount > 0 then
  119.     while (ParamCount > i) and (Not Found) do
  120.     begin
  121.       Inc(i);
  122.       if UCaseString(ParamStr(i)) = UCaseString(S) then Found:=True;
  123.     end;
  124.   SearchForParameter:=Found;
  125. end;
  126.  
  127. {Screen}
  128. procedure SetXY(Col, Row: Byte); Assembler;
  129. asm
  130.   MOV  AH,02h
  131.   XOR  BH, BH
  132.   MOV  DH, Row
  133.   DEC  DH
  134.   MOV  DL, COL
  135.   DEC  DL
  136.   PUSH SI
  137.   PUSH DI
  138.   PUSH BP
  139.   PUSH ES
  140.   INT  10H
  141.   POP  ES
  142.   POP  BP
  143.   POP  DI
  144.   POP  SI
  145. end;
  146.  
  147. procedure GetXY(var Col, Row: Byte); Assembler;
  148. asm
  149.   push es
  150.   push di
  151.   MOV  AH,03h
  152.   XOR  BH,BH
  153.   INT  10H
  154.   INC  DH
  155.   INC  DL
  156.   les  di, Col
  157.   mov  Byte Ptr es:[di], dl
  158.   les  di, Row
  159.   mov  Byte Ptr es:[di], dh
  160.   pop  di
  161.   pop  es
  162. end;
  163.  
  164. procedure SetBackGroundIntensity(On: Boolean); Assembler;
  165. asm
  166.   mov bl, On
  167.   or  bl, bl
  168.   jne @To0
  169.   mov bl, 01h
  170.   jmp @Folyt
  171. @To0:
  172.   xor bl, bl
  173. @Folyt:
  174.   mov ax, 1003h
  175.   int 10h
  176. end;
  177.  
  178. function  IsBackGroundIntensityOn: Boolean;
  179. var B: ^Byte;
  180. begin
  181.   B:=Ptr(Seg0040, $65);
  182.   IsBackGroundIntensityOn:=((B^ and 32) div 32) = 0;
  183. end;
  184.  
  185. procedure GetScreen(var Kepernyo: TScreen);
  186. var i, j, k: Byte;
  187. begin
  188.   inline($60); {PUSHA}
  189.   for i:=1 to 25 do
  190.     for j:=1 to 80 do
  191.       for k:=1 to 2 do
  192.         Kepernyo[i, j, k]:=Screen^[i, j, k];
  193.   inline($61); {POPA}
  194. end;
  195.  
  196. procedure PutScreen(Kepernyo: TScreen);
  197. var i, j, k: Byte;
  198. begin
  199.   inline($60); {PUSHA}
  200.   for i:=1 to 25 do
  201.     for j:=1 to 80 do
  202.       for k:=1 to 2 do
  203.         Screen^[i, j, k]:=Kepernyo[i, j, k];
  204.   inline($61); {POPA}
  205. end;
  206.  
  207. {Char edit}
  208. procedure NewCharOn(Dat: Pointer; Car, Fm: Word); Assembler;
  209. asm
  210.   {$IfNDef DPMI}
  211.   xor  dx, dx
  212.   mov  bx, OFFSET @Code1
  213.   mov  cx, OFFSET @CodePre2
  214.   sub  cx, bx
  215.   cmp  Byte Ptr cs:[bx], 163
  216.   jne  @ContCode
  217. @ContXOR:
  218.   xor  Byte Ptr cs:[bx], 165
  219.   inc  bx
  220.   inc  dx
  221.   cmp  dx, cx
  222.   jb   @ContXOR
  223.   jmp  @Code1
  224.  
  225. @ContCode:
  226.   push bx
  227.   retn
  228.   dw   0303h {=> 0303h}
  229.   dw   0310h {=> 1003h}
  230.   {$ENDIf}
  231.  
  232. @Code1:
  233.   push es
  234.   push ds
  235.   {$IfDef DPMI}
  236.   mov  ax, SegA000 {0A000h}
  237.   {$ELSE}
  238.   mov  ax, 0A000h
  239.   {$ENDIf}
  240.   mov  es, ax
  241.   lds  si, Dat
  242.   mov  di, Car
  243.   shl  di, 5
  244.   mov  cx, Fm
  245.   cld
  246.  
  247.   mov  dx, 03CEh
  248.   mov  ax, 0005h
  249.   out  dx, ax
  250.   mov  ax, 0406h
  251.   out  dx, ax
  252.   mov  dx, 03C4h
  253.   mov  ax, 0402h
  254.   out  dx, ax
  255.   mov  ax, 0704h
  256.   out  dx, ax
  257.  
  258.   rep  movsb
  259.  
  260.   mov  ax, 0302h
  261.   out  dx, ax
  262.   mov  ax, 0304h
  263.   out  dx, ax
  264.   mov  dx, 03CEh
  265.   mov  ax, 1005h
  266.   out  dx, ax
  267.   mov  ax, 0E06h
  268.   out  dx, ax
  269.  
  270.   pop  ds
  271.   pop  es
  272.  
  273.   jmp  @Code2
  274. @CodePre2:
  275.   {$IfNDef DPMI}
  276.   dw   0303h {=> 0303h}
  277.   dw   0310h {=> 1003h}
  278.   {$ENDIf}
  279. @Code2:
  280. end;
  281.  
  282. procedure NewCharsOn(CharSet: TChrData; car, fm, count: Word);
  283. var i, k: Byte;
  284. begin
  285.   if Count > 255 then Count:=1;
  286.   for i:=Car to Car + Count do
  287.   begin
  288.     for k:=0 to 15 do
  289.       Temp2[k]:=CharSet[i*16+k];
  290.     NewCharOn(Addr(Temp2), i, fm);
  291.   end;
  292. end;
  293.  
  294. procedure GetChar(dat: Pointer; Car, Fm: Word); Assembler;
  295. asm
  296.   push ds
  297.   push es
  298.   {$IfDef DPMI}
  299.   mov  ax, SegA000 {0A000h}
  300.   {$ELSE}
  301.   mov  ax, 0A000h
  302.   {$ENDIf}
  303.   mov  ds, ax
  304.   les  di, Dat
  305.   mov  si, Car
  306.   mov  cl, 5
  307.   shl  si, Cl
  308.   mov  cx, Fm
  309.   cld
  310.  
  311.   mov dx, 3C4h; {  Sequencer port address  }
  312.   mov ax, 0704h; {  Sequential addressing  }
  313.   out dx, ax;
  314.   mov dx, 03CEh
  315.   mov ax, 0005h; { Disable odd-even addressing }
  316.   out dx, ax;
  317.   mov ax, 0406h; { Map starts at A000:0000 (64K mode) }
  318.   out dx, ax
  319.   mov ax, 0204h { Map starts at A000:0000 (64K mode) }
  320.   out dx, ax;
  321.  
  322.   rep movsb
  323.  
  324.   mov  dx, 3C4h; { Sequencer port address }
  325.   mov  ax, 0302h
  326.   out  dx, ax
  327.   mov  ax, 0304h
  328.   out  dx, ax
  329.   mov  dx, 03CEh
  330.   mov  ax, 1005h
  331.   out  dx, ax
  332.   mov  ax, 0E06h
  333.   out  dx, ax
  334.   mov  ax, 0004h
  335.   out  dx, ax
  336.  
  337.   pop  es
  338.   pop  ds
  339. end;
  340.  
  341. procedure GetChars(var CharSets: TChrData; Car, Fm, Count: Word);
  342. var i, k: Byte;
  343. begin
  344.   if Count > 255 then Count:=255;
  345.   for i:=Car to Car + Count do
  346.   begin
  347.     GetChar(Addr(Temp2), i, fm);
  348.       for k:=0 to 15 do
  349.        CharSets[i*16+k]:=Temp2[k];
  350.   end;
  351. end;
  352.  
  353. procedure GetSaveableChars;
  354. begin
  355.   GetChars(SavedFont, 0, 16, 255);
  356. end;
  357.  
  358. procedure PutSavedChars;
  359. begin
  360.   NewCharsOn(SavedFont, 0, 16, 255);
  361. end;
  362.  
  363.   {$IfNDef DPMI}
  364.     procedure PCX_Font; external {$L PCX_Font};
  365.   {$Else}
  366.     procedure PCX_Font; external {$L PCX_Fond};
  367.   {$ENDIf}
  368.  
  369. procedure AddFontsToLogicalFontTable(NameOfArray: TChrData;FromASCII,ASCIICount:Byte);
  370. var Ckl, D: Word;
  371. begin
  372.   D:=0;
  373.   for Ckl:=FromASCII*16 to (FromASCII*16)+(ASCIICount*16)-1 do
  374.   begin
  375.     CharSet[Ckl]:=NameOfArray[D];
  376.     D:=D+1;
  377.   end;
  378. end;
  379.  
  380. procedure SetPCXGraphChars(State: Boolean);
  381. begin
  382.   IsPCXGraphCharsOn:=State;
  383.   if State
  384.   then begin
  385.          Move(@PCX_Font^, Addr(CharSet)^, 4096);
  386.          AddFontsToLogicalFontTable(CharSet, 0, 255);
  387.          NewCharsOn(CharSet, 0, 16, 255);
  388.        end
  389.   else asm
  390.          mov  ax, 1104h
  391.          xor  bl, bl
  392.          int  10h
  393.        end;
  394. end;
  395.  
  396.  
  397. {Key}
  398. procedure KeyStrokeToKeyboardBuffer(ASCII, ScanC: Byte); Assembler;
  399. asm
  400.   mov ah,  05h
  401.   mov cl,  ASCII
  402.   mov ch,  ScanC
  403.   int 16h
  404. end;
  405.  
  406. {Byte}
  407. function  SwapHighAndLowAreaOfByte(BByte: Byte): Byte; Assembler;
  408. asm
  409.   mov  al, BByte
  410.   mov  cl, 4
  411.   rol  al, cl
  412. end;
  413.  
  414.  
  415. {Internal}
  416. function  GetVideoSeg: Word;
  417. begin
  418.   if GetPrimaryAdapterType = $01 then GetVideoSeg:=SegB000  {MDA}
  419.                                  else GetVideoSeg:=SegB800; {Not MDA}
  420. end;
  421.  
  422.  
  423. BEGIN
  424.   if Test8086 < 2 then begin
  425.                          WriteLn;
  426.                          WriteLn('Error: This program required least 386 CPU !');
  427.                          WriteLn('Exitting . . .');
  428.                          ExitCode:=$FF;
  429.                        end
  430.                   else begin
  431.                          Screen:=Ptr(GetVideoSeg, $0000);
  432.  
  433.                          {$IFDef DPMI}
  434.                          SegC000:=ConvertPhisicalAddrToDPMIAddr($C0000);
  435.                          SegD000:=ConvertPhisicalAddrToDPMIAddr($D0000);
  436.                          SegE000:=ConvertPhisicalAddrToDPMIAddr($E0000);
  437.                          SegF000:=ConvertPhisicalAddrToDPMIAddr($F0000);
  438.                          {$ENDIf}
  439.  
  440.                          {if Not (SearchForParameter('/NoDumpCache') or SearchForParameter('-NoDumpCache')) then
  441.                          begin
  442.                            if IsInstalledNUTSR(NU_NCache_S) then FlushBuffesrsNUTSR(NU_NCache_S);
  443.                            if IsInstalledNUTSR(NU_NCache_F) then FlushBuffesrsNUTSR(NU_NCache_F);
  444.                            if IsSmartDrvInstalled then CommitCacheSmartDrv;
  445.                          end;}
  446.  
  447.                          {OldExitProc:=ExitProc;
  448.                          ExitProc:=@PCXExitProc;}
  449.                        end;
  450. END.