From d15342f46cb6e8144d3b78aff4ec59451b284404 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 18:07:35 -0500 Subject: [PATCH 01/14] Initial Support for OPL2Board Arduino --- src/include/86box/snd_opl.h | 6 +- src/include/86box/sound.h | 3 + src/sound/CMakeLists.txt | 11 +- src/sound/snd_opl.c | 7 + src/sound/snd_opl2board.c | 183 +++++++++++ src/sound/snd_opl_opl2board.cpp | 550 ++++++++++++++++++++++++++++++++ src/sound/sound.c | 1 + 7 files changed, 758 insertions(+), 3 deletions(-) create mode 100644 src/sound/snd_opl2board.c create mode 100644 src/sound/snd_opl_opl2board.cpp diff --git a/src/include/86box/snd_opl.h b/src/include/86box/snd_opl.h index 441e2a119..95eec2687 100644 --- a/src/include/86box/snd_opl.h +++ b/src/include/86box/snd_opl.h @@ -23,7 +23,8 @@ enum fm_type { FM_YMF289B = 2, /* OPL3-L */ FM_YMF278B = 3, /* OPL 4 */ FM_ESFM = 4, /* ESFM */ - FM_MAX = 5 + FM_MAX = 5, + FM_OPL2BOARD = 6 /* OPL2BOARD (External Device)*/ }; enum fm_driver { @@ -47,6 +48,7 @@ extern uint8_t fm_driver_get(int chip_id, fm_drv_t *drv); extern const fm_drv_t nuked_opl_drv; extern const fm_drv_t ymfm_drv; extern const fm_drv_t esfmu_opl_drv; +extern const fm_drv_t ymfm_opl2board_drv; #ifdef EMU_DEVICE_H extern const device_t ym3812_nuked_device; @@ -58,6 +60,8 @@ extern const device_t ymf289b_ymfm_device; extern const device_t ymf278b_ymfm_device; extern const device_t esfm_esfmu_device; + +extern const device_t ym_opl2board_device; #endif #endif /*SOUND_OPL_H*/ diff --git a/src/include/86box/sound.h b/src/include/86box/sound.h index 9895e73d7..428f12932 100644 --- a/src/include/86box/sound.h +++ b/src/include/86box/sound.h @@ -209,6 +209,9 @@ extern const device_t tndy_device; extern const device_t wss_device; extern const device_t ncr_business_audio_device; +/* External Audio device OPL2Board (Host Connected hardware)*/ +extern const device_t opl2board_device; + #endif #endif /*EMU_SOUND_H*/ diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index f67630c47..438b558a2 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -13,9 +13,9 @@ # Copyright 2020-2021 David Hrdlička. # -add_library(snd OBJECT sound.c snd_opl.c snd_opl_nuked.c snd_opl_ymfm.cpp snd_resid.cc +add_library(snd OBJECT sound.c snd_opl.c snd_opl_nuked.c snd_opl_ymfm.cpp snd_opl_opl2board.cpp snd_resid.cc midi.c snd_speaker.c snd_pssj.c snd_lpt_dac.c snd_ac97_codec.c snd_ac97_via.c - snd_lpt_dss.c snd_ps1.c snd_adlib.c snd_adlibgold.c snd_ad1848.c snd_audiopci.c + snd_lpt_dss.c snd_ps1.c snd_adlib.c snd_adlibgold.c snd_opl2board.c snd_ad1848.c snd_audiopci.c snd_azt2316a.c snd_cms.c snd_cmi8x38.c snd_cs423x.c snd_gus.c snd_sb.c snd_sb_dsp.c snd_emu8k.c snd_mpu401.c snd_pas16.c snd_sn76489.c snd_ssi2001.c snd_wss.c snd_ym7128.c snd_optimc.c esfmu/esfm.c esfmu/esfm_registers.c snd_opl_esfm.c) @@ -125,5 +125,12 @@ if(OPL4ML) target_sources(snd PRIVATE midi_opl4.c midi_opl4_yrw801.c) endif() + find_package(PkgConfig REQUIRED) + pkg_check_modules(SERIALPORT REQUIRED libserialport) + include_directories(${SERIALPORT_INCLUDE}) + target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) + + + add_subdirectory(resid-fp) target_link_libraries(86Box resid-fp) diff --git a/src/sound/snd_opl.c b/src/sound/snd_opl.c index d98b3ccc2..9f7e4c459 100644 --- a/src/sound/snd_opl.c +++ b/src/sound/snd_opl.c @@ -59,6 +59,13 @@ fm_driver_get(int chip_id, fm_drv_t *drv) } break; + case FM_OPL2BOARD: + + *drv = ymfm_opl2board_drv; + drv->priv = device_add_inst(&ym_opl2board_device, fm_dev_inst[fm_driver][chip_id]++); + + break; + case FM_YMF289B: *drv = ymfm_drv; drv->priv = device_add_inst(&ymf289b_ymfm_device, fm_dev_inst[fm_driver][chip_id]++); diff --git a/src/sound/snd_opl2board.c b/src/sound/snd_opl2board.c new file mode 100644 index 000000000..1ad147e8c --- /dev/null +++ b/src/sound/snd_opl2board.c @@ -0,0 +1,183 @@ +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H + +#include <86box/86box.h> +#include <86box/device.h> +#include <86box/io.h> +#include <86box/mca.h> +#include <86box/sound.h> +#include <86box/timer.h> +#include <86box/snd_opl.h> +#include <86box/plat_unused.h> + + +#ifdef ENABLE_OPL2DEVICE_LOG +int opl2board_device_do_log = ENABLE_OPL2DEVICE_LOG; + +static void +opl2board_device_log(const char *fmt, ...) +{ + va_list ap; + + if (opl2board_device_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define opl2board_device_log(fmt, ...) +#endif + +typedef struct opl2board_device_t { + fm_drv_t opl; + + uint8_t pos_regs[8]; + + +} opl2board_device_t; + + + + +static void +opl2board_device_get_buffer(int32_t *buffer, int len, void *priv) +{ + opl2board_device_t *serial = (opl2board_device_t *) priv; + + const int32_t *opl_buf = serial->opl.update(serial->opl.priv); + + for (int c = 0; c < len * 2; c++) + buffer[c] += opl_buf[c]; + + serial->opl.reset_buffer(serial->opl.priv); +} + +uint8_t +opl2board_device_mca_read(int port, void *priv) +{ + const opl2board_device_t *serial = (opl2board_device_t *) priv; + + opl2board_device_log("opl2board_device_mca_read: port=%04x\n", port); + + return serial->pos_regs[port & 7]; +} + +void +opl2board_device_mca_write(int port, uint8_t val, void *priv) +{ + opl2board_device_t *serial = (opl2board_device_t *) priv; + + if (port < 0x102) + return; + + opl2board_device_log("opl2board_device_mca_write: port=%04x val=%02x\n", port, val); + + switch (port) { + case 0x102: + if ((serial->pos_regs[2] & 1) && !(val & 1)) + io_removehandler(0x0388, 0x0002, + serial->opl.read, NULL, NULL, + serial->opl.write, NULL, NULL, + serial->opl.priv); + if (!(serial->pos_regs[2] & 1) && (val & 1)) + io_sethandler(0x0388, 0x0002, + serial->opl.read, NULL, NULL, + serial->opl.write, NULL, NULL, + serial->opl.priv); + break; + + default: + break; + } + serial->pos_regs[port & 7] = val; +} + +uint8_t +opl2board_device_mca_feedb(void *priv) +{ + const opl2board_device_t *serial = (opl2board_device_t *) priv; + + return (serial->pos_regs[2] & 1); +} + +void * +opl2board_device_init(UNUSED(const device_t *info)) +{ + opl2board_device_t *serial = malloc(sizeof(opl2board_device_t)); + memset(serial, 0, sizeof(opl2board_device_t)); + + + opl2board_device_log("opl2board_device_init\n"); + fm_driver_get(FM_OPL2BOARD, &serial->opl); + io_sethandler(0x0388, 0x0002, + serial->opl.read, NULL, NULL, + serial->opl.write, NULL, NULL, + serial->opl.priv); + music_add_handler(opl2board_device_get_buffer, serial); + + + return serial; + +} + +void * +opl2board_device_mca_init(const device_t *info) +{ + opl2board_device_t *serial = opl2board_device_init(info); + + io_removehandler(0x0388, 0x0002, + serial->opl.read, NULL, NULL, + serial->opl.write, NULL, NULL, + serial->opl.priv); + mca_add(opl2board_device_mca_read, + opl2board_device_mca_write, + opl2board_device_mca_feedb, + NULL, + serial); + serial->pos_regs[0] = 0xd7; + serial->pos_regs[1] = 0x70; + + return serial; +} + +void +opl2board_device_close(void *priv) +{ + opl2board_device_t *serial = (opl2board_device_t *) priv; + free(serial); +} + + +static const device_config_t opl2board_config[] = { + + { + .name = "host_serial_path", + .description = "Host Serial Device", + .type = CONFIG_SERPORT, + .default_string = "", + .file_filter = NULL, + .spinner = {}, + .selection = {} + }, + { .name = "", .description = "", .type = CONFIG_END } + + }; +const device_t opl2board_device = { + .name = "OPL2Board (External Device)", + .internal_name = "opl2board_device", + .flags = DEVICE_ISA, + .local = 0, + .init = opl2board_device_init, + .close = opl2board_device_close, + .reset = NULL, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = opl2board_config +}; diff --git a/src/sound/snd_opl_opl2board.cpp b/src/sound/snd_opl_opl2board.cpp new file mode 100644 index 000000000..91649f372 --- /dev/null +++ b/src/sound/snd_opl_opl2board.cpp @@ -0,0 +1,550 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Interface to the YMFM External audio device (USB) + * For OPL2Board arduino based. + * + * Authors: Jose Phillips, + * Adrien Moulin, + * + * Copyright 2024 Jose Phillips. + * Copyright 2022 Adrien Moulin. + */ +#include +#include +#include +#include +#include +#include "ymfm/ymfm_opl.h" +#include + + +extern "C" { +#define HAVE_STDARG_H +#include <86box/86box.h> +#include <86box/timer.h> +#include <86box/device.h> +#include <86box/sound.h> +#include <86box/snd_opl.h> +#include <86box/mem.h> +#include <86box/rom.h> +#include <86box/plat_unused.h> +#include <86box/config.h> +#include <86box/ini.h> +#include <86box/device.h> + + +// Disable c99-designator to avoid the warnings in *_ymfm_device +#ifdef __clang__ +# if __has_warning("-Wc99-designator") +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wc99-designator" +# endif +#endif + +} + + +#define RSM_FRAC 10 + +#define OPL_FREQ FREQ_48000 + +enum { + FLAG_CYCLES = (1 << 0) +}; + +uint8_t lastval = 0x00; + + +class OPLBOARDChipBase { +public: + OPLBOARDChipBase(UNUSED(uint32_t clock), fm_type type, uint32_t samplerate) + : m_buf_pos(0) + , m_flags(0) + , m_type(type) + , m_samplerate(samplerate) + { + memset(m_buffer, 0, sizeof(m_buffer)); + } + + virtual ~OPLBOARDChipBase() + { + } + + fm_type type() const { return m_type; } + int8_t flags() const { return m_flags; } + void set_do_cycles(int8_t do_cycles) { do_cycles ? m_flags |= FLAG_CYCLES : m_flags &= ~FLAG_CYCLES; } + int32_t *buffer() const { return (int32_t *) m_buffer; } + void reset_buffer() { m_buf_pos = 0; } + + virtual uint32_t sample_rate() const = 0; + + virtual void write(uint16_t addr, uint8_t data) = 0; + virtual void generate(int32_t *data, uint32_t num_samples) = 0; + virtual int32_t *update() = 0; + virtual uint8_t read(uint16_t addr) = 0; + virtual void set_clock(uint32_t clock) = 0; + + +protected: + int32_t m_buffer[MUSICBUFLEN * 2]; + int m_buf_pos; + int *m_buf_pos_global; + int8_t m_flags; + fm_type m_type; + uint32_t m_samplerate; +}; + +template +class OPLBOARDChip : public OPLBOARDChipBase, public ymfm::ymfm_interface { +public: + OPLBOARDChip(uint32_t clock, fm_type type, uint32_t samplerate) + : OPLBOARDChipBase(clock, type, samplerate) + , m_chip(*this) + , m_clock(clock) + , m_samplerate(samplerate) + , m_samplecnt(0) + { + memset(m_samples, 0, sizeof(m_samples)); + memset(m_oldsamples, 0, sizeof(m_oldsamples)); + m_rateratio = (samplerate << RSM_FRAC) / m_chip.sample_rate(m_clock); + m_clock_us = 1000000.0 / (double) m_clock; + m_subtract[0] = 80.0; + m_subtract[1] = 320.0; + m_type = type; + m_buf_pos_global = (samplerate == FREQ_49716) ? &music_pos_global : &wavetable_pos_global; + + if (m_type == FM_YMF278B) { + if (rom_load_linear("roms/sound/yamaha/yrw801.rom", 0, 0x200000, 0, m_yrw801) == 0) { + fatal("YRW801 ROM image \"roms/sound/yamaha/yrw801.rom\" not found\n"); + } + } + + timer_add(&m_timers[0], OPLBOARDChip::timer1, this, 0); + timer_add(&m_timers[1], OPLBOARDChip::timer2, this, 0); + } + + virtual uint32_t sample_rate() const override + { + return m_chip.sample_rate(m_clock); + } + + virtual void ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks) override + { + if (tnum > 1) + return; + + m_duration_in_clocks[tnum] = duration_in_clocks; + pc_timer_t *timer = &m_timers[tnum]; + if (duration_in_clocks < 0) + timer_stop(timer); + else { + double period = m_clock_us * duration_in_clocks; + if (period < m_subtract[tnum]) + m_engine->engine_timer_expired(tnum); + else + timer_on_auto(timer, period); + } + } + + virtual void set_clock(uint32_t clock) override + { + m_clock = clock; + m_clock_us = 1000000.0 / (double) m_clock; + m_rateratio = (m_samplerate << RSM_FRAC) / m_chip.sample_rate(m_clock); + + ymfm_set_timer(0, m_duration_in_clocks[0]); + ymfm_set_timer(1, m_duration_in_clocks[1]); + } + + virtual void generate(int32_t *data, uint32_t num_samples) override + { + for (uint32_t i = 0; i < num_samples; i++) { + m_chip.generate(&m_output); + if ((m_type == FM_YMF278B) && (sizeof(m_output.data) > (4 * sizeof(int32_t)))) { + if (ChipType::OUTPUTS == 1) { + *data++ = m_output.data[4]; + *data++ = m_output.data[4]; + } else { + *data++ = m_output.data[4]; + *data++ = m_output.data[5]; + } + } else if (ChipType::OUTPUTS == 1) { + *data++ = m_output.data[0]; + *data++ = m_output.data[0]; + } else { + *data++ = m_output.data[0]; + *data++ = m_output.data[1 % ChipType::OUTPUTS]; + } + } + } + +#if 0 + virtual void generate_resampled(int32_t *data, uint32_t num_samples) override + { + if ((m_samplerate == FREQ_49716) || (m_samplerate == FREQ_44100)) { + generate(data, num_samples); + return; + } + + for (uint32_t i = 0; i < num_samples; i++) { + while (m_samplecnt >= m_rateratio) { + m_oldsamples[0] = m_samples[0]; + m_oldsamples[1] = m_samples[1]; + m_chip.generate(&m_output); + if ((m_type == FM_YMF278B) && (sizeof(m_output.data) > (4 * sizeof(int32_t)))) { + if (ChipType::OUTPUTS == 1) { + m_samples[0] = m_output.data[4]; + m_samples[1] = m_output.data[4]; + } else { + m_samples[0] = m_output.data[4]; + m_samples[1] = m_output.data[5]; + } + } else if (ChipType::OUTPUTS == 1) { + m_samples[0] = m_output.data[0]; + m_samples[1] = m_output.data[0]; + } else { + m_samples[0] = m_output.data[0]; + m_samples[1] = m_output.data[1 % ChipType::OUTPUTS]; + } + m_samplecnt -= m_rateratio; + } + + *data++ = ((int32_t) ((m_oldsamples[0] * (m_rateratio - m_samplecnt) + + m_samples[0] * m_samplecnt) + / m_rateratio)); + *data++ = ((int32_t) ((m_oldsamples[1] * (m_rateratio - m_samplecnt) + + m_samples[1] * m_samplecnt) + / m_rateratio)); + + m_samplecnt += 1 << RSM_FRAC; + } + } +#endif + + virtual int32_t *update() override + { + if (m_buf_pos >= *m_buf_pos_global) + return m_buffer; + + generate(&m_buffer[m_buf_pos * 2], *m_buf_pos_global - m_buf_pos); + + for (; m_buf_pos < *m_buf_pos_global; m_buf_pos++) { + m_buffer[m_buf_pos * 2] /= 2; + m_buffer[(m_buf_pos * 2) + 1] /= 2; + } + + return m_buffer; + } + + virtual void write(uint16_t addr, uint8_t data) override + { + + m_chip.write(addr, data); + } + + virtual uint8_t read(uint16_t addr) override + { + return m_chip.read(addr); + } + + virtual uint32_t get_special_flags(void) override + { + return ((m_type == FM_YMF262) || (m_type == FM_YMF289B) || (m_type == FM_YMF278B)) ? 0x8000 : 0x0000; + } + + static void timer1(void *priv) + { + OPLBOARDChip *drv = (OPLBOARDChip *) priv; + drv->m_engine->engine_timer_expired(0); + } + + static void timer2(void *priv) + { + OPLBOARDChip *drv = (OPLBOARDChip *) priv; + drv->m_engine->engine_timer_expired(1); + } + + virtual uint8_t ymfm_external_read(ymfm::access_class type, uint32_t address) override + { + if (type == ymfm::access_class::ACCESS_PCM && address < 0x200000) { + return m_yrw801[address]; + } + return 0xFF; + } + +private: + ChipType m_chip; + uint32_t m_clock; + double m_clock_us; + double m_subtract[2]; + typename ChipType::output_data m_output; + pc_timer_t m_timers[2]; + int32_t m_duration_in_clocks[2]; // Needed for clock switches. + uint32_t m_samplerate; + + // YRW801-M wavetable ROM. + uint8_t m_yrw801[0x200000]; + + // Resampling + int32_t m_rateratio; + int32_t m_samplecnt; + int32_t m_oldsamples[2]; + int32_t m_samples[2]; +}; + +extern "C" { +#include +#include +#include +#include +#include +#include +#define HAVE_STDARG_H + +#include "cpu.h" +#include <86box/86box.h> +#include <86box/io.h> +#include <86box/snd_opl.h> +#include <86box/device.h> +#include <86box/config.h> +#include <86box/ini.h> + + +#ifdef ENABLE_OPL_LOG +int ymfm_do_log = ENABLE_OPL_LOG; + +static void +ymfm_log(const char *fmt, ...) +{ + va_list ap; + + if (ymfm_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +# define ymfm_log(fmt, ...) +#endif + +struct sp_port *port; + + + +void opl2board_init() { + + device_add(&opl2board_device); + const char* port_name = device_get_config_string("host_serial_path"); + device_context_restore(); + + enum sp_return result; + + result = sp_get_port_by_name(port_name, &port); + if (result != SP_OK) { + ymfm_log("Error: Cannot find port %s\n", port_name); + return; + } + + result = sp_open(port, SP_MODE_READ_WRITE); + if (result != SP_OK) { + ymfm_log ("Error: Cannot open port %s\n", port_name); + return; + } + + // Set port configuration this values are hardcoded. + sp_set_baudrate(port, 115200); + sp_set_bits(port, 8); + sp_set_parity(port, SP_PARITY_NONE); + sp_set_stopbits(port, 1); + sp_set_flowcontrol(port, SP_FLOWCONTROL_NONE); + + + ymfm_log("OPL2Board Serial port %s initialized at 115200 baud.\n", port_name); + +} + + +void opl2board_write(uint8_t data) { + if (port == NULL) { + ymfm_log(stderr, "Error: OPL2Board Port not initialized.\n"); + + return; + } + + enum sp_return result = sp_blocking_write(port, &data, sizeof(data), 1000); + if (result < 0) { + ymfm_log(stderr, "Error: Failed to write to OPL2Board port.\n"); + } else { + ymfm_log("OPL2Board: data sent: %02X\n", data); + } +} + + +void opl2board_reset() { + + // Reset all voices to 0 + ymfm_log("Performing OPL2Board reset\n"); + for (uint8_t i = 0x00; i < 0xFF; i++) { + if (i >= 0x40 && i <= 0x55) { + opl2board_write(i); + opl2board_write(0x3F); + } else { + opl2board_write (i); + opl2board_write(0x00); + } } +} + +void opl2board_close() { + + if (port != NULL) { + opl2board_reset(); + sp_close(port); + sp_free_port(port); + port = NULL; + ymfm_log("OPL2Board port closed.\n"); + } +} + + +static void * +ymfm_opl2board_drv_init(const device_t *info) +{ + OPLBOARDChipBase *fm; + + switch (info->local) { + default: + case FM_OPL2BOARD: + fm = (OPLBOARDChipBase *) new OPLBOARDChip(3579545, FM_OPL2BOARD, FREQ_49716); + break; + } + fm->set_do_cycles(1); + + return fm; +} + +static void +ymfm_opl2board_drv_close(void *priv) +{ + OPLBOARDChipBase *drv = (OPLBOARDChipBase *) priv; + opl2board_close(); + if (drv != NULL) + delete drv; +} + +static uint8_t +ymfm_opl2board_drv_read(uint16_t port, void *priv) +{ + OPLBOARDChipBase *drv = (OPLBOARDChipBase *) priv; + + if ((port == 0x380) || (port == 0x381)) + port |= 4; + + /* Point to register read port. */ + if (drv->flags() & FLAG_CYCLES) + cycles -= ((int) (isa_timing * 8)); + + uint8_t ret = drv->read(port); + drv->update(); + + ymfm_log("YMFM read port %04x, status = %02x\n", port, ret); + return ret; +} + +static void +ymfm_opl2board_drv_write(uint16_t port, uint8_t val, void *priv) +{ + + OPLBOARDChipBase *drv = (OPLBOARDChipBase *) priv; + + ymfm_log("YMFM write port %04x value = %02x\n", port, val); + if ((port == 0x380) || (port == 0x381)) + port |= 4; + // Allow initialization of adlib + if ((val == 0x04 || val == 0x02) || (lastval == 0x04 || lastval == 0x02)) { + drv->write(port, val); + } + lastval = val; + opl2board_write(val); + drv->update(); +} + + +static int32_t * +ymfm_opl2board_drv_update(void *priv) +{ + if (port == NULL) { + opl2board_init(); + opl2board_reset(); + } + OPLBOARDChipBase *drv = (OPLBOARDChipBase *) priv; + + return drv->update(); +} + +static void +ymfm_opl2board_drv_reset_buffer(void *priv) +{ + OPLBOARDChipBase *drv = (OPLBOARDChipBase *) priv; + + drv->reset_buffer(); +} + +static void +ymfm_opl2board_drv_set_do_cycles(void *priv, int8_t do_cycles) +{ + OPLBOARDChipBase *drv = (OPLBOARDChipBase *) priv; + drv->set_do_cycles(do_cycles); +} + +static void +ymfm_opl2board_drv_generate(void *priv, int32_t *data, uint32_t num_samples) +{ + + OPLBOARDChipBase *drv = (OPLBOARDChipBase *) priv; + // drv->generate_resampled(data, num_samples); + drv->generate(data, num_samples); + +} + + + + +const device_t ym_opl2board_device = { + .name = "YMOPL2Board (External Device)", + .internal_name = "ym_opl2board_device", + .flags = 0, + .local = FM_OPL2BOARD, + .init = ymfm_opl2board_drv_init, + .close = ymfm_opl2board_drv_close, + .reset = NULL, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const fm_drv_t ymfm_opl2board_drv { + &ymfm_opl2board_drv_read, + &ymfm_opl2board_drv_write, + &ymfm_opl2board_drv_update, + &ymfm_opl2board_drv_reset_buffer, + &ymfm_opl2board_drv_set_do_cycles, + NULL, + ymfm_opl2board_drv_generate + +}; + +#ifdef __clang__ +# if __has_warning("-Wc99-designator") +# pragma clang diagnostic pop +# endif +#endif + +} diff --git a/src/sound/sound.c b/src/sound/sound.c index f941c8817..0571bc203 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -181,6 +181,7 @@ static const SOUND_CARD sound_cards[] = { { &ess_1688_device }, { &ess_ess0102_pnp_device }, { &ess_ess0968_pnp_device }, + { &opl2board_device }, { NULL } // clang-format on }; From a651cd113b0deb08cda3fac57bc2bd7a8a19a704 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 18:12:57 -0500 Subject: [PATCH 02/14] Some code clean --- src/sound/CMakeLists.txt | 4 ---- src/sound/snd_opl.c | 5 +---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index 438b558a2..98788b6b8 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -124,13 +124,9 @@ if(OPL4ML) target_compile_definitions(snd PRIVATE USE_OPL4ML) target_sources(snd PRIVATE midi_opl4.c midi_opl4_yrw801.c) endif() - find_package(PkgConfig REQUIRED) pkg_check_modules(SERIALPORT REQUIRED libserialport) include_directories(${SERIALPORT_INCLUDE}) target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) - - - add_subdirectory(resid-fp) target_link_libraries(86Box resid-fp) diff --git a/src/sound/snd_opl.c b/src/sound/snd_opl.c index 9f7e4c459..931277332 100644 --- a/src/sound/snd_opl.c +++ b/src/sound/snd_opl.c @@ -60,12 +60,9 @@ fm_driver_get(int chip_id, fm_drv_t *drv) break; case FM_OPL2BOARD: - *drv = ymfm_opl2board_drv; - drv->priv = device_add_inst(&ym_opl2board_device, fm_dev_inst[fm_driver][chip_id]++); - + drv->priv = device_add_inst(&ym_opl2board_device, fm_dev_inst[fm_driver][chip_id]++); break; - case FM_YMF289B: *drv = ymfm_drv; drv->priv = device_add_inst(&ymf289b_ymfm_device, fm_dev_inst[fm_driver][chip_id]++); From 984a71ccfb90c64fc6879876639f984c3fd64a25 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 19:04:55 -0500 Subject: [PATCH 03/14] Added dependencies on CI --- .ci/dependencies_macports.txt | 1 + .ci/dependencies_msys.txt | 1 + src/sound/CMakeLists.txt | 1 + src/sound/snd_opl2board.c | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/.ci/dependencies_macports.txt b/.ci/dependencies_macports.txt index b23ac441d..e530871ae 100644 --- a/.ci/dependencies_macports.txt +++ b/.ci/dependencies_macports.txt @@ -16,3 +16,4 @@ ghostscript libslirp vde2 libsndfile +libserialport diff --git a/.ci/dependencies_msys.txt b/.ci/dependencies_msys.txt index eacdb8b36..1d4692d3f 100644 --- a/.ci/dependencies_msys.txt +++ b/.ci/dependencies_msys.txt @@ -14,3 +14,4 @@ qt5-static qt5-translations vulkan-headers libsndfile +ibserialport \ No newline at end of file diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index b77ad423a..e25c39391 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -32,6 +32,7 @@ add_library(snd OBJECT snd_adlib.c snd_adlibgold.c snd_opl2board.c + snd_opl_opl2board.cpp snd_ad1848.c snd_audiopci.c snd_azt2316a.c diff --git a/src/sound/snd_opl2board.c b/src/sound/snd_opl2board.c index 1ad147e8c..57fafbae7 100644 --- a/src/sound/snd_opl2board.c +++ b/src/sound/snd_opl2board.c @@ -1,3 +1,23 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Interface to the OPL2Board External audio device (USB) + * + * + * Authors: Jose Phillips + * Fred N. van Kempen, + * Miran Grca, + * + * Copyright 2024 Jose Phillips. + * Copyright 2017-2020 Fred N. van Kempen. + * Copyright 2016-2020 Miran Grca. + */ + #include #include #include From a71dafcae3234e36b57e7c71479404510483ce9c Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 19:15:22 -0500 Subject: [PATCH 04/14] More CI tests --- .ci/dependencies_msys.txt | 2 +- debian/control | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.ci/dependencies_msys.txt b/.ci/dependencies_msys.txt index 1d4692d3f..766aadda3 100644 --- a/.ci/dependencies_msys.txt +++ b/.ci/dependencies_msys.txt @@ -14,4 +14,4 @@ qt5-static qt5-translations vulkan-headers libsndfile -ibserialport \ No newline at end of file +libserialport \ No newline at end of file diff --git a/debian/control b/debian/control index a718aee33..a11e2af48 100644 --- a/debian/control +++ b/debian/control @@ -16,7 +16,8 @@ Build-Depends: cmake (>= 3.21), libsndfile-dev, ninja-build, qttools5-dev, - qtbase5-private-dev + qtbase5-private-dev, + libserialport-dev Standards-Version: 4.6.0 Homepage: https://86box.net/ #Vcs-Browser: https://salsa.debian.org/debian/86box From 2b6538460b084bae4f76a348c147bba07c7361b3 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 19:23:08 -0500 Subject: [PATCH 05/14] More CI additions --- .github/workflows/cmake_linux.yml | 1 + .github/workflows/cmake_macos.yml | 1 + .github/workflows/cmake_windows_msys2.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/cmake_linux.yml b/.github/workflows/cmake_linux.yml index a8945172b..b2ec5321a 100644 --- a/.github/workflows/cmake_linux.yml +++ b/.github/workflows/cmake_linux.yml @@ -82,6 +82,7 @@ jobs: libslirp-dev libfluidsynth-dev libvdeplug-dev + libserialport-dev ${{ matrix.ui.packages }} - name: Checkout repository diff --git a/.github/workflows/cmake_macos.yml b/.github/workflows/cmake_macos.yml index d02ec595b..2e35c13de 100644 --- a/.github/workflows/cmake_macos.yml +++ b/.github/workflows/cmake_macos.yml @@ -82,6 +82,7 @@ jobs: fluidsynth libslirp vde + libserialport ${{ matrix.ui.packages }} - name: Checkout repository diff --git a/.github/workflows/cmake_windows_msys2.yml b/.github/workflows/cmake_windows_msys2.yml index 7620351b3..e55e1c1f7 100644 --- a/.github/workflows/cmake_windows_msys2.yml +++ b/.github/workflows/cmake_windows_msys2.yml @@ -97,6 +97,7 @@ jobs: rtmidi:p libslirp:p fluidsynth:p + libserialport:p ${{ matrix.ui.packages }} - name: Checkout repository From 7f8a34990c761c4336cc218fde61c9a13cbe5354 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 19:33:10 -0500 Subject: [PATCH 06/14] added dependencies to codeql --- .github/workflows/codeql_linux.yml | 1 + .github/workflows/codeql_macos.yml | 1 + .github/workflows/codeql_windows_msys2.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/codeql_linux.yml b/.github/workflows/codeql_linux.yml index 412a2045c..fc0397703 100644 --- a/.github/workflows/codeql_linux.yml +++ b/.github/workflows/codeql_linux.yml @@ -85,6 +85,7 @@ jobs: libslirp-dev libfluidsynth-dev libvdeplug-dev + libserialport-dev ${{ matrix.ui.packages }} - name: Checkout repository diff --git a/.github/workflows/codeql_macos.yml b/.github/workflows/codeql_macos.yml index 5ce12548b..234e04f55 100644 --- a/.github/workflows/codeql_macos.yml +++ b/.github/workflows/codeql_macos.yml @@ -76,6 +76,7 @@ jobs: fluidsynth libslirp vde + libserialport ${{ matrix.ui.packages }} - name: Checkout repository diff --git a/.github/workflows/codeql_windows_msys2.yml b/.github/workflows/codeql_windows_msys2.yml index 67de8ec8b..7a0055910 100644 --- a/.github/workflows/codeql_windows_msys2.yml +++ b/.github/workflows/codeql_windows_msys2.yml @@ -102,6 +102,7 @@ jobs: rtmidi:p libslirp:p fluidsynth:p + libserialport:p ${{ matrix.ui.packages }} - name: Checkout repository From 04db328bf32948ca05fa24d2a57ca3e9ff6e833f Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 20:33:51 -0500 Subject: [PATCH 07/14] Added library on CMAKE --- .github/workflows/cmake_macos.yml | 3 +++ .github/workflows/codeql_macos.yml | 1 + CMakePresets.json | 4 +++- src/sound/sound.c | 5 ----- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cmake_macos.yml b/.github/workflows/cmake_macos.yml index 2e35c13de..18aafd544 100644 --- a/.github/workflows/cmake_macos.yml +++ b/.github/workflows/cmake_macos.yml @@ -103,6 +103,7 @@ jobs: -D Qt5_ROOT=$(brew --prefix qt@5) -D Qt5LinguistTools_ROOT=$(brew --prefix qt@5) -D OpenAL_ROOT=$(brew --prefix openal-soft) + -D LIBSERIALPORT_ROOT=$(brew --prefix libserialport) - name: Build run: | @@ -182,6 +183,7 @@ jobs: openal-soft fluidsynth libslirp + libserialport ${{ matrix.ui.packages }} - name: Checkout repository @@ -202,6 +204,7 @@ jobs: -D Qt5_ROOT=$(brew --prefix qt@5) -D Qt5LinguistTools_ROOT=$(brew --prefix qt@5) -D OpenAL_ROOT=$(brew --prefix openal-soft) + -D LIBSERIALPORT_ROOT=$(brew --prefix libserialport) - name: Build run: | diff --git a/.github/workflows/codeql_macos.yml b/.github/workflows/codeql_macos.yml index 234e04f55..841ca98f5 100644 --- a/.github/workflows/codeql_macos.yml +++ b/.github/workflows/codeql_macos.yml @@ -98,6 +98,7 @@ jobs: -D Qt5_ROOT=$(brew --prefix qt@5) -D Qt5LinguistTools_ROOT=$(brew --prefix qt@5) -D OpenAL_ROOT=$(brew --prefix openal-soft) + -D LIBSERIALPORT_ROOT=$(brew --prefix libserialport) - name: Build run: cmake --build build diff --git a/CMakePresets.json b/CMakePresets.json index c19a7abc0..d4af8e6cb 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -68,7 +68,8 @@ "Qt5_DIR": "/opt/homebrew/opt/qt@5/lib/cmake/Qt5", "MOLTENVK_DIR": "/opt/homebrew/opt/molten-vk", "Qt5LinguistTools_DIR": "/opt/homebrew/opt/qt@5/lib/cmake/Qt5LinguistTools", - "OpenAL_ROOT": "/opt/homebrew/opt/openal-soft" + "OpenAL_ROOT": "/opt/homebrew/opt/openal-soft", + "LIBSERIALPORT_ROOT": "/opt/homebrew/opt/libserialport" }, "inherits": "regular" }, @@ -86,6 +87,7 @@ "MOLTENVK_DIR": "/opt/homebrew/opt/molten-vk", "Qt5LinguistTools_DIR": "/opt/homebrew/opt/qt@5/lib/cmake/Qt5LinguistTools", "OpenAL_ROOT": "/opt/homebrew/opt/openal-soft", + "LIBSERIALPORT_ROOT": "/opt/homebrew/opt/libserialport", "CMAKE_CXX_FLAGS_DEBUG": "-g -O0 -DENABLE_VDE_LOG", "CMAKE_C_FLAGS_DEBUG": "-g -O0 -DENABLE_VDE_LOG" }, diff --git a/src/sound/sound.c b/src/sound/sound.c index 54d0d857f..851c849e4 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -153,11 +153,6 @@ static const SOUND_CARD sound_cards[] = { { &ct5880_device }, { &ad1881_device }, { &cs4297a_device }, - { &ess_688_device }, - { &ess_ess0100_pnp_device }, - { &ess_1688_device }, - { &ess_ess0102_pnp_device }, - { &ess_ess0968_pnp_device }, { &opl2board_device }, { NULL } // clang-format on From 875bfc6fb7851046e987c6bc60edf98251210b5e Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 21:03:43 -0500 Subject: [PATCH 08/14] More fixes on Cmakelists --- src/sound/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index e25c39391..644deb5c3 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -173,7 +173,7 @@ if(OPL4ML) target_sources(snd PRIVATE midi_opl4.c midi_opl4_yrw801.c) endif() find_package(PkgConfig REQUIRED) - pkg_check_modules(SERIALPORT REQUIRED libserialport) + pkg_check_modules(LIBSERIALPORT REQUIRED libserialport) include_directories(${SERIALPORT_INCLUDE}) target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) add_subdirectory(resid-fp) From 9003217840d7146e9343bc26c5725ec1ea2f1e76 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 21:44:51 -0500 Subject: [PATCH 09/14] fix apple --- src/sound/CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index 644deb5c3..386e8a2dc 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -172,9 +172,13 @@ if(OPL4ML) target_compile_definitions(snd PRIVATE USE_OPL4ML) target_sources(snd PRIVATE midi_opl4.c midi_opl4_yrw801.c) endif() - find_package(PkgConfig REQUIRED) - pkg_check_modules(LIBSERIALPORT REQUIRED libserialport) - include_directories(${SERIALPORT_INCLUDE}) - target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(SERIALPORT REQUIRED libserialport) +if(APPLE) + include_directories(${LIBSERIALPORT_ROOT}/include) + target_link_libraries(86Box ${LIBSERIALPORT_ROOT}/lib/libserialport.dylib) +endif() + add_subdirectory(resid-fp) target_link_libraries(86Box resid-fp) From 7f8f49e6e7f0d283ce95142bb3bfce17c131dd23 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 22:32:15 -0500 Subject: [PATCH 10/14] fix for other platforms --- src/sound/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index 386e8a2dc..b4a0f3796 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -178,6 +178,9 @@ pkg_check_modules(SERIALPORT REQUIRED libserialport) if(APPLE) include_directories(${LIBSERIALPORT_ROOT}/include) target_link_libraries(86Box ${LIBSERIALPORT_ROOT}/lib/libserialport.dylib) +else() + include_directories(${SERIALPORT_INCLUDE_DIRS}) + target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) endif() add_subdirectory(resid-fp) From 9e77792f7b2b7de989ccc794738428a6b98ff21b Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 1 Dec 2024 23:45:53 -0500 Subject: [PATCH 11/14] test windows --- src/sound/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index b4a0f3796..4837d76ac 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -182,6 +182,9 @@ else() include_directories(${SERIALPORT_INCLUDE_DIRS}) target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) endif() - +if (WIN32) + target_compile_options(86Box PUBLIC ${SERIALPORT_CFLAGS_OTHER} --static ) +endif() + add_subdirectory(resid-fp) target_link_libraries(86Box resid-fp) From d3a69df4d31eb17aa5d66e7d380868023aa376c3 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Mon, 2 Dec 2024 00:09:43 -0500 Subject: [PATCH 12/14] test windows --- .github/workflows/cmake_windows_msys2.yml | 1 + .github/workflows/codeql_windows_msys2.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/cmake_windows_msys2.yml b/.github/workflows/cmake_windows_msys2.yml index e55e1c1f7..d5d3e8200 100644 --- a/.github/workflows/cmake_windows_msys2.yml +++ b/.github/workflows/cmake_windows_msys2.yml @@ -116,6 +116,7 @@ jobs: -D CMAKE_INSTALL_PREFIX=./build/artifacts -D QT=${{ matrix.ui.qt }} -D STATIC_BUILD=${{ matrix.ui.static }} + -D CMAKE_EXE_LINKER_FLAGS="$(pkg-config --libs libserialport --static )" - name: Build run: | diff --git a/.github/workflows/codeql_windows_msys2.yml b/.github/workflows/codeql_windows_msys2.yml index 7a0055910..7382f503c 100644 --- a/.github/workflows/codeql_windows_msys2.yml +++ b/.github/workflows/codeql_windows_msys2.yml @@ -122,6 +122,7 @@ jobs: -D CMAKE_INSTALL_PREFIX=./build/artifacts -D QT=${{ matrix.ui.qt }} -D STATIC_BUILD=${{ matrix.ui.static }} + -D CMAKE_EXE_LINKER_FLAGS="$(pkg-config --libs libserialport --static )" - name: Build run: cmake --build build From 267d4b2e022fd97e91aa6fbd131b69e1858ab5b1 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Mon, 2 Dec 2024 00:40:06 -0500 Subject: [PATCH 13/14] adding setupAPI --- .github/workflows/cmake_windows_msys2.yml | 1 - .github/workflows/codeql_windows_msys2.yml | 1 - src/sound/CMakeLists.txt | 7 ++++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cmake_windows_msys2.yml b/.github/workflows/cmake_windows_msys2.yml index d5d3e8200..e55e1c1f7 100644 --- a/.github/workflows/cmake_windows_msys2.yml +++ b/.github/workflows/cmake_windows_msys2.yml @@ -116,7 +116,6 @@ jobs: -D CMAKE_INSTALL_PREFIX=./build/artifacts -D QT=${{ matrix.ui.qt }} -D STATIC_BUILD=${{ matrix.ui.static }} - -D CMAKE_EXE_LINKER_FLAGS="$(pkg-config --libs libserialport --static )" - name: Build run: | diff --git a/.github/workflows/codeql_windows_msys2.yml b/.github/workflows/codeql_windows_msys2.yml index 7382f503c..7a0055910 100644 --- a/.github/workflows/codeql_windows_msys2.yml +++ b/.github/workflows/codeql_windows_msys2.yml @@ -122,7 +122,6 @@ jobs: -D CMAKE_INSTALL_PREFIX=./build/artifacts -D QT=${{ matrix.ui.qt }} -D STATIC_BUILD=${{ matrix.ui.static }} - -D CMAKE_EXE_LINKER_FLAGS="$(pkg-config --libs libserialport --static )" - name: Build run: cmake --build build diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index 4837d76ac..315da61e4 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -178,13 +178,14 @@ pkg_check_modules(SERIALPORT REQUIRED libserialport) if(APPLE) include_directories(${LIBSERIALPORT_ROOT}/include) target_link_libraries(86Box ${LIBSERIALPORT_ROOT}/lib/libserialport.dylib) +elseif(WIN32) + include_directories(${SERIALPORT_INCLUDE_DIRS}) + target_link_libraries(86Box ${SERIALPORT_LIBRARIES} SetupAPI) else() include_directories(${SERIALPORT_INCLUDE_DIRS}) target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) endif() -if (WIN32) - target_compile_options(86Box PUBLIC ${SERIALPORT_CFLAGS_OTHER} --static ) -endif() + add_subdirectory(resid-fp) target_link_libraries(86Box resid-fp) From 803c19b4c2c1d62d0e2e80a505f98d40aa6472c8 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Sun, 8 Dec 2024 18:10:05 -0500 Subject: [PATCH 14/14] check if libserial exists for unsupported libserial OS --- src/include/86box/snd_opl.h | 4 +++- src/include/86box/sound.h | 2 ++ src/sound/CMakeLists.txt | 36 +++++++++++++++++++++--------------- src/sound/snd_opl.c | 3 ++- src/sound/sound.c | 2 ++ 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/include/86box/snd_opl.h b/src/include/86box/snd_opl.h index 95eec2687..8a6a7d6ef 100644 --- a/src/include/86box/snd_opl.h +++ b/src/include/86box/snd_opl.h @@ -60,8 +60,10 @@ extern const device_t ymf289b_ymfm_device; extern const device_t ymf278b_ymfm_device; extern const device_t esfm_esfmu_device; - +#ifdef USE_LIBSERIALPORT extern const device_t ym_opl2board_device; #endif +#endif + #endif /*SOUND_OPL_H*/ diff --git a/src/include/86box/sound.h b/src/include/86box/sound.h index 428f12932..bcf7f2ae5 100644 --- a/src/include/86box/sound.h +++ b/src/include/86box/sound.h @@ -209,8 +209,10 @@ extern const device_t tndy_device; extern const device_t wss_device; extern const device_t ncr_business_audio_device; +#ifdef USE_LIBSERIALPORT /* External Audio device OPL2Board (Host Connected hardware)*/ extern const device_t opl2board_device; +#endif #endif diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index 315da61e4..a381051ba 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -31,8 +31,6 @@ add_library(snd OBJECT snd_ps1.c snd_adlib.c snd_adlibgold.c - snd_opl2board.c - snd_opl_opl2board.cpp snd_ad1848.c snd_audiopci.c snd_azt2316a.c @@ -172,20 +170,28 @@ if(OPL4ML) target_compile_definitions(snd PRIVATE USE_OPL4ML) target_sources(snd PRIVATE midi_opl4.c midi_opl4_yrw801.c) endif() - -find_package(PkgConfig REQUIRED) -pkg_check_modules(SERIALPORT REQUIRED libserialport) -if(APPLE) - include_directories(${LIBSERIALPORT_ROOT}/include) - target_link_libraries(86Box ${LIBSERIALPORT_ROOT}/lib/libserialport.dylib) -elseif(WIN32) - include_directories(${SERIALPORT_INCLUDE_DIRS}) - target_link_libraries(86Box ${SERIALPORT_LIBRARIES} SetupAPI) -else() - include_directories(${SERIALPORT_INCLUDE_DIRS}) - target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) -endif() + +find_package(PkgConfig ) +pkg_check_modules(SERIALPORT libserialport) +if(SERIALPORT_FOUND OR DEFINED LIBSERIALPORT_ROOT) + add_compile_definitions(USE_LIBSERIALPORT=1) + + if(APPLE) + include_directories(${LIBSERIALPORT_ROOT}/include) + target_link_libraries(86Box ${LIBSERIALPORT_ROOT}/lib/libserialport.dylib) + elseif(WIN32) + include_directories(${SERIALPORT_INCLUDE_DIRS}) + target_link_libraries(86Box ${SERIALPORT_LIBRARIES} SetupAPI) + else() + include_directories(${SERIALPORT_INCLUDE_DIRS}) + target_link_libraries(86Box ${SERIALPORT_LIBRARIES}) + endif() + target_sources(snd PRIVATE + snd_opl2board.c + snd_opl_opl2board.cpp +) +endif() add_subdirectory(resid-fp) target_link_libraries(86Box resid-fp) diff --git a/src/sound/snd_opl.c b/src/sound/snd_opl.c index 931277332..cddc18119 100644 --- a/src/sound/snd_opl.c +++ b/src/sound/snd_opl.c @@ -58,11 +58,12 @@ fm_driver_get(int chip_id, fm_drv_t *drv) drv->priv = device_add_inst(&ymf262_ymfm_device, fm_dev_inst[fm_driver][chip_id]++); } break; - +#ifdef USE_LIBSERIALPORT case FM_OPL2BOARD: *drv = ymfm_opl2board_drv; drv->priv = device_add_inst(&ym_opl2board_device, fm_dev_inst[fm_driver][chip_id]++); break; +#endif case FM_YMF289B: *drv = ymfm_drv; drv->priv = device_add_inst(&ymf289b_ymfm_device, fm_dev_inst[fm_driver][chip_id]++); diff --git a/src/sound/sound.c b/src/sound/sound.c index 851c849e4..7e6a1ac1c 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -153,7 +153,9 @@ static const SOUND_CARD sound_cards[] = { { &ct5880_device }, { &ad1881_device }, { &cs4297a_device }, +#ifdef USE_LIBSERIALPORT /*The following devices required LIBSERIALPORT*/ { &opl2board_device }, +#endif { NULL } // clang-format on };