CoCo Chiptunes Player

The CoCo Chiptunes player is a little application I wrote to help with development of the Mega-mini MPI with it’s built-in YMF-262 (OPL3) FM synthesis chip.  It also supports the CoCo PSG (Yamaha YM2149), and will be updated to support other CoCo sound chip devices as they are made available, such as Jim Brain’s CoCo SDC Expander.

The program uses a menu system similar to the CoCo SDC Media Player’s to browse and select files on the SD card for playback.

IMG_20190213_182655

CoCo Chiptunes Player

Both OPL2, OPL3, and YM files that have been converted to .CCT (CoCo Chiptune) format can be played back.  Initially, the system required a CoCo PSG to be in the multipak, as it utilized the 512K RAM chip there for storage when playing chip data.  With version .3, the player now utilizes a ring buffer in upper RAM, and no longer requires extended memory beyond 64K.

Requirements for use currently are; a 64K CoCo 1/2/3, a Mega-mini MPI, or any other MPI and a CoCo PSG.  A 6309 CPU, and a CoCo SDC is also required.

Attached at the end of this page, you’ll find a link to a .DSK image with the player.  To run the program, simply mount the image in drive 0 using your SDC, and type ‘DOS’, then press enter.  From there browse to a .CCT meant for your particular sound device and hit enter to play it.  The ‘BREAK’ key will exit playback and return you to the browser menu.

At the link you’ll also find a zip containing .CCT files to play.  Unzip the file and copy the .CCT’s over to your SD card containing the player .DSK image.  It’s a work in progress so there may be a glitch or two, but I hope you enjoy it anyway.  🙂

I haven’t had an opportunity to test every file included, and not all of them are great, but there’s definitely some gems in there.  Give it a try and let me know what you think!

Download the Player!

 

 

 

CoCo OPL Composer

Now that a number of MEGA-mini MPI’s have made their way out into the world, it’s time to start in with some software to support some of it’s extended features, and to help with further development.  One of these features is the YMF-262 (OPL3) chip included in the MEGA-mini.

Though VGM style music is pretty easy to prepare and play back using a few cross-platform tools and a player that I wrote for the CoCo, I wanted to try something a little different.  Something that would let you use the CoCo itself to compose music for the chip.

Thinking about how I might want to go about this, I decided on some features.

It…

  • would run on a single-speed (.89MHz) CoCo1/2
  • would use the CoCoVGA’s 64 column text mode
  • would generate sound data designed to play from interrupt
  • would keep the resulting data as compact as possible (without using compression)
  • would use a ‘tracker-like’ interface

One of the first things I determined was the general form the data would take.  Using a tracker like format, the song pattern is 14 channels (columns) wide and uses one line per interrupt period to display the events for each channel.

I determined that at a minimum, we would need to define the following events (in the data) in order to operate the YMF-262…

  • a ‘start interrupt period’ indicator per line (IRQ period)
  • a ‘key-on’ event – the command to start playing a note
  • a ‘key-off’ event – the command to stop playing a previously issued ‘key-on’
  • an ‘end-of-song’ indicator

Deciding to structure these events as a series of commands, I came up with the following command (event) format.  Commands can be of variable byte size, and are arranged in channel order (0-13) after an IRQ indicator.  The upper nibble of a command byte indicates the command.  The lower nibble indicates the channel the command is for.  If the command requires additional data, it will immediately follow the command byte.

$Fx – start of IRQ period.

Data between this marker and the next ‘$Fx’ byte is the event data for this period, appearing in order of the channels (0-13).  Data is only present for a channel if there is an event for the period

$Ex – ‘key-on’ event.   This is a two-byte command

The lower nibble is the channel number, a note/octave byte follows this with the note encoded in the upper nibble (A-G = 1-7) and the octave number (0-7) in the lower nibble.

$Dx – ‘key-off’ event.  One byte

The lower nibble is the channel (0-13).

$Cx – ‘song-end’

Indicates the end of song data.

These are the possible events I’m implementing to start with in building the composer.  This scheme leaves room for eleven other commands to be defined at some later time if needed, but for now, this gives us something to work with.

The byte-stream used in the composer during editing is stored in the same arrangement as the final generated data will be in order to use the available system memory as efficiently as possible.

With the basic data format settled on, we move on to the user interface.  Laying down the basic structure of the pattern editor screen.

IMG_20190129_222133

The editor screen

The layout of the editor screen is shown above.  You can see the pattern laid out by line number (IRQ period) and sound channel.  Fourteen of the available eighteen 2-operator channels on the YMF-262 are used due to screen width.  Fourteen is quite a few instruments to work with though.  The remaining four can be used for additional in program sound effects depending on the software (game or whatnot) using the generated song.

