diff --git a/src/fixed/room.h b/src/fixed/room.h index 43f98f3..c8c25f3 100644 --- a/src/fixed/room.h +++ b/src/fixed/room.h @@ -185,7 +185,7 @@ void Sector::getTriggerFloorCeiling(int32 x, int32 y, int32 z, int32* floor, int } while (!FD_END(cmd)); } - +#ifndef USE_ASM const Sector* Room::getSector(int32 x, int32 z) const { // TODO remove clamp? @@ -194,6 +194,7 @@ const Sector* Room::getSector(int32 x, int32 z) const return sectors + sx * info->zSectors + sz; } +#endif const Sector* Room::getWaterSector(int32 x, int32 z) const { diff --git a/src/platform/gba/asm/getSector.s b/src/platform/gba/asm/getSector.s new file mode 100644 index 0000000..49d6147 --- /dev/null +++ b/src/platform/gba/asm/getSector.s @@ -0,0 +1,44 @@ +#include "common_asm.inc" + +this .req r0 +x .req r1 +z .req r2 +info .req r3 +roomX .req r12 +roomZ .req roomX +sx .req x +sz .req z +sectors .req this +sectorsX .req roomX +sectorsZ .req roomZ +offset .req sectorsZ + +// const Sector* Room::getSector(int32 x, int32 z) const +.global _ZNK4Room9getSectorEii +_ZNK4Room9getSectorEii: + ldr info, [this, #4] + + // sx = X_CLAMP((x - (info->x << 8)) >> 10, 0, info->xSectors - 1); + ldrsh roomX, [info] + subs sx, x, roomX, lsl #8 + movlt sx, #0 + mov sx, sx, lsr #10 + ldrb sectorsX, [info, #20] + cmp sx, sectorsX + subge sx, sectorsX, #1 + + // sz = X_CLAMP((z - (info->z << 8)) >> 10, 0, info->zSectors - 1); + ldrsh roomZ, [info, #2] + subs sz, z, roomZ, lsl #8 + movlt sz, #0 + mov sz, sz, lsr #10 + ldrb sectorsZ, [info, #21] + cmp sz, sectorsZ + subge sz, sectorsZ, #1 + + // return sectors + sx * info->zSectors + sz; + ldr sectors, [this, #8] + mla offset, sx, sectorsZ, sz + add sectors, offset, lsl #3 // sizeof(Sector) == (1 << 3) + + bx lr