Refactor events for less jitter

This commit is contained in:
Ian Scott committed 2024-11-25 22:30:09 -07:00
1 parent a972ffaa44
commit d84e4437a4
16 files changed
+99 -173

No files matched your search

-1
View File
@@ -78,7 +78,6 @@ function(config_target TARGET_NAME MULTIFW)
PICO_AUDIO_I2S_DATA_PIN=16
PICO_AUDIO_I2S_CLOCK_PIN_BASE=17
PICO_AUDIO_I2S_PIO=1
USE_ALARM=1
M62429_PIO=1
)
+2 -2
View File
@@ -22,7 +22,7 @@
#ifdef USB_STACK
#include "tusb.h"
#endif
#if (defined(USB_MOUSE) || defined(SOUND_MPU)) && defined(USE_ALARM)
#if defined(USB_MOUSE) || defined(SOUND_MPU)
#include "pico_pic.h"
#endif
@@ -94,7 +94,7 @@ void play_cms() {
puts("starting core 1 CMS");
flash_safe_execute_core_init();
#if (defined(USB_MOUSE) || defined(SOUND_MPU)) && defined(USE_ALARM)
#if defined(USB_MOUSE) || defined(SOUND_MPU)
// Init PIC on this core so it handles timers
PIC_Init();
puts("pic inited on core 1");
+19 -10
View File
@@ -751,7 +751,13 @@ void DEBUG_PrintGUS() { //debugger "GUS" command
static INLINE void GUS_CheckIRQ(void);
static uint32_t GUS_TimerEvent(Bitu val);
static uint32_t GUS_TimerEventHandler(Bitu val);
static PIC_TimerEvent GUS_TimerEvent0 = {
.handler = GUS_TimerEventHandler,
};
static PIC_TimerEvent GUS_TimerEvent1 = {
.handler = GUS_TimerEventHandler,
};
void GUS_StopDMA();
void GUS_StartDMA();
@@ -814,7 +820,8 @@ static void GUSReset(void) {
myGUS.timers[0].running = false;
myGUS.timers[1].running = false;
PIC_RemoveEvents(GUS_TimerEvent);
PIC_RemoveEvent(&GUS_TimerEvent0);
PIC_RemoveEvent(&GUS_TimerEvent1);
// myGUS.fixed_44k_output = false;
@@ -1031,7 +1038,7 @@ __force_inline static uint16_t ExecuteReadRegister(void) {
}
}
static uint32_t GUS_TimerEvent(Bitu val) {
static uint32_t GUS_TimerEventHandler(Bitu val) {
// putchar('-');
critical_section_enter_blocking(&gus_crit);
if (!myGUS.timers[val].masked) myGUS.timers[val].reached=true;
@@ -1374,13 +1381,13 @@ __force_inline void write_gus(Bitu port, Bitu val) {
myGUS.timers[1].masked=(val & 0x20)>0;
if (val & 0x1) {
if (!myGUS.timers[0].running) {
PIC_AddEvent(GUS_TimerEvent,myGUS.timers[0].delay,0);
PIC_AddEvent(&GUS_TimerEvent0, myGUS.timers[0].delay, 0);
myGUS.timers[0].running=true;
}
} else myGUS.timers[0].running=false;
if (val & 0x2) {
if (!myGUS.timers[1].running) {
PIC_AddEvent(GUS_TimerEvent,myGUS.timers[1].delay,1);
PIC_AddEvent(&GUS_TimerEvent1, myGUS.timers[1].delay, 1);
myGUS.timers[1].running=true;
}
} else myGUS.timers[1].running=false;
@@ -1435,7 +1442,7 @@ static bool GUS_DMA_Active = false;
__force_inline
#endif
uint32_t
GUS_DMA_Event(Bitu val) {
GUS_DMA_EventHandler(Bitu val) {
(void)val;//UNUSED
if (!GUS_DMA_Active) {
return 0;
@@ -1465,6 +1472,9 @@ GUS_DMA_Event(Bitu val) {
DMA_Start_Write(&dma_config);
return 0;
}
static PIC_TimerEvent GUS_DMA_Event = {
.handler = GUS_DMA_EventHandler
};
void
GUS_DMA_isr() {
@@ -1518,7 +1528,7 @@ GUS_DMA_isr() {
} else {
++myGUS.dmaAddr;
/* keep going */
PIC_AddEvent(GUS_DMA_Event, myGUS.dmaInterval, 2);
PIC_AddEvent(&GUS_DMA_Event, myGUS.dmaInterval, 0);
}
}
irq_handler_t GUS_DMA_isr_pt = GUS_DMA_isr;
@@ -1550,7 +1560,7 @@ void __force_inline process_dma(void) {
}
uint32_t cur_time = time_us_32();
if (next_event && cur_time >= next_event) {
next_event = cur_time + GUS_DMA_Event(2);
next_event = cur_time + GUS_DMA_Event(0);
}
}
#endif
@@ -1591,8 +1601,7 @@ __force_inline void GUS_StartDMA() {
}
#ifndef POLLING_DMA
// PIC_AddEvent(GUS_DMA_Event, 13, 2);
PIC_AddEvent(GUS_DMA_Event, myGUS.dmaInterval, 2);
PIC_AddEvent(&GUS_DMA_Event, myGUS.dmaInterval, 0);
#else
next_event = time_us_32() + myGUS.dmaInterval;
#endif
-4
View File
@@ -17,9 +17,7 @@
#include "pico/audio_i2s.h"
#include "pico/flash.h"
#ifdef USE_ALARM
#include "pico_pic.h"
#endif
#ifdef USB_STACK
#include "tusb.h"
@@ -92,10 +90,8 @@ void play_gus() {
flash_safe_execute_core_init();
uint32_t start, end;
#ifdef USE_ALARM
// Init PIC on this core so it handles timers
PIC_Init();
#endif
// Init ISA DMA on this core so it handles the ISR
puts("Initing ISA DMA PIO...");
+7 -4
View File
@@ -31,7 +31,10 @@
uart_state_t uart_state;
// forward declarations
static uint32_t uartemu_event(Bitu val);
static uint32_t uartemu_event_handler(Bitu val);
static PIC_TimerEvent uartemu_event = {
.handler = uartemu_event_handler,
};
// initialize emulation
uint32_t uartemu_init(int iobase) {
@@ -71,7 +74,7 @@ uint32_t uartemu_init(int iobase) {
// deinit emulation
uint32_t uartemu_done() {
// remove stale events
PIC_RemoveEvents(uartemu_event);
PIC_RemoveEvent(&uartemu_event);
// deinit critical section
critical_section_deinit(&uart_state.crit);
@@ -126,7 +129,7 @@ static void uartemu_rxdata_advance() {
}
}
static uint32_t uartemu_event(Bitu val) {
static uint32_t uartemu_event_handler(Bitu val) {
// acquire lock
critical_section_enter_blocking(&uart_state.crit);
@@ -172,7 +175,7 @@ static uint32_t uartemu_event(Bitu val) {
static void uartemu_post_event(uint32_t type, uint32_t delay_us) {
// add event
PIC_AddEvent(uartemu_event, delay_us, type);
PIC_AddEvent(&uartemu_event, delay_us, type);
}
// TX message pipe drain
+26 -16
View File
@@ -33,8 +33,6 @@
/* SOFTMPU: Moved exported functions & types to header */
#include "export.h"
extern uint LED_PIN;
/* HardMPU includes */
/*
#include <avr/sfr_defs.h>
@@ -59,10 +57,22 @@ void MIDI_Init(bool delaysysex,bool fakeallnotesoff);
void MIDI_RawOutByte(Bit8u data);
bool MIDI_Available(void);
static uint32_t MPU401_Event(Bitu val);
static uint32_t MPU401_ResetDone(Bitu val);
static uint32_t MPU401_EventHandler(Bitu val);
static PIC_TimerEvent MPU401_Event = {
.handler = MPU401_EventHandler
};
static uint32_t MPU401_ResetDoneHandler(Bitu val);
static PIC_TimerEvent MPU401_ResetDone = {
.handler = MPU401_ResetDoneHandler
};
static uint32_t MPU401_InitHandler(Bitu val);
static PIC_TimerEvent MPU401_InitEvent = {
.handler = MPU401_InitHandler
};
static uint32_t MPU401_EOIHandler(Bitu val);
static PIC_TimerEvent MPU401_EOI = {
.handler = MPU401_EOIHandler
};
static void MPU401_Reset(void);
static void MPU401_EOIHandlerDispatch(void);
@@ -172,7 +182,7 @@ __force_inline void MPU401_WriteCommand(Bit8u val, bool crit) { /* SOFTMPU */
mpu.state.cmd_pending=val+1;
goto write_command_return;
}
PIC_RemoveEvents(MPU401_ResetDone);
PIC_RemoveEvent(&MPU401_ResetDone);
mpu.state.reset=false;
}
if (val<=0x2f) {
@@ -185,7 +195,7 @@ __force_inline void MPU401_WriteCommand(Bit8u val, bool crit) { /* SOFTMPU */
switch (val&0xc) {
case 0x4: /* Stop */
if (mpu.state.playing && !mpu.clock.clock_to_host)
PIC_RemoveEvents(MPU401_Event);
PIC_RemoveEvent(&MPU401_Event);
mpu.state.playing=false;
for (i=0xb0;i<0xbf;i++) { /* All notes off */
MIDI_RawOutByte(i);
@@ -196,7 +206,7 @@ __force_inline void MPU401_WriteCommand(Bit8u val, bool crit) { /* SOFTMPU */
case 0x8: /* Play */
/*LOG(LOG_MISC,LOG_NORMAL)("MPU-401:Intelligent mode playback started");*/ /* SOFTMPU */
if (!mpu.state.playing && !mpu.clock.clock_to_host)
PIC_AddEvent(MPU401_Event,MPU401_TIMECONSTANT/((mpu.clock.tempo*mpu.clock.timebase*mpu.clock.tempo_rel)/0x40), 2);
PIC_AddEvent(&MPU401_Event,MPU401_TIMECONSTANT/((mpu.clock.tempo*mpu.clock.timebase*mpu.clock.tempo_rel)/0x40), 0);
mpu.state.playing=true;
ClrQueue();
break;
@@ -227,12 +237,12 @@ __force_inline void MPU401_WriteCommand(Bit8u val, bool crit) { /* SOFTMPU */
break;
case 0x94: /* Clock to host */
if (mpu.clock.clock_to_host && !mpu.state.playing)
PIC_RemoveEvents(MPU401_Event);
PIC_RemoveEvent(&MPU401_Event);
mpu.clock.clock_to_host=false;
break;
case 0x95:
if (!mpu.clock.clock_to_host && !mpu.state.playing)
PIC_AddEvent(MPU401_Event,MPU401_TIMECONSTANT/((mpu.clock.tempo*mpu.clock.timebase*mpu.clock.tempo_rel)/0x40), 2);
PIC_AddEvent(&MPU401_Event,MPU401_TIMECONSTANT/((mpu.clock.tempo*mpu.clock.timebase*mpu.clock.tempo_rel)/0x40), 0);
mpu.clock.clock_to_host=true;
break;
case 0xc2: /* Internal timebase */
@@ -307,7 +317,7 @@ __force_inline void MPU401_WriteCommand(Bit8u val, bool crit) { /* SOFTMPU */
break;
case 0xff: /* Reset MPU-401 */
/*LOG(LOG_MISC,LOG_NORMAL)("MPU-401:Reset %X",val);*/ /* SOFTMPU */
PIC_AddEvent(MPU401_ResetDone, MPU401_RESETBUSY, 0);
PIC_AddEvent(&MPU401_ResetDone, MPU401_RESETBUSY, 0);
mpu.state.reset=true;
if (mpu.mode==M_UART) {
MPU401_Reset();
@@ -621,7 +631,7 @@ __force_inline static void UpdateConductor(void) {
mpu.state.req_mask|=(1<<9);
}
uint32_t MPU401_Event(Bitu val) {
uint32_t MPU401_EventHandler(Bitu val) {
/* SOFTMPU */
/* putchar('.'); */
Bit8u i;
@@ -656,7 +666,7 @@ next_event:
__force_inline static void MPU401_EOIHandlerDispatch(void) {
if (mpu.state.send_now) {
mpu.state.eoi_scheduled=true;
PIC_AddEvent(MPU401_EOIHandler, 60, 1); // Possible a bit longer
PIC_AddEvent(&MPU401_EOI, 60, 0); // Possible a bit longer
}
else if (!mpu.state.eoi_scheduled) MPU401_EOIHandler(0);
}
@@ -693,7 +703,7 @@ __force_inline uint32_t MPU401_EOIHandler(Bitu val) {
return 0;
}
static uint32_t MPU401_ResetDone(Bitu val) { /* SOFTMPU */
static uint32_t MPU401_ResetDoneHandler(Bitu val) { /* SOFTMPU */
critical_section_enter_blocking(&mpu_crit);
mpu.state.reset=false;
if (mpu.state.cmd_pending) {
@@ -711,8 +721,8 @@ __force_inline static void MPU401_Reset(void) {
PIC_DeActivateIRQ();
#endif
mpu.mode=(mpu.intelligent ? M_INTELLIGENT : M_UART);
PIC_RemoveEvents(MPU401_Event);
PIC_RemoveEvents(MPU401_EOIHandler);
PIC_RemoveEvent(&MPU401_Event);
PIC_RemoveEvent(&MPU401_EOI);
mpu.state.eoi_scheduled=false;
mpu.state.wsd=false;
mpu.state.wsm=false;
@@ -752,7 +762,7 @@ void MPU401_Init(bool delaysysex, bool fakeallnotesoff)
if (!critical_section_is_initialized(&mpu_crit)) {
critical_section_init(&mpu_crit);
}
PIC_AddEvent(MPU401_InitHandler, 1000, 3);
PIC_AddEvent(&MPU401_InitEvent, 1000, 0);
}
uint32_t MPU401_InitHandler(Bitu val)
-4
View File
@@ -5,9 +5,7 @@ extern Settings settings;
#include "pico/flash.h"
#ifdef USE_ALARM
#include "pico_pic.h"
#endif
#ifdef USB_STACK
#include "tusb.h"
@@ -24,11 +22,9 @@ void play_mpu() {
tuh_init(BOARD_TUH_RHPORT);
#endif
#ifdef USE_ALARM
// Init PIC on this core so it handles timers
PIC_Init();
puts("pic inited on core 1");
#endif
MPU401_Init(settings.MPU.delaySysex, settings.MPU.fakeAllNotesOff);
for (;;) {
+1 -1
View File
@@ -159,7 +159,7 @@ void PG_Wifi_Connect(const char* ssid, const char* pass) {
void PG_Wifi_Reconnect(void)
{
int16_t status = cyw43_wifi_link_status(&cyw43_state, CYW43_ITF_STA);
printf("status: %d\n", status);
//printf("status: %d\n", status);
switch(status)
{
case CYW43_LINK_JOIN :
+10 -11
View File
@@ -30,14 +30,23 @@ extern Settings settings;
extern uint LED_PIN;
static uint32_t Wifi_Reconnect_EventHandler(Bitu val) {
PG_Wifi_Reconnect();
return 1000000;
}
static PIC_TimerEvent Wifi_Reconnect_Event = {
.handler = Wifi_Reconnect_EventHandler
};
void play_ne2000() {
//flash_safe_execute_core_init();
puts("starting core 1 ne2000");
PG_EnableWifi();
PG_Wifi_Connect(settings.WiFi.ssid, settings.WiFi.password);
static bool flag = false;
while(1) {
PIC_AddEvent(&Wifi_Reconnect_Event, 1000000, 0);
if (multicore_fifo_rvalid()) {
switch(multicore_fifo_pop_blocking()) {
case FIFO_NE2K_SEND:
@@ -51,15 +60,5 @@ void play_ne2000() {
}
}
/* cyw43_arch_poll(); */
/*
if (((time_us_32() >> 21) & 0x1) == 0x1) {
if (flag == false) {
PG_Wifi_Reconnect();
flag = true;
}
} else {
flag = false;
}
*/
}
}
+4 -42
View File
@@ -9,25 +9,16 @@
// 8250uart has 3
// mpu401 has 3
// SB has 1
PIC_TimerEvent timerEvents[PIC_MAX_TIMERS];
alarm_pool_t* alarm_pool;
int64_t clear_irq(alarm_id_t id, void *user_data) {
gpio_put(IRQ_PIN, 0);
return 0;
}
int64_t PIC_HandleEvent(alarm_id_t id, void *user_data) {
PIC_TimerEvent* event = (PIC_TimerEvent *)user_data;
#ifdef USE_ALARM
if (id != event->alarm_id) {
return 0;
}
#endif
uint32_t ret = (event->handler)(event->value);
// printf("called event handler: %x %x, ret %d\n", event->handler, event->value, ret);
#ifdef USE_ALARM
// gpio_xor_mask(1u << PICO_DEFAULT_LED_PIN);
if (!ret) {
event->alarm_id = 0;
@@ -36,46 +27,17 @@ int64_t PIC_HandleEvent(alarm_id_t id, void *user_data) {
// A negative return value re-sets the alarm from the time when it initially triggered
return -(int64_t)ret;
/* return (int64_t)ret; */
#else
if (ret) {
event->deadline = time_us_32() + ret;
} else {
event->active = false;
}
return 0;
#endif
}
void PIC_RemoveEvents(PIC_EventHandler handler) {
void PIC_RemoveEvent(PIC_TimerEvent* event) {
// puts("removeevents");
for (int i = 0; i < PIC_MAX_TIMERS; ++i) {
if (timerEvents[i].handler == handler) {
#ifdef USE_ALARM
if (timerEvents[i].alarm_id) {
// cancel_alarm(timerEvents[i].alarm_id);
alarm_pool_cancel_alarm(alarm_pool, timerEvents[i].alarm_id);
timerEvents[i].alarm_id = 0;
}
#else
timerEvents[i].active = false;
#endif
}
if (event->alarm_id) {
alarm_pool_cancel_alarm(alarm_pool, event->alarm_id);
event->alarm_id = 0;
}
}
void PIC_Init() {
#ifdef USE_ALARM
alarm_pool = alarm_pool_create(2, PICO_TIME_DEFAULT_ALARM_POOL_MAX_TIMERS);
irq_set_priority(TIMER_IRQ_2, PICO_HIGHEST_IRQ_PRIORITY);
for (int i = 0; i < PIC_MAX_TIMERS; ++i) {
timerEvents[i].alarm_id = 0;
timerEvents[i].handler = 0;
}
#else
for (int i = 0; i < PIC_MAX_TIMERS; ++i) {
timerEvents[i].active = false;
timerEvents[i].deadline = UINT32_MAX;
timerEvents[i].handler = 0;
}
#endif
}
+6 -45
View File
@@ -22,23 +22,13 @@ typedef uint32_t (* PIC_EventHandler)(Bitu val);
typedef struct {
PIC_EventHandler handler;
Bitu value;
#ifdef USE_ALARM
alarm_id_t alarm_id;
#else
uint32_t deadline;
bool active;
#endif
} PIC_TimerEvent;
#define PIC_MAX_TIMERS 8
extern PIC_TimerEvent timerEvents[PIC_MAX_TIMERS];
extern alarm_pool_t* alarm_pool;
int64_t PIC_HandleEvent(alarm_id_t id, void *user_data);
int64_t clear_irq(alarm_id_t id, void *user_data);
static __force_inline void PIC_ActivateIRQ(void) {
// puts("activate irq");
gpio_put(IRQ_PIN, 1);
@@ -51,47 +41,18 @@ static __force_inline void PIC_DeActivateIRQ(void) {
// void PIC_AddEvent(PIC_EventHandler handler, uint32_t delay, Bitu val=0);
static __force_inline void PIC_AddEvent(PIC_EventHandler handler, uint32_t delay, Bitu val) {
// printf("add event: %x %x %d\n", handler, val, delay);
// find free slot - TBD if this is too jittery
int i;
for (i = 0; i < PIC_MAX_TIMERS; ++i) {
if (
#ifdef USE_ALARM
!timerEvents[i].alarm_id
#else
!timerEvents[i].active
#endif
) {
break;
}
}
timerEvents[i].handler = handler;
timerEvents[i].value = val;
#ifdef USE_ALARM
// timerEvents[val].alarm_id = add_alarm_in_us(delay, PIC_HandleEvent, timerEvents + val, true);
// alarm_pool_cancel_alarm(alarm_pool, timerEvents[val].alarm_id);
timerEvents[i].alarm_id = alarm_pool_add_alarm_in_us(alarm_pool, delay, PIC_HandleEvent, timerEvents + i, true);
#else
timerEvents[i].deadline = time_us_32() + delay;
timerEvents[i].active = true;
#endif
static __force_inline void PIC_AddEvent(PIC_TimerEvent* event, uint32_t delay, Bitu val) {
// event->handler = handler;
event->value = val;
// alarm_pool_cancel_alarm(alarm_pool, event->alarm_id);
event->alarm_id = alarm_pool_add_alarm_in_us(alarm_pool, delay, PIC_HandleEvent, event, true);
// gpio_put(PICO_DEFAULT_LED_PIN, 1);
}
void PIC_RemoveEvents(PIC_EventHandler handler);
void PIC_RemoveEvent(PIC_TimerEvent* event);
void PIC_Init(void);
#ifndef USE_ALARM
static __force_inline void PIC_HandleEvents() {
for (int i = 0; i < PIC_MAX_TIMERS; ++i) {
if (timerEvents[i].active && timerEvents[i].deadline <= time_us_32()) {
PIC_HandleEvent(0, &timerEvents[i]);
}
}
}
#endif
#ifdef __cplusplus
}
-11
View File
@@ -837,10 +837,6 @@ void err_blink(void) {
}
}
#ifndef USE_ALARM
#include "pico_pic.h"
#endif
constexpr uint32_t rp2_clock = RP2_CLOCK_SPEED;
constexpr float psram_clkdiv = (float)rp2_clock / 200000.0;
constexpr float pwm_clkdiv = (float)rp2_clock / 22727.27;
@@ -1115,10 +1111,6 @@ extern void PIC_DeActivateIRQ(void);
gpio_xor_mask(LED_PIN);
#ifndef USE_ALARM
PIC_Init();
#endif
processSettings();
for (;;) {
@@ -1131,9 +1123,6 @@ extern void PIC_DeActivateIRQ(void);
handle_ior();
}
#endif
#ifndef USE_ALARM
PIC_HandleEvents();
#endif
#ifdef POLLING_DMA
process_dma();
#endif
+22 -12
View File
@@ -11,6 +11,8 @@ Author : Kevin Moonlight <me@yyzkevin.com>
*/
extern uint LED_PIN;
#include "isa_dma.h"
@@ -107,8 +109,6 @@ typedef struct sbdsp_t {
static sbdsp_t sbdsp;
static uint32_t DSP_DMA_Event(Bitu val);
#if 0
uint16_t sbdsp_fifo_level() {
if(sbdsp.dma_buffer_tail < sbdsp.dma_buffer_head) return DSP_DMA_FIFO_SIZE - (sbdsp.dma_buffer_head - sbdsp.dma_buffer_tail);
@@ -148,9 +148,14 @@ uint16_t sbdsp_fifo_tx(char *buffer,uint16_t len) {
}
#endif
static uint32_t DSP_DMA_EventHandler(Bitu val);
static PIC_TimerEvent DSP_DMA_Event = {
.handler = DSP_DMA_EventHandler,
};
static __force_inline void sbdsp_dma_disable() {
sbdsp.dma_enabled=false;
PIC_RemoveEvents(DSP_DMA_Event);
PIC_RemoveEvent(&DSP_DMA_Event);
sbdsp.cur_sample = 0; // zero current sample
}
@@ -158,14 +163,14 @@ static __force_inline void sbdsp_dma_enable() {
if(!sbdsp.dma_enabled) {
// sbdsp_fifo_clear();
sbdsp.dma_enabled=true;
PIC_AddEvent(DSP_DMA_Event,sbdsp.dma_interval,1);
PIC_AddEvent(&DSP_DMA_Event, sbdsp.dma_interval, 0);
}
else {
//printf("INFO: DMA Already Enabled");
}
}
static uint32_t DSP_DMA_Event(Bitu val) {
static uint32_t DSP_DMA_EventHandler(Bitu val) {
DMA_Start_Write(&dma_config);
uint32_t current_interval;
sbdsp.dma_sample_count_rx++;
@@ -192,12 +197,14 @@ static void sbdsp_dma_isr(void) {
sbdsp.cur_sample = (int16_t)(dma_data & 0xFF) - 0x80 << 5;
}
static uint32_t DSP_DAC_Resume_event(Bitu val) {
static uint32_t DSP_DAC_Resume_eventHandler(Bitu val) {
PIC_ActivateIRQ();
sbdsp.dac_resume_pending = false;
PIC_RemoveEvents(DSP_DAC_Resume_event);
return 0;
}
static PIC_TimerEvent DSP_DAC_Resume_event = {
.handler = DSP_DAC_Resume_eventHandler,
};
int16_t sbdsp_sample() {
return (sbdsp.speaker_on & ~sbdsp.dac_resume_pending) ? sbdsp.cur_sample : 0;
@@ -419,7 +426,7 @@ void sbdsp_process(void) {
sbdsp.dac_pause_duration = sbdsp.dac_pause_duration_low + (sbdsp.inbox << 8);
sbdsp.dac_resume_pending = true;
// When the specified duration elapses, the DSP generates an interrupt.
PIC_AddEvent(DSP_DAC_Resume_event, sbdsp.dma_interval * sbdsp.dac_pause_duration, 1);
PIC_AddEvent(&DSP_DAC_Resume_event, sbdsp.dma_interval * sbdsp.dac_pause_duration, 0);
sbdsp.dav_dsp=0;
sbdsp.current_command=0;
//printf("(0x80) Pause Duration:%u\n\r",sbdsp.dac_pause_duration);
@@ -441,7 +448,7 @@ void sbdsp_process(void) {
sbdsp.dsp_busy=0;
}
static uint32_t DSP_Reset_Event(Bitu val) {
static uint32_t DSP_Reset_EventHandler(Bitu val) {
sbdsp.reset_state=0;
sbdsp.outbox = 0xAA;
sbdsp.dav_pc=1;
@@ -455,13 +462,16 @@ static uint32_t DSP_Reset_Event(Bitu val) {
sbdsp.dac_resume_pending = false;
return 0;
}
static PIC_TimerEvent DSP_Reset_Event = {
.handler = DSP_Reset_EventHandler,
};
static __force_inline void sbdsp_reset(uint8_t value) {
//TODO: COLDBOOT ? WARMBOOT ?
value &= 1; // Some games may write unknown data for bits other than the LSB.
switch(value) {
case 1:
PIC_RemoveEvents(DSP_Reset_Event);
PIC_RemoveEvent(&DSP_Reset_Event);
sbdsp.autoinit=0;
sbdsp_dma_disable();
sbdsp.reset_state=1;
@@ -470,8 +480,8 @@ static __force_inline void sbdsp_reset(uint8_t value) {
if(sbdsp.reset_state==1) {
sbdsp.dav_pc=0;
// sbdsp.outbox = 0xAA;
PIC_RemoveEvents(DSP_Reset_Event);
PIC_AddEvent(DSP_Reset_Event, 100, 1);
PIC_RemoveEvent(&DSP_Reset_Event);
PIC_AddEvent(&DSP_Reset_Event, 100, 0);
sbdsp.reset_state = 2;
}
break;
-4
View File
@@ -26,10 +26,8 @@ extern "C" void OPL_Pico_PortWrite(opl_port_t, unsigned int);
extern int16_t sbdsp_sample();
#endif
#if defined(SOUND_SB) || defined(USB_MOUSE) || defined(SOUND_MPU)
#ifdef USE_ALARM
#include "pico_pic.h"
#endif
#endif
#include "clamp.h"
@@ -108,11 +106,9 @@ void play_adlib() {
uint32_t start, end;
#if defined(SOUND_SB) || defined(USB_MOUSE) || defined(SOUND_MPU)
#ifdef USE_ALARM
// Init PIC on this core so it handles timers
PIC_Init();
#endif
#endif
#ifdef USB_STACK
// Init TinyUSB for joystick support
+2 -2
View File
@@ -28,7 +28,7 @@ extern uint LED_PIN;
#ifdef USB_STACK
#include "tusb.h"
#endif
#if (defined(USB_MOUSE) || defined(SOUND_MPU)) && defined(USE_ALARM)
#if defined(USB_MOUSE) || defined(SOUND_MPU)
#include "pico_pic.h"
#endif
@@ -91,7 +91,7 @@ void play_tandy() {
puts("starting core 1 tandy");
flash_safe_execute_core_init();
#if (defined(USB_MOUSE) || defined(SOUND_MPU)) && defined(USE_ALARM)
#if defined(USB_MOUSE) || defined(SOUND_MPU)
// Init PIC on this core so it handles timers
PIC_Init();
puts("pic inited on core 1");
-4
View File
@@ -7,9 +7,7 @@
// #include <string.h>
#ifdef USE_ALARM
#include "pico_pic.h"
#endif
void play_usb() {
puts("starting core 1 USB");
@@ -17,11 +15,9 @@ void play_usb() {
// board_init();
#ifdef USE_ALARM
// Init PIC on this core so it handles timers
PIC_Init();
puts("pic inited on core 1");
#endif
// init host stack on configured roothub port
tuh_init(BOARD_TUH_RHPORT);