
                      4.3.  WINDOW
                      ------------------

         WINDOW  ॠ ࠢ ᨬ-
묨 .  ᯮ 㫨 SCREEN  SEGMEM. 室騥
 ⠢   楤    㯭
࠭  ⢥ ॠ쭮 ࠡ祩 ,  ⠪   ⠫쭠
 ࠭ ⠥  ⮬  -  饭  -
.

      뢮 ⥪⮢ ଠ樨  "Orion" ⢫
 ᪮ ०,   ᨬ쭮  㫨 ⥬ -
⠭ ᪮ , ࠧ ண   ᮮ-
⢨  ࠧࠬ ᨬ.

     㫥 WINDOW ॠ ⥪  ⥬, -
   ணࠬ   SEGMEM. ਭ樯 ࠡ-
   ⥬ ᫥騩.   ନ஢ (⨨) -
।  뢮 ᮤন ࠭  ࠬ ⥪饣  -
, 梥,    ⠪   ࠭  ᪮
 (ᮤন ࠭ -  ᥣ⭮ ,  ࠬ - 
"⠭⭮" ).  ⨨ ᫥  室-
    ࠭  ⠫ ࠬ  ⠭-
,  ᯮ짮 ᪠  ᢮.

       ࠡ    ⥪   ⥬ 
 訡  ᫥騬 ,  뢠
 ६ WindowError:

    0 -  諠 ᯥ譮;
    1 - ९ ᯨ᪠ ᢮ ⥩;
    2 - ९ ᥣ⭮ ᪮ ;
    3 - ९ ⠭⭮ ᪮ ;
    4 - ⥪   ( ⨨ ).

     ஫   訡 室 -
  訡 ᫥ 맮 ᮮ⢥  ணࠬ  (
⮣     ᮧ 㭨ᠫ쭠 楤  ࠬ-
஢).

    ᬮਬ 䥩  WINDOW:

const
  WindBaseX: Integer = 16; { 饭    X  . }
  WindBaseY: Integer =  3; { 饭    Y  . }

  WindowError: Byte = 0;   {  訡 ࠡ⪨ ⥪  }
    { 0 - ଠ }
    { 1 - ९ ᯨ᪠ ᢮ ⥩ }
    { 2 - ९ ᥣ⭮ ᪮   }
    { 3 - ९ 筮 .  (⥪ ) }
    { 4 - ⥪   ( PopWindow) }

  FrameChars: string[8] = 'ͻȺ'; {  ࠬ }

type
  WindPtr = ^WindRec;  { ⥫   }

  WindRec = record   { ᠭ ࠬ஢  }
              x1,y1,x2,y2: Byte;  {  ᮧ.  }
              x,dx: Integer;      { . ࠧ ⥪.  }
              y,dy: Byte;
              BaseX,              { .   .}
              BaseY: Integer;
              CurX,CurY: Byte;    { न  }
              Dim: Byte;          { ୮  }
              BackGround,
              Color: Byte;        { 騥 梥 }
              Len: Integer;       {   }
              Head: SegBufPtr;    {    }
              Prev: WindPtr;      { .  ।. }
            end;

var
  LastWindow: WindPtr; { ⥫  ᫥  }
  SList: SegList;  { ᮪ ᥣ⮢  .. .  }
  FList: FreeList; { ᮪ ᢮ ᪨ ⥩ }


procedure Window (x1,y1,x2,y2: Byte);
  {-⠭ ᨬ쭮  }

procedure FullWindow;
  {-⠭    ࠭ }

function WindMinX: Byte;
  {- ࠭   ᨬ }

function WindMinY: Byte;
  {- ࠭   ᨬ }

function WindMaxX: Byte;
  {-ࠢ ࠭   ᨬ }

function WindMaxY: Byte;
  {- ࠭   ᨬ }

