mirror of
https://github.com/polpo/picogus.git
synced 2026-10-25 21:40:16 +00:00
Experiments with nuked-opl3
This commit is contained in:
1 parent
ab813bba3d
commit
782243e06d
3 files changed
+55
-11
No files matched your search
+12
-8
@@ -89,26 +89,30 @@ if(PROJECT_TYPE STREQUAL "GUS")
|
||||
)
|
||||
pico_enable_stdio_uart(picogus 0)
|
||||
else()
|
||||
pico_enable_stdio_uart(picogus 1)
|
||||
pico_enable_stdio_uart(picogus 0)
|
||||
endif()
|
||||
pico_enable_stdio_usb(picogus 0)
|
||||
pico_enable_stdio_usb(picogus 1)
|
||||
pico_enable_stdio_semihosting(picogus 0)
|
||||
endif()
|
||||
|
||||
if(PROJECT_TYPE STREQUAL "OPL")
|
||||
pico_set_program_name(picogus "picogus-adlib")
|
||||
target_sources(picogus PRIVATE adlibplay.cpp)
|
||||
target_sources(picogus PRIVATE
|
||||
adlibplay.cpp
|
||||
Nuked-OPL3/opl3.c
|
||||
)
|
||||
target_link_libraries(
|
||||
picogus
|
||||
opl
|
||||
# opl
|
||||
)
|
||||
target_compile_definitions(picogus PRIVATE
|
||||
SOUND_OPL=1
|
||||
USE_EMU8950_OPL=1
|
||||
EMU8950_ASM=1
|
||||
# USE_EMU8950_OPL=1
|
||||
# EMU8950_ASM=1
|
||||
OPL_NUKED=1
|
||||
)
|
||||
add_subdirectory(opl)
|
||||
pico_enable_stdio_uart(picogus 0)
|
||||
# add_subdirectory(opl)
|
||||
pico_enable_stdio_uart(picogus 1)
|
||||
pico_enable_stdio_usb(picogus 0)
|
||||
pico_enable_stdio_semihosting(picogus 0)
|
||||
endif()
|
||||
|
||||
@@ -18,7 +18,12 @@
|
||||
|
||||
#include "pico/audio_i2s.h"
|
||||
|
||||
#ifdef OPL_NUKED
|
||||
#include "Nuked-OPL3/opl3.h"
|
||||
extern opl3_chip nuked_chip;
|
||||
#else
|
||||
#include "opl.h"
|
||||
#endif
|
||||
|
||||
#if PICO_ON_DEVICE
|
||||
#include "pico/binary_info.h"
|
||||
@@ -70,9 +75,26 @@ void play_adlib() {
|
||||
uint32_t start, end;
|
||||
|
||||
struct audio_buffer_pool *ap = init_audio();
|
||||
|
||||
OPL3_Reset(&nuked_chip, 49716);
|
||||
|
||||
for (;;) {
|
||||
struct audio_buffer *buffer = take_audio_buffer(ap, true);
|
||||
#ifdef OPL_NUKED
|
||||
int16_t *samples = (int16_t *) buffer->buffer->bytes;
|
||||
uint32_t audio_begin = time_us_32();
|
||||
// putchar('=');
|
||||
for (int i = 0; i < buffer->max_sample_count; ++i) {
|
||||
OPL3_Generate(&nuked_chip, samples + (i << 1));
|
||||
}
|
||||
uint32_t audio_elapsed = time_us_32() - audio_begin;
|
||||
if (audio_elapsed > 1280) {
|
||||
printf("took too long: %u\n", audio_elapsed);
|
||||
}
|
||||
buffer->sample_count = buffer->max_sample_count;
|
||||
#else
|
||||
OPL_Pico_Mix_callback(buffer);
|
||||
#endif
|
||||
// putchar((unsigned char)buffer->buffer->bytes[1]);
|
||||
give_audio_buffer(ap, buffer);
|
||||
}
|
||||
|
||||
+21
-3
@@ -27,14 +27,20 @@ psram_spi_inst_t* async_spi_inst;
|
||||
#define BAUD_RATE 115200
|
||||
|
||||
#ifdef SOUND_OPL
|
||||
#ifdef OPL_NUKED
|
||||
#include "Nuked-OPL3/opl3.h"
|
||||
uint8_t opl_reg;
|
||||
opl3_chip nuked_chip = {};
|
||||
#else
|
||||
#include "opl.h"
|
||||
static uint16_t basePort = 0x388u;
|
||||
|
||||
void play_adlib(void);
|
||||
extern "C" int OPL_Pico_Init(unsigned int);
|
||||
extern "C" void OPL_Pico_PortWrite(opl_port_t, unsigned int);
|
||||
extern "C" unsigned int OPL_Pico_PortRead(opl_port_t);
|
||||
#endif
|
||||
static uint16_t basePort = 0x388u;
|
||||
|
||||
void play_adlib(void);
|
||||
#endif
|
||||
|
||||
#ifdef SOUND_GUS
|
||||
#include "gus-x.cpp"
|
||||
@@ -265,13 +271,21 @@ __force_inline void handle_iow(void) {
|
||||
case 0:
|
||||
// Fast write
|
||||
pio_sm_put(pio0, iow_sm, IO_END);
|
||||
#ifdef OPL_NUKED
|
||||
opl_reg = iow_read & 0xFF;
|
||||
#else
|
||||
OPL_Pico_PortWrite(OPL_REGISTER_PORT, iow_read & 0xFF);
|
||||
#endif
|
||||
// Fast write - return early as we've already written 0x0u to the PIO
|
||||
return;
|
||||
break;
|
||||
case 1:
|
||||
pio_sm_put(pio0, iow_sm, IO_WAIT);
|
||||
#ifdef OPL_NUKED
|
||||
OPL3_WriteRegBuffered(&nuked_chip, opl_reg, iow_read & 0xFF);
|
||||
#else
|
||||
OPL_Pico_PortWrite(OPL_DATA_PORT, iow_read & 0xFF);
|
||||
#endif
|
||||
// __dsb();
|
||||
break;
|
||||
}
|
||||
@@ -364,6 +378,7 @@ __force_inline void handle_ior(void) {
|
||||
// gpio_xor_mask(LED_PIN);
|
||||
} else // if follows down below
|
||||
#elif defined(SOUND_OPL)
|
||||
#if 0 // commenting out because hand386
|
||||
if (port == basePort) {
|
||||
// Tell PIO to wait for data
|
||||
pio_sm_put(pio0, ior_sm, IO_WAIT);
|
||||
@@ -371,6 +386,7 @@ __force_inline void handle_ior(void) {
|
||||
// OR with 0x0000ff00 is required to set pindirs in the PIO
|
||||
pio_sm_put(pio0, ior_sm, IOR_SET_VALUE | value);
|
||||
} else // if follows down below
|
||||
#endif
|
||||
#elif defined(SOUND_MPU)
|
||||
if (port == basePort) {
|
||||
// Tell PIO to wait for data
|
||||
@@ -510,7 +526,9 @@ int main()
|
||||
|
||||
#ifdef SOUND_OPL
|
||||
puts("Creating OPL");
|
||||
#ifndef OPL_NUKED
|
||||
OPL_Pico_Init(basePort);
|
||||
#endif
|
||||
multicore_launch_core1(&play_adlib);
|
||||
#endif // SOUND_OPL
|
||||
|
||||
|
||||
Reference in new issue
Block a user