match ScrollWindow

This commit is contained in:
camthesaxman 2018-01-07 16:58:20 -06:00
parent 0fd6ae4791
commit 75c359e300
1 changed files with 59 additions and 681 deletions

View File

@ -465,696 +465,74 @@ void FillWindowPixelBuffer(u8 windowId, u8 fillValue)
CpuFastFill8(fillValue, gWindows[windowId].tileData, 0x20 * fillSize);
}
// functionally equivalent, its fucking hard to match
#ifdef NONMATCHING
#define MOVE_TILES_DOWN(a) \
{ \
destOffset = i + (a); \
srcOffset = i + (((width * (distanceLoop & ~7)) | (distanceLoop & 7)) * 4); \
if (srcOffset < size) \
*(u32*)(tileData + destOffset) = *(u32*)(tileData + srcOffset); \
else \
*(u32*)(tileData + destOffset) = fillValue32; \
distanceLoop++; \
}
#define MOVE_TILES_UP(a) \
{ \
destOffset = i + (a); \
srcOffset = i + (((width * (distanceLoop & ~7)) | (distanceLoop & 7)) * 4); \
if (srcOffset < size) \
*(u32*)(tileData - destOffset) = *(u32*)(tileData - srcOffset); \
else \
*(u32*)(tileData - destOffset) = fillValue32; \
distanceLoop++; \
}
void ScrollWindow(u8 windowId, u8 direction, u8 distance, u8 fillValue)
{
s32 i, id1, id2, size;
u32 distanceLoop, toFill, width;
u8 *tileData;
struct WindowTemplate window;
struct WindowTemplate window = gWindows[windowId].window;
u8 *tileData = gWindows[windowId].tileData;
u32 fillValue32 = (fillValue << 24) | (fillValue << 16) | (fillValue << 8) | fillValue;
s32 size = window.height * window.width * 32;
u32 width = window.width;
s32 i;
s32 srcOffset, destOffset;
u32 distanceLoop;
tileData = gWindows[windowId].tileData;
toFill = (fillValue << 0x18) | (fillValue << 0x10) | (fillValue << 8) | fillValue;
window = gWindows[windowId].window;
size = 0x20 * (window.height * window.width);
width = window.width;
if (direction != 1)
switch (direction)
{
s32 signedDirection = direction;
if (signedDirection <= 1)
{
if (signedDirection == 0)
{
for (i = 0; i < size; i += 0x20)
{
distanceLoop = distance;
id1 = i + 0;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData + id1) = *(u32*)(tileData + id2);
else
*(u32*)(tileData + id1) = toFill;
distanceLoop++;
id1 = i + 4;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData + id1) = *(u32*)(tileData + id2);
else
*(u32*)(tileData + id1) = toFill;
distanceLoop++;
id1 = i + 8;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData + id1) = *(u32*)(tileData + id2);
else
*(u32*)(tileData + id1) = toFill;
distanceLoop++;
id1 = i + 12;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData + id1) = *(u32*)(tileData + id2);
else
*(u32*)(tileData + id1) = toFill;
distanceLoop++;
id1 = i + 16;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData + id1) = *(u32*)(tileData + id2);
else
*(u32*)(tileData + id1) = toFill;
distanceLoop++;
id1 = i + 20;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData + id1) = *(u32*)(tileData + id2);
else
*(u32*)(tileData + id1) = toFill;
distanceLoop++;
id1 = i + 24;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData + id1) = *(u32*)(tileData + id2);
else
*(u32*)(tileData + id1) = toFill;
distanceLoop++;
id1 = i + 28;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData + id1) = *(u32*)(tileData + id2);
else
*(u32*)(tileData + id1) = toFill;
}
}
}
}
else
{
tileData += size - 4;
for (i = 0; i < size; i += 0x20)
case 0:
for (i = 0; i < size; i += 32)
{
distanceLoop = distance;
id1 = i + 0;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData - id1) = *(u32*)(tileData - id2);
else
*(u32*)(tileData - id1) = toFill;
distanceLoop++;
id1 = i + 4;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData - id1) = *(u32*)(tileData - id2);
else
*(u32*)(tileData - id1) = toFill;
distanceLoop++;
id1 = i + 8;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData - id1) = *(u32*)(tileData - id2);
else
*(u32*)(tileData - id1) = toFill;
distanceLoop++;
id1 = i + 12;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData - id1) = *(u32*)(tileData - id2);
else
*(u32*)(tileData - id1) = toFill;
distanceLoop++;
id1 = i + 16;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData - id1) = *(u32*)(tileData - id2);
else
*(u32*)(tileData - id1) = toFill;
distanceLoop++;
id1 = i + 20;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData - id1) = *(u32*)(tileData - id2);
else
*(u32*)(tileData - id1) = toFill;
distanceLoop++;
id1 = i + 24;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData - id1) = *(u32*)(tileData - id2);
else
*(u32*)(tileData - id1) = toFill;
distanceLoop++;
id1 = i + 28;
id2 = i + (((width * ((distanceLoop) & ~(7))) | ((distanceLoop) & 7)) * 4);
if (id2 < size)
*(u32*)(tileData - id1) = *(u32*)(tileData - id2);
else
*(u32*)(tileData - id1) = toFill;
MOVE_TILES_DOWN(0)
MOVE_TILES_DOWN(4)
MOVE_TILES_DOWN(8)
MOVE_TILES_DOWN(12)
MOVE_TILES_DOWN(16)
MOVE_TILES_DOWN(20)
MOVE_TILES_DOWN(24)
MOVE_TILES_DOWN(28)
}
break;
case 1:
tileData += size - 4;
for (i = 0; i < size; i += 32)
{
distanceLoop = distance;
MOVE_TILES_UP(0)
MOVE_TILES_UP(4)
MOVE_TILES_UP(8)
MOVE_TILES_UP(12)
MOVE_TILES_UP(16)
MOVE_TILES_UP(20)
MOVE_TILES_UP(24)
MOVE_TILES_UP(28)
}
break;
case 2:
break;
}
}
#else
__attribute__((naked))
void ScrollWindow(u8 windowId, u8 direction, u8 distance, u8 fillValue)
{
asm(".syntax unified\n\
push {r4-r7,lr}\n\
mov r7, r10\n\
mov r6, r9\n\
mov r5, r8\n\
push {r5-r7}\n\
sub sp, 0x8\n\
lsls r0, 24\n\
lsrs r0, 24\n\
lsls r1, 24\n\
lsrs r1, 24\n\
mov r8, r1\n\
lsls r2, 24\n\
lsrs r2, 24\n\
str r2, [sp]\n\
lsls r3, 24\n\
lsrs r3, 24\n\
ldr r2, =gWindows\n\
lsls r1, r0, 1\n\
adds r1, r0\n\
lsls r1, 2\n\
adds r4, r1, r2\n\
adds r2, 0x8\n\
adds r1, r2\n\
ldr r5, [r1]\n\
lsls r7, r3, 24\n\
lsls r0, r3, 16\n\
orrs r7, r0\n\
lsls r0, r3, 8\n\
orrs r7, r0\n\
orrs r7, r3\n\
ldr r1, [r4]\n\
ldr r2, [r4, 0x4]\n\
ldrb r3, [r4, 0x4]\n\
lsrs r0, r1, 24\n\
muls r0, r3\n\
lsls r6, r0, 5\n\
lsrs r1, 24\n\
mov r12, r1\n\
mov r0, r8\n\
cmp r0, 0x1\n\
bne _08003CE8\n\
b _08003E9E\n\
_08003CE8:\n\
cmp r0, 0x1\n\
ble _08003CEE\n\
b _08004046\n\
_08003CEE:\n\
cmp r0, 0\n\
beq _08003CF4\n\
b _08004046\n\
_08003CF4:\n\
movs r4, 0\n\
cmp r4, r6\n\
blt _08003CFC\n\
b _08004046\n\
_08003CFC:\n\
movs r1, 0x8\n\
negs r1, r1\n\
mov r9, r1\n\
movs r2, 0x7\n\
mov r8, r2\n\
mov r10, r5\n\
_08003D08:\n\
ldr r3, [sp]\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
adds r0, r3, 0\n\
mov r2, r8\n\
ands r0, r2\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003D34\n\
adds r0, r5, r1\n\
ldr r0, [r0]\n\
mov r1, r10\n\
str r0, [r1]\n\
b _08003D38\n\
.pool\n\
_08003D34:\n\
mov r2, r10\n\
str r7, [r2]\n\
_08003D38:\n\
adds r3, 0x1\n\
adds r2, r4, 0x4\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003D64\n\
adds r0, r5, r2\n\
adds r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003D68\n\
_08003D64:\n\
adds r0, r5, r2\n\
str r7, [r0]\n\
_08003D68:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x8\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003D96\n\
adds r0, r5, r2\n\
adds r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003D9A\n\
_08003D96:\n\
adds r0, r5, r2\n\
str r7, [r0]\n\
_08003D9A:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0xC\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003DC8\n\
adds r0, r5, r2\n\
adds r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003DCC\n\
_08003DC8:\n\
adds r0, r5, r2\n\
str r7, [r0]\n\
_08003DCC:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x10\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003DFA\n\
adds r0, r5, r2\n\
adds r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003DFE\n\
_08003DFA:\n\
adds r0, r5, r2\n\
str r7, [r0]\n\
_08003DFE:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x14\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003E2C\n\
adds r0, r5, r2\n\
adds r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003E30\n\
_08003E2C:\n\
adds r0, r5, r2\n\
str r7, [r0]\n\
_08003E30:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x18\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003E5E\n\
adds r0, r5, r2\n\
adds r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003E62\n\
_08003E5E:\n\
adds r0, r5, r2\n\
str r7, [r0]\n\
_08003E62:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x1C\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
adds r0, r1, 0\n\
mov r1, r8\n\
ands r3, r1\n\
orrs r0, r3\n\
lsls r0, 2\n\
adds r1, r4, r0\n\
cmp r1, r6\n\
bge _08003E8C\n\
adds r0, r5, r2\n\
adds r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003E90\n\
_08003E8C:\n\
adds r0, r5, r2\n\
str r7, [r0]\n\
_08003E90:\n\
movs r2, 0x20\n\
add r10, r2\n\
adds r4, 0x20\n\
cmp r4, r6\n\
bge _08003E9C\n\
b _08003D08\n\
_08003E9C:\n\
b _08004046\n\
_08003E9E:\n\
subs r0, r6, 0x4\n\
adds r5, r0\n\
movs r4, 0\n\
cmp r4, r6\n\
blt _08003EAA\n\
b _08004046\n\
_08003EAA:\n\
movs r0, 0x8\n\
negs r0, r0\n\
mov r9, r0\n\
movs r1, 0x7\n\
mov r8, r1\n\
mov r10, r5\n\
_08003EB6:\n\
ldr r3, [sp]\n\
adds r0, r3, 0\n\
mov r2, r9\n\
ands r0, r2\n\
mov r1, r12\n\
muls r1, r0\n\
adds r0, r3, 0\n\
mov r2, r8\n\
ands r0, r2\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003EDC\n\
subs r0, r5, r1\n\
ldr r0, [r0]\n\
mov r1, r10\n\
str r0, [r1]\n\
b _08003EE0\n\
_08003EDC:\n\
mov r2, r10\n\
str r7, [r2]\n\
_08003EE0:\n\
adds r3, 0x1\n\
adds r2, r4, 0x4\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003F0C\n\
subs r0, r5, r2\n\
subs r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003F10\n\
_08003F0C:\n\
subs r0, r5, r2\n\
str r7, [r0]\n\
_08003F10:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x8\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003F3E\n\
subs r0, r5, r2\n\
subs r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003F42\n\
_08003F3E:\n\
subs r0, r5, r2\n\
str r7, [r0]\n\
_08003F42:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0xC\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003F70\n\
subs r0, r5, r2\n\
subs r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003F74\n\
_08003F70:\n\
subs r0, r5, r2\n\
str r7, [r0]\n\
_08003F74:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x10\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003FA2\n\
subs r0, r5, r2\n\
subs r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003FA6\n\
_08003FA2:\n\
subs r0, r5, r2\n\
str r7, [r0]\n\
_08003FA6:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x14\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08003FD4\n\
subs r0, r5, r2\n\
subs r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08003FD8\n\
_08003FD4:\n\
subs r0, r5, r2\n\
str r7, [r0]\n\
_08003FD8:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x18\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
str r1, [sp, 0x4]\n\
adds r0, r3, 0\n\
mov r1, r8\n\
ands r0, r1\n\
ldr r1, [sp, 0x4]\n\
orrs r1, r0\n\
lsls r1, 2\n\
adds r1, r4, r1\n\
cmp r1, r6\n\
bge _08004006\n\
subs r0, r5, r2\n\
subs r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _0800400A\n\
_08004006:\n\
subs r0, r5, r2\n\
str r7, [r0]\n\
_0800400A:\n\
adds r3, 0x1\n\
adds r2, r4, 0\n\
adds r2, 0x1C\n\
adds r0, r3, 0\n\
mov r1, r9\n\
ands r0, r1\n\
mov r1, r12\n\
muls r1, r0\n\
adds r0, r1, 0\n\
mov r1, r8\n\
ands r3, r1\n\
orrs r0, r3\n\
lsls r0, 2\n\
adds r1, r4, r0\n\
cmp r1, r6\n\
bge _08004034\n\
subs r0, r5, r2\n\
subs r1, r5, r1\n\
ldr r1, [r1]\n\
str r1, [r0]\n\
b _08004038\n\
_08004034:\n\
subs r0, r5, r2\n\
str r7, [r0]\n\
_08004038:\n\
movs r2, 0x20\n\
negs r2, r2\n\
add r10, r2\n\
adds r4, 0x20\n\
cmp r4, r6\n\
bge _08004046\n\
b _08003EB6\n\
_08004046:\n\
add sp, 0x8\n\
pop {r3-r5}\n\
mov r8, r3\n\
mov r9, r4\n\
mov r10, r5\n\
pop {r4-r7}\n\
pop {r0}\n\
bx r0\n\
.syntax divided");
}
#endif // NONMATCHING
void CallWindowFunction(u8 windowId, void ( *func)(u8, u8, u8, u8, u8, u8))
{