procedure Frame (x1,y1,x2,y2: Byte;
                 FrameBackGround,FrameColor,
                 HeaderBackGround,HeaderColor: Byte;
                 Header: ScreenLine);
  {-뢮 ࠬ                                     }
  { x1,y1,x2,y2 - न 㣫                  }
  { FrameBackGround, FrameColor   - 梥 ࠬ     }
  { HeaderBackGround, Headercolor - 梥  }
  { Header      -                          }

procedure FrameWindow (x1,y1,x2,y2: Byte;
                       FrameBackGround,FrameColor,
                       HeaderBackGround,HeaderColor: Byte;
                       Header: ScreenLine);
  {-뢮 ࠬ  ⠭    }

procedure PushWindow (x1,y1,x2,y2: Byte);
  {-⠭   ࠭   ⥪  }

procedure PushFrameWindow (x1,y1,x2,y2: Byte;
              FrameBackGround,FrameColor,
              HeaderBackGround,HeaderColor: Byte;
              Header: ScreenLine);
  {-뢮 ࠬ  ⠭    ࠭  }

procedure PopWindow;
  {-⠭ ᫥   ⥪  }


    樠஢ ६ FrameChars     8
ᨬ, ᯮ㥬   ᮢ ࠬ  楤 Frame,
FrameWindow, PushFrameWindow ( ᮢ ५, 稭  -
 孥 㣫).

    ६ LastWindow  㦥,   砫 믮-
 ணࠬ    ᢮ 祭 NIL.

    ६ SList ᯮ  ࠭ ᯨ᪠ ᥣ⮢
, ᯮ㥬      ⥪ ⥬,  FList - 
࠭ 㦥 ᯨ᪠ ᢮ ⥩ (⨯  Seglist  
FreeList ᠭ  㫥 SEGMEM).

    :   砫 믮 ணࠬ ६ SList 
FList   樠஢, ਬ:

    with SList do  { 樠 ᯨ᪠ ᥣ⮢ }
      begin
        N:=8;  { ᫮ ᯮ㥬 ᥣ⮢ }
        Seg[1]:=$1B; Seg[2]:=$1C; Seg[3]:=$1D; Seg[4]:=$1E;
        Seg[5]:=$1A; Seg[6]:=$19; Seg[7]:=$18; Seg[5]:=$17;
      end;
    { 樠 ᯨ᪠ ᢮ ⥩ }
    InitSegMem (SList,FList,WindowError);
    LastWindow:=nil; { 樠 ⥪  }
    if (WindowError<>0) then
       begin
         { 뤠 ᮮ饭  訡 }
         ...
         Halt;
       end;

     襭  ࠧࠡ뢠 ணࠬ  㪠
᫥⥫쭮 ஢      ଫ ⤥쭮
楤ன,  㦠  ࠧ襭   ᯮ짮-
 ᥣ⮢      ⥪⮢  䠩    
樠 ᥣ  .

        ।। ६  Wind-
BaseX = 16  WindBaseY = 3.  ६  ᬥ饭 
 ନ㥬   ᥫ  X  Y  ⭮⥫쭮  
孥 㣫  ࠭.    ⮬,   ࠧ  ࠭
(384x256  512x256 ᥫ)    ࠧࠬ  ⠭
ᨬ (6x10 ᥫ), - 祣   ࠭ -
⠥ ᯮ㥬.    ࠧ஬ 80x25 ᨬ  ᮮ-
騥 ࠧ   ᥫ  ᫥騥:  480x250.  
ᯥ祭 ॡ㥬 ᬥ饭   ⨥ , -
⥫쭮 ன ⢫  न X  Y. -
  ᮮ⢥ ᨬ쭠  (1,1).    ,
  ᨬ筮 ᯮ  480x250 ᥫ ᬥ-
   X   Y  ⠢ 16   3  ᥫ  ᮮ-
⢥.

    ࠢ쭥 뫮    樠஢  祭 WindBaseX 
WindBaseY  砫 믮 ணࠬ ᫥騬 ࠧ:

    Regs.A:=17; Call($F80C,Regs);
    WindBaseX:=Regs.DE; WindBaseY:=Regs.C;

    楤 Window  ।祭    ⠭ ᨬ쭮
  묨 न⠬  孥  ࠢ 
