Skip to content

Commit

Permalink
- Enable patches on FSP server.
Browse files Browse the repository at this point in the history
- Add streaming audio emulation for FSP.
  • Loading branch information
Extrems committed Mar 15, 2022
1 parent d1a0402 commit 1a10861
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 45 deletions.
21 changes: 20 additions & 1 deletion cube/patches/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ideexipatch: ideexi-v1.bin ideexi-v1.card.bin ideexi-v1.dtk.bin ideexi-v2.bin id
dvdpatch: dvd.bin dvd.card.bin
usbgeckopatch: usbgecko.bin
wkfpatch: wkf.bin wkf.card.bin wkf.dtk.bin
fsppatch: fsp.bin
fsppatch: fsp.bin fsp.dtk.bin
gcloaderpatch: gcloader-v1.bin gcloader-v1.card.bin gcloader-v2.bin gcloader-v2.card.bin

clean:
Expand Down Expand Up @@ -384,6 +384,25 @@ fsp.bin:
@$(BIN2S) fsp.bin > $(DEST)/FSPPatch.s
@rm -f *.bin *.elf *.o

fsp.dtk.bin:
@echo Building FSP Patch + DTK ...
@$(CC) -Os $(OPTS) -c base/base.S
@$(CC) -Os $(OPTS) -c base/emulator.c -DASYNC_READ -DBBA -DDTK
@$(CC) -Os $(OPTS) -c base/audio.c
@$(CC) -Os $(OPTS) -c base/fifo.c
@$(CC) -Os $(OPTS) -c base/frag.c -DDEVICE_PATCHES=1
@$(CC) -Os $(OPTS) -c base/igr.c
@$(CC) -Os $(OPTS) -c bba/bba.c -DASYNC_READ -DQUEUE_SIZE=3
@$(CC) -Os $(OPTS) -c usbgecko/uart.c
@$(CC) -Os $(OPTS) -c base/dolphin/os.c
@$(CC) -Os $(OPTS) -c base/setjmp.S
@$(CC) -Os $(OPTS) -o fsp.dtk.elf -T base/base.ld -T base/common.ld -T base/dolphin/os.ld base.o emulator.o audio.o fifo.o frag.o igr.o bba.o uart.o os.o setjmp.o
@mkdir -p $(DISASM)
@$(OBJDUMP) -D fsp.dtk.elf > $(DISASM)/fsp.dtk.txt
@$(OBJCOPY) -O binary fsp.dtk.elf fsp.dtk.bin
@$(BIN2S) fsp.dtk.bin > $(DEST)/FSPPatch.dtk.s
@rm -f *.bin *.elf *.o

gcloader-v1.bin:
@echo Building GCLoader-v1 Patch ...
@$(CC) -Os $(OPTS) -c base/base.S
Expand Down
18 changes: 18 additions & 0 deletions cube/patches/base/frag.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@
#define DEVICE_PATCHES DEVICE_DISC
#endif

__attribute((weak))
bool do_read_write_async(void *buffer, uint32_t length, uint32_t offset, uint64_t sector, bool write, frag_callback callback)
{
return false;
}

__attribute((weak))
int do_read_write(void *buffer, uint32_t length, uint32_t offset, uint64_t sector, bool write)
{
return 0;
}

__attribute((weak))
void end_read(void)
{
return;
}

static bool frag_get(int file, uint32_t offset, size_t size, frag_t *frag)
{
const frag_t *frags = *(frag_t **)VAR_FRAG_LIST;
Expand Down
30 changes: 22 additions & 8 deletions cube/patches/bba/tcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,26 @@ static void fsp_read_queued(void)
if (!_bba.lock) EXIUnlock(EXI_CHANNEL_0);
}

static void fsp_pop_queue(void)
{
#if QUEUE_SIZE > 2
for (int i = 0; i < QUEUE_SIZE; i++) {
if (_fsp.queue[i].callback != NULL && _fsp.queue[i].length + _fsp.queue[i].position % 512 <= 512) {
_fsp.queued = &_fsp.queue[i];
fsp_read_queued();
return;
}
}
#endif
for (int i = 0; i < QUEUE_SIZE; i++) {
if (_fsp.queue[i].callback != NULL) {
_fsp.queued = &_fsp.queue[i];
fsp_read_queued();
return;
}
}
}

