Harmonic Maximization Engine

2022-02-16

Part of my journey through Shenzhen I/O

Problem: There are two simple I/O slots for audio: audio-in and audio-out. There is a single XBus switch, maximize, which enables maximization when enabled. If not enabled, the signal is simply copied from audio-in to audio-out. When enabled, the audio value should be altered according to the provided formula.

Here's that formula, provided in the manual:

audio_out = 4 · (audio_in - 50) + 50

The chips available don't handle three simple I/O pins. Both the MC4000 and MC6000 only have 2 simple I/O pins and either 2 or 5 XBus pins. So in order to get the value of maximize into the mix, I added a dedicated MC4000 that simply copies the simple I/O value to XBus:

  mov p0 x1
  slp 1

Not great, but I can't think of anything better.

For the core logic, we now have an MC4000 with audio-in and audio-out coming in over simple I/O, and the maximize value coming in to x0 over XBus.

The first insight is that we can expand the formula to execute it in two computations instead of three:

audio_out = 4 · (audio_in - 50) + 50
audio_out = 4 · audio_in - 200 + 50
audio_out = 4 · audio_in - 150

This saves an instruction, leading to this code for the second MC4000:

  mov x0 acc
  teq 0 acc
  mov p0 acc
- mul 4
- sub 150
  mov acc p1
  slp 1

This ended up costing ¥6, using 490 power, and requiring 9 lines of code. All three dimensions have significant populations of answers lower than what I achieved (¥4, ~250P, 7LoC), so I might return to optimize.