Skip to content

Commit

Permalink
trig tables shiftable (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaMech authored Apr 6, 2024
1 parent 12f3326 commit c4d596d
Show file tree
Hide file tree
Showing 24 changed files with 297 additions and 305 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ DATA_DIR := data
INCLUDE_DIRS := include

# Directories containing source files
SRC_DIRS := src src/data src/racing src/ending src/audio src/debug src/os src/os/math courses
SRC_DIRS := src src/data src/buffers src/racing src/ending src/audio src/debug src/os src/os/math courses
ASM_DIRS := asm asm/os asm/unused $(DATA_DIR) $(DATA_DIR)/sound_data $(DATA_DIR)/karts


Expand Down
2 changes: 1 addition & 1 deletion ctx_includes.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
#include "src/data/data_800E8700.h"
#include "src/data/some_data.h"
#include "src/data/path_spawn_data.h"
#include "src/data/trig_tables.h"
#include "src/buffers/trig_tables.h"
#include "src/data_segment2.h"
#include "src/effects.h"
#include "src/ending/ceremony_and_credits.h"
Expand Down
21 changes: 0 additions & 21 deletions include/linker_segments.h

This file was deleted.

33 changes: 23 additions & 10 deletions mk64.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

OUTPUT_ARCH (mips)

#include "include/linker_segments.h"
#define LINKER_MAIN 0x80000400

#define LINKER_ENDING 0x80280000

#define LINKER_RACING 0x8028DF00

// End of Jumper pak memory
#define RDRAM_END 0x807FFFFF

#define BEGIN_SEG(name, addr) \
_##name##SegmentStart = ADDR(.name); \
Expand Down Expand Up @@ -81,7 +88,7 @@ SECTIONS
BUILD_DIR/src/debug/crash_screen_enhancement.o(.text);
BUILD_DIR/src/debug/debug.o(.text);
BUILD_DIR/src/os/sprintf.o(.text);
BUILD_DIR/src/os/is_debug.o(.text);
BUILD_DIR/src/os/is_debug.o(.text);
#endif
BUILD_DIR/src/os/osCreateThread.o(.text);
#ifdef VERSION_EU
Expand Down Expand Up @@ -342,13 +349,15 @@ SECTIONS
BUILD_DIR/src/os/osEepromWrite.o(.bss);
BUILD_DIR/asm/os/__osException.o(.bss);
BUILD_DIR/src/os/osLeoDiskInit.o(.bss);
. = ALIGN(0x10);
}
END_NOLOAD(main)

/* Checks that segments are not overlapping into the memory pool but is not strictly necessary */
BEGIN_NOLOAD(memoryPool)
{
BUILD_DIR/src/data/memory_pool.o(.bss);
BUILD_DIR/src/buffers/memory_pool.o(.bss);
. = ALIGN(0x10);
}
END_NOLOAD(memoryPool)

Expand Down Expand Up @@ -387,19 +396,21 @@ SECTIONS
BUILD_DIR/src/racing/race_logic.o(.bss*);
BUILD_DIR/src/racing/actors.o(.bss*);
BUILD_DIR/src/racing/memory.o(.bss*);
BUILD_DIR/src/buffers/random.o(.bss*);
. = ALIGN(0x10);
}
END_NOLOAD(racing)

BEGIN_NOLOAD(buffers)
{
BUILD_DIR/src/data/buffers.o(.bss*);
BUILD_DIR/src/data/gfx_output_buffer.o(.bss*);
BUILD_DIR/src/buffers/trig_tables_bss.o(.bss*);
BUILD_DIR/src/buffers/buffers.o(.bss*);
BUILD_DIR/src/buffers/gfx_output_buffer.o(.bss*);
BUILD_DIR/src/audio/synthesis.o(.bss*);
BUILD_DIR/src/audio/heap.o(.bss*);
BUILD_DIR/src/audio/load.o(.bss);
BUILD_DIR/src/audio/data.o(.bss);
. = ALIGN(0x8);
BUILD_DIR/src/audio/load.o(.bss*);
BUILD_DIR/src/audio/data.o(.bss*);
. = ALIGN(0x10);
}
END_NOLOAD(buffers)

Expand Down Expand Up @@ -476,9 +487,9 @@ SECTIONS
END_SEG(other_textures)

/* 0x802BA370 724220-729A30 [0x5810] */
BEGIN_SEG(trigTables, LINKER_TRIG_TABLES)
BEGIN_SEG(trigTables, _buffersSegmentNoloadStart)
{
BUILD_DIR/src/data/trig_tables.o(.data);
BUILD_DIR/src/buffers/trig_tables.o(.data);
. = ALIGN(0x10);
}
END_SEG(trigTables)
Expand Down Expand Up @@ -645,6 +656,8 @@ SECTIONS
ASSERT((_mainSegmentNoloadEnd <= _memoryPoolSegmentNoloadStart), "Error: Main segment extended into the memory pool.")
ASSERT((_memoryPoolSegmentNoloadEnd <= _endingSegmentStart), "Error: Memory pool extended into the ending segment.")
ASSERT((_endingSegmentNoloadEnd <= _racingSegmentStart), "Error: Ending segment extended into the racing segment")
ASSERT((_endingSegmentNoloadEnd <= _racingSegmentStart), "Error: Ending segment extended into the racing segment.")
ASSERT((_racingSegmentNoloadEnd <= _buffersSegmentNoloadStart), "Error: Racing segment extended into the buffers segment.")
ASSERT((_buffersSegmentNoloadEnd <= RDRAM_END), "Error: Buffers segment extended past 8MB of memory")
ASSERT((_buffersSegmentNoloadEnd <= RDRAM_END), "Error: Buffers segment extended into trig tables segment.")
}
2 changes: 1 addition & 1 deletion src/audio/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "audio/synthesis.h"
#include "audio/seqplayer.h"
#include "audio/port_eu.h"
#include "data/gfx_output_buffer.h"
#include "buffers/gfx_output_buffer.h"

#define ALIGN16(val) (((val) + 0xF) & ~0xF)

