renamed methods to SYS_xxx, added debug logs
#include "sprite_eng.h"
#include "bmp.h"
+#include "tools.h"
+
#include "mapper.h"
+
#define NUM_BANK 8
@@ -14,12 +17,12 @@ static u16 banks[NUM_BANK] = {0, 0, 0, 0, 0, 0, 0, 0};
static u16 reg = 0;
-u16 BANK_getBank(u16 regionIndex)
+u16 SYS_getBank(u16 regionIndex)
{
return banks[regionIndex];
}
-void BANK_setBank(u16 regionIndex, u16 bankIndex)
+void SYS_setBank(u16 regionIndex, u16 bankIndex)
{
// check we are in valid region
if ((regionIndex > 0) && (regionIndex < 8))
@@ -28,19 +31,28 @@ void BANK_setBank(u16 regionIndex, u16 bankIndex)
*(vu8*)(MAPPER_BASE + (regionIndex * 2)) = bankIndex;
// store it so we can read it later
banks[regionIndex] = bankIndex;
+
+#if (LIB_DEBUG != 0)
+ KLog_U2("Region #", regionIndex, " set to bank #", bankIndex);
+#endif
}
+#if (LIB_DEBUG != 0)
+ else
+ KLog_U1("Cannot set bank in region #", regionIndex);
+#endif
}
static bool needBankSwitch(u32 addr)
{
- return (addr & 0x00700000) >= 0x00300000;
+ const u16 mask = (addr >> 16) & 0x00F0;
+ return (mask >= 0x0030) && (mask < 0x00C0);
}
static u32 setBank(u32 addr)
{
// get 512 KB bank index
- const u16 bankIndex = addr >> 11;
+ const u16 bankIndex = (addr >> 19) & 0x3F;
// check if bank is already set ?
if (banks[6] == bankIndex) return 0x300000;
@@ -68,7 +80,7 @@ static u32 setBank(u32 addr)
}
}
-void* BANK_getFarData(void* data)
+void* SYS_getFarData(void* data)
{
// convert to address
const u32 addr = (u32) data;
@@ -76,6 +88,13 @@ void* BANK_getFarData(void* data)
// don't require bank switch --> return direct pointer
if (!needBankSwitch(addr)) return data;
- // set bank and return adjusted address
- return (void*) (setBank(addr) + (addr & 0x07FFFF));
+ // set bank and get mapped address
+ const u32 mappedAddr = setBank(addr) + (addr & 0x07FFFF);
+
+#if (LIB_DEBUG != 0)
+ KLog_U2("Data at ", addr, " accessed through bank switch from ", mappedAddr);
+#endif
+
+ // return it
+ return (void*) mappedAddr;
}
