Skip to content

Commit

Permalink
#368 GBA matrixFrame_asm
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed Dec 3, 2022
1 parent 90e03fa commit f7d6d4d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 24 deletions.
44 changes: 22 additions & 22 deletions src/fixed/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,28 @@ void matrixRotateYXZ_c(int32 angleX, int32 angleY, int32 angleZ)
if (angleZ) matrixRotateZ(angleZ);
}

void matrixFrame_c(const void* pos, const void* angles)
{
int16 aX, aY, aZ;
DECODE_ANGLES(*(uint32*)angles, aX, aY, aZ);

uint32 xy = ((uint32*)pos)[0];
uint32 zu = ((uint32*)pos)[1];

#ifdef CPU_BIG_ENDIAN
int32 posX = int16(xy >> 16);
int32 posY = int16(xy & 0xFFFF);
int32 posZ = int16(zu >> 16);
#else
int32 posX = int16(xy & 0xFFFF);
int32 posY = int16(xy >> 16);
int32 posZ = int16(zu & 0xFFFF);
#endif

matrixTranslateRel(posX, posY, posZ);
matrixRotateYXZ(aX, aY, aZ);
}

void boxTranslate_c(AABBi &box, int32 x, int32 y, int32 z)
{
box.minX += x;
Expand Down Expand Up @@ -1374,28 +1396,6 @@ void boxRotateYQ_c(AABBi &box, int32 quadrant)
}
#endif

void matrixFrame(const void* pos, const void* angles)
{
int16 aX, aY, aZ;
DECODE_ANGLES(*(uint32*)angles, aX, aY, aZ);

uint32 xy = ((uint32*)pos)[0];
uint32 zu = ((uint32*)pos)[1];

#ifdef CPU_BIG_ENDIAN
int32 posX = int16(xy >> 16);
int32 posY = int16(xy & 0xFFFF);
int32 posZ = int16(zu >> 16);
#else
int32 posX = int16(xy & 0xFFFF);
int32 posY = int16(xy >> 16);
int32 posZ = int16(zu & 0xFFFF);
#endif

matrixTranslateRel(posX, posY, posZ);
matrixRotateYXZ(aX, aY, aZ);
}

void matrixFrameLerp(const void* pos, const void* anglesA, const void* anglesB, int32 delta, int32 rate)
{
int16 aX, aY, aZ;
Expand Down
6 changes: 5 additions & 1 deletion src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,7 @@ vec3i boxPushOut(const AABBi &a, const AABBi &b);
void matrixRotateZ_asm(int32 angle);
void matrixRotateYQ_asm(int32 quadrant);
void matrixRotateYXZ_asm(int32 angleX, int32 angleY, int32 angleZ);
void matrixFrame_asm(const void* pos, const void* angles);
void boxTranslate_asm(AABBi &box, int32 x, int32 y, int32 z);
void boxRotateYQ_asm(AABBi &box, int32 quadrant);
int32 sphereIsVisible_asm(int32 x, int32 y, int32 z, int32 r);
Expand All @@ -2667,6 +2668,7 @@ vec3i boxPushOut(const AABBi &a, const AABBi &b);
#define matrixRotateZ matrixRotateZ_asm
#define matrixRotateYXZ matrixRotateYXZ_asm
#define matrixRotateYQ matrixRotateYQ_asm
#define matrixFrame matrixFrame_asm
#define boxTranslate boxTranslate_asm
#define boxRotateYQ boxRotateYQ_asm
#define sphereIsVisible sphereIsVisible_asm
Expand All @@ -2684,6 +2686,7 @@ vec3i boxPushOut(const AABBi &a, const AABBi &b);
#define matrixRotateZ matrixRotateZ_c
#define matrixRotateYXZ matrixRotateYXZ_c
#define matrixRotateYQ matrixRotateYQ_c
#define matrixFrame matrixFrame_c
#define boxTranslate boxTranslate_c
#define boxRotateYQ boxRotateYQ_c
#define sphereIsVisible sphereIsVisible_c
Expand All @@ -2701,6 +2704,7 @@ vec3i boxPushOut(const AABBi &a, const AABBi &b);
void matrixRotateZ_c(int32 angle);
void matrixRotateYQ_c(int32 quadrant);
void matrixRotateYXZ_c(int32 angleX, int32 angleY, int32 angleZ);
void matrixFrame_c(const void* pos, const void* angles);

void boxTranslate_c(AABBi &box, int32 x, int32 y, int32 z);
void boxRotateYQ_c(AABBi &box, int32 quadrant);
Expand Down Expand Up @@ -2771,7 +2775,7 @@ X_INLINE vec3i matrixGetDir(const Matrix &m)
return _vec3i(m.e20, m.e21, m.e22);
}

void matrixFrame(const void* pos, const void* angles);
void matrixFrame_c(const void* pos, const void* angles);
void matrixFrameLerp(const void* pos, const void* anglesA, const void* anglesB, int32 delta, int32 rate);
void matrixSetView(const vec3i &pos, int32 angleX, int32 angleY);

Expand Down
2 changes: 1 addition & 1 deletion src/platform/gba/asm/flush.s
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ sprites .req index01
SP_SIZE = (8 * VERTEX_SIZEOF) + 4
SP_SPRITES = SP_SIZE - 4

.extern rasterize_c, drawPoly
.extern drawPoly

.global flush_asm
flush_asm:
Expand Down
39 changes: 39 additions & 0 deletions src/platform/gba/asm/matrixFrame.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "common_asm.inc"

pos .req r0 // arg
angles .req r1 // arg
x .req pos
y .req angles
z .req r2
packed .req r12

.extern matrixTranslateRel_asm, matrixRotateYXZ_asm

.global matrixFrame_asm
matrixFrame_asm:
stmfd sp!, {lr}

ldr packed, [angles]
ldrsh z, [pos, #4]
ldrsh y, [pos, #2]
ldrsh x, [pos, #0]

bl matrixTranslateRel_asm // doesn't affect user mode r12

lsl z, packed, #22
asr z, #16

lsr packed, #10

lsl y, packed, #22
asr y, #16

lsr packed, #10

lsl x, packed, #22
asr x, #16

ldmfd sp!, {lr}
b matrixRotateYXZ_asm

// TODO matrixFrameLerp

0 comments on commit f7d6d4d

Please sign in to comment.