/* Generates random sounds in the APU, printing the parameters to the screen. Also shows an asterisk while each channel is playing, i.e. while its length counter is active. */ #include #include #include #include "neslib.h" #include "apu.h" //#link "apu.c" #include "vrambuf.h" //#link "vrambuf.c" // link the pattern table into CHR ROM //#link "chr_generic.s" typedef struct APUParam { byte chmask; const char* name; word valmask; } APUParam; #define APU_DEFCOUNT 20 const APUParam APU_DEFS[APU_DEFCOUNT] = { {0x01, "Pulse1 Period", 0x7ff }, {0x01, "Pulse1 Duty", 0xc0 }, {0x01, "Pulse1 Decay", 0x0f }, {0x01, "Pulse1 Length", 0x0f }, {0x01, "Pulse1 Sweep Period", 0x07 }, {0x01, "Pulse1 Sweep Rate", 0x07 }, {0x01, "Pulse1 Sweep Up?", 0x01 }, {0x02, "Pulse2 Period", 0x7ff }, {0x02, "Pulse2 Duty", 0xc0 }, {0x02, "Pulse2 Decay", 0x0f }, {0x02, "Pulse2 Length", 0x0f }, {0x02, "Pulse2 Sweep Period", 0x07 }, {0x02, "Pulse2 Sweep Rate", 0x07 }, {0x02, "Pulse2 Sweep Up?", 0x01 }, {0x04, "Triangle Period", 0x7ff }, {0x04, "Triangle Length", 0x0f }, {0x08, "Noise Period", 0x0f }, {0x08, "Noise Decay", 0x0f }, {0x08, "Noise Length", 0x0f }, {0x08, "Noise Buzz", NOISE_PERIOD_BUZZ }, }; word enmask; word vals[APU_DEFCOUNT]; void random_sound() { byte i; do { enmask = rand() & 15; // all except DMC } while (enmask == 0); for (i=0; i