Add a three-voice sound chip for the PmodAMP2 on JA
Ports 90h-9Dh: three square-wave voices and a noise source, a mixer, 16 log volumes with attack/decay envelopes, summed and played through a sigma-delta output on JA[0]. CLS and reset hush it. Includes a testbench (scripts/sim-sound.sh), a BASIC example and manual section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b629cbec00
commit
2d1be15786
11 files changed
+428
-3
No files matched your search
@@ -629,6 +629,7 @@ kept free for it.
|
||||
| 112–120, 128–135 | sprites (section 7) | sprites (section 7) |
|
||||
| 136 | keys held down, for games (below) | — |
|
||||
| 137 | 1 if the key picked with `OUT 137` is held down, else 0 | pick a key by its scan code |
|
||||
| 144–157 | voice volumes now (152–154) | sound (below) |
|
||||
|
||||
```
|
||||
10 FOR I = 0 TO 255
|
||||
@@ -677,6 +678,45 @@ game should throw those away now and then with `IF INP(0) AND 1 THEN K =
|
||||
INP(1)` in a loop. Held keys only work with the board's own keyboard, not with
|
||||
characters sent from the PC.
|
||||
|
||||
### Sound
|
||||
|
||||
The board has no speaker of its own. Plug a Digilent **PmodAMP2** into the
|
||||
top row of Pmod header **JA** (pin 1 at the end marked 1) and headphones or a
|
||||
powered speaker into its jack. The FPGA has a little sound chip in the style
|
||||
of the 8-bit computers: three voices that play square-wave tones, a noise
|
||||
source they can use instead or as well, sixteen volumes and an envelope for
|
||||
each voice, so a note or a bang fades away by itself.
|
||||
|
||||
| Port | `OUT` |
|
||||
|---|---|
|
||||
| 144, 145 | voice 0 pitch: low byte, then high byte (0–15) |
|
||||
| 146, 147 | voice 1 pitch |
|
||||
| 148, 149 | voice 2 pitch |
|
||||
| 150 | noise pitch, 0–31 (higher is lower and rougher) |
|
||||
| 151 | mixer: add 1, 2, 4 for the tone of voice 0, 1, 2 and 8, 16, 32 for noise on voice 0, 1, 2 |
|
||||
| 152, 153, 154 | voice 0, 1, 2 volume, 0 (off) to 15, which starts its envelope; `INP` gives the volume it has got to |
|
||||
| 155, 156, 157 | voice 0, 1, 2 envelope: attack × 16 + decay, each 0–15 |
|
||||
|
||||
- **Pitch** = 125000 ÷ frequency: 284 is the A above middle C (440 Hz),
|
||||
477 middle C. Each voice goes from about 30 Hz up beyond hearing.
|
||||
- **Envelope:** with an attack, the volume climbs from 0 to the volume set,
|
||||
one step every attack × 4 ms; then, with a decay, it falls back to 0 one step
|
||||
every decay × 4 ms. 0 means no climb, or hold the volume until it is
|
||||
changed. An envelope of 3 plays a short note; 8 with noise is an explosion.
|
||||
- **Waiting for a sound to end:** `IF INP(152) > 0 THEN …` loops until voice
|
||||
0 has faded out.
|
||||
- A voice that has neither its tone nor noise on in the mixer gives a steady
|
||||
level, so changing its volume clicks; that is how the old chips played
|
||||
samples.
|
||||
- `CLS` silences everything (as does restarting the Z-80).
|
||||
|
||||
```
|
||||
10 OUT 151, 1: OUT 155, 3 : REM TONE ON VOICE 0, A SHORT NOTE
|
||||
20 OUT 144, 28: OUT 145, 1: OUT 152, 15 : REM PITCH 284 = 440 HZ
|
||||
```
|
||||
|
||||
`basic/examples/sound.bas` plays a scale, a laser, an explosion and a chord.
|
||||
|
||||
### Speed
|
||||
|
||||
The Z-80 runs at 90 MHz and needs about 2.7 clocks per instruction, roughly 50
|
||||
|
||||
Reference in new issue
Block a user