Manual Labors: SPAM: SPAM Mark II Microcode

The microcode for SPAM mark II featured major modifications. Two (2) new macros, SYNCHH and SYNCHL were added, since we got sick of writing code to synchronize with various inputs. The BEEP macro was rewritten so that beeps would always end on a falling edge of CLK_FSM, so that timing for rewinds and silent message detection would work.

In addition, changes were made to the following blocks of code:

Initialization
We now need to set up the start and end addresses of the outgoing message, which is not of variable length, but still needs these values so it can be played, and so message one (1) will be able to find it's start location. This is done with the rather cute trick of incrementing the address it reaches zero (by waiting for a falling edge on ADR_DON while incrementing the counter. We then store the zero in the OGM's start location, and increment the counter until ADR_DON has a rising edge, meaning 16384 increments have elapsed. Then we store this in the end address for the OGM. This process will increment the counter at most 65535 times, and incrementing once every clock cycle at 64KHz, it will take at most one (1) second to complete initialization.
Event Loop
The event loop itself is unchanged. Handling a ring, however, is completely rewritten. When USR_RNG goes high, SPAM checks to see if three messages are already recorded, or if the sound ram is full. If not, SPAM plays an outgoing message. Then executes HUPCHK, which makes sure USR_RNG is still held down, and then polls BUS_BUZ until some sound occurs on the data bus. If no sound occurs before one pulse of the CLK_FSM (about 1/2 second), or if USR_RNG is release, no message is recorded. Otherwise, HUPCHK branches back to continue recording the message. Note that while HUPCHK is polling the bus, no memory is being wasted recording the silence.
Back in the "main" code, we set the address register to the end of the previous message. Then we set the start address for the current message, increment message count, and record the user's message.
Record
Record has now been broken up into RECOGM and RECORD. RECOGM is virtually the same as before, except that it gets its start address from the ewe ram. RECORD now gets its start address from the ewe ram, and then records until USR_RNG is released or ADR_DON goes low (signaling that we have wrapped around counting addresses, so SPAM is out of space). Then, the final address is stored in ewe ram.
Play Outgoing Message
This has only changed to load the start address (zero (0)) from the ewe ram.
Play
Play has two major changes. First, it loads the start address for a message from ewe ram, then sets up the ewe ram to output the end message. This makes ADR_EQU go high when the two addresses are equal, so that it can keep incrementing the address until the message is complete. The other change is the requirement that rewind only go back to the previous message if it occurs soon after the message begins playing. This is accomplished by having two play loops. The first will rewind to the previous message if USR_REW is high, and branch into the second loop if CLK_FSM goes high. The second loop simply restarts the current message if USR_REW goes high.

Next: SPAM Mark III