Program Configur;

Uses Dos,Extense,Crt,Records,CfgScrn;

Const Menu1 : Array[1..6] of String[50] =
('[ ..|07..|15. |07Main Config |15.|07..|08.. ]',
 '[ .|07.|15. |07System Settings |15.|07.|08. ]',
 '[ |15.|07 Modem Configuration |15. |08]',
 '[ |08.|07.|15. |07Directory Setup |15.|07.|08. ]',
 '[ |08.|07.|15. |07Passwords Setup |15.|07.|08. ]',
 '[ |08..|07..|15. |07Exit Config |15.|07..|08.. ]');

Menu2 : Array[1..17] of String[50] =
        ('[. BBS Long Name .........>',
         '[. BBS Short Name ........>',
         '[. Telephone Number ......>',
         '[. Registration Code .....>',
         '[. Node Number ...........>',
         '[. Total Nodes ...........>',
         '[. Default UserNote ......>',
         '[. Use Newuser Voting.....>',
         '[. Use SysOp Password.....>',
         '[. Chat Passwd Level......>',
         '[. SysOp Passwd Level.....>',
         '[. Recent Callers Level...>',
         '[. Time System Opens .....>',
         '[. Time System Closes ....>',
         '[. Votes to be Validated .>',
         '[. Votes to be Deleted ...>',
         '[. New Users Leave Note ..>');

Menu3 : Array[1..17] of String[50] =
        ('[. Validated Level .......>',
         '[. Maximum Chat Requests .>',
         '[. Use Credit System......>',
         '[. ew              .......>',
         '[.             ...........>',
         '[.             ...........>',
         '[.                   .....>',
         '[.                   .....>',
         '[.                   .....>',
         '[.                  ......>',
         '[.                   .....>',
         '[.                     ...>',
         '[.                   .....>',
         '[.                    ....>',
         '[.                       .>',
         '[.                     ...>',
         '[.                      ..>');

Var Active,X : Byte;
    CH : Char;
    Hour,Minute,Second,Msec : Word;


Procedure ClearWindow;
Begin
 Window(7,4,73,17);
 ClrScr;
 Window(1,1,80,25);
End;

Procedure Header(Menu : Byte);
Var Hour,Minute,Second,MSEc : Word;
    Marker : Char;
   Description : String;
Begin
 Case Menu of
  1 : Qwrite(13,3,'Configuration Branch     ',15,3,80);
  2 : Qwrite(13,3,'Main System Configuration',15,3,80);
 End;
 GetTime(Hour,Minute,Second,MSec);
 If Hour > 12 then
  Begin
   Dec(Hour,12);
   Marker := 'p';
  End else Marker := 'a';
 Qwrite(61,3,LeadingZero(Hour)+':'+LeadingZero(Minute)+Marker+'m',15,3,80);
 Qwrite(43,3,'Page <'+Strr(Menu)+'/5>',15,3,80);
 Case Menu of
  1 : Case Active of
       1 : Description := 'Settings Vital to the Opperation of the BBS';
       2 : Description := 'System Variable Settings';
       3 : Description := 'Modem Communications Settings';
       4 : Description := 'Directory and File Locations';
       5 : Description := 'Password Settings';
       6 : Description := 'Save Changes and Exit to Dos';
      End;
 End;
 WaitRetrace;
 FillWord(Mem[$b800:(18*160)+(11*2)],57,$3020);
End;

Procedure Write_Config;
Begin
 Rewrite(ConfigF);
 With Config do
   Begin
    Writeln(ConfigF,LongName);
    Writeln(ConfigF,Shortname);
    Writeln(ConfigF,SysOpName);
    Writeln(ConfigF,BoardPhone);
    Writeln(ConfigF,RegistrationCode);
    Writeln(ConfigF,NodeNumber);
    Writeln(ConfigF,TotalNodes);
    Writeln(ConfigF,DefaultUserNote);
    If Use_NUV then Writeln(COnfigF,'TRUE') else Writeln(ConfigF,'FALSE');
    If Use_SPW then Writeln(COnfigF,'TRUE') else Writeln(ConfigF,'FALSE');
    {----------------------- Passwords & Shit ----------------------}
    Writeln(ConfigF,NUPS[1]);
    Writeln(ConfigF,NUPS[2]);
    Writeln(ConfigF,NUPS[3]);
    Writeln(ConfigF,NUPS[4]);
    Writeln(ConfigF,NUPS[5]);
    Writeln(ConfigF,NUPAccess[1]);
    Writeln(ConfigF,NUPAccess[2]);
    Writeln(ConfigF,NUPAccess[3]);
    Writeln(ConfigF,NUPAccess[4]);
    Writeln(ConfigF,NUPAccess[5]);
    Writeln(ConfigF,SystemPW);
    Writeln(ConfigF,BadBaudPW);
    Writeln(ConfigF,ShellPW);
    Writeln(ConfigF,ExitPW);
    Writeln(ConfigF,SysOpPW);
    Writeln(ConfigF,ChatPW);
    {------------------------- Directory Shit ----------------------}
    Writeln(ConfigF,Quantum_dir);
    Writeln(ConfigF,Text_dir);
    Writeln(ConfigF,Board_Dir);
    Writeln(ConfigF,Data_Dir);
    Writeln(ConfigF,Textfile_dir);
    Writeln(ConfigF,Door_dir);
    Writeln(ConfigF,work_dir);
    Writeln(ConfigF,Extract_dir);
    {-------------------------- Modem Shit -------------------------}
    Writeln(ConfigF,Comport);
    Writeln(ConfigF,LockBaud);
    Writeln(ConfigF,LowestBaud);
    Writeln(ConfigF,AnswerStr);
    Writeln(ConfigF,InitStr);
    End;
  Close(ConfigF);
End;

Procedure Read_Config;
Var Temp : String;
Begin
 Reset(ConfigF);
 With Config do
  Begin
    Readln(ConfigF,LongName);
    Readln(ConfigF,Shortname);
    Readln(ConfigF,SysOpName);
    Readln(ConfigF,BoardPhone);
    Readln(ConfigF,RegistrationCode);
    Readln(ConfigF,NodeNumber);
    Readln(ConfigF,TotalNodes);
    Readln(ConfigF,DefaultUserNote);
    Readln(ConfigF,Temp);
    If Pos('T',Temp) <> 0 then Use_NUV := True else Use_NUV := False;
    Readln(ConfigF,Temp);
    If Pos('T',Temp) <> 0 then Use_SPW := True else Use_SPW := False;
    {----------------------- Passwords & Shit ----------------------}
    Readln(ConfigF,NUPS[1]);
    Readln(ConfigF,NUPS[2]);
    Readln(ConfigF,NUPS[3]);
    Readln(ConfigF,NUPS[4]);
    Readln(ConfigF,NUPS[5]);
    Readln(ConfigF,NUPAccess[1]);
    Readln(ConfigF,NUPAccess[2]);
    Readln(ConfigF,NUPAccess[3]);
    Readln(ConfigF,NUPAccess[4]);
    Readln(ConfigF,NUPAccess[5]);
    Readln(ConfigF,SystemPW);
    Readln(ConfigF,BadBaudPW);
    Readln(ConfigF,ShellPW);
    Readln(ConfigF,ExitPW);
    Readln(ConfigF,SysOpPW);
    Readln(ConfigF,ChatPW);
    {------------------------- Directory Shit ----------------------}
    Readln(ConfigF,Quantum_dir);
    Readln(ConfigF,Text_dir);
    Readln(ConfigF,Board_Dir);
    Readln(ConfigF,Data_Dir);
    Readln(ConfigF,Textfile_dir);
    Readln(ConfigF,Door_dir);
    Readln(ConfigF,work_dir);
    Readln(ConfigF,Extract_dir);
    {-------------------------- Modem Shit -------------------------}
    Readln(ConfigF,Comport);
    Readln(ConfigF,LockBaud);
    Readln(ConfigF,LowestBaud);
    Readln(ConfigF,AnswerStr);
    Readln(ConfigF,InitStr);
  End;
 Close(ConfigF);
End;

Procedure MainConfig;
Var TopQues,ActQues : Byte;
    Gay : Byte;
    Answers : Array[1..17] of String[80];
    TempS : String;
