Skip to content

Commit

Permalink
Update to 1.03
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldholdsworth committed Feb 22, 2022
1 parent d9ee9b8 commit 15df5d1
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 112 deletions.
17 changes: 2 additions & 15 deletions Lazarus Source/MainUnit.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ object MainForm: TMainForm
Top = 23
Width = 754
AllowDropFiles = True
Caption = 'UEF Reader 1.02 by Gerald J Holdsworth'
Caption = 'UEF Reader 1.03 by Gerald J Holdsworth'
ClientHeight = 855
ClientWidth = 754
Color = 14737632
OnDropFiles = FormDropFiles
LCLVersion = '2.0.12.0'
LCLVersion = '2.2.0.4'
object Report: TMemo
Left = 0
Height = 655
Expand All @@ -18,7 +18,6 @@ object MainForm: TMainForm
Align = alClient
BorderStyle = bsNone
Font.Name = 'Courier New'
Lines.Strings = ( )
ParentColor = True
ParentFont = False
ReadOnly = True
Expand Down Expand Up @@ -66,7 +65,6 @@ object MainForm: TMainForm
Top = 0
Width = 139
Caption = 'File loading progress:'
ParentColor = False
end
object Panel3: TPanel
Left = 0
Expand All @@ -85,7 +83,6 @@ object MainForm: TMainForm
Align = alClient
BorderStyle = bsNone
Font.Name = 'Courier New'
Lines.Strings = ( )
ParentColor = True
ParentFont = False
ReadOnly = True
Expand All @@ -110,7 +107,6 @@ object MainForm: TMainForm
Alignment = taRightJustify
AutoSize = False
Caption = 'Chunk ID:'
ParentColor = False
end
object Label3: TLabel
Left = 0
Expand All @@ -120,7 +116,6 @@ object MainForm: TMainForm
Alignment = taRightJustify
AutoSize = False
Caption = 'Chunk Length:'
ParentColor = False
end
object Label4: TLabel
Left = 0
Expand All @@ -130,7 +125,6 @@ object MainForm: TMainForm
Alignment = taRightJustify
AutoSize = False
Caption = 'Chunk Details:'
ParentColor = False
end
object Label5: TLabel
Left = 0
Expand All @@ -140,7 +134,6 @@ object MainForm: TMainForm
Alignment = taRightJustify
AutoSize = False
Caption = 'Unknown chunks:'
ParentColor = False
end
object Label6: TLabel
Left = 0
Expand All @@ -150,47 +143,41 @@ object MainForm: TMainForm
Alignment = taRightJustify
AutoSize = False
Caption = 'Number of files:'
ParentColor = False
end
object lb_chunkID: TLabel
Left = 136
Height = 16
Top = 0
Width = 200
AutoSize = False
ParentColor = False
end
object lb_chunkLen: TLabel
Left = 136
Height = 16
Top = 16
Width = 200
AutoSize = False
ParentColor = False
end
object lb_chunkDesc: TLabel
Left = 136
Height = 16
Top = 32
Width = 200
AutoSize = False
ParentColor = False
end
object lb_chunkUnk: TLabel
Left = 136
Height = 16
Top = 48
Width = 200
AutoSize = False
ParentColor = False
end
object lb_files: TLabel
Left = 136
Height = 16
Top = 64
Width = 200
AutoSize = False
ParentColor = False
end
object UEFProgress: TProgressBar
Left = 0
Expand Down
75 changes: 51 additions & 24 deletions Lazarus Source/MainUnit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface

uses
Classes,SysUtils,Forms,Controls,Graphics,Dialogs,ExtCtrls,StdCtrls,Buttons,
Classes,SysUtils,Forms,Controls,Dialogs,ExtCtrls,StdCtrls,Buttons,
ComCtrls,ZStream,crc,Global,StrUtils,Math;

type
Expand Down Expand Up @@ -50,7 +50,7 @@ TMainForm = class(TForm)
function TargetMachine(machine: Byte): String;
function GetCRC16(start,length: Cardinal;var buffer: TDynByteArray): Cardinal;
function GetCRC32(var buffer: TDynByteArray): String;
function Inflate(source: String): TDynByteArray;
function Inflate(source: String;var IsInflated: Boolean): TDynByteArray;
function GetIEEEFloat(input: Cardinal): Real;
private

