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