Hi Roland,
That looks like an interesting version of ms pac man. I would like to see you port it to freepascal/lazarus. Turbo Pascal 16 color modes store bitmaps in a planar mode. Just like EGA\VGA hardware specs describe. Also Turbo Pascal and Turbo C remap the plane/color order to make it even more confusing.
Freepascal stores the bitmaps for putimage slightly different. I have modified the advance unit to do an on the fly conversion when you BLoad the image. This way you don't need to convert every single image. You can if you like - just bsave the new converted image.
unit Advanced;
{ Advanced Routines Unit, Version 1.0, Copyright 1996 by George M. Tzoumas }
interface
procedure BSave(FN: String; P: Pointer; Length: Word);
procedure BLoad(FN: String; var P: Pointer);
implementation
const
MaxWidth = 2047;
type
BLine = Array [0..MaxWidth] of Byte;
WLine = Array [0..MaxWidth] of Word;
TPImgRec = Record
width,height : word;
Buf : array[0..10000] of byte;
end;
FPImgRec = Record
width,height,reserved : longint;
Buf : array[0..10000] of word;
end;
var
BorlandColorMap : array[0..15] of Word = (0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15);
Function BitOn(Position,Testbyte : Byte) : Boolean;
Var
Bt : Byte;
Begin
Bt :=$01;
Bt :=Bt Shl Position;
Biton :=(Bt And Testbyte) > 0;
End;
Function BytesPerRow(width : word) : Word;
begin
BytesPerRow :=(width+7) div 8;
end;
Procedure mpTOsp(Var mPlane : bLine;Var splane : wLine;BPR : Word);
Var
i,j : Word;
xpos : Word;
Col : Word;
ImgOff2,ImgOff3,ImgOff4 : Word;
begin
ImgOff2:=BPR;
ImgOff3:=BPR*2;
ImgOff4:=BPR*3;
xpos:=0;
FillChar(splane,SizeOf(sPlane),0);
For i:=0 to ImgOff2-1 do
begin
For j:=7 downto 0 do
begin
Col:=0;
if biton(j,mPlane[i]) then
begin
Inc(Col,1);
end;
if biton(j,mPlane[i+ImgOff2]) then
begin
Inc(Col,2);
end;
if biton(j,mPlane[i+ImgOff3]) then
begin
Inc(Col,4);
end;
if biton(j,mPlane[i+ImgOff4]) then
begin
Inc(Col,8);
end;
// Splane[xpos]:=Col;
Splane[xpos]:=BorlandColorMap[Col];
Inc(xpos);
end;
end;
end;
procedure BSave(FN: String; P: Pointer; Length: Word);
var
F: File;
begin
Assign(F, FN);
Rewrite(F, Length);
BlockWrite(F, P^, 1);
Close(F);
end;
Procedure TPImageToFPImage(var P : Pointer;PSize : LongInt);
var
FPImgPtr : ^FPImgRec;
TPImgPtr : ^TPImgRec;
bbuf : bline;
wbuf : wline;
pos,pos2 : word;
width,height : word;
BPR : word;
NP : Pointer;
NPSize : longint;
i,j : word;
begin
TPImgPtr:=P;
width:=TPImgPtr^.width+1;
height:=TPImgPtr^.height+1;
BPR:=BytesPerRow(width);
NPSize:=12+ (BPR*4*2)*height;
GetMem(NP, NPSize);
FPImgPtr:=NP;
FPImgPtr^.width:=width;
FPImgPtr^.height:=height;
FPImgPtr^.reserved:=0;
pos:=0;
pos2:=0;
For i:=1 to height do
begin
Move(TPImgPtr^.Buf[pos],bbuf,BPR*4);
mpTosp(bbuf,wbuf,BPR);
Move(wbuf,FPImgPtr^.Buf[pos2],width*2);
inc(pos,BPR*4);
inc(pos2,width);
end;
FreeMem(P,PSize);
P:=NP;
end;
procedure BLoad(FN: String; var P: Pointer);
var
F: File;
FSize : LongInt;
begin
Assign(F, FN);
Reset(F, 1);
FSize:= FileSize(F);
GetMem(P, FSize );
BlockRead(F, P^, FSize);
Close(F);
TPImageToFPImage(P,FSize);
end;
end.