better hardware support for odd PI_WR_LEN_REG addresses (cdx pull request #64)

This commit is contained in:
zilmar 2015-02-13 08:26:17 +11:00
parent c973db8e35
commit 17a3561c23
1 changed files with 15 additions and 8 deletions

View File

@ -56,7 +56,7 @@ void CDMA::PI_DMA_READ (void) {
m_FlashRam.DmaToFlashram(
g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG,
g_Reg->PI_CART_ADDR_REG - 0x08000000,
g_Reg->PI_WR_LEN_REG + 1
g_Reg->PI_RD_LEN_REG + 1
);
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
g_Reg->MI_INTR_REG |= MI_INTR_PI;
@ -82,10 +82,17 @@ void CDMA::PI_DMA_READ (void) {
return;
}
void CDMA::PI_DMA_WRITE (void) {
void CDMA::PI_DMA_WRITE (void)
{
DWORD PI_WR_LEN_REG = ((g_Reg->PI_WR_LEN_REG) & 0x00FFFFFFul) + 1;
if ((PI_WR_LEN_REG & 1) != 0)
{
PI_WR_LEN_REG += 1; /* fixes AI Shougi 3, Doraemon 3, etc. */
}
g_Reg->PI_STATUS_REG |= PI_STATUS_DMA_BUSY;
if ( g_Reg->PI_DRAM_ADDR_REG + g_Reg->PI_WR_LEN_REG + 1 > g_MMU->RdramSize())
if ( g_Reg->PI_DRAM_ADDR_REG + PI_WR_LEN_REG > g_MMU->RdramSize())
{
if (g_Settings->LoadBool(Debugger_ShowUnhandledMemory)) { g_Notify->DisplayError("PI_DMA_WRITE not in Memory"); }
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
@ -100,7 +107,7 @@ void CDMA::PI_DMA_WRITE (void) {
m_Sram.DmaFromSram(
g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG,
g_Reg->PI_CART_ADDR_REG - 0x08000000,
g_Reg->PI_WR_LEN_REG + 1
PI_WR_LEN_REG
);
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
g_Reg->MI_INTR_REG |= MI_INTR_PI;
@ -111,7 +118,7 @@ void CDMA::PI_DMA_WRITE (void) {
m_FlashRam.DmaFromFlashram(
g_MMU->Rdram()+g_Reg->PI_DRAM_ADDR_REG,
g_Reg->PI_CART_ADDR_REG - 0x08000000,
g_Reg->PI_WR_LEN_REG + 1
PI_WR_LEN_REG
);
g_Reg->PI_STATUS_REG &= ~PI_STATUS_DMA_BUSY;
g_Reg->MI_INTR_REG |= MI_INTR_PI;
@ -134,8 +141,8 @@ void CDMA::PI_DMA_WRITE (void) {
BYTE * ROM = g_Rom->GetRomAddress();
BYTE * RDRAM = g_MMU->Rdram();
g_Reg->PI_CART_ADDR_REG -= 0x10000000;
if (g_Reg->PI_CART_ADDR_REG + g_Reg->PI_WR_LEN_REG + 1 < g_Rom->GetRomSize()) {
for (i = 0; i < g_Reg->PI_WR_LEN_REG + 1; i ++) {
if (g_Reg->PI_CART_ADDR_REG + PI_WR_LEN_REG < g_Rom->GetRomSize()) {
for (i = 0; i < PI_WR_LEN_REG; i ++) {
*(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((g_Reg->PI_CART_ADDR_REG + i) ^ 3));
}
} else {
@ -144,7 +151,7 @@ void CDMA::PI_DMA_WRITE (void) {
for (i = 0; i < Len; i ++) {
*(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = *(ROM+((g_Reg->PI_CART_ADDR_REG + i) ^ 3));
}
for (i = Len; i < g_Reg->PI_WR_LEN_REG + 1 - Len; i ++) {
for (i = Len; i < PI_WR_LEN_REG - Len; i ++) {
*(RDRAM+((g_Reg->PI_DRAM_ADDR_REG + i) ^ 3)) = 0;
}
}