From S_ROHRBACHER@iravcl.ira.uka.de Tue Sep 15 11:28:22 1992
Return-Path: <S_ROHRBACHER@iravcl.ira.uka.de>
Received: from iraun1.ira.uka.de by ludvig.solan.unit.no with SMTP 
	id <AA11225>; Tue, 15 Sep 1992 11:28:06 +0200
Received: from iravcl.ira.uka.de by iraun1.ira.uka.de with SMTP (PP) 
          id <23536-0@iraun1.ira.uka.de>; Tue, 15 Sep 1992 10:36:45 +0200
Received: from IRAVCL.IRA.UKA.DE by IRAVCL.IRA.UKA.DE (PMDF #3198 ) 
          id <01GOT6UL2LAOAEL0RU@IRAVCL.IRA.UKA.DE>;
          Tue, 15 Sep 1992 10:38:40 MET
Date: 15 Sep 1992 10:38:40 +0100 (MET)
From: KAI ROHRBACHER <S_ROHRBACHER@iravcl.ira.uka.de>
Subject: Regarding last mail...
To: robert@solan.unit.no
Message-Id: <01GOT6UL2UXUAEL0RU@IRAVCL.IRA.UKA.DE>
X-Vms-To: IN%"robert@solan.unit.no"
Mime-Version: 1.0
Content-Transfer-Encoding: 7BIT
X-Charset: ISO_8859-1
X-Char-Esc: 29
Status: OR

Hi Robert,

command back! After hacking some hours, I found out what was wrong with
my short demo program:
a) I oversaw that port $3c1 is only for reading
b) I forgot to reenable the attribute controller after programming it
c) I had to unlock the write protection for the CRT-controller
Now as I *hate* doing work twice, I wrote a small program which reads in
a parameter file of tweak and produces as output an TurboPascal procedure
which switches into that mode. Feel free to include that file into a next
version of TWEAK, if you like:

PROGRAM generate_InitModeProc;
{Purpose  : Generates a TurboPascal procedure to initialize a tweaked}
{           VGA-video mode from TWEAK's parameter files              }
{Author   : Kai Rohrbacher    }
{Language : TurboPascal 6.0   }
{Date     : 11.09.1992        }
{Remarks  : Should work with all TP versions >= 4.0                  }

USES Dos;
TYPE data=ARRAY[0..35] OF BYTE; {data files of TWEAK}
VAR a:data;
    fin:FILE OF BYTE;
    f:TEXT;
    fname:STRING;
    i:BYTE;

function hexbyte(zahl:BYTE):STRING;
var i,j:byte;
begin
 i:=zahl mod 16+48; if i>$39 then inc(i,7);
 j:=zahl div 16+48; if j>$39 then inc(j,7);
 hexbyte:=chr(j)+chr(i)
end;

function hexword(zahl:WORD):STRING;
begin
 hexword:=hexbyte(hi(zahl))+hexbyte(lo(zahl))
end;

PROCEDURE produce_proc;
VAR i,j:BYTE;
BEGIN
 j:=0; {counter for byte index}
 WRITELN(f,'PROCEDURE SetMode;');
 WRITELN(f,'{ This procedure will set the VGA into mode '+fName+' }');
 WRITELN(f,'VAR dummy:BYTE;');
 WRITELN(f,'BEGIN');
 WRITELN(f,' port[$3C2]:=$'+hexbyte(a[j])+';'); inc(j);
 WRITELN(f,' inline($FA); {CLI}');
 WRITELN(f,' port[$3D4]:=$11; port[$3D5]:=port[$3D5] AND $7F;'+
         ' {unlock CRT-registers}');
 WRITELN(f,' inline($FB); {STI}');
 FOR i:=0 TO 9 DO
  BEGIN
   WRITELN(f,' portw[$3D4]:=$'+hexword(a[j] SHL 8 +i)+';');
   inc(j);
  END;
 FOR i:=$10 TO $17 DO
  BEGIN
   WRITELN(f,' portw[$3D4]:=$'+hexword(a[j] SHL 8 +i)+';');
   inc(j);
  END;
 FOR i:=1 TO 4 DO
  BEGIN
   WRITELN(f,' portw[$3C4]:=$'+hexword(a[j] SHL 8 +i)+';');
   inc(j);
  END;
 FOR i:=0 TO 3 DO
  BEGIN
   WRITELN(f,' portw[$3CE]:=$'+hexword(a[j] SHL 8 +i)+';');
   inc(j);
  END;
 FOR i:=5 TO 8 DO
  BEGIN
   WRITELN(f,' portw[$3CE]:=$'+hexword(a[j] SHL 8 +i)+';');
   inc(j);
  END;
 WRITELN(f,' inline($FA); {CLI}');
 WRITELN(f,' dummy:=port[$3DA]; {set flipflop into address mode}');
 FOR i:=$10 TO $14 DO
  BEGIN
   WRITELN(f,' port[$3C0]:=$'+hexbyte(i)+'; port[$3C0]:=$'+hexbyte(a[j])+';');
   inc(j);
  END;
 WRITELN(f,' port[$3C0]:=$20; {reenable attribute controller}');
 WRITELN(f,' inline($FB); {STI}');
 WRITELN(f,'END;');
END;

PROCEDURE Help;
BEGIN
 WRITELN;
 WRITELN('You must call this program with two parameters, the '+
         'first one specifying the');
 WRITELN('parameter file of TWEAK you want to use, the second '+
         'one specifying the name of');
 WRITELN('the text file to be produced, e.g.:');
 WRITELN;
 WRITELN(ParamStr(0)+' 432x600.256 initproc.pas');
 halt;
END;

BEGIN
 IF ParamCount<>2
  THEN Help
  ELSE BEGIN
        {$I-}
        Assign(fin,ParamStr(1));
        Reset(fin);
        IF (IOResult<>0) OR (FileSize(fin)<>SizeOf(Data)) THEN Help;
        i:=0;
        WHILE NOT EOF(fin) DO
	 BEGIN
          READ(fin,a[i]);
          inc(i)
         END;
        Close(fin);
        fname:=ParamStr(2);
        Assign(f,fname);
        Rewrite(f);
        IF IOResult<>0 THEN Help;
        produce_proc;
        Close(f);
        {$I+}
        IF IOResult=0
         THEN WRITELN('Done!')
         ELSE WRITELN('??? Error occured during write attempt!');
       END;
END.


cu,
   Kai

+--------------------------------------------+-------------------------------+
|Kai Rohrbacher, University Karlsruhe/Germany| "Be patient - half the people |
|email: S_ROHRBACHER@IRAVCL.IRA.UKA.DE,      |  in the world are below       |
|       UKB8@DKAUNI2.BITNET,  2:241/7521.7   |  average!"                    |

