BAS to PHC converter


Objective

The goal is to convert BASIC programs (in text file form) into the PHC format, a binary used for emulators. The PHC file can then be converted into WAV format for real machines.

How to

This application converts BASIC code to PHC format and is currently in beta test.
Load the file, convert, if ok, save it (donwload folder).



No file loaded...
Basic
PHC (hex view)

TO DO

Improve comments and indent in files.

The decrypted PHC binary

Description of the PHC file structure.

Sync header

10 bytes of value A5h

a5 a5 a5 a5 a5 a5 a5 a5 a5 a5

Program name:

6 ASCII characters (padded with 00h if shorter).

nn nn nn nn nn nn

Program body

Repeated blocks of BASIC code encoded in tokens/ASCII.
Each line ends with 00h.
Continue until no more lines.

nn nn nn nn nn 00

End of program marker

This includ the end of the last line.

00 00 00

Line index table (stored in reverse order)

Each entry is 4 bytes:

  • AL, AH : memory address of the line (little endian)
  • NL, NH : line number (little endian)
Repeat until no more entries.
The first four bytes are the last line, the last four bytes are the first line.

 al ah nl nh ...

Trailer

00h FFh FFh FFh FFh

followed by padding with 00h bytes (18).

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Fixed tail section to mark the end of the file.