unit Menu1;
{$I Sets.inc}

interface
procedure UserMenu;     { spousti uzivatelske menu }

{=======================================================================}

implementation
uses
  BMPTCh,               { data pouzite bitmapy - Tynsky chram           }

  F8x8c,                { data fontu 8x8                                }
  F12x16c,              { data fontu 12x16                              }

  G240x128,             { Grafika 240 x 128 pixelu                      }

  uAMenu,               { Abstraktni Menu                               }
  uMenuChr,             { Znakove Menu                                  }
  uMenuGr,              { Graficke Menu                                 }

  uATerm,               { Abstraktni terminal                           }
  uTermT10,             { Terminal TERM10                               }

 {$IFDEF SimPC}         { Je zapnut simulator TERM10 na obrazovce PC ?  }
  uSimT10,              { Simulator TERM10 na obrazovce a klavesnici PC }
 {$ELSE}
  uDispT10,             { Displej terminalu TERM10                      }
  uKeybT10,             { Klavesnice terminalu TERM10                   }
 {$ENDIF}
  uInit;                { Inicializace - pro priznak FlEnd              }


{-----------------------------------------------------------------------}


const

    DispStr     : String='';    { String pro vypis textu na display     }
    HlpStr      : String='';    { String pro help                       }
    GraphStr    : String='';    { String pro grafiku                    }
    BkBMP       : Integer=-1;   { Bitmapa pozadi                        }

{-----------------------------------------------------------------------}
type                    { Vyctovy typ jednotlivych menuobrazovek        }
  tSelector=(tMPozdrav,
             tMKonec
            );

const                   { Konstanta prvni a posledni menu-obrazovky     }
  BegMenu = tMPozdrav;
  EndMenu = tMKonec;

{-----------------------------------------------------------------------}
{               M e n u - o b r a z o v k y                             }
{-----------------------------------------------------------------------}

procedure pMPozdrav(P: pMenuGr); far;       { TERM10 vas zdravi         }

begin
  with P^ do
  begin
    if ChangeMenu then          { Doslo k zmene Menu-obrazovky ?        }
    begin
      BkBmp     :=-1;           { Nastaveni pozadi -1= prazdne          }
                                { Formatovany text pro vypis            }
      DispStr   :=zESC+ 'F1,20,40;' +'TERM10 vás zdraví';
                                { Formatovany text pro help             }
      HlpStr    :=zESC+'F1,60,12;'  +'NÁPOVĚDA';

      GraphStr  :='R(2,2,237,125)';
    end;
  end;
end;

{-----------------------------------------------------------------------}

procedure pMKonecThird(P: pMenuGr); far;  { Procedura pro ukonceni      }
begin              { Doslo-li k stisku [Q] nastavi se priznak ukonceni  }
  if p^.ActChar='Q' then FlgEnd:=True;
end;



procedure pMKonec(P: pMenuGr); far;       { Tynsky chram , Quit         }
begin
  with P^ do
  begin
    if ChangeMenu then          { Doslo k zmene Menu-obrazovky ?        }
    begin
      BkBMP:=0;                 { Nastaveni pozadi 0 = Tynsky chram     }
                                { Formatovany text pro vypis            }
      DispStr:=zESC+'F0,190,110;' +'Quit';
                                { Formatovany text pro help             }
      HlpStr :=zESC+'F0,40,45;'    +'   Stisk Q ukončí   '+
                                    '       program      ';
                                { Grafika - nic                         }
      GraphStr:='';
      AddTerminateChar(['Q']);  { Pridani ukoncovaci klavesy            }
                                { Instalace procedury pro ukonceni      }
      SetUserThird(Addr(pMKonecThird));
    end;
  end;
end;

{-----------------------------------------------------------------------}
{-----------------------------------------------------------------------}

const                           { Pole procedur menu-obrazovek          }
ProcPtrArray  :array [tSelector] of tMMenuGr =
             (
             pMPozdrav,
             pMKonec
             );


{-----------------------------------------------------------------------}

const                   { Adresa terminalu TERM10 v IO prostoru         }
 {$ifdef SimPC}
  AdrTerm =$300;
 {$else}
  {$ifdef VerPC}
  AdrTerm =$300;
  {$endif}
 {$endif}

 {$ifdef VerMc}
  AdrTerm =$2300;
 {$endif}
                        { Nastaveni parametru terminalu                 }
  sParTerm='CMODE=2 CCHAR='+#$80+' REF=ON';

                        { Definice procesu Tick  - viz o.s.RETOS        }
  TermName  = 'TICK';   { Jmeno procesu                                 }
  TermStk   = 8000;     { Velikost zasobniku procesu                    }
  TermSPrio = 99;       { Staticka priorita                             }
  TermDPrio = 254;      { Dynamicka priorita                            }

                        { Definice procesu Menu                         }
  Menuname  = 'MENU';   { Jmeno procesu                                 }
  MenuStk   = 8000;     { Velikost zasobniku procesu                    }
  MenuSPrio = 101;      { Staticka priorita                             }
  MenuDPrio = 254;      { Dynamicka priorita                            }

{-----------------------------------------------------------------------}

procedure UserMenu;
var pMyMenu  :pMenuGr;  { Ukazatel na objekt uzivatelskeho menu         }
    pMyTerm  :pTermT10; { Ukazatel na objekt terminalu                  }

begin
 {$IFDEF SimPC}         { Je zapnut simulator TERM10 na obrazovce PC ?  }
                        { Inicializace simulatoru terminalu TERM10 }
  pMyTerm:=New(pTermT10,Init(New(PSimDispT10,Init(nil,20,6,AdrTerm,true,
                                                0,0,2,2,265,165,False)),
                             New(PSimKeybT10,Init(nil,20,AdrTerm,FlgEnd)),
                             AdrTerm,nil,nil));

 {$ELSE}                { Neni zapnut simulator TERM10 na obrazovce PC  }
                        { Inicializace terminalu TERM10                 }
  pMyTerm:=New(pTermT10,Init(New(PDispT10A,Init(nil,20,6,AdrTerm,True)),
                             New(PKeybT10,Init(nil,20,AdrTerm)),
                             AdrTerm,nil,nil));
 {$ENDIF}
                        { Nastaveni parametru terminalu                 }
  pMyTerm^.SetTDispParam(sParTerm);
                        { Inicializace menu                             }
  pMyMenu:=New(pMenuGr,Init(@ProcPtrArray,
                            ord(EndMenu),
                            DispStr,
                            HlpStr,
                            GraphStr,
                            @BkBMP,
                            pMyTerm,
                            '',
                            2));
                        { Spusteni menu                                 }
  InitRunMenu(pMyMenu,
              MenuName,MenuStk,MenuSPrio,MenuDPrio,
              TermName,TermStk,TermSPrio,TermDPrio,
              2,2,
              edNop,edNop,
              FlgEnd);

end;

{-----------------------------------------------------------------------}

procedure InitializeBMPs;
var Lng:word;

                        { Prirazeni adresy bitmapy s Tynskym chramem    }
begin                   { do pole ukazatelu na uzivatelske bitmapy.     }
  User_BkBMPs[0].AssignBMPAddr(GetBMPAddr_BMPTCH(Lng),Lng);
end;

{-----------------------------------------------------------------------}
const
 { Identifikatory typu pouzitych fontu }
    cF8x8c    = 0;
    cF12x16n  = 1;

{-----------------------------------------------------------------------}

procedure InitializeAppFonts;       { Inicializace fontu                }
var   PomLng  :word;
begin
  { Inicializace pole zobrazovacich procedur }
  with User_FontArray[cF8x8c   ] do
  begin
    P:=pViewFont08x08;
    U:=GetFontAddr_F8x8c(PomLng);
  end;

  with User_FontArray[cF12x16n ] do
  begin
    P:=pViewFont12x16;
    U:=GetFontAddr_f12x16c(PomLng);
  end;
end;

Begin
  InitializeAppFonts;               { Inicializace bitmap               }
  InitializeBMPs;                   { Inicializace fontu                }
End.

