Skip to content

Commit

Permalink
Lua: Add memory hook handler for DMA read
Browse files Browse the repository at this point in the history
  • Loading branch information
gocha committed May 6, 2015
1 parent a5c8909 commit 7ab9f75
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2104(Work);
UPDATE_COUNTERS;
} while (--count > 0);
Expand All @@ -747,6 +750,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2118_linear(Work);
UPDATE_COUNTERS;
} while (--count > 0);
Expand All @@ -756,6 +762,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2118_tile(Work);
UPDATE_COUNTERS;
} while (--count > 0);
Expand All @@ -769,6 +778,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2119_linear(Work);
UPDATE_COUNTERS;
} while (--count > 0);
Expand All @@ -778,6 +790,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2119_tile(Work);
UPDATE_COUNTERS;
} while (--count > 0);
Expand All @@ -789,6 +804,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2122(Work);
UPDATE_COUNTERS;
} while (--count > 0);
Expand All @@ -801,6 +819,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2180(Work);
UPDATE_COUNTERS;
} while (--count > 0);
Expand All @@ -819,6 +840,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2100 + d->BAddress);
UPDATE_COUNTERS;
} while (--count > 0);
Expand All @@ -840,12 +864,18 @@ bool8 S9xDoDMA (uint8 Channel)
while (count > 1)
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2118_linear(Work);
UPDATE_COUNTERS;
count--;

case 1:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2119_linear(Work);
UPDATE_COUNTERS;
count--;
Expand All @@ -855,6 +885,9 @@ bool8 S9xDoDMA (uint8 Channel)
if (count == 1)
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2118_linear(Work);
UPDATE_COUNTERS;
b = 1;
Expand All @@ -870,12 +903,18 @@ bool8 S9xDoDMA (uint8 Channel)
while (count > 1)
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2118_tile(Work);
UPDATE_COUNTERS;
count--;

case 1:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2119_tile(Work);
UPDATE_COUNTERS;
count--;
Expand All @@ -885,6 +924,9 @@ bool8 S9xDoDMA (uint8 Channel)
if (count == 1)
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
REGISTER_2118_tile(Work);
UPDATE_COUNTERS;
b = 1;
Expand All @@ -902,12 +944,18 @@ bool8 S9xDoDMA (uint8 Channel)
while (count > 1)
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2100 + d->BAddress);
UPDATE_COUNTERS;
count--;

case 1:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2101 + d->BAddress);
UPDATE_COUNTERS;
count--;
Expand All @@ -917,6 +965,9 @@ bool8 S9xDoDMA (uint8 Channel)
if (count == 1)
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2100 + d->BAddress);
UPDATE_COUNTERS;
b = 1;
Expand All @@ -934,6 +985,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2100 + d->BAddress);
UPDATE_COUNTERS;
if (--count <= 0)
Expand All @@ -944,6 +998,9 @@ bool8 S9xDoDMA (uint8 Channel)

case 1:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2100 + d->BAddress);
UPDATE_COUNTERS;
if (--count <= 0)
Expand All @@ -954,6 +1011,9 @@ bool8 S9xDoDMA (uint8 Channel)

case 2:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2101 + d->BAddress);
UPDATE_COUNTERS;
if (--count <= 0)
Expand All @@ -964,6 +1024,9 @@ bool8 S9xDoDMA (uint8 Channel)

case 3:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2101 + d->BAddress);
UPDATE_COUNTERS;
if (--count <= 0)
Expand All @@ -983,6 +1046,9 @@ bool8 S9xDoDMA (uint8 Channel)
do
{
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2100 + d->BAddress);
UPDATE_COUNTERS;
if (--count <= 0)
Expand All @@ -993,6 +1059,9 @@ bool8 S9xDoDMA (uint8 Channel)

case 1:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2101 + d->BAddress);
UPDATE_COUNTERS;
if (--count <= 0)
Expand All @@ -1003,6 +1072,9 @@ bool8 S9xDoDMA (uint8 Channel)

case 2:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2102 + d->BAddress);
UPDATE_COUNTERS;
if (--count <= 0)
Expand All @@ -1013,6 +1085,9 @@ bool8 S9xDoDMA (uint8 Channel)

