Skip to content

Commit d3a5b8d

Browse files
committed
tzx: revert using an array of bytes
1 parent d384930 commit d3a5b8d

File tree

2 files changed

+14
-76
lines changed

2 files changed

+14
-76
lines changed

format/tzx/testdata/basic_prog1.fqtest

+3-39
Original file line numberDiff line numberDiff line change
@@ -78,43 +78,7 @@ $ fq -d tzx dv basic_prog1.tzx
7878
0xa0| 28 00 | (. | length: 40 0xa3-0xa5 (2)
7979
| | | data{}: 0xa5-0xcd (40)
8080
0xa0| ff | . | flag: "standard_speed_data" (255) 0xa5-0xa6 (1)
81-
| | | bytes[0:38]: 0xa6-0xcc (38)
82-
0xa0| 00 | . | [0]: 0 byte 0xa6-0xa7 (1)
83-
0xa0| 0a | . | [1]: 10 byte 0xa7-0xa8 (1)
84-
0xa0| 14 | . | [2]: 20 byte 0xa8-0xa9 (1)
85-
0xa0| 00 | . | [3]: 0 byte 0xa9-0xaa (1)
86-
0xa0| 20 | | [4]: 32 byte 0xaa-0xab (1)
87-
0xa0| f5 | . | [5]: 245 byte 0xab-0xac (1)
88-
0xa0| 22 | " | [6]: 34 byte 0xac-0xad (1)
89-
0xa0| 66 | f | [7]: 102 byte 0xad-0xae (1)
90-
0xa0| 71 | q | [8]: 113 byte 0xae-0xaf (1)
91-
0xa0| 20| | [9]: 32 byte 0xaf-0xb0 (1)
92-
0xb0|69 |i | [10]: 105 byte 0xb0-0xb1 (1)
93-
0xb0| 73 | s | [11]: 115 byte 0xb1-0xb2 (1)
94-
0xb0| 20 | | [12]: 32 byte 0xb2-0xb3 (1)
95-
0xb0| 74 | t | [13]: 116 byte 0xb3-0xb4 (1)
96-
0xb0| 68 | h | [14]: 104 byte 0xb4-0xb5 (1)
97-
0xb0| 65 | e | [15]: 101 byte 0xb5-0xb6 (1)
98-
0xb0| 20 | | [16]: 32 byte 0xb6-0xb7 (1)
99-
0xb0| 62 | b | [17]: 98 byte 0xb7-0xb8 (1)
100-
0xb0| 65 | e | [18]: 101 byte 0xb8-0xb9 (1)
101-
0xb0| 73 | s | [19]: 115 byte 0xb9-0xba (1)
102-
0xb0| 74 | t | [20]: 116 byte 0xba-0xbb (1)
103-
0xb0| 21 | ! | [21]: 33 byte 0xbb-0xbc (1)
104-
0xb0| 22 | " | [22]: 34 byte 0xbc-0xbd (1)
105-
0xb0| 0d | . | [23]: 13 byte 0xbd-0xbe (1)
106-
0xb0| 00 | . | [24]: 0 byte 0xbe-0xbf (1)
107-
0xb0| 14| .| [25]: 20 byte 0xbf-0xc0 (1)
108-
0xc0|0a |. | [26]: 10 byte 0xc0-0xc1 (1)
109-
0xc0| 00 | . | [27]: 0 byte 0xc1-0xc2 (1)
110-
0xc0| ec | . | [28]: 236 byte 0xc2-0xc3 (1)
111-
0xc0| 31 | 1 | [29]: 49 byte 0xc3-0xc4 (1)
112-
0xc0| 30 | 0 | [30]: 48 byte 0xc4-0xc5 (1)
113-
0xc0| 0e | . | [31]: 14 byte 0xc5-0xc6 (1)
114-
0xc0| 00 | . | [32]: 0 byte 0xc6-0xc7 (1)
115-
0xc0| 00 | . | [33]: 0 byte 0xc7-0xc8 (1)
116-
0xc0| 0a | . | [34]: 10 byte 0xc8-0xc9 (1)
117-
0xc0| 00 | . | [35]: 0 byte 0xc9-0xca (1)
118-
0xc0| 00 | . | [36]: 0 byte 0xca-0xcb (1)
119-
0xc0| 0d | . | [37]: 13 byte 0xcb-0xcc (1)
81+
0xa0| 00 0a 14 00 20 f5 22 66 71 20| .... ."fq | bytes: raw bits 0xa6-0xcc (38)
82+
0xb0|69 73 20 74 68 65 20 62 65 73 74 21 22 0d 00 14|is the best!"...|
83+
0xc0|0a 00 ec 31 30 0e 00 00 0a 00 00 0d |...10....... |
12084
0xc0| b6| | .| | checksum: 0xb6 (valid) 0xcc-0xcd (1)

format/tzx/tzx.go

+11-37
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ func decodeBlock(d *decode.D) {
9797
length := d.FieldU24("length") // Length of data that follows
9898

9999
// Data as in .TAP files
100-
d.FieldArray("data", func(d *decode.D) {
101-
for i := uint64(0); i < length; i++ {
102-
d.FieldU8("byte")
103-
}
104-
})
100+
d.FieldRawLen("data", int64(length)*8)
105101
},
106102

107103
// ID: 12h (18d) | Pure Tone
@@ -135,11 +131,7 @@ func decodeBlock(d *decode.D) {
135131
length := d.FieldU24("length") // Length of data that follows
136132

137133
// Data as in .TAP files
138-
d.FieldArray("data", func(d *decode.D) {
139-
for i := uint64(0); i < length; i++ {
140-
d.FieldU8("byte")
141-
}
142-
})
134+
d.FieldRawLen("data", int64(length)*8)
143135
},
144136

145137
// ID: 15h (21d) | Direct Recording
@@ -151,17 +143,11 @@ func decodeBlock(d *decode.D) {
151143
// The preferred sampling frequencies are 22050 or 44100 Hz
152144
// (158 or 79 T-states/sample).
153145
0x15: func(d *decode.D) {
154-
d.FieldU16("t_states") // Number of T-states per sample (bit of data)
155-
d.FieldU16("pause") // Pause after this block in milliseconds (ms.)
156-
d.FieldU8("used_bits") // Used bits (samples) in last byte of data (1-8)
157-
length := d.FieldU24("length") // Length of data that follows
158-
159-
// Samples data. Each bit represents a state on the EAR port
160-
d.FieldArray("data", func(d *decode.D) {
161-
for i := uint64(0); i < length; i++ {
162-
d.FieldU8("byte")
163-
}
164-
})
146+
d.FieldU16("t_states") // Number of T-states per sample (bit of data)
147+
d.FieldU16("pause") // Pause after this block in milliseconds (ms.)
148+
d.FieldU8("used_bits") // Used bits (samples) in last byte of data (1-8)
149+
length := d.FieldU24("length") // Length of data that follows
150+
d.FieldRawLen("data", int64(length)*8) // Samples data. Each bit represents a state on the EAR port
165151
},
166152

167153
// ID: 18h (24d) | CSW Recording
@@ -184,11 +170,7 @@ func decodeBlock(d *decode.D) {
184170
d.FieldU32("stored_pulse_count")
185171

186172
// CSW data, encoded according to the CSW specification
187-
d.FieldArray("data", func(d *decode.D) {
188-
for i := uint64(0); i < length; i++ {
189-
d.FieldU8("byte")
190-
}
191-
})
173+
d.FieldRawLen("data", int64(length)*8)
192174
},
193175

194176
// ID: 19h (25d) | Generalized Data
@@ -212,11 +194,7 @@ func decodeBlock(d *decode.D) {
212194
// PilotStreams []PilotRLE // 0x12+ (2*NPP+1)*ASP - PRLE[TOTP] Pilot and sync data stream
213195
// DataSymbols []Symbol // 0x12+ (TOTP>0)*((2*NPP+1)*ASP)+TOTP*3 - SYMDEF[ASD] Data symbols definition table
214196
// DataStreams []uint8 // 0x12+ (TOTP>0)*((2*NPP+1)*ASP)+ TOTP*3+(2*NPD+1)*ASD - BYTE[DS] Data stream
215-
d.FieldArray("data", func(d *decode.D) {
216-
for i := uint64(0); i < length; i++ {
217-
d.FieldU8("byte")
218-
}
219-
})
197+
d.FieldRawLen("data", int64(length)*8)
220198
},
221199

222200
// ID: 20h (32d) | Pause Tape Command
@@ -409,13 +387,9 @@ func decodeBlock(d *decode.D) {
409387
// some information written by a utility, extra settings required by a
410388
// particular emulator, etc.
411389
0x35: func(d *decode.D) {
412-
d.FieldStr("identification", 10, charmap.ISO8859_1)
390+
d.FieldStr("identification", 16, charmap.ISO8859_1)
413391
length := d.FieldU32("length")
414-
d.FieldArray("info", func(d *decode.D) {
415-
for i := uint64(0); i < length; i++ {
416-
d.FieldU8("byte")
417-
}
418-
})
392+
d.FieldRawLen("info", int64(length)*8)
419393
},
420394

421395
// ID: 5Ah (90d) | Glue Block

0 commit comments

Comments
 (0)