Skip to content

Commit

Permalink
[isoldr] Fixed CDDA loops and improved DMA hiding.
Browse files Browse the repository at this point in the history
  • Loading branch information
DC-SWAT committed Jan 15, 2023
1 parent 5c0bbfb commit 2d06158
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 35 deletions.
2 changes: 1 addition & 1 deletion firmware/isoldr/loader/Makefile.cfg
Expand Up @@ -32,7 +32,7 @@ TARGETLDFLAGS = -Wl,--gc-sections -Tshlelf.xc -nostartfiles -nostdlib -nodefault
TARGETCFLAGS = -ml -m4-single-only -ffunction-sections -fdata-sections -ffreestanding \
-fno-builtin -fno-strict-aliasing -fomit-frame-pointer \
-Wall -std=c11 -Wextra -Werror \
-DVERSION=\"0.8.0.Beta.9\" -DLOADER_ADDR=$(TARGET)
-DVERSION=\"0.8.0.Beta.10\" -DLOADER_ADDR=$(TARGET)

LIBS = -lgcc
INSTALL_PATH = ../../../build/firmware/isoldr
Expand Down
4 changes: 4 additions & 0 deletions firmware/isoldr/loader/asic.c
Expand Up @@ -13,6 +13,7 @@
#ifdef NO_ASIC_LT
void* g1_dma_handler(void *passer, register_stack *stack, void *current_vector);
void* maple_dma_handler(void *passer, register_stack *stack, void *current_vector);
void* aica_dma_handler(void *passer, register_stack *stack, void *current_vector);
#endif

