Skip to content

Commit

Permalink
#368 GBA clearFB_asm + sndClear_asm instead of DMA fill, increase fog…
Browse files Browse the repository at this point in the history
… distance (2 blocks)
  • Loading branch information
XProger committed Dec 5, 2022
1 parent f1c1d83 commit 40eb268
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/fixed/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ EWRAM_DATA const char* const* STR = STR_EN;

EWRAM_DATA ExtraInfoLara playersExtra[MAX_PLAYERS];

#if defined(USE_VRAM_MESH) || defined(USE_VRAM_ROOM)
uint8* vramPtr = (uint8*)0x06014000;
#endif

#if defined(__GBA__)
#include "TRACKS_IMA.h"
#include "TITLE_SCR.h"
Expand Down
2 changes: 1 addition & 1 deletion src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ extern uint8* vramPtr;
#define FOV_SHIFT 3
#define FOG_SHIFT 1
#define FOG_MAX VIEW_DIST
#define FOG_MIN (FOG_MAX - 4096)
#define FOG_MIN (FOG_MAX - 2048)
#define VIEW_MIN_F (64 << FIXED_SHIFT)
#define VIEW_MAX_F (VIEW_DIST << FIXED_SHIFT)

Expand Down
1 change: 1 addition & 0 deletions src/fixed/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ void readLevel(const uint8* data)

#ifdef USE_VRAM_MESH // experimental, should be per level or dynamic
vramMeshesCount = 0;
vramPtr = (uint8*)0x06014000;
vramPtr = pushToVRAM(vramPtr, models + ITEM_LARA);
vramPtr = pushToVRAM(vramPtr, models + ITEM_LARA_PISTOLS);
vramPtr = pushToVRAM(vramPtr, models + ITEM_LARA_SHOTGUN);
Expand Down
43 changes: 43 additions & 0 deletions src/platform/gba/asm/clearFB.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "common_asm.inc"

dst .req r0 // arg
end .req r14

.global clearFB_asm
clearFB_asm:
stmfd sp!, {r4-r6}
fiq_on

// 12 words
mov r1, #0
mov r2, #0
mov r3, #0
mov r4, #0
mov r5, #0
mov r6, #0
// FIQ regs
mov r8, #0
mov r9, #0
mov r10, #0
mov r11, #0
mov r12, #0
mov r13, #0
add end, dst, #(FRAME_WIDTH * FRAME_HEIGHT)

.loop:
// fill 12 * 4 * 8 bytes per iteration
stmia dst!, {r1-r6, r8-r13}
stmia dst!, {r1-r6, r8-r13}
stmia dst!, {r1-r6, r8-r13}
stmia dst!, {r1-r6, r8-r13}
stmia dst!, {r1-r6, r8-r13}
stmia dst!, {r1-r6, r8-r13}
stmia dst!, {r1-r6, r8-r13}
stmia dst!, {r1-r6, r8-r13}

cmp dst, end
blt .loop

fiq_off
ldmfd sp!, {r4-r6}
bx lr
2 changes: 1 addition & 1 deletion src/platform/gba/asm/common_asm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
.equ VIEW_MAX, (10 << 10)
.equ VIEW_OFF, 4096
.equ FOG_SHIFT, 4
.equ FOG_MIN, (VIEW_MAX - 4096)
.equ FOG_MIN, (VIEW_MAX - 2048)

.equ OT_SHIFT, 4
.equ OT_SIZE, ((VIEW_MAX >> OT_SHIFT) + 1)
Expand Down
23 changes: 23 additions & 0 deletions src/platform/gba/asm/sndPCM.s
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,27 @@ sndPCM_mix_asm:
blt .loop_mix

ldmfd sp!, {r4-r6}
bx lr

.global sndClear_asm
sndClear_asm:
// 4 words
mov r1, #0
mov r2, #0
mov r3, #0
mov r12, #0

