-
Notifications
You must be signed in to change notification settings - Fork 2
/
tzxblock35.inc
95 lines (78 loc) · 2.25 KB
/
tzxblock35.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2022-2024 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$ifdef tzx_header_section}
{ TTzxBlock35 }
TTzxBlock35 = class (TTzxBlock)
private
FLen: Integer;
FIdentificationString: AnsiString;
FCustomInfo: PByte;
public
constructor Create(ATapePlayer: TTapePlayer); override;
destructor Destroy; override;
class function GetBlockId: DWord; override;
{returns whole block length, without id byte}
function GetBlockLength: Integer; override;
function LoadBlock(const Stream: TStream): Boolean; override;
class function GetBlockDescription: String; override;
procedure Details(out S: String); override;
end;
{$else}
constructor TTzxBlock35.Create(ATapePlayer: TTapePlayer);
begin
inherited Create(ATapePlayer);
FCustomInfo := nil;
FIdentificationString := '';
FLen := 0;
end;
destructor {TTzxPlayer.}TTzxBlock35.Destroy;
begin
if FCustomInfo <> nil then
Freemem(FCustomInfo);
inherited Destroy;
end;
class function {TTzxPlayer.}TTzxBlock35.GetBlockId: DWord;
begin
Result := $35;
end;
function {TTzxPlayer.}TTzxBlock35.GetBlockLength: Integer;
begin
Result := FLen;
end;
function {TTzxPlayer.}TTzxBlock35.LoadBlock(const Stream: TStream): Boolean;
var
LL: UInt32;
L: Int32 absolute LL;
begin
Result := False;
if Stream.Size - Stream.Position >= $14 then begin
SetLength(FIdentificationString, $10);
if Stream.Read(FIdentificationString[1], $10) = $10 then begin
// identification string must be in ascii (so no chars above 127)?
// Just in case:
TCommonFunctions.ConvertCodePageFromCp1252ToUtf8(FIdentificationString);
if Stream.Read(LL{%H-}, 4) = 4 then begin
LL := LEtoN(LL);
if Stream.Size - Stream.Position >= L then begin
Result := L = 0;
FLen := $14 + L;
if not Result then begin
GetMem(FCustomInfo, L);
if Stream.Read(FCustomInfo^, L) = L then begin
Result := True;
end;
end;
end;
end;
end;
end;
end;
class function {TTzxPlayer.}TTzxBlock35.GetBlockDescription: String;
begin
Result := 'Custom info block';
end;
procedure {TTzxPlayer.}TTzxBlock35.Details(out S: String);
begin
S := FIdentificationString;
end;
{$endif}