Skip to content

Commit

Permalink
Made actual GHDMA source and dest registers increment during transfer…
Browse files Browse the repository at this point in the history
…, instead of copies - fixes #2 , #23 , #24 , #25 , #26
  • Loading branch information
MeGaL0DoN committed Feb 4, 2025
1 parent e77ed76 commit 01858ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/MMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void MMU::executeGHDMA()
gbc.ghdma.transferLength -= 0x10;

for (int i = 0; i < 0x10; i++)
gb.ppu->VRAM[gbc.ghdma.currentDestAddr++] = (this->*read_func)(gbc.ghdma.currentSourceAddr++);
gb.ppu->VRAM[(gbc.ghdma.destAddr++) & 0x1FFF] = (this->*read_func)(gbc.ghdma.sourceAddr++);

if (gbc.ghdma.transferLength == 0)
{
Expand Down Expand Up @@ -333,15 +333,15 @@ void MMU::write8(uint16_t addr, uint8_t val)
break;
case 0xFF52:
if constexpr (sys == GBSystem::CGB)
gbc.ghdma.sourceAddr = (gbc.ghdma.sourceAddr & 0xFF00) | val;
gbc.ghdma.sourceAddr = (gbc.ghdma.sourceAddr & 0xFF00) | (val & 0xF0);
break;
case 0xFF53:
if constexpr (sys == GBSystem::CGB)
gbc.ghdma.destAddr = (gbc.ghdma.destAddr & 0x00FF) | (val << 8);
break;
case 0xFF54:
if constexpr (sys == GBSystem::CGB)
gbc.ghdma.destAddr = (gbc.ghdma.destAddr & 0xFF00) | val;
gbc.ghdma.destAddr = (gbc.ghdma.destAddr & 0xFF00) | (val & 0xF0);
break;
case 0xFF55:
if constexpr (sys == GBSystem::CGB)
Expand All @@ -353,9 +353,6 @@ void MMU::write8(uint16_t addr, uint8_t val)
}
else
{
gbc.ghdma.currentSourceAddr = gbc.ghdma.sourceAddr & 0xFFF0;
gbc.ghdma.currentDestAddr = gbc.ghdma.destAddr & 0x1FF0; // ignore 3 upper bits too, because destination is always in VRAM

gbc.ghdma.transferLength = ((val & 0x7F) + 1) * 0x10;
gbc.ghdma.cycles = 0;

Expand Down
3 changes: 0 additions & 3 deletions src/MMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class MMU
uint16_t sourceAddr{ 0xFF };
uint16_t destAddr{ 0xFF };

uint16_t currentSourceAddr{ 0x00 };
uint16_t currentDestAddr { 0x00 };

uint16_t transferLength{ 0xFF };
uint8_t cycles{ 0x00 };
GHDMAStatus status { GHDMAStatus::None };
Expand Down

0 comments on commit 01858ad

Please sign in to comment.