Skip to content

Commit

Permalink
- Consolidate into a single EXI callback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Apr 8, 2024
1 parent 2936e0d commit 0f9e3c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
45 changes: 26 additions & 19 deletions cube/patches/bba/bba.c
Expand Up @@ -31,12 +31,13 @@
#include "ipl.h"

static struct {
bool lock;
bool locked;
uint8_t rwp;
uint8_t rrp;
bba_page_t (*page)[8];
ppc_context_t *entry;
ppc_context_t *exit;
void (*callback)(void);
} _bba;

static struct {
Expand All @@ -46,6 +47,8 @@ static struct {
bool read, patch;
} dvd;

static void exi_callback();

#include "tcpip.c"

static void exi_clear_interrupts(int32_t chan, bool exi, bool tc, bool ext)
Expand Down Expand Up @@ -156,10 +159,10 @@ void bba_ins(uint16_t reg, void *val, uint32_t len)
exi_clear_interrupts(EXI_CHANNEL_0, false, true, false);
exi_dma_read(val, len, false);

_bba.lock = false;
_bba.locked = false;
if (!setjmp(_bba.entry))
longjmp(_bba.exit, 1);
_bba.lock = true;
_bba.locked = true;

exi_deselect();
}
Expand All @@ -168,22 +171,21 @@ void bba_outs(uint16_t reg, const void *val, uint32_t len)
{
exi_select();
exi_imm_read_write(0xC0 << 24 | reg << 8, 4);

if (!_bba.lock) {
#ifdef ETH_EMULATOR
#ifdef ETH_EMULATOR
if (!_bba.locked) {
exi_immex_write(val, len);
#else
exi_dma_write(val, len, true);
#endif
} else {
exi_clear_interrupts(EXI_CHANNEL_0, false, true, false);
exi_dma_write(val, len, false);

_bba.lock = false;
if (!setjmp(_bba.entry))
longjmp(_bba.exit, 1);
_bba.lock = true;
exi_deselect();
return;
}
#endif

exi_clear_interrupts(EXI_CHANNEL_0, false, true, false);
exi_dma_write(val, len, false);

_bba.locked = false;
if (!setjmp(_bba.entry))
longjmp(_bba.exit, 1);
_bba.locked = true;

exi_deselect();
}
Expand Down Expand Up @@ -252,11 +254,16 @@ static void exi_callback()
static void exi_coroutine()
{
if (EXILock(EXI_CHANNEL_0, EXI_DEVICE_2, exi_callback)) {
_bba.lock = true;
_bba.locked = true;

set_interrupt_handler(OS_INTERRUPT_EXI_0_TC, exi_callback);
unmask_interrupts(OS_INTERRUPTMASK_EXI_0_TC);

if (_bba.callback) {
_bba.callback();
_bba.callback = NULL;
}

uint8_t status = bba_cmd_in8(0x03);
bba_cmd_out8(0x02, BBA_CMD_IRMASKALL);

Expand All @@ -267,7 +274,7 @@ static void exi_coroutine()

mask_interrupts(OS_INTERRUPTMASK_EXI_0_TC);

_bba.lock = false;
_bba.locked = false;
EXIUnlock(EXI_CHANNEL_0);
}

Expand Down
9 changes: 6 additions & 3 deletions cube/patches/bba/tcpip.c
Expand Up @@ -230,8 +230,13 @@ static void fsp_get_file(uint32_t offset, uint32_t length, const char *path, uin

static void fsp_read_queued(void)
{
if (!_bba.lock && !EXILock(EXI_CHANNEL_0, EXI_DEVICE_2, (EXICallback)fsp_read_queued))
if (!_bba.locked) {
if (!_bba.callback) {
_bba.callback = fsp_read_queued;
exi_callback();
}
return;
}

void *buffer = _fsp.queued->buffer + _fsp.queued->offset;
uint32_t length = _fsp.queued->length - _fsp.queued->offset;
Expand All @@ -242,8 +247,6 @@ static void fsp_read_queued(void)
fsp_get_file(offset, length, path, pathlen);

OSSetAlarm(&read_alarm, OSSecondsToTicks(1), (OSAlarmHandler)fsp_read_queued);

if (!_bba.lock) EXIUnlock(EXI_CHANNEL_0);
}

static void fsp_pop_queue(void)
Expand Down

0 comments on commit 0f9e3c7

Please sign in to comment.