Skip to content

Instantly share code, notes, and snippets.

@shadwork
Created May 14, 2024 10:41
Show Gist options
  • Select an option

  • Save shadwork/8826e64411e0285630025dac1c611969 to your computer and use it in GitHub Desktop.

Select an option

Save shadwork/8826e64411e0285630025dac1c611969 to your computer and use it in GitHub Desktop.
Python script to decompile ZX-Spectrum BASIC to text using tzxtools library
#!/usr/bin/env python3
import argparse
import sys
from tzxlib.convert import convertToBasic
def main():
parser = argparse.ArgumentParser(description='Convert Sinclair Basic code representation into Text')
parser.add_argument('file',
nargs='?',
type=argparse.FileType('rb'),
default=(None if sys.stdin.isatty() else sys.stdin.buffer),
help='Input file, stdin if omitted')
parser.add_argument('-o', '--to',
dest='to',
metavar='TARGET',
type=argparse.FileType('wb'),
default=sys.stdout.buffer,
help='Target text file, stdout if omitted')
args = parser.parse_args()
if args.file is None:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
data = bytearray(args.file.read())
convertToBasic(data,args.to)
if __name__ == "__main__":
main()
@scruss
Copy link

scruss commented Jul 10, 2025

listbasic from the fuse emulator will also do this.

You can do the reverse (BASIC source → .tap or .p) using zmakebas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment