Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ else()
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${COMMON_CXX_FLAGS}")
endif()

# Toggle for GLES (Required for many ARM/Mobile platforms)
option(USE_OPENGLES "Use OpenGLES instead of Desktop OpenGL" OFF)

# Set game compilation version
set(VERSION us)
set(USE_NETWORKING OFF)
Expand All @@ -189,6 +192,7 @@ set(GFX_DEBUG_DISASSEMBLER OFF)
# Add compile definitions for the target
add_compile_definitions(
VERSION_US=1
$<$<BOOL:${USE_OPENGLES}>:USE_OPENGLES>
ENABLE_RUMBLE=1
F3DEX_GBI=1
_LANGUAGE_C
Expand All @@ -200,10 +204,6 @@ add_compile_definitions(
SPAGHETTI_VERSION="${PROJECT_VERSION}"
)

# Find necessary libraries
if (UNIX AND NOT APPLE)
find_package(OpenGL REQUIRED)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/properties.h.in ${CMAKE_CURRENT_SOURCE_DIR}/properties.h @ONLY)
Expand Down Expand Up @@ -319,6 +319,18 @@ else()
add_executable(${PROJECT_NAME} ${ALL_FILES})
endif()

################################################################################
# OpenGL / OpenGLES library
################################################################################
if (UNIX AND NOT APPLE)
if (USE_OPENGLES)
find_library(GLESv2_LIBRARY GLESv2 REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ${GLESv2_LIBRARY})
else()
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)
endif()
endif()

################################################################################
# MSVC runtime library
Expand Down Expand Up @@ -402,10 +414,13 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/libultraship/include
${CMAKE_CURRENT_SOURCE_DIR}/libultraship/include/libultraship
${SDL2_INCLUDE_DIRS}
${GLEW_INCLUDE_DIRS}
${dr_libs_SOURCE_DIR}
)

if (NOT USE_OPENGLES)
include_directories(${GLEW_INCLUDE_DIRS})
endif()

add_subdirectory(libultraship ${CMAKE_CURRENT_SOURCE_DIR}/libultraship)
add_dependencies(${PROJECT_NAME} libultraship)
target_link_libraries(${PROJECT_NAME} PRIVATE libultraship)
Expand Down Expand Up @@ -516,8 +531,10 @@ option(USE_STANDALONE "Build as a standalone executable" OFF)
option(BUILD_STORMLIB "Build with StormLib support" OFF)

option(BUILD_SM64 "Build with Super Mario 64 support" OFF)
option(BUILD_MK64 "Build with Mario Kart 64 support" ON)
option(BUILD_SF64 "Build with Star Fox 64 support" OFF)
option(BUILD_FZERO "Build with F-Zero X support" OFF)
option(BUILD_MARIO_ARTIST "Build with Mario Artist support" OFF)

add_subdirectory(torch)
target_link_libraries(${PROJECT_NAME} PRIVATE torch "${ADDITIONAL_LIBRARY_DEPENDENCIES}")
Expand Down
11 changes: 9 additions & 2 deletions include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,25 @@

// Align to 8-byte boundary for DMA requirements
#ifdef __GNUC__
#define ALIGNED8
#define ALIGNED8 __attribute__((aligned(8)))
#else
#define ALIGNED8
#endif

// Align to 16-byte boundary for audio lib requirements
#ifdef __GNUC__
#define ALIGNED16
#define ALIGNED16 __attribute__((aligned(16)))
#else
#define ALIGNED16
#endif

// Align to 4096-byte boundary for 64-bit page requirements
#ifdef __GNUC__
#define ALIGNED4096 __attribute__((aligned(4096)))
#else
#define ALIGNED4096
#endif

// Fixed point macros
#define FTOFIX(f) ((s32) ((f) * 65536.0))
#define ITOFIX(i) ((s32) ((i) << 16))
Expand Down
1 change: 0 additions & 1 deletion include/stubs.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <libultraship.h>