The following video shows some of the initial progress.  Pattern editor window display, navigation, and IRQ based parsing and playback of the data have been implemented.  Next I’ll be working on the user interface for entering events in the editor.

Off to a good start

Since the last update I’ve been working on implementing some of the interface features for placing and removing events.  I have a method of placing notes by octave and note in the pattern, and was even able to grab a piece of sheet music off of the internet and enter a recognizable tune into the first channel in just a few minutes.

Entering events

I’ll be working on ways to make entering events quicker and easier as I work on other features of the program, such as loading and saving sequences to the CoCo SDC.  My plan right now is to save the data out into files on the FAT volume that’ll be easy to take into a modern machine to use in cross-development environments for putting together CoCo software.

But before I implement loading/saving, I think it’s time to nail down how timing will be used in the composer.  In particular, I’d like to make it easier to transcribe sheet music into the pattern.  This should also make it easier for actual musicians who are accustomed to reading and writing music to work with.  After some study of how timing information is encoded into sheet music, I think I’ve settled on how to handle timing.

My understanding is now that 4/4 timing is the most common employed, and so we’ll go with that as we move along.  The 4/4 time signature indicates 4 quarter notes per measure.  Song tempo is measured in beats per minute (BPM) and relates to our notes in that it gives us our note (and rest) durations, which are measured in beats.

FQD9028HUK2B70D.LARGE

From this, we’re able to calculate the time in seconds of a note, for instance, a quarter note in a 120 bpm song would have a duration of 1/2 of a second (120/60 = 2 beats per second).

Different pieces of music use all sorts of different tempos (bpm), so our composition software must take that into account.  In order for the timing of our pattern based system to closely follow the usual system for music, we’ll use beats for our timing as well.

Notes can go down to very short durations, as little as a 256th note, or 1/64th of a beat.  This is probably a little impractical for what we’re trying to do here, as we are also trying to minimize (or at least be reasonable with) storage and playback requirements of music on the CoCo.

Take for example a song at 120 bpm.  A whole note would be 2 seconds, a 256th note .0078125 seconds (128th of a second).  I think a more reasonable downward limit on note duration for our purposes is a 32nd note (1/8 of a beat), which will also be more in line with human hearing perception at beat rates we’ll likely be using.

So, going from that reasoning, our shortest duration, measured in beats, will be 1/8 of a beat.  Since our composer operates on interrupt periods, this means 8 IRQs per beat will be the basis of our timing, from which we’ll calculate the timer setting for our IRQs.

In other words, from the user perspective, you’ll set your beats per minute, and then just remember that each line is 1/8 of a beat.  The bpm will be adjustable to make it easy to transcribe and write music.

*** more to come ***

 

 

 

 

 

 

Programming the OPL3 chip with the Color Computer

This article is intended to give a basic overview of using the Yamaha YMF-262 (OPL3) chip on the Color Computer, to help aid in the understanding of its use on the MEGA mini MPI and the upcoming CoCo SDC sound extender.

The YMF-262 (OPL3) is an FM synthesis sound chip that offers a huge amount of flexibility in generating musical notes and sound effects. It’s backwards compatible with OPL2 sound chips, and starts up in this mode by default.

There are a few good references for programming the chip, including the application manual (data sheet), and the document linked here.

Programming the chip can be a little intimidating at first as there are a lot of options to work with. The OPL3 is extremely flexible in how it generates sound, which leads to a lot of complexity (potentially), but it can be operated in a fairly simple manner as well.  How it’s used is up to the programmer and how much CPU time he wants to devote to manipulating chip settings / channels to get the desired effects.

For the purposes of simplifying things here as we begin, our examples will stick to two-operator melodic tones.

Eighteen operator pairs are available on the OPL3. The simplest way to think about an operator pair is probably as an instrument. So essentially there are 18 ‘instruments’ that you can define.

For each instrument, there are two operators; a carrier wave, and a modulator. The carrier is the basic sound wave for the instrument, which is then modulated in either AM or FM mode to produce a more complex sound.

All the settings for an instrument pair need to be written to specific registers in the chip. Let’s take a look at registers for the first operator pair (or channel).

These registers define the carrier and modulator for the sound.

MODULATOR        CARRIER        PURPOSE
$20                            $23                  VIBRATO,SUSTAIN,SCALING,MULTI
$40                            $43                  KEY SCALE LEVEL, OUTPUT LEVEL
$60                            $63                  ATTACK / DECAY
$80                            $83                  SUSTAIN LEVEL / RELEASE RATE
$E0                            $E3                  WAVEFORM