Expand Down
4 changes: 0 additions & 4 deletions src/audio/synthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ Acmd *final_resample(Acmd *acmd, struct NoteSynthesisState *synthesisState, s32
Acmd *func_800B86A0(Acmd *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, u32 flags);
Acmd *note_apply_headset_pan_effects(Acmd *acmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight);

// These 2 are almost certainly misnamed and misplaced
extern u64 gGfxSPTaskOutputBuffer[];
extern u32 gGfxSPTaskOutputBufferSize;

extern struct SynthesisReverb gSynthesisReverbs[4];

/*
Expand Down
22 changes: 22 additions & 0 deletions src/buffers/buffers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <ultra64.h>
#include <macros.h>
#include "config.h"
#include "buffers.h"

ALIGNED8 union_D_802BFB80 D_802BFB80;
ALIGNED8 struct_D_802DFB80 D_802DFB80[2][2][8];
#ifdef AVOID_UB
ALIGNED8 struct_D_802F1F80 D_802F1F80[2][4][8];
#else
ALIGNED8 u16 D_802F1F80[2][4][0x100 * 8];
#endif

ALIGNED8 u16 gZBuffer[SCREEN_WIDTH * SCREEN_HEIGHT];

#ifdef AVOID_UB
ALIGNED8 u16 gFramebuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT];
#else
u16 gFramebuffer0[SCREEN_WIDTH * SCREEN_HEIGHT];
u16 gFramebuffer1[SCREEN_WIDTH * SCREEN_HEIGHT];
u16 gFramebuffer2[SCREEN_WIDTH * SCREEN_HEIGHT];
#endif
7 changes: 7 additions & 0 deletions src/buffers/gfx_output_buffer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <ultra64.h>
#include <macros.h>
#include "gfx_output_buffer.h"

ALIGNED8 u64 gGfxSPTaskOutputBuffer[GFX_OUTPUT_BUFFER_SIZE];

u32 gGfxSPTaskOutputBufferSize;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@

// 0x3F00
extern u64 gGfxSPTaskOutputBuffer[GFX_OUTPUT_BUFFER_SIZE];
extern u32 gGfxSPTaskOutputBufferSize;

#endif // GFX_OUTPUT_BUFFER_H
4 changes: 2 additions & 2 deletions src/data/memory_pool.c → src/buffers/memory_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define MEMORY_POOL_SIZE 0xAB630

/**
* Memory pool setup to prevent other code segments flowing into the memory pool
* and for easier portability.
* Memory pool variable prevents code segments flowing into the memory pool
* for easier portability.
*/
u8 memoryPool[MEMORY_POOL_SIZE];
4 changes: 4 additions & 0 deletions src/buffers/random.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <segments.h>

u16 gRandomSeed16;
u8 randomSeedPadding[216];
4 changes: 4 additions & 0 deletions src/buffers/random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <ultra64.h>

extern u16 gRandomSeed16;
extern u8 randomSeedPadding[];
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions src/buffers/trig_tables_bss.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <ultra64.h>
#include <macros.h>

/**
* Trig tables get loaded into memory at this location.
* See trig_tables.c for the real file.
*/

#ifdef VERSION_EU
ALIGNED8 u8 trigTablesPadding[0x5750];
#else
ALIGNED8 u8 trigTablesPadding[0x5810];
#endif
32 changes: 0 additions & 32 deletions src/data/buffers.c

This file was deleted.

6 changes: 0 additions & 6 deletions src/data/gfx_output_buffer.c

This file was deleted.

2 changes: 1 addition & 1 deletion src/debug/all_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#include <objects.h>
#include <segments.h>
#include <sounds.h>
#include "data/trig_tables.h"
#include "buffers/trig_tables.h"
#include <types.h>
#include <ultra64.h>
#include <vehicles.h>
Expand Down
14 changes: 7 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "staff_ghosts.h"
#include <debug.h>
#include "crash_screen.h"
#include "data/gfx_output_buffer.h"
#include "buffers/gfx_output_buffer.h"

// Declarations (not in this file)
void func_80091B78(void);
Expand All @@ -53,9 +53,9 @@ struct VblankHandler *gVblankHandler2 = NULL;

struct SPTask *gActiveSPTask = NULL;
struct SPTask *sCurrentAudioSPTask = NULL;
struct SPTask* sCurrentDisplaySPTask = NULL;
struct SPTask* sNextAudioSPTask = NULL;
struct SPTask* sNextDisplaySPTask = NULL;
struct SPTask *sCurrentDisplaySPTask = NULL;
struct SPTask *sNextAudioSPTask = NULL;
struct SPTask *sNextDisplaySPTask = NULL;


struct Controller gControllers[NUM_PLAYERS];
Expand Down Expand Up @@ -137,7 +137,7 @@ struct SPTask *gGfxSPTask;
s32 D_801502A0;
s32 D_801502A4;
u16 *gPhysicalFramebuffers[3];
u32 D_801502B4;
uintptr_t gPhysicalZBuffer;
UNUSED u32 D_801502B8;
UNUSED u32 D_801502BC;
Mat4 D_801502C0;
Expand Down Expand Up @@ -368,7 +368,7 @@ void read_controllers(void) {
}

void func_80000BEC(void) {
D_801502B4 = VIRTUAL_TO_PHYSICAL(&gZBuffer);
gPhysicalZBuffer = VIRTUAL_TO_PHYSICAL(&gZBuffer);
}

void dispatch_audio_sptask(struct SPTask *spTask) {
Expand Down Expand Up @@ -538,7 +538,7 @@ void setup_game_memory(void) {
textureSegStart = (ptrdiff_t) SEG_RACING - commonCourseDataSize;
#else
textureSegStart = SEG_RACING - commonCourseDataSize;
#endif
#endif
osPiStartDma(&gDmaIoMesg, 0, 0, COMMON_TEXTURES_ROM_START, (void *) textureSegStart, commonCourseDataSize, &gDmaMesgQueue);
osRecvMesg(&gDmaMesgQueue, &gMainReceivedMesg, OS_MESG_BLOCK);

Expand Down
7 changes: 1 addition & 6 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ extern struct SPTask *gGfxSPTask;
extern s32 D_801502A0;
extern s32 D_801502A4;
extern u16 *gPhysicalFramebuffers[];
extern u32 D_801502B4;
extern uintptr_t gPhysicalZBuffer;
extern Mat4 D_801502C0;

extern s32 padding[];
Expand Down Expand Up @@ -231,9 +231,4 @@ extern f32 gCourseTimer;

// end of definition of main.c variables

extern u64 gGfxSPTaskOutputBuffer[];
extern u32 gGfxSPTaskOutputBufferSize;

extern u32 *D_801978D0; // Segment? Keeps track of segmented addresses?

#endif
2 changes: 1 addition & 1 deletion src/racing/math_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <main.h>
#include "buffers.h"
#include <PR/rcp.h>
#include "data/trig_tables.h"
#include "buffers/trig_tables.h"
#include "math.h"

#pragma intrinsic (sqrtf,fabs)
Expand Down
4 changes: 0 additions & 4 deletions src/racing/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,4 @@ f32 is_within_render_distance(Vec3f, Vec3f, u16, f32, f32, f32);
extern s32 D_802B91C0[];
extern Vec3f D_802B91C8;

// end of math_util.c variables

extern u16 gRandomSeed16;

#endif // MATH_UTIL_H
8 changes: 4 additions & 4 deletions src/racing/skybox_and_splitscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ void func_802A39E0(struct UnkStruct_800DC5EC *arg0) {

gDPPipeSync(gDisplayListHead++);
gDPSetCycleType(gDisplayListHead++, G_CYC_FILL);
gDPSetDepthImage(gDisplayListHead++, D_801502B4);
gDPSetColorImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, D_801502B4);
gDPSetDepthImage(gDisplayListHead++, gPhysicalZBuffer);
gDPSetColorImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, gPhysicalZBuffer);
gDPSetFillColor(gDisplayListHead++, 0xFFFCFFFC);
gDPPipeSync(gDisplayListHead++);
gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, ulx, uly, lrx, lry);
Expand All @@ -197,8 +197,8 @@ void func_802A39E0(struct UnkStruct_800DC5EC *arg0) {
void init_z_buffer(void) {
gDPPipeSync(gDisplayListHead++);
gDPSetCycleType(gDisplayListHead++, G_CYC_FILL);
gDPSetDepthImage(gDisplayListHead++, D_801502B4);
gDPSetColorImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, D_801502B4);
gDPSetDepthImage(gDisplayListHead++, gPhysicalZBuffer);
gDPSetColorImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, gPhysicalZBuffer);
gDPSetFillColor(gDisplayListHead++, 0xFFFCFFFC);
gDPPipeSync(gDisplayListHead++);
gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
Expand Down
Loading

0 comments on commit c4d596d

Please sign in to comment.