static void write32_GCDATAIN(u32 val) { nds_dscard& card = MMU.dscard[0]; //bool log=false; memcpy(&card.command[0], &MMU.MMU_MEM[0][0x40][0x1A8], 8); //last_write_count = write_count; if(card.command[4]) { // transfer is done T1WriteLong(MMU.MMU_MEM[0][0x40], 0x1A4,val & 0x7F7FFFFF); // if needed, throw irq for the end of transfer if(MMU.AUX_SPI_CNT & 0x4000) NDS_makeIrq(ARMCPU_ARM9, IRQ_BIT_GC_TRANSFER_COMPLETE); return; } switch(card.command[0]) { case 0xBB: { if(write_count && write_enabled) { fwrite(&val, 1, 4, img); fflush(img); write_count--; } break; } default: break; } if(write_count==0) { write_enabled = 0; // transfer is done T1WriteLong(MMU.MMU_MEM[0][0x40], 0x1A4,val & 0x7F7FFFFF); // if needed, throw irq for the end of transfer if(MMU.AUX_SPI_CNT & 0x4000) NDS_makeIrq(ARMCPU_ARM9, IRQ_BIT_GC_TRANSFER_COMPLETE); } /*if(log) { INFO("WRITE CARD command: %02X%02X%02X%02X%02X%02X%02X%02X\t", card.command[0], card.command[1], card.command[2], card.command[3], card.command[4], card.command[5], card.command[6], card.command[7]); INFO("FROM: %08X\t", NDS_ARM9.instruct_adr); INFO("VAL: %08X\n", val); }*/ }
void IPC_FIFOcnt(u8 proc, u16 val) { u8 proc_remote = proc ^ 1; u16 cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184); u16 cnt_r = T1ReadWord(MMU.MMU_MEM[proc^1][0x40], 0x184); if (val & IPCFIFOCNT_FIFOERROR) { //at least SPP uses this, maybe every retail game cnt_l &= ~IPCFIFOCNT_FIFOERROR; } if (val & IPCFIFOCNT_SENDCLEAR) { ipc_fifo[proc].head = 0; ipc_fifo[proc].tail = 0; ipc_fifo[proc].size = 0; cnt_l |= IPCFIFOCNT_SENDEMPTY; cnt_r |= IPCFIFOCNT_RECVEMPTY; cnt_l &= ~IPCFIFOCNT_SENDFULL; cnt_r &= ~IPCFIFOCNT_RECVFULL; } cnt_l &= ~IPCFIFOCNT_WRITEABLE; cnt_l |= val & IPCFIFOCNT_WRITEABLE; //IPCFIFOCNT_SENDIRQEN may have been set (and/or the fifo may have been cleared) so we may need to trigger this irq //(this approach is used by libnds fifo system on occasion in fifoInternalSend, and began happening frequently for value32 with r4326) if(cnt_l&IPCFIFOCNT_SENDIRQEN) if(cnt_l & IPCFIFOCNT_SENDEMPTY) NDS_makeIrq(proc, IRQ_BIT_IPCFIFO_SENDEMPTY); //IPCFIFOCNT_RECVIRQEN may have been set so we may need to trigger this irq if(cnt_l&IPCFIFOCNT_RECVIRQEN) if(!(cnt_l & IPCFIFOCNT_RECVEMPTY)) NDS_makeIrq(proc, IRQ_BIT_IPCFIFO_RECVNONEMPTY); T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l); T1WriteWord(MMU.MMU_MEM[proc^1][0x40], 0x184, cnt_r); NDS_Reschedule(); }
u32 IPC_FIFOrecv(u8 proc) { u16 cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184); if (!(cnt_l & IPCFIFOCNT_FIFOENABLE)) return (0); // FIFO disabled u8 proc_remote = proc ^ 1; u32 val = 0; if ( ipc_fifo[proc_remote].size == 0 ) // remote FIFO error { cnt_l |= IPCFIFOCNT_FIFOERROR; T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l); return (0); } u16 cnt_r = T1ReadWord(MMU.MMU_MEM[proc_remote][0x40], 0x184); cnt_l &= 0xBCFF; // clear send full bit & empty cnt_r &= 0xBFFC; // set recv full bit & empty val = ipc_fifo[proc_remote].buf[ipc_fifo[proc_remote].head]; ipc_fifo[proc_remote].head++; ipc_fifo[proc_remote].size--; if (ipc_fifo[proc_remote].head > 15) ipc_fifo[proc_remote].head = 0; //LOG("IPC%s recv FIFO 0x%08X size %03i (l 0x%X, tail %02i) (r 0x%X, tail %02i)\n", // proc?"7":"9", val, ipc_fifo[proc].size, cnt_l, ipc_fifo[proc].tail, cnt_r, ipc_fifo[proc^1].tail); if ( ipc_fifo[proc_remote].size == 0 ) // FIFO empty { cnt_l |= IPCFIFOCNT_RECVEMPTY; cnt_r |= IPCFIFOCNT_SENDEMPTY; if(cnt_r&IPCFIFOCNT_SENDIRQEN) NDS_makeIrq(proc_remote, IRQ_BIT_IPCFIFO_SENDEMPTY); } T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l); T1WriteWord(MMU.MMU_MEM[proc_remote][0x40], 0x184, cnt_r); NDS_Reschedule(); return (val); }
void IPC_FIFOsend(u8 proc, u32 val) { u16 cnt_l = T1ReadWord(MMU.MMU_MEM[proc][0x40], 0x184); if (!(cnt_l & IPCFIFOCNT_FIFOENABLE)) return; // FIFO disabled u8 proc_remote = proc ^ 1; if (ipc_fifo[proc].size > 15) { cnt_l |= IPCFIFOCNT_FIFOERROR; T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l); return; } u16 cnt_r = T1ReadWord(MMU.MMU_MEM[proc_remote][0x40], 0x184); //LOG("IPC%s send FIFO 0x%08X size %03i (l 0x%X, tail %02i) (r 0x%X, tail %02i)\n", // proc?"7":"9", val, ipc_fifo[proc].size, cnt_l, ipc_fifo[proc].tail, cnt_r, ipc_fifo[proc^1].tail); cnt_l &= 0xBFFC; // clear send empty bit & full cnt_r &= 0xBCFF; // set recv empty bit & full ipc_fifo[proc].buf[ipc_fifo[proc].tail] = val; ipc_fifo[proc].tail++; ipc_fifo[proc].size++; if (ipc_fifo[proc].tail > 15) ipc_fifo[proc].tail = 0; if (ipc_fifo[proc].size > 15) { cnt_l |= IPCFIFOCNT_SENDFULL; // set send full bit cnt_r |= IPCFIFOCNT_RECVFULL; // set recv full bit } T1WriteWord(MMU.MMU_MEM[proc][0x40], 0x184, cnt_l); T1WriteWord(MMU.MMU_MEM[proc_remote][0x40], 0x184, cnt_r); if(cnt_r&IPCFIFOCNT_RECVIRQEN) NDS_makeIrq(proc_remote, IRQ_BIT_IPCFIFO_RECVNONEMPTY); NDS_Reschedule(); }