In addition to the operators, there are three registers that control the overall channel (instrument). Again for the first channel.

$A0 – F-NUM, OR FREQUENCY (LOWER 8 BITS)
$B0 – KEY ON/OFF, BLOCK NUMBER (OCTAVE), UPPER TWO BITS OF F-NUM
$C0 – OUTPUT CHANNEL, FEEDBACK, SYNTHESIS TYPE

These 13 registers are all that’s needed to define a sound and play it. In its simplest usage, the 10 registers for the operator pair would be set up, and then afterward the sound controlled using only two registers ($A0 and $B0) to change note frequency and key-on / key-off.

Some assembly code
Let’s go through some 6809 assembly code that sets up an instrument and plays through the natural notes in an octave as an example. Leaving out the equates, here is the code that sets up the MEGA mini YMF-262 and plays the scale.

This portion does a little basic setup for the CoCo system and switches the sound source to the cartridge port sound-in line.

code1

Now we set up the MEGA mini’s analog switch to use the YMF-262 for sound, and select it for /SCS routing so that we can program the chip.

code2.jpg

Here, we set up the instrument by writing the registers for the operator pair. You can see the register numbers and their data below the routine for writing them. You’ll notice the NOP instruction between selecting the register to be written and sending the data. This is because the YMF-262 requires 32 of its clock cycles to process the register selection (at 14.318MHz). This works out to a 2,233.6ns, which is just slightly less than 2 cycles for the 6809 at .89MHz (2,235ns). You’d want a 4 cycle delay at 1.79MHz.

code3

Now our instrument is set up, except for the frequency data (F-NUM and octave).

Let’s play the octave. At the bottom of the following code, you can see the frequency data for each note based on the A440 pitch standard. This is a 10 digit binary number (0-1023) and the base frequency for each note. This, along with the octave data (block number) in register $B0, determines the frequency of the note.

Three register writes are required per note if the frequency changes. Frequency data, key-on, and key off. A note could be played with only two without changing the lower byte of frequency data.

Notes here are played in succession through the octave and then repeated endlessly.

code4

And that’s really all there is to it for regular melodic notes. Your program of course has to supply the timing for key-on/key-off events, and handle frequency changes, but the OPL can do the rest for simple music. You can also go nuts with the CPU and manipulate the various registers during play for different effects, but you don’t have to.

It’s a very flexible system.

I hope that gives enough insight to get some of us started on writing for the OPL3 on the CoCo. As you can (hopefully) see, it’s really not as difficult to program as it might seem at first. The OPL is *very* geared towards synthesizer type music, and it really shows in its design and operation.

Coming up with instrument definitions
Many instruments and sound effects have been designed for the OPL3, from general midi to all sorts of sounds used in games from back in the 90’s. You can use instrument data from these sources as well as use bank editors such as this OPL3 Bank Editor to experiment and come up with your own instruments.

 

 

CoCo2 Composite A/V modulator replacements

Not long after I did my first CoCo project (a composite A/V board) I happened to buy a CoCo2 that had an interesting difference from the usual models.  It had factory composite and sound output in place of the RF modulator! What a surprise!

20141120_190514Tandy factory original composite/sound board

After a little research, I discovered this was a variant that had been intended for educational sales, where a composite monitor was prefered to TV sets as a display.  I was very interested in this as I had just been working on something similar, but this was clearly a different circuit that Tandy used.  It’s also interesting to note that this ‘educational’ model uses the T1 variant (XC80652P) of the MC6847 VDG.

I decided to reverse-engineered the circuit and design some modulator replacements of my own based on this design.  Here is an early prototype of that effort.

20141213_225143
Modulator replacements, first prototype

The board is a direct replacement for the RF modulator, requires no modifications to the case, and uses the channel switch to select between B&W / COLOR.

Output appears to be very good. I would say considerably better than the simple reference circuit in the MC6847 data sheet, which was all I’d been able to find previously.

Further working with this circuit, I decided to develop versions for both major modulator types, the ‘vertical’ modulator found in early American produced CoCo2s, and the ‘flat’ type found in Korean models.  Here are some pictures taken during development.

After getting the design more or less finalized, I produced a number of these and sold them to people wanting something a bit better than RF output on their CoCo2s.  Well over 100 boards were distributed.

Type A’s (Korean), in production

Final versions

Identifying modulator types

This portion is to help identify which composite video board style you will need to replace the RF modulator in different CoCo 2 computers.

