Add an optional argument to the APU command

This commit is contained in:
Lior Halphon 2022-03-12 15:08:15 +02:00
parent ef15c9b160
commit b5e271386a

View File

@ -1744,12 +1744,15 @@ static bool lcd(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg
static bool apu(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugger_command_t *command) static bool apu(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugger_command_t *command)
{ {
NO_MODIFIERS NO_MODIFIERS
if (strlen(lstrip(arguments))) { const char *stripped = lstrip(arguments);
if (strlen(stripped)) {
if (stripped[0] != 0 && (stripped[0] < '1' || stripped[0] > '5')) {
print_usage(gb, command); print_usage(gb, command);
return true; return true;
} }
}
if (stripped[0] == 0 || stripped[0] == '5') {
GB_log(gb, "Current state: "); GB_log(gb, "Current state: ");
if (!gb->apu.global_enable) { if (!gb->apu.global_enable) {
GB_log(gb, "Disabled\n"); GB_log(gb, "Disabled\n");
@ -1789,9 +1792,12 @@ static bool apu(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg
GB_log(gb, " no channels"); GB_log(gb, " no channels");
} }
GB_log(gb, "%s\n", gb->io_registers[GB_IO_NR50] & 0x80 ? " VIN": ""); GB_log(gb, "%s\n", gb->io_registers[GB_IO_NR50] & 0x80 ? " VIN": "");
}
for (uint8_t channel = GB_SQUARE_1; channel <= GB_SQUARE_2; channel++) { for (uint8_t channel = GB_SQUARE_1; channel <= GB_SQUARE_2; channel++) {
if (stripped[0] != 0 && stripped[0] != ('1') + channel) continue;
GB_log(gb, "\nCH%u:\n", channel + 1); GB_log(gb, "\nCH%u:\n", channel + 1);
GB_log(gb, " Current volume: %u, current sample length: %u APU ticks (next in %u ticks)\n", GB_log(gb, " Current volume: %u, current sample length: %u APU ticks (next in %u ticks)\n",
gb->apu.square_channels[channel].current_volume, gb->apu.square_channels[channel].current_volume,
@ -1831,7 +1837,7 @@ static bool apu(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg
} }
} }
if (stripped[0] == 0 || stripped[0] == '3') {
GB_log(gb, "\nCH3:\n"); GB_log(gb, "\nCH3:\n");
GB_log(gb, " Wave:"); GB_log(gb, " Wave:");
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
@ -1853,8 +1859,10 @@ static bool apu(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg
GB_log(gb, " Channel will end in %u 256 Hz ticks\n", GB_log(gb, " Channel will end in %u 256 Hz ticks\n",
gb->apu.wave_channel.pulse_length); gb->apu.wave_channel.pulse_length);
} }
}
if (stripped[0] == 0 || stripped[0] == '4') {
GB_log(gb, "\nCH4:\n"); GB_log(gb, "\nCH4:\n");
GB_log(gb, " Current volume: %u, current internal counter: 0x%04x (next increase in %u ticks)\n", GB_log(gb, " Current volume: %u, current internal counter: 0x%04x (next increase in %u ticks)\n",
gb->apu.noise_channel.current_volume, gb->apu.noise_channel.current_volume,
@ -1876,6 +1884,7 @@ static bool apu(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugg
GB_log(gb, " Channel will end in %u 256 Hz ticks\n", GB_log(gb, " Channel will end in %u 256 Hz ticks\n",
gb->apu.noise_channel.pulse_length); gb->apu.noise_channel.pulse_length);
} }
}
GB_log(gb, "\n\nReminder: APU ticks are @ 2 MiHz\n"); GB_log(gb, "\n\nReminder: APU ticks are @ 2 MiHz\n");
@ -1978,7 +1987,7 @@ static const debugger_command_t commands[] = {
{"registers", 1, registers, "Print values of processor registers and other important registers"}, {"registers", 1, registers, "Print values of processor registers and other important registers"},
{"cartridge", 2, mbc, "Displays information about the MBC and cartridge"}, {"cartridge", 2, mbc, "Displays information about the MBC and cartridge"},
{"mbc", 3, }, /* Alias */ {"mbc", 3, }, /* Alias */
{"apu", 3, apu, "Displays information about the current state of the audio chip"}, {"apu", 3, apu, "Displays information about the current state of the audio processing unit", "[channel (1-4, 5 for NR5x)]"},
{"wave", 3, wave, "Prints a visual representation of the wave RAM." HELP_NEWLINE {"wave", 3, wave, "Prints a visual representation of the wave RAM." HELP_NEWLINE
"Modifiers can be used for a (f)ull print (the default)," HELP_NEWLINE "Modifiers can be used for a (f)ull print (the default)," HELP_NEWLINE
"a more (c)ompact one, or a one-(l)iner", "", "(f|c|l)", .modifiers_completer = wave_completer}, "a more (c)ompact one, or a one-(l)iner", "", "(f|c|l)", .modifiers_completer = wave_completer},