Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ project(butterscotch C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
add_compile_options(-Wall -Wextra -Werror -Wno-error=unused-parameter -Wno-error=unused-variable -Wno-error=unused-const-variable -Wno-error=unused-function)
add_compile_options(-Wall -Wextra -Werror)

set(PLATFORM "desktop" CACHE STRING "Platform backend")
set(DESKTOP_BACKEND "" CACHE STRING "Desktop platform backend")
Expand Down
3 changes: 3 additions & 0 deletions src/audio/miniaudio/ma_audio_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#include "stb_vorbis.c"

#define MINIAUDIO_IMPLEMENTATION
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "miniaudio.h"
#pragma GCC diagnostic pop

#include "ma_audio_system.h"
#include "data_win.h"
Expand Down
2 changes: 1 addition & 1 deletion src/audio/openal/al_audio_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ static float maGetSoundLength(AudioSystem* audio, int32_t soundOrInstance) {
}

static void maSetMasterGain(AudioSystem* audio, float gain) {
AlAudioSystem* ma = (AlAudioSystem*) audio;
(void)audio;
alListenerf(AL_GAIN, gain);
}

Expand Down
12 changes: 5 additions & 7 deletions src/gl/gl_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,7 @@ static void glGpuSetShader(Renderer* renderer, int32_t ShaderIndex) {
GLint gm_Matrices3 = glGetUniformLocation(Shader, "gm_Matrices[3]");
GLint gm_Matrices4 = glGetUniformLocation(Shader, "gm_Matrices[4]");


GLint gm_FogStart = glGetUniformLocation(Shader, "gm_FogStart");
GLint gm_RcpFogRange = glGetUniformLocation(Shader, "gm_RcpFogRange");
GLint gm_PS_FogEnabled = glGetUniformLocation(Shader, "gm_PS_FogEnabled");
GLint gm_FogColour = glGetUniformLocation(Shader, "gm_FogColour");
GLint gm_VS_FogEnabled = glGetUniformLocation(Shader, "gm_VS_FogEnabled");

//Lights are for another time

Expand Down Expand Up @@ -1803,6 +1798,9 @@ static void glDrawSurface(Renderer* renderer, int32_t surfaceID, int32_t srcLeft
}

static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID, int32_t x, int32_t y, int32_t w, int32_t h, bool removeback, bool smooth, int32_t xorig, int32_t yorig) {
// TODO: implement these
(void)smooth;
(void)removeback;
GLRenderer* gl = (GLRenderer*) renderer;
DataWin* dw = renderer->dataWin;

Expand Down Expand Up @@ -1927,7 +1925,7 @@ static void glGpuSetBlendEnable(Renderer* renderer, bool enable) {
}

static bool glGpuGetBlendEnable(Renderer* renderer) {

(void)renderer;
return glIsEnabled(GL_BLEND);
}

Expand Down Expand Up @@ -2220,7 +2218,7 @@ static bool glShaderIsCompiled(Renderer* renderer, int32_t shaderID) {
return gl->gmlShaderCompiled[shaderID];
}

static bool glShadersSupported(Renderer* renderer) {
static bool glShadersSupported(void) {
return true;
}

Expand Down
8 changes: 6 additions & 2 deletions src/gl_legacy/gl_legacy_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,9 @@ static uint32_t findOrAllocTpagSlot(DataWin* dw, uint32_t originalTpagCount) {
}

static int32_t glCreateSpriteFromSurface(Renderer* renderer, int32_t surfaceID, int32_t x, int32_t y, int32_t w, int32_t h, bool removeback, bool smooth, int32_t xorig, int32_t yorig) {
// TODO: implement these
(void)smooth;
(void)removeback;
GLLegacyRenderer* gl = (GLLegacyRenderer*) renderer;
DataWin* dw = renderer->dataWin;

Expand Down Expand Up @@ -1340,7 +1343,8 @@ static void glGpuSetBlendModeExt(MAYBE_UNUSED Renderer* renderer, int32_t sfacto
glBlendFunc(GLCommon_blendFactorToGL(sfactor), GLCommon_blendFactorToGL(dfactor));
}

static void glGpuSetBlendEnable(MAYBE_UNUSED Renderer* renderer, bool enable) {
static void glGpuSetBlendEnable(Renderer* renderer, bool enable) {
(void)renderer;
enable ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
}

Expand Down Expand Up @@ -1680,7 +1684,7 @@ static void glShaderSetUniformF(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED in
static void glShaderSetUniformFArray(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t handle, MAYBE_UNUSED float* values, MAYBE_UNUSED uint32_t count) {}
static void glShaderSetUniformI(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t handle, MAYBE_UNUSED int32_t count, MAYBE_UNUSED int32_t value1, MAYBE_UNUSED int32_t value2, MAYBE_UNUSED int32_t value3, MAYBE_UNUSED int32_t value4) {}
static bool glShaderIsCompiled(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t shader) { return false; }
static bool glShadersSupported(MAYBE_UNUSED Renderer* renderer) { return false; }
static bool glShadersSupported(void) { return false; }

static RendererVtable glVtable;

Expand Down
14 changes: 11 additions & 3 deletions src/ps2/gs_renderer.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#include "gs_renderer.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <gsInline.h>
#pragma GCC diagnostic pop

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <malloc.h>
#include <kernel.h>
#include <gsInline.h>

#include "binary_reader.h"
#include "binary_utils.h"
Expand Down Expand Up @@ -2877,7 +2881,11 @@ static void gsDrawSurface(Renderer* renderer, int32_t surfaceID, int32_t srcLeft
// Restore default REPEAT so subsequent atlas draws aren't stuck on this region.
gsKit_set_clamp(gs->gsGlobal, GS_CMODE_REPEAT);
}
static void gsSurfaceResize(MAYBE_UNUSED Renderer* renderer, int32_t surfaceID, int32_t width, int32_t height) {
static void gsSurfaceResize(Renderer* renderer, int32_t surfaceID, int32_t width, int32_t height) {
(void)renderer;
(void)surfaceID;
(void)width;
(void)height;
// No-op: PS2 doesn't actually resize anything
}

Expand Down Expand Up @@ -3052,7 +3060,7 @@ static void gsShaderSetUniformF(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED in
static void gsShaderSetUniformFArray(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t handle, MAYBE_UNUSED float* values, MAYBE_UNUSED uint32_t count) {}
static void gsShaderSetUniformI(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t handle, MAYBE_UNUSED int32_t count, MAYBE_UNUSED int32_t value1, MAYBE_UNUSED int32_t value2, MAYBE_UNUSED int32_t value3, MAYBE_UNUSED int32_t value4) {}
static bool gsShaderIsCompiled(MAYBE_UNUSED Renderer* renderer, MAYBE_UNUSED int32_t shader) { return false; }
static bool gsShadersSupported(MAYBE_UNUSED Renderer* renderer) { return false; }
static bool gsShadersSupported(void) { return false; }

static RendererVtable gsVtable;

Expand Down
2 changes: 1 addition & 1 deletion src/ps2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ static unsigned int hidUsageToAsciiChar(uint8_t hid, bool shift) {


int main(int argc, char* argv[]) {
(void)argc;
SifInitRpc(0);
sbv_patch_enable_lmb();

Expand Down Expand Up @@ -552,7 +553,6 @@ int main(int argc, char* argv[]) {
// ===[ Main Loop ]===
bool debugOverlayStartEnabled = JsonReader_getBool(JsonReader_getObject(configRoot, "debugOverlayEnabled"));
PS2Overlay_setDebugOverlayState(debugOverlayStartEnabled ? STATS_ENABLED : STATS_DISABLED, runner);
uint16_t prevOverlayPadButtons = 0xFFFF;

u64 lastFrameStartTime = GetTimerSystemTime(); // for delta_time
while (!runner->shouldExit) {
Expand Down
10 changes: 9 additions & 1 deletion src/ps2/ps2_file_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,18 +486,26 @@ static void ps2BinaryRewrite(MAYBE_UNUSED FileSystem* fs, void* handle) {

//Directory, pretty much stubbed
static bool ps2DirectoryExists(FileSystem* fs, const char* relativePath) {
(void)fs;
(void)relativePath;
return true;
}

static bool ps2CreateDirectory(FileSystem* fs, const char* relativePath) {
(void)fs;
(void)relativePath;
return true;
}

static bool ps2DeleteDirectory(FileSystem* fs, const char* relativePath) {
(void)fs;
(void)relativePath;
return true;
}

static FileSystemDirEntry* ps2ListDirectory(MAYBE_UNUSED FileSystem* fs, MAYBE_UNUSED const char* relativeDirPath) {
static FileSystemDirEntry* ps2ListDirectory(FileSystem* fs, const char* relativeDirPath) {
(void)fs;
(void)relativeDirPath;
return nullptr;
}

Expand Down
5 changes: 4 additions & 1 deletion src/ps2/ps2_overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

// ===[ Loading Screen ]===

static const int PROFILER_WINDOW_FRAMES = 60;
static bool gPS2OverlayInitialized = false;
static PS2Overlay gOverlay = { 0 };

Expand Down Expand Up @@ -113,6 +112,8 @@ void PS2Overlay_setDebugOverlayState(DebugOverlayState state, Runner* runner) {
Profiler_setEnabled(&runner->vmContext->profiler, PS2Overlay_getDebugOverlayState() == STATS_ENABLED_WITH_PROFILER);
gOverlay.profilerFramesInWindow = 0;
gOverlay.profilerOverlayText[0] = '\0';
#else
(void)runner;
#endif
}

Expand All @@ -124,6 +125,8 @@ void PS2Overlay_toggleDebugOverlay(Runner* runner) {
Profiler_setEnabled(&runner->vmContext->profiler, PS2Overlay_getDebugOverlayState() == STATS_ENABLED_WITH_PROFILER);
gOverlay.profilerFramesInWindow = 0;
gOverlay.profilerOverlayText[0] = '\0';
#else
(void)runner;
#endif
}

Expand Down
5 changes: 4 additions & 1 deletion src/ps3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ bool shouldExit = false;
// ===[ MAIN ]===

static void sys_callback(uint64_t status, uint64_t param, void* userdata) {
(void)param;
(void)userdata;
switch (status) {
case SYSUTIL_EXIT_GAME:
shouldExit = true;
Expand Down Expand Up @@ -156,7 +158,8 @@ char *str_replace(char *orig, char *rep, char *with) {
static char buffer[9999];
int main(int argc, char* argv[]) {
printf("%s\n", argv[0]);
strcpy(buffer, argv[0]);
if (argc > 0)
strcpy(buffer, argv[0]);
char* tmp = str_replace(buffer, "butterscotch.elf", "");
char* tmp2 = str_replace(tmp, "butterscotch.self", "");
char* tmp3 = str_replace(tmp2, "EBOOT.BIN", "");
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ typedef struct {
bool (*textureGetUVs)(Renderer* renderer, uint32_t texID, float* outUVs);
void (*textureSetStage)(Renderer* renderer, int32_t slot, uint32_t texID);
bool (*shaderIsCompiled)(Renderer* renderer, int32_t shader);
bool (*shadersSupported)(Renderer* renderer);
bool (*shadersSupported)(void);
} RendererVtable;

// ===[ Renderer Base Struct ]===
Expand Down
2 changes: 2 additions & 0 deletions src/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ static inline void Runner_setActiveState(Runner* runner, Instance* instance, boo
fprintf(stderr, "VM: Instance %s (instanceId=%d,objectIndex=%d) marked as %s at (%f, %f)\n", objDef->name, instance->instanceId, instance->objectIndex, active ? "active" : "inactive", instance->x, instance->y);
}
}
#else
(void)runner;
#endif

instance->active = active;
Expand Down
27 changes: 19 additions & 8 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,15 @@ static int32_t stackPopInt32(VMContext* ctx) {
return value;
}

#if IS_WAD17_OR_HIGHER_ENABLED

static RValue* stackPeek(VMContext* ctx) {
require(ctx->stack.top > 0);
return &ctx->stack.slots[ctx->stack.top - 1];
}

#endif

// ===[ Instruction Decoding ]===

static uint8_t instrOpcode(uint32_t instr) {
Expand Down Expand Up @@ -267,6 +271,7 @@ static GMLArray* VM_arraySetWithCoW(VMContext* ctx, RValue* slot, int32_t index,
#if IS_WAD17_OR_HIGHER_ENABLED
intendedOwner = IS_WAD17_OR_HIGHER(ctx) ? ctx->currentArrayOwner : (void*) slot;
#else
(void)ctx;
intendedOwner = (void*) slot;
#endif

Expand Down Expand Up @@ -418,11 +423,15 @@ static ArrayAccess popArrayAccess(VMContext* ctx, uint32_t varRef) {
// ===[ Variable Resolution ]===

// Returns the object name for an instance, or "<global_scope>" for the global scope dummy instance
#ifdef ENABLE_VM_TRACING

static const char* instanceObjectName(VMContext* ctx, Instance* inst) {
if (inst->objectIndex == STRUCT_OBJECT_INDEX) return "<global_scope>";
return ctx->dataWin->objt.objects[inst->objectIndex].name;
}

#endif

static Variable* resolveVarDef(VMContext* ctx, uint32_t varRef) {
uint32_t varIndex = varRef & 0x07FFFFFF;
require(ctx->dataWin->vari.variableCount > varIndex);
Expand Down Expand Up @@ -638,6 +647,8 @@ static bool tryReadInstanceVarOrStatic(VMContext* ctx, Instance* instance, int32
*out = staticVal;
return true;
}
#else
(void)ctx;
#endif
return false;
}
Expand Down Expand Up @@ -1360,7 +1371,7 @@ static inline RValue coerceIntStoreToReal(RValue val, uint8_t type2) {
return val;
}

static void handlePop(VMContext* ctx, uint32_t instr, uint8_t type1, uint8_t type2, uint32_t varRef, uint8_t varType, int32_t instanceType) {
static void handlePop(VMContext* ctx, uint8_t type1, uint8_t type2, uint32_t varRef, uint8_t varType, int32_t instanceType) {
RValue val;
int32_t arrayIndex = -1;

Expand Down Expand Up @@ -3016,7 +3027,7 @@ static RValue executeLoop(VMContext* ctx) {
val = coerceIntStoreToReal(val, type2);
resolveVariableWrite(ctx, instanceType, varRef, val);
} else {
handlePop(ctx, instr, type1, type2, varRef, varType, instanceType);
handlePop(ctx, type1, type2, varRef, varType, instanceType);
}
break;
}
Expand Down Expand Up @@ -3926,7 +3937,7 @@ static void disasmFormatVar(VMContext* ctx, const uint8_t* extraData, const char
}

// Returns stack effect comment for a variable access instruction
static void disasmFormatVarComment(VMContext* ctx, const uint8_t* extraData, bool isPop, char* buf, size_t bufSize) {
static void disasmFormatVarComment(const uint8_t* extraData, bool isPop, char* buf, size_t bufSize) {
uint32_t varRef = resolveVarOperand(extraData);
uint8_t varType = (varRef >> 24) & 0xF8;
if (isPop) {
Expand Down Expand Up @@ -4038,7 +4049,7 @@ static void formatInstruction(VMContext* ctx, const uint8_t* bytecodeBase, uint3
case GML_TYPE_VARIABLE:
snprintf(opcodeStr, opcodeSize, "Push.v");
disasmFormatVar(ctx, extraData, nullptr, (int32_t) instType, operandStr, operandSize);
disasmFormatVarComment(ctx, extraData, false, commentStr, commentSize);
disasmFormatVarComment(extraData, false, commentStr, commentSize);
break;
case GML_TYPE_INT16:
snprintf(opcodeStr, opcodeSize, "Push.e");
Expand All @@ -4057,17 +4068,17 @@ static void formatInstruction(VMContext* ctx, const uint8_t* bytecodeBase, uint3
case OP_PUSHLOC:
snprintf(opcodeStr, opcodeSize, "PushLoc.v");
disasmFormatVar(ctx, extraData, "local", (int32_t) instType, operandStr, operandSize);
disasmFormatVarComment(ctx, extraData, false, commentStr, commentSize);
disasmFormatVarComment(extraData, false, commentStr, commentSize);
break;
case OP_PUSHGLB:
snprintf(opcodeStr, opcodeSize, "PushGlb.v");
disasmFormatVar(ctx, extraData, "global", (int32_t) instType, operandStr, operandSize);
disasmFormatVarComment(ctx, extraData, false, commentStr, commentSize);
disasmFormatVarComment(extraData, false, commentStr, commentSize);
break;
case OP_PUSHBLTN:
snprintf(opcodeStr, opcodeSize, "PushBltn.v");
disasmFormatVar(ctx, extraData, nullptr, (int32_t) instType, operandStr, operandSize);
disasmFormatVarComment(ctx, extraData, false, commentStr, commentSize);
disasmFormatVarComment(extraData, false, commentStr, commentSize);
break;

// PushI (int16 immediate)
Expand All @@ -4081,7 +4092,7 @@ static void formatInstruction(VMContext* ctx, const uint8_t* bytecodeBase, uint3
case OP_POP:
snprintf(opcodeStr, opcodeSize, "Pop.%c.%c", gmlTypeChar(type1), gmlTypeChar(type2));
disasmFormatVar(ctx, extraData, nullptr, (int32_t) instType, operandStr, operandSize);
disasmFormatVarComment(ctx, extraData, true, commentStr, commentSize);
disasmFormatVarComment(extraData, true, commentStr, commentSize);
break;

// Unconditional branch
Expand Down
Loading
Loading