Boing

Found on:
"Boing (E&J Software)"

Loader files:
ROM Header 1
Only filename
ROM Data 1
Autostart, loads turbo loader using ROM routines
ROM Header 2
Only filename
ROM Data 2
Turbo loader

Encoding:
Endianess:MSbF
Threshold:~0x1A8-0x1B0
Lead-in:1500/544 x 1-bit + 1 x 0-bit
Sync:0x36/0x69
Byte:8 bits
0-bit:Short

Structure:
Header:Yes
Checksum:Yes
Threshold:
Threshold is calculated by the loader using the 256 first pulses of the lead-in.
These are assumed by the loader to be long pulses.
Calculation: (Sum/256)*3/4.
Each duration (CPU cycles) is divided by 8 before being added together.
No duration will exceed 0x7f since this is considered an illegal duration by the loader and a 0 return.

This threshold calculation is performed at every new lead-in.

Lead-in:
The longer lead-in appears before the header, while the shorter is between header and payload.

Sync:
0x36 used for header and 0x69 used for payload.

Checksum:
Checksum is calculated separately for header and data areas.
Both areas are followed by the two checksum bytes, low/high order.

Checksum is not based on data bytes, it's based on bit durations (CPU cycles).
The following routing is called for every bit.

When called, the A register contains (bit duration / 8) - calculated threshold.
$21/$22 (low/high checksum bytes) are both initialized to 0xff prior to loading header/data areas.

ckSum:php
 // Divide the value with 2 and change sign since carry
 // will be carried over from the earlier 'sbc threshold' instruction.
 ror
 clc
 eor$22
 bplC
 lda$22
 eor#$08
 sta$22
 lda$21
 eor#$10
 sta$21
 sec
C:rol$21
 rol$22
 plp
 rts

Header:
00-10   Filename. 0x00 padded/terminated.
11-12   Load start address (Low/high order)
13-14   Load size (Low/high order)
15        Unknown/Unused
16        Unknown/Unused
17        File Id
18        Last file flag, 0xff if this is the last file, 0x00 otherwise.

Notes:
Filename and Id is used to check for errors.
Filename is always "BOING.PRG" for all files.
File Id starts at 1 and increases by 1 for each file.

Start address always 0x7a34 in the header.
Start address is hardcoded to 0x0801 in the loader.
Load size is used, and seems to be 0x800 for all files except the last.