Type A
I’ll call the first one the “Type A” modulator.  This is found on later, Korean made CoCo 2’s.  It lays flat against the motherboard next to the channel switch.  If your modulator looks like this, you need a Type A Composite board.

Type A, Korean motherboards, ‘flat’

Type B
I’ll call the second the “Type B” modulator. This is found on earlier, US made CoCo 2’s.
It attaches to the motherboard by one of it’s edges, and has the channel switch in the RF box. If your modulator looks like this, you need a Type B Composite board.

Type B, American motherboards, ‘vertical’

Installing the board, Type A

Here you will find some basic instructions for installing the Type A composite video board.  This is how I do it, of course it’s not the only way, and all the usual disclaimers apply.

Removing the RF modulator

The first step after removing the motherboard from the computer, and removing any shielding on the bottom, is to remove the RF modulator box.

You will need a temperature controlled soldering iron for this, as it takes quite a bit of heat.  Somewhere around 350º C is appropriate, otherwise the large ground plane under the modulator sinks too much heat to get the solder for the box ground connections liquid in a timely manner, or heat the signal pins enough to melt the solder at the top of the pin where they are connected to the modulator pcb.

First the modulator pins carrying the various signals should be removed.
Special care needs to be taken not to damage the pads these pins are soldered to.  I’ve found the safest way is to heat the pin from the motherboard bottom while applying moderate pressure to the end of the pin.

When it gets hot enough, you’ll be able to push it up into the modulator box. At this point there is enough of the pin protruding on the top side so that it can be grasped with a pair of need-nosed pliers or the like, and pulled (with moderate force again) while it’s heated again from the bottom until free. Repeat for the other 7 pins.

Heat the large solder connections where the RF box is connected to the ground plane, using a solder sucking device of some sort to remove the bulk of the solder.  Use soldering wick to get what that won’t until the sheet metal tabs of the box are free.  A couple of them will need to be straightened to fit through the slots in the board where they were originally bent to hold them in place prior to soldering.

The modulator should now be easily lifted/gently pried free.

Whew…  The hard part is done!

Preparing the motherboard for installation

Use solder wick to clean up the pads for the pins, and also the rearmost slot in the ground plane where the modulator box was soldered.  This is where the ground lug on the new board will attach. You’ll want to be sure that slot is completely open (free of solder).

Next, insert the board (pins and ground lug), make sure it’s fully seated and level.  Solder one of the pins to hold it in place until you are sure you’ve got it positioned as you want it (down all the way and parallel to the motherboard).

Solder the rest of the pins, and then the ground lug.  The ground lug is soldered to the board, so you’ll want to apply enough heat long enough to solder it to the motherboard, but not so long that it melts the connection on the Composite board; not really an issue as it can’t move around at that point anyway, just something to be aware of.

All that’s left now is the power leads.  The WHITE wire connected to P2 is the AC power to the board, and will be attached to the anode of one of the large power diodes on the motherboard.  This should be ~ 8.4 VAC,  you can use a voltmeter to verify.  The RED wire connected to P1 supplies DC voltage to the board, and will be attached to the cathode of one of the large power diodes.   It should read ~ +9.9 VDC.

Type A installed.jpg

Type A, installed

Once the power leads are attached, you just need to trim the pins sticking out of the bottom of the motherboard (the ground lug is pre-cut and should not need trimming).

I will have already set the potentiometers while connected to a TV and an oscilloscope for testing, before sending the board. They can be adjusted if needed on your particular setup, but try it first. 🙂

And that’s it! Put it all back together and enjoy Composite video on your CoCo2.

Notes for installing the Type B composite board

Installing the Type B composite boards is essentially the same, except for replacing one resistor on the motherboard.  Remove the 10K resistor at R13 (shown in the pic below), and replace with a 1K resistor.  This should improve your artifact colors.  If you installed the board some time ago, before I added this note, you may want to consider swapping the resistor.  Especially if artifact colors are not quite as expected.

IMG_20200913_191015

Location of R13, next to the MC6847 VDG

Also, watch the power connections carefully. The diodes are reversed in their orientation on the motherboard.

Type B Power Connections.png

Power connections, Type B

CoCo MECH mechanical keyboard

 

One thing the CoCo community has needed for some time is a viable way to repair or replace the keyboards in our aging machines.

The original CoCo keyboard is a membrane type internally, with the circuit printed on mylar.  Many of these mylars are wearing out today, and the conductor tends to develop cracks in the section connecting to the motherboard.

In the recent past, there has been talk of having a run of replacement mylars made, with a couple of individuals going as far as to get quotes.  Though an option, prices seem to be expensive enough that to date this has not happened.

Cloud9 has developed a solution that involves a very thin PCB with tactile switches being used to replace the mylar in original keyboard casings which looks like a good option.

Having wanted to make a keyboard replacement myself for quite some time, I decided to throw my hat into the ring with my own design.  I had a couple of criteria for the final keyboard.

  1. It had to use standard modern key switches of the current de facto standard
  2.  It had to be a drop-in replacement

Later models of the CoCo1, as well as CoCo 2 models and the CoCo3, can all accommodate the same design.  These are models I’ve targeted.

One of the major obstacles to a new keyboard for the CoCo is that like most early computers, the legends on the keycaps are not laid out as they are in what has become the standard layout over the years.  This means that new keycaps that will fit modern key switches cannot be purchased with pre-labeled keys.  Blank keycap sets are available, but then there is the issue of labeling them in a professional fashion.

Of course there are companies that will produce custom keycap sets for you, but prices and minimum quantities are high, and any change in design would be very expensive.

One of the ways manufacturers label keys is using lasers.  After investigating this a bit, I decided that would be a good way for me to go.  Owning the laser system myself would allow me a great deal of flexibility as well, enabling me to put nearly anything on nearly any keycap at a whim.

So I purchased a 20w fiber laser system for the purpose (and for other things).

IMG_20180817_114940 copy
20w fiber laser system

The system is quite flexible, and does the keycaps with ease.

Untitled

Laser marked keys, an early test

Keycap marking with the laser

With a solution for the keys decided on, I moved on to the rest of the design.  To avoid needing special molded or printed parts for a keyboard housing while still providing enough rigidity, I decided on a design that would sandwich aluminum bars between the switch PCB and a top plate (bezel) around the keys.

Board BottomBoard Top Initial PCB design

Another issue with a CoCo drop in keyboard is how to go about the connection to the motherboard.  This I accomplished with a thin (.6mm) PCB for the main board connector and a ribbon cable.  Receiving the PCBs back for the fabricator for all this, I proceeded to assemble a prototype.

PCBs for prototype keyboard

IMG_20180907_201655.jpg

Switches installed

  The keyboard is modeled after the original CoCo3 keyboard, shown with the prototype in the picture below.

IMG_20180907_210831

Prototype with original CoCo3 keyboard

First test, CoCo MECH keyboard

Next I installed the aluminum frame, drilling and tapping the rails to fit the PCBs.  I assembled this prototype in a hurry with hand tools.  Things will be more precise in actual production, but still, this went well.

Prototype with frame installed

 

IMG_20180909_114545.jpg

Prototype installed in a CoCo3

IMG_20180913_214049.jpg

Installed in an ‘F’ board CoCo 1

I made some changes and produced a 2nd revision of the board which I’ll order to continue development with.  This project has gone extremely well so far and I don’t see any issues in further refining it into a great drop in keyboard option for our CoCos!

REV02

REV02 design, main PCB

After receiving back REV02 PCBs, I built a prototype using that board.  And experimented with different colored keys in the set, similar to how the original Color Computer 3 keyboard looked.

IMG_20181003_203244

CoCo3 style key colors – REV02

 

IMG_20181004_194454

Keyboard to main board connection

 

IMG_20181004_130143

With the keys marked

Moving along towards actually producing these, I started looking for something a bit easier to manufacture for the various parts of  of the keyboard (outside the PCB and keyswitches themselves) and have decided to use 3d printing to produce plastic parts to fill this role (printed in PETG).

To be able to do this I acquired a large format printer, a Creality CR-10 S5, which has a 500x500mm print bed, giving me the width to do keyboard parts.

IMG_20190511_121328

Creality CR-10 S5, printing keyboard parts

Screen Shot 2019-06-07 at 9.58.52 AMIMG_20190512_172310

Keyboard parts set

After designing the plastic parts for the keyboard, including a support for CoCo2 machines, I printed out a set and assembled a unit.  This results in a very nice keyboard which is very stable and pleasant to use once installed and the CoCo case is buttoned up.

Keyboard installed in an American CoCo2

I’ll probably also be adding (as an option at least) a vinyl layer on the keyboard top plate for those that don’t want to see the pattern left in the plastic by 3d printing.

Vinyl sheet added to top plate

After working with the support system for a while, it became apparent that different supports would be needed for pretty much every case style.  Below is a video showing installation in a CoCo3 with the supports I devised for that machine.

Installing in a CoCo3

 

 

 

…more to come…