-
Notifications
You must be signed in to change notification settings - Fork 1
/
tzxblock11.inc
121 lines (104 loc) · 3.5 KB
/
tzxblock11.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
// Copyright 2022-2024 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$ifdef tzx_header_section}
TTzxBlock11 = class (TTzxBlock11abstract)
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;
end;
{$else}
function TTzxBlock11.Details2: String;
begin
Result := inherited Details2
+ #13 + 'Pilot pulse t-states: ' + IntToStr(PilotTicksNeeded)
+ #13 + Format('Sync pulses t-states: (%d, %d)', [Sync1TicksNeeded, Sync2TicksNeeded])
+ #13 + Format('T-states in zero/one bit pulses: (%d, %d)', [Bit0TicksNeeded, Bit1TicksNeeded])
+ #13 + 'Pilot tone pulses: ' + IntToStr(PilotPulsesNeeded)
;
end;
constructor TTzxBlock11.Create(ATapePlayer: TTapePlayer);
begin
inherited Create(ATapePlayer);
PilotTicksNeeded := 0;
end;
class function TTzxBlock11.GetBlockId: DWord;
begin
Result := $11;
end;
function TTzxBlock11.LoadBlock(const Stream: TStream): Boolean;
var
W: Word;
B: Byte;
N: Int32;
begin
Result := False;
if Stream.Size - Stream.Position >= $12 then begin
if Stream.Read(W{%H-}, 2) = 2 then begin
W := LEtoN(W);
PilotTicksNeeded := W;
if Stream.Read(W, 2) = 2 then begin
W := LEtoN(W);
Sync1TicksNeeded := W;
if Stream.Read(W, 2) = 2 then begin
W := LEtoN(W);
Sync2TicksNeeded := W;
if Stream.Read(W, 2) = 2 then begin
W := LEtoN(W);
Bit0TicksNeeded := W;
if Stream.Read(W, 2) = 2 then begin
W := LEtoN(W);
Bit1TicksNeeded := W;
if Stream.Read(W, 2) = 2 then begin
W := LEtoN(W);
PilotPulsesNeeded := W;
if Stream.Read(B{%H-}, 1) = 1 then begin
if Stream.Read(W, 2) = 2 then begin
W := LEtoN(W);
PauseAfterBlock := W;
if ReadThreeBytes(Stream, N) then begin
if Stream.Size - Stream.Position >= N then begin
DataLen := N;
Result := N = 0;
FLen := N + $12;
if not Result then begin
GetMem(Data, N);
try
if Stream.Read(Data^, N) = N then begin
if B >= 8 then
UsedBitsInLastByte := 8
else if B = 0 then begin
Dec(N);
UsedBitsInLastByte := 8;
end else
UsedBitsInLastByte := B;
if N > 0 then begin
PEnd := Data + (N - 1);
Result := True;
end;
end;
finally
if not Result then
FreeMemAndNil(Data);
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
class function TTzxBlock11.GetBlockDescription: String;
begin
Result := 'Turbo Speed Data Block';
end;
{$endif}