home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / FASTSC.ZIP / FASTSCRN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-06-30  |  13.5 KB  |  520 lines

  1. {$A-,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}
  2. {$M 16384,0,655360}
  3. Unit FastScrn;
  4. (***************************************************************************)
  5. (* Program: FastScrn.Pas                                                   *)
  6. (* Last udpate: June 29, 1989                                              *)
  7. (* Author: Mark Addleman                                                   *)
  8. (*                                                                         *)
  9. (* Public domain.  Please distribute freely and in complete form.          *)
  10. (*                                                                         *)
  11. (* Any comments, suggestions, questions, please inform me via CompuServe   *)
  12. (* my ID number is 72777,740                                               *)
  13. (*                                                                         *)
  14. (* Thanks for using FastScrn                                               *)
  15. (***************************************************************************)
  16.  
  17. Interface
  18. Uses Dos, FastDef;
  19. Type
  20.    ScreenObj                 =   Object
  21.                                     Rows,
  22.                                     Cols         :   Byte;
  23.                                     LastRow      :   Byte;
  24.                                     LastCol      :   Byte;
  25.                                     ScrPtr       :   Pointer;
  26.  
  27.                                     Constructor Init;
  28.                                     Destructor  Done;
  29.  
  30.                                     Function  Snow:Boolean; virtual;
  31.                                     Function  ScreenPtr(_Row, _Col:Byte):Pointer; virtual;
  32.                                     Procedure Write(_Row, _Col:Byte; _Color:Integer; _St:String);
  33.                                     Procedure WriteV(_Row, _Col:Byte; _Color:Integer; _St:String);
  34.                                     Procedure WriteA(_Row, _Col:Byte; _Color:Integer; Var _St; _Len:Byte); virtual;
  35.                                     Procedure WriteAv(_Row, _Col:Byte; _Color:Integer; Var _St; _Len:Byte); virtual;
  36.                                     Procedure WriteC(_Row, _Col1, _Col2:Byte; _Color:Integer; _St:String);
  37.                                     Procedure WriteAC(_Row, _Col1, _Col2:Byte; _Color:Integer; Var _St; _Len:Byte);
  38.                                     Procedure WriteCv(_Row1, _Row2, _Col:Byte; _Color:Integer; _St:String);
  39.                                     Procedure WriteACv(_Row1, _Row2, _Col:Byte; _Color:Integer; Var _St; _Len:Byte);
  40.                                     Procedure Fill(_Row, _Col, _Rows, _Cols:Byte; _Color:Integer; _Ch:Char); virtual;
  41.                                     Procedure Color(_Row, _Col, _Rows, _Cols:Byte; _Color:Byte); virtual;
  42.                                     Function  CharAt(_Row, _Col:Byte):Char; virtual;
  43.                                     Function  ColorAt(_Row, _Col:Byte):Byte; virtual;
  44.  
  45.                                     Procedure Copy(_SourceScreen:ScreenObj; _sRow, _sCol, _Rows, _Cols:Byte;
  46.                                                    _dRow, _dCol:Byte); virtual;
  47.  
  48.                                     Procedure SetLasts(Rs, Cs:Byte); virtual;
  49.                                  End;
  50.  
  51.    DisplayObj                =   Object(ScreenObj)
  52.                                     ScreenType   :   Byte;
  53.                                     ScreenSnow   :   Boolean;
  54.                                     Page         :   Byte;
  55.  
  56.                                     Constructor Init;
  57.                                     Function  Snow:Boolean; virtual;
  58.  
  59.                                     Function  CurrentRows:Byte; virtual;
  60.                                     Function  CurrentCols:Byte; virtual;
  61.                                     Function  CurrentVideoMode:Byte; virtual;
  62.                                     Procedure SetVideoMode(Mode:Byte); virtual;
  63.  
  64.                                     Procedure SetCursor(Top, Bottom:Byte); virtual;
  65.                                     Function  GetCursor:Word; virtual;
  66.                                     Procedure CursorOff; virtual;
  67.                                     Procedure CursorOn; virtual;
  68.                                     Procedure CursorFast; virtual;
  69.                                     Procedure CursorSlow; virtual;
  70.                                     Function  WhereR:Byte; virtual;
  71.                                     Function  WhereC:Byte; virtual;
  72.                                     Procedure GotoRC(Row, Col:Byte); virtual;
  73.  
  74.                                     Procedure UsePage(PageNum:Byte); virtual;
  75.                                     Procedure DisplayPage(PageNum:Byte); virtual;
  76.                                     Function CurrentPage:Byte;
  77.                                  End;
  78.  
  79. Var
  80.    DisplayScreen             :   DisplayObj;
  81.  
  82. Implementation
  83. Var
  84.    BaseScreenSeg             :   Word;
  85.  
  86. Type
  87.    ScreenCharArray           =   Array[1..2] of Byte;
  88.  
  89. {$L Fast.Obj}
  90. Procedure FcopyAsm(Var Source, Dest; Rows, Cols, SkipSource, SkipDest:Word; Snow:Boolean); external;
  91. Procedure FfillAsm(CharColor:Word; Var Dest; Rows, Cols, SkipDest:Word; Snow:Boolean); external;
  92. Procedure FfillGetColorAsm(Char:Word; Var Dest; Rows, Cols, SkipDest:Word; Snow:Boolean); external;
  93. Procedure FwriteAsm(Var Source, Dest; Len:Word; Color:Word; Snow:Boolean); external;
  94. Procedure FwriteGetColorAsm(Var Source, Dest; Len:Word; Snow:Boolean); external;
  95. Procedure FattrAsm(Char:Word; Var Dest; Rows, Cols, SkipDest:Word; Snow:Boolean); external;
  96. Procedure FwriteVasm(Var Source, Dest; Len:Word; Color:Word; SkipDest:Word; Snow:Boolean); external;
  97. Procedure FwriteVGetColorAsm(Var Source, Dest; Len:Word; SkipDest:Word; Snow:Boolean); external;
  98.  
  99. Const
  100.    CharacterPos              =   1;
  101.    ColorPos                  =   2;
  102.    SlowCursor                =   3 shl 5;
  103.    HideCursor                =   1 shl 6;
  104.  
  105. Procedure ScreenObj.SetLasts;
  106. Begin
  107.    If Cs+LastCol > Cols Then Begin
  108.       Inc(LastRow, (Cs+LastCol) div Cols);
  109.       LastCol:=LastCol+Cs-Cols;
  110.    End
  111.    Else Begin
  112.       Inc(LastCol, Cs);
  113.       Inc(LastRow, Rs);
  114.    End;
  115. End;
  116.  
  117. Function ScreenObj.Snow;
  118. Begin
  119.    Snow:=False;
  120. End;
  121.  
  122. Function ScreenObj.ScreenPtr;
  123. Begin
  124.    ScreenPtr:=Ptr(Seg(ScrPtr^),
  125.                   Ofs(ScrPtr^)+2*(Pred(_Row)*Cols+Pred(_Col)));
  126. End;
  127.  
  128. Function ScreenObj.CharAt;
  129. Begin
  130.    CharAt:=Char(ScreenCharArray(ScreenPtr(_Row, _Col)^)[CharacterPos]);
  131. End;
  132.  
  133. Function ScreenObj.ColorAt;
  134. Begin
  135.    ColorAt:=Byte(ScreenCharArray(ScreenPtr(_Row, _Col)^)[ColorPos]);
  136. End;
  137.  
  138. Procedure ScreenObj.Write;
  139. Var
  140.    P                         :   Pointer;
  141.  
  142. Begin
  143.    LastRow:=_Row;
  144.    LastCol:=_Col;
  145.  
  146.    P:=ScreenPtr(_Row, _Col);
  147.  
  148.    If _Color=SameAttr Then Begin
  149.       FwriteGetColorAsm(_St[1], P^, Length(_St), Snow);
  150.    End
  151.    Else
  152.       FwriteAsm(_St[1], P^, Length(_St), _Color*$100, Snow);
  153.  
  154.    SetLasts(0, Length(_St));
  155. End;
  156.  
  157. Procedure ScreenObj.WriteV;
  158. Var
  159.    P                         :   Pointer;
  160.  
  161. Begin
  162.    LastRow:=_Row;
  163.    LastCol:=_Col;
  164.  
  165.    P:=ScreenPtr(_Row, _Col);
  166.  
  167.    If _Color=SameAttr Then Begin
  168.       FwriteVGetColorAsm(_St[1], P^, Length(_St), Cols*2, Snow);
  169.    End
  170.    Else
  171.       FwriteVasm(_St[1], P^, Length(_St), _Color*$100, Cols*2, Snow);
  172.  
  173.    SetLasts(Length(_St), 0);
  174. End;
  175.  
  176. Procedure ScreenObj.WriteCv;
  177. Begin
  178.    WriteV((_Row1+_Row2-Length(_St)) div 2, _Col, _Color, _St);
  179. End;
  180.  
  181. Procedure ScreenObj.WriteC;
  182. Begin
  183.    Write(_Row, (_Col1+_Col2-Length(_St)) div 2, _Color, _St);
  184. End;
  185.  
  186. Procedure ScreenObj.WriteA;
  187. Var
  188.    St                        :   String;
  189.  
  190. Begin
  191.    St:=String(_St)[0]+String(_St);
  192.    St[0]:=Char(_Len);
  193.    Write(_Row, _Col, _Color, St);
  194. End;
  195.  
  196. Procedure ScreenObj.WriteAC;
  197. Begin
  198.    WriteA(_Row, (_Col1+_Col2-_Len) div 2, _Color, _St, _Len);
  199. End;
  200.  
  201. Procedure ScreenObj.WriteAv;
  202. Var
  203.    St                        :   String;
  204.  
  205. Begin
  206.    St:=String(_St)[0]+String(_St);
  207.    St[0]:=Char(_Len);
  208.    WriteV(_Row, _Col, _Color, St);
  209. End;
  210.  
  211. Procedure ScreenObj.WriteACv;
  212. Begin
  213.    WriteAv((_Row1+_Row2-_Len) div 2, _Col, _Color, _St, _Len);
  214. End;
  215.  
  216. Procedure ScreenObj.Fill;
  217. Var
  218.    P                         :   Pointer;
  219.  
  220. Begin
  221.    LastRow:=_Row;
  222.    LastCol:=_Col;
  223.  
  224.    P:=ScreenPtr(_Row, _Col);
  225.  
  226.    If _Color=SameAttr Then Begin
  227.       FfillGetColorAsm(Byte(_Ch), P^, _Rows, _Cols, (Cols-_Cols)*2, Snow);
  228.    End
  229.    Else Begin
  230.       FfillAsm((Byte(_Color)*$100+Byte(_Ch)), P^, _Rows, _Cols,
  231.                (Cols-_Cols)*2, Snow);
  232.    End;
  233.  
  234.    SetLasts(Rows, Cols);
  235. End;
  236.  
  237. Procedure ScreenObj.Color;
  238. Var
  239.    P                         :   Pointer;
  240.  
  241. Begin
  242.    LastRow:=_Row;
  243.    LastCol:=_Col;
  244.  
  245.    P:=ScreenPtr(_Row, _Col);
  246.  
  247.    FattrAsm(Byte(_Color)*$100, P^, _Rows, _Cols, (Cols-_Cols)*2, Snow);
  248. End;
  249.  
  250. Procedure ScreenObj.Copy;
  251. Var
  252.    Dest, Source              :   Pointer;
  253.  
  254. Begin
  255.    Source:=_SourceScreen.ScreenPtr(_sRow, _sCol);
  256.    Dest:=ScreenPtr(_dRow, _dCol);
  257.  
  258.    FcopyAsm(Source^, Dest^, _Rows, _Cols, (_SourceScreen.Cols-_Cols)*2,
  259.             (Cols-_Cols)*2, Snow);
  260. End;
  261.  
  262. Constructor ScreenObj.Init;
  263. Begin
  264.    LastRow:=1;
  265.    LastCol:=1;
  266. End;
  267.  
  268. Destructor ScreenObj.Done;
  269. Begin
  270. End;
  271.  
  272.  
  273. Constructor DisplayObj.Init;
  274.    Function EGAinstalled:Boolean;
  275.    Var
  276.       R                      :   Dos.Registers;
  277.  
  278.    Begin
  279.       R.Ax:=$1200;
  280.       R.Bx:=$0010;
  281.       R.Cx:=$FFFF;
  282.       Intr($10, R);
  283.       EGAinstalled:=Not (R.Cx=$FFFF);
  284.    End;
  285.  
  286.    Function VGAinstalled:Boolean;
  287.    Var
  288.       R                      :   Dos.Registers;
  289.  
  290.    Begin
  291.       R.Ax:=$1A00;
  292.       Intr($10, R);
  293.       VGAinstalled:=((R.Al and $FF) = $1a) and
  294.                     ((R.Bl and $FF) in [$7, $8, $B, $C]);
  295.    End;
  296.  
  297. Label
  298.    CheckVideoMode;
  299.  
  300. Var
  301.    R                         :   Registers;
  302.  
  303. Begin
  304.    ScreenObj.Init;
  305.  
  306.    CheckVideoMode:
  307.    Case CurrentVideoMode of
  308.       7,2,
  309.       0   :   If EGAinstalled Then Begin
  310.                  If VGAinstalled Then
  311.                     ScreenType:=VGAmono
  312.                  Else
  313.                     ScreenType:=EGAmono;
  314.               End
  315.               Else
  316.                  ScreenType:=MDAmono;
  317.       3,1 :   If EGAinstalled Then Begin
  318.                  If VGAinstalled Then
  319.                     ScreenType:=VGAcolor
  320.                  Else
  321.                     ScreenType:=EGAcolor;
  322.               End
  323.               Else
  324.                  ScreenType:=CGAcolor;
  325.       Else Begin
  326.          SetVideoMode(3);
  327.          Goto CheckVideoMode;
  328.       End;
  329.    End;
  330.  
  331.    Case ScreenType of
  332.       VGAcolor,
  333.       EGAcolor,
  334.       CGAcolor   :   ScrPtr:=Ptr($B800,0);
  335.       VGAmono,
  336.       EGAmono,
  337.       VGAmono    :   ScrPtr:=Ptr($B000,0);
  338.    End;
  339.  
  340.    If ScreenType=CGAcolor Then
  341.       ScreenSnow:=True
  342.    Else
  343.       ScreenSnow:=False;
  344.  
  345.    {Simple snow detecting and not very practical.  I lack the ability
  346.     to test on a snow producing card.  I would welcome input!}
  347.  
  348.    R.Ah:=15;
  349.    Intr($10, R);
  350.    Page:=R.Bh;
  351.  
  352.    Rows:=CurrentRows;
  353.    Cols:=CurrentCols;
  354. End;
  355.  
  356. Function DisplayObj.Snow;
  357. Begin
  358.    Snow:=ScreenSnow;
  359. End;
  360.  
  361. Procedure DisplayObj.SetCursor;
  362. Var
  363.    Registers                 :   Dos.Registers;
  364.  
  365. Begin
  366.    With Registers Do Begin
  367.       Ah:=1;
  368.       Cl:=Pred(Bottom);
  369.       Ch:=Pred(Top);
  370.    End;
  371.    Intr($10, Registers);
  372. End;
  373.  
  374. Function DisplayObj.GetCursor;
  375. Var
  376.    R                         :   Registers;
  377.  
  378. Begin
  379.    R.Ah:=3;
  380.    Intr($10, R);
  381.    GetCursor:=R.Cx;
  382. End;
  383.  
  384. Procedure DisplayObj.GotoRC;
  385. Var
  386.    Registers                 :   Dos.Registers;
  387.  
  388. Begin
  389.    With Registers Do Begin
  390.       Ah:=2;
  391.       Bh:=Page;
  392.       Dl:=Pred(Col);
  393.       Dh:=Pred(Row);
  394.    End;
  395.    Intr($10,Registers);
  396. End;
  397.  
  398. Function DisplayObj.WhereR;
  399. Begin
  400.    WhereR:=Succ(Mem[0:Page+$044F]);
  401. End;
  402.  
  403. Function DisplayObj.WhereC;
  404. Begin
  405.    WhereC:=Succ(Mem[0:Page+$0450]);
  406. End;
  407.  
  408. Procedure DisplayObj.CursorOff;
  409. Var
  410.    R                         :   Registers;
  411.  
  412. Begin
  413.    R.Cx:=GetCursor;
  414.    R.Ch:=R.Ch or HideCursor;
  415.  
  416.    R.Ah:=1;
  417.    Intr($10, R);
  418. End;
  419.  
  420. Procedure DisplayObj.CursorOn;
  421. Var
  422.    R                         :   Registers;
  423.  
  424. Begin
  425.    R.Cx:=GetCursor;
  426.    R.Ch:=R.Ch and not HideCursor;
  427.  
  428.    R.Ah:=1;
  429.    Intr($10, R);
  430. End;
  431.  
  432. Procedure DisplayObj.CursorFast;
  433. Var
  434.    R                         :   Registers;
  435.  
  436. Begin
  437.    R.Cx:=GetCursor;
  438.    R.Ch:=R.Ch and not SlowCursor;
  439.  
  440.    R.Ah:=1;
  441.    Intr($10, R);
  442. End;
  443.  
  444. Procedure DisplayObj.CursorSlow;
  445. Var
  446.    R                         :   Registers;
  447.  
  448. Begin
  449.    R.Cx:=GetCursor;
  450.    R.Ch:=R.Ch or SlowCursor;
  451.  
  452.    R.Ah:=1;
  453.    Intr($10, R);
  454. End;
  455.  
  456. Procedure DisplayObj.UsePage;
  457. Begin
  458.    Page:=PageNum;
  459.    ScrPtr:=Ptr(BaseScreenSeg+(Page*MemW[$0000:$044C] div 16), Ofs(ScrPtr^));
  460. End;
  461.  
  462. Procedure DisplayObj.DisplayPage;
  463. Var
  464.    Registers                 :   Dos.Registers;
  465.  
  466. Begin
  467.    Page:=PageNum;
  468.    With Registers Do Begin
  469.       Ah:=5;
  470.       Al:=PageNum;
  471.    End;
  472.  
  473.    Intr($10, Registers);
  474. End;
  475.  
  476. Function DisplayObj.CurrentPage;
  477. Begin
  478.    CurrentPage:=Page;
  479. End;
  480.  
  481. Function DisplayObj.CurrentVideoMode;
  482. Var
  483.    R                         :   Dos.Registers;
  484.  
  485. Begin
  486.    R.Ah:=$0F;
  487.    Intr($10, R);
  488.    CurrentVideoMode:=R.Al;
  489. End;
  490.  
  491. Procedure DisplayObj.SetVideoMode;
  492. Var
  493.    R                         :   Dos.Registers;
  494.  
  495. Begin
  496.    R.Ah:=0;
  497.    R.Al:=Mode;
  498.  
  499.    Intr($10, R);
  500. End;
  501.  
  502. Function DisplayObj.CurrentRows;
  503. Begin
  504.    If DisplayScreen.ScreenType < EGAColor Then
  505.       CurrentRows:=25
  506.    Else
  507.       CurrentRows:=MemW[$0:$484];
  508. End;
  509.  
  510. Function DisplayObj.CurrentCols;
  511. Begin
  512.    CurrentCols:=MemW[$0:$44A];
  513. End;
  514.  
  515. Begin
  516.    DisplayScreen.Init;
  517.  
  518.    BaseScreenSeg:=Seg(DisplayScreen.ScrPtr^);
  519. End.
  520.