case 3:
Work = *(base + p);
#ifdef HAVE_LUA
CallRegisteredLuaMemHook((d->ABank << 16) + d->AAddress, 1, Work, LUAMEMHOOK_READ);
#endif
S9xSetPPU(Work, 0x2103 + d->BAddress);
UPDATE_COUNTERS;
if (--count <= 0)
Expand Down Expand Up @@ -1614,18 +1689,27 @@ uint8 S9xDoHDMA (uint8 byte)
switch (p->TransferMode)
{
case 0:
#ifdef HAVE_LUA
CallRegisteredLuaMemHook(ShiftedIBank + IAddr, 1, *HDMAMemPointers[d], LUAMEMHOOK_READ);
#endif
S9xSetPPU(*HDMAMemPointers[d]++, 0x2100 + p->BAddress);
ADD_CYCLES(SLOW_ONE_CYCLE);
break;

case 5:
#ifdef HAVE_LUA
CallRegisteredLuaMemHook(ShiftedIBank + IAddr, 2, *(uint16*)HDMAMemPointers[d], LUAMEMHOOK_READ);
#endif
S9xSetPPU(*(HDMAMemPointers[d] + 0), 0x2100 + p->BAddress);
ADD_CYCLES(SLOW_ONE_CYCLE);
S9xSetPPU(*(HDMAMemPointers[d] + 1), 0x2101 + p->BAddress);
ADD_CYCLES(SLOW_ONE_CYCLE);
HDMAMemPointers[d] += 2;
/* fall through */
case 1:
#ifdef HAVE_LUA
CallRegisteredLuaMemHook(ShiftedIBank + IAddr + (p->TransferMode == 5 ? 2 : 0), 2, *(uint16*)HDMAMemPointers[d], LUAMEMHOOK_READ);
#endif
S9xSetPPU(*(HDMAMemPointers[d] + 0), 0x2100 + p->BAddress);
ADD_CYCLES(SLOW_ONE_CYCLE);
S9xSetPPU(*(HDMAMemPointers[d] + 1), 0x2101 + p->BAddress);
Expand All @@ -1635,6 +1719,9 @@ uint8 S9xDoHDMA (uint8 byte)

case 2:
case 6:
#ifdef HAVE_LUA
CallRegisteredLuaMemHook(ShiftedIBank + IAddr, 2, *(uint16*)HDMAMemPointers[d], LUAMEMHOOK_READ);
#endif
S9xSetPPU(*(HDMAMemPointers[d] + 0), 0x2100 + p->BAddress);
ADD_CYCLES(SLOW_ONE_CYCLE);
S9xSetPPU(*(HDMAMemPointers[d] + 1), 0x2100 + p->BAddress);
Expand All @@ -1644,6 +1731,9 @@ uint8 S9xDoHDMA (uint8 byte)

case 3:
case 7:
#ifdef HAVE_LUA
CallRegisteredLuaMemHook(ShiftedIBank + IAddr, 4, *(uint32*)HDMAMemPointers[d], LUAMEMHOOK_READ);
#endif
S9xSetPPU(*(HDMAMemPointers[d] + 0), 0x2100 + p->BAddress);
ADD_CYCLES(SLOW_ONE_CYCLE);
S9xSetPPU(*(HDMAMemPointers[d] + 1), 0x2100 + p->BAddress);
Expand All @@ -1656,6 +1746,9 @@ uint8 S9xDoHDMA (uint8 byte)
break;

case 4:
#ifdef HAVE_LUA
CallRegisteredLuaMemHook(ShiftedIBank + IAddr, 4, *(uint32*)HDMAMemPointers[d], LUAMEMHOOK_READ);
#endif
S9xSetPPU(*(HDMAMemPointers[d] + 0), 0x2100 + p->BAddress);
ADD_CYCLES(SLOW_ONE_CYCLE);
S9xSetPPU(*(HDMAMemPointers[d] + 1), 0x2101 + p->BAddress);
Expand Down

0 comments on commit 7ab9f75

Please sign in to comment.