== Memory ==
The SP0256 can address 60Kbytes (480Kbits) of internal or external ROM, however, usally the ROMs are only 2Kbytes (16Kbit). The ROM contains plain program code, without any kind of data arrays.
The upper 4bit of the program counter cannot be zero, so the memory starts at byte-address 1000h, and ends at FFFFh. The first 512 bytes are entrypoints, usually containing JUMP opcodes for up to 256 allophones or words.
The opcodes and their parameters are transferred serially, LSB first (except, for some reason, the JUMP/CALL/SETPAGE "Target" values are MSB first).
== Opcodes ==
* Opcode 1110b - JUMP - Jump to 12-bit PAGE-Relative Address* Opcode 1101b - CALL - Jump to Subroutine (12-bit PAGE-Relative Address)
4 Target bit8-11 (in reversed bit-order!)
CALL pushes the 16bit byte-aligned return address onto stack, and marks the stack as not empty. The previous contents of the stack are lost (the stack is only one entry deep).
---- * Opcode 0000b with Zero-Operand - RET - Return from Subroutine (or HALT)
4 Zero for RET (00h=Return)
Note: HALT state stops program execution, but does not stop the sound generator - to obtain silence, issue a short PAUSE (or another opcode that sets amplitude=0).
---- * Opcode 0000b with Nonzero-Operand - SETPAGE - Set the PAGE register
4 Target bit12-15 (in reversed bit-order!) (01h..0Fh=Page)
(Note that address loads via ALD appear to ignore PAGE, and set the four MSBs to $1000. They do not modify the PAGE register, so subsequent JUMP/CALL instructions will jump relative to the current value in PAGE.)
---- * Opcode 0001b - SETMODE - Set the MODE bits and Repeat MSBs
2 Repeat Count bit4-5 (expands the next ONE opcode that uses 4bit repeat)
Some opcodes have optional parameters (for example "(8)" means an optional 8bit parameter), which is included in the opcode only when EXTRA=1.
---- * Opcode 1111b - PAUSE - Silent Pause
4 Repeat Count
Provides a silent pause of varying length. The pause behaves identially to a pitch with Amplitude=0 and Period=64. All coefficients are cleared, as well.
---- * Opcode 0111b - LOAD_PA - Load Pitch, Amplitude
4 Repeat Count
8 Pitch (00h=Noise)
---- * Opcode 1000b - LOAD_ALL - Load All Parameters (at full 8bit precision)
4 Repeat Count
Notes: The pitch and amplitude deltas that are available when EXTRA=1 are applied every pitch period, not just once. Wraparound may occur. If the Pitch goes to zero, the periodic excitation switches to noise.
---- * Opcode 0010b - LOAD_23 - Load Pitch, Amplitude, 2-3 Coefficients* Opcode 0011b - LOAD_56 - Load Pitch, Amplitude, 5-6 Coefficients* Opcode 0100b - LOAD_56D - Load Pitch, Amplitude, 5-6 Coefficients, Delta
4 Repeat Count
Sets the unspecified coefficients to 0. The "unsigned" B0,B1,B2,B3 values are zero-expanded from N bits to (N+1) bits, and are then copied to the upper (N+1) bits of the register.
---- * Opcode 0110b - SETMSB_23 - Load Amplitude, MSBs of 2 or 3 Coeffcients* Opcode 0101b - SETMSB_3 - Load Amplitude, MSBs of 3 Coefficients* Opcode 1010b - SETMSB_3P - Load Amplitude, MSBs of 3 Coefficients, Pitch* Opcode 1100b - SETMSB_3D - Load Amplitude, MSBs of 3 Coefficients, Delta
4 Repeat Count
All other coefficient bits are unaffected (ie. all coefficients that aren't accessed by the specific opcode, as well as LSBs of accessed coefficients).
---- * Opcode 1001b - DELTA_56 - Add Delta to Amplitude, Pitch, 5 or 6 Coefficients* Opcode 1011b - DELTA_23 - Add Delta to Amplitude, Pitch, 2 or 3 Coefficients
4 Repeat Count
4/5 F3 6,7 MSBs signed ;/
4/5 B4 x,8 MSBs signed ;\ <---- DELTA_56: x=6, and DELTA_23: x=7 (?)
4/5 F4 6,8 MSBs signed ;/
(5) B5 (8) MSBs signed ;\ ;\when EXTRA=1 only