㣫  ⮬ ⥪饩  ,   ⮬   
ᮤন ࠭  ந室  뢮 ଠ樨.

    楤 FullWindow ⠭    ࠭ 
   .   楤   ᯮ짮 
⪨ ࠡ祩  ࠭ ( । ),   -
।   맮  室 ࠭ न ⥪饣 .
᫨ ஬ ⪨ ࠭  室 믮 㣨 -
 樨    ᥬ ࠭,  㫨 ६ WindBaseX 
WindBaseY.

    㭪樨 WindMinX,  WindMinY,  WindMaxX, WindMaxY 
ᨬ न ⥪饣  뢮.  ਭ   ᨬ-
   祭  Succ(WindMaxX-WindMinX),  -
 Succ(WindMaxY-WindMinY).

     㭪樨   ᯮ짮  ࠭  ࠧ-
஢ ⥪饣  । ४祭 ०, ஢ ࠭
 । 맮 楤 FullWindow, ਬ:

    ...
    x1:=WindMinX; y1:=WindMinY; x2:=WindMaxX; y2:=WindMaxY;
    FullWindow; ClrScr;
    Window (x1,y1,x2,y2);
    ...

    楤 Frame ନ ࠬ  ᨬ FrameChars (
⠭ )  㪠묨  梥⠬  䮭  FrameBackGround  
ࠦ FrameColor,   ⠪ 뢮  孥 ப ࠬ
 - ப Header  梥⠬ HeaderBackGround   Header-
Color.

    楤 FrameWindow ⠪  ࠬ,    -
⥫쭮  ⠭    頥   ࠬ.

    楤 PushWindow  筠  楤 Window,  
। ⠭  ᮤন ࠭  㣨 ࠬ -
࠭  ⥪ .  ᫥ 맮 楤 PushWindow -
室 ஠஢  WindowError  । ९
.

    楤 PushFrameWindow 筠 楤 FrameWindow,
 ⥫쭮 믮 ⠫  ⥪  ⠪ ,  
 PushWindow.

    楤 PopWindow ⠫    ⥪    ࠬ
᫥ ࠭   ⠭ ଠ樨 -
. ᫨ ⢮ 맮 PopWindow ॢᨫ ⢮  -
 PushWindow (PushFrameWindow),   ६ Windowerror
ନ ᮮ⢥騩  訡.   ᢮⢮ 㤮
ᯮ짮  ࠡ⪥ ⠫ 訡, ਬ:

    PushFrameWindow (...);
    if (WindowError<>0) then  {     }
       begin
         { ⠫   }
         repeat PopWindow until WindowError<>0;
         WriteLn ('९  !');
         Halt;
       end;


    ਬ ᯮ짮 ணࠬ  WINDOW  
 㫥 FILES.


                       4.4.  FONT
                       ----------------

     FONT  ।祭   ࠢ ⠬  -
஬. ᯮ  SCREEN.


type
  FontParm = record  { ࠬ  }
               Seg: Byte;
               Addr,             {   0..$3FFF     }
               PicStep: Integer; {  蠡          }
               PicLeftShift,     { 饭 蠡 0..7 }
               Width,Height,     { ਭ         }
               StepX,StepY,      {  뢮 ᨬ   }
               DispMode: Byte;   {  ⮡ࠦ     }
             end;

  CurParm  = record  { ࠬ  }
               Seg: Byte;
               Addr: Integer;    { .蠡. 0..$3FFF }
               PicLeftShift,     { 饭 蠡 0..7     }
               Width,Height,     { ਭ             }
               dx,dy,            { 饭  X  Y         }
               DispMode: Byte;   {  ⮡ࠦ         }
               ScrBuf: SegBufPtr;{ . .. .}
               BufLen: Integer;  {  .- 稭 R/O  }
             end;


procedure MemAddr (Seg: Byte; SegAddr: Integer;
                   var MemPage: Byte; var MemAddr: Integer);
  {-᫥     ᥣ    ᥣ }