#ifdef _WIN32
#define bzero(b, len) (memset((b), '\0', (len)), (void) 0)
#define bcopy(b1, b2, len) (memmove((b2), (b1), (len)), (void) 0)
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/code_80005FD0.c
Original file line number Diff line number Diff line change
Expand Up @@ -3468,7 +3468,7 @@ void func_8000F124(void) {

// Delete track waypoints
void clear_path_point(TrackPathPoint* arg0, size_t size) {
bzero((void*) arg0, size * sizeof(TrackPathPoint));
memset((void*) arg0, 0, size * sizeof(TrackPathPoint));
}

// Appears to allocate memory for each track.
Expand Down
4 changes: 2 additions & 2 deletions src/code_8006E9C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void reset_object_variable(void) {
s32 j;
func_8006EB10();
clear_object_list();
bzero(playerHUD, HUD_PLAYERS_SIZE * sizeof(hud_player));
memset(playerHUD, 0, HUD_PLAYERS_SIZE * sizeof(hud_player));

for (i = 0; i < HUD_PLAYERS_SIZE; i++) {
playerHUD[i].lapCount = 0;
Expand Down Expand Up @@ -114,7 +114,7 @@ void func_8006EB10(void) {
}

void clear_object_list() {
bzero(gObjectList, OBJECT_LIST_SIZE * sizeof(Object));
memset(gObjectList, 0, OBJECT_LIST_SIZE * sizeof(Object));
objectListSize = -1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ending/podium_ceremony_actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ CeremonyActor* find_available_entry(void) {

// Find an inactive actor.
if ((actor->isActive & 1) == 0) {
bzero(actor, sizeof(CeremonyActor));
memset(actor, 0, sizeof(CeremonyActor));
actor->isActive = 1;
actor->unk24 = 1.0f;
return actor;
Expand Down Expand Up @@ -311,7 +311,7 @@ void unused_80280FA8(UNUSED CeremonyActor* actor) {
void balloons_and_fireworks_init(void) {
D_802874D8.actorTimer = 0;
sPodiumActorList = (CeremonyActor*) get_next_available_memory_addr(sizeof(CeremonyActor) * 200);
bzero(sPodiumActorList, (sizeof(CeremonyActor) * 200));
memset(sPodiumActorList, 0, (sizeof(CeremonyActor) * 200));
new_actor(&initDummy);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void display_and_vsync(void) {

void init_segment_ending_sequences(void) {
#ifdef TARGET_N64
bzero((void*) SEG_ENDING, SEG_ENDING_SIZE);
memset((void*) SEG_ENDING, 0, SEG_ENDING_SIZE);
osWritebackDCacheAll();
dma_copy((u8*) SEG_ENDING, (u8*) SEG_ENDING_ROM_START, SEG_ENDING_ROM_SIZE);
osInvalICache((void*) SEG_ENDING, SEG_ENDING_SIZE);
Expand All @@ -532,7 +532,7 @@ void init_segment_ending_sequences(void) {

void init_segment_racing(void) {
#ifdef TARGET_N64
bzero((void*) SEG_RACING, SEG_RACING_SIZE);
memset((void*) SEG_RACING, 0, SEG_RACING_SIZE);
osWritebackDCacheAll();
dma_copy((u8*) SEG_RACING, (u8*) SEG_RACING_ROM_START, SEG_RACING_ROM_SIZE);
osInvalICache((void*) SEG_RACING, SEG_RACING_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion src/os/__osViInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern OSViMode osViModeMpalLan1;
extern OSViMode osViModeNtscLan1;

void __osViInit(void) {
bzero(sViContexts, sizeof(sViContexts));
memset(sViContexts, 0, sizeof(sViContexts));
__osViCurr = &sViContexts[0];
__osViNext = &sViContexts[1];
__osViNext->retraceCount = 1;
Expand Down
1 change: 0 additions & 1 deletion src/os/bstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern "C" {

extern void bcopy(const void*, void*, size_t);
extern int bcmp(const void*, const void*, int);
extern void bzero(void*, size_t);
extern void blkclr(void*, int);

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/os/osCartRomInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ OSPiHandle* osCartRomInit(void) {
CartRomHandle.domain = PI_DOMAIN1;
// CartRomHandle.speed = 0;

bzero(&CartRomHandle.transferInfo, sizeof(__OSTranxInfo));
memset(&CartRomHandle.transferInfo, 0, sizeof(__OSTranxInfo));

saveMask = __osDisableInt();
CartRomHandle.next = __osPiTable;
Expand Down
2 changes: 1 addition & 1 deletion src/os/osInitialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void osInitialize(void) {
}
osClockRate = osClockRate * 3 / 4;
if (osResetType == RESET_TYPE_COLD_RESET) {
bzero(osAppNmiBuffer, sizeof(osAppNmiBuffer));
memset(osAppNmiBuffer, 0, sizeof(osAppNmiBuffer));
}

eu_sp30 = HW_REG(PI_STATUS_REG, u32);
Expand Down
2 changes: 1 addition & 1 deletion src/os/osLeoDiskInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ OSPiHandle* osLeoDiskInit(void) {
HW_REG(PI_BSD_DOM2_PWD_REG, u32) = LeoDiskHandle.pulse;
HW_REG(PI_BSD_DOM2_PGS_REG, u32) = LeoDiskHandle.pageSize;
HW_REG(PI_BSD_DOM2_RLS_REG, u32) = LeoDiskHandle.relDuration;
bzero(&LeoDiskHandle.transferInfo, sizeof(__OSTranxInfo));
memset(&LeoDiskHandle.transferInfo, 0, sizeof(__OSTranxInfo));
sp1c = __osDisableInt();
LeoDiskHandle.next = __osPiTable;
__osPiTable = &LeoDiskHandle;
Expand Down
2 changes: 1 addition & 1 deletion src/port/audio/HMAS.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct HMAS_Effect {
struct HMAS_ChannelInfo {
ma_sound* sound;

uint64_t cursor;
ma_uint64 cursor;
float pitch;
float volume;

Expand Down
21 changes: 10 additions & 11 deletions src/racing/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
s32 sGfxSeekPosition;
s32 sPackedSeekPosition;

static u8 sMemoryPool[0xFFFFFFF]; // Stock memory pool size: 0xAB630
static u8 sMemoryPool[0x10000000] ALIGNED4096;
Comment thread
JeodC marked this conversation as resolved.
uintptr_t sPoolEnd = sMemoryPool + sizeof(sMemoryPool);

uintptr_t sPoolFreeSpace;
Expand Down Expand Up @@ -88,17 +88,16 @@ static uintptr_t get_texture2(size_t offset, const course_texture* textures) {
* Default memory size, 701.984 Kilobytes.
*/
void initialize_memory_pool() {
// Clear pool
memset(sMemoryPool, 0, sizeof(sMemoryPool));

uintptr_t poolStart = sMemoryPool;
// uintptr_t sPoolEnd = sMemoryPool + sizeof(sMemoryPool);
// Force the pointer to be exactly at the start of the aligned array
uintptr_t poolStart = (uintptr_t)sMemoryPool;

// Ensure sPoolEnd is exactly at the end of the 256MB block
sPoolEnd = poolStart + sizeof(sMemoryPool);

bzero(sMemoryPool, sizeof(sMemoryPool));

poolStart = ALIGN16(poolStart);
// Truncate to a 16-byte boundary.
sPoolEnd &= ~0xF;

gFreeMemorySize = (sPoolEnd - poolStart) - 0x10;
gFreeMemorySize = sPoolEnd - poolStart;
gNextFreeMemoryAddress = poolStart;

PRINT_MEMPOOL;
Expand Down Expand Up @@ -309,7 +308,7 @@ u8* load_lakitu_tlut_x64(const char** textureList, size_t length) {
}

u8* textures = (u8*) gNextFreeMemoryAddress;
gNextFreeMemoryAddress += size;
gNextFreeMemoryAddress = ALIGN16(gNextFreeMemoryAddress + size);
size_t offset = 0;
for (size_t i = 0; i < length; i++) {
u8* tex = (u8*) LOAD_ASSET_RAW(textureList[i]);
Expand Down
Loading