Casio SA-series hardware is a softsynth on a chip. Long ago DTech mentioned that he had decapped the microcontroller but couldn't understand how it works. I have done some work to dig through the patents and analyze the pinout of the thing, This is an unfinished analysis I wrote for my website:
The classic Casio SA-series hardware is based on the single chip CPU "OKI M6387-xx" (where "xx" indicates the software number of the internal ROM). Although DIL shaped, its 30 pins are narrower and don't fit into regular DIL sockets (some websites refer this "SDIL"). It is hard to find info about this chip, but it appears to be a 4bit RISC microcontroller crystal clocked at 21.725 MHz. There is likely DRAM in it, because it can not be underclocked very much without crashing. Thus although these keyboards are popular circuit-bending victims, on the digital side there is beside known matrix eastereggs not much more to explore than semi-random shitshots. (It has no exposed data bus to play with).
The classic SA-series supports only 32 keys, but a 49 keys matrix was used in the technically very similar MA- and CA-series keyboards of its era (but not in the newer MA-150/ MA-170). Some of these (e.g. MA-130) have the same CPU. All keyboards with polyphony >2 notes contain matrix diodes and pulldown resistor arrays at the input lines. Because the same CPU is built into 2 and 4 note polyphonic keyboards, 2 connected pins tell it how much polyphony to use.
The sound engine is mono and uses a 4 note polyphonic wavetable sound generator with each voice based 2 mixed low-res loop samples with independent, partly very complex algorithmic volume and pitch envelopes (possibly program loop synthesis) and modulations. In the MA-130 one subvoice can be muted to achieve 8 instead of 4 note polyphony, thus internally it has at least 8 sound channels. The digital volume control seems to be implemented in software by crude changes of the envelope start points, which not only steals a lot of bit resolution but also speeds up the cycling tempo of complex envelope patterns, which makes me conclude that instead of using an independent timer register, the envelope simply switches to the next step once its volume register is counting down to zero. I yet had no chance to look into the machine code, but it seems to be quite a miracle of minimalistic efficient hardware design. I think the M6387 has it in itself to be a true classic. When you listen to it first, you may ask why it can't do certain things too well, but once it is fully deciphered, it will likely turn into a big surprise how it can do so many things at all. Like with Atari VCS2600 I expect the underlying hardware to be incredible tiny.
The case bottom of my Casio SA-41 lists the US patents 4121284, 4371923 and 4942516, those however only refer to third party inventions about very generic principles of small microcomputers (key debouncing, multitasking, integrated I/O etc.) and may be rather listed as a warning that it is patented, while enshrouding the inner working by not telling competitors where to search for the important parts.
the Casio softsynth on a chip
In fact, the Casio "PCM" sound engine is apparently described quite detailedly in the US patent 5319151; it is based on a highly complex softsynth with many algorithms those can perform PCM, DPCM, FM and TM (triangular wave modulation) synthesis with sophisticated envelopes. This rather confusing 121 page tome of a patent text however is ambiguous, because it covers plenty of different implementations those e.g. can employ different counts of chip-internal sub-CPU cores for sound generation in higher grade instruments. The SA-series is surely the cheapest described "First" or "Second Embodiment" which has none. The algorithms for this version even describe how shorter tasks are stuffed with blank "dummy commands" to keep the timing in sync when different sounds would need different computing time. It works indeed very VCS2600-like - a marvel of freakish realtime programming made from one big loop (plus in "First Embodiment" one timer IRQ to compute waveforms and fill the DAC output FIFO; the "Second" does even this during dummy commands).
The interpolation method with that Casio smoothly blends between wavetable sections is described in the US patent 4442745 "Long duration aperiodic musical waveform generator" It plays sections of compacted samples back and forward to implement things like long decaying cymbals. US patent 4958552 explains algorithms how envelope data is extracted from natural instrument recordings and applied on loop samples as a approximated segmented functions. The original envelope may be removed from the stored loop sample by a waveform normalizer (US patent 4691608). Most important is that these chained envelopes can have basically any length and have (unlike e.g. ADSR) no fixed count of steps. Combined with crossfading between adjacent loop samples this permits very flexible sound definition.
Triangular wave modulation (US patent 5164530) is an FM-like Casio speciality that generates waveforms by modulating a monotonous carrier function with a sine (or other) wave - decoding the signal by mirroring it at a triangular wave. With the same count of operators (here only 2?) the produced waveform has higher harmonics than normal FM because at high modulation the wave peaks fold back into the opposite direction. Without modulation it outputs a sine wave and so can nicely blend between very dull and bright timbres. The carrier waveform stands in ROM and so can be switched between a variety of timbres. Like with FM, operators can be combined in various ways.
The US patent 5319151 "Data processing apparatus outputting waveform data in a certain interval" mentions for the "First Embodiment" that the chip size is only 5x5mm, a program word has 28 bits (including lower potion of next address) and these further hardware specs:
"With regard to the circuit scale and the operation time of the specific embodiment (PCM sound source system capable of producing eight polyphonic sounds) the control ROM has a size of 112K bits, RAM 445.4K bits and the control data/waveform ROM (for 100 timbres) 508K bits; one machine cycle is about 276 nanoseconds with a maximum number of cycles of the interrupt program when invoked being about 150; and the executing period of the interrupting process (tone output sampling period) is about 47 microseconds."
Expressed in KBytes this would mean 55.7KB RAM, 14KB program ROM and 63.5KB sound ROM, which isn't far away from a Commodore C64 with large ROM cartridge. Said CPU speed would be about 3.6 MIPS.
Interesting is that OKI made a general midi sound IC ML2860 (32 note polyphonic ADPCM) to play high quality ring tones in mobile phones, but the datasheet from 2002 contains a very strange note: "Please appreciate that ML2860 is not offered for musical instrument and toy applications, such as keyboards." This suggests that OKI licensed an efficient sound synthesis engine (possibly even surplus ICs) from Casio keyboards, but had to sign an agreement not to use it in competitive products against Casio.
The only M6387 based keyboard with MIDI (out) is the GZ-5, but it was crippled to only 10 preset sounds and no rhythm (likely to save ROM space to make the midi implementation fit). Many keyboards with M6387 CPU were initially released with a current pop song as the demo, and once the song wasn't popular anymore, they were re-released (to save royalties?) with more generic demos.
The "OKI M6387-xx" (30 pin SDIL, "xx" = software number of internal ROM) is the CPU of small polyphonic Casio keyboards. Technically it is a sophisticated softsynth on a chip with many algorithms (wavetable and FM variants, program loop synthesis?), complex envelopes and up to 8 note internal polyphony. It has only 1 sound output with internal DAC and supports a keyboard matrix with up to 12 outputs and 8 inputs.
I first had compared many keyboard PCBs and finally found the real thing in SA-series service manuals. Strange is that many PCB layouts look like when a (prototype?) version with 34 pins exists, where the additional 4 outer pins are simply connected with the regular corner pins. The clock rate 21.725 MHz is the same like with NEC 938GD in MT-540; also some pin names are similar, which hints that it might be based on it. Interesting is that the apparent GND pins 1 and 2 are genuinely test pins, those may help to read out the internal rom, connect external memory or even make it communicate with an external computer or microcontroller for editing synth parameters or playing midi data. Pin 4 is the filtered analogue power supply, which is wired through [a diode || 100 Ohm] to +5V and to a 100µF filter capacitor against GND. Also analogue GND can be wired independently to reduce crosstalk interferences.
The versions of "OKI M6387-xx" ("xx" = software number of internal ROM) strongly differ in demo songs, supported keyboard length and partly sound set.
software number hardware class notes & features
01 SA-1 32 keys, 100 sounds, 29 rhythms+13 fixed accomp., demo "Wake Me Up"
01B SA-20 dto. (bugfix release?)
03 SA-7 like 11(?) with demo "Classical Medley"
04 MA-120 49 keys, 100 sounds & 100 rhythms, demo "Together Forever"
11 SA-21 01 successor with 5 drumpads, 5 demos
13 MA-130 like 04 with demo "Classical Medley"
16 SA-35 32 keys, changed sound set & rhythms, 10 demos
22 SA-40 32 keys, only 8 sounds, no rhythm, dial controller, 6 demos
31 SA-41 like 11 with changed 5 demos (3 Hindi songs)
A23 GZ-5 32 keys, midi-out, only 10 sounds, no rhythm, no demo
A28 SA-65 37 keys, 30 rhythms, lcd port, 10 demos
Despite commercial IC vendor websites seem to offer them (who can say this about a Yongmei?!), I find absolutely no technical info about the M6387 (except that they often confuse it with Mitsubishi transistors). Unlike for other OKI ICs they have neither datasheets nor official pinouts, nor I found a generic OKI microcontroller with same package and matching pinout. But the OKI M6388 is a 4bit ADPCM voice recorder IC, and OKI made plenty of other ADPCM sound ICs (e.g. for speech synthesis). From what I read in such datasheets, their test pins often respond to something like 3 different voltages (between 0 and 5V) to select test modes, which might be useful to dump the internal ROM (likely complicated - I haven't tried yet and a better hacker than me failed). But datasheets don't tell more about it; I found only some references to a proprietary OKI chip development system µPLAT.
This pinout is based on various Casio SA-series service manuals and own examination.
pin name purpose
1 TEST2 test pin (wired to GND)
2 TEST1 test pin (wired to GND)
3 /RESET reset
4 AVDD analogue supply voltage +5V
5 OUT sound out
6 AGND analogue ground
7 GND ground
8 COSI crystal in | clock in (21.725 MHz)
9 COSO crystal out
10 VDD supply voltage +5V
11 KI0 key matrix in
12 KI1 key matrix in
13 KI2 key matrix in
14 KI3 key matrix in
15 KI4 key matrix in
16 KI5 key matrix in
17 KI6 key matrix in
18 KI7 key matrix in
19 KO11 key matrix out | NC
20 KO10 key matrix out | NC
21 KO9 key matrix out | NC
22 KO8 key matrix out | NC
23 KO7 key matrix out | POLY
24 KO6 key matrix out
25 KO5 key matrix out
26 KO4 key matrix out
27 KO3 key matrix out
28 KO2 key matrix out
29 KO1 key matrix out
30 KO0 key matrix out
The keyboard matrix inputs are active-high (react on +Vs aka VDD). The count of active KO lines depends on the software number, thus higher KO lines may be unused (NC) in certain CPU versions. SA-series only have 7 or 8, but I found 10 in the MA-130. My only keyboards using all KO lines are GZ-5 and SA-65. Both have a more complex discrete clock oscillator with COS0 unused. GZ-5 uses KO11 for MIDI-out and the rest for keyboard matrix. SA-65 uses KO8..KO11 to communicate with its LCD display controller IC "KS0035". Unusual is that the SA-series (and GZ-5) has its piano keyboard matrix grouped by 8 while those of most Casios are grouped by 6 (i.e. 2 per octave).
In 32 keys instruments (except SA-40), during startup (power-on reset) the M6387 CPU pulls KO7 (pin 23) high while it polls KI7 (pin 18). If both pins are connected, it will detect this pulse and enable higher polyphony; else it will limit polyphony to 2 notes. Then it sets KO7 low again to avoid blocking the input.
Thus to enable higher polyphony, you have to connect pin 23 with pin 8 (permanently or only at boot time). In keyboard models those use KO7 also for the key matrix (if yes, you will hear a beep when you hold an 1k resistor between pin 5 and 23) you need to connect them through a diode to avoid matrix bugs. In keyboards those don't, you can simply connect them directly.
However to prevent polyphony bugs, for polyphony >2 notes, a diode needs to be wired in series with each key (from an output to an input). This upgrade would be mechanically very difficult (involving trace cutting and likely SMD diodes) because small SA-series keyboards use a narrow multi-layer PCB with carbon trace contacts, where 32 additional diodes are very hard to fit (unless you anyway install an external keys PCB or MIDI kit). Thus in practise this is not worth the effort, because the corresponding midsize models with higher polyphony are quite cheap and easy to find on eBay.
If you like, of course you can also do the opposite and install a switch into a given connection between pin 23 and pin 8 to reduce the polyphony to 2 and though make melodies thinner. To test if your version supports it, simply short pin 23 with GND during power on; it will suppress said pulse and so switch to 2-note polyphony. (Don't do this regularly; the overload may harm the KO7 output, thus better cut the connection between 8 and 23 and replace it with a switch.)
In keyboards with key lighting or ROM-Pack support (like ML-2, PT-88, CT-840) SMD variants of the M6387 were used to permit higher pin count.
The "OKI M6521-xx" is a 60 pin SMD variant of the M6387 that (unlike older Casio keyboards) supports a matrix of key lighting LEDs without the need of driver transistors and can control a ROM-Pack port. Without a ROM-Pack connected, the key lighting apparently uses demo songs from its internal ROM. Like M6387 it is clocked at 21.725 MHz.
The "OKI M6567-xx" is an 80 pin SMD variant of the M6521 with even more pins, that is clocked twice as high (43.45 MHz) to support double polyphony (8/16 notes), a chord sequencer (100 chords) and LCD display. It was used e.g. in CT-840.