procedure MoveToSeg (SourcePage: Byte; SourceAddr: Integer;
                     TargetSeg: Byte; TargetSegAddr,Len: Integer);
  {-뫪   㪠 ᥣ  }

procedure MoveFromSeg (SourceSeg: Byte; SourceSegAddr: Integer;
                       TargetPage: Byte; TargetAddr,Len: Integer);
  {-뫪   㪠 ᥣ  }

procedure SetFontParm (var FP: FontParm);
  {-⠭ ࠬ஢  }

procedure GetFontParm (var FP: FontParm);
  {-祭 ࠬ஢ ⥪饣  }

procedure SetCurParm (var CP: CurParm);
  {-⠭ ࠬ஢  }

procedure GetCurParm (var CP: CurParm);
  {-祭 ࠬ஢  }

function FontLen (Addr,PicStep: Integer; NumOfChars: Byte):
                                                   Integer;
  {-⭠ 楤 ।   }

function CharAddr (Addr,PicStep: Integer; C: Byte):
                                                   Integer;
  {-⭠ 楤 ।  ᨬ   }

function PicLen (Width,Height,PicLeftShift: Byte): Integer;
  {-।  蠡   }

function SetFont (BufAddr: Integer; Char1,Char2: Byte;
                  var FP: FontParm): Boolean;
  {-⠭                                      }
  { BufAddr -  ࠧ.蠡 ᨬ Char1-Char2 }
  { FP      - ࠬ                                }

function GetFont (BufAddr: Integer; Char1,Char2: Byte;
                  var FP: FontParm): Boolean;
  {-祭 ⥪饣                              }
  { BufAddr -  ࠧ. 蠡 ᨬ Char1-Char2 }
  { FP      - ࠬ                                 }

function SetCur (BufAddr: Integer; var CP: CurParm): Boolean;
  {-⠭   }
  { BufAddr -  ࠧ饭 蠡  }
  { CP      - ࠬ                 }

function GetCur (BufAddr: Integer; var CP: CurParm): Boolean;
  {-祭 ⥪饣  }
  { BufAddr -  ࠧ饭 蠡  }
  { CP      - ࠬ                 }

function UnpStdFont (Seg: Byte; addr: Integer; Coding: Byte;
                     Wide,High,Cursor,Activate: Boolean):
                                                     Boolean;
  {-ᯠ ⠭⭮       }
  { Seg, Addr - 㤠                    }
  { Coding - ஢ 0..3             }
  { Wide,High - ਧ ࠧ஢ 㪢  }
  { Cursor - ਧ ᯠ  }
  { Activate - ਧ ⨢樨    }

function StdFontLen (Wide,High,Cursor: Boolean): Integer;
  {- ⠭⭮            }
  { Wide,High - ਧ ࠧ஢ 㪢  }
  { Cursor - ਧ ᯠ  }

procedure NormalCursor;
  {-⠭ ⠭⭮    窨 }

procedure BlockCursor;
  {-⠭ ⠭⭮    אַ㣮쭨 }

procedure FatCursor;
  {-⠭ ⠭⭮ ⮫饭  }


    楤 MemAddr ᯮ    ᥣ-
 ( ᥣ,   ᥣ)   ࠭  (-
 ࠭,   ࠭).

    楤 MoveToSeg  MoveFromSeg ।祭    -
뫪   ᮮ⢥⢥      ࠭  
ᥣ  ,    ᥣ   ࠭,
 ⮬ 㪠뢠   ࠭  ᥣ   -
뫠  (1..$4000).  ᯮ짮  楤 
 묨   ६묨 ணࠬ  ⢥ ࠭ 
㪠뢠 祭 Port [$08],   ⢥  - 祭
Addr (६).

    楤 SetFontParm ᯮ  ⠭ ࠬ஢
 ,    ६ ⨯ FontParm.  楤
GetFontParm  믮  ⭮ ⢨ - 뢠 ࠬ
⥪饣   ६ ⨯ FontParm.

    楤 SetCurParm    GetCurParm  믮  