Begin
 Fillchar(Answers,SizeOf(Answers),#0);
 Answers[1] := Config.LongName;
 Answers[2] := Config.ShortName;
 Answers[3] := Config.BoardPhone;
 Answers[4] := Config.RegistrationCode;
 Answers[5] := Strr(Config.nodeNumber);
 Answers[6] := Strr(Config.TotalNodes);
 Answers[7] := Config.DefaultUserNote;
 If Config.Use_NUV then Answers[8] := 'Yes' else Answers[8] := 'No ';
 If Config.Use_SPW then Answers[9] := 'Yes' else Answers[9] := 'No ';
 TopQues := 1;
 ActQues := 1;
 CH := #0;
 ClearWindow;
 Repeat
  Header(2);
  For X := 1 to 13 do
   Begin
    If X = ActQues then
     Begin
      QWrite(7,4+X,Padstring(Menu2[TopQues+X-1],27),7,0,80);
      GotoXy(35,4+X);PipeWrite(Answers[TopQues+X-1],True);
      For Gay := WhereX to 77 do Write(' ');
     End else
     Begin
      QWrite(7,4+X,Padstring(Menu2[TopQues+X-1],27),8,0,80);
      GotoXy(35,4+X);PipeWrite(Answers[TopQues+X-1],False);
      For Gay := WhereX to 77 do Write(' ');
     End;
   End;
  CH := Readkey;If CH = #0 then CH := Readkey;
  Case CH of
   #13 : Case ActQues of
        1,2 : Begin
               GotoXy(35,4+actques);
               Inputln(TempS,40,False,False,answers[actques]);
               Nocursor;
               If (TempS <> 'Aborted') and (TempS <> '') then Answers[actques] := TempS;
              End;
          8 : If Answers[8] = 'Yes' then Answers[8] := 'No' else
                       answers[8] := 'Yes';
          9 : If Answers[9] = 'Yes' then Answers[9] := 'No' else
                       answers[9] := 'Yes';
         End;
   #72 : If ActQues > 1 then Dec(ActQues) else If TopQues > 1 then Dec(Topques);
   #80 : If ActQues+TopQues-1 < 17 then
          Begin
           If ActQues < 13 then Inc(ActQues) else Inc(TopQues);
          End;
  End;
 Until CH = #27;
End;

Procedure ShowScreen;
Var
 pallette : Array[0..63,1..3] of byte;
 vga_font : Array[1..4096] of char;
 X : Byte;
Procedure Set_Vga_Font;
Var Regs : Registers;
Begin
 regs.bx:= 4096;          {16 scanline font}
 regs.es:= seg(VGA_Font); {segment of the font data}
 regs.bp:= ofs(VGA_Font); {offset of the font data}
 regs.ax:= 4368;          {int 10h subfunction}
 regs.cx:= 256;           {256 characters}
 regs.dx:= 0;             {start with char #0}
 Intr(16, Regs);          {load actual data $10}
End;
Begin
 MovW(Mem[Seg(cfg):0001],Pallette,Sizeof(pallette) shr 1);
 For X := 0 to 63 do
    VGA_SetPallette(X,pallette[X,1],pallette[X,2],pallette[X,3]);
 VGA_GrabPallette;
 movW(Mem[Seg(cfg):0193],Vga_Font[1],2048);
 Set_VGA_Font;
 Fastmove(Mem[Seg(cfg):4289],Mem[$b800:0000],160*23);
End;

Var Marker : Char;
   Description : String[80];

Begin
 Assign(ConfigF,'QUANTUM.CFG');
 {$I-} Reset(ConfigF); {$I+}
 If IOResult <> 0 then
  Begin
   Writeln('þ Creating Default Configuration...'#10#13);
   With Config Do
    Begin
      LongName   := 'No Fly Zone';
      Shortname  := 'NFZ';
      SysOpName  := 'Sudden Death';
      BoardPhone := '606-342-5081';
      RegistrationCode := '00000000000000000000';
      NodeNumber := 1;
      TotalNodes := 1;
    {----------------------- Passwords & Shit ----------------------}
      NUPS[1] := 'NEWUSER';
      NUPS[2] := '';
      NUPS[3] := '';
      NUPS[4] := '';
      NUPS[5] := '';
      NUPAccess[1] := 10;
      NUPAccess[2] := 0;
      NUPAccess[3] := 0;
      NUPAccess[4] := 0;
      NUPAccess[5] := 0;
      SystemPW  := 'LETMEIN';
      BadBaudPW := 'TOO SLOW!';
      ShellPW   := 'SHELL';
      ExitPW    := 'EXIT';
      SysOpPW   := 'SYSOP';
      ChatPW    := 'EMERGENCY';
    {------------------------- Directory Shit ----------------------}
      Quantum_dir  := 'C:\QUANTUM\';
      Text_dir     := 'C:\QUANTUM\TEXT\';
      Board_Dir    := 'C:\QUANTUM\BOARDS\';
      Data_Dir     := 'C:\QUANTUM\DATA\';
      Textfile_dir := 'C:\QUANTUM\TEXTFILE\';
      Door_dir     := 'C:\QUANTUM\DOORS\';
      work_dir     := 'C:\QUANTUM\WORK\';
      Extract_dir  := 'C:\QUANTUM\EXTRACT\';
    {-------------------------- Modem Shit -------------------------}
      Comport     := 2;
      LockBaud    := 57600;
      LowestBaud  := 9600;
      AnswerStr   := 'ATA';
      InitStr     := 'ATZS0=0';
    End;{With Config}
    Write_Config;
  End;
 Read_Config;
 ClearScreen;
 Active := 1;
 ShowScreen;
 Nocursor;
 VGA_Set8x16Font;
 Repeat
  Header(1);
  WaitRetrace;
  FillWord(Mem[$b800:(18*160)+(11*2)],57,$3020);
  Qwrite(40 - (Length(Description) div 2),19,Description,15,3,80);
  For X := 1 to 6 do
   If Active = X then
     Begin
      GotoXy(26,8+X);

      TEXTBACKGROUND(1);

      PipeWrite(Menu1[X],True);
     End else
     Begin
      GotoXy(26,8+X);
      Textcolor(8);
      TEXTBACKGROUND(0);
      PipeWrite(Menu1[X],False);
     End;
  CH := #0;
  If Keypressed then Getkeys(CH,CH);
  Case CH of
    #72 : If Active > 1 then Dec(Active);
    #80 : If Active < 6 then Inc(Active);
    #13 : Begin
           Case Active of
            1 : MainConfig;
            2 : Break;
            3 : Break;
            4 : Break;
            5 : Break;
            6 : Break;
          End;
          ClearWindow;
         End;
   End;
 Until 0 = 1;
 Asm mov ax,3; int 10h; end;
End.