static asic_lookup_table asic_table;
Expand Down Expand Up @@ -59,6 +60,9 @@ static void* asic_handle_exception(register_stack *stack, void *current_vector)
if (code == EXP_CODE_INT13 || code == EXP_CODE_INT11 || code == EXP_CODE_INT9) {

# ifdef HAVE_CDDA
if(status & ASIC_NRM_AICA_DMA && code == EXP_CODE_INT11) {
back_vector = aica_dma_handler(NULL, stack, back_vector);
}
CDDA_MainLoop();
# endif
if (status & ASIC_NRM_VSYNC) {
Expand Down
68 changes: 53 additions & 15 deletions firmware/isoldr/loader/cdda.c
Expand Up @@ -118,7 +118,7 @@ static void aica_dma_irq_disable() {
*ASIC_IRQ13_MASK &= ~ASIC_NRM_AICA_DMA;

} else {
cdda->irq_index = 0;
cdda->irq_index = (uint32)-1;
}
}

Expand Down Expand Up @@ -254,6 +254,10 @@ static void setup_pcm_buffer() {
if(exception_inited()) {
cdda->size = 0x4000;
cdda->end_tm = 36176 / cdda->chn;
#ifdef LOG
cdda->size >>= 1;
cdda->end_tm >>= 1;
#endif
}
break;
}
Expand All @@ -267,10 +271,12 @@ static void setup_pcm_buffer() {
cdda->alloc_buff = malloc(cdda->size + 32);
}

if (cdda->alloc_buff) {
cdda->buff[0] = (uint8 *)ALIGN32_ADDR((uint32)cdda->alloc_buff);
if (cdda->alloc_buff == NULL) {
LOGFF("Failed malloc");
return;
}

cdda->buff[0] = (uint8 *)ALIGN32_ADDR((uint32)cdda->alloc_buff);
cdda->buff[1] = cdda->buff[0] + (cdda->size >> 1);

/* Setup buffer at end of sound memory */
Expand Down Expand Up @@ -682,8 +688,24 @@ static uint32 sector_align(uint32 offset) {
}


#if defined(HAVE_EXPT) && !defined(NO_ASIC_LT)
#ifdef HAVE_EXPT

void *aica_dma_handler(void *passer, register_stack *stack, void *current_vector) {

(void)passer;
(void)stack;

if (cdda->irq_index == 0) {
return current_vector;
}

ASIC_IRQ_STATUS[ASIC_MASK_NRM_INT] = ASIC_NRM_AICA_DMA;
return my_exception_finish;
}

# ifndef NO_ASIC_LT
static asic_handler_f old_vsync_handler;
static asic_handler_f old_dma_handler;
static void *vsync_handler(void *passer, register_stack *stack, void *current_vector) {

if(old_vsync_handler) {
Expand All @@ -693,6 +715,15 @@ static void *vsync_handler(void *passer, register_stack *stack, void *current_ve
CDDA_MainLoop();
return current_vector;
}
static void *dma_handler(void *passer, register_stack *stack, void *current_vector) {

if(old_dma_handler) {
current_vector = old_dma_handler(passer, stack, current_vector);
}

return aica_dma_handler(passer, stack, current_vector);
}
# endif
#endif

int CDDA_Init() {
Expand All @@ -719,14 +750,21 @@ int CDDA_Init() {
#endif

#if defined(HAVE_EXPT) && !defined(NO_ASIC_LT)
asic_lookup_table_entry a_entry;
memset(&a_entry, 0, sizeof(a_entry));

a_entry.irq = EXP_CODE_ALL;
a_entry.mask[ASIC_MASK_NRM_INT] = ASIC_NRM_VSYNC;
a_entry.handler = vsync_handler;
asic_lookup_table_entry vsync_entry, dma_entry;

memset(&vsync_entry, 0, sizeof(vsync_entry));
memset(&dma_entry, 0, sizeof(dma_entry));

return asic_add_handler(&a_entry, &old_vsync_handler, 0);
dma_entry.irq = EXP_CODE_ALL;
dma_entry.mask[ASIC_MASK_NRM_INT] = ASIC_NRM_AICA_DMA;
dma_entry.handler = dma_handler;
asic_add_handler(&dma_entry, NULL, 0);

vsync_entry.irq = EXP_CODE_ALL;
vsync_entry.mask[ASIC_MASK_NRM_INT] = ASIC_NRM_VSYNC;
vsync_entry.handler = vsync_handler;

return asic_add_handler(&vsync_entry, &old_vsync_handler, 0);
#else
return 0;
#endif
Expand Down Expand Up @@ -1084,7 +1122,7 @@ static void fill_pcm_buff() {
return;
}

DBGFF("0x%08lx at %ld\n", (uint32)cdda->buff[PCM_TMP_BUFF], cdda->cur_offset);
DBGFF("%ld %ld\n", cdda->cur_offset, cdda->track_size - cdda->cur_offset);

/* Reading data for all channels */
#ifdef _FS_ASYNC
Expand Down Expand Up @@ -1114,7 +1152,7 @@ void CDDA_MainLoop(void) {
if(cdda->stat == CDDA_STAT_WAIT) {
/* Polling async data transfer */
#if defined(DEV_TYPE_IDE) || defined(DEV_TYPE_GD)
if(!exception_inited())
if(!exception_inited() || !pre_read_xfer_busy())
#endif
{
if(poll(cdda->fd) < 0) {
Expand All @@ -1139,9 +1177,9 @@ void CDDA_MainLoop(void) {

/* Split PCM data to left and right channels */
if(cdda->stat == CDDA_STAT_PREP) {

aica_check_cdda();

if(!aica_transfer_in_progress()) {

if(cdda->irq_index) {
Expand Down
36 changes: 17 additions & 19 deletions firmware/isoldr/loader/dev/ide/ide.c
Expand Up @@ -213,18 +213,10 @@ void *g1_dma_handler(void *passer, register_stack *stack, void *current_vector)
(void)stack;

if ((statusErr & ASIC_ERR_G1DMA_ILLEGAL) || (statusErr & ASIC_ERR_G1DMA_OVERRUN) || (statusErr & ASIC_ERR_G1DMA_ROM_FLASH)) {
LOGF("ASIC_ERR_G1DMA: 0x%08lx %d\n", statusErr, g1_dma_irq_visible);
LOGFF("ERROR 0x%08lx %d\n", statusErr, g1_dma_irq_visible);
ASIC_IRQ_STATUS[ASIC_MASK_ERR_INT] = ASIC_ERR_G1DMA_ROM_FLASH | ASIC_ERR_G1DMA_ILLEGAL | ASIC_ERR_G1DMA_OVERRUN;
}

if (statusExt & ASIC_EXT_GD_CMD) {
DBGF("ASIC_EXT_GD_CMD: 0x%08lx %d\n", statusExt, g1_dma_irq_visible);

if (!g1_dma_irq_visible) {
g1_ata_ack_irq();
}
}

uint32 g1_dma_irq_idx = (g1_dma_irq_visible ? g1_dma_irq_idx_game : g1_dma_irq_idx_internal);

if ((g1_dma_irq_idx == 13 && code != EXP_CODE_INT13) ||
Expand All @@ -233,27 +225,33 @@ void *g1_dma_handler(void *passer, register_stack *stack, void *current_vector)
) {
return current_vector;
}

#ifdef DEBUG
LOGFF("IRQ: %08lx NRM: 0x%08lx EXT: 0x%08lx ERR: 0x%08lx, VISIBLE: %d\n",
DBGFF("IRQ: %08lx NRM: 0x%08lx EXT: 0x%08lx ERR: 0x%08lx, VISIBLE: %d\n",
*REG_INTEVT, status, statusExt, statusErr, g1_dma_irq_visible);
// dump_regs(stack);
#else
LOGFF("%08lx 0x%08lx %d 0x%08lx\n", *REG_INTEVT, status, g1_dma_irq_visible, (uint32)r15());
// LOGFF("%08lx 0x%08lx 0x%02lx %d 0x%08lx\n",
// *REG_INTEVT, status, statusExt, g1_dma_irq_visible, (uint32)r15());
#endif


if (statusExt & ASIC_EXT_GD_CMD) {
if (g1_dma_irq_visible == 0) {
g1_ata_ack_irq();
}
}
if (status & ASIC_NRM_GD_DMA) {
/* Processing filesystem */
poll_all();

if (g1_dma_irq_visible) {
return current_vector;
if (g1_dma_irq_visible == 0) {
/* Ack DMA IRQ. */
ASIC_IRQ_STATUS[ASIC_MASK_NRM_INT] = ASIC_NRM_GD_DMA;
}
/* Ack DMA IRQ. */
ASIC_IRQ_STATUS[ASIC_MASK_NRM_INT] = ASIC_NRM_GD_DMA;
}

if (g1_dma_irq_visible) {
return current_vector;
}
return my_exception_finish;
}

Expand Down Expand Up @@ -283,8 +281,8 @@ s32 g1_dma_init_irq() {
#endif

void g1_dma_abort(void) {
OUT8(G1_ATA_DMA_ENABLE, 0);
if (g1_dma_in_progress()) {
OUT8(G1_ATA_DMA_ENABLE, 0);
g1_ata_wait_dma();
g1_ata_wait_bsydrq();
}
Expand Down

0 comments on commit 2d06158

Please sign in to comment.