Four channels on ports 0x40 to 0x4F, each one a whole soundThing voice:
two oscillators, two envelopes, a filter and the routing between them. A
channel keeps its patch between notes, so a program sets an instrument up
once and then plays it.
Six ports rather than forty, because a voice has around forty settings and
four of them would spend more than half the port space on one device.
There is a selector and a value instead: say which channel, say which
setting, write it. That is three writes to change a setting and two to
play a note, which is the right way round - patches are loaded, notes are
played in an inner loop.
Samples come from the machine's clock and not the host's: 48,000 a second
of emulated time, worked out in whole numbers so it never drifts. A
million cycles is exactly 48,000 samples on any host at any speed, which
is what makes a sound something a test can compare. --sound writes them
out, the way --screen writes a picture, for the same reason: the suite has
no speaker.
Tests/sound.sh is 22 checks and found three real defects the first time it
ran, all the same shape - a synthesizer written for a patch editor, wired
up as hardware and inheriting the editor's assumptions:
- Only one voice had an oscillator switched on, so three of the four
channels could not make a sound whatever was written to them.
- That voice's oscillator arrived at full gain and every other one
arrived at nothing, an asymmetry with no reason behind it.
- A note with no sustain is silent but not over, so the obvious way to
wait for a sound to finish waits for ever.
The first two are fixed by the device defining its own power-on state
rather than inheriting synthInit's: every channel arrives able to make a
sound, so writing a note number is the whole of playing a note. The third
was already written into the manual as advice, an hour before the check
existed. The check disagreed with the documentation and the check was
right; the manual now says the one rule, which is that a note sounds until
the gate is dropped.
Programs/Examples/tune.asm plays eight notes, taking its tempo from the
screen's frame interrupt because that is the only regular beat this
machine has. It spends 99.8% of its cycles asleep in WAIT.
Voyager has no speaker yet - this is the device and its tests. Playing the
samples out of the window is the next commit.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
41 lines
1.6 KiB
C
41 lines
1.6 KiB
C
// utility.h
|
|
// Utilities for the SplitBit CPU Emulator
|
|
// Written by Anachronaut
|
|
// 10/15/2024
|
|
|
|
|
|
#ifndef UTILITY_H
|
|
#define UTILITY_H
|
|
|
|
#include <stdint.h>
|
|
#include "cpu.h"
|
|
|
|
// Results of reading the command line.
|
|
#define OPTIONS_OK 0 // Carry on and run the program.
|
|
#define OPTIONS_HELP 1 // The user asked for help, so stop, but not because of an error.
|
|
#define OPTIONS_ERROR 2 // The command line was no good, stop and complain.
|
|
|
|
typedef struct {
|
|
uint8_t debug; // Step one instruction at a time, printing the registers.
|
|
uint8_t fast; // Ignore the cycle rate and run as fast as the host allows.
|
|
unsigned long cycles; // Stop after this many cycles. Zero means run until the program halts.
|
|
unsigned long diskCycles; // How long a block move takes. Zero is instant, and the default.
|
|
const char *disk; // Disk image to attach, or NULL for a machine with no disk.
|
|
uint8_t writeProtect; // Attach the disk read only, the way a tab on a floppy would.
|
|
const char *screen; // Where to save a picture of the screen when the machine stops.
|
|
const char *keyboard; // Feed the console from this file as a keyboard, not a terminal.
|
|
const char *sound; // Where to save the samples the machine made, as raw 16 bit.
|
|
} EmulatorOptions;
|
|
|
|
uint8_t parseOptions(int argc, char *argv[], EmulatorOptions *options);
|
|
|
|
void printHelp(const char *programName);
|
|
|
|
uint8_t loadFile(const char *path, uint8_t *Program, uint8_t *Data);
|
|
|
|
void bootStrap(uint8_t *Program, uint8_t *Data);
|
|
|
|
void printRegisters(CPURegisters *cpu, uint8_t *Program, uint8_t *Data);
|
|
|
|
#endif // UTILITY_H
|