Adding gskit dependency
authorFrancisco Javier Trujillo Mata <fjtrujy@gmail.com>
Sun, 31 Dec 2023 17:27:46 +0000 (18:27 +0100)
committerkub <derkub@gmail.com>
Sun, 18 Feb 2024 22:30:34 +0000 (23:30 +0100)
configure
platform/ps2/emu.c

index dc88761..e73c695 100755 (executable)
--- a/configure
+++ b/configure
@@ -157,8 +157,8 @@ set_platform()
     MFLAGS=""
     ARCH=mips64r5900el
     ASFLAGS="$ASFLAGS -G0 -call_shared"
-    CFLAGS="$CFLAGS -D_EE -G0 -I${PS2SDK}/ee/include -I${PS2SDK}/common/include -I${PS2SDK}/ports/include"
-    LDFLAGS="$LDFLAGS -Wl,-zmax-page-size=128 -T${PS2SDK}/ee/startup/linkfile -L${PS2SDK}/ee/lib -L${PS2SDK}/ports/lib"
+    CFLAGS="$CFLAGS -D_EE -G0 -I${PS2SDK}/ee/include -I${PS2SDK}/common/include -I${PS2DEV}/gsKit/include -I${PS2SDK}/ports/include"
+    LDFLAGS="$LDFLAGS -Wl,-zmax-page-size=128 -T${PS2SDK}/ee/startup/linkfile -L${PS2SDK}/ee/lib -L${PS2DEV}/gsKit/lib -L${PS2SDK}/ports/lib"
     ;;
   *)
     fail "unsupported platform: $platform"
index c0dd7d2..a2562f4 100644 (file)
@@ -1,9 +1,14 @@
 #include <stddef.h>
+#include <malloc.h>
 
 #include <kernel.h>
 #include <ps2_joystick_driver.h>
 #include <ps2_audio_driver.h>
 #include <libpad.h>
+#include <gsKit.h>
+#include <dmaKit.h>
+#include <gsToolkit.h>
+#include <gsInline.h>
 
 #include "in_ps2.h"
 #include "../libpicofe/input.h"
 
 #define OSD_FPS_X 220
 
+/* turn black GS Screen */
+#define GS_BLACK GS_SETREG_RGBA(0x00, 0x00, 0x00, 0x80)
+/* Generic tint color */
+#define GS_TEXT GS_SETREG_RGBA(0x80, 0x80, 0x80, 0x80)
+
 static int osd_buf_cnt, osd_cdleds;
 
 static int out_x, out_y;
@@ -42,9 +52,70 @@ const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast
 const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };
 enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
 
+typedef struct ps2_video {
+       GSGLOBAL *gsGlobal;
+
+       GSTEXTURE *scrbitmap;
+       GSTEXTURE *tex_spr0;
+       GSTEXTURE *tex_spr1;
+       GSTEXTURE *tex_spr2;
+       GSTEXTURE *tex_fix;
+       uint32_t offset;
+       uint8_t vsync; /* 0 (Disabled), 1 (Enabled), 2 (Dynamic) */
+       uint8_t pixel_format;
+} ps2_video_t;
+
+ps2_video_t *ps2_video = NULL;
+
 #define is_16bit_mode() \
        (currentConfig.renderer == RT_16BIT || (PicoIn.AHW & PAHW_32X))
 
+static void video_init(void)
+{
+    ps2_video = (ps2_video_t*)calloc(1, sizeof(ps2_video_t));
+
+    GSGLOBAL *gsGlobal;
+
+    gsGlobal = gsKit_init_global();
+
+    gsGlobal->Mode = GS_MODE_NTSC;
+    gsGlobal->Height = 448;
+
+    gsGlobal->PSM  = GS_PSM_CT24;
+    gsGlobal->PSMZ = GS_PSMZ_16S;
+    gsGlobal->ZBuffering = GS_SETTING_OFF;
+    gsGlobal->DoubleBuffering = GS_SETTING_ON;
+    gsGlobal->PrimAlphaEnable = GS_SETTING_ON;
+    gsGlobal->Dithering = GS_SETTING_OFF;
+
+    gsKit_set_primalpha(gsGlobal, GS_SETREG_ALPHA(0, 1, 0, 1, 0), 0);
+
+    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);
+
+    gsKit_set_clamp(gsGlobal, GS_CMODE_REPEAT);
+
+    gsKit_vram_clear(gsGlobal);
+
+    gsKit_init_screen(gsGlobal);
+
+    gsKit_TexManager_init(gsGlobal);
+
+    gsKit_mode_switch(gsGlobal, GS_ONESHOT);
+    gsKit_clear(gsGlobal, GS_BLACK);
+    ps2_video->gsGlobal = gsGlobal;
+}
+
+static void video_deinit(void)
+{
+    if (!ps2_video) return;
+
+    gsKit_clear(ps2_video->gsGlobal, GS_BLACK);
+    gsKit_vram_clear(ps2_video->gsGlobal);
+    gsKit_deinit_global(ps2_video->gsGlobal);
+    free(ps2_video);
+}
+
 static int get_renderer(void)
 {
        if (PicoIn.AHW & PAHW_32X)
@@ -179,6 +250,7 @@ void pemu_finalize_frame(const char *fps, const char *notice)
 
 void plat_init(void) 
 {
+    video_init();
     init_joystick_driver(false);
     in_ps2_init(in_ps2_defbinds);
     in_probe();
@@ -189,6 +261,7 @@ void plat_init(void)
 void plat_finish(void) {
     deinit_audio_driver();
     deinit_joystick_driver(false);
+    video_deinit();
 }
 
 /* display emulator status messages before holding emulation */