Skip to content
Open
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ sm64config.txt
!/sound/**/*custom*/**/*.aiff
!/assets/**/*custom*.bin
!/assets/**/*custom*/**/*.bin

# PS2dev files
ps2dev*.tar.gz
ps2dev
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ TARGET_PS2 ?= 1
# Compiler to use (ido or gcc)
COMPILER ?= ido

GAME_CODE ?= SLUS_064.64

# Automatic settings only for ports
ifeq ($(TARGET_N64),0)

Expand Down Expand Up @@ -862,7 +864,7 @@ endif



.PHONY: all clean distclean default diff test load libultra
.PHONY: all clean distclean default diff test load libultra iso
# with no prerequisites, .SECONDARY causes no intermediate target to be removed
.SECONDARY:

Expand All @@ -872,3 +874,9 @@ MAKEFLAGS += --no-builtin-rules
-include $(DEP_FILES)

print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true

iso: $(ELF)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convinient way to create an ISO, perhaps mkiosfs needs to be added to the docker image?

@echo Creating iso from $(ELF)
@cp -r ps2/ntsc $(BUILD_DIR)/iso
@cp $< $(BUILD_DIR)/iso/$(GAME_CODE)
@mkisofs -o $(BUILD_DIR)/sm64.iso $(BUILD_DIR)/iso/
3 changes: 3 additions & 0 deletions ps2/ntsc/SYSTEM.CNF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BOOT2 = cdrom0:\SLUS_064.64;1
VER = 1.00
VMODE = NTSC
8 changes: 8 additions & 0 deletions src/game/area.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "save_file.h"
#include "level_table.h"

#ifdef TARGET_PS2
#include "pc/ps2_vid_mode_select.h"
#endif

struct SpawnInfo gPlayerSpawnInfos[1];
struct GraphNode *D_8033A160[0x100];
struct Area gAreaData[8];
Expand Down Expand Up @@ -383,6 +387,10 @@ void render_game(void) {
gSaveOptSelectIndex = gPauseScreenMode;
}

#ifdef TARGET_PS2
handle_ps2_vid_mode_select();
#endif

if (D_8032CE78 != NULL) {
make_viewport_clip_rect(D_8032CE78);
} else
Expand Down
17 changes: 16 additions & 1 deletion src/game/game_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#include "thread6.h"
#include <prevent_bss_reordering.h>

#ifdef TARGET_PS2
#include "pc/ps2_vid_mode_select.h"
#endif