㭪樨    ᯮ짮 ६ ⨯ CurParm.

    楤 Piclen    蠡 ( )  -
 ਭ,   ᨬ ()  ᬥ饭  蠡
  ⮫ ⮢.

    㭪 SetFont ⠭  "稢" 
 ᨬ   Char1-Char2  ࠬࠬ  FP.  砫
 蠡  ("㤠")  ᨬ Char1  ࠬ஬
BufAddr. ᫨   ᨬ Char1-Char2  㬥-
  ᥣ, ।塞 ࠬ஬ FP,  㭪 -
頥 祭 False,  ⥪騩   .

    㭪 GetFont 믮 ⭮ ⢨ - 㦠 -
騩      BufAddr   ᨬ
Char1-Char2,   ࠬ 頥  FP. ᫨ 
 ᨬ  Char1-Char2   㬥頥  ᥣ,   㭪
頥 祭 False.

    㭪樨 SetCur  GetCur  㭪 SetFont   Get-
Font: 祭 BufAddr   蠡 , CP - -
 .

    㭪 UnpStdFont ᯠ뢠 ⠭   -
 Addr    ᥣ  Seg       ஢ Coding
(0-, 1-8, 2-7/2, 3-7/1). ਧ Wide (ப),
High (᮪)  ।  樨  ⨯ ࠧ-
஢ ᨬ;  ਧ Cursor ࠧ蠥 ᯠ ⠭⭮
, ਧ Activate ⨢ ᯠ -
 ( ).  ᫨   㬥頥  ᥣ,
 㭪 頥 祭 False.

    㭪 StdFontLen 뤠  ⠭⭮ -
  ࠧ (Wide, High)  ⮬ 蠡  (-
 Cursor=True).

    楤 NormalCursor  ⠭    -
, FatCursor  -      אַ㣮쭨  㬥襭  ,
BlockCursor -   אַ㣮쭨 ࠧ஬  . 
ਬ  楤 室,  ⮡  ⠭ 蠡-
 ⠭⭮ ,  ਬ, ᫥ ᯠ ⠭-
 .

    ᫨ ணࠬ   (),    砫 믮-
    ࠭ ࠬ ⥪饣  ()
 ᫥騬  ⮬.

    ᬮਬ ⮩ ਬ  ᨬ ''   -
 箪,   -  אַ㣮 ࠬ:


program Fokus;
{ == ਬ     == }
{$I Screen }
{$I Font }

type
  PicBuffer = array[1..10] of Byte;
const
  SpcPicture: PicBuffer =
                 ($12,$24,$08,$12,$24,$08,$12,$24,$00,$00);
  CurPicture: PicBuffer =
                 ($3f,$21,$21,$21,$21,$21,$21,$3f,$00,$00);
var
  SpcBuffer: PicBuffer;
  fp: FontParm;
  cp,cp1: CurParm;

begin
  {  ࠬ ᨬ   }
  GetFontParm(fp);
  GetCurParm(cp);
  if (fp.Width<>6) or (fp.Height<>10) then
     begin
       Writeln('⠭ !');
       Halt;
     end;

  { 塞 ࠬ  }
  cp1.Seg:=cp.Seg;
  cp1.Addr:=cp1.Addr+PicLen(6,10,2); {   蠡 }
  cp1.Width:=6; cp1.Height:=10; cp1.PicLeftShift:=2;
  cp1.dx:=0; cp1.dy:=0; cp1.DispMode:=cp.DispMode;

  Write(^J^M' ᨬ "": ');

  {  蠡 ᨬ "" }
  if GetFont(Addr(SpcBuffer),$20,$20,fp) then
  { ⠭  "" }
  if SetFont(Addr(SpcPicture),$20,$20,fp) then
  { ⠭   }
  if SetCur(Addr(CurPicture),cp1) then
     ReadLn;

  {  "" }
  if SetFont(Addr(SpcBuffer),$20,$20,fp) then
  {   }
  SetCurParm(cp);
end.


