-
Notifications
You must be signed in to change notification settings - Fork 1
/
tzxblock10.inc
179 lines (150 loc) · 4.07 KB
/
tzxblock10.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Copyright 2022-2024 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$ifdef tzx_header_section}
TTzxTapBlock = class (TTzxBlock11abstract)
strict private
FHeaderDetails: String;
strict protected
function Details2: String; override;
public
constructor Create(ATapePlayer: TTapePlayer); override;
class function GetBlockId: DWord; override;
function LoadBlock(const Stream: TStream): Boolean; override;
class function GetBlockDescription: String; override;
procedure Details(out S: String); override;
end;
TTzxBlock10 = class (TTzxTapBlock)
public
class function GetBlockId: DWord; override;
function LoadBlock(const Stream: TStream): Boolean; override;
end;
{$else}
class function TTzxBlock10.GetBlockId: DWord;
begin
Result := $10;
end;
function TTzxBlock10.LoadBlock(const Stream: TStream): Boolean;
var
W: Word;
begin
Result := False;
if Stream.Size - Stream.Position >= 2 then begin
if Stream.Read(W{%H-}, 2) = 2 then begin
W := LEtoN(W);
PauseAfterBlock := W;
Result := inherited LoadBlock(Stream);
FLen := FLen + 2;
end;
end;
end;
function TTzxTapBlock.Details2: String;
begin
Result := '';
end;
constructor TTzxTapBlock.Create(ATapePlayer: TTapePlayer);
begin
inherited Create(ATapePlayer);
FHeaderDetails := '';
end;
class function TTzxTapBlock.GetBlockId: DWord;
begin
Result := 0;
end;
function TTzxTapBlock.LoadBlock(const Stream: TStream): Boolean;
type
THeader = packed record
DataType: Byte;
FileName: packed array [1..10] of Byte;
DataLenght: Word;
Param1: Word;
Param2: Word;
end;
var
Header: THeader;
function DecodeVariableName(): RawByteString;
var
C: AnsiChar;
begin
if (Header.DataType in [1, 2]) then begin
C := AnsiChar((WordRec(Header.Param1).Hi and $1F) + $60);
if C in ['a'..'z'] then begin
Result := #13 + 'variable name: ' + C;
if Header.DataType = 2 then
Result := Result + '$';
Exit;
end;
end;
Result := '';
end;
procedure DecodeHeader();
var
FileName: RawByteString;
begin
Header.Param1 := LEtoN(Header.Param1);
Header.Param2 := LEtoN(Header.Param2);
Header.DataLenght := LEtoN(Header.DataLenght);
case Header.DataType of
0:
FHeaderDetails := 'Program';
1:
FHeaderDetails := 'Number array';
2:
FHeaderDetails := 'Character array';
3:
FHeaderDetails := 'Code file';
otherwise
Exit;
end;
SetLength(FileName{%H-}, 10);
Move(Header.FileName[1], FileName[1], 10);
FileName := TCommonFunctions.SpectrumCharToUtf8(FTapePlayer.GetSpectrum.Is128KModel, FileName);
FHeaderDetails :=
FHeaderDetails + ': ' + FileName + DecodeVariableName() + #13
+ Format('Length of data block: %d%sParam1: %d%sParam2: %d%s',
[Header.DataLenght, #13, Header.Param1, #13, Header.Param2, #13])
;
end;
var
L: Integer;
W: Word;
begin
Result := False;
FHeaderDetails := '';
L := Stream.Size - Stream.Position - 2;
if L >= 0 then begin
if Stream.Read(W{%H-}, 2) = 2 then begin
W := LEtoN(W);
DataLen := W;
if DataLen <= L then begin
Result := DataLen = 0;
FLen := DataLen + 2;
if not Result then begin
Getmem(Data, DataLen);
if Stream.Read(Data^, DataLen) = DataLen then begin
PEnd := Data + (DataLen - 1);
Result := True;
if (Data^ and $80) = 0 then begin
PilotPulsesNeeded := DefaultPilotHeaderPulsesNeeded;
if DataLen = SizeOf(THeader) + 2 then begin
Move((Data + 1)^, Header, SizeOf(THeader));
DecodeHeader();
end;
end else
PilotPulsesNeeded := DefaultPilotDataPulsesNeeded;
end else
FreeMemAndNil(Data);
end;
end;
end;
end;
end;
class function TTzxTapBlock.GetBlockDescription: String;
begin
Result := 'Standard Speed Data Block';
end;
procedure TTzxTapBlock.Details(out S: String);
begin
inherited Details(S);
S := FHeaderDetails + S;
end;
{$endif}