Skip to content

Commit

Permalink
Updated libgs:
Browse files Browse the repository at this point in the history
*Changed the initialization function to be more like the Sony sceGsResetGraph() to make initializing and resetting this library simpler.
*Modified GsSetDefaultDisplayEnv() to function similarly to the Sony sceGsSetDefDispEnv(): NTSC, PAL and 480P will have the relevant values automatically filled in. DX and DY will be automatically adjusted, based on input from the EE kernel if supported.
*Moved the PSM specification for the draw and display environments to the respective set functions of both environment.
*FBW will be automatcally calculated within the respective set functions of both the draw and display environments.
*The functions have been categorized to reduce the amount of bloat that simpler programs will end up having.
*The uncached segment is now used instead of a call to SyncDCache(), since only a few bytes will be written as GS commands.
*The samples have been updated to compile with the updated libgs.

Also, the warnings in SBV have been silenced.
  • Loading branch information
sp193 committed Apr 25, 2014
1 parent a52355c commit 126517d
Showing 22 changed files with 1,428 additions and 1,183 deletions.
2 changes: 1 addition & 1 deletion ee/libgs/Makefile
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ EE_LIB_DIR = lib/
EE_SRC_DIR = src/
EE_INC_DIR = include/

EE_OBJS = libgs.o erl-support.o
EE_OBJS = libgs.o DxDyOffset.o ResetPath.o dma.o DoubleBuff.o draw.o Zbuffer.o lowlevel.o packets.o primitives.o sync.o texture.o erl-support.o
EE_OBJS := $(EE_OBJS:%=$(EE_OBJS_DIR)%)

EE_LIB = $(EE_LIB_DIR)libgs.a
118 changes: 57 additions & 61 deletions ee/libgs/include/libgs.h
Original file line number Diff line number Diff line change
@@ -13,64 +13,65 @@
#define _LIBGS_H_

/**/
#define GS_DISABLE 0
#define GS_ENABLE 1
typedef struct {
unsigned char interlace; //Interlace/non-interlace mode.
unsigned char omode; //Video mode.
unsigned char ffmode; //FIELD/FRAME value.
unsigned char version; //GS version.
} GsGParam_t;

#define GS_INIT_RESET 0 //Resets the GS and GIF.
#define GS_INIT_DRAW_RESET 1 //Drawing operations are cancelled and primitive data will be discarded.

#define GS_NONINTERLACED 0x00
#define GS_INTERLACED 0x01

#define GS_FFMD_INTERLACE 0x00
#define GS_FFMD_FRAME 0x01
#define GS_FFMD_INTERLACE 0x00 //Read every other line from the beginning with the start of FIELD.
#define GS_FFMD_FRAME 0x01 //Read every line from the beginning with the start of FRAME.

/* About the supported video modes:
As GsSetDefaultDisplayEnv() has been modified to provide functionality that is similar to the Sony sceGsSetDefDispEnv() function,
it will now automatically in fill in the GS_DISPENV structure with values for the video mode that is specified for GsResetGraph().
However, as with the Sony function:
1. Only NTSC, PAL and 480P video modes are supported.
2. MAGV isn't automatically calculated.
It is possible to cover these limitations by setting the relevant values after calling GsSetDefaultDisplayEnv(), but I do not know how these values are to be calculated for other video modes.
*/
enum GsVideoModes{
GS_MODE_NTSC = 0x02,
GS_MODE_PAL,
GS_MODE_VGA_640_60 = 0x1A,
GS_MODE_VGA_640_72,
GS_MODE_VGA_640_75,
GS_MODE_VGA_640_85,
GS_MODE_VGA_800_56 = 0x2A,
GS_MODE_VGA_800_60,
GS_MODE_VGA_800_72,
GS_MODE_VGA_800_75,
GS_MODE_VGA_800_85,
GS_MODE_VGA_1024_60 = 0x3B,
GS_MODE_VGA_1024_70,
GS_MODE_VGA_1024_75,
GS_MODE_VGA_1024_85,
GS_MODE_VGA_1280_60 = 0x4A,
GS_MODE_VGA_1280_75,

GS_MODE_DTV_480P = 0x50,
GS_MODE_DTV_1080I,
GS_MODE_DTV_720P,
GS_MODE_DTV_576P //Available only on the SCPH-50000 and above.
};