// fill 11 * 4 * 4 = 176 bytes
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}
stmia r0!, {r1-r3, r12}

bx lr
9 changes: 8 additions & 1 deletion src/platform/gba/render.iwram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ Face* gOT[OT_SIZE]; // IWRAM 2.5k
Vertex* gVerticesBase = gVertices;
Face* gFacesBase = gFaces;

#if defined(USE_VRAM_MESH) || defined(USE_VRAM_ROOM)
uint8* vramPtr;
#endif

enum ClipFlags {
CLIP_LEFT = 1 << 0,
CLIP_RIGHT = 1 << 1,
Expand Down Expand Up @@ -129,6 +133,7 @@ extern "C" {
#define faceAddMeshQuads faceAddMeshQuads_asm
#define faceAddMeshTriangles faceAddMeshTriangles_asm
#define rasterize rasterize_asm
#define clearFB clearFB_asm

extern "C" {
void transformRoom_asm(const RoomVertex* vertices, int32 count);
Expand All @@ -139,6 +144,7 @@ extern "C" {
void faceAddMeshQuads_asm(const MeshQuad* polys, int32 count);
void faceAddMeshTriangles_asm(const MeshTriangle* polys, int32 count);
void rasterize_asm(uint32 flags, VertexLink* top);
void clearFB_asm(void* fb);
}
#else
#define transformRoom transformRoom_c
Expand All @@ -149,6 +155,7 @@ extern "C" {
#define faceAddMeshQuads faceAddMeshQuads_c
#define faceAddMeshTriangles faceAddMeshTriangles_c
#define rasterize rasterize_c
#define clearFB(fb) dmaFill(fb, 0, FRAME_WIDTH * FRAME_HEIGHT)

X_INLINE bool checkBackface(const Vertex* a, const Vertex* b, const Vertex* c)
{
Expand Down Expand Up @@ -805,7 +812,7 @@ void faceAddMesh(const MeshQuad* quads, const MeshTriangle* triangles, int32 qCo

void clear()
{
dmaFill((void*)fb, 0, FRAME_WIDTH * FRAME_HEIGHT);
clearFB((void*)fb);
}

void renderRoom(Room* room)
Expand Down
5 changes: 4 additions & 1 deletion src/platform/gba/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ int8 soundBuffer[2 * SND_SAMPLES + 32]; // 32 bytes of silence for DMA overrun w
#define sndIMA_fill sndIMA_fill_asm
#define sndPCM_fill sndPCM_fill_asm
#define sndPCM_mix sndPCM_mix_asm
#define sndClear sndClear_asm

extern "C" {
void sndClear_asm(int8* buffer);
void sndIMA_fill_asm(IMA_STATE &state, int8* buffer, const uint8* data, int32 size);
int32 sndPCM_fill_asm(int32 pos, int32 inc, int32 size, int32 volume, const uint8* data, int8* buffer);
int32 sndPCM_mix_asm(int32 pos, int32 inc, int32 size, int32 volume, const uint8* data, int8* buffer);
Expand All @@ -37,6 +39,7 @@ int8 soundBuffer[2 * SND_SAMPLES + 32]; // 32 bytes of silence for DMA overrun w
#define sndIMA_fill sndIMA_c
#define sndPCM_fill sndPCM_c
#define sndPCM_mix sndPCM_c
#define sndClear(b) dmaFill(b, SND_ENCODE(0), SND_SAMPLES * sizeof(b[0]))

#define DECODE_IMA_4(n)\
step = IMA_STEP[idx];\
Expand Down Expand Up @@ -286,7 +289,7 @@ void sndFill(int8* buffer)
if (mix) {
music.fill(buffer);
} else {
dmaFill(buffer, SND_ENCODE(0), SND_SAMPLES * sizeof(buffer[0]));
sndClear(buffer);
}

int32 ch = channelsCount;
Expand Down

0 comments on commit 40eb268

Please sign in to comment.