Casio-931-2006-06-17.txt Copyright 1983 - 2006 Robin Whittle Please don't publish this file, but refer to it's permanent home: http://www.firstpr.com.au/rwi/casio-keyboards/ If this site disappears when I do, you should be able to find a copy at http://www.archive.org . This is my 1984 documentation for the upD931 sound chip in the MT65, and the CPU inside this machine. Using this, you should be able to remotely control the sound chip, including defining your own voices. I think the serial nature of the way the bits are sent to specify voices indicates that for reasons of silicon layout, the designers chose a single-bit path for sending identical data to the 8 separate sound generation circuits. It is reasonable to assume that a single-bit path is also used to set up similar circuits in the upD77x chips used in the M10 and other first generation Casio keyboards, except that another part of the chip has ROM to store the bits. The sound generation system of these two series of chips is probably very similar, although I recall that the upD931 chip has more output bits than the uPD77x chips. By the way, I purchased 10 of these 42 pin upD931 chips as spare parts with the SIP R-2R network which is essential, or at least highly convenient, for making a low-glitch DAC to create the sound. I can part with some of these to a good home, for a moderate price. Below are my files, verbatim from its original CPM Wordstar 4.0 format converted to text by setting all bit 7s to 0, and removing a few lines ".pa" before tables (these were for page breaks when printing). First is the main doco file (my file 931LOT, on CPM disk -MISC.012). Then some C code, for the BDS C compiler (CPM, Z80), from -MISC.013. Below that are some text files showing the bits sent for voices etc. I have a few other files on my copies of these CPM disks, but as far as I know, all the important stuff is contained in the text file you are now reading. I have not documented here what I know about making a better DAC for it, but it basically involves using 74HC174 chips to latch the data bits, clocked on a clock line which is readily available, so the bits at the output of the latches always change at the same time and with symmetrical rise and fall times. Then we have the usual R-2R network, and a trimpot to finely adjust the weighting of the most significant bit. This can sound really good, but it is a lot of work to build or modify such a thing. Also it is important to sheild the circuit from capacitive contact with other signals - so use some foil around it. The trimpot can be strung between a latch output A, driven from the normal polarity of the most significant bit, and another latch B, driven from and inverted verstion of the most significant bit (use a 74HC04 in front of the input to the latch - do not invert the output of the latch to get this signal, because the inverter introduces a time delay which will cause horrible glitches.) Be sure to use multiple latch outputs in parallel for the most significant bit of the R-2R network. This ensures that the impedence driving the resistor array is relatively low, so as not to subtract much from the voltage generated by the MSB. We need to make that MSB voltage be almost exactly the same as the MSB being off, and all the other bits being on. This approach to the DAC, including adding extra resistors for lower bits not used in the original design (they don't need to be very precise) can be used for the M10, MT-30, CT-202 (two DACs - two upD77X chips) and the upD931 instruments. It can sound really good - be sure to take the DAC output itself and so not use the low pass filter and other guff which is part of the standard circuitry. One nice thing to do is a pot which fades between the raw and the filtered signal. Be sure to avoid capacitive coupling between the latch outputs and the point on the R-2R network where the currents are summed. All such capacitive coupling produces glitches. Normally, one never has a raw DAC output for audio, but here we are converting at 500kHz or so, and we can't have a sample and hold, since the DAC does not settle properly within such a short time. Our objects are to have: 1 - Accurate MSB value so there is no level mismatch around zero. 2 - Low capacitive glitches, as noted above. 3 - Symmetrical rise and fall times and symmetrcical impedance for low and high frowm whatever we drive the R-2R network with. A bunch of 74HC174s is a good approach. Do not use 74C174 - they are too slow, have asymmetrical rise and fall times and probably have high, asymmetrical output impedences too. I have some circuit diagrams for this stuff, but all the important details are described above. My permanent Web address is http://www.firstpr.com.au rw@firstpr.com.au Robin Whittle 17 June 2006 ************************************************************************ ** ** ** CASIO SOFTWARE CONTROL - TALKING TO THE UPD-931 CHIP ** ** ** ** The Casio Techzine Volume II Robin Whittle ** ** ** ** Investigations started 1/83 Written 3/84 ** ** ** ** For Ian Robson 5/11/84 ** ** ** ************************************************************************ ****** INTRODUCTION ****** **** GENERALITIES **** This Bulletin is a follow up to "Modifying the Casiotone Instruments" - a 14 page booklet I published in August 1981. In early 1983 Casio released the MT-65 and the CT-405 which use the upd-931C sound LSI. This is controlled by a separate computer chip which tells it when to play notes, and defines the exact details of the sound to be played. This means that it is possible to talk to the 931 from an external computer so as to play notes and define new voices. This Bulletin tells you everything you need to know to construct the hardware and software interfaces to do this. I have assumed that the reader is reasonably adept at digital and analog electronics, and computer programming, or is willing and able to come to terms with these realms as the work procceeds. **** BACKGROUND **** In early 1981 when I first started prowling around inside the M- 10 I kept thinking "Wouldn't it be good if there was some way of computer interfacing to this machine so I could define voices.". I was rather depressed when the MT-31 and MT-40 were replaced by the MT-11 and MT-45, but my prayers were answered when the MT-65 was released. I bought one immediately and soon found out that voices and notes were indeed defined exterally to the sound chip, so I wrote a computer program to look at the messages which were being sent to the 931. What I saw confused me greatly and it was many months before I could spend the time to figure it out. Now I have got almost to the bottom of it all I can write a Bulletin on it. Last year I contacted the Australian Casio importers and ordered a service manual and 10 931 chip with 10 resistor arrays with which to build DACs. It will be a long time before I can build a ten headed programmable Casio, so all my work is being done with my MT-65 which has a totally new DAC built into it as well as a "Slow Instrument Rate" or hardware octave drop. My CPM computer system is a Big Board I with 8" disk drives and a 4 Mhz clock. I have used C as the language for writing the 931 interface programs and can report that it seemed to be the right tool for the job. I used the Leor Zolman's BDS C compiler and found it to be a snappy and pleasing way to write these programs. **** 931 HARDWARE CHARACTERISTICS **** The 931 is a 42 pin IC which could make it tricky to find suitable sockets - I was lucky and found some in a surplus store. One alternative is to wire pins 20 and 21 together, and 22 and 42 together and then plug it into a 40 pin IC socket with pins 21 and 22 sticking out. The Casio Documentation calls it a 931G and uPD931C, while the chip itself is marked D931C. Although it is an NEC device I was unable to purchase it through normal NEC distributors, so I ordered 10 of them together with resistor arrays as spare parts for a total cost of AUS$260. TABLE 1 - 931 PIN CONNECTIONS Pin FUNCTION 1 D-3 } Data from the controlling computer is sent 2 D-2 } to these pins. 3 D-1 } 4 D-0 } 5 Chip Select Active Low (Ground). 6 Strobe A } Strobe lines from the controlling 7 Strobe B } computer. Active Low. 8 Clock inverter in. (4.9 MHz) 9 Clock inverter out. 10 Clock/3 out Sends 1.6 MHz to CPU. 11 "I/O 8" Not used. 12 Master/Slave control for clock (+5Volts). 13 Reset Active High. Driven by external circuit. 14 F-3 } 15 F-2 } Four latched outputs used to control 16 F-1 } the filter. F0, F1 and F2 are used in 17 F-0 } the MT-65. 18 Test - Connect to Ground for normal operation. 19 "I/O 5" Not used. 20 "I-4" Connect to Ground. 21 Main Ground connection. 22 "I-6" Connect to +5Volts. 23 "I/O 7" Sample and Hold pulse. 24 "I/O 6" Not used. 25 A-0 } Least significant bit. 26 A-1 } 27 A-2 } 28 A-3 } 29 A-4 } 30 A-5 } 31 A-6 } 32 A-7 } 33 A-8 } 17 Bit Audio output to DAC. 34 A-9 } Bits 0, 1 and 2 are not used in MT-65. 35 A-10 } 36 A-11 } 37 A-12 } 38 A-13 } 39 A-14 } 40 A-15 } 41 A-16 } Most significant bit. 42 VDD +5 Volts supply. The 931 is controlled by commands sent to it by an external computer. I will call each command a triplet because three 4 bit nybbles are sent each time. No notice is taken of the data input D0 to D3 pins until one of the strobes falls low. The first nybble is strobed into the 931 by presenting the nybble to the data pins and driving Strobe A from Hi to Lo and then back to Hi again - see Fig. 1. The data is then changed to the second nybble and Strobe B is driven Lo, the third nybble is presented and Strobe B is driven Hi. If the chip select input on Pin 5 is Hi then the strobes are ignored. The timing of data and strobes is completely asyncronous with respect to the clock, and can proceed at any speed, although I have not looked for an upper limit. The 931 was designed to generate its own clock from a varactor tuned inductor connected to Pins 8 and 9. At the last moment, this must have proved unreliable since the MT-65 has a little PC board containing a 74C04 to drive the tuned circuit into oscillation. The 74C04 then drives the 931 through Pins 8 and 9 with the clock signal and its inverse. It seems that inside the 931 there is an inverter with its input connected to Pin 8 and its output to Pin 9. This inverter is evidently intended to drive the tuned circuit into oscillation while a second inverter looks at Pin 9 and produces a square clock signal for the rest of the chip. Pin 8 has a high impedance and it seems sufficient to drive only this pin from a CMOS device with a symetrical signal to drive the chip properly. At present there seems little need for driving Pin 8 (as Casio do) with an inverted version of what they are feeding to Pin 9. Pin 10 is a divide by three clock output for driving the upd-930 CPU LSI which controls the 931 in the MT-65. It is about 1.6 MHz and is Hi for 66% of its cycle. When I was using my computer to read the triplets being sent by the upd-930, I needed to slow it down somewhat so I fed it with a 1KHz clock instead of the signal on Pin 10. Pin 12 is normally wired Hi to say that this 931 is generating its own clock instead of receiving from another source. Pin 13 is driven Hi at power on by an external circuit to reset the 931 chip. When an F4 X triplet is sent to the 931, the X nybble is latched to Pins 14 to 17, where they are used to control external devices such as filters. Sending F4 0 will cause the MT-65 Low Pass Filter (which follows the DAC to open up for the brightest sound. The 931 produces a 17 bit audio word every 8 clock cycles - at a rate of about 600 KHz. This is an extremely high sample rate by digital audio standards and is of great significance to the bright clear Casio sound. In a sampled audio system, any harmonics of the signal which are above the Nyquist frequency (half the sample rate) are reproduced below the Nyquist frequency rather than above it. For instance in a Yamaha DX7, which has a sample frequency of about 50 KHz, if you try to create a sine wave X KHz above 25 KHz it will come out at X KHz below 25 KHz. If you tried to make a 40 KHz sine wave it would in fact be audible as a 10 KHz sound. This is a problem in the Yamaha DX7 because some of the more complex FM sounds have very high harmonics which can fold over the Nyquist frequency and become objectionably audible - for instance the Sitar voice played in the highest octave. Similarly when a recording is being made for a Compact Disk which samples at 44 KHz, the sound must be put through a really mean filter to remove all signals above 22 KHz which would fold over as "Aliasing Distortion". Since the Casio sounds are all made of step waveforms, they are very rich in upper harmonics which will extend way beyond the audio range - these waveforms would sound terrible from a DX7 because virtually every sound would have a significant harmonic content above 35 KHz and so would fold over unmusically to below 15 KHz. Since the 931 samples at about 600 KHz only those harmonics above 1185 KHz will fold down to below 15 KHz to become audible, and since the harmonics are getting rather low in energy at this frequency, there is very little "Aliasing Distortion". Four clock cycles after the 17 Audio bits change, the Pin 23 Sample and Hold output goes Hi where it stays for three clock cycles before returning Lo one cycle before the next sample is produced. All DACs produce a glitch or spike when the input data is changed (mainly because of unwanted capacitive coupling in the resistor array) and the S/H signal is intended to sample the DAC only after its glitches have settled down. Unfortunately in the MT-65 the glitches last longer than four clock cycles and so the Sample and Hold is largely ineffective. This signal should however be useful for strobing and deglitching other DACs. ****** MODIFICATIONS TO THE MT-65 ****** ** APO DISABLE AND FOOTPEDAL SUSTAIN ** There are a few mods which you may find worth doing to the MT-65 - disabling the auto-power-off function, halving the clock rate, installing transpose switches and a foot pedal sustain function. The MT- 65 and the CT-405 use the same main circuit board - the only difference is that the MT-65 is missing a few components. Table 2 is a copy of the switch map of the upd-930 CPU LSI as shown in the MT-65 sevice manual, with a few additional notes. The auto power off function of the MT-65 can be disabled by installing the diode labelled Y in Fig 2. If you install the diode A, PNP transistor B and resistors C and D you will be able to add an external foot pedal sustain function to the MT-65. The footswitch connects between ground and the junction of the two new resistors. Closing the switch will cause this circuit to close switch position 6-8 to enable the pedal sustain function - the 930 CPU will not turn off the notes you have played until you release the footswitch. In my MT-65 I can turn pedal sustain on with either an external footswitch or a toggle switch mounted to the left of the keyboard. Fig 2 shows the component side of the board just to the left and to the rear of the 930 CPU LSI. ** SLOW INSTRUMENT RATE ** The slow instrument rate or hardware octave drop is achieved by dividing the 4.9 MHz clock which is fed to the 931 LSI. Disconnect the two wires between the 74C04 and Pins 8 and 9 of the 931, and connect Pin 8 to the centre of a toggle switch (C&K T101). Also connect Pin 8 to a 10k resistor going to ground. One side of the toggleswitch goes to Pin 6 of the 74C04 and the other side goes to Pin 13 of a 4013 flip-flop which is wired up according to Fig 14 of "Modifying the Casiotone Instruments". Pin 11 of the 4013 is also connected to Pin 6 of the 74C04. Beware that a 4013 is not specified to work at 4.9 MHz so you may have to try alternative chips to get it working. Be sure to ground the chassis of the switch by wrapping a piece of wire around a spring washer between the switch body and the case of the MT-65. For all my modifications I use precut, prestripped lengths of Wire-Wrap wire which I trim so that only 2mm of bare conductor is exposed at each end. ** TRANSPOSE SWITCH ** The main circuit board has three ribbon cables attached to its rear edge - from left to right these are called CC, CK and CY. Table 3 shows the function of these wires in detail. One useful feature that can easily be added to the MT-65 is a transpose switch - connect the cathode of a diode to CY 8 and the anode to the middle terminal of a centre off toggleswitch (C&K T103). The two oustide terminals of the switch go to CC 5 and CC 6 so that when the switch is moved to the left, the 8-8 switch position is closed. When you press a key with 8-8 closed the 930 CPU remembers that note and transposes the entire keyboard up to that note when 8-8 is released and 8-7 is closed. In this way the middle C key can be set to C, C# D etc up to B above middle C. ** CONNECTING AN EXTERNAL KEYBOARD ** I intend to connect a full sized external keyboard to my MT-65 in the near future. This will involve bringing buffered Common and Sense lines out to a 25 pin D socket on the side of instrument - buffering is neccesary to protect the 930 CPU from external static electricity. I will connect the Common lines C1 to C9 to the inputs of CMOS buffers such as a 74C244 and connect the outputs to the D socket. The Sense lines coming back from the new keyboard will be pulled up to +5 Volts with 10K resistors and sent to some more buffers. The output of each Sense buffer connects to the cathode of a diode, and the anode goes to one of the MT- 65 sense lines S1 to S6, so that either the internal or external keyboard can pull the sense line low. I will be using a keyboard from a second hand CT-101, which is wired up to suit the switch map of the upd-773 as shown on page 6 of "Modifying the Casiotone Instruments". The wiring is compatable with the MT-65 except for the C1 and C5 keys, so I will modify the new keyboard to suit. ** COMPUTER INTERFACE TO THE 931 ** To control the 931 sound LSI from an external computer, it is neccesary to install a socket and data selectors or buffers so that the data and strobe lines of the 931 can be driven either by the 930 CPU or by the external computer. Probably the neatest way to acheive this is to cut the tracks leading to 931 Pins 1, 2, 3, 4, 6 and 7, and install two 74C157 quad 2 input multiplexers, so that they select either the 930 CPU or the socket to drive the 931. The select pins of the 74C157 are pulled high by a 10K resistor to select the 930 until the external computer pulls them low. The wiring of the single 8 bit external computer port is shown in Table 4. It is wise when transmitting edge sensitive data along a ribbon cable to ensure that the signal wires are separated by ground wires which are connected to ground at each end of the cable. I drive my MT-65 directly from a Z-80 PIO chip because I beleive that TTL buffers are too fast for their own good and would generate objectionable noise spikes in the ribbon cable. I found that the PIO does not pull up sufficiently to satisfy CMOS devices all the time so I installed 33K pullup resistors in the MT-65 to make sure. Since I want to be able to send the Data and Strobe pulses from the 930 CPU to external 931 chips, I do not use a multiplexer as described above, but use three 74C244s and an inverter so that when Bit 6 of the computer port is not pulled Lo, then the MT-65 drives Bits 0 to 5 with the Data and Strobe signals. In the future I will send this to other 931 chips so I can play them directly from the MT-65. When I was using my computer to read the triplets coming from the 930 CPU, I slowed its clock to 1 KHz and used a program to look at the port for Strobe and Data signals, which were converted into an ASCII file. If you want your computer to read the triplets when the 930 when it is operating at full speed, then I think you will need to devise a means of putting the Strobe and Data signals into a FIFO (First In First Out memory) such as the Western Digital WD1510. I beleive there is also a Zilog FIFO device which can probably connect directly to your computer bus. Alternatively you could slow the 930 clock rate only when it sends a triplet. ** CLEAN UNFILTERED AUDIO OUTPUT ** To get a clear unfiltered audio signal from the MT-65, connect your line out socket via a 0.1 uf capacitor to Pin 1 of 4558-2, which is the 8 pin dual op-amp second from the right on the main board. You can adjust the trimpot marked VR-6 to get the clearest sound - this is the weighting adjustment for the most significant bit of the DAC. I have made a clear low glitch 16 bit DAC but I want to do more work on it before I publish the design as proper layout is crucial in getting it to work correctly. TABLE 4 - EXTERNAL COMPUTER PORT FUNCTIONS PORT FUNCTION BIT No. 0 Data 0 To 931 Pin 4 via Multiplexer. 1 Data 1 To 931 Pin 3 via Multiplexer. 2 Data 2 To 931 Pin 2 via Multiplexer. 3 Data 3 To 931 Pin 1 via Multiplexer. 4 Strobe A To 931 Pin 6 via Multiplexer. 5 Strobe B To 931 Pin 7 via Multiplexer. 6 Multiplexer control - External drive enable active Lo. 7 Not used. TABLE 3 - RIBBON CABLES TO MT-65 MAIN BOARD CC 1* Ground CK 1 C1 CC 2* Pedal Sustain CK 2 C2 CC 3* CK 3 C3 CC 4 To Tempo Pot CK 4 S1 CC 5 S8 CK 5 S2 CC 6 S7 CK 6 S3 CC 7 S6 CK 7 S4 CC 8 S5 CK 8 S5 CC 9 S4 CK 9 S6 CC 10 S3 CC 11 S2 CY 1 S6 CC 12 S1 CY 2 S5 CC 13 C3 CY 3 S4 CC 14 C4 CY 4 S3 CC 15 C9 CY 5 S2 CC 16 C10 CY 6 S1 CC 17 C20 CY 7 C9 CC 18 C19 CY 8 C8 CC 19 Tempo LED CY 9 C7 CC 20 +5 Volts CY 10 C6 CY 11 C5 * Not used in MT-65 CY 12 C4 CY 13 C1 TABLE 2 - SWITCH MAP FOR THE UPD-930 CPU LSI Sense S1 S2 S3 S4 S5 S6 S7 S8 Pin 51 Pin 50 Pin 49 Pin 48 Pin 47 Pin 46 Pin 45 Pin 44 CC 12 CC 11 CC 10 CC 9 CC 8 CC 7 CC 6 CC 5 Common C1 C 1 C#1 D 1 D#1 E 1 F 1 CK 1 Pin 52 C2 F#1 G 1 G#1 A 1 A#1 B 1 Y Z CK 2 APO Chrd Pin 53 disable Memory C3 C 2 C#2 D 2 D#2 E 2 F 2 Casio Fingered CK 3 Chord Pin 54 C4 F#2 G 2 G#2 A 2 A#2 B 2 Manual Arpeggio CY 12 Bass Pin 55 C5 C 3 C#3 D 3 D#3 E 3 F 3 CY 11 Pin 56 C6 F#3 G 3 G#3 A 3 A#3 B 3 Pedal CY 10 Sustain Pin 57 C7 C 4 C#4 D 4 D#4 E 4 F 4 X Octave CY 9 Memory Down Pin 58 C8 F#4 G 4 G#4 A 4 A#4 B 4 Trans- Trans- CY 8 pose Set Pin 59 C9 C 5 Syncro Start/ Fill- Mod I Mod II Tone Rhythm CY 7 Stop In Select Select Pin 60 C10 Organ Flute Trumpet Oboe Violin Tone CC 16 (Piano) (Harps) (Celst) (Mando) (Funny) Change Pin 61 C19 Bass 2 Bass 3 Chord2 Chord3 Sustain Vibrato Delay Reverb CC 18 (---Bass4---) (---Chord4---) Vibrato Pin 71 C20 Rock Pops Disco 16Beat Swing Latin Arp. 2 Arp. 3 CC 17 Swing (---Arp. 4---) Pin 70 Notes: Notes to Table 2. 1/ To close a particular switch position, connect a diode from the Common line (Cathode) to the Sense line (Anode). For instance to add an octave down switch (Switch position 7-8), connect the switch and diode in series with the cathode of the diode going to Pin 58 (CY 9) and the other end of the switch going to Pin 44 (CC5). The CC, CK and CY numbers refer to the three ribbon cables that connect to the main board and are the most convenient place to connect to the C and S lines. 2/ The 80 pins of the upd-930 are numbered anticlockwise from the dot on the package - the PCB has a little 1 to indicate pin 1. 3/ Tones within ( ) are selected when switch position 10-6 is closed - (Tone Change). 4/ X is permanently closed by a diode in the MT-65 for reasons unknown. See Diode X in Fig 2. 5/ Y and Z are permanently closed in the MT-405 but not in the MT-65. Adding Y (Switch position 2-7) as shown in Fig 2 will disable the MT-65's auto power off function. Adding Z causes the Auto Chord to hold after the keys are released. **** LOW LEVEL INTERFACE SOFTWARE **** Once you have interfaced your 931 to a port accessable by your computer as described in Table 4, the next step is to write a subroutine to transmit a triplet to the 931. In this document I will represent a triplet as three hexadecimal digits such as 21 6, F4 3, A7 1 or E1 0. Triplets consist of three 4 bit nybbles, each represented here by a hex digit. It is important to note that my representation puts the third physical nybble second and the second physical nybble third. This is because the second physical nybble seems to be data while the first and third seem to be the address it is being written to. Therefore a triplet that I write as 12 3 is actually transmitted as 132. The exact bit pattern you need to send to the port is summarised in Table 5. Note that the enable line is only low while the triplet is being sent, so that the computer only takes control of the 931 when neccesary. If you have any trouble with your program or interface, step through the program very slowly and use a CRO or logic probe to verify that the correct signals are getting to the pins of the 931 itself. If this does not clarify the problem, you should suspect spikes caused by capacitive coupling in the connection cable. To find these spikes you will need to send a continuous stream of triplets and look at the pins with a fast bright CRO. With this information you should be able to write a suitable program for your computer in machine code, assembler, Basic, C, Pascal or almost anything else. At present I have two programs, both written in C, which take ASCII as an input and drive the port using the same subroutine. One program takes triplets from a text file and the other takes them directly from the keyboard. The file program has special facilities for ignoring comments in the file so that I can heavily comment the voice definition files as I edit them with Wordstar. Now that the exact format for a voice specification is known you may wish to bypass this approach and write a special voice definition program which communicates directly with the 931 and allows you to interactively change voice parameters. TABLE 5 - BIT PATTERN TO WRITE A TRIPLET TO THE PORT Pattern of bits for the triplet ab c Output Port Function Time 7654 3210 EBA data 1111 1111 Initial state T0 1011 aaaa Setup nybble a T1 1010 aaaa Strobe nybble a T2 1011 aaaa Send nybble a T3 1011 cccc Setup nybble c T4 1001 cccc Send nybble c T5 1001 bbbb Setup nybble b T6 1011 bbbb Send nybble b T7 1111 1111 Final state T8 **** PLAYING NOTES AND SELECTING MODES **** When the MT-65 is turned on, both the 931 and 930 CPU are reset. The 930 wakes up and scans the control panel to determine which voice button has been depressed. It then sends the appropriate voice message of about 110 triplets to the 931. This voice message includes triplets to select the appropriate reverb and vibrato mode. The 930 CPU scans the keyboard and when it detects that a key has been pressed, it figures out what pitch has to be played - and sends three triplets to the 931 to start that note. When that key is released, a single triplet is sent to turn the note off. The 931 handles all aspects of sound generation including delayed vibrato, sustain and reverb. Only the transposition and footpedal sustain functions are handled by the 930 CPU chip. The 931 has eight sound channels with which to play notes and the 930 uses these in turn as it needs them. When the 930 CPU wants to a play a note it tells the 931 :- 24 9 Sound channel 4, your note is G. 34 6 Sound channel 4, your octave is one above middle C. E4 1 Sound channel 4, start playing! When it wants to turn that note off, it sends a single triplet :- E4 0 Sound channel 4, stop playing! When you select a new vibrato mode or sustain mode, the 930 CPU sends a single triplet such as :- D3 3 Set delayed wide vibrato mode. D4 1 Set sustain mode. ** PLAYING NOTES ** Here is the exact definition of how to play a note on the 931. First of all you need to set the note of a sound channel :- 2S N Where S is the sound channel 0, 1, 2, 3, 4, 5, 6, or 7, and N is one of the following :- Pitch = 2S 0 (0 Hz - the waveform stops.) 2S 1 (Very high, irrespective of octave.) 2S 2 C 2S 3 C# 2S 4 D 2S 5 D# 2S 6 E 2S 7 F 2S 8 F# 2S 9 G 2S A G# 2S B A 2S C A# 2S D B 2S E C one octave up. 2S F (Very high, irrespective of octave.) The descriptions in brackets are for those functions which are not normally used. Next you specify which octave you want your note played in :- 3S 0 (3 octaves below Middle C) 3S 1 (2 octaves below Middle C) 3S 2 3 octaves below Middle C 3S 3 2 octaves below Middle C 3S 4 1 octave below Middle C 3S 5 Middle C octave 3S 6 1 octave above Middle C 3S 7 2 octaves above Middle C 3S 8 (Middle C +2, but only every 8th cycle happens.) 3S 9 (Middle C +2, but only every 4th cycle happens.) 3S A (Same as 3S 8) 3S B (Same as 3S 9) 3S C (Middle C +2, but only every 2nd cycle happens.) 3S D (Middle C +2, every cycle happens.) 3S E (As above except slightly different waveforms.) 3S F (As above but with weird tones and fluctuations.) The third triplet is to turn on the sound channel :- ES 1 Sound channel - start playing your note. Only bit 0 is relevant - 1 is on and 0 is off. So to end the note for a particular sound channel the triplet is :- ES 0 Sound channel - stop playing your note. If Reverb or Sustain is enabled then the note will fade away slowly, if not then it will end smoothly and quickly in about 25 ms. ** SETTING REVERB AND VIBRATO MODES ** The Vibrato triplets usually start with D1 but D0, D2 and D3 work just as well. The possible modes are listed below. D1 0 No Vibrato D1 1 Narrow Vibrato D1 2 (Wide Vibrato) D1 3 Delayed Wide Vibrato D1 4 to D1 F (Repetition of above.) Similarly the Reverb modes could start with D5, D6 or D7 instead of D4. D4 0 No Sustain or Reverb - 25 ms release D4 1 Sustain - 0.9 sec release D4 2 (Longer Sustain - 1.2 sec, plus Reverb tail) D4 3 (Same as D4 2) D4 4 Reverb - 1.7 second tail D4 5 (0.9 sec Sustain with 1.7 sec Reverb tail) D4 6 (Same as D4 2) D4 7 (Same as D4 2) D4 8 to D4 F (Repetition of above) The Reverb mode is one of the most original and exiting features Casio have ever put into an instrument. When the volume drops to one eighth of its maximum, the decay rate slows right down, so that it takes another 1.5 seconds to decay completely. This reverb tail comes on either near the end of the 25 ms end decay when a note ended, or when the note decays naturally - for instance an extended Harpsicord note. Certain voices such as Celeste cannot have a Reverb tail because they have no "Time 4". This is explained in section on the Bitlist. **** HOW VOICES ARE DEFINED **** Below is a list of the triplets which are sent by the 930 CPU when the Cosmic Tone voice is selected. These are the exact triplets as read by my computer, but I have arranged them on the page in logical groups and added my own comments. Cosmic Tone D4 0 Turn off Sustain and Reverb modes. E7 0 E6 0 Turn off all sound channels so no E5 0 E4 0 notes are playing. E3 0 E2 0 E1 0 E0 0 20 0 Set sound channel 0 to pitch = 0 Hz. (?) 90 0 This is a deep mystery. (?) B0 0 Select Waveform A for loading. Load the 16 increments for Wave A. -87654321012345678+ 60 0 A7 2 +2 * 60 1 A7 C -4 * 60 2 A7 2 +2 * 60 3 A7 0 * 60 4 A7 0 * 60 5 A7 0 * 60 6 A7 0 * 60 7 A7 0 * 60 8 A7 2 +2 * 60 9 A7 2 +2 * 60 A A7 0 * 60 B A7 0 * 60 C A7 A -2 * 60 D A7 A -2 * 60 E A7 0 * 60 F A7 0 * .pa B2 1 Select Waveform B for loading. Load the 16 increments for Wave B. -87654321012345678+ 60 0 A7 0 * 60 1 A7 0 * 60 2 A7 0 * 60 3 A7 0 * 60 4 A7 6 +8 * 60 5 A7 E -8 * 60 6 A7 0 * 60 7 A7 0 * 60 8 A7 0 * 60 9 A7 0 * 60 A A7 0 * 60 B A7 0 * 60 C A7 0 * 60 D A7 0 * 60 E A7 0 * 60 F A7 0 * F4 0 Load 0000 into the filter latch. B1 1 B1 1 B1 1 The Bitlist - 26 bits which B1 1 B1 4 B1 4 control the operation of the B1 4 B1 4 B1 4 eight sound channels. B1 4 B1 4 B1 4 B1 4 B1 1 B1 1 B1 4 B1 4 B1 4 B1 4 B1 4 B1 4 B1 4 B1 4 B1 1 B1 4 B1 4 D1 0 D4 1 Set up correct Vibrato and Sustain modes. F1 1 Reset the audio output accumulator to 0. 20 8 Set sound channel 0 to strange mode. (?) Pretty odd eh?? If you thought notes could only be made from wavetables and ADSR parameters then you would be lost in Casio/NEC country, because things are WEIRD out here! When it comes to defining voices, the upd-931 is idiosyncrasy city - you can imagine my confusion when I first saw this stream of triplets. Now for a guided tour in greater detail. Turning off the Sustain mode and ending possible notes in all sound channels makes good sense, so that there are no nasty sounds while the voice is being changed. You can do without these triplets provided there are no notes playing. I have no idea why sound channel 0 is set to a frequency of 0 and I have been unable to find the function of the 90 0 triplet. Neither of these triplets seem to be essential to the proper loading of voices. Each of the 8 sound channels must have its own copy of the two Waves A snd B. The B0 0 triplet selects the Wave A increment memory to be loaded. The 60 0 triplet says that increment 0 is about to be loaded, and the A7 2 triplet specifies that the increment is +2. 60 1 and A7 C specify that the second increment is C which translates into -4. 60 2 and A7 2 specify that the third increment is +2, and so on with the next few increments being 0. The waves are not stored as a list of values, but are calculated in real time from a list of 16 increments, where the possible increments are -8, -4, -2, -1, 0, +1, +2, +4 and +8. If all the increments do not total 0 then watch out! There are two possible reasons for this seemingly overcomplicated approach. One is that it is really the easiest way to get the range and detail they wanted in the waveforms. The other is more legalistic - see the "Ravings and Droolings" section. Wave B is loaded in a similar fashion to Wave A. This procedure is fully discussed later on. F4 0 simply latches 0000 to Pins 14, 15, 16 and 17 of the 931, which in the MT-65 means that the Low Pass filter which follows the DAC is disabled and has a flat response. The 26 triplets which follow are actually a list of 26 bits which must be loaded into each sound channel. The B1 4 triplets are identical to B1 0 so you can see this as simply as a list of 1s and 0s. I beleive this data format is an interesting indication of the layout of the 931 chip itself. Each sound channel is a separate but identical area of the 931 chip and each needs 26 bits to tell it how to make the sound. One approach would be to have one 26 bit latch with 26 conductors feeding the data to each sound channel. This would impose awkward layout problems, and so an alternative method has been chosen. Since the various bits are required in different locations within the sound channel area, flip-flops are put in each of the desired locations and connected to a common clock. The output of one flip-flop is fed the input of the next to form a shift register, in addition to driving the relevant part of the sound channel. This means two conductors winding their way along the sound channel rather than having 26 conductors trailing across it. The 26 bits are loaded by clocking them into the first flip-flop one at a time. The B1 4 or B1 0 triplet clocks in a 0 while a B1 1 clocks in a 1. All sound channels are loaded with their bit list simultaneously. ** WAVE INCREMENTS ** Each of the two waves has a range of between +31 and -31, that is to say that the accumulator that generates the waves is six bits wide. The total of the two waves, after multiplication by each wave's respective volume number, cannot exceed + or - 31 or terrible noises will be produced. The standard Casio voices only use half of this range, and there may well be good reasons for this. The waves must be constructed of increments of + or - 1, 2, 4 or 8. First of all you must push a 1 or 0 into the sound channel shift register - the first bit controls whether the A or B waveform is to be defined. Note that the second nybble is non relevant as are bits 3, 2 and 1 of the third nybble - all that matters when pushing bits is the B in the first nybble and the bit 0 of the third nybble. B0 0 Wave A is ready to be loaded. B0 1 Wave B is ready to be loaded. A pair of triplets loads the increment into the wave memory - the first triplet specifies which of the 16 time periods is to be loaded, and the second loads in a nybble which is interpreted as the desired increment. There are 16 possible A7 X triplets, of which only 9 are used. 60 3 Here comes the increment for segment 3. A7 7 (+8) A7 6 +8 A7 5 (+4) A7 4 +4 A7 3 (+2) A7 2 +2 A7 1 +1 A7 0 0 A7 9 -1 A7 A -2 A7 B (-2) A7 C -4 A7 D (-4) A7 E -8 A7 F (-8) To make life easier here is a graphic representation of the increment triplets. A7 6 +8 +7 +6 +5 A7 4 +4 +3 A7 2 +2 A7 1 +1 A7 0 ----0----- A7 9 -1 A7 A -2 -3 A7 C -4 -5 -6 -7 A7 E -8 To select the wave you want to load, you must push a bit into the bitlist shift register, which shifts all the bits along so that the sound is radically changed. Therefore once you have loaded your waves, you must reload the bitlist. It is however possible to reload the bitlist without changing waves. Each MT-65 voice has four "modulations" or mutations which differ only in certain parts of the bitlist, the 930 CPU however loads both waves and bitlist when one of the modulation buttons is pressed. ** THE BITLIST ** Any triplet starting with a B will push a bit into the shift registers which control the sound channels. The second nybble could be anything and only the least significant bit of the third nybble is used. The bitlist fills the 26 flip-flops that make up each shift register. The outside flip-flop is the one which controls whether the A or B waveform is to be loaded, and when the bitlist has been pushed, it is filled with the last bit on the list - bit 26. This bit has no effect on the sound. The first bit on the list - bit 1 is pushed furthest into the depths of the sound channel. This means that when you want to load the shift register, you should push 26 bits - no more, no less. The bitlist breaks into sections as shown in Table 6. The envelopes of the two waves cannot be individually controlled, and are locked together in time. There are four possible envelope structures which are selected by bits 14 and 15 while bit 13 provides a split mutation of each one of these four basic modes. When bit 13 is on, Wave A follows the A envelope and the B envelope on alternate cycles. The eight envelope modes are shown in Fig 3. There are three or four time zones which control how long the individual sections of the envelope last. If bit 16 is 1 then the volume of both waves decays to 0 at the end of Time 3. If bit 16 is 0 then Time 4 is started before the end of Time 3. Normally Time 4 will start when the volume has decayed to half of the maximum - this occurs after half of Time 3 has elapsed. If however bit 10 is 1 then Time 4 will start when the volume has dropped to a quarter of the maximum. The length of the Time 4 decay is determined by bit 11 which controls the decay rate (1 = slow) and bit 10 which controls the volume that T4 starts with. I have used my CRO to measure the various time options and have listed them in Table 7. Note that when the Time 1 bits are equal to 1,2 or 3, the Time 1 envelope consists of two time segments - the first is controlled by the bits and the second which is always 11 ms long. The second segment starts when the first has reached 7/8 of the maximum volume. It seems that each wave produces 6 bits of data (+ - 31) and that this is multiplied by an 8 bit volume counter (0 to 255). The two 14 bit products are summed and but if the total overflows into the 15th bit then trouble occurs. Therefore each sound channel produces a 14 bit note, and these are added to form a 17 bit output to the DAC. The envelope structure of the note is controlled by whether the two volume counters are clocked up or down, and the rate at which the counters rise or fall is determined by the frequency which is selected to clock them. For instance a 430 msec decay could be generated by clocking the 8 bit volume counters with the 4.9 MHz clock after 14 stages of division. .pa The rules for generating the envelope times seem to be as follows. Provided the note is not terminated early, Time 1 is followed by Time 2 and Time 3. If Bit 16 is 1 then both waves will decay to 0 at the end of Time 3. If Bit 16 is 0 then Time 4 will be started when the Time 3 volume reaches 1/2 (or 1/4 if Bit 10 = 1) of maximum. Time 4 has two decay rates which are selected by Bit 11, and when the volume reaches 1/8 of maximum, a slightly slower rate usually takes over. However if the Reverb mode has been set then a 1.7 second Reverb decay rate takes over - even though the note has not been terminated yet. If the sound channel is told to stop playing during Times 1 or 2, then their times are immediately changed to 27 ms so that they are completed in less than 53 ms. Instead of switching to Time 3 or Time 4, the sound channel goes to Release Time which has a 27 ms decay unless the Sustain mode is on, in which case one of two slower decay rates is substituted. If Reverb mode is on when the volume during Release Time reaches 1/8 of maximum, then a 1.7 sec decay will take over from there. If the note is terminated during Time 3 or Time 4 the sound channel immediately switches to Release Time and the sound decays as above from the current volume. Note that the Reverb Mode will add a 1.7 sec decay to all notes which pass through the 1/8 volume point during Time 4 or Release Time. Therefore unless Time 4 has been disabled with Bit 16, then all notes will have a 1.7 sec Reverb decay whether they are terminated or not. A voice such as Celesta which has no Time 4 will not end with a Reverb decay if the note is held on. I am very interested in having Reverb decays on all notes whether I hold or release a key because if the decays rate slows at 1/2 volume (Time 4) and slows further at 1/8 volume, then this is a pretty good approximation of a natural exponential decay. The people at Casio and NEC obviously had this in mind when they designed this piece of silicon - I bow in their general direction. Bit 12 is set only in the Mandolin voices of the MT-65. Its function is to retrigger the note at 12.7 Hz as long as the note is on, and Times 1 and 2 are complete. If these times add up to more than about 78 ms - as in the Mandolin I voice - then alternate trigger cycles are ignored and the note retriggers at half the normal rate. The 12.7 Hz seems to be twice the Vibrato speed - the pitch of Mandolin notes alternates between high and low when the Vibrato is turned on. The timebase for this retrigger/vibrato system seems to be started by the first note that is played after no others have been playing. Once the timebase has started all other notes will follow it, although a Mandolin I note could trigger on every odd or even cycle. There does not seem to be any way of changing the speed of this timebase except by speeding up everything as mentioned below. Bits 17 and 18 control the initial division of the master clock frequency for the envelope and vibrato counters. It seems that they are mainly intended to speed up the testing of the chip, by disabling one or two frequency division stages. Bit 17 doubles the envelope speeds (halves envelope times) and bit 18 quadruples them irrespective of bit 17. I cannot find the function of Bit 19 but I am sure it has one. This remains an unsolved riddle. When Bit 20 is set, alternate cycles of both waves appear upside down and back to front - they go negative instead of positive and run backwards instead of forwards. Graphicaly speaking, this is a rotation, but its musical significance is that it is great for making bass sounds. Bit 21 simply inverts alternate waves, so if both bits 20 and 21 are set then the waves will be played alternately backwards and forwards. Bits 22 and 23 control the way in which Wave B can be turned off and on over a cycle of four waves - while bits 24 and 25 perform a similar function for wave A. When both bits are 0, the wave is always turned on, but if bit 22 is set, the only the 1st and 3rd waves out of a cycle of 4 are enabled. If bit 23 is set then the 1st wave is enabled and the 2nd, 3rd and 4th turned off. If both bits are set then only the 1st and 2nd waves are enabled. This is illustrated in Table 6 where a > represents a wave that is turned on, and a | represents a wave that has been turned off. TABLE 6 - THE FUNCTIONS OF THE BITLIST Trumpet Celesta Harp BIT MandolinHarpsi Funny 1 0 0 0 0 1 1 Time 3 1 1 0 0 1 0 2 1 0 1 1 0 1 3 0 0 0 1 0 0 4 Time 2 0 1 0 0 1 0 5 0 0 0 0 0 1 6 1 0 0 0 0 0 7 Time 1 0 0 0 0 0 0 8 0 0 0 0 0 0 9 1 1 0 0 0 1 10 Time 4 starts at 1/4 Vol 1 1 1 0 1 1 11 Double Time 4 0 1 0 0 0 0 12 Retrigger at 12.7 Hz ENVELOPE MODE SELECT 0 0 0 0 0 0 13 A env split A/B/A/B 0 1 0 0 1 1 14 B decays to 0 in Time 2 0 0 0 1 0 1 15 A rises from 0 during T2 0 0 1 0 0 0 16 Disable Time 4 0 0 0 0 0 0 17 Double Env & Vib speed 0 0 0 0 0 0 18 Quadruple Env & Vib speed 0 0 0 0 0 0 19 Mystery 1 1 0 0 1 1 20 Alternate cycles are upside down and back to front 0 0 0 0 1 0 21 Invert alternate cycles 0 1 0 0 1 0 22 Mode Bits 0 1 0 1 0 0 0 0 0 0 23 Wave A 0 0 1 1 1 1 0 1 1 0 24 Mode Bits > > > > 0 0 0 0 0 0 25 Wave B > | | > > > | | > | | | 0 0 0 0 0 0 26 Controls loading of waves - has no effect on the sound TABLE 7 - ENVELOPE TIMES Bits T1 T2 T3 T4 0 Bit 7 Bit 4 Bit 1 Bit 10 1 Bit 8 Bit 5 Bit 2 Bit 11 2 Bit 9 Bit 6 Bit 3 0 0 0 ms 0 ms 7.5 ms 1100 ms 0 From 1/2 Vol 0 1 1 17 ms 7.5 ms 20 ms 650 ms 0 (6+11) From 1/4 Vol 0 0 2 29 ms 53 ms 86 ms 2200 ms 1 (18+11) From 1/2 Vol 0 1 3 59 ms 107 ms 430 ms 1300 ms 1 (48+11) From 1/4 Vol 0 0 4 82 ms 215 ms 860 ms 0 1 1 5 164 ms 430 ms 1720 ms 0 1 0 6 430 ms 860 ms 6900 ms 1 1 1 7 1720 ms 1720 ms Infinite 1 1 ///////////////////////////////////////////////////////////////////////////// C Code ------ Here are some programs which seem to be relevant to reading data sent to the upD931 chip and for sending data to it. CAS.C (Probably low-key - see the later programs for more functional code.) ---------------------------------------------------------------------------- #include bdscio.h #define END =64 /* This is the @ character to terminate the session */ main() { int abc[3]; /* Small array to hold three nybbles */ int t; /* Temporary variable for inpu character */ int p; /* Pointer to abc[] */ int q; /* Made = to 1 if a hex character or space is found */ int comm; /* Made = to 1 if comment mode has started */ printf("Driver for the Casio uPd-931 sound LSI\n"); p=0; while (t=getchar()) { q=0; if ( t >= '0' && t <= '9' && comm == 0) { abc[p++]=(t-'0'); /* 0 to 9 conversion */ q=1; } if ( t >= 'A' && t <= 'F' && comm == 0) { abc[p++]=(t-'A'+ 10 ); /* A to F conversion */ q=1; } if ( t >= 'a' && t <= 'f' && comm == 0) { abc[p++]=(t-'a'+ 10 ); /* a to f conversion */ q=1; } if ( t == ' ') { q=1; /* Space character */ } if ( q == 0) { /* If q is still 0 then the */ /* character was not a space */ /* or 0 - 9 ABCDEF abcdef */ /* Therefore it is the first */ /* character of a comment */ comm = 1; /* Comment Mode is set */ } if ( t == '\n') { /* Carriage Return */ comm = 0; /* End of comment mode */ p=0; /* Force pointer to start */ } if(p==2) { printf(" "); } if(p >= 3) { /* The array is full */ send(abc); p=0; } } } send(sabc) /* Sends the three nybbles to the LSI */ /* This drives an eight bit port which */ /* talks to the uPd931 via a Tristate */ /* buffer :- */ /* Bits 0, 1, 2 and 3 are data */ /* Bit 4 is Strobe A */ /* Bit 5 is Strobe B */ /* Bit 6 is Drive enable active low */ #define PIO 0x08 /* Address of Z80 PIO output port */ /* EBA data Functions of bits */ #define M1 0xFF /* 1111 1111 T1 initial */ #define M2 0xA0 /* 1010 aaaa T2 setup nybble a */ #define M3 0xB0 /* 1011 aaaa T3 send nybble a */ /* 1011 cccc T4 setup nybble c */ #define M5 0x90 /* 1001 cccc T5 send nybble c */ /* 1001 bbbb T6 setup nybble b */ /* 1011 bbbb T7 send nybble b */ /* 1111 1111 T8 final state */ int sabc[3]; { outp((PIO+1), 0x0F); /* Set port A to output */ /* EBA data Functions of bits */ outp(PIO, M1); /* 1111 1111 T1 initial */ outp(PIO,(sabc[0])|M2); /* 1010 aaaa T2 setup nybble a */ outp(PIO,(sabc[0])|M3); /* 1011 aaaa T3 send nybble a */ outp(PIO,(sabc[2])|M3); /* 1011 cccc T4 setup nybble c */ outp(PIO,(sabc[2])|M5); /* 1001 cccc T5 send nybble c */ outp(PIO,(sabc[1])|M5); /* 1001 bbbb T6 setup nybble b */ outp(PIO,(sabc[1])|M3); /* 1011 bbbb T7 send nybble b */ outp(PIO, M1); /* 1111 1111 T8 final state */ printf(". "); } =============================================================================== CF.C ---- /* PROGRAM TO READ A WS FILE AND SPIT IT OUT TO THE MT-65 */ #include bdscio.h #define END '@' main(argc,argv) char **argv; { int abc[3]; /* Small array to hold three nybbles */ int t; /* Temporary variable for inpu character */ int p; /* Pointer to abc[] */ int q; /* Made = to 1 if a hex character or space is found */ int comm; /* Made = to 1 if comment mode has started */ char ibuf[BUFSIZ]; if(fopen(argv[1],ibuf) == ERROR) { printf("Can't open %s\n",argv[2]); exit(); } printf("Driver for the Casio uPd-931 sound LSI\n"); p=0; while (t= (getc(ibuf) & 0x7F) ) { printf("%c",t); if ((t == END)|(t== EOF)|(t==CPMEOF)){ exit(); } q=0; if ( t >= '0' && t <= '9' && comm == 0) { abc[p++]=(t-'0'); /* 0 to 9 conversion */ q=1; } if ( t >= 'A' && t <= 'F' && comm == 0) { abc[p++]=(t-'A'+ 10 ); /* A to F conversion */ q=1; } if ( t >= 'a' && t <= 'f' && comm == 0) { abc[p++]=(t-'a'+ 10 ); /* a to f conversion */ q=1; } if (( t == ' ')|(t == '.')|(t == ':')|(t == '+')) { q=1; /* Space character or dot */ } /* or : or + */ if ( q == 0) { /* If q is still 0 then the */ /* character was not a space */ /* or 0 - 9 ABCDEF abcdef */ /* Therefore it is the first */ /* character of a comment */ comm = 1; /* Comment Mode is set */ } if ( t == '\n') { /* Carriage Return */ comm = 0; /* End of comment mode */ p=0; /* Force pointer to start */ } /* if(p==2) { printf(" "); } */ if(p >= 3) { /* The array is full */ send(abc); p=0; } } } send(sabc) /* Sends the three nybbles to the LSI */ /* This drives an eight bit port which */ /* talks to the uPd931 via a Tristate */ /* buffer :- */ /* Bits 0, 1, 2 and 3 are data */ /* Bit 4 is Strobe A */ /* Bit 5 is Strobe B */ /* Bit 6 is Drive enable active low */ #define PIO 0x08 /* Address of Z80 PIO output port */ /* EBA data Functions of bits */ #define M0 0xFF /* 1111 1111 T0 initial */ #define M1 0xB0 /* 1011 aaaa T1 setup nybble a */ #define M2 0xA0 /* 1010 aaaa T2 strobe nybble a */ #define M3 0xB0 /* 1011 aaaa T3 send nybble a */ /* 1011 cccc T4 setup nybble c */ #define M5 0x90 /* 1001 cccc T5 send nybble c */ /* 1001 bbbb T6 setup nybble b */ /* 1011 bbbb T7 send nybble b */ /* 1111 1111 T8 final state */ int sabc[3]; { outp((PIO+1), 0x0F); /* Set port A to output */ /* EBA data Functions of bits */ outp(PIO, M0); /* 1111 1111 T0 initial */ outp(PIO,(sabc[0])|M1); /* 1011 aaaa T1 setup nybble a */ outp(PIO,(sabc[0])|M2); /* 1010 aaaa T2 strobe nybble a */ outp(PIO,(sabc[0])|M3); /* 1011 aaaa T3 send nybble a */ outp(PIO,(sabc[2])|M3); /* 1011 cccc T4 setup nybble c */ outp(PIO,(sabc[2])|M5); /* 1001 cccc T5 send nybble c */ outp(PIO,(sabc[1])|M5); /* 1001 bbbb T6 setup nybble b */ outp(PIO,(sabc[1])|M3); /* 1011 bbbb T7 send nybble b */ outp(PIO, M0); /* 1111 1111 T8 final state */ printf(". "); } =============================================================================== CF.C ---- /* PROGRAM TO READ A WS FILE AND SPIT IT OUT TO THE MT-65 */ #include bdscio.h #define END '@' main(argc,argv) char **argv; { int abc[3]; /* Small array to hold three nybbles */ int t; /* Temporary variable for inpu character */ int p; /* Pointer to abc[] */ int q; /* Made = to 1 if a hex character or space is found */ int comm; /* Made = to 1 if comment mode has started */ char ibuf[BUFSIZ]; if(fopen(argv[1],ibuf) == ERROR) { printf("Can't open %s\n",argv[2]); exit(); } printf("Driver for the Casio uPd-931 sound LSI\n"); p=0; while (t= (getc(ibuf) & 0x7F) ) { printf("%c",t); if ((t == END)|(t== EOF)|(t==CPMEOF)){ exit(); } q=0; if ( t >= '0' && t <= '9' && comm == 0) { abc[p++]=(t-'0'); /* 0 to 9 conversion */ q=1; } if ( t >= 'A' && t <= 'F' && comm == 0) { abc[p++]=(t-'A'+ 10 ); /* A to F conversion */ q=1; } if ( t >= 'a' && t <= 'f' && comm == 0) { abc[p++]=(t-'a'+ 10 ); /* a to f conversion */ q=1; } if (( t == ' ')|(t == '.')|(t == ':')|(t == '+')) { q=1; /* Space character or dot */ } /* or : or + */ if ( q == 0) { /* If q is still 0 then the */ /* character was not a space */ /* or 0 - 9 ABCDEF abcdef */ /* Therefore it is the first */ /* character of a comment */ comm = 1; /* Comment Mode is set */ } if ( t == '\n') { /* Carriage Return */ comm = 0; /* End of comment mode */ p=0; /* Force pointer to start */ } /* if(p==2) { printf(" "); } */ if(p >= 3) { /* The array is full */ send(abc); p=0; } } } send(sabc) /* Sends the three nybbles to the LSI */ /* This drives an eight bit port which */ /* talks to the uPd931 via a Tristate */ /* buffer :- */ /* Bits 0, 1, 2 and 3 are data */ /* Bit 4 is Strobe A */ /* Bit 5 is Strobe B */ /* Bit 6 is Drive enable active low */ #define PIO 0x08 /* Address of Z80 PIO output port */ /* EBA data Functions of bits */ #define M0 0xFF /* 1111 1111 T0 initial */ #define M1 0xB0 /* 1011 aaaa T1 setup nybble a */ #define M2 0xA0 /* 1010 aaaa T2 strobe nybble a */ #define M3 0xB0 /* 1011 aaaa T3 send nybble a */ /* 1011 cccc T4 setup nybble c */ #define M5 0x90 /* 1001 cccc T5 send nybble c */ /* 1001 bbbb T6 setup nybble b */ /* 1011 bbbb T7 send nybble b */ /* 1111 1111 T8 final state */ int sabc[3]; { outp((PIO+1), 0x0F); /* Set port A to output */ /* EBA data Functions of bits */ outp(PIO, M0); /* 1111 1111 T0 initial */ outp(PIO,(sabc[0])|M1); /* 1011 aaaa T1 setup nybble a */ outp(PIO,(sabc[0])|M2); /* 1010 aaaa T2 strobe nybble a */ outp(PIO,(sabc[0])|M3); /* 1011 aaaa T3 send nybble a */ outp(PIO,(sabc[2])|M3); /* 1011 cccc T4 setup nybble c */ outp(PIO,(sabc[2])|M5); /* 1001 cccc T5 send nybble c */ outp(PIO,(sabc[1])|M5); /* 1001 bbbb T6 setup nybble b */ outp(PIO,(sabc[1])|M3); /* 1011 bbbb T7 send nybble b */ outp(PIO, M0); /* 1111 1111 T8 final state */ printf(". "); } =============================================================================== CR-C ---- /* PROGRAM TO READ THE NYBBLES BEING SENT TO THE D931 AND WRITE THEM TO A FILE IN ASCII FORMAT */ #include bdscio.h #define END '@' #define MAXL 500 #define PIO 0x08 /* Address of Z80 PIO output port */ #define STRMASK 0x30 /* 0011 0000 Mask for strobe bits */ #define DMASK 0x3F /* 0011 1111 Mask for data &strobes */ main() { char ibuf[BUFSIZ]; /* Disk file buffer */ int *filename; /* Pointer for filename */ int ds[MAXL]; /* Array to put the data stream in */ int p; /* Pointer to ds[] */ int l; /* Final length of data stream */ printf("Reader for the Casio uPd-931 sound LSI\n"); printf("Enter filename when message is completed"); /* This drives an eight bit port which */ /* talks to the uPd931 via a Tristate */ /* buffer :- */ /* Bits 0, 1, 2 and 3 are data */ /* Bit 4 is Strobe A */ /* Bit 5 is Strobe B */ /* Bit 6 is Drive enable active low */ /* This leaves the port as input, */ /* looks at the strobes and records */ /* the activity in a long array */ outp((PIO+1),0x4F); /* Set port A to input */ p=0; /* Pointer to zero */ for(p=0; p > > > B1 4 1 > | | > 2 > > | | 3 > | | | Mystery 4 B1 4 D1 0 D4 1 F1 1 20 8 =============================================================================== PULSE ----- Single Pulse Waveform E7 0 E6 0 E5 0 E4 0 E3 0 E2 0 E1 0 E0 0 20 0 90 0 B0 1 ** WAVE A ** -FEDCBA9876543210123456789ABCDEF+ 60 0 A7 ...............0............... 60 1 A7 ...............0............... 60 2 A7 ...............0............... 60 3 A7 ...............0............... 60 4 A7 ...............0............... 60 5 A7 ...............0............... 60 6 A7 ...............0............... 60 7 A7 ...............0............... 60 8 A7 ...............0............... 60 9 A7 ...............0............... 60 A A7 ...............0............... 60 B A7 ...............0............... 60 C A7 ...............0............... 60 D A7 ...............0............... 60 E A7 ...............0............... 60 F A7 ...............0............... -FDECBA9876543210123456789ABCDEF+ B0 0 ** WAVE B ** -FEDCBA9876543210123456789ABCDEF+ 60 0 A7 ...............7............... 60 1 A7 .......................F........ 60 2 A7 ...............0............... 60 3 A7 ...............0............... 60 4 A7 ...............0............... 60 5 A7 ...............0............... 60 6 A7 ...............0............... 60 7 A7 ...............0............... 60 8 A7 ...............0............... 60 9 A7 ...............0............... 60 A A7 ...............0............... 60 B A7 ...............0............... 60 C A7 ...............0............... 60 D A7 ...............0............... 60 E A7 ...............0............... 60 F A7 ...............0................ -FDECBA9876543210123456789ABCDEF+ F4 4 B1 0 Time 3 B1 0 B1 0 B1 1 Time 2 B1 0 B1 0 B1 0 Time 1 B1 0 B1 0 B1 0 Time 4 B1 0 B1 0 Recycle at end of Time 3 B1 0 ENVELOPE MODE SELECT B1 1 B1 0 B1 1 T4 DOES NOT EXIST B1 0 Envelope, reverb 0 1 0 1 B1 1 and vibrato speed 0 0 1 1 multiplied by : 1 2 4 4 B1 0 Mystery 1 B1 0 Turns alternate cycles upside down and back to front B1 0 Invert alternate cycles B1 0 Mode Bits Wave B 0 1 0 1 B1 1 0 0 1 1 B1 0 Mode Bits Wave A 0 > > > > B1 1 1 > | | > 2 > > | | 3 > | | | B1 0 Dummy bit. This last location is believed to select which wave can be loaded next. It has no effect on the sound.