Expand Down Expand Up @@ -96,9 +96,12 @@ procedure TMainForm.ReadUEFFile(source: String);
chunklen,
blocklen,
blocknum,
lastblock,
ptr,
headcrc,
datacrc : Cardinal;
firstblock,
IsGZip,
ok : Boolean;
temp,
line : String;
Expand All @@ -114,6 +117,7 @@ procedure TMainForm.ReadUEFFile(source: String);
SetLength(files,0);
baud:=1200; //Default baud rate
phase:=180;
IsGZip:=False;
//Reset the controls
Report.Clear; //The reading of the file would actually go quicker without these
FileLoader.Clear; //being updated as it read.
Expand All @@ -128,7 +132,8 @@ procedure TMainForm.ReadUEFFile(source: String);
//Begin the report
Report.Lines.Add('File: "'+source+'"'); //Put the filename in as the first line
//Open the file
buffer:=Inflate(source);
buffer:=Inflate(source,IsGzip);
if(IsGZip)then Report.Lines.Add('File is GZipped');
Report.Lines.Add('Total uncompressed file length: '
+IntToStr(Length(buffer))+' bytes (0x'
+IntToHex(Length(buffer),10)+')');
Expand All @@ -143,6 +148,9 @@ procedure TMainForm.ReadUEFFile(source: String);
Report.Lines.Add('File is a UEF file');
Report.Lines.Add('UEF version: '+IntToStr(buffer[$0A])+'.'+IntToStr(buffer[$0B]));
Report.Lines.Add('');
//Keep track of the last block's details
lastblock:=0;
firstblock:=True;
//Starting position is after the magic string
pos:=$0C;
//Keep track of which file we are on
Expand Down Expand Up @@ -218,21 +226,34 @@ procedure TMainForm.ReadUEFFile(source: String);
files[filenum].Filename:=temp; //Filename
files[filenum].Offset :=pos-6; //Where to find it (first block)
SetLength(files[filenum].Data,0);//Clear the data
FileLoader.Lines.Add(temp);
end;
//Read in the load address
files[filenum].LoadAddr:=buffer[pos+i]
+buffer[pos+i+1]*$100
+buffer[pos+i+2]*$10000
+buffer[pos+i+3]*$1000000;
//Read in the execution address
files[filenum].ExecAddr:=buffer[pos+i+4]
+buffer[pos+i+5]*$100
+buffer[pos+i+6]*$10000
+buffer[pos+i+7]*$1000000;
firstblock:=True;
//Read in the load address
files[filenum].LoadAddr:=buffer[pos+i]
+buffer[pos+i+1]*$100
+buffer[pos+i+2]*$10000
+buffer[pos+i+3]*$1000000;
//Read in the execution address
files[filenum].ExecAddr:=buffer[pos+i+4]
+buffer[pos+i+5]*$100
+buffer[pos+i+6]*$10000
+buffer[pos+i+7]*$1000000;
end else firstblock:=False;
//Read in the block number
blocknum:=buffer[pos+i+8]+buffer[pos+i+9]*$100;
line:=line+' #'+IntToHex(blocknum,4);
//Is it a new block, or copy protection?
if(blocknum>0)and(firstblock)and(Length(files)>1)then
if (lastblock=blocknum-1)
and(files[filenum-1].Filename=files[filenum].Filename)
{and(files[filenum-1].LoadAddr=files[filenum].LoadAddr)
and(files[filenum-1].ExecAddr=files[filenum].ExecAddr)}then
begin
SetLength(files,Length(files)-1);
dec(filenum);
firstblock:=False;
end;
lastblock:=blocknum;
if firstblock then FileLoader.Lines.Add(files[filenum].Filename);
//Take a note of where we are in the file's data, as we build it up
ptr:=files[filenum].Length;
//Get the length of this block
Expand All @@ -241,6 +262,7 @@ procedure TMainForm.ReadUEFFile(source: String);
inc(files[filenum].Length,blocklen);
//Get the block status
blockst:=buffer[pos+i+12];
line:=line+' Status: '+IntToHex(blockst,2);
//Get the CRC16 value for the header
headcrc:=buffer[pos+i+17]+buffer[pos+i+18]*$100;
//Check it is valid
Expand Down Expand Up @@ -497,7 +519,7 @@ function TMainForm.GetCRC32(var buffer: TDynByteArray): String;
{-------------------------------------------------------------------------------
Load, and inflate if it is GZipped, a UEF file
-------------------------------------------------------------------------------}
function TMainForm.Inflate(Source: String): TDynByteArray;
function TMainForm.Inflate(Source: String;var IsInflated: Boolean): TDynByteArray;
function L_Inflate(Source: String): TDynByteArray;
var
GZ : TGZFileStream;
Expand Down Expand Up @@ -554,14 +576,18 @@ function TMainForm.Inflate(Source: String): TDynByteArray;
except
end;
F.Free;
//Count how many blocks and make note of their positions
for ptr:=0 to Length(buffer)-10 do
if(buffer[ptr]=$1F)and(buffer[ptr+1]=$8B)and(buffer[ptr+2]=$08)then
begin
//Make a note of the position
SetLength(blockptrs,Length(blockptrs)+1);
blockptrs[Length(blockptrs)-1]:=ptr;
end;
//First, is it actually a GZip file?
if(buffer[$00]=$1F)and(buffer[$01]=$8B)and(buffer[$02]=$08)then
begin
//Count how many blocks and make note of their positions
for ptr:=0 to Length(buffer)-10 do
if(buffer[ptr]=$1F)and(buffer[ptr+1]=$8B)and(buffer[ptr+2]=$08)then
begin
//Make a note of the position
SetLength(blockptrs,Length(blockptrs)+1);
blockptrs[Length(blockptrs)-1]:=ptr;
end;
end;
//Separate each block, if more than one
if Length(blockptrs)>1 then
begin
Expand Down Expand Up @@ -597,6 +623,7 @@ function TMainForm.Inflate(Source: String): TDynByteArray;
if Length(blockptrs)=1 then Result:=L_Inflate(Source);
//If there are no blocks, then just return the entire file
if Length(blockptrs)=0 then Result:=buffer;
IsInflated:=Length(buffer)<>Length(Result);
end;

{-------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 15df5d1

Please sign in to comment.