Skip to content

Commit

Permalink
Clean up MPU-401, increase midi buffer size in non-MPU modes
Browse files Browse the repository at this point in the history
  • Loading branch information
polpo committed Dec 9, 2024
1 parent fe8e968 commit a3df9cd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 31 deletions.
2 changes: 1 addition & 1 deletion sw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ if(PROJECT_TYPE STREQUAL "MULTIFW")
pico_add_extra_outputs(bootloader)
# set_linker_script(bootloader ${CMAKE_SOURCE_DIR}/multifw/bootloader.ld)
target_include_directories(bootloader PRIVATE ${CMAKE_BINARY_DIR}/generated/multifw)
pico_enable_stdio_uart(bootloader 1)
pico_enable_stdio_uart(bootloader 0)
pico_enable_stdio_usb(bootloader 0)
pico_enable_stdio_semihosting(bootloader 0)
add_dependencies(bootloader generate_flash_firmware_h)
Expand Down
2 changes: 1 addition & 1 deletion sw/gusplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void play_gus() {
#endif
#ifdef SOUND_MPU
// Calculate number of midi bytes to send at current sample rate and number of samples generated
send_midi_bytes(MAX(31250 * sample_count / playback_rate + 1, 4));
send_midi_bytes(MAX(31250 * sample_count / playback_rate + 1, 8));
#endif
}
}
4 changes: 2 additions & 2 deletions sw/mpu401/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ typedef int32_t Bits;
#define RAWBUF 65536
#define RAWBUF_BITS 65535
#else
#define RAWBUF 8192
#define RAWBUF_BITS 8191
#define RAWBUF 16384
#define RAWBUF_BITS 16383
#endif // MPU_ONLY

typedef struct ring_buffer {
Expand Down
29 changes: 2 additions & 27 deletions sw/mpu401/mpu401.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ typedef uint16_t Bit16u;
typedef int32_t Bits;
typedef int8_t Bit8s;

// autodetect when Gateway runs by watching for it setting this message on the MT-32's LCD
static const char* gateway_msg = "\xf0\x41\x10\x16\x12\x20\x00\x00 Gateway";
static uint8_t gateway_pos = 0;
static uint8_t gateway_len = 22;

#include "../pico_pic.h"

void MIDI_Init(bool delaysysex,bool fakeallnotesoff);
Expand Down Expand Up @@ -100,7 +95,6 @@ typedef enum MpuDataType MpuDataType; /* SOFTMPU */
#define MSG_MPU_CLOCK 0xfd
#define MSG_MPU_ACK 0xfe

static bool config_versionfix = false;
static bool config_delaysysex = false;
static bool config_fakeallnotesoff = false;

Expand Down Expand Up @@ -278,14 +272,8 @@ __force_inline void MPU401_WriteCommand(Bit8u val, bool crit) { /* SOFTMPU */
QueueByte(0);
goto write_command_return;
case 0xac: /* Request version */
if (config_versionfix) {
// Hack for Gateway
QueueByte(MPU401_VERSION);
QueueByte(MSG_MPU_ACK);
} else {
QueueByte(MSG_MPU_ACK);
QueueByte(MPU401_VERSION);
}
QueueByte(MSG_MPU_ACK);
QueueByte(MPU401_VERSION);
goto write_command_return;
case 0xad: /* Request revision */
QueueByte(MSG_MPU_ACK);
Expand Down Expand Up @@ -388,18 +376,6 @@ __force_inline void MPU401_WriteData(Bit8u val, bool crit) { /* SOFTMPU */
static Bit8u length,cnt,posd; /* SOFTMPU */
if (mpu.mode==M_UART) {
MIDI_RawOutByte(val);
// autodetect when Gateway runs
if (val == gateway_msg[gateway_pos]) {
// printf("v: %x (%c)\n", val, val);
++gateway_pos;
if (gateway_pos == gateway_len) {
// printf("Gateway hack enabled!");
config_versionfix = true;
gateway_pos = 0;
}
} else {
gateway_pos = 0;
}
goto write_return;
}
switch (mpu.state.command_byte) { /* 0xe# command data */
Expand Down Expand Up @@ -759,7 +735,6 @@ void MPU401_Init(bool delaysysex, bool fakeallnotesoff)
{
config_delaysysex = delaysysex;
config_fakeallnotesoff = fakeallnotesoff;
config_versionfix = false;
if (!critical_section_is_initialized(&mpu_crit)) {
critical_section_init(&mpu_crit);
}
Expand Down

0 comments on commit a3df9cd

Please sign in to comment.