Forum > Graphics

Convert pictures of a Turbo Pascal program ported to ptcGraph

(1/6) > >>

Roland57:
Hello!

I am trying to port to ptcGraph a Turbo Pascal game, a Pacman clone (by George M. Tzoumas) that I found here.

My code compiles and runs, but the screen is black. I think that pictures need to be converted. I wrote a little program to convert one picture, but the result is bad. Could you help me to find what I am doing wrong?

Regards.

Roland

retronick:
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.

--- Code: ---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.

--- End code ---

lucamar:
For gods sake, please use code tags or learn to share larger pieces of code! ;)

Roland57:
@retronick

Thank you for your message and for your adaptation of the Advanced unit.

I had to modify this line to compile the code. I don't know if my modification has sense.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---     if biton(j,mPlane[i]) then // <---
After that the program can be compiled but here, it crashes.


--- Quote ---Loading ...An unhandled exception occurred at $0000000000422608:
EAccessViolation: Access violation
$0000000000422608
$0000000000474991  BLOAD,  line 155 of advanced.pas

--- End quote ---

Did you manage, on your side, to run the program?

ASAP I will try to use your code for the little test program, which is made for displaying a single (strawberry) image.

Regards.

Roland 

retronick:
I think it got mangled - I have attached a zip version.

I was also calculating the memory size wrong.

I was able to compile the original TP code to the point where it was displaying the pacman and ghost properly but the maze was messed up.

Try it with just a small test program to see if this code works better.

Navigation

[0] Message Index

[#] Next page

Go to full version