Skip to content

Instantly share code, notes, and snippets.

@kolen
Created May 8, 2019 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolen/75252ffef8b0de121ccb6943020628a0 to your computer and use it in GitHub Desktop.
Save kolen/75252ffef8b0de121ccb6943020628a0 to your computer and use it in GitHub Desktop.
Fixed kaitai struct for zx spectrum .tap files (fixed prefixing data with header)
meta:
id: zx_spectrum_tap
file-extension: tap
endian: le
license: CC0-1.0
title: ZX Spectrum tape file format
xref:
justsolve: TAP_(ZX_Spectrum)
pronom: fmt/801
doc-ref: https://faqwiki.zxnet.co.uk/wiki/TAP_format
seq:
- id: block
type: block
repeat: eos
enums:
flag_enum:
0x00: header
0xFF: data
header_type_enum:
0: program
1: num_array
2: char_array
3: bytes
types:
block:
seq:
- id: len_block
type: u2
- id: flag
type: u1
enum: flag_enum
- id: header
type: header
if: len_block == 0x13 and flag == flag_enum::header
- id: data
if: len_block != 0x13 or flag != flag_enum::header
size: len_block - 2
- id: checksum
type: u1
doc: Bitwise XOR of all bytes including the flag byte
header:
seq:
- id: header_type
type: u1
enum: header_type_enum
- id: filename
size: 10
pad-right: 0x20
- id: len_data
type: u2
- id: params
type:
switch-on: header_type
cases:
'header_type_enum::program': program_params
'header_type_enum::num_arry': array_params
'header_type_enum::char_arry': array_params
'header_type_enum::bytes': bytes_params
program_params:
seq:
- id: autostart_line
type: u2
- id: len_program
type: u2
array_params:
seq:
- id: reserved
type: u1
- id: var_name
type: u1
doc: Variable name (1..26 meaning A$..Z$ +192)
- id: reserved1
contents: [0x00, 0x80]
bytes_params:
seq:
- id: start_address
type: u2
- id: reserved
size: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment