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
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
67 changes: 51 additions & 16 deletions src/pc/gfx/gfx_ps2_wapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@

#include <kernel.h>
#include <gsKit.h>
#include <gsHires.h>
#include <dmaKit.h>

#include "gfx_window_manager_api.h"
#include "gfx_screen_config.h"
#include "gfx_ps2.h"

#define FRAMERATE_SHIFT 1
#define FRAMESKIP 10

struct VidMode {
const char *name;
s16 mode;
Expand All @@ -24,20 +28,21 @@ struct VidMode {
int width;
int height;
int vck;
int iPassCount;
int x_off;
int y_off;
};

static const struct VidMode vid_modes[] = {
// NTSC
{ "480i", GS_MODE_NTSC, GS_INTERLACED, GS_FIELD, 704, 480, 704, 452, 4, 0, 0 },
{ "480p", GS_MODE_DTV_480P, GS_NONINTERLACED, GS_FRAME, 704, 480, 704, 452, 2, 0, 0 },
{ "480i", GS_MODE_NTSC, GS_INTERLACED, GS_FIELD, 704, 480, 704, 452, 4, 1, 0, 0 },
{ "480p", GS_MODE_DTV_480P, GS_NONINTERLACED, GS_FRAME, 704, 480, 704, 452, 2, 1, 0, 0 },
// PAL
{ "576i", GS_MODE_PAL, GS_INTERLACED, GS_FIELD, 704, 576, 704, 536, 4, 0, 0 },
{ "576p", GS_MODE_DTV_576P, GS_NONINTERLACED, GS_FRAME, 704, 576, 704, 536, 2, 0, 0 },
{ "576i", GS_MODE_PAL, GS_INTERLACED, GS_FIELD, 704, 576, 704, 536, 4, 1, 0, 0 },
{ "576p", GS_MODE_DTV_576P, GS_NONINTERLACED, GS_FRAME, 704, 576, 704, 536, 2, 1, 0, 0 },
// HDTV
{ "720p", GS_MODE_DTV_720P, GS_NONINTERLACED, GS_FRAME, 1280, 720, 1280, 698, 1, 0, 0 },
{"1080i", GS_MODE_DTV_1080I, GS_INTERLACED, GS_FIELD, 1920, 1080, 1920, 1080, 1, 0, 0 },
{ "720p", GS_MODE_DTV_720P, GS_NONINTERLACED, GS_FRAME, 1280, 720, 1280, 720, 1, 2, 0, 0 },
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.

2 passes works fine

{"1080i", GS_MODE_DTV_1080I, GS_INTERLACED, GS_FIELD, 1920, 1080, 1920, 1080, 1, 2, 0, 0 },
};

GSGLOBAL *gs_global;
Expand All @@ -47,6 +52,7 @@ static int vsync_sema_2nd_id;
static int vsync_sema_id = -1;

static const struct VidMode *vid_mode;
static bool use_hires = false;

/* Copy of gsKit_sync_flip, but without the 'flip' */
static void gsKit_sync(GSGLOBAL *gsGlobal)
Expand Down Expand Up @@ -99,31 +105,51 @@ static void prepare_sema() {
}

static void gfx_ps2_init(const char *game_name, bool start_in_fullscreen) {
gs_global = gsKit_init_global();

dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);

dmaKit_chan_init(DMA_CHANNEL_GIF);

#if defined(VERSION_EU)
vid_mode = &vid_modes[2]; // PAL
#else
vid_mode = &vid_modes[0]; // NTCS
// change to 5 for 1080i
// vid_mode = &vid_modes[5];
#endif
use_hires = (vid_mode->mode == GS_MODE_DTV_720P || vid_mode->mode == GS_MODE_DTV_1080I);

if (use_hires) {
gs_global = gsKit_hires_init_global();
} else {
gs_global = gsKit_init_global();
}

dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);

dmaKit_chan_init(DMA_CHANNEL_GIF);

gs_global->Mode = vid_mode->mode;
gs_global->Width = vid_mode->width;
gs_global->Height = vid_mode->height;
if (gs_global->Mode == GS_MODE_DTV_1080I) {
gs_global->Height /= 2;
}

gs_global->Interlace = vid_mode->interlace;
gs_global->Field = vid_mode->field;
gs_global->ZBuffering = GS_SETTING_ON;
gs_global->DoubleBuffering = GS_SETTING_ON;
gs_global->PrimAAEnable = GS_SETTING_OFF;
gs_global->PSM = GS_PSM_CT24;
// this could be enabled for hires, but I don't like it
gs_global->Dithering = GS_SETTING_OFF;
// hires runs out of VRAM if using more than 16bit color
gs_global->PSM = use_hires ? GS_PSM_CT16 : GS_PSM_CT24;
gs_global->PSMZ = GS_PSMZ_16; // 16-bit unsigned zbuffer

gsKit_init_screen(gs_global);
if (use_hires) {
gsKit_hires_init_screen(gs_global, vid_mode->iPassCount);
} else {
gsKit_init_screen(gs_global);
}
// hires sets the texture pointer to the wrong location. Ensure it's correct.
gs_global->TexturePointer = gs_global->CurrentPointer;
gsKit_TexManager_init(gs_global);
}

Expand All @@ -146,6 +172,11 @@ static void gfx_ps2_main_loop(void (*run_one_game_iter)(void)) {
static void gfx_ps2_get_dimensions(uint32_t *width, uint32_t *height) {
*width = gs_global->Width;
*height = gs_global->Height;
// the game doesn't need to know that we are
// rendering at half height for 1080i
if (gs_global->Mode == GS_MODE_DTV_1080I) {
*height *= 2;
}
}

static void gfx_ps2_handle_events(void) {
Expand All @@ -167,8 +198,12 @@ static void gfx_ps2_swap_buffers_begin(void) {
static void gfx_ps2_swap_buffers_end(void) {
/* How SM64 expect to run at 30 PFS we need to wait for 2 vsync */
gsKit_sync(gs_global);
if (use_hires) {
gsKit_hires_flip(gs_global);
} else {
gsKit_flip(gs_global);
}

gsKit_flip(gs_global);
gsKit_queue_exec(gs_global);
gsKit_TexManager_nextFrame(gs_global);
}
Expand Down
8 changes: 6 additions & 2 deletions src/pc/pc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#ifdef TARGET_PS2
# include <tamtypes.h>
# include <kernel.h>
# include <iopheap.h>
# include <iopcontrol.h>
# include <sifrpc.h>
# include <loadfile.h>
Expand Down Expand Up @@ -150,17 +151,20 @@ void reset_IOP() {
static void prepare_IOP() {
reset_IOP();
SifInitRpc(0);

sbv_patch_enable_lmb();
sbv_patch_disable_prefix_check();
}

static void init_drivers() {
init_ps2_filesystem_driver();
init_only_boot_ps2_filesystem_driver();
Comment thread
freshollie marked this conversation as resolved.
Outdated
init_memcard_driver(TRUE);
ps2_memcard_init();
}

static void deinit_drivers() {
deinit_ps2_filesystem_driver();
deinit_memcard_driver(TRUE);
deinit_only_boot_ps2_filesystem_driver();
}
#endif

Expand Down