diff --git a/apple2e.cpp b/apple2e.cpp index bef9531..6f76517 100644 --- a/apple2e.cpp +++ b/apple2e.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include "fake6502.h" @@ -2604,31 +2603,6 @@ enum APPLE2Einterface::EventType process_events(MAINboard *board, bus_frontend& return APPLE2Einterface::NONE; } -ao_device *open_ao() -{ - ao_device *device; - ao_sample_format format; - int default_driver; - - ao_initialize(); - - default_driver = ao_default_driver_id(); - - memset(&format, 0, sizeof(format)); - format.bits = 8; - format.channels = 1; - format.rate = 44100; - format.byte_format = AO_FMT_LITTLE; - - /* -- Open driver -- */ - device = ao_open_live(default_driver, &format, NULL /* no options */); - if (device == NULL) { - fprintf(stderr, "Error opening libao audio device.\n"); - return nullptr; - } - return device; -} - int main(int argc, char **argv) { @@ -2637,8 +2611,6 @@ int main(int argc, char **argv) argv += 1; char *diskII_rom_name = NULL, *floppy1_name = NULL, *floppy2_name = NULL; - bool have_audio = true; - while((argc > 0) && (argv[0][0] == '-')) { if(strcmp(argv[0], "-debugger") == 0) { debugging = true; @@ -2654,10 +2626,6 @@ int main(int argc, char **argv) floppy2_name = argv[3]; argv += 4; argc -= 4; - } else if(strcmp(argv[0], "-noaudio") == 0) { - have_audio = false; - argv += 1; - argc -= 1; } else if(strcmp(argv[0], "-fast") == 0) { run_fast = true; argv += 1; @@ -2703,27 +2671,14 @@ int main(int argc, char **argv) system_clock clk; - ao_device *aodev = open_ao(); - if(aodev == NULL) - exit(EXIT_FAILURE); - MAINboard* mainboard; MAINboard::display_write_func display = [](int addr, bool aux, unsigned char data)->bool{return APPLE2Einterface::write(addr, aux, data);}; - MAINboard::audio_flush_func audio; + MAINboard::get_paddle_func paddle = [](int num)->tuple{return APPLE2Einterface::get_paddle(num);}; - if(have_audio) - audio = [aodev](char *buf, size_t sz){ - // static char prev_sample; - // for(int i = 0; i < sz; i++) - // if(buf[i] != prev_sample) { - if(!run_fast) ao_play(aodev, buf, sz); - // break; - // } - // prev_sample = buf[sz - 1]; - }; - else - audio = [](char *buf, size_t sz){}; + + MAINboard::audio_flush_func audio = [](char *buf, size_t sz){ if(!run_fast) APPLE2Einterface::enqueue_audio_samples(buf, sz); }; + mainboard = new MAINboard(clk, b, display, audio, paddle); bus.board = mainboard; bus.reset(); diff --git a/interface.cpp b/interface.cpp index 19bf65f..386da89 100644 --- a/interface.cpp +++ b/interface.cpp @@ -7,6 +7,7 @@ #include #include #include +#include // implicit centering in widget? Or special centering widget? // lines (for around toggle and momentary) @@ -27,6 +28,7 @@ namespace APPLE2Einterface chrono::time_point start_time; static GLFWwindow* my_window; +ao_device *aodev; DisplayMode display_mode = TEXT; int display_page = 0; // Apple //e page minus 1 (so 0,1 not 1,2) @@ -1742,8 +1744,42 @@ void drop_callback(GLFWwindow* window, int count, const char** paths) ui->drop(elapsed.count(), wx, wy, count, paths); } +void enqueue_audio_samples(char *buf, size_t sz) +{ + ao_play(aodev, buf, sz); +} + +ao_device *open_ao() +{ + ao_device *device; + ao_sample_format format; + int default_driver; + + ao_initialize(); + + default_driver = ao_default_driver_id(); + + memset(&format, 0, sizeof(format)); + format.bits = 8; + format.channels = 1; + format.rate = 44100; + format.byte_format = AO_FMT_LITTLE; + + /* -- Open driver -- */ + device = ao_open_live(default_driver, &format, NULL /* no options */); + if (device == NULL) { + fprintf(stderr, "Error opening libao audio device.\n"); + return nullptr; + } + return device; +} + void start(bool run_fast, bool add_floppies, bool floppy0_inserted, bool floppy1_inserted) { + aodev = open_ao(); + if(aodev == NULL) + exit(EXIT_FAILURE); + load_joystick_setup(); glfwSetErrorCallback(error_callback); diff --git a/interface.h b/interface.h index c4713b3..44ac0e3 100644 --- a/interface.h +++ b/interface.h @@ -54,4 +54,6 @@ std::tuple get_paddle(int num); void show_floppy_activity(int number, bool activity); +void enqueue_audio_samples(char *buf, size_t sz); + };