Skip to content

Commit 8d4e1ab

Browse files
committed
Add option to disable sound
It offers a easy workaround when audio initialization fails.
1 parent f5e9c60 commit 8d4e1ab

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/core.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ bool init_vm(gb_vm *vm,
1414
const char *filename,
1515
int opt_level,
1616
int scale,
17-
bool init_io)
17+
bool init_render,
18+
bool init_sound)
1819
{
1920
if (!gb_memory_init(&vm->memory, filename))
2021
return false;
@@ -92,7 +93,7 @@ bool init_vm(gb_vm *vm,
9293
if (!read_battery(vm->memory.savname, &vm->memory))
9394
LOG_ERROR("Fail to read battery\n");
9495

95-
if (init_io) {
96+
if (init_render) {
9697
/* both audio and lcd will be initialized if init_io is true*/
9798
if (!init_window(&vm->lcd, scale))
9899
return false;
@@ -104,7 +105,8 @@ bool init_vm(gb_vm *vm,
104105
vm->frame_cnt = 0;
105106

106107
vm->opt_level = opt_level;
107-
108+
}
109+
if (init_sound) {
108110
audio_init(&vm->audio, &vm->memory);
109111
}
110112

src/core.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ bool init_vm(gb_vm *vm,
3535
const char *filename,
3636
int opt_level,
3737
int scale,
38-
bool init_io);
38+
bool init_render,
39+
bool init_sound);
3940
bool run_vm(gb_vm *vm, bool turbo);
4041
bool free_vm(gb_vm *vm);
4142

src/main.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ static void usage(const char *exe)
1313
"Options:\n"
1414
" -O, --opt-level=LEVEL Set the optimization level (default: 0)\n"
1515
" -s, --scale=SCALE Set the scale of the window (default: 3)\n"
16-
" -t, --turbo Run in turbo mode\n",
16+
" -t, --turbo Run in turbo mode\n"
17+
" --no-sound Disable audio initialization\n",
1718
exe);
1819
}
1920

@@ -52,12 +53,14 @@ int main(int argc, char *argv[])
5253
int opt_level = 0;
5354
int scale = 3;
5455
int turbo = false;
56+
int init_sound = true;
5557

5658
int c;
5759
const struct option long_options[] = {
5860
{"opt-level", required_argument, NULL, 'O'},
5961
{"scale", required_argument, NULL, 's'},
6062
{"turbo", no_argument, NULL, 't'},
63+
{"no-sound", no_argument, NULL, 'a'},
6164
{NULL, 0, NULL, 0} // Terminating element
6265
};
6366

@@ -72,6 +75,9 @@ int main(int argc, char *argv[])
7275
case 't':
7376
turbo = true;
7477
break;
78+
case 'a':
79+
init_sound = false;
80+
break;
7581
case '?':
7682
default:
7783
usage(argv[0]);
@@ -91,7 +97,7 @@ int main(int argc, char *argv[])
9197

9298
/* initialize memory */
9399
gb_vm *vm = malloc(sizeof(gb_vm));
94-
if (!init_vm(vm, argv[optind], opt_level, scale, true)) {
100+
if (!init_vm(vm, argv[optind], opt_level, scale, true, init_sound)) {
95101
LOG_ERROR("Fail to initialize\n");
96102
exit(1);
97103
}

tests/instr_test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void gbz80_init(size_t tester_instruction_mem_size,
3737
instruction_mem = tester_instruction_mem;
3838

3939
vm = malloc(sizeof(gb_vm));
40-
if (!init_vm(vm, NULL, 0, 0, false)) {
40+
if (!init_vm(vm, NULL, 0, 0, false, false)) {
4141
LOG_ERROR("Fail to initialize\n");
4242
exit(1);
4343
}

0 commit comments

Comments
 (0)