Skip to content

Commit

Permalink
[Core/VDP] improved accuracy of DMA to CRAM/VSRAM (verified on real h…
Browse files Browse the repository at this point in the history
…ardware by Mask of Destiny) and DMA Fill timings
  • Loading branch information
ekeeke committed Feb 23, 2024
1 parent 5f2f0ce commit 9a0a1c2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
Binary file modified builds/genesis_plus_gx_libretro.dll
Binary file not shown.
Binary file modified builds/genplus_cube.dol
Binary file not shown.
Binary file modified builds/genplus_wii.dol
Binary file not shown.
10 changes: 10 additions & 0 deletions core/vdp_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,13 @@ void vdp_dma_update(unsigned int cycles)

/* Adjust for 68k bus DMA to VRAM (one word = 2 access) or DMA Copy (one read + one write = 2 access) */
rate = rate >> (dma_type & 1);

/* Adjust for 68k bus DMA to CRAM or VSRAM when display is off (one additional access slot is lost for each refresh slot) */
if (dma_type == 0)
{
if (rate == 166) rate = 161; /* 5 refresh slots per line in H32 mode when display is off */
else if (rate == 204) rate = 198; /* 6 refresh slots per line in H40 mode when display is off */
}

/* Remaining DMA cycles */
if (status & 8)
Expand Down Expand Up @@ -2444,6 +2451,9 @@ static void vdp_68k_data_w_m5(unsigned int data)
dma_length = 0x10000;
}

/* Take into account initial data word processing */
dma_length += 2;

/* Trigger DMA */
vdp_dma_update(m68k.cycles);
}
Expand Down

1 comment on commit 9a0a1c2

@ekeeke
Copy link
Owner Author

@ekeeke ekeeke commented on 9a0a1c2 Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference: https://gendev.spritesmind.net/forum/viewtopic.php?f=22&t=1291&hilit=161&start=34

In H40 mode, there are 6 refresh slots when the display is off. There is one refresh slot every 32 slots starting at slot 37 (assuming slot 0 = the first slot in which sprite tile data is read). The refresh slots are: 37, 69, 102, 133, 165 and 197. This means that contrary to the documentation, the 68K->VRAM DMA capacity is only 204 bytes rather than 205.

In H32 mode there are 5 refresh slots when the display is off as opposed to 4 when the display is on. I haven't gotten around to determining exactly which slots they are though.

I can also confirm that 68K->VDP DMA transfers go through the FIFO. This means that if a transfer is small enough to fit in the FIFO, the bus can be returned to the 68K before the data is written to the destination. The DMA engine will perform one read per slot until the FIFO is full. When a refresh slot occurs, you lose a single write slot, but you actually lose 2 68K read slots. When VRAM is the destination, this doesn't really matter since each word read needs 2 slots to write to VRAM; however, for VSRAM and CRAM you lose an extra transfer for each refresh slot. This gives you only 198 transfers per line in H40 mode.

This fixes following test ROM:
dma_speed_test.zip

Before:
image

After:
image

Please sign in to comment.