Skip to content

Commit

Permalink
Merge branch 'port' into port
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfdsfgs authored Aug 20, 2023
2 parents 93679e6 + 170f264 commit d007550
Show file tree
Hide file tree
Showing 42 changed files with 367 additions and 492 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ else ifeq ($(COMPILER), gcc)

$(C_O_FILES): OPT_LVL := $(GCC_OPT_LVL)

CFLAGS := $(C_DEFINES) -DAVOID_UB=1 $(INCLUDES) \
C_DEFINES += -DAVOID_UB

CFLAGS := $(C_DEFINES) $(INCLUDES) \
-EB \
-march=vr4300 \
-mabi=32 \
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ There are currently no "extra features" implemented
except for janky mouselook, arbitrary resolution support (with partial widescreen support)
and somewhat expanded heap size.

## Download

Latest [automatic builds](https://github.com/fgsfdsfgs/perfect_dark/actions) for supported platforms:
* [i686-windows](https://nightly.link/fgsfdsfgs/perfect_dark/workflows/c-cpp/port/pd-i686-windows.zip)
* [i686-linux](https://nightly.link/fgsfdsfgs/perfect_dark/workflows/c-cpp/port/pd-i686-linux.zip)

## Running

You can get the latest Windows and Linux binaries from the latest CI run in the Actions tab.
Note that you must already have a Perfect Dark ROM to run the game, as specified above.
You must already have a Perfect Dark ROM to run the game, as specified above.

1. Create a directory named `data` next to `pd.exe`.
2. Put your Perfect Dark ROM named `pd.ntsc-final.z64` into it.
Expand Down
4 changes: 3 additions & 1 deletion port/fast3d/gfx_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ static uint32_t gfx_cm_to_opengl(uint32_t val) {
}

static void gfx_opengl_set_sampler_parameters(int tile, bool linear_filter, uint32_t cms, uint32_t cmt) {
const GLint filter = linear_filter && current_filter_mode == FILTER_LINEAR ? GL_LINEAR : GL_NEAREST;
const GLint filter = linear_filter && (current_filter_mode == FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST;
glActiveTexture(GL_TEXTURE0 + tile);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
Expand Down Expand Up @@ -972,11 +972,13 @@ void gfx_opengl_clear_framebuffer() {
void gfx_opengl_resolve_msaa_color_buffer(int fb_id_target, int fb_id_source) {
Framebuffer& fb_dst = framebuffers[fb_id_target];
Framebuffer& fb_src = framebuffers[fb_id_source];
glDisable(GL_SCISSOR_TEST);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb_dst.fbo);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb_src.fbo);
glBlitFramebuffer(0, 0, fb_src.width, fb_src.height, 0, 0, fb_dst.width, fb_dst.height, GL_COLOR_BUFFER_BIT,
GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, current_framebuffer);
glEnable(GL_SCISSOR_TEST);
}

void* gfx_opengl_get_framebuffer_texture_id(int fb_id) {
Expand Down
17 changes: 4 additions & 13 deletions port/fast3d/gfx_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "gfx_screen_config.h"

uintptr_t gfxFramebuffer;
std::stack<std::string> currentDir;

using namespace std;

Expand Down Expand Up @@ -1769,13 +1768,11 @@ static void gfx_dp_set_scissor(uint32_t mode, uint32_t ulx, uint32_t uly, uint32
rdp.viewport_or_scissor_changed = true;
}

static void gfx_dp_set_texture_image(uint32_t format, uint32_t size, uint32_t width, const char* texPath,
uint32_t texFlags, RawTexMetadata rawTexMetdata, const void* addr) {
static void gfx_dp_set_texture_image(uint32_t format, uint32_t size, uint32_t width, uint32_t tex_flags, const void* addr) {
rdp.texture_to_load.addr = (const uint8_t*)addr;
rdp.texture_to_load.siz = size;
rdp.texture_to_load.width = width;
rdp.texture_to_load.tex_flags = texFlags;
rdp.texture_to_load.raw_tex_metadata = rawTexMetdata;
rdp.texture_to_load.tex_flags = tex_flags;
}

static void gfx_dp_set_tile(uint8_t fmt, uint32_t siz, uint32_t line, uint32_t tmem, uint8_t tile, uint32_t palette,
Expand Down Expand Up @@ -2385,16 +2382,12 @@ static void gfx_run_dl(Gfx* cmd) {
#endif
break;
case G_COL:
gfx_sp_set_vertex_colors(C0(0, 16) / 4, (struct NormalColor *)seg_addr(cmd->words.w1));
gfx_sp_set_vertex_colors(C0(0, 16) / 4, (NormalColor *)seg_addr(cmd->words.w1));
break;

// RDP Commands:
case G_SETTIMG: {
uintptr_t i = (uintptr_t)seg_addr(cmd->words.w1);
char* imgData = (char*)i;
uint32_t texFlags = 0;
RawTexMetadata rawTexMetdata = {};
gfx_dp_set_texture_image(C0(21, 3), C0(19, 2), C0(0, 10), imgData, texFlags, rawTexMetdata, (void*)i);
gfx_dp_set_texture_image(C0(21, 3), C0(19, 2), C0(0, 10), 0, seg_addr(cmd->words.w1));
break;
}
case G_SETTIMG_FB_EXT:
Expand Down Expand Up @@ -2559,7 +2552,6 @@ extern "C" void gfx_init(struct GfxWindowManagerAPI* wapi, struct GfxRenderingAP
gfx_rapi->init();
gfx_rapi->update_framebuffer_parameters(0, width, height, 1, false, true, true, true);
gfx_current_dimensions.internal_mul = 1;
gfx_msaa_level = 1;
gfx_current_game_window_viewport.width = gfx_current_dimensions.width = width;
gfx_current_game_window_viewport.height = gfx_current_dimensions.height = height;
game_framebuffer = gfx_rapi->create_framebuffer();
Expand Down Expand Up @@ -2676,7 +2668,6 @@ extern "C" void gfx_run(Gfx* commands) {
gfx_run_dl(commands);
gfx_flush();
gfxFramebuffer = 0;
currentDir = std::stack<std::string>();

if (game_renders_to_framebuffer) {
gfx_rapi->start_draw_to_framebuffer(0, 1);
Expand Down
2 changes: 1 addition & 1 deletion port/fast3d/gfx_rendering_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct GfxClipParameters {
bool invert_y;
};

enum FilteringMode { FILTER_THREE_POINT, FILTER_LINEAR, FILTER_NONE };
enum FilteringMode { FILTER_NONE, FILTER_LINEAR, FILTER_THREE_POINT };

struct GfxRenderingAPI {
const char* (*get_name)(void);
Expand Down
4 changes: 4 additions & 0 deletions port/include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ void sysFatalError(const char *fmt, ...) __attribute__((noreturn));

void sysGetExecutablePath(char *outPath, const u32 outLen);

void *sysMemAlloc(const u32 size);
void *sysMemZeroAlloc(const u32 size);
void sysMemFree(void *ptr);

#endif
14 changes: 12 additions & 2 deletions port/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,27 @@ struct configentry {
{ "Video.VSync", CONFIG_S32, { .s32val = 1 } },
{ "Video.FramerateLimit", CONFIG_S32, { .s32val = 0 } },
{ "Video.FovY", CONFIG_F32, { .f32val = 60.f } },
{ "Video.TextureFilter", CONFIG_S32, { .s32val = 1 } },
{ "Video.MSAA", CONFIG_S32, { .s32val = 0 } },
/* Audio */
{ "Audio.BufferSize", CONFIG_S32, { .s32val = 512 } },
{ "Audio.QueueLimit", CONFIG_S32, { .s32val = 8192 } },
/* Input */
{ "Input.MouseEnabled", CONFIG_S32, { .s32val = 1 } },
{ "Input.MouseSpeedX", CONFIG_F32, { .f32val = 1.5f } },
{ "Input.MouseSpeedY", CONFIG_F32, { .f32val = 1.5f } },
{ "Input.LStickDeadzone", CONFIG_S32, { .s32val = 4096 } },
{ "Input.RStickDeadzone", CONFIG_S32, { .s32val = 4096 } },
{ "Input.LStickDeadzoneX", CONFIG_S32, { .s32val = 4096 } },
{ "Input.LStickDeadzoneY", CONFIG_S32, { .s32val = 4096 } },
{ "Input.LStickScaleX", CONFIG_F32, { .f32val = 1.f } },
{ "Input.LStickScaleY", CONFIG_F32, { .f32val = 1.f } },
{ "Input.RStickDeadzoneX", CONFIG_S32, { .s32val = 4096 } },
{ "Input.RStickDeadzoneY", CONFIG_S32, { .s32val = 6144 } },
{ "Input.RStickScaleX", CONFIG_F32, { .f32val = 1.f } },
{ "Input.RStickScaleY", CONFIG_F32, { .f32val = 1.f } },
{ "Input.SwapSticks", CONFIG_S32, { .s32val = 1 } },
{ "Input.RumbleScale", CONFIG_F32, { .f32val = 0.333f } },
{ "Input.FirstGamepadNum", CONFIG_S32, { .s32val = 0 } },
{ "Input.FakeGamepads", CONFIG_S32, { .s32val = 0 } },
/* Game */
{ "Game.BaseDir", CONFIG_STR, { .strval = "./data" } },
{ "Game.MemorySize", CONFIG_S32, { .s32val = 16 } },
Expand Down
2 changes: 1 addition & 1 deletion port/src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void *fsFileLoad(const char *name, u32 *outSize)

void *buf = NULL;
if (size) {
buf = calloc(1, size + 1); // sick hack for a free null terminator
buf = sysMemZeroAlloc(size + 1); // sick hack for a free null terminator
if (!buf) {
fprintf(stderr, "fsFileLoad: could not alloc %d bytes for file: %s\n", size, fullName);
fclose(f);
Expand Down
Loading

0 comments on commit d007550

Please sign in to comment.