static void fsp_done_queued(void)
{
void *buffer = _fsp.queued->buffer;
Expand All @@ -256,13 +276,7 @@ static void fsp_done_queued(void)
_fsp.queued->callback = NULL;
_fsp.queued = NULL;

for (int i = 0; i < QUEUE_SIZE; i++) {
if (_fsp.queue[i].callback != NULL) {
_fsp.queued = &_fsp.queue[i];
fsp_read_queued();
return;
}
}
fsp_pop_queue();
}

bool do_read_disc(void *buffer, uint32_t length, uint32_t offset, const frag_t *frag, frag_callback callback)
Expand Down Expand Up @@ -317,7 +331,7 @@ static void fsp_input(bba_page_t *page, eth_header_t *eth, ipv4_header_t *ipv4,
_fsp.queued->offset += data_size;

if (_fsp.queued->offset != _fsp.queued->length)
fsp_read_queued();
fsp_pop_queue();

bba_receive_dma(page[1], data_size - page_size);
memcpy(data, fsp->data, data_size);
Expand Down
7 changes: 0 additions & 7 deletions cube/patches/gcloader/gcloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,6 @@ bool do_read_disc(void *buffer, uint32_t length, uint32_t offset, const frag_t *
return gcode_push_queue(buffer, length, offset >> 2, frag->sector, DI_CMD_SEEK << 24, callback);
}

int do_read_write(void *buffer, uint32_t length, uint32_t offset, uint64_t sector, bool write)
{
return 0;
}

void end_read(void) {}

void schedule_read(OSTick ticks)
{
void read_callback(void *address, uint32_t length)
Expand Down
7 changes: 0 additions & 7 deletions cube/patches/ide-exi/ata.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,6 @@ bool do_read_write_async(void *buffer, uint32_t length, uint32_t offset, uint64_

return false;
}
#else
bool do_read_write_async(void *buffer, uint32_t length, uint32_t offset, uint64_t sector, bool write, frag_callback callback)
{
return false;
}
#endif

int do_read_write(void *buf, u32 len, u32 offset, u64 sectorLba, bool write) {
Expand Down Expand Up @@ -533,5 +528,3 @@ int do_read_write(void *buf, u32 len, u32 offset, u64 sectorLba, bool write) {
ata.count--;
return numBytes;
}

void end_read() {}
5 changes: 0 additions & 5 deletions cube/patches/sdgecko/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ bool do_read_write_async(void *buffer, uint32_t length, uint32_t offset, uint64_

return false;
}
#else
bool do_read_write_async(void *buffer, uint32_t length, uint32_t offset, uint64_t sector, bool write, frag_callback callback)
{
return false;
}
#endif

int do_read_write(void *buf, u32 len, u32 offset, u64 sectorLba, bool write) {
Expand Down
2 changes: 2 additions & 0 deletions cube/swiss/include/patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ extern u8 dvd_card_bin[];
extern u32 dvd_card_bin_size;
extern u8 fsp_bin[];
extern u32 fsp_bin_size;
extern u8 fsp_dtk_bin[];
extern u32 fsp_dtk_bin_size;
extern u8 gcloader_v1_bin[];
extern u32 gcloader_v1_bin_size;
extern u8 gcloader_v1_card_bin[];
Expand Down
39 changes: 29 additions & 10 deletions cube/swiss/source/devices/fsp/deviceHandler-FSP.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ s32 deviceHandler_FSP_setupFile(file_handle* file, file_handle* file2, int numTo
devices[DEVICE_PATCHES]->closeFile(&patchFile);
}

// Card Type
*(vu8*)VAR_SD_SHIFT = (u8)(sdgecko_getAddressingType(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2)) ? 9:0);
// Copy the actual freq
*(vu8*)VAR_EXI_FREQ = (u8)(sdgecko_getSpeed(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2)));
// Device slot (0, 1 or 2)
*(vu8*)VAR_EXI_SLOT = (u8)(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2));
*(vu32**)VAR_EXI_REGS = ((vu32(*)[5])0xCC006800)[*(vu8*)VAR_EXI_SLOT];
if(devices[DEVICE_PATCHES] != devices[DEVICE_CUR]) {
// Card Type
*(vu8*)VAR_SD_SHIFT = (u8)(sdgecko_getAddressingType(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2)) ? 9:0);
// Copy the actual freq
*(vu8*)VAR_EXI_FREQ = (u8)(sdgecko_getSpeed(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2)));
// Device slot (0, 1 or 2)
*(vu8*)VAR_EXI_SLOT = (u8)(devices[DEVICE_PATCHES] == &__device_sd_a ? EXI_CHANNEL_0:(devices[DEVICE_PATCHES] == &__device_sd_b ? EXI_CHANNEL_1:EXI_CHANNEL_2));
*(vu32**)VAR_EXI_REGS = ((vu32(*)[5])0xCC006800)[*(vu8*)VAR_EXI_SLOT];
}
}