// FIXME: I'm not sure all of these variables belong in this file, but I don't
// know of a good way to split them
struct Controller gControllers[3];
Expand Down Expand Up @@ -480,7 +485,11 @@ void read_controller_inputs(void) {

// if any controllers are plugged in, update the
// controller information.
if (gControllerBits) {
if (gControllerBits
#ifndef TARGET_N64
&& !gDisableInput
#endif
) {
osRecvMesg(&gSIEventMesgQueue, &D_80339BEC, OS_MESG_BLOCK);
osContGetReadData(&gControllerPads[0]);
#ifdef VERSION_SH
Expand Down Expand Up @@ -602,6 +611,12 @@ void thread5_game_loop(UNUSED void *arg) {
#endif
save_file_load_all();

#ifdef TARGET_PS2
// Must be called after save file loaded to
// configure preferred video mode
ps2_vid_mode_select_init();
#endif

set_vblank_handler(2, &gGameVblankHandler, &gGameVblankQueue, (OSMesg) 1);

// point levelCommandAddr to the entry point into the level script data.
Expand Down
1 change: 1 addition & 0 deletions src/game/ingame_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ extern s8 gRedCoinsCollected;

void create_dl_identity_matrix(void);
void create_dl_translation_matrix(s8 pushOp, f32 x, f32 y, f32 z);
void create_dl_scale_matrix(s8 pushOp, f32 x, f32 y, f32 z);
void create_dl_ortho_matrix(void);
void print_generic_string(s16 x, s16 y, const u8 *str);
void print_hud_lut_string(s8 hudLUT, s16 x, s16 y, const u8 *str);
Expand Down
4 changes: 4 additions & 0 deletions src/game/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ s8 D_8032C650 = 0;
s8 gShowProfiler = FALSE;
s8 gShowDebugText = FALSE;

#ifndef TARGET_N64
s8 gDisableInput = FALSE;
#endif

// unused
void handle_debug_key_sequences(void) {
static u16 sProfilerKeySequence[] = {
Expand Down
3 changes: 3 additions & 0 deletions src/game/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ extern s8 gDebugLevelSelect;
extern s8 D_8032C650;
extern s8 gShowProfiler;
extern s8 gShowDebugText;
#ifndef TARGET_N64
extern s8 gDisableInput;
#endif

void set_vblank_handler(s32 index, struct VblankHandler *handler, OSMesgQueue *queue, OSMesg *msg);
void dispatch_audio_sptask(struct SPTask *spTask);
Expand Down
17 changes: 17 additions & 0 deletions src/game/save_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,23 @@ u16 save_file_get_sound_mode(void) {
return gSaveBuffer.menuData[0].soundMode;
}

#ifdef TARGET_PS2
void save_file_set_ps2_vid_mode(u16 mode) {
gSaveBuffer.menuData[0].ps2VidMode = mode;
gSaveBuffer.menuData[0].ps2VidModeSet = 1;

gMainMenuDataModified = TRUE;
save_main_menu_data();
}

u16 save_file_get_ps2_vid_mode(void) {
if (gSaveBuffer.menuData[0].ps2VidModeSet == 1) {
return gSaveBuffer.menuData[0].ps2VidMode;
}
return (u16)-1;
}
#endif

void save_file_move_cap_to_default_location(void) {
if (save_file_get_flags() & SAVE_FLAG_CAP_ON_GROUND) {
switch (gSaveBuffer.files[gCurrSaveFileNum - 1][0].capLevel) {
Expand Down
18 changes: 18 additions & 0 deletions src/game/save_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,23 @@ struct MainMenuSaveData

#ifdef VERSION_EU
u16 language;
#endif

#ifdef TARGET_PS2
// u16 for consistency, like why is language u16?
u16 ps2VidMode;
u16 ps2VidModeSet;
#ifdef VERSION_EU
#define SUBTRAHEND 12
#else
#define SUBTRAHEND 10
#endif
#else
#ifdef VERSION_EU
#define SUBTRAHEND 8
#else
#define SUBTRAHEND 6
#endif
#endif

// Pad to match the EEPROM size of 0x200 (10 bytes on JP/US, 8 bytes on EU)
Expand Down Expand Up @@ -143,6 +157,10 @@ void save_file_set_cap_pos(s16 x, s16 y, s16 z);
s32 save_file_get_cap_pos(Vec3s capPos);
void save_file_set_sound_mode(u16 mode);
u16 save_file_get_sound_mode(void);
#ifdef TARGET_PS2
void save_file_set_ps2_vid_mode(u16 mode);
u16 save_file_get_ps2_vid_mode(void);
#endif
void save_file_move_cap_to_default_location(void);

void disable_warp_checkpoint(void);
Expand Down
2 changes: 2 additions & 0 deletions src/pc/controller/controller_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
struct ControllerAPI {
void (*init)(void);
void (*read)(OSContPad *pad);
// returns the raw button values for this controller
u32 (*read_btns)(void);
};

#endif
12 changes: 11 additions & 1 deletion src/pc/controller/controller_ps2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <libpad.h>
#include <libmtap.h>

#include "controller_ps2.h"
#include "controller_api.h"

#define DEADZONE 24
Expand Down Expand Up @@ -142,7 +143,16 @@ static void controller_ps2_read(OSContPad *pad) {
}
}

u32 controller_ps2_read_btns(void) {
if (joy_id > -1 && padRead(joy_port, joy_slot, &joy_buttons)) {
const u32 btns = 0xffff ^ joy_buttons.btns;
return btns;
}
return 0;
}

struct ControllerAPI controller_ps2 = {
controller_ps2_init,
controller_ps2_read
controller_ps2_read,
controller_ps2_read_btns,
};
1 change: 1 addition & 0 deletions src/pc/controller/controller_ps2.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CONTROLLER_PS2_H
#define CONTROLLER_PS2_H

#include <libpad.h>
#include "controller_api.h"

extern struct ControllerAPI controller_ps2;
Expand Down
9 changes: 7 additions & 2 deletions src/pc/gfx/gfx_pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ static struct ColorCombiner *gfx_lookup_or_create_color_combiner(uint32_t cc_id)
return prev_combiner = comb;
}

void gfx_clear_texture_cache(void) {
if (gfx_rapi->flush_textures) gfx_rapi->flush_textures();
gfx_texture_cache.pool_pos = 0;
}

static bool gfx_texture_cache_lookup(int tile, struct TextureHashmapNode **n, const uint8_t *orig_addr, uint32_t fmt, uint32_t siz) {
size_t hash = (uintptr_t)orig_addr;
hash = (hash >> 5) & 0x3ff;
Expand All @@ -336,8 +341,7 @@ static bool gfx_texture_cache_lookup(int tile, struct TextureHashmapNode **n, co
}
if (gfx_texture_cache.pool_pos == sizeof(gfx_texture_cache.pool) / sizeof(struct TextureHashmapNode)) {
// Pool is full. We just invalidate everything and start over.
if (gfx_rapi->flush_textures) gfx_rapi->flush_textures();
gfx_texture_cache.pool_pos = 0;
gfx_clear_texture_cache();
node = &gfx_texture_cache.hashmap[hash];
//puts("Clearing texture cache");
}
Expand Down Expand Up @@ -2025,3 +2029,4 @@ void gfx_end_frame(void) {
gfx_wapi->swap_buffers_end();
}
}

1 change: 1 addition & 0 deletions src/pc/gfx/gfx_pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct GfxRenderingAPI *gfx_get_current_rendering_api(void);
void gfx_start_frame(void);
void gfx_run(Gfx *commands);
void gfx_end_frame(void);
void gfx_clear_texture_cache(void);

#ifdef __cplusplus
}
Expand Down
10 changes: 9 additions & 1 deletion src/pc/gfx/gfx_ps2_rapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ static void gfx_ps2_set_viewport(int x, int y, int width, int height) {
r_view.x = x;
r_view.y = y;
r_view.w = width;
// 1080i requires the view point is half height
if (gs_global->Mode == GS_MODE_DTV_1080I) {
height /= 2;
}
r_view.h = height;
r_view.hw = r_view.w * 0.5f;
r_view.hh = r_view.h * 0.5f;
Expand All @@ -324,6 +328,11 @@ static void gfx_ps2_set_viewport(int x, int y, int width, int height) {
}

static inline void draw_set_scissor(const int x0, const int y0, const int x1, const int y1) {
// scissor doesn't work with gskit hires
if (gs_global->Mode == GS_MODE_DTV_720P || gs_global->Mode == GS_MODE_DTV_1080I) {
return;
}

u64 *p_data = gsKit_heap_alloc(gs_global, 1, 16, GIF_AD);

*p_data++ = GIF_TAG_AD(1);
Expand Down Expand Up @@ -645,7 +654,6 @@ static void draw_clear(const u64 color) {

u32 pos = 0;

strips++;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was one of the major bugs, doesn't show up on low res but hires it makes lines all over the screen. It's possibly something which was left in by mistake.

while (strips--) {
gsKit_prim_sprite(gs_global, pos, 0, pos + 64, gs_global->Height, 0, color);
pos += 64;
Expand Down
Loading