From d392ccc6aff63ef4d087b74639d103df77bcb00e Mon Sep 17 00:00:00 2001 From: Happy Date: Fri, 18 Nov 2016 12:05:10 -0700 Subject: [PATCH 1/4] Revert "n64: Remove incorrect factor of two in VI and AI interrupt timing." This reverts commit 0aaf4f00fd2471a9fd5d9d0c94f27cafcde576fb. --- src/mame/drivers/n64.cpp | 2 +- src/mame/machine/n64.cpp | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mame/drivers/n64.cpp b/src/mame/drivers/n64.cpp index 4be88ddb49a..53b0bfcf0f0 100644 --- a/src/mame/drivers/n64.cpp +++ b/src/mame/drivers/n64.cpp @@ -441,7 +441,7 @@ static MACHINE_CONFIG_START( n64, n64_mess_state ) /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) /* Video DACRATE is for quarter pixels, so the horizontal is also given in quarter pixels. However, the horizontal and vertical timing and sizing is adjustable by register and will be reset when the registers are written. */ - MCFG_SCREEN_RAW_PARAMS(DACRATE_NTSC,3093,0,3093,525,0,525) + MCFG_SCREEN_RAW_PARAMS(DACRATE_NTSC*2,3093,0,3093,525,0,525) //MCFG_SCREEN_REFRESH_RATE(60) //MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) //MCFG_SCREEN_SIZE(640, 525) diff --git a/src/mame/machine/n64.cpp b/src/mame/machine/n64.cpp index 8ab56187b43..21159f5a8b6 100644 --- a/src/mame/machine/n64.cpp +++ b/src/mame/machine/n64.cpp @@ -980,7 +980,7 @@ WRITE32_MEMBER( n64_periphs::dp_reg_w ) TIMER_CALLBACK_MEMBER(n64_periphs::vi_scanline_callback) { signal_rcp_interrupt(VI_INTERRUPT); - vi_scanline_timer->adjust(m_screen->time_until_pos(vi_intr)); + vi_scanline_timer->adjust(m_screen->time_until_pos(vi_intr >> 1)); } // Video Interface @@ -995,7 +995,7 @@ void n64_periphs::vi_recalculate_resolution() rectangle visarea = m_screen->visible_area(); // DACRATE is the quarter pixel clock and period will be for a field, not a frame - attoseconds_t period = (vi_hsync & 0xfff) * (vi_vsync & 0xfff) * HZ_TO_ATTOSECONDS(DACRATE_NTSC); + attoseconds_t period = (vi_hsync & 0xfff) * (vi_vsync & 0xfff) * HZ_TO_ATTOSECONDS(DACRATE_NTSC) / 2; if (width == 0 || height == 0 || (vi_control & 3) == 0) { @@ -1116,7 +1116,7 @@ WRITE32_MEMBER( n64_periphs::vi_reg_w ) case 0x0c/4: // VI_INTR_REG vi_intr = data; - vi_scanline_timer->adjust(m_screen->time_until_pos(vi_intr)); + vi_scanline_timer->adjust(m_screen->time_until_pos(vi_intr)); // >> 1)); break; case 0x10/4: // VI_CURRENT_REG @@ -1268,7 +1268,7 @@ void n64_periphs::ai_dma() ai_status |= 0x40000000; // adjust the timer - period = attotime::from_hz(DACRATE_NTSC) * (ai_dacrate + 1) * (current->length / 2); + period = attotime::from_hz(DACRATE_NTSC) * (ai_dacrate + 1) * (current->length / 4); ai_timer->adjust(period); } @@ -1300,16 +1300,16 @@ READ32_MEMBER( n64_periphs::ai_reg_r ) { case 0x04/4: // AI_LEN_REG { - if (ai_status & 0x40000000) - { - double secs_left = (ai_timer->expire() - machine().time()).as_double(); - ret = 2 * (uint32_t)(secs_left * (double)DACRATE_NTSC / (double)(ai_dacrate + 1)); - } - else if (ai_status & 0x80000001) + if (ai_status & 0x80000001) { ret = ai_len; } - + else if (ai_status & 0x40000000) + { + double secs_left = (ai_timer->expire() - machine().time()).as_double(); + unsigned int samples_left = (uint32_t)(secs_left * (double)DACRATE_NTSC / (double)(ai_dacrate + 1)); + ret = samples_left * 4; + } else { ret = 0; @@ -1340,12 +1340,12 @@ WRITE32_MEMBER( n64_periphs::ai_reg_w ) break; case 0x04/4: // AI_LEN_REG - ai_len = data & 0x3fff8; // Hardware v2.0 has 18 bits, v1.0 has 15 bits + ai_len = data & 0x3ffff; // Hardware v2.0 has 18 bits, v1.0 has 15 bits ai_fifo_push(ai_dram_addr, ai_len); break; case 0x08/4: // AI_CONTROL_REG - ai_control = data & 1; + ai_control = data; break; case 0x0c/4: From b1d19880e3a0d6124b2a465a7587694fd9338501 Mon Sep 17 00:00:00 2001 From: Happy Date: Fri, 18 Nov 2016 13:29:25 -0700 Subject: [PATCH 2/4] n64: Give priority to current transfer when reading AI length register --- src/mame/machine/n64.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mame/machine/n64.cpp b/src/mame/machine/n64.cpp index 21159f5a8b6..421e424de39 100644 --- a/src/mame/machine/n64.cpp +++ b/src/mame/machine/n64.cpp @@ -1300,16 +1300,16 @@ READ32_MEMBER( n64_periphs::ai_reg_r ) { case 0x04/4: // AI_LEN_REG { - if (ai_status & 0x80000001) + if (ai_status & 0x40000000) { - ret = ai_len; - } - else if (ai_status & 0x40000000) - { - double secs_left = (ai_timer->expire() - machine().time()).as_double(); + double secs_left = (ai_timer->remaining()).as_double(); unsigned int samples_left = (uint32_t)(secs_left * (double)DACRATE_NTSC / (double)(ai_dacrate + 1)); ret = samples_left * 4; } + else if (ai_status & 0x80000001) + { + ret = ai_len; + } else { ret = 0; From b50dd9d5488c6fb8e82b757571910820ce88c9f3 Mon Sep 17 00:00:00 2001 From: Happy Date: Fri, 18 Nov 2016 14:06:17 -0700 Subject: [PATCH 3/4] Eliminate explicit temps in AI length calculation. --- src/mame/machine/n64.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/mame/machine/n64.cpp b/src/mame/machine/n64.cpp index 421e424de39..80161386bcb 100644 --- a/src/mame/machine/n64.cpp +++ b/src/mame/machine/n64.cpp @@ -1302,9 +1302,7 @@ READ32_MEMBER( n64_periphs::ai_reg_r ) { if (ai_status & 0x40000000) { - double secs_left = (ai_timer->remaining()).as_double(); - unsigned int samples_left = (uint32_t)(secs_left * (double)DACRATE_NTSC / (double)(ai_dacrate + 1)); - ret = samples_left * 4; + ret = 4 * (uint32_t)(ai_timer->remaining().as_double() * (double)DACRATE_NTSC / (double)(ai_dacrate + 1)); } else if (ai_status & 0x80000001) { From 75b2632fa8d17701de4d7846f095a1b423219227 Mon Sep 17 00:00:00 2001 From: Happy Date: Fri, 18 Nov 2016 14:22:34 -0700 Subject: [PATCH 4/4] cleanup commented out lines --- src/mame/machine/n64.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/mame/machine/n64.cpp b/src/mame/machine/n64.cpp index 80161386bcb..17eb1b6f8e2 100644 --- a/src/mame/machine/n64.cpp +++ b/src/mame/machine/n64.cpp @@ -215,8 +215,6 @@ void n64_periphs::device_reset() si_dma_dir = 0; si_dma_timer->adjust(attotime::never); - //memset(m_save_data.eeprom, 0, 2048); - dp_clock = 0; cic_status = 0; @@ -980,7 +978,7 @@ WRITE32_MEMBER( n64_periphs::dp_reg_w ) TIMER_CALLBACK_MEMBER(n64_periphs::vi_scanline_callback) { signal_rcp_interrupt(VI_INTERRUPT); - vi_scanline_timer->adjust(m_screen->time_until_pos(vi_intr >> 1)); + vi_scanline_timer->adjust(m_screen->time_until_pos(vi_intr)); } // Video Interface @@ -1116,7 +1114,7 @@ WRITE32_MEMBER( n64_periphs::vi_reg_w ) case 0x0c/4: // VI_INTR_REG vi_intr = data; - vi_scanline_timer->adjust(m_screen->time_until_pos(vi_intr)); // >> 1)); + vi_scanline_timer->adjust(m_screen->time_until_pos(vi_intr)); break; case 0x10/4: // VI_CURRENT_REG @@ -1205,7 +1203,6 @@ void n64_periphs::ai_fifo_push(uint32_t address, uint32_t length) if (! (ai_status & 0x40000000)) { - //signal_rcp_interrupt(AI_INTERRUPT); ai_dma(); } } @@ -1228,7 +1225,6 @@ void n64_periphs::ai_fifo_pop() if (ai_fifo_num < AUDIO_DMA_DEPTH) { ai_status &= ~0x80000001; // FIFO not full - //signal_rcp_interrupt(AI_INTERRUPT); } } @@ -1372,7 +1368,6 @@ WRITE32_MEMBER( n64_periphs::ai_reg_w ) TIMER_CALLBACK_MEMBER(n64_periphs::pi_dma_callback) { pi_dma_tick(); - //m_rsp->yield(); } void n64_periphs::pi_dma_tick() @@ -1552,7 +1547,6 @@ WRITE32_MEMBER( n64_periphs::pi_reg_w ) attotime dma_period = attotime::from_hz(93750000) * (int)((float)(pi_rd_len + 1) * 5.08f); // Measured as between 2.53 cycles per byte and 2.55 cycles per byte pi_dma_timer->adjust(dma_period); - //pi_dma_tick(); break; } @@ -1565,8 +1559,6 @@ WRITE32_MEMBER( n64_periphs::pi_reg_w ) attotime dma_period = attotime::from_hz(93750000) * (int)((float)(pi_wr_len + 1) * 5.08f); // Measured as between 2.53 cycles per byte and 2.55 cycles per byte pi_dma_timer->adjust(dma_period); - - //pi_dma_tick(); break; }