if(!getFragments(DEVICE_CUR, file, &fragList, &numFrags, FRAGS_DISC_1, 0, 0)) {
Expand Down Expand Up @@ -238,6 +240,7 @@ s32 deviceHandler_FSP_init(file_handle* file) {
DrawDispose(msgBox);
return 0;
}

fsp_session = fsp_open_session(swissSettings.fspHostIp, swissSettings.fspPort, swissSettings.fspPassword);
if(!fsp_session) {
uiDrawObj_t *msgBox = DrawMessageBox(D_FAIL, "Check FSP Configuration");
Expand All @@ -246,6 +249,19 @@ s32 deviceHandler_FSP_init(file_handle* file) {
DrawDispose(msgBox);
return 0;
}

u8 dirpro;
if(fsp_getpro(fsp_session, "swiss/patches", &dirpro) &&
fsp_getpro(fsp_session, "swiss", &dirpro) &&
fsp_getpro(fsp_session, "", &dirpro))
dirpro = 0;

if((dirpro & (FSP_DIR_MKDIR|FSP_DIR_ADD|FSP_DIR_DEL|FSP_DIR_GET)) == (FSP_DIR_MKDIR|FSP_DIR_ADD|FSP_DIR_DEL) ||
(dirpro & FSP_DIR_OWNER))
__device_fsp.features |= FEAT_PATCHES;
else
__device_fsp.features &= ~FEAT_PATCHES;

return 1;
}

Expand Down Expand Up @@ -289,7 +305,10 @@ bool deviceHandler_FSP_test() {
}

u32 deviceHandler_FSP_emulated() {
return EMU_READ;
if (swissSettings.audioStreaming)
return EMU_READ|EMU_AUDIO_STREAMING;
else
return EMU_READ;
}

DEVICEHANDLER_INTERFACE __device_fsp = {
Expand All @@ -298,8 +317,8 @@ DEVICEHANDLER_INTERFACE __device_fsp = {
"File Service Protocol",
"Configurable via the settings screen",
{TEX_SAMBA, 140, 64},
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_HYPERVISOR,
EMU_READ,
FEAT_READ|FEAT_WRITE|FEAT_BOOT_GCM|FEAT_HYPERVISOR|FEAT_AUDIO_STREAMING,
EMU_READ|EMU_AUDIO_STREAMING,
LOC_SERIAL_PORT_1,
&initial_FSP,
(_fn_test)&deviceHandler_FSP_test,
Expand Down
29 changes: 22 additions & 7 deletions cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,28 @@ int install_code(int final)
}
// Broadband Adapter
else if(devices[DEVICE_CUR] == &__device_fsp) {
switch (devices[DEVICE_CUR]->emulated()) {
case EMU_READ:
patch = fsp_bin;
patchSize = fsp_bin_size;
break;
default:
return 0;
if (devices[DEVICE_PATCHES] != &__device_fsp) {
switch (devices[DEVICE_CUR]->emulated()) {
case EMU_READ:
patch = fsp_bin;
patchSize = fsp_bin_size;
break;
default:
return 0;
}
} else {
switch (devices[DEVICE_CUR]->emulated()) {
case EMU_READ:
patch = fsp_bin;
patchSize = fsp_bin_size;
break;
case EMU_READ | EMU_AUDIO_STREAMING:
patch = fsp_dtk_bin;
patchSize = fsp_dtk_bin_size;
break;
default:
return 0;
}
}
print_gecko("Installing Patch for File Service Protocol\r\n");
}
Expand Down

0 comments on commit 1a10861

Please sign in to comment.