//type of primitives
#define GS_DISABLE 0
#define GS_ENABLE 1

//types of primitives
enum GsPrimitiveTypes{
GS_PRIM_POINT =0,
GS_PRIM_LINE,
GS_PRIM_LINE_STRIP,
GS_PRIM_TRI,
GS_PRIM_TRI_STRIP,
GS_PRIM_TRI_FAN,
GS_PRIM_SPRITE,
GS_PRIM_PS2DEV
GS_PRIM_SPRITE
};

// regular pixmodes
// regular Pixel Storage Modes (PSM)
#define GS_PIXMODE_32 0
#define GS_PIXMODE_24 1
#define GS_PIXMODE_16 2
#define GS_PIXMODE_16S 10

// clut pixmodes
// clut Pixel Storage Modes (PSM)
#define GS_CLUT_32 0
#define GS_CLUT_16 2
#define GS_CLUT_16S 10

// texture/image pixmodes
// texture/image Pixel Storage Modes (PSM)
#define GS_TEX_32 0
#define GS_TEX_24 1
#define GS_TEX_16 2
@@ -81,7 +82,7 @@ enum GsPrimitiveTypes{
#define GS_TEX_4HL 36
#define GS_TEX_4HH 44

// Z-Buffer modes
// Z-Buffer Pixel Storage Modes (PSM)
#define GS_ZBUFF_32 48
#define GS_ZBUFF_24 49
#define GS_ZBUFF_16 50
@@ -342,7 +343,6 @@ typedef struct {
float padq; // 0x0
}GS_BGCOLOR;


/*CSR*/
typedef struct {
unsigned signal_evnt :1; // Signal event control(write: 0=nothing,1=enable signal event, read: 0=signal not generated, 1=signal generated)
@@ -365,7 +365,6 @@ typedef struct {
unsigned pad2 :32;// Pad with zeros
}GS_CSR;


/*IMR*/
typedef struct {
unsigned pad1 :8; // Pad with zeros
@@ -380,7 +379,6 @@ typedef struct {
unsigned int pad3; // Pad with zeros
}GS_IMR;


/*BUSDIR*/
typedef struct {
unsigned direction :1; // Transmission direction(0=host->local, 1=host<-local)
@@ -2061,45 +2059,47 @@ int GsSetPixelTest2(unsigned char enable_alpha_test, unsigned char alpha_test_me
int GsSelectTexure1(unsigned short tex_addr, unsigned char addr_width, unsigned char tex_pixmode, unsigned short tex_width, unsigned short tex_height, unsigned short clut_addr, unsigned char clut_pixmode, unsigned char clut_storagemode,unsigned char clut_offset);
int GsSelectTexure2(unsigned short tex_addr, unsigned char addr_width, unsigned char tex_pixmode, unsigned short tex_width, unsigned short tex_height, unsigned short clut_addr, unsigned char clut_pixmode, unsigned char clut_storagemode,unsigned char clut_offset);
void GsSetFogColor(unsigned char r, unsigned char g, unsigned char b);
void GsEnableColorClamp(unsigned short enable);

/*----------------------------------------------------
-- NORMAL FUNTIONS --
-- --
-- --
------------------------------------------------------*/

int GsInit(short int interlace, short int videomode, short int ffmd);
int GsSetCRTCSettings(unsigned long settings, unsigned char alpha_value);
int GsSetVideoMode(short int interlace, short int videomode, short int ffmd);
GsGParam_t *GsGetGParam(void);
void GsResetGraph(short int mode, short int interlace, short int omode, short int ffmode);
void GsResetPath(void);
void GsSetCRTCSettings(unsigned long settings, unsigned char alpha_value);

/* Initialise structs with defaults Based On Input*/
int GsSetDefaultDrawEnv(GS_DRAWENV *drawenv, unsigned short int w, unsigned short int h);
int GsSetDefaultDrawEnvAddress(GS_DRAWENV *drawenv, unsigned short vram_addr, unsigned char fbw, unsigned char psm);
int GsSetDefaultDisplayEnv(GS_DISPENV *dispenv, unsigned short int w, unsigned short int h, unsigned short int x, unsigned short int y);
int GsSetDefaultDisplayEnvAddress(GS_DISPENV *dispenv, unsigned short vram_addr, unsigned char fbw, unsigned char psm);
int GsSetDefaultZBufferEnv(GS_ZENV *zenv, unsigned char update_mask);
int GsSetDefaultZBufferEnvAddress(GS_ZENV *zenv, unsigned short vram_addr, unsigned char psm);

/* Execute struct's data(Env.ironments)*/
int GsPutDrawEnv1(GS_DRAWENV *drawenv);
int GsPutDrawEnv2(GS_DRAWENV *drawenv);
int GsPutDisplayEnv1(GS_DISPENV *dispenv);
int GsPutDisplayEnv2(GS_DISPENV *dispenv);
int GsPutZBufferEnv1(GS_ZENV *zenv);
int GsPutZBufferEnv2(GS_ZENV *zenv);
int GsClearDrawEnv1(GS_DRAWENV *drawenv); // clear draw buffer with GS_DRAWENV->bg_color color (contex 1)
int GsClearDrawEnv2(GS_DRAWENV *drawenv); // clear draw buffer with GS_DRAWENV->bg_color color (contex 2)
void GsSetDefaultDrawEnv(GS_DRAWENV *drawenv, unsigned short int psm, unsigned short int w, unsigned short int h);
void GsSetDefaultDrawEnvAddress(GS_DRAWENV *drawenv, unsigned short vram_addr);
void GsSetDefaultDisplayEnv(GS_DISPENV *dispenv, unsigned short int psm, unsigned short int w, unsigned short int h, unsigned short int dx, unsigned short int dy);
void GsSetDefaultDisplayEnvAddress(GS_DISPENV *dispenv, unsigned short vram_addr);
void GsSetDefaultZBufferEnv(GS_ZENV *zenv, unsigned char update_mask);
void GsSetDefaultZBufferEnvAddress(GS_ZENV *zenv, unsigned short vram_addr, unsigned char psm);

/* Execute struct's data (Environments)*/
void GsPutDrawEnv1(GS_DRAWENV *drawenv);
void GsPutDrawEnv2(GS_DRAWENV *drawenv);
void GsPutDisplayEnv1(GS_DISPENV *dispenv);
void GsPutDisplayEnv2(GS_DISPENV *dispenv);
void GsPutZBufferEnv1(GS_ZENV *zenv);
void GsPutZBufferEnv2(GS_ZENV *zenv);
void GsClearDrawEnv1(GS_DRAWENV *drawenv); // clear draw buffer with GS_DRAWENV->bg_color color (contex 1)
void GsClearDrawEnv2(GS_DRAWENV *drawenv); // clear draw buffer with GS_DRAWENV->bg_color color (contex 2)

/* Gif packet execution*/
QWORD *GsGifPacketsAlloc(GS_PACKET_TABLE *table, unsigned int num_qwords);
int GsGifPacketsClear(GS_PACKET_TABLE *table);
void GsGifPacketsClear(GS_PACKET_TABLE *table);
int GsGifPacketsExecute(GS_PACKET_TABLE *table, unsigned short wait);

/* Texture/Image Funtions*/
int GsLoadImage(void *source_addr, GS_IMAGE *dest);
int GsLoadImage(const void *source_addr, GS_IMAGE *dest);

/**/
int GsOverridePrimAttributes(char override, char iip, char tme, char fge, char abe, char aa1, char fst, char ctxt, char fix);
void GsOverridePrimAttributes(char override, char iip, char tme, char fge, char abe, char aa1, char fst, char ctxt, char fix);
void GsEnableDithering(unsigned char enable, int mode);
void GsEnableAlphaTransparency1(unsigned short enable,unsigned short method,unsigned char alpha_ref,unsigned short fail_method);
void GsEnableAlphaTransparency2(unsigned short enable,unsigned short method,unsigned char alpha_ref,unsigned short fail_method);
@@ -2109,9 +2109,9 @@ void GsEnableAlphaBlending1(unsigned short enable, unsigned short mode);
void GsEnableAlphaBlending2(unsigned short enable, unsigned short mode);

/**/
int GsDrawSync(int mode);
int GsHSync(int mode);
int GsVSync(int mode);
void GsDrawSync(int mode);
void GsHSync(int mode);
void GsVSync(int mode);

/* Vram Allocation*/
int GsVramAllocFrameBuffer(short w, short h, short psm);
@@ -2124,10 +2124,6 @@ int GsDbGetDrawBuffer(void);
int GsDbGetDisplayBuffer(void);
void GsDbSwapBuffer(void);

/* return a propper value for */
/* GS_TEX0->tex_width/tex_height (ito) (dont use it if you dont have to)*/
char twh4(short wh);

#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
}
#endif
26 changes: 13 additions & 13 deletions ee/libgs/samples/libgs_doublebuffer/main.c
Original file line number Diff line number Diff line change
@@ -89,28 +89,28 @@ static int InitGraphics(void)
{
int env0_address, env1_address;

GsInit(GS_INTERLACED, GS_MODE_NTSC, GS_FFMD_FRAME);
GsResetGraph(GS_INIT_RESET, GS_INTERLACED, GS_MODE_NTSC, GS_FFMD_FRAME);

//alloc 2 buffers in vram
env0_address = GsVramAllocFrameBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, GS_PIXMODE_32);
env1_address = GsVramAllocFrameBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, GS_PIXMODE_32);
env0_address = GsVramAllocFrameBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, GS_PIXMODE_32);
env1_address = GsVramAllocFrameBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, GS_PIXMODE_32);

/*********SETUP CONTEX 1 ENVIRONMENT*************/
GsSetDefaultDrawEnv(&draw_env[0], SCREEN_WIDTH, SCREEN_HEIGHT);
GsSetDefaultDrawEnv(&draw_env[0], GS_PIXMODE_32, SCREEN_WIDTH, SCREEN_HEIGHT);
//Retrieve screen offset parameters.
ScreenOffsetX=draw_env[0].offset_x;
ScreenOffsetY=draw_env[0].offset_y;
GsSetDefaultDrawEnvAddress(&draw_env[0], env0_address, SCREEN_WIDTH/64, GS_PIXMODE_32);
GsSetDefaultDrawEnvAddress(&draw_env[0], env0_address);

GsSetDefaultDisplayEnv(&disp_env[0], SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
GsSetDefaultDisplayEnvAddress(&disp_env[0], env1_address, SCREEN_WIDTH/64, GS_PIXMODE_32);
GsSetDefaultDisplayEnv(&disp_env[0], GS_PIXMODE_32, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
GsSetDefaultDisplayEnvAddress(&disp_env[0], env1_address);

/*********SETUP CONTEX 2 ENVIRONMENT*************/
GsSetDefaultDrawEnv(&draw_env[1], SCREEN_WIDTH, SCREEN_HEIGHT);
GsSetDefaultDrawEnvAddress(&draw_env[1], env1_address, SCREEN_WIDTH/64, GS_PIXMODE_32);
GsSetDefaultDrawEnv(&draw_env[1], GS_PIXMODE_32, SCREEN_WIDTH, SCREEN_HEIGHT);
GsSetDefaultDrawEnvAddress(&draw_env[1], env1_address);

GsSetDefaultDisplayEnv(&disp_env[1], SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
GsSetDefaultDisplayEnvAddress(&disp_env[1], env0_address, SCREEN_WIDTH/64, GS_PIXMODE_32);
GsSetDefaultDisplayEnv(&disp_env[1], GS_PIXMODE_32, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
GsSetDefaultDisplayEnvAddress(&disp_env[1], env0_address);

//execute draw/display environment(s) (contex 1)
GsPutDrawEnv1 (&draw_env[0]);
@@ -139,10 +139,10 @@ static void SelectDisplayContext(int context_id)
// the CRTC is used to select which contex we see on our TV/VGA/HDTV

if(context_id==0)
GsSetCRTCSettings(CRTC_SETTINGS_DEFAULT1, 255);
GsSetCRTCSettings(CRTC_SETTINGS_DEFAULT1, 0x80);

if(context_id==1)
GsSetCRTCSettings(CRTC_SETTINGS_DEFAULT2, 255);
GsSetCRTCSettings(CRTC_SETTINGS_DEFAULT2, 0x80);
}

static void ClearDrawingContext(int context_id)
10 changes: 5 additions & 5 deletions ee/libgs/samples/libgs_draw/main.c
Original file line number Diff line number Diff line change
@@ -90,17 +90,17 @@ int InitGraphics(void)
{
unsigned int FrameBufferVRAMAddress;

GsInit(GS_INTERLACED, GS_MODE_NTSC, GS_FFMD_INTERLACE);
GsResetGraph(GS_INIT_RESET, GS_INTERLACED, GS_MODE_NTSC, GS_FFMD_INTERLACE);

FrameBufferVRAMAddress=GsVramAllocFrameBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, GS_PIXMODE_32);
GsSetDefaultDrawEnv(&draw_env, SCREEN_WIDTH, SCREEN_HEIGHT);
GsSetDefaultDrawEnv(&draw_env, GS_PIXMODE_32, SCREEN_WIDTH, SCREEN_HEIGHT);
//Retrieve screen offset parameters.
ScreenOffsetX=draw_env.offset_x;
ScreenOffsetY=draw_env.offset_y;
GsSetDefaultDrawEnvAddress(&draw_env, FrameBufferVRAMAddress, SCREEN_WIDTH/64, GS_PIXMODE_32);
GsSetDefaultDrawEnvAddress(&draw_env, FrameBufferVRAMAddress);

GsSetDefaultDisplayEnv(&disp_env, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
GsSetDefaultDisplayEnvAddress(&disp_env, FrameBufferVRAMAddress, SCREEN_WIDTH/64, GS_PIXMODE_32);
GsSetDefaultDisplayEnv(&disp_env, GS_PIXMODE_32, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
GsSetDefaultDisplayEnvAddress(&disp_env, FrameBufferVRAMAddress);

//execute draw/display environment(s) (context 1)
GsPutDrawEnv1(&draw_env);
34 changes: 34 additions & 0 deletions ee/libgs/src/DoubleBuff.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
# _____ ___ ____ ___ ____
# ____| | ____| | | |____|
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
#-----------------------------------------------------------------------
# (c) 2009 Lion
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.
#
*/

#include <errno.h>
#include <stdio.h>
#include <kernel.h>
#include <libgs.h>

#include "internal.h"

static short int gs_db_draw_buffer=0;

int GsDbGetDrawBuffer(void)
{
return gs_db_draw_buffer;
}

int GsDbGetDisplayBuffer(void)
{
return(gs_db_draw_buffer? 0: 1);
}

void GsDbSwapBuffer(void)
{
gs_db_draw_buffer = gs_db_draw_buffer? 0: 1;
}
8 changes: 8 additions & 0 deletions ee/libgs/src/DxDyOffset.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.global _GetGsDxDyOffset
.ent _GetGsDxDyOffset
_GetGsDxDyOffset:
li $v1, 0x80
syscall
jr $ra
nop
.end _GetGsDxDyOffset
32 changes: 32 additions & 0 deletions ee/libgs/src/ResetPath.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.data

init_vif_regs_12: .word 0x10000404, 0x20000000, 0x00000000, 0x50000000
.word 0x60000000, 0x30000000, 0x20000000, 0x40000000

.text

.globl GsResetPath
.ent GsResetPath
GsResetPath:
li $a3, 1
la $v0, 0x10003C10
sw $a3, ($v0)
la $v1, 0x10003C20
li $v0, 2
move $a0, $zero
sw $v0, 0($v1)
sync
cfc2 $a0, $28
ori $a0, 0x200
ctc2 $a0, $28
sync.p
la $a1, init_vif_regs_12
la $a2, 0x10005000
lq $a0, ($a1)
la $v1, 0x10003000
sq $a0, ($a2)
lq $v0, 8($a1)
sq $v0, ($a2)
jr $ra
sw $a3, 0($v1)
.end GsResetPath
Loading

0 comments on commit 126517d

Please sign in to comment.