This file documents the process used to disassemble and document the SAM source code from the C64 version.
- In VICE, load SAM and RECITER into low memory
- Execute code at $97e2-97e8 to map LOMEM at $A000-$BFFF
- Create dump file (need $7d00-$bfff)
- Trace entry points with WFDis
- $9500 installs the SAM wedge
- $950D executes the wedge, which reaches the rest of the code
- Mechanically convert to CA65 syntax
- A lot of this was semi-automated with Vim macros and regexes:
- Add
:
after labels:'<,'>-1s/^\([LS][0-9a-f]\{4\}\)/\1:^M /g
- Convert hex into '.byte' statements:
- Insert
, $
between bytes:'<,'>-1s/\(\w\) \(\w\)\1, $\2/g
- Add
.byte
prefix:'<,'>-1s/^\(\s*\)\1.byte $/g
- Insert
- Add
- Node scripts were used to decode some tables (see /reference/tools/*)
- A lot of this was semi-automated with Vim macros and regexes:
- Authored custom 'c64.cfg' to place SAM at $7D00
Author stub 'startup.s' to install wedge (jsr $9500
).
Documented on page 35 of the C64 manual.
HEX | Function | Example | Notes |
---|---|---|---|
$9500 | (Re)install S.A.M. Wedge | SYS 38144 | |
$97E0 | Throat | POKE 38880, n | (Default 128) |
$97E1 | Mouth | POKE 38881, n | (Default 128) |
$9A00 | S.A.M. from BASIC | SYS 39424 | |
$9A03 | S.A.M. from ML | JSR $9A03 | |
$9A06 | RECITER from BASIC | SYS 39430 | |
$9A09 | RECITER from ML | JSR $9A09 | |
$9A0E | SPEED | POKE 39438, n | (Default 72) |
$9A0F | PITCH | POKE 39439, n | (Default 64) |
$9A10 | LIGHTS | POKE 39440, n | (Default 0 = off) |
$9A11 | INTERRUPTS | POKE 39441, n | (Default 0 = disabled) |
$9A15 | TEXT | (ASCII string terminated by $9b) |
Identified by relocating SAM and using a memory breakpoint to detect access to the previous memory region.
- $9271, $928b: Split pointer table to alphabetic rules at $7d00-$8cda
- $92a5: LTS rules for non-alphanumeric characters
- $Lb3c0: Sample table
- $a800-$af00: Rendering tables (Note: Must be page aligned)
Identified through code inspection aided by memory breakpoints.
During the process of documenting SAM, I found and fixed a few minor/benign bugs:
- '?' did not cause a rising inflection when using RECITER due to '(?)=.'
- A benign bug where 'e_rules' pointed to $8039 instead of $803f.
- 'jsr' to $a439 (which is mid-instruction). Probably benign as I think this code is unreachable.
The reverse-engineered comments borrow liberally from pre-existing efforts:
- C64 disassembly by Groepaz
- 'C' port by Sebastian Macke
- 'C#' port by Simon