From f3e040230772f978540a71aea43dfde200992922 Mon Sep 17 00:00:00 2001 From: "John Wilbert M. Villamor" Date: Sat, 6 Apr 2019 10:11:07 +0800 Subject: First commit --- examples/balls/ball16c.h | 16 + examples/balls/ball16c.tim | Bin 0 -> 192 bytes examples/balls/balls | Bin 0 -> 21752 bytes examples/balls/main.c | 225 ++ examples/balls/makefile | 39 + examples/gte/main.c | 311 ++ examples/gte/makefile | 39 + examples/makefile | 16 + examples/n00bdemo/data.h | 12 + examples/n00bdemo/data.s | 31 + examples/n00bdemo/data.xml | 49 + examples/n00bdemo/data/bulb.smd | Bin 0 -> 1708 bytes examples/n00bdemo/data/bulb.smx | 147 + examples/n00bdemo/data/bungirl.smd | Bin 0 -> 67532 bytes examples/n00bdemo/data/bungirl.smx | 5608 +++++++++++++++++++++++++++++ examples/n00bdemo/data/bungirl.tim | Bin 0 -> 16928 bytes examples/n00bdemo/data/celmapi.bmp | Bin 0 -> 3126 bytes examples/n00bdemo/data/celmapi.tim | Bin 0 -> 576 bytes examples/n00bdemo/data/clktower.tim | Bin 0 -> 832 bytes examples/n00bdemo/data/font.bmp | Bin 0 -> 12406 bytes examples/n00bdemo/data/font.tim | Bin 0 -> 12352 bytes examples/n00bdemo/data/hatkid.png | Bin 0 -> 390 bytes examples/n00bdemo/data/hatkid.smd | Bin 0 -> 15676 bytes examples/n00bdemo/data/hatkid.smx | 1281 +++++++ examples/n00bdemo/data/hatkid.tim | Bin 0 -> 576 bytes examples/n00bdemo/data/lamelotl16c.png | Bin 0 -> 5777 bytes examples/n00bdemo/data/lamelotl16c.tim | Bin 0 -> 24640 bytes examples/n00bdemo/data/lightworld.smd | Bin 0 -> 13700 bytes examples/n00bdemo/data/lightworld.smx | 1097 ++++++ examples/n00bdemo/data/logo.smd | Bin 0 -> 13524 bytes examples/n00bdemo/data/logo.smx | 1169 ++++++ examples/n00bdemo/data/mtekdisk.smd | Bin 0 -> 4204 bytes examples/n00bdemo/data/mtekdisk.smx | 379 ++ examples/n00bdemo/data/mtektext.smd | Bin 0 -> 7172 bytes examples/n00bdemo/data/mtektext.smx | 671 ++++ examples/n00bdemo/data/n00blogo-pixel.png | Bin 0 -> 1035 bytes examples/n00bdemo/data/n00blogo-pixel.tim | Bin 0 -> 3392 bytes examples/n00bdemo/data/petscum.smd | Bin 0 -> 13844 bytes examples/n00bdemo/data/petscum.smx | 1093 ++++++ examples/n00bdemo/data/petscum16c.png | Bin 0 -> 955 bytes examples/n00bdemo/data/petscum16c.tim | Bin 0 -> 5184 bytes examples/n00bdemo/data/psn00blogo.smd | Bin 0 -> 8612 bytes examples/n00bdemo/data/psn00blogo.smx | 745 ++++ examples/n00bdemo/data/rbowshade.smd | Bin 0 -> 676 bytes examples/n00bdemo/data/rbowshade.smx | 50 + examples/n00bdemo/data/riftbld1.tim | Bin 0 -> 1088 bytes examples/n00bdemo/data/riftbld2.tim | Bin 0 -> 1088 bytes examples/n00bdemo/data/star.smd | Bin 0 -> 220 bytes examples/n00bdemo/data/star.smx | 26 + examples/n00bdemo/data/star_mask.smd | Bin 0 -> 220 bytes examples/n00bdemo/data/star_mask.smx | 25 + examples/n00bdemo/data/timerift.smd | Bin 0 -> 16232 bytes examples/n00bdemo/data/timerift.smx | 1085 ++++++ examples/n00bdemo/disp.c | 72 + examples/n00bdemo/disp.h | 25 + examples/n00bdemo/lightdemo.c | 494 +++ examples/n00bdemo/logo.c | 428 +++ examples/n00bdemo/logo.h | 6 + examples/n00bdemo/main.c | 650 ++++ examples/n00bdemo/makefile | 45 + examples/n00bdemo/overlay.c | 199 + examples/n00bdemo/plasma_tbl.c | 500 +++ examples/n00bdemo/plasma_tbl.h | 9 + examples/n00bdemo/plasmagen.s | 181 + examples/n00bdemo/scrolltext.c | 136 + examples/n00bdemo/smd.h | 68 + examples/n00bdemo/smd.s | 924 +++++ examples/n00bdemo/smd_cel.s | 1073 ++++++ examples/n00bdemo/smd_flat.s | 832 +++++ examples/n00bdemo/smd_s.h | 336 ++ examples/n00bdemo/smdparser.s | 129 + examples/sdk-common.mk | 19 + 72 files changed, 20240 insertions(+) create mode 100644 examples/balls/ball16c.h create mode 100644 examples/balls/ball16c.tim create mode 100644 examples/balls/balls create mode 100644 examples/balls/main.c create mode 100644 examples/balls/makefile create mode 100644 examples/gte/main.c create mode 100644 examples/gte/makefile create mode 100644 examples/makefile create mode 100644 examples/n00bdemo/data.h create mode 100644 examples/n00bdemo/data.s create mode 100644 examples/n00bdemo/data.xml create mode 100644 examples/n00bdemo/data/bulb.smd create mode 100644 examples/n00bdemo/data/bulb.smx create mode 100644 examples/n00bdemo/data/bungirl.smd create mode 100644 examples/n00bdemo/data/bungirl.smx create mode 100644 examples/n00bdemo/data/bungirl.tim create mode 100644 examples/n00bdemo/data/celmapi.bmp create mode 100644 examples/n00bdemo/data/celmapi.tim create mode 100644 examples/n00bdemo/data/clktower.tim create mode 100644 examples/n00bdemo/data/font.bmp create mode 100644 examples/n00bdemo/data/font.tim create mode 100644 examples/n00bdemo/data/hatkid.png create mode 100644 examples/n00bdemo/data/hatkid.smd create mode 100644 examples/n00bdemo/data/hatkid.smx create mode 100644 examples/n00bdemo/data/hatkid.tim create mode 100644 examples/n00bdemo/data/lamelotl16c.png create mode 100644 examples/n00bdemo/data/lamelotl16c.tim create mode 100644 examples/n00bdemo/data/lightworld.smd create mode 100644 examples/n00bdemo/data/lightworld.smx create mode 100644 examples/n00bdemo/data/logo.smd create mode 100644 examples/n00bdemo/data/logo.smx create mode 100644 examples/n00bdemo/data/mtekdisk.smd create mode 100644 examples/n00bdemo/data/mtekdisk.smx create mode 100644 examples/n00bdemo/data/mtektext.smd create mode 100644 examples/n00bdemo/data/mtektext.smx create mode 100644 examples/n00bdemo/data/n00blogo-pixel.png create mode 100644 examples/n00bdemo/data/n00blogo-pixel.tim create mode 100644 examples/n00bdemo/data/petscum.smd create mode 100644 examples/n00bdemo/data/petscum.smx create mode 100644 examples/n00bdemo/data/petscum16c.png create mode 100644 examples/n00bdemo/data/petscum16c.tim create mode 100644 examples/n00bdemo/data/psn00blogo.smd create mode 100644 examples/n00bdemo/data/psn00blogo.smx create mode 100644 examples/n00bdemo/data/rbowshade.smd create mode 100644 examples/n00bdemo/data/rbowshade.smx create mode 100644 examples/n00bdemo/data/riftbld1.tim create mode 100644 examples/n00bdemo/data/riftbld2.tim create mode 100644 examples/n00bdemo/data/star.smd create mode 100644 examples/n00bdemo/data/star.smx create mode 100644 examples/n00bdemo/data/star_mask.smd create mode 100644 examples/n00bdemo/data/star_mask.smx create mode 100644 examples/n00bdemo/data/timerift.smd create mode 100644 examples/n00bdemo/data/timerift.smx create mode 100644 examples/n00bdemo/disp.c create mode 100644 examples/n00bdemo/disp.h create mode 100644 examples/n00bdemo/lightdemo.c create mode 100644 examples/n00bdemo/logo.c create mode 100644 examples/n00bdemo/logo.h create mode 100644 examples/n00bdemo/main.c create mode 100644 examples/n00bdemo/makefile create mode 100644 examples/n00bdemo/overlay.c create mode 100644 examples/n00bdemo/plasma_tbl.c create mode 100644 examples/n00bdemo/plasma_tbl.h create mode 100644 examples/n00bdemo/plasmagen.s create mode 100644 examples/n00bdemo/scrolltext.c create mode 100644 examples/n00bdemo/smd.h create mode 100644 examples/n00bdemo/smd.s create mode 100644 examples/n00bdemo/smd_cel.s create mode 100644 examples/n00bdemo/smd_flat.s create mode 100644 examples/n00bdemo/smd_s.h create mode 100644 examples/n00bdemo/smdparser.s create mode 100644 examples/sdk-common.mk (limited to 'examples') diff --git a/examples/balls/ball16c.h b/examples/balls/ball16c.h new file mode 100644 index 0000000..c79f273 --- /dev/null +++ b/examples/balls/ball16c.h @@ -0,0 +1,16 @@ +unsigned int ball16c_size=192; +unsigned char ball16c[] = { +0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10, +0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d, +0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a, +0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01, +0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32, +0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52, +0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31, +0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4, +0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce, +0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7, +0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e, +0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4, +0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00 +}; diff --git a/examples/balls/ball16c.tim b/examples/balls/ball16c.tim new file mode 100644 index 0000000..e2a5d17 Binary files /dev/null and b/examples/balls/ball16c.tim differ diff --git a/examples/balls/balls b/examples/balls/balls new file mode 100644 index 0000000..b3fbe8f Binary files /dev/null and b/examples/balls/balls differ diff --git a/examples/balls/main.c b/examples/balls/main.c new file mode 100644 index 0000000..3e23fb5 --- /dev/null +++ b/examples/balls/main.c @@ -0,0 +1,225 @@ +/* + * LibPSn00b Example Programs + * + * Balls Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * To build, simply run make. + * + * Example by Lameguy64 + * + * Changelog: + * + * November 20, 2018 - Initial version. + * + */ + +#include +#include +#include +#include +#include +#include "ball16c.h" + + +#define MAX_BALLS 384 + +#define OT_LEN 8 + +#define SCREEN_XRES 640 +#define SCREEN_YRES 480 + +#define CENTER_X SCREEN_XRES/2 +#define CENTER_Y SCREEN_YRES/2 + + +/* Display and drawing environments */ +DISPENV disp; +DRAWENV draw; + +char pribuff[2][65536]; /* Primitive packet buffers */ +unsigned int ot[2][OT_LEN]; /* Ordering tables */ +char *nextpri; /* Pointer to next packet buffer offset */ +int db = 0; /* Double buffer index */ + + +/* Ball struct and array */ +typedef struct { + short x,y; + short xdir,ydir; + unsigned char r,g,b,p; +} BALL_TYPE; + +BALL_TYPE balls[MAX_BALLS]; + + +/* TIM image parameters for loading the ball texture and drawing sprites */ +TIM_IMAGE tim; + + +void init() { + + int i; + + /* Reset GPU (also installs event handler for VSync) */ + printf("Init GPU... "); + ResetGraph( 0 ); + printf("Done.\n"); + + + printf("Set video mode... "); + + /* Set display and draw environment parameters */ + SetDefDispEnv( &disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + disp.isinter = 1; /* Enable interlace (required for hires) */ + + /* Set clear color, area clear and dither processing */ + setRGB0( &draw, 63, 0, 127 ); + draw.isbg = 1; + draw.dtd = 1; + + /* Apply the display and drawing environments */ + PutDispEnv( &disp ); + PutDrawEnv( &draw ); + + /* Enable video output */ + SetDispMask( 1 ); + + printf("Done.\n"); + + + /* Upload the ball texture */ + printf("Upload texture... "); + GetTimInfo( (unsigned int*)ball16c, &tim ); /* Get TIM parameters */ + + LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */ + if( tim.mode & 0x8 ) { + LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */ + } + + printf("Done.\n"); + + + /* Calculate ball positions */ + printf("Calculating balls... "); + + for(i=0; i>5), + (CENTER_Y-8)-(icos((counter-(i<<2))<<3)>>5) ); + setRGB0( sprt, rand()%256, rand()%256, rand()%256 ); + setUV0( sprt, 0, 0 ); + setClut( sprt, tim.crect->x, tim.crect->y ); + + addPrim( ot[db]+(OT_LEN-1), sprt ); + sprt++; + + } + + /* Sort the balls */ + for( i=0; ix, tim.crect->y ); + + addPrim( ot[db]+(OT_LEN-1), sprt ); + sprt++; + + balls[i].x += balls[i].xdir; + balls[i].y += balls[i].ydir; + + if( ( balls[i].x+16 ) > 640 ) { + balls[i].xdir = -2; + } else if( balls[i].x < 0 ) { + balls[i].xdir = 2; + } + + if( ( balls[i].y+16 ) > 480 ) { + balls[i].ydir = -2; + } else if( balls[i].y < 0 ) { + balls[i].ydir = 2; + } + + } + nextpri = (char*)sprt; + + + /* Sort a TPage primitive so the sprites will draw pixels from */ + /* the correct texture page in VRAM */ + tpri = (DR_TPAGE*)nextpri; + setDrawTPage( tpri, 0, 0, tim.prect->x, tim.prect->y ); + addPrim( ot[db]+(OT_LEN-1), tpri ); + nextpri += sizeof(DR_TPAGE); + + /* Wait for GPU and VSync */ + DrawSync(); + VSync(); + + /* Since draw.isbg is non-zero this clears the screen */ + PutDrawEnv( &draw ); + + /* Begin drawing the new frame */ + DrawOTag( ot[db]+(OT_LEN-1) ); + + /* Alternate to the next buffer */ + db = !db; + + /* Increment counter for the snake animation */ + counter++; + + } + + return 0; + +} diff --git a/examples/balls/makefile b/examples/balls/makefile new file mode 100644 index 0000000..b5c8d91 --- /dev/null +++ b/examples/balls/makefile @@ -0,0 +1,39 @@ +include ../sdk-common.mk + +TARGET = balls.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +INCLUDE += +LIBDIRS += + +LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lgcc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/gte/main.c b/examples/gte/main.c new file mode 100644 index 0000000..aa7042d --- /dev/null +++ b/examples/gte/main.c @@ -0,0 +1,311 @@ +/* + * LibPSn00b Example Programs + * + * GTE Graphics Example + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * To build, simply run make. + * + * Example by Lameguy64 + * + * Changelog: + * + * Jan 26, 2019 - Initial version. + * + */ + +#include +#include +#include +#include + +/* OT and Packet Buffer sizes */ +#define OT_LEN 256 +#define PACKET_LEN 1024 + +/* Screen resolution */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +/* Screen center position */ +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +/* Double buffer structure */ +typedef struct { + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + int ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ +} DB; + +/* Double buffer variables */ +DB db[2]; +int db_active = 0; +char *db_nextpri; + + +/* For easier handling of vertex indices */ +typedef struct { + short v0,v1,v2,v3; +} INDEX; + +/* Cube vertices */ +SVECTOR cube_verts[] = { + { -100, -100, -100, 0 }, + { 100, -100, -100, 0 }, + { -100, 100, -100, 0 }, + { 100, 100, -100, 0 }, + { 100, -100, 100, 0 }, + { -100, -100, 100, 0 }, + { 100, 100, 100, 0 }, + { -100, 100, 100, 0 } +}; + +/* Cube face normals */ +SVECTOR cube_norms[] = { + { 0, 0, -ONE, 0 }, + { 0, 0, ONE, 0 }, + { 0, -ONE, 0, 0 }, + { 0, ONE, 0, 0 }, + { -ONE, 0, 0, 0 }, + { ONE, 0, 0, 0 } +}; + +/* Cube vertex indices */ +INDEX cube_indices[] = { + { 0, 1, 2, 3 }, + { 4, 5, 6, 7 }, + { 5, 4, 0, 1 }, + { 6, 7, 3, 2 }, + { 0, 2, 5, 7 }, + { 3, 1, 6, 4 } +}; + +/* Number of faces of cube */ +#define CUBE_FACES 6 + + +/* Light color matrix */ +/* Each column represents the color matrix of each light source and is */ +/* used as material color when using gte_ncs() or multiplied by a */ +/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ +/* A column of zeroes disables the light source. */ +MATRIX color_mtx = { + ONE, 0, 0, /* Red */ + ONE, 0, 0, /* Green */ + ONE, 0, 0 /* Blue */ +}; + +/* Light matrix */ +/* Each row represents a vector direction of each light source. */ +/* An entire row of zeroes disables the light source. */ +MATRIX light_mtx = { + /* X, Y, Z */ + -2048 , -2048 , -2048, + 0 , 0 , 0, + 0 , 0 , 0 +}; + + +/* Function declarations */ +void init(); +void display(); + + +/* Main function */ +int main() { + + int i,p,xy_temp; + + SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ + VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ + MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ + + POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ + + + /* Init graphics and GTE */ + init(); + + + /* Main loop */ + while( 1 ) { + + /* Set rotation and translation to the matrix */ + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + /* Multiply light matrix by rotation matrix so light source */ + /* won't appear relative to the model's rotation */ + MulMatrix0( &light_mtx, &mtx, &lmtx ); + + /* Set rotation and translation matrix */ + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + /* Set light matrix */ + gte_SetLightMatrix( &lmtx ); + + /* Make the cube SPEEN */ + rot.vx += 16; + rot.vz += 16; + + + /* Draw the cube */ + pol4 = (POLY_F4*)db_nextpri; + + for( i=0; i>2) > OT_LEN ) + continue; + + /* Initialize a quad primitive */ + setPolyF4( pol4 ); + + /* Set the projected vertices to the primitive */ + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + /* Compute the last vertex and set the result */ + gte_ldv0( &cube_verts[cube_indices[i].v3] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + /* Load primitive color even though gte_ncs() doesn't use it. */ + /* This is so the GTE will output a color result with the */ + /* correct primitive code. */ + gte_ldrgb( &pol4->r0 ); + + /* Load the face normal */ + gte_ldv0( &cube_norms[i] ); + + /* Normal Color Single */ + gte_ncs(); + + /* Store result to the primitive */ + gte_strgb( &pol4->r0 ); + + /* Sort primitive to the ordering table */ + addPrim( db[db_active].ot+(p>>2), pol4 ); + + /* Advance to make another primitive */ + pol4++; + + } + + /* Update nextpri variable */ + /* (IMPORTANT if you plan to sort more primitives after this) */ + db_nextpri = (char*)pol4; + + /* Swap buffers and draw the primitives */ + display(); + + } + + return 0; + +} + +void init() { + + /* Reset the GPU, also installs a VSync event handler */ + ResetGraph( 0 ); + + /* Set display and draw environment areas */ + /* (display and draw areas must be separate, otherwise hello flicker) */ + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + /* Enable draw area clear and dither processing */ + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + /* Define the second set of display/draw environments */ + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + + /* Apply the drawing environment of the first double buffer */ + PutDrawEnv( &db[0].draw ); + + + /* Clear both ordering tables to make sure they are clean at the start */ + ClearOTagR( db[0].ot, OT_LEN ); + ClearOTagR( db[1].ot, OT_LEN ); + + /* Set primitive pointer address */ + db_nextpri = db[0].p; + + /* Initialize the GTE */ + InitGeom(); + + /* Set GTE offset (recommended method of centering) */ + gte_SetGeomOffset( CENTERX, CENTERY ); + + /* Set screen depth (basically FOV control, W/2 works best) */ + gte_SetGeomScreen( CENTERX ); + + /* Set light ambient color and light color matrix */ + gte_SetBackColor( 63, 63, 63 ); + gte_SetColorMatrix( &color_mtx ); + +} + +void display() { + + /* Wait for GPU to finish drawing and vertical retrace */ + DrawSync(); + VSync(); + + /* Swap buffers */ + db_active ^= 1; + db_nextpri = db[db_active].p; + + /* Clear the OT of the next frame */ + ClearOTagR( db[db_active].ot, OT_LEN ); + + /* Apply display/drawing environments */ + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + /* Enable display */ + SetDispMask( 1 ); + + /* Start drawing the OT of the last buffer */ + DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); + +} \ No newline at end of file diff --git a/examples/gte/makefile b/examples/gte/makefile new file mode 100644 index 0000000..763b3d8 --- /dev/null +++ b/examples/gte/makefile @@ -0,0 +1,39 @@ +include ../sdk-common.mk + +TARGET = gte.elf + +CFILES = $(notdir $(wildcard *.c)) +CPPFILES = $(notdir $(wildcard *.cpp)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)) + +INCLUDE += +LIBDIRS += + +LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lgcc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) diff --git a/examples/makefile b/examples/makefile new file mode 100644 index 0000000..dda76ce --- /dev/null +++ b/examples/makefile @@ -0,0 +1,16 @@ +# Run using make (Linux) or gmake (BSD) +# Part of the PSn00bSDK Project +# 2019 Lameguy64 / Meido-Tek Productions + +TOPTARGETS = all clean + +DIRS = balls gte n00bdemo + + +$(TOPTARGETS): $(DIRS) +$(DIRS): + @$(MAKE) -C $@ $(MAKECMDGOALS) + +clean: $(DIRS) + +.PHONY: $(TOPTARGETS) $(DIRS) diff --git a/examples/n00bdemo/data.h b/examples/n00bdemo/data.h new file mode 100644 index 0000000..3be0e3d --- /dev/null +++ b/examples/n00bdemo/data.h @@ -0,0 +1,12 @@ +#ifndef _DATA_H +#define _DATA_H + +extern unsigned char lz_resources[]; + +/*extern unsigned char smd_mtekdisk[]; +extern unsigned char smd_mtektext[]; +extern unsigned char smd_star[]; +extern unsigned char smd_psn00b[]; +extern unsigned char smd_scarletlogo[];*/ + +#endif \ No newline at end of file diff --git a/examples/n00bdemo/data.s b/examples/n00bdemo/data.s new file mode 100644 index 0000000..3ca33cb --- /dev/null +++ b/examples/n00bdemo/data.s @@ -0,0 +1,31 @@ +.section .data + +.global lz_resources +.type lz_resources, @object +lz_resources: + .incbin "data.lzp" + +#.global smd_mtekdisk +#.type smd_mtekdisk, @object +#smd_mtekdisk: +# .incbin "data/mtekdisk.smd" + +#.global smd_mtektext +#.type smd_mtektext, @object +#smd_mtektext: +# .incbin "data/mtektext.smd" + +#.global smd_star +#.type smd_star, @object +#smd_star: +# .incbin "data/star.smd" + +#.global smd_psn00b +#.type smd_psn00b, @object +#smd_psn00b: +# .incbin "data/psn00blogo.smd" + +#.global smd_scarletlogo +#.type smd_scarletlogo, @object +#smd_scarletlogo: +# .incbin "data/scarletlogo.smd" \ No newline at end of file diff --git a/examples/n00bdemo/data.xml b/examples/n00bdemo/data.xml new file mode 100644 index 0000000..292a325 --- /dev/null +++ b/examples/n00bdemo/data.xml @@ -0,0 +1,49 @@ + + + + + data/petscum16c.tim + data/bungirl.tim + + + data/clktower.tim + data/riftbld1.tim + data/riftbld2.tim + data/hatkid.tim + + data/celmapi.tim + + data/lamelotl16c.tim + data/n00blogo-pixel.tim + data/font.tim + + + + + + + data/mtekdisk.smd + data/mtektext.smd + data/star.smd + data/psn00blogo.smd + data/logo.smd + + + data/petscum.smd + data/bulb.smd + + + data/bungirl.smd + + data/star_mask.smd + data/timerift.smd + data/rbowshade.smd + + data/hatkid.smd + + + textures.qlp + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/bulb.smd b/examples/n00bdemo/data/bulb.smd new file mode 100644 index 0000000..9b77c6d Binary files /dev/null and b/examples/n00bdemo/data/bulb.smd differ diff --git a/examples/n00bdemo/data/bulb.smx b/examples/n00bdemo/data/bulb.smx new file mode 100644 index 0000000..89225e6 --- /dev/null +++ b/examples/n00bdemo/data/bulb.smx @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/bungirl.smd b/examples/n00bdemo/data/bungirl.smd new file mode 100644 index 0000000..63f96b5 Binary files /dev/null and b/examples/n00bdemo/data/bungirl.smd differ diff --git a/examples/n00bdemo/data/bungirl.smx b/examples/n00bdemo/data/bungirl.smx new file mode 100644 index 0000000..6093d70 --- /dev/null +++ b/examples/n00bdemo/data/bungirl.smx @@ -0,0 +1,5608 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/bungirl.tim b/examples/n00bdemo/data/bungirl.tim new file mode 100644 index 0000000..11ee9f4 Binary files /dev/null and b/examples/n00bdemo/data/bungirl.tim differ diff --git a/examples/n00bdemo/data/celmapi.bmp b/examples/n00bdemo/data/celmapi.bmp new file mode 100644 index 0000000..f44f94f Binary files /dev/null and b/examples/n00bdemo/data/celmapi.bmp differ diff --git a/examples/n00bdemo/data/celmapi.tim b/examples/n00bdemo/data/celmapi.tim new file mode 100644 index 0000000..c043e0b Binary files /dev/null and b/examples/n00bdemo/data/celmapi.tim differ diff --git a/examples/n00bdemo/data/clktower.tim b/examples/n00bdemo/data/clktower.tim new file mode 100644 index 0000000..15c6edc Binary files /dev/null and b/examples/n00bdemo/data/clktower.tim differ diff --git a/examples/n00bdemo/data/font.bmp b/examples/n00bdemo/data/font.bmp new file mode 100644 index 0000000..1d078f3 Binary files /dev/null and b/examples/n00bdemo/data/font.bmp differ diff --git a/examples/n00bdemo/data/font.tim b/examples/n00bdemo/data/font.tim new file mode 100644 index 0000000..64cdad2 Binary files /dev/null and b/examples/n00bdemo/data/font.tim differ diff --git a/examples/n00bdemo/data/hatkid.png b/examples/n00bdemo/data/hatkid.png new file mode 100644 index 0000000..369ce32 Binary files /dev/null and b/examples/n00bdemo/data/hatkid.png differ diff --git a/examples/n00bdemo/data/hatkid.smd b/examples/n00bdemo/data/hatkid.smd new file mode 100644 index 0000000..a68f414 Binary files /dev/null and b/examples/n00bdemo/data/hatkid.smd differ diff --git a/examples/n00bdemo/data/hatkid.smx b/examples/n00bdemo/data/hatkid.smx new file mode 100644 index 0000000..f9e8012 --- /dev/null +++ b/examples/n00bdemo/data/hatkid.smx @@ -0,0 +1,1281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/n00bdemo/data/hatkid.tim b/examples/n00bdemo/data/hatkid.tim new file mode 100644 index 0000000..b2e9318 Binary files /dev/null and b/examples/n00bdemo/data/hatkid.tim differ diff --git a/examples/n00bdemo/data/lamelotl16c.png b/examples/n00bdemo/data/lamelotl16c.png new file mode 100644 index 0000000..67490c8 Binary files /dev/null and b/examples/n00bdemo/data/lamelotl16c.png differ diff --git a/examples/n00bdemo/data/lamelotl16c.tim b/examples/n00bdemo/data/lamelotl16c.tim new file mode 100644 index 0000000..194c034 Binary files /dev/null and b/examples/n00bdemo/data/lamelotl16c.tim differ diff --git a/examples/n00bdemo/data/lightworld.smd b/examples/n00bdemo/data/lightworld.smd new file mode 100644 index 0000000..4c1bb59 Binary files /dev/null and b/examples/n00bdemo/data/lightworld.smd differ diff --git a/examples/n00bdemo/data/lightworld.smx b/examples/n00bdemo/data/lightworld.smx new file mode 100644 index 0000000..665e8c9 --- /dev/null +++ b/examples/n00bdemo/data/lightworld.smx @@ -0,0 +1,1097 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/n00bdemo/data/logo.smd b/examples/n00bdemo/data/logo.smd new file mode 100644 index 0000000..9eb1954 Binary files /dev/null and b/examples/n00bdemo/data/logo.smd differ diff --git a/examples/n00bdemo/data/logo.smx b/examples/n00bdemo/data/logo.smx new file mode 100644 index 0000000..1ed0549 --- /dev/null +++ b/examples/n00bdemo/data/logo.smx @@ -0,0 +1,1169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/mtekdisk.smd b/examples/n00bdemo/data/mtekdisk.smd new file mode 100644 index 0000000..f99bd46 Binary files /dev/null and b/examples/n00bdemo/data/mtekdisk.smd differ diff --git a/examples/n00bdemo/data/mtekdisk.smx b/examples/n00bdemo/data/mtekdisk.smx new file mode 100644 index 0000000..fce2fa2 --- /dev/null +++ b/examples/n00bdemo/data/mtekdisk.smx @@ -0,0 +1,379 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/mtektext.smd b/examples/n00bdemo/data/mtektext.smd new file mode 100644 index 0000000..a158521 Binary files /dev/null and b/examples/n00bdemo/data/mtektext.smd differ diff --git a/examples/n00bdemo/data/mtektext.smx b/examples/n00bdemo/data/mtektext.smx new file mode 100644 index 0000000..50aa59d --- /dev/null +++ b/examples/n00bdemo/data/mtektext.smx @@ -0,0 +1,671 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/n00blogo-pixel.png b/examples/n00bdemo/data/n00blogo-pixel.png new file mode 100644 index 0000000..db7aa89 Binary files /dev/null and b/examples/n00bdemo/data/n00blogo-pixel.png differ diff --git a/examples/n00bdemo/data/n00blogo-pixel.tim b/examples/n00bdemo/data/n00blogo-pixel.tim new file mode 100644 index 0000000..c372593 Binary files /dev/null and b/examples/n00bdemo/data/n00blogo-pixel.tim differ diff --git a/examples/n00bdemo/data/petscum.smd b/examples/n00bdemo/data/petscum.smd new file mode 100644 index 0000000..9a1c8eb Binary files /dev/null and b/examples/n00bdemo/data/petscum.smd differ diff --git a/examples/n00bdemo/data/petscum.smx b/examples/n00bdemo/data/petscum.smx new file mode 100644 index 0000000..8f1b9e5 --- /dev/null +++ b/examples/n00bdemo/data/petscum.smx @@ -0,0 +1,1093 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/n00bdemo/data/petscum16c.png b/examples/n00bdemo/data/petscum16c.png new file mode 100644 index 0000000..c9d115c Binary files /dev/null and b/examples/n00bdemo/data/petscum16c.png differ diff --git a/examples/n00bdemo/data/petscum16c.tim b/examples/n00bdemo/data/petscum16c.tim new file mode 100644 index 0000000..18af842 Binary files /dev/null and b/examples/n00bdemo/data/petscum16c.tim differ diff --git a/examples/n00bdemo/data/psn00blogo.smd b/examples/n00bdemo/data/psn00blogo.smd new file mode 100644 index 0000000..3c1412a Binary files /dev/null and b/examples/n00bdemo/data/psn00blogo.smd differ diff --git a/examples/n00bdemo/data/psn00blogo.smx b/examples/n00bdemo/data/psn00blogo.smx new file mode 100644 index 0000000..0921b6c --- /dev/null +++ b/examples/n00bdemo/data/psn00blogo.smx @@ -0,0 +1,745 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/rbowshade.smd b/examples/n00bdemo/data/rbowshade.smd new file mode 100644 index 0000000..c218d05 Binary files /dev/null and b/examples/n00bdemo/data/rbowshade.smd differ diff --git a/examples/n00bdemo/data/rbowshade.smx b/examples/n00bdemo/data/rbowshade.smx new file mode 100644 index 0000000..6648b5d --- /dev/null +++ b/examples/n00bdemo/data/rbowshade.smx @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/riftbld1.tim b/examples/n00bdemo/data/riftbld1.tim new file mode 100644 index 0000000..5581bb3 Binary files /dev/null and b/examples/n00bdemo/data/riftbld1.tim differ diff --git a/examples/n00bdemo/data/riftbld2.tim b/examples/n00bdemo/data/riftbld2.tim new file mode 100644 index 0000000..4048024 Binary files /dev/null and b/examples/n00bdemo/data/riftbld2.tim differ diff --git a/examples/n00bdemo/data/star.smd b/examples/n00bdemo/data/star.smd new file mode 100644 index 0000000..68a5725 Binary files /dev/null and b/examples/n00bdemo/data/star.smd differ diff --git a/examples/n00bdemo/data/star.smx b/examples/n00bdemo/data/star.smx new file mode 100644 index 0000000..c91947e --- /dev/null +++ b/examples/n00bdemo/data/star.smx @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/n00bdemo/data/star_mask.smd b/examples/n00bdemo/data/star_mask.smd new file mode 100644 index 0000000..fe624fe Binary files /dev/null and b/examples/n00bdemo/data/star_mask.smd differ diff --git a/examples/n00bdemo/data/star_mask.smx b/examples/n00bdemo/data/star_mask.smx new file mode 100644 index 0000000..695bd47 --- /dev/null +++ b/examples/n00bdemo/data/star_mask.smx @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/n00bdemo/data/timerift.smd b/examples/n00bdemo/data/timerift.smd new file mode 100644 index 0000000..dc22e4d Binary files /dev/null and b/examples/n00bdemo/data/timerift.smd differ diff --git a/examples/n00bdemo/data/timerift.smx b/examples/n00bdemo/data/timerift.smx new file mode 100644 index 0000000..38d53f6 --- /dev/null +++ b/examples/n00bdemo/data/timerift.smx @@ -0,0 +1,1085 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/n00bdemo/disp.c b/examples/n00bdemo/disp.c new file mode 100644 index 0000000..5a9bb22 --- /dev/null +++ b/examples/n00bdemo/disp.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include "smd.h" +#include "disp.h" + +DISPENV disp; +DRAWENV draw; + +char pribuff[2][131072]; +unsigned int ot[2][OT_LEN]; +char *nextpri; +int db = 0; + +MATRIX mtx; + + +void initDisplay() { + + ResetGraph( 3 ); + + if( GetVideoMode() == MODE_NTSC ) { + SetDefDispEnv( &disp, 0, 0, 640, 480 ); + SetDefDrawEnv( &draw, 0, 0, 640, 480 ); + scSetClipRect( 0, 0, 640, 480 ); + printf("NTSC System.\n"); + } else { + SetDefDispEnv( &disp, 0, 0, 640, 512 ); + SetDefDrawEnv( &draw, 0, 0, 640, 512 ); + scSetClipRect( 0, 0, 640, 512 ); + disp.screen.y = 20; + disp.screen.h = 256; + printf("PAL System.\n"); + } + + disp.isinter = 1; + draw.isbg = 1; + + PutDispEnv( &disp ); + PutDrawEnv( &draw ); + + ClearOTagR( ot[0], OT_LEN ); + ClearOTagR( ot[1], OT_LEN ); + nextpri = pribuff[0]; + + InitGeom(); + gte_SetGeomScreen( 320 ); + + if( GetVideoMode() == MODE_NTSC ) { + gte_SetGeomOffset( 320, 240 ); + } else { + gte_SetGeomOffset( 320, 256 ); + } + +} + +void display() { + + VSync(); + DrawSync(); + + PutDrawEnv( &draw ); + DrawOTag( ot[db]+OT_LEN-1 ); + + db ^= 1; + ClearOTagR( ot[db], OT_LEN ); + nextpri = pribuff[db]; + + SetDispMask( 1 ); + +} \ No newline at end of file diff --git a/examples/n00bdemo/disp.h b/examples/n00bdemo/disp.h new file mode 100644 index 0000000..ecf6dcf --- /dev/null +++ b/examples/n00bdemo/disp.h @@ -0,0 +1,25 @@ +#ifndef _DISP_H +#define _DISP_H + +#include + +#define SCENE_TIME 60*15 + +#define CENTERX 320 +#define CENTERY 240 + +#define OT_LEN 260 + +void initDisplay(); +void display(); + +extern unsigned int ot[2][OT_LEN]; +extern char *nextpri; +extern int db; + +extern DISPENV disp; +extern DRAWENV draw; + +extern MATRIX mtx; + +#endif // _DISP_H \ No newline at end of file diff --git a/examples/n00bdemo/lightdemo.c b/examples/n00bdemo/lightdemo.c new file mode 100644 index 0000000..ff858c0 --- /dev/null +++ b/examples/n00bdemo/lightdemo.c @@ -0,0 +1,494 @@ +#include +#include +#include +#include +#include "disp.h" +#include "smd.h" + +extern MATRIX lgt_colmtx; + +extern SMD *o_world; +extern SMD *o_lightbulb; + +void sort_overlay(int showlotl); + +void lightdemo() { + + /* + The point lighting demo is perhaps the most impressive part of + n00bDEMO. A more streamlined version of this demo where you control + various attributes of the light source such as position, intensity + and color might be made as a dedicated example program in the future. + + The point lighting trick is actually not that too complicated. You + basically calculate the distance and direction vector of two points + which are the light source and the vertex of a polygon. + + Calculating the normal whose result can later be used to calculate + the distance between two points is achieved with: + + vec_dir.vx = lgt_point.vx - pri_vert.vx; + vec_dir.vy = lgt_point.vy - pri_vert.vy; + vec_dir.vz = lgt_point.vz - pri_vert.vz; + + The intensity is calculated with (this might not be accurate but this + is faster than applying a square root): + + i = 4096 - ( ( + (vec_dir.vx*vec_dir.vx) + + (vec_dir.vy*vec_dir.vy) + + (vec_dir.vz*vec_dir.vz) ) >> 7 ); + + // Clip minimum intensity + if( i < 0 ) + i = 0; + + This intensity value is then used to set the color of the light source + through the light color matrix. + + col_mtx.m[0][0] = i; + col_mtx.m[1][0] = i; + col_mtx.m[2][0] = i; + gte_SetColorMatrix( &col_mtx ); + + The direction vector can then be used as the direction of the light + source. It is recommended to normalize it first to prevent possible + overflow related issues. + + VectorNormalS( &vec_dir, &vec_norm ); + + lgt_mtx.m[0][0] = vec_norm.vx; + lgt_mtx.m[0][1] = vec_norm.vy; + lgt_mtx.m[0][2] = vec_norm.vz; + + gte_SetLightMatrix( &lgt_mtx ); + + This operation is then performed for each point of a polygon to + achieve a nice smooth shaded point lighting effect. The macros used + are still the same as doing light source calculation with the GTE + the normal way. + + 3D geometry still requires normal data as with most lighting + processing operations. 'Flat' normals (faces with a single normal + vector) work best on flat surfaces while 'smooth' normals (faces with + normals on each point) work best on round or curved surfaces. + + */ + + int i,p_ang; + + SC_OT s_ot; + + SVECTOR rot; + VECTOR pos; + SMD_PRIM s_pri; + + VECTOR l_point; + SVECTOR nrm; + + MATRIX lmtx,llmtx,omtx; + + SVECTOR orot = { 0 }; + + int timeout = SCENE_TIME; + + + // Set clear color to black + setRGB0( &draw, 0, 0, 0 ); + + // Base values for the environment geometry + setVector( &pos, 0, 0, 600 ); + setVector( &rot, 512, 0, 0 ); + + // Set base tpage value for the SMD drawing routines + smdSetBaseTPage( 0x200 ); + + // Set back or ambient color to black for pure darkness + gte_SetBackColor( 0, 0, 0 ); + + memset( &llmtx, 0, sizeof(MATRIX) ); + + + // demo loop + while( 1 ) { + + char buff[32]; + + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + rot.vy += 4; + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + + setVector( &l_point, (icos( p_ang )>>2)>>2, -350+(icos( p_ang<<1 )>>4), (isin( p_ang )>>2)>>2 ); + p_ang += 16; + + + // Begin parsing the SMD data of the environment + OpenSMD( o_world ); + + // Prototype point lighting renderer + while( ReadSMD( &s_pri ) ) { + + VECTOR v_dir; + SVECTOR v_nrm; + VECTOR v_sqr; + + int flg; + + if( s_pri.prim_id.texture ) { + + POLY_GT4 *pri; + + // Perform standard rotate, translate and perspective + // transformation of the geometry + pri = (POLY_GT4*)nextpri; + + gte_ldv3( + &o_world->p_verts[s_pri.v0], + &o_world->p_verts[s_pri.v1], + &o_world->p_verts[s_pri.v2] ); + + gte_rtpt(); + + gte_nclip(); // Backface culling + + gte_stopz( &flg ); + + if( flg < 0 ) + continue; + + gte_stsxy3( &pri->x0, &pri->x1, &pri->x2 ); + + gte_ldv0( &o_world->p_verts[s_pri.v3] ); + gte_rtps(); + + gte_avsz4(); // Depth sort + gte_stotz( &flg ); + + if( (flg>>2) >= OT_LEN ) + continue; + + gte_stsxy( &pri->x3 ); + + + // Load base color of polygon to GTE + gte_ldrgb( &s_pri.r0 ); + + // Load normal of polygon + gte_ldv0( &o_world->p_norms[s_pri.n0] ); + + // Calculate the direction between the vertex of the + // polygon and the light source + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v0].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v0].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v0].vz; + + // Calculate distance and light intensity using square + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + // Clip minimum intensity + if( i < 0 ) + i = 0; + + // Set intensity to color matrix + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + gte_SetColorMatrix( &llmtx ); + + // Normalize light direction and set it to light matrix + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + + // Calculate (output is retrieved through gte_strgb) + gte_nccs(); + + + // Repeat process for the next 3 vertices + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v1].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v1].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v1].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r0 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v2].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v2].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v2].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r1 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v3].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v3].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v3].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r2 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + setUV4( pri, + s_pri.tu0, s_pri.tv0, + s_pri.tu1, s_pri.tv1, + s_pri.tu2, s_pri.tv2, + s_pri.tu3, s_pri.tv3 ); + + pri->tpage = s_pri.tpage; + pri->clut = s_pri.clut; + + setPolyGT4( pri ); + addPrim( ot[db]+(flg>>2), pri ); + nextpri += sizeof(POLY_GT4); + + gte_strgb( &pri->r3 ); + + } else { + + POLY_G4 *pri; + + pri = (POLY_G4*)nextpri; + + gte_ldv3( + &o_world->p_verts[s_pri.v0], + &o_world->p_verts[s_pri.v1], + &o_world->p_verts[s_pri.v2] ); + + gte_rtpt(); + + gte_nclip(); + + gte_stopz( &flg ); + + if( flg < 0 ) + continue; + + gte_stsxy3( &pri->x0, &pri->x1, &pri->x2 ); + + gte_ldv0( &o_world->p_verts[s_pri.v3] ); + gte_rtps(); + + gte_avsz4(); + gte_stotz( &flg ); + + if( (flg>>2) >= OT_LEN ) + continue; + + gte_stsxy( &pri->x3 ); + + gte_ldrgb( &s_pri.r0 ); + gte_ldv0( &o_world->p_norms[s_pri.n0] ); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v0].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v0].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v0].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v1].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v1].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v1].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r0 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v2].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v2].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v2].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r1 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + v_dir.vx = l_point.vx - o_world->p_verts[s_pri.v3].vx; + v_dir.vy = l_point.vy - o_world->p_verts[s_pri.v3].vy; + v_dir.vz = l_point.vz - o_world->p_verts[s_pri.v3].vz; + + i = 4096 - ( ( + (v_dir.vx*v_dir.vx) + + (v_dir.vy*v_dir.vy) + + (v_dir.vz*v_dir.vz) ) >> 7 ); + + if( i < 0 ) + i = 0; + + llmtx.m[0][0] = i; + llmtx.m[1][0] = i; + llmtx.m[2][0] = i; + + gte_strgb( &pri->r2 ); + + gte_SetColorMatrix( &llmtx ); + VectorNormalS( &v_dir, &v_nrm ); + lmtx.m[0][0] = v_nrm.vx; + lmtx.m[0][1] = v_nrm.vy; + lmtx.m[0][2] = v_nrm.vz; + gte_SetLightMatrix( &lmtx ); + gte_nccs(); + + setPolyG4( pri ); + addPrim( ot[db]+(flg>>2), pri ); + + nextpri += sizeof(POLY_G4); + + gte_strgb( &pri->r3 ); + + } + + } + + + // Sort the light bulb to represent the position of the light source + orot.vx += 32; + orot.vy += 32; + orot.vz += 32; + + RotMatrix( &orot, &omtx ); + TransMatrix( &omtx, &l_point ); + + CompMatrixLV( &mtx, &omtx, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + s_ot.ot = ot[db]; + s_ot.otlen = OT_LEN; + s_ot.zdiv = 2; + s_ot.zoff = 0; + + nextpri = smdSortModel( &s_ot, nextpri, o_lightbulb ); + + + // Sort overlay and display + sort_overlay( 1 ); + + display(); + + timeout--; + if( timeout < 0 ) + break; + + } + +} \ No newline at end of file diff --git a/examples/n00bdemo/logo.c b/examples/n00bdemo/logo.c new file mode 100644 index 0000000..3fdef5e --- /dev/null +++ b/examples/n00bdemo/logo.c @@ -0,0 +1,428 @@ +#include +#include +#include +#include +#include +#include +#include "malloc.h" +#include "smd.h" +#include "lzp.h" + +#include "disp.h" +#include "data.h" + +#define MAX_STARS 64 + + +typedef struct { + int x,y; + int xvel,yvel; + int scale; + int rot,rotv; +} PARTICLE; + +typedef struct { + unsigned int tag; + unsigned int tpage; + unsigned int mask1; + unsigned char r0,g0,b0,code; + short x0,y0; + short x1,y1; + short x2,y2; + short x3,y3; + unsigned int mask2; +} MASKP_F4; + +typedef struct { + unsigned int tag; + unsigned int tpage; + unsigned char r0,g0,b0,code; + short x0,y0; + short w,h; +} FADERECT; + + +SMD *o_psn00b, *o_n00blogo; + + +typedef struct { + unsigned int *prev; + unsigned int *next; + int size; +} NODE; + +void DumpHeap() { + + NODE *n = (NODE*)GetBSSend(); + + printf( "--\n" ); + + while( 1 ) { + + printf( "B:%08p P:%08p N:%08p SZ:%d BS:%d\n", + n, n->prev, n->next, n->size, + ((unsigned int)n->next - (unsigned int)n) ); + + if ( !n->next ) + break; + + n = (NODE*)n->next; + + } + +} + + +void intro() { + + SVECTOR quad_coords[] = { + { -100, -100, 0, 0 }, + { 100, -100, 0, 0 }, + { -100, 100, 0, 0 }, + { 100, 100, 0, 0 } + }; + + PARTICLE stars[MAX_STARS]; + + VECTOR mpos; + SVECTOR mrot,trot; + SC_OT s_ot; + + SMD *o_disk, *o_star, *o_text, *o_psn00b, *o_n00blogo; + + int i,count = 0; + + int logo_scale; + int logo_rot; + + int logo_yvel; + int logo_ypos; + int logo_step; + int logo_spin; + int logo_svel; + int logo_count = 0; + int logo_tscale; + + int logo_n00b_spin; + int logo_fade = 0; + + struct { + int step; + int yvel; + int ypos; + int rot; + int scale; + int spin; + int spinvel; + int tscale; + int trot; + } mtek = { + 0, + 0, + ONE*750, + -ONE*512, + ONE*7, + 0, + 0, + 3072, + 0 + }; + + struct { + VECTOR pos; + int scale; + int scarlet_spin; + } psn00b = { + { 0, 0, 0 }, + ONE, + 1024 + }; + + + i = lzpSearchFile( "mtekdisk", lz_resources ); + o_disk = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_disk, lz_resources, i ); + smdInitData( o_disk ); + + i = lzpSearchFile( "mtektext", lz_resources ); + o_text = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_text, lz_resources, i ); + smdInitData( o_text ); + + i = lzpSearchFile( "starsprite", lz_resources ); + o_star = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_star, lz_resources, i ); + smdInitData( o_star ); + + i = lzpSearchFile( "psn00blogo", lz_resources ); + o_psn00b = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_psn00b, lz_resources, i ); + smdInitData( o_psn00b ); + + i = lzpSearchFile( "n00blogo", lz_resources ); + o_n00blogo = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_n00blogo, lz_resources, i ); + smdInitData( o_n00blogo ); + + //DumpHeap(); + + + // Set some Scarlet global parameters + smdSetBaseTPage( 0x200 ); + + // Change clear color + setRGB0( &draw, 255, 255, 255 ); + + setVector( &trot, 0, 0, 0 ); + + + // Initialize stars + for( i=0; i 360 ) { + mtek.spin -= mtek.spinvel; + mtek.spinvel += 1280; + } + + setVector( &mpos, 0, -(mtek.ypos>>12)-20, 400 ); + setVector( &mrot, 0, mtek.spin>>12, mtek.rot>>12 ); + + RotMatrix( &mrot, &mtx ); + TransMatrix( &mtx, &mpos ); + setVector( &mpos, mtek.scale, mtek.scale, 4096 ); + ScaleMatrix( &mtx, &mpos ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+10, nextpri, o_disk ); + + + if( mtek.step > 0 ) { + + setVector( &mpos, 0, 180, 400 ); + TransMatrix( &mtx, &mpos ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+8, nextpri, o_text ); + + if( logo_count < 480 ) { + + SVECTOR srot; + + for( i=0; i>12, stars[i].y>>12, 320 ); + setVector( &srot, 0, 0, stars[i].rot>>12 ); + + stars[i].x += stars[i].xvel; + stars[i].y += stars[i].yvel; + + stars[i].yvel += 512; + stars[i].rot += stars[i].rotv; + + RotMatrix( &srot, &mtx ); + TransMatrix( &mtx, &mpos ); + + setVector( &mpos, stars[i].scale, stars[i].scale, 4096 ); + ScaleMatrix( &mtx, &mpos ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+6, nextpri, o_star ); + + } + + } + + } + + if( !mtek.step ) { + mtek.rot -= ONE*20; + } else if( mtek.step == 1 ) { + mtek.rot += ( -mtek.rot )>>4; + } + + + if( mtek.step < 2 ) { + mtek.scale += (ONE-mtek.scale )>>5; + mtek.yvel += 512; + mtek.ypos -= mtek.yvel; + } + + + if( ( mtek.ypos <= 0 ) && ( mtek.yvel > 0 ) ) { + mtek.yvel = -ONE*6; + mtek.step++; + } + + // Does the transition effect + if( logo_count > 480 ) { + + TILE *rect = (TILE*)nextpri; + + mtek.trot += 16; + + setTile( rect ); + setXY0( rect, 0, 0 ); + setWH( rect, 640, 511 ); + setRGB0( rect, 0, 0, 0 ); + addPrim( ot[db]+4, rect ); + nextpri += sizeof(TILE); + + setVector( &mrot, 0, 0, mtek.trot ); + setVector( &mpos, mtek.tscale, mtek.tscale, 4096 ); + + RotMatrix( &mrot, &mtx ); + ScaleMatrix( &mtx, &mpos ); + + gte_SetRotMatrix( &mtx ); + + for( i=0; i<6; i++ ) { + + MASKP_F4 *pol4 = (MASKP_F4*)nextpri; + + setVector( &mpos, -100+(100*(i%3)), -60+(120*(i/3)), 160 ); + TransMatrix( &mtx, &mpos ); + gte_SetTransMatrix( &mtx ); + + pol4->tag = 0x08000000; + pol4->tpage = 0xe1000020; + pol4->mask1 = 0xe6000001; + pol4->mask2 = 0xe6000002; + pol4->code = 0x2A; + + gte_ldv3( &quad_coords[0], &quad_coords[1], &quad_coords[2] ); + gte_rtpt(); + gte_stsxy0( &pol4->x0 ); + gte_ldv0( &quad_coords[3] ); + gte_rtps(); + gte_stsxy3( &pol4->x1, &pol4->x2, &pol4->x3 ); + setRGB0( pol4, 0, 0, 0 ); + + addPrim( ot[db]+4, pol4 ); + nextpri += sizeof(MASKP_F4); + + } + + mtek.tscale += ( -mtek.tscale )>>6; + + } + + } else { + + setRGB0( &draw, 0, 0, 0 ); + + } + + if( logo_count >= 480 ) { + + if( logo_count > 840 ) { + + psn00b.pos.vx += ((ONE*-450)-psn00b.pos.vx)>>4; + psn00b.pos.vy += ((ONE*350)-psn00b.pos.vy)>>4; + + setVector( &mpos, 0, 0, 600 ); + mpos.vx = psn00b.pos.vx>>12; + mpos.vy = psn00b.pos.vy>>12; + + psn00b.scale += ( 1536-psn00b.scale )>>4; + + setVector( &mrot, 0, 0, 0 ); + + RotMatrix( &mrot, &mtx ); + TransMatrix( &mtx, &mpos ); + + setVector( &mpos, psn00b.scale, psn00b.scale, ONE ); + + ScaleMatrix( &mtx, &mpos ); + + } else { + + setVector( &mpos, 0, 0, 600 ); + setVector( &mrot, 0, logo_n00b_spin, 0 ); + + RotMatrix( &mrot, &mtx ); + TransMatrix( &mtx, &mpos ); + + logo_n00b_spin += ( -logo_n00b_spin )>>6; + + } + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+3, nextpri, o_psn00b ); + + if( logo_count > 900 ) { + + setVector( &mpos, 0, 0, 250 ); + setVector( &mrot, psn00b.scarlet_spin, 0, 0 ); + + RotMatrix( &mrot, &mtx ); + TransMatrix( &mtx, &mpos ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+3, nextpri, o_n00blogo ); + + psn00b.scarlet_spin += ( -psn00b.scarlet_spin )>>6; + + } + + } + + if( logo_count > 1200 ) { + + FADERECT *fade = (FADERECT*)nextpri; + + fade->tag = 0x04000000; + fade->tpage = 0xe1000040; + fade->code = 0x62; + + setRGB0( fade, logo_fade, logo_fade, logo_fade ); + setXY0( fade, 0, 0 ); + setWH( fade, 640, 480 ); + addPrim( ot[db]+2, fade ); + + if( logo_fade < 250 ) { + logo_fade += 4; + } + + nextpri += sizeof(FADERECT); + + } + + display(); + + logo_count++; + + } + + free( o_disk ); + free( o_text ); + free( o_star ); + free( o_psn00b ); + free( o_n00blogo ); + +} diff --git a/examples/n00bdemo/logo.h b/examples/n00bdemo/logo.h new file mode 100644 index 0000000..6429c8e --- /dev/null +++ b/examples/n00bdemo/logo.h @@ -0,0 +1,6 @@ +#ifndef _LOGO_H +#define _LOGO_H + +void intro(); + +#endif // _LOGO_H diff --git a/examples/n00bdemo/main.c b/examples/n00bdemo/main.c new file mode 100644 index 0000000..2a5874f --- /dev/null +++ b/examples/n00bdemo/main.c @@ -0,0 +1,650 @@ +/* + * LibPSn00b Example Programs + * + * n00bDEMO Source Code + * 2019 Meido-Tek Productions / PSn00bSDK Project + * + * To build, simply run make. Make sure you have the lzpack tool accessible + * through your PATH environment variable. + * + * Demo by Lameguy64 + * + * Changelog: + * + * Apr 4, 2019 - Some code clean-up and added more comments. + * + * Mar 20, 2019 - Initial completed version. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "malloc.h" +#include "smd.h" +#include "data.h" +#include "disp.h" +#include "logo.h" +#include "plasma_tbl.h" + + +// Standard light color matrix +MATRIX lgt_colmtx = { + //#1,#2,#3 + ONE, 0, 0, // R + ONE, 0, 0, // G + ONE, 0, 0 // B +}; + +// SMD data global pointers +SMD *o_rbowshade; +SMD *o_world, *o_lightbulb; +SMD *o_timerift, *o_star; +SMD *o_hatkid,*o_bungirl;; + +// TPage and CLUT globals +unsigned short lamelotl_tpage,psn00b_tpage; +unsigned short font_tpage,font_clut; +SPRT llotl_sprite; +SPRT psn00b_sprite; + + +// Some function definition +void sort_overlay(int showlotl); +void lightdemo(); + + +void UploadTIM(TIM_IMAGE *tim) { + + /* + Very simple texture upload function + */ + + LoadImage( tim->prect, tim->paddr ); + + if( tim->mode & 0x8 ) + LoadImage( tim->crect, tim->caddr ); + +} + +void loadTextures() { + + /* + Unpack textures from an embedded LZP archive and upload them to VRAM. + */ + int i; + int *tex_buff,*ttim,j; + TIM_IMAGE tim; + + i = lzpSearchFile( "textures", lz_resources ); + tex_buff = (int*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( tex_buff, lz_resources, i ); + + + for( j=0; jx, tim.prect->y )|0x200; + setSprt( &psn00b_sprite ); + setClut( &psn00b_sprite, tim.crect->x, tim.crect->y ); + setWH( &psn00b_sprite, tim.prect->w<<2, tim.prect->h ); + setUV0( &psn00b_sprite, (tim.prect->x%64)<<2, tim.prect->y ); + setRGB0( &psn00b_sprite, 128, 128, 128 ); + + + GetTimInfo( (unsigned int*)qlpFileAddr( + qlpFindFile( "lamelotl", tex_buff ), tex_buff ), &tim ); + + UploadTIM( &tim ); + + lamelotl_tpage = getTPage( 0, 0, tim.prect->x, tim.prect->y )|0x200; + setSprt( &llotl_sprite ); + setClut( &llotl_sprite, tim.crect->x, tim.crect->y ); + setWH( &llotl_sprite, tim.prect->w<<2, tim.prect->h ); + setUV0( &llotl_sprite, 0, 0 ); + setRGB0( &llotl_sprite, 128, 128, 128 ); + + + GetTimInfo( (unsigned int*)qlpFileAddr( + qlpFindFile( "celmap", tex_buff ), tex_buff ), &tim ); + + UploadTIM( &tim ); + + smdSetCelTex( getTPage( 0, 2, tim.prect->x, tim.prect->y )|0x200, + getClut( tim.crect->x, tim.crect->y ) ); + smdSetCelParam( 3, 3, 0x4f4f4f ); + + + GetTimInfo( (unsigned int*)qlpFileAddr( + qlpFindFile( "font", tex_buff ), tex_buff ), &tim ); + + UploadTIM( &tim ); + + font_tpage = getTPage( 0, 1, tim.prect->x, tim.prect->y )|0x200; + font_clut = getClut( tim.crect->x, tim.crect->y ); + +} + +void unpackModels() { + + /* + Unpack model data from an embedded LZP archive. + */ + + int i; + + i = lzpSearchFile( "rbowshade", lz_resources ); + o_rbowshade = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_rbowshade, lz_resources, i ); + smdInitData( o_rbowshade ); + + i = lzpSearchFile( "bungirl", lz_resources ); + o_bungirl = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_bungirl, lz_resources, i ); + smdInitData( o_bungirl ); + + i = lzpSearchFile( "lightworld", lz_resources ); + o_world = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_world, lz_resources, i ); + smdInitData( o_world ); + + i = lzpSearchFile( "lightbulb", lz_resources ); + o_lightbulb = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_lightbulb, lz_resources, i ); + smdInitData( o_lightbulb ); + + i = lzpSearchFile( "timerift", lz_resources ); + o_timerift = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_timerift, lz_resources, i ); + smdInitData( o_timerift ); + + i = lzpSearchFile( "starmask", lz_resources ); + o_star = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_star, lz_resources, i ); + smdInitData( o_star ); + + i = lzpSearchFile( "hatkid", lz_resources ); + o_hatkid = (SMD*)malloc( lzpFileSize( lz_resources, i ) ); + lzpUnpackFile( o_hatkid, lz_resources, i ); + smdInitData( o_hatkid ); + +} + +void init() { + + int i; + + // Init display + initDisplay(); + + FntLoad( 960, 0 ); + + // Just to remove all sound + SpuInit(); + + // Load all textures + loadTextures(); + +} + +// Bungirl stuff +void bungirldemo() { + + /* + The bunny girl demo is just a simple demonstration of rendering a 1390 + polygon 3D model of a bunny girl with lighting using SMD drawing routines + from Scarlet Engine. + */ + + SC_OT s_ot; + + MATRIX lmtx; + + SVECTOR rot,brot,srot; + VECTOR pos; + + int timeout = SCENE_TIME; + + // Set clear color + setRGB0( &draw, 63, 0, 127 ); + + // Set tpage base value for SMD drawing routines + smdSetBaseTPage( 0x200 ); + + // Set initial rotation values + setVector( &rot, 192, 0, 0 ); + setVector( &brot, 0, 0, 128 ); + setVector( &srot, 0, 0, 0 ); + + // Set lighting color matrix + gte_SetColorMatrix( &lgt_colmtx ); + + // Set 'backside' or ambient light color + gte_SetBackColor( 113, 113, 113 ); + + + // Demo loop + while( 1 ) { + + // Bungirl position + setVector( &pos, 0, 50, 350 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &brot, &mtx ); + + // Calculate light matrix + lmtx.m[0][0] = isin( -brot.vy<<2 ); + lmtx.m[0][1] = -2048; + lmtx.m[0][2] = icos( -brot.vy<<2 ); + + MulMatrix0( &lmtx, &mtx, &lmtx ); + + // Set matrices + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + gte_SetLightMatrix( &lmtx ); + + // Sort the bungirl model + s_ot.ot = ot[db]; + s_ot.otlen = OT_LEN; + s_ot.zdiv = 1; + s_ot.zoff = 0; + nextpri = smdSortModel( &s_ot, nextpri, o_bungirl ); + + + // Sort the rotating rainbow background + setVector( &pos, 0, 0, 200 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &srot, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_rbowshade ); + + brot.vy += 8; + srot.vz += 4; + + + // Sort overlay then display + sort_overlay( 0 ); + + display(); + + timeout--; + if( timeout < 0 ) + break; + + } + +} + +// Stencil effect stuff +void stencilstuff() { + + /* + The stencil demo is achieved by utilizing the mask bit setting + primitive GP0(E6h). The structure of this primitive is defined as + DR_MASK initialized and set by setDrawMask(). These are not available + in Sony's SDK by default. + + The DR_MASK primitive controls mask bit operations for drawing + primitives such as setting mask bits on every pixel drawn or mask + bit test where pixels won't be drawn on pixels with the mask bit set. + It applies to most graphics drawing primitives except VRAM fill. + The mask bits are stored in the 16th bit of each pixel drawn. + + The semi-transparency bits of a texture always carry over as mask + bits in textured primitives. The only way to clear mask bits is by + using VRAM fill commands or drawing primitives with the set mask + bit operation disabled. + + The stencil effect featured in this demo is achieved by enabling set + mask bit with DR_MASK, drawing semi-transparent primitives using + additive blending but color is all zero to make it completely invisible + but is enough to update the mask bits, disable mask set bit but enable + mask test with DR_MASK and then drawing a rectangle that fills the + entire screen. Semi-transparency mask in textures must not be used when + drawing the scene that will be 'below' the mask layer. + */ + int timeout = SCENE_TIME; + + int spin=0; + + DR_MASK *mask; + TILE *rect; + + SC_OT s_ot; + + SVECTOR rot; + SVECTOR srot; + VECTOR pos; + + // Set clear color + setRGB0( &draw, 127, 0, 63 ); + + // Set tpage base value for SMD drawing routines + smdSetBaseTPage( 0x200 ); + + // Base rotation coordinates + setVector( &rot, 0, 0, 0 ); + setVector( &srot, 0, 0, 0 ); + + // Set perspective + gte_SetGeomScreen( 320 ); + + + // Demo loop + while( timeout > 0 ) { + + + // Draw the timerift background + setVector( &rot, 0, spin, 0 ); + setVector( &pos, 0, 0, 0 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &rot, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + s_ot.ot = ot[db]; + s_ot.otlen = 32; + s_ot.zdiv = 2; + s_ot.zoff = 20; + + nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_timerift ); + + + // Sort mask primitive that enables setting mask bits + mask = (DR_MASK*)nextpri; + setDrawMask( mask, 1, 0 ); + addPrim( ot[db]+20, mask ); + nextpri += sizeof(DR_MASK); + + + // Sort the stars + setVector( &rot, 0, 0, spin<<2 ); + setVector( &pos, + (isin(spin<<2)*icos(spin))>>16, + (icos(spin<<2)*isin(spin))>>16, 400 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &rot, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+19, nextpri, o_star ); + + setVector( &rot, 0, 0, -spin<<2 ); + setVector( &pos, + (isin(-spin<<2)*icos(-spin))>>16, + (icos(-spin<<2)*isin(-spin))>>16, 400 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &rot, &mtx ); + + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+19, nextpri, o_star ); + + + // Sort mask primitive that enables mask bit test + mask = (DR_MASK*)nextpri; + setDrawMask( mask, 0, 1 ); + addPrim( ot[db]+18, mask ); + nextpri += sizeof(DR_MASK); + + + // Sort rectangle that fills the screen + rect = (TILE*)nextpri; + setTile( rect ); + setXY0( rect, 0, 0 ); + setWH( rect, 640, 511 ); + setRGB0( rect, 128, 0, 255 ); + addPrim( ot[db]+17, rect ); + nextpri += sizeof(TILE); + + + // Clear all mask settings + mask = (DR_MASK*)nextpri; + setDrawMask( mask, 0, 0 ); + addPrim( ot[db]+15, mask ); + nextpri += sizeof(DR_MASK); + + + // Sort overlay then display + sort_overlay( 0 ); + + display(); + + spin += 4; + timeout--; + } + +} + +// Orbiting around cel-shaded hatkid stuff +void hatkidstuff() { + + /* + The cel-shading effect works in a similar manner as conventional + per-vertex light source calculation except the color values are used + in a different manner. The resulting color values are divided down + using bit shifts to fit as texture coordinates (usually within the + range of 0-31) which are then used to map to a shading map which is a + simple texture of 3 to 4 shading levels. This technique is very similar + to how cel-shading is achieved on the Gamecube except all the vertex to + texture coordinate conversion is all done on the GX itself. + + To achieve this effect on untextured and textured polygons seamlessly + the shading map is drawn over the original unshaded polygons of the + model as semi-transparent polygons with subtractive blending. The + shading map had to be inverted for this effect to work properly since + blending is subtractive and not multiplicative after all. + */ + + int timeout = SCENE_TIME; + int spin=0; + + SC_OT s_ot; + + MATRIX lmtx; + + SVECTOR rot; + VECTOR pos; + + // Set clear color + setRGB0( &draw, 127, 0, 63 ); + + // Sets base TPage value for SMD drawing routines + smdSetBaseTPage( 0x200 ); + + setVector( &rot, 0, 0, 0 ); + + // Set light color matrix + gte_SetColorMatrix( &lgt_colmtx ); + + // Set back/ambient color to black (required for good cel-shading) + gte_SetBackColor( 0, 0, 0 ); + + gte_SetGeomScreen( 320 ); + + // Demo loop + while( timeout > 0 ) { + + // Sort 3D timerift background + setVector( &rot, spin, spin, spin>>1 ); + setVector( &pos, 0, 0, 0 ); + + TransMatrix( &mtx, &pos ); + RotMatrix( &rot, &mtx ); + + // Fixed light source direction + lmtx.m[0][0] = -2048; + lmtx.m[0][1] = -2048; + lmtx.m[0][2] = -2048; + + // Multiply by rotation matrix to make it relative to the camera rotation + MulMatrix0( &lmtx, &mtx, &lmtx ); + + gte_SetLightMatrix( &lmtx ); + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + nextpri = smdSortModelFlat( ot[db]+(OT_LEN-1), nextpri, o_timerift ); + + + // Sort the cel-shaded hatkid + setVector( &pos, 0, 0, 600 ); + TransMatrix( &mtx, &pos ); + gte_SetTransMatrix( &mtx ); + + s_ot.ot = ot[db]; + s_ot.otlen = 250; + s_ot.zdiv = 1; + s_ot.zoff = 0; + + nextpri = smdSortModelCel( &s_ot, nextpri, o_hatkid ); + + + // Sort overlay then display + sort_overlay( 1 ); + display(); + + spin += 8; + timeout--; + + } + +} + +// Plasma stuff +void genPlasma(char *out, int count); +char *sortPlasma(int *ot, char *pri, char *map); + +void plasmastuff() { + + DR_TPAGE* tp; + char plasbuff[1271]; + + int pcount = 0; + int timeout = SCENE_TIME; + + while( timeout > 0 ) { + + genPlasma( plasbuff, pcount ); + nextpri = sortPlasma( ot[db]+1, nextpri, plasbuff ); + + sort_overlay( 1 ); + + display(); + timeout--; + pcount++; + + } + +} + +// Simple stripe transition effect +void transition() { + + int i,count,comp; + int bheight[16] = { 0 }; + + TILE *tile = (TILE*)nextpri; + draw.isbg = 0; + + while( 1 ) { + + comp = 0; + + for( i=0; i<16; i++ ) { + + if( bheight[i] > 0 ) { + + + setTile( tile ); + setXY0( tile, 0, 32*i ); + setRGB0( tile, 0, 151, 255 ); + setWH( tile, 640, bheight[i] ); + addPrim( ot[db], tile ); + tile++; + + if( bheight[i] < 32 ) + bheight[i]++; + else + comp++; + + } + + } + + if( bheight[count>>1] == 0 ) + bheight[count>>1] = 1; + + display(); + count++; + + if( comp >= 16 ) + break; + + } + + DrawSync(); + + draw.isbg = 1; + +} + +int main(int argc, const char *argv[]) { + + // Init + init(); + + // Do transition + transition(); + + // Do Meido-Tek, PSn00bSDK and n00bDEMO logo intros + intro(); + + // Unpack model data + unpackModels(); + + // Demo sequence loop + while( 1 ) { + + lightdemo(); + bungirldemo(); + stencilstuff(); + hatkidstuff(); + plasmastuff(); + + } + + return 0; +} \ No newline at end of file diff --git a/examples/n00bdemo/makefile b/examples/n00bdemo/makefile new file mode 100644 index 0000000..a87f299 --- /dev/null +++ b/examples/n00bdemo/makefile @@ -0,0 +1,45 @@ +include ../sdk-common.mk + +TARGET = demo.elf + +CFILES = $(notdir $(wildcard *.c)) +AFILES = $(notdir $(wildcard *.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) + +INCLUDE += -I../../libpsn00b/lzp +LIBDIRS += -L../../libpsn00b/lzp + +LIBS = -llzp -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lgcc + +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections +CPPFLAGS = $(CFLAGS) -fno-exceptions +AFLAGS = -g -msoft-float +LDFLAGS = -g -Ttext=0x80010000 -gc-sections + +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +AS = $(PREFIX)as +LD = $(PREFIX)ld + +all: resources $(OFILES) + $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET) + elf2x -q $(TARGET) + +build/%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +resources: + lzpack data.xml + touch data.s + +iso: + mkpsxiso -y -q -o demo.iso iso.xml + +clean: + rm -rf build *.lzp *.qlp $(TARGET) $(TARGET:.elf=.exe) $(TARGET:.elf=.iso) diff --git a/examples/n00bdemo/overlay.c b/examples/n00bdemo/overlay.c new file mode 100644 index 0000000..9b04274 --- /dev/null +++ b/examples/n00bdemo/overlay.c @@ -0,0 +1,199 @@ +#include +#include +#include +#include "disp.h" + +extern const char scroll_text[]; +extern unsigned short lamelotl_tpage,psn00b_tpage; +extern unsigned short font_tpage,font_clut; + +extern SPRT llotl_sprite; +extern SPRT psn00b_sprite; + +u_char font_width[] = { + 10 ,6 ,12 ,16 ,12 ,14 ,14 ,8 ,10 ,10 ,14 ,12 ,8 ,14 ,6 ,14 , + 14 ,6 ,12 ,13 ,14 ,14 ,14 ,14 ,14 ,14 ,6 ,8 ,12 ,14 ,12 ,14 , + 14 ,14 ,14 ,13 ,14 ,14 ,14 ,14 ,14 ,14 ,14 ,14 ,12 ,15 ,14 ,14 , + 14 ,14 ,14 ,13 ,14 ,15 ,15 ,16 ,16 ,16 ,16 ,10 ,14 ,10 ,14 ,14 , + 8 ,14 ,13 ,11 ,13 ,12 ,13 ,12 ,13 ,6 ,14 ,14 ,8 ,16 ,14 ,14 , + 14 ,14 ,13 ,12 ,12 ,14 ,14 ,14 ,13 ,13 ,14 ,10 ,6 ,10 ,16 ,16 +}; + +int scrolltext_pos = 640; +int scrolltext_cpos = 0; +int overlay_count = 0; + +void sort_overlay(int showlotl) { + + SPRT *spr; + SPRT_16 *spr16; + DR_TPAGE *tp; + POLY_G4 *quad; + LINE_G2 *line; + + int i = scrolltext_cpos; + int j, k, tx, par_end = 0; + + tx = scrolltext_pos; + + while( scroll_text[i] != 0 ) { + + if( scroll_text[i] == '\n' ) { + par_end = 1; + break; + } + + j = scroll_text[i]-32; + + if( j > 0 ) { + + spr16 = (SPRT_16*)nextpri; + setSprt16( spr16 ); + setSemiTrans( spr16, 1 ); + setXY0( spr16, tx, 28 ); + setUV0( spr16, (j%16)<<4, (j>>4)<<4 ); + + if( tx < 128 ) { + k = tx; + if( k < 0 ) + k = 0; + setRGB0( spr16, k, k, k ); + } else if( tx > 512 ) { + k = 128-(tx-512); + if( k < 0 ) + k = 0; + setRGB0( spr16, k, k, k ); + } else { + setRGB0( spr16, 128, 128, 128 ); + } + + spr16->clut = font_clut; + addPrim( ot[db], spr16 ); + nextpri += sizeof(SPRT_16); + + } + + tx += font_width[j]; + + if( tx > 640 ) + break; + + i++; + + } + + scrolltext_pos -= 4; + j = scroll_text[scrolltext_cpos]-32; + if( j >= 0 ) { + + if( scrolltext_pos <= -font_width[j] ) { + + scrolltext_pos += font_width[j]; + scrolltext_cpos++; + + } + + } else { + + scrolltext_pos = 0; + scrolltext_cpos++; + + if( par_end ) + scrolltext_pos = 640; + + if( scroll_text[scrolltext_cpos] == 0 ) { + scrolltext_cpos = 0; + scrolltext_pos = 640; + } + + } + + line = (LINE_G2*)nextpri; + setLineG2( line ); + setSemiTrans( line, 1 ); + setXY2( line, 0, 46, 320, 46 ); + setRGB0( line, 0, 0, 0 ); + setRGB1( line, 255, 255, 255 ); + addPrim( ot[db], line ); + line++; + setLineG2( line ); + setSemiTrans( line, 1 ); + setXY2( line, 320, 46, 640, 46 ); + setRGB0( line, 255, 255, 255 ); + setRGB1( line, 0, 0, 0 ); + addPrim( ot[db], line ); + line++; + nextpri = (char*)line; + + tp = (DR_TPAGE*)nextpri; + setDrawTPageVal( tp, font_tpage ); + addPrim( ot[db], tp ); + nextpri += sizeof(DR_TPAGE); + + quad = (POLY_G4*)nextpri; + setPolyG4( quad ); + setSemiTrans( quad, 1 ); + setXY4( quad, + 0, 25, 320, 25, + 0, 46, 320, 46 ); + setRGB0( quad, 0, 0, 0 ); + setRGB1( quad, 64, 64, 64 ); + setRGB2( quad, 0, 0, 0 ); + setRGB3( quad, 64, 64, 64 ); + addPrim( ot[db], quad ); + quad++; + setPolyG4( quad ); + setSemiTrans( quad, 1 ); + setXY4( quad, + 320, 25, 640, 25, + 320, 46, 640, 46 ); + setRGB0( quad, 64, 64, 64 ); + setRGB1( quad, 0, 0, 0 ); + setRGB2( quad, 64, 64, 64 ); + setRGB3( quad, 0, 0, 0 ); + addPrim( ot[db], quad ); + quad++; + nextpri = (char*)quad; + + i = isin( overlay_count )>>9; + + if( GetVideoMode() == MODE_PAL ) { + j = 32; + } else { + j = 0; + } + + tp = (DR_TPAGE*)nextpri; + setDrawTPageVal( tp, getTPage( 0, 2, 0, 0 )|0x200 ); + addPrim( ot[db], tp ); + nextpri += sizeof(DR_TPAGE); + + if( showlotl ) { + + spr = (SPRT*)nextpri; + *spr = llotl_sprite; + setXY0( spr, 440, (200+j)+i ); + addPrim( ot[db], spr ); + nextpri += sizeof(SPRT); + + tp = (DR_TPAGE*)nextpri; + setDrawTPageVal( tp, lamelotl_tpage ); + addPrim( ot[db], tp ); + nextpri += sizeof(DR_TPAGE); + + } + + spr = (SPRT*)nextpri; + *spr = psn00b_sprite; + setXY0( spr, 8, (400+j)-i ); + addPrim( ot[db], spr ); + nextpri += sizeof(SPRT); + + tp = (DR_TPAGE*)nextpri; + setDrawTPageVal( tp, psn00b_tpage ); + addPrim( ot[db], tp ); + nextpri += sizeof(DR_TPAGE); + + overlay_count += 32; + +} \ No newline at end of file diff --git a/examples/n00bdemo/plasma_tbl.c b/examples/n00bdemo/plasma_tbl.c new file mode 100644 index 0000000..2cbd9b6 --- /dev/null +++ b/examples/n00bdemo/plasma_tbl.c @@ -0,0 +1,500 @@ +// These are from Meido-Menu which was a very simple demo I made back in 2013 +// Man, time sure does fly. - Lameguy64 + +unsigned int plasma_colors[256] = { + 0x00000000, + 0x00000408, + 0x00040811, + 0x0008111a, + 0x00081623, + 0x000d1f2c, + 0x00112335, + 0x0011273d, + 0x0016304a, + 0x001a3553, + 0x001f3d5b, + 0x001f4163, + 0x00234a6b, + 0x00274e73, + 0x0027537b, + 0x002c5b83, + 0x00305f8e, + 0x00356795, + 0x00356b9c, + 0x00396fa3, + 0x003d77aa, + 0x003d7bb1, + 0x004183b7, + 0x004687bd, + 0x00468ac6, + 0x004a92cb, + 0x004e95d0, + 0x00539cd5, + 0x0053a0da, + 0x0057a7df, + 0x005baae3, + 0x005bade7, + 0x005fb4ec, + 0x0063b7ef, + 0x0067bdf2, + 0x0067c0f5, + 0x006bc6f7, + 0x006fc8f9, + 0x006fcbfb, + 0x0073d0fc, + 0x0077d3fe, + 0x007bd8fe, + 0x007bdafe, + 0x007fdcfe, + 0x0083e1fe, + 0x0083e3fe, + 0x0087e7fd, + 0x008ae8fb, + 0x008eecf9, + 0x008eeef7, + 0x0092eff5, + 0x0095f2f2, + 0x0095f3ef, + 0x0099f6ec, + 0x009cf7e8, + 0x009cf8e5, + 0x00a0fadf, + 0x00a3fbda, + 0x00a7fcd5, + 0x00a7fdd0, + 0x00aafdcb, + 0x00adfec6, + 0x00adfec0, + 0x00b1feba, + 0x00b4ffb1, + 0x00b7feaa, + 0x00b7fea3, + 0x00bafe9c, + 0x00bdfd95, + 0x00bdfd8e, + 0x00c0fb87, + 0x00c3fb7f, + 0x00c3fa73, + 0x00c6f86b, + 0x00c8f763, + 0x00cbf55b, + 0x00cbf353, + 0x00cef14a, + 0x00d0ef41, + 0x00d0ee39, + 0x00d3ea2c, + 0x00d5e823, + 0x00d8e51a, + 0x00d8e311, + 0x00dae108, + 0x00dcdc00, + 0x00dcda08, + 0x00dfd511, + 0x00e1d31f, + 0x00e3ce27, + 0x00e3cb30, + 0x00e5c839, + 0x00e7c341, + 0x00e7c04a, + 0x00e8ba53, + 0x00eab75b, + 0x00eab467, + 0x00ecad6f, + 0x00eeaa77, + 0x00efa37f, + 0x00efa087, + 0x00f1998e, + 0x00f29595, + 0x00f2929c, + 0x00f38aa7, + 0x00f587ad, + 0x00f67fb4, + 0x00f67bba, + 0x00f773c0, + 0x00f86fc6, + 0x00f86bcb, + 0x00f963d0, + 0x00fa5fd8, + 0x00fb57dc, + 0x00fb53e1, + 0x00fb4ee5, + 0x00fc46e8, + 0x00fc41ec, + 0x00fd39ef, + 0x00fd35f2, + 0x00fe2cf6, + 0x00fe27f8, + 0x00fe23fa, + 0x00fe1afb, + 0x00fe16fd, + 0x00fe0dfe, + 0x00fe08fe, + 0x00fe04fe, + 0x00fe04fe, + 0x00fe08fe, + 0x00fe11fd, + 0x00fe16fc, + 0x00fe1ffb, + 0x00fe23f9, + 0x00fe27f7, + 0x00fe30f5, + 0x00fd35f1, + 0x00fd3dee, + 0x00fd41ea, + 0x00fc46e7, + 0x00fb4ee3, + 0x00fb53df, + 0x00fb5bda, + 0x00fa5fd5, + 0x00f967ce, + 0x00f96bc8, + 0x00f86fc3, + 0x00f777bd, + 0x00f77bb7, + 0x00f683b1, + 0x00f587aa, + 0x00f58aa3, + 0x00f39299, + 0x00f29592, + 0x00f19c8a, + 0x00f1a083, + 0x00efa77b, + 0x00eeaa73, + 0x00eead6b, + 0x00ecb463, + 0x00eab757, + 0x00e8bd4e, + 0x00e8c046, + 0x00e7c33d, + 0x00e5c835, + 0x00e5cb2c, + 0x00e3d023, + 0x00e1d31a, + 0x00dfd80d, + 0x00dfda04, + 0x00dcdc04, + 0x00dae10d, + 0x00dae316, + 0x00d8e71f, + 0x00d5e827, + 0x00d5ea30, + 0x00d3ee3d, + 0x00d0ef46, + 0x00cef24e, + 0x00cef357, + 0x00cbf65f, + 0x00c8f767, + 0x00c8f86f, + 0x00c6fa77, + 0x00c3fb83, + 0x00c0fc8a, + 0x00c0fd92, + 0x00bdfd99, + 0x00bafea0, + 0x00bafea7, + 0x00b7fead, + 0x00b4ffb4, + 0x00b1febd, + 0x00b1fec3, + 0x00adfec8, + 0x00aafdce, + 0x00aafdd3, + 0x00a7fbd8, + 0x00a3fbdc, + 0x00a3fae1, + 0x00a0f8e7, + 0x009cf7ea, + 0x0099f5ee, + 0x0099f3f1, + 0x0095f1f3, + 0x0092eff6, + 0x0092eef8, + 0x008eeafa, + 0x008ae8fc, + 0x0087e5fd, + 0x0087e3fe, + 0x0083e1fe, + 0x007fdcff, + 0x007fdafe, + 0x007bd5fe, + 0x0077d3fd, + 0x0073cefb, + 0x0073cbfa, + 0x006fc8f8, + 0x006bc3f6, + 0x006bc0f3, + 0x0067baf1, + 0x0063b7ee, + 0x0063b4ea, + 0x005fade5, + 0x005baae1, + 0x0057a3dc, + 0x0057a0d8, + 0x00539cd3, + 0x004e95ce, + 0x004e92c8, + 0x004a8ac3, + 0x004687ba, + 0x00417fb4, + 0x00417bad, + 0x003d77a7, + 0x00396fa0, + 0x00396b99, + 0x00356392, + 0x00305f8a, + 0x00305b7f, + 0x002c5377, + 0x00274e6f, + 0x00234667, + 0x0023415f, + 0x001f3957, + 0x001a354e, + 0x001a3046, + 0x00162739, + 0x00112330, + 0x000d1a27, + 0x000d161f, + 0x00081116, + 0x0004080d, + 0x00040404, + 0x00000404 +}; + +short plasma_sin1[] = { + 0, + 6, + 12, + 18, + 24, + 30, + 36, + 42, + 47, + 53, + 59, + 65, + 71, + 76, + 82, + 88, + 93, + 99, + 104, + 110, + 115, + 120, + 125, + 131, + 136, + 141, + 146, + 150, + 155, + 160, + 165, + 169, + 173, + 178, + 182, + 186, + 190, + 194, + 198, + 202, + 205, + 209, + 212, + 216, + 219, + 222, + 225, + 227, + 230, + 233, + 235, + 237, + 240, + 242, + 243, + 245, + 247, + 248, + 250, + 251, + 252, + 253, + 254, + 255, + 255, + 256, + 256, + 256, + 256, + 256, + 256, + 255, + 255, + 254, + 253, + 252, + 251, + 250, + 248, + 247, +}; + +short plasma_sin2[] = { + 0, + 4, + 9, + 13, + 17, + 21, + 24, + 27, + 29, + 30, + 32, + 32, + 32, + 31, + 30, + 28, + 25, + 22, + 19, + 15, + 11, + 7, + 2, + -2, + -7, + -11, + -15, + -19, + -22, + -25, + -28, + -30, + -31, + -32, + -32, + -32, + -30, + -29, + -27, + -24, + -21, + -17, + -13, + -9, + -4, + 0, + 4, + 9, + 13, + 17, + 21, + 24, + 27, + 29, + 30, + 32, + 32, + 32, + 31, + 30 +}; + +short plasma_sin3[] = { +0, + 4, + 9, + 13, + 18, + 22, + 26, + 30, + 34, + 38, + 41, + 44, + 48, + 50, + 53, + 55, + 58, + 59, + 61, + 62, + 63, + 64, + 64, + 64, + 64, + 63, + 62, + 61, + 59, + 58, + 55, + 53, + 50, + 48, + 44, + 41, + 38, + 34, + 30, + 26, + 22, + 18, + 13, + 9, + 4, + 0, + -4, + -9, + -13, + -18, + -22, + -26, + -30, + -34, + -38, + -41, + -44, + -48, + -50, + -53, + -55, + -58, + -59, + -61, + -62, + -63, + -64, + -64, + -64, + -64, + -63, + -62, + -61, + -59, + -58, + -55, + -53, + -50, + -48, + -44, + -41, + -38, + -34, + -30, + -26, + -22, + -18, + -13, + -9, + -4, +}; \ No newline at end of file diff --git a/examples/n00bdemo/plasma_tbl.h b/examples/n00bdemo/plasma_tbl.h new file mode 100644 index 0000000..dd322e6 --- /dev/null +++ b/examples/n00bdemo/plasma_tbl.h @@ -0,0 +1,9 @@ +#ifndef _PLASMA_TBL_H +#define _PLASMA_TBL_H + +unsigned int plasma_colors[256]; +extern short plasma_sin1[]; +extern short plasma_sin2[]; +extern short plasma_sin3[]; + +#endif \ No newline at end of file diff --git a/examples/n00bdemo/plasmagen.s b/examples/n00bdemo/plasmagen.s new file mode 100644 index 0000000..07b3f48 --- /dev/null +++ b/examples/n00bdemo/plasmagen.s @@ -0,0 +1,181 @@ +.set noreorder + +.set POLYG4_tag, 0 +.set POLYG4_rgb0, 4 +.set POLYG4_xy0, 8 +.set POLYG4_rgb1, 12 +.set POLYG4_xy1, 16 +.set POLYG4_rgb2, 20 +.set POLYG4_xy2, 24 +.set POLYG4_rgb3, 28 +.set POLYG4_xy3, 32 +.set POLYG4_len, 36 + +# a0 - Plasma output +# a1 - Counter +.global genPlasma +.type genPlasma, @function +genPlasma: + move $t1, $0 + +.gn_y_loop: move $t0, $0 + +.gn_x_loop: la $v0, plasma_sin1 + sll $v1, $t0, 1 + addu $v1, $v0 + lh $v0, 0($v1) + + la $a2, plasma_sin2 + sll $v1, $t1, 1 + addu $v1, $a2 + lh $v1, 0($v1) + nop + add $v0, $v1 + + add $v1, $t0, $t1 + add $v1, $a1 + divu $v1, 90 + la $a2, plasma_sin3 + mfhi $v1 + + sll $v1, 1 + addu $v1, $a2 + lh $v1, 0($v1) + nop + add $v0, $v1 + + andi $v0, 0xff + + sb $v0, 0($a0) + addu $a0, 1 + + addiu $t0, 1 + blt $t0, 41, .gn_x_loop + nop + + addiu $t1, 1 + blt $t1, 31, .gn_y_loop + nop + + jr $ra + nop + + +# a0 - OT entry +# a1 - Primitive address +# a2 - Plasma map source +.global sortPlasma +.type sortPlasma, @function +sortPlasma: + move $t1, $0 + +.y_loop: + move $t0, $0 + +.x_loop: + lbu $v0, 0($a2) + addiu $a2, 1 + la $a3, plasma_colors + sll $v0, 2 + addu $v0, $a3 + lw $v0, 0($v0) + + lui $v1, 0x3800 + or $v0, $v1 + sw $v0, POLYG4_rgb0($a1) + + + lbu $v0, 0($a2) + nop + sll $v0, 2 + addu $v0, $a3 + lw $v0, 0($v0) + nop + sw $v0, POLYG4_rgb1($a1) + + + lbu $v0, 40($a2) + nop + sll $v0, 2 + addu $v0, $a3 + lw $v0, 0($v0) + nop + sw $v0, POLYG4_rgb2($a1) + + + lbu $v0, 41($a2) + nop + sll $v0, 2 + addu $v0, $a3 + lw $v0, 0($v0) + nop + sw $v0, POLYG4_rgb3($a1) + + + sll $v0, $t0, 4 + andi $v0, 0xffff + sll $v1, $t1, 20 + or $v0, $v1 + sw $v0, POLYG4_xy0($a1) + + sll $v0, $t0, 4 + andi $v0, 0xffff + addi $v0, 16 + sll $v1, $t1, 20 + or $v0, $v1 + sw $v0, POLYG4_xy1($a1) + + sll $v0, $t0, 4 + andi $v0, 0xffff + sll $v1, $t1, 4 + addi $v1, 16 + sll $v1, 16 + or $v0, $v1 + sw $v0, POLYG4_xy2($a1) + + sll $v0, $t0, 4 + andi $v0, 0xffff + addi $v0, 16 + sll $v1, $t1, 4 + addi $v1, 16 + sll $v1, 16 + or $v0, $v1 + sw $v0, POLYG4_xy3($a1) + + .set noat + + lui $v1, 0x0800 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + addiu $a1, POLYG4_len + + + addiu $t0, 1 + blt $t0, 40, .x_loop + nop + + addiu $a2, 1 + addiu $t1, 1 + blt $t1, 30, .y_loop + nop + + + jr $ra + move $v0, $a1 \ No newline at end of file diff --git a/examples/n00bdemo/scrolltext.c b/examples/n00bdemo/scrolltext.c new file mode 100644 index 0000000..e844f21 --- /dev/null +++ b/examples/n00bdemo/scrolltext.c @@ -0,0 +1,136 @@ +const char scroll_text[] = { +"Greetings! Lameguy64 proudly presents a new PlayStation homebrew demo called " +"n00bDEMO and is very much the first time I've released a new demo in years! The " +"last time I released a PlayStation demo was Meido-Demo back in 2013 and boy " +"does this new demo show how far I've gotten good at programming for the " +"PlayStation with graphical effects such as stencil masks and cel-shading " +"never before seen in demos that I'm aware of presented in hi-res mode at 60FPS " +"(50 if PAL). Though there's some flickering issues here and there (though it " +"probably flickers less in PAL mode and none on the PS2 and emulators) which " +"I'll explain the cause of such problems in a bit...\n" + +"Making this demo was pretty challenging (actually, mostly annoying) but " +"mostly for the wrong reasons because this demo is actually not made using " +"the official Sony SDK whatsoever. Yes, I actually put together my own SDK " +"using the GNU GCC toolchain and made the PlayStation GPU and GTE libraries " +"myself mostly in MIPS assembly. I call this SDK project of my own PSn00bSDK " +"and is probably the first homebrewn PlayStation SDK that can actually do 3D " +"graphics with full GTE support that is on-par to the official SDK even in " +"its current work-in-progress state as all other open source SDK examples I've " +"seen only offer very limited or no 3D capabilities whatsoever as with the case " +"of PSXSDK. I used n00b in the naming as I don't want to put pro in the name " +"of my projects knowing that its been used and abused in a lot of shovelware " +"and I wanted something less generic sounding. This SDK project is not exactly " +"professional software after all especially when I get into the issues I've had " +"with this project as of the making of this demo...\n" + +"Currently my SDK mostly offers support for the GPU and GTE but not so much on " +"other hardware features such as SPU, CD (which would be a disgrace not to support), " +"MDEC, controller/memory card and serial I/O. I mostly focused on supporting the " +"GPU and GTE as I feel it was the best way to present a proof of concept that making " +"an open source SDK that is on par to the official SDK should definitely be " +"possible especially when the ins and outs of the PlayStation hardware " +"had since been extensively documented so there's absolutely no excuse for not " +"supporting the hardware features of the console. I'm not certain if I'll continue " +"working on this PSn00bSDK project because I've experienced numerous issues with " +"this project, a lot of which appear to be compiler related (I'm using GCC " +"7.2.0 targetting mipsel-unknown-elf) as doing small code changes would sometimes break " +"or cripple certain parts of a large program that results to slowdown (hence " +"why there's some flicker and I had to omit the Lamelotl artwork in some scenes to " +"try to keep the flicker down) even when the code changes are completely unrelated to the " +"parts that got affected. Issues like these made developing this demo a MASSIVE " +"pain in the butt and it feels like things seem to stall more often than when using the " +"official SDK which also used GCC (2.8.1 to be specific). I'm not entirely sure if " +"they're optimization issues or I'm just pushing the console a little too far :). " +"I feel these issues are detrimental to this project as I don't really want to " +"work with a potentially unstable compiler in my SDK project as that would make " +"creating much larger projects (such as a full game) an even bigger pain " +"in the butt as things would break randomly over small code changes and having to " +"deal with such issues do not conform to my standards. I haven't checked if " +"GCC 8.2.0 has better mipsel support and I've yet to look into clang which is " +"said to support MIPS down to version 1 of the ISA.\n" + +"What I hoped to achieve with PSn00bSDK is to create a 100% free and open " +"source PlayStation SDK that is on-par to the official SDK to make homebrew " +"development for the PS1 much more attractive especially to those interested " +"in developing commercial homebrew for the console without the legal issues " +"surrounding the use of Sony's libraries. But considering the compiler issues " +"I've had and the PS1 community being mostly focussed on emulators and PSIO over " +"actually making homebrew for the console and many of the folks who actually knew how " +"to program for the console especially in low-level have either retired or " +"disappeared, making the feat I wanted to achieve with my SDK project somewhat " +"unlikely I feel. I'll be releasing source code of this demo and " +"the PSn00bSDK libraries on github a week or two as of the release of this " +"demo if things go according to plan on my end and contributions are accepted " +"for those interested to volunteer for this project...\n" + +"You should have noticed by now that there's something inherently missing " +"about this demo. Yes, there's no music in this demo at all. I would've " +"used some CD audio for music but I never got CD playback code working for " +"this demo and I've already made numerous attempts trying to crack the darn " +"thing with no success. At least there's no overused Kevin Macleod music here " +"unlike my last demo which I still wonder why I chose that for the music " +"over rendering out a MOD file into a WAV file and using that instead, man " +"was I stupid back then. Another option would be to use MOD music as I have " +"some SPU support in my SDK but writing my own MOD player would take a lot of " +"time and effort and finishing up this demo has taken long enough I feel as " +"I was originally going to release this demo back in December of 2018. " +"None of the existing MOD players can be used either as Hitmen's player " +"relies on Sony's libraries and is only offered in binary form (because " +"stupid) and PSXSDK's MOD player does all sample mixing in software instead " +"of using the SPU for playing the samples which is abslutely retarded and is " +"definitely not fit for this demo project. If you're watching this demo in " +"video form I've likely dubbed over some music to help keep things " +"interesting as you read this scroll text...\n" + +"There's actually some Scarlet Engine technology featured in this demo " +"namely the SMD model data format which is basically my own implementation " +"of the TMD model data for Scarlet and its drawing functions written in " +"assembly. The implementation featured here uses a newer revision of the SMD " +"model data and the drawing functions are a rewrite but they're still work " +"in progress as it currently does not support the features added in the new " +"revision of the SMD model data format. I haven't worked on Scarlet in awhile " +"as I've somewhat diverted to other things as of late and I've yet to do " +"research on better culling and rendering techniques as my last implementation " +"wasn't really all that good I feel. I plan to implement automated culling " +"using ray scanning when compiling a map and probably a geometry " +"LOD system similar to Spyro's engine. Developing Scarlet has been taking a " +"very long time I know but you have to consider this is being worked on by a " +"single person (who's probably a nobhead) as a hobby with no prior experience " +"in developing a 3D engine and to be honest, working on Scarlet feels a bit " +"too big for a single individual to work on. And in case you're wondering " +"about the apparent name change from Project Scarlet, that's because MS's new " +"Xbox is also codenamed Project Scarlet and I don't really like to have " +"Xbox fanboys looking desperately for videos about MS's Project Scarlet " +"and finding videos about my Project Scarlet instead that would only serve to " +"enrage them or something...\n" + +"Another piece of somewhat advanced technology used in this demo is that " +"all the assets in this demo are all stored in the PS-EXE in LZ77 compressed " +"form using my LZPack libraries to keep PS-EXE size low which speeds up the " +"boot time of this demo. I actually developed the LZPack library for the " +"official SDK in the past but I haven't got around to releasing them but I'm " +"likely going to include them with PSn00bSDK along with the compression/packing " +"tools and it should still work with the official SDK with only minor changes...\n" + +"I think that's pretty much all there is I wanted to say in this demo. I " +"was originally going to release this demo back in December of 2018 but " +"got delayed due to work and other things getting in the way but I hope " +"you enjoyed watching the visuals that were presented in this little " +"proof of concept demo...\n" + +"Greets to nocash NITROYUASH Orion danhans42 Shendo TriMesh " +"inc^lightforce Shadow\n" + +"Programming and most graphical assets in this demo are done by me " +"(Lameguy64). Lamelotl artwork drawn by Lumdrop. Hatkid from A Hat in " +"Time is owned by Gears for Breakfast and the 3D model featured in this " +"demo is made by me...\n" + +"Visit my website at http://lameguy64.tk if you want... " +"Pages are super lightweight with absolutely zero ads! (except joke ads that " +"don't do much other than mock the real ads, in case I've added them in the future)\n" + +"This has been a 2019 Meido-Tek Production!\n" + +}; \ No newline at end of file diff --git a/examples/n00bdemo/smd.h b/examples/n00bdemo/smd.h new file mode 100644 index 0000000..29c2812 --- /dev/null +++ b/examples/n00bdemo/smd.h @@ -0,0 +1,68 @@ +#ifndef _SMD_H +#define _SMD_H + +typedef struct { + int *ot; + short otlen; + unsigned char zdiv,zoff; +} SC_OT; + +typedef struct { + char id[3]; + unsigned char version; + unsigned short flags; + unsigned short n_verts; + unsigned short n_norms; + unsigned short n_prims; + SVECTOR *p_verts; + SVECTOR *p_norms; + void *p_prims; +} SMD; + +typedef struct { + unsigned char type:2; + unsigned char l_type:2; + unsigned char c_type:1; + unsigned char texture:1; + unsigned char blend:2; + unsigned char zoff:4; + unsigned char nocull:1; + unsigned char mask:1; + unsigned char texwin:2; + unsigned char texoff:2; + unsigned char reserved:6; + unsigned char len; +} SMD_PRI_TYPE; + +typedef struct { + SMD_PRI_TYPE prim_id; + unsigned short v0,v1,v2,v3; // Vertex indices + unsigned short n0,n1,n2,n3; // Normal indices + unsigned char r0,g0,b0,code; // RGB0 + unsigned char r1,g1,b1,p0; // RGB1 + unsigned char r2,g2,b2,p1; // RGB2 + unsigned char r3,g3,b3,p2; // RGB3 + unsigned char tu0,tv0; + unsigned char tu1,tv1; + unsigned char tu2,tv2; + unsigned char tu3,tv3; + unsigned short tpage,clut; +} SMD_PRIM; + + +int OpenSMD(void *smd); +SMD_PRIM *ReadSMD(SMD_PRIM *pri); + +void scSetClipRect(int x0, int y0, int x1, int y1); + +SMD *smdInitData(void *data); +void smdSetBaseTPage(unsigned short tpage); + +char *smdSortModel(SC_OT *ot, char* pribuff, SMD *smd); +char *smdSortModelFlat(unsigned int *ot, char* pribuff, SMD *smd); + +void smdSetCelTex(unsigned short tpage, unsigned short clut); +void smdSetCelParam(int udiv, int vdiv, unsigned int col); +char *smdSortModelCel(SC_OT *ot, char* pribuff, SMD *smd); + +#endif \ No newline at end of file diff --git a/examples/n00bdemo/smd.s b/examples/n00bdemo/smd.s new file mode 100644 index 0000000..f9cf2fe --- /dev/null +++ b/examples/n00bdemo/smd.s @@ -0,0 +1,924 @@ +.set noreorder + +.include "gtereg.h" +.include "inline_s.h" +.include "smd_s.h" + + +.section .text + +# Currently does not do header checks +.global smdInitData +.type smdInitData, @function +smdInitData: + + lw $a1, SMD_HEAD_PVERTS($a0) # Initialize header pointers + lw $a2, SMD_HEAD_PNORMS($a0) + lw $a3, SMD_HEAD_PPRIMS($a0) + + addu $a1, $a0 + addu $a2, $a0 + addu $a3, $a0 + + sw $a1, SMD_HEAD_PVERTS($a0) + sw $a2, SMD_HEAD_PNORMS($a0) + sw $a3, SMD_HEAD_PPRIMS($a0) + + jr $ra + move $v0, $a0 + + +.global scSetClipRect +.type scSetClipRect, @function +scSetClipRect: + sll $a1, 16 + or $a0, $a1 + sll $a3, 16 + or $a2, $a3 + la $a1, _sc_clip + sw $a0, 0( $a1 ) + jr $ra + sw $a2, 4( $a1 ) + + +.global smdSetBaseTPage +.type smdSetBaseTPage, @function +smdSetBaseTPage: + la $v0, _smd_tpage_base + jr $ra + sw $a0, 0($v0) + + +.global smdSortModel +.type smdSortModel, @function +smdSortModel: + + # a0 - Pointer SC_OT structure + # a1 - Pointer to next primitive + # a2 - Pointer to SMD data address + # v0 - New pointer of primitive buffer (return) + + addiu $sp, -16 + sw $s0, 0($sp) + sw $s1, 4($sp) + sw $s2, 8($sp) + sw $s3, 12($sp) + + la $v0, _sc_clip + lw $t8, 0($v0) + lw $t9, 4($v0) + + lw $t0, OT_LEN($a0) + lw $a0, OT_ADDR($a0) + lw $t1, SMD_HEAD_PVERTS($a2) + lw $t2, SMD_HEAD_PNORMS($a2) + lw $t3, SMD_HEAD_PPRIMS($a2) + +.sort_loop: + + nop + lw $a3, 0($t3) # Get primitive ID word + move $t4, $t3 + + beqz $a3, .exit # Check if terminator (just zero) + addiu $t4, 4 + + lhu $t5, 0( $t4 ) # Load vertices + lhu $t6, 2( $t4 ) + lhu $t7, 4( $t4 ) + sll $t5, 3 + sll $t6, 3 + sll $t7, 3 + addu $t5, $t1 + addu $t6, $t1 + addu $t7, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + lwc2 C2_VXY1, 0( $t6 ) + lwc2 C2_VZ1 , 4( $t6 ) + lwc2 C2_VXY2, 0( $t7 ) + lwc2 C2_VZ2 , 4( $t7 ) + + srl $v1, $a3, 24 # Get primitive size + addu $t3, $v1 # Step main pointer to next primitive + + RTPT + + cfc2 $v0, C2_FLAG # Get GTE flag value + nop + + bltz $v0, .skip_prim # Skip primitive if Z overflow + andi $v0, $a3, 0x3 + + NCLIP # Backface culling + + srl $v1, $a3, 12 + andi $v1, 1 + + bnez $v1, .no_culling + nop + + mfc2 $v1, C2_MAC0 + nop + bltz $v1, .skip_prim + nop + +.no_culling: + + beq $v0, 0x1, .prim_tri # If primitive is a triangle + nop + beq $v0, 0x2, .prim_quad # If primitive is a quad + nop + + b .skip_prim + nop + +## Triangles + +.prim_tri: # Triangle processing + + addiu $t4, 8 # Advance from indices + + AVSZ3 # Calculate average Z + + srl $v0, $t0, 16 # Get Z divisor from OT_LEN value + andi $v0, 0xff + + mfc2 $t5, C2_OTZ # Get AVSZ3 result + + sra $v1, $t0, 24 # Get Z offset from OT_LEN value + + srl $t5, $v0 # Apply divisor and offset + sub $t5, $v1 + + blez $t5, .skip_prim # Skip primitive if less than zero + andi $v1, $t0, 0xffff + bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length + sll $t5, 2 + addu $t5, $a0 # Append OTZ to OT address + + ClipTestTri + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw + and $v0, $s2, $s0 # v2 & v0 + beqz $v0, .do_draw + nop + b .skip_prim + nop + +.do_draw: + + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F3_light + nop + + andi $v0, $a3, 0x10 # Gouraud shaded + bnez $v0, .F3_gouraud + nop + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_textured + nop + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2000 + or $v0, $v1 + + b .sort_F3_pri + sw $v0, POLYF3_rgbc( $a1 ) + +.F3_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3000 + or $v0, $at + .set at + sw $v0, POLYG3_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG3_rgbc1($a1) + b .sort_G3_pri + sw $v0, POLYG3_rgbc2($a1) + +.F3_textured: + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2400 + or $v0, $v1 + sw $v0, POLYFT3_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v0, 8( $t4 ) # Tpage + CLUT + nop + andi $v1, $v0, 0xffff + sh $v1, POLYFT3_tpage( $a1 ) + srl $v0, 16 + + b .sort_FT3_pri + sh $v0, POLYFT3_clut( $a1 ) + +.F3_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F3_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2000 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_light_tex + nop + + swc2 C2_RGB2, POLYF3_rgbc( $a1 ) + + b .sort_F3_pri + nop + +.F3_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT3_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT3_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2400 + or $v0, $v1 + + b .sort_FT3_pri + sw $v0, POLYFT3_rgbc( $a1 ) + +.F3_light_smt: + + lhu $v0, 2( $t4 ) # Load normals 1 and 2 + lhu $v1, 4( $t4 ) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0( $v0 ) + lwc2 C2_VZ1 , 4( $v0 ) + lw $v0, 8( $t4 ) + lwc2 C2_VXY2, 0( $v1 ) + lwc2 C2_VZ2 , 4( $v1 ) + lui $v1, 0x3000 # Load color + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 12 + nop + + NCCT + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_light_tex_smt + nop + + swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) + swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) + swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) + + b .sort_G3_pri + nop + +.F3_light_tex_smt: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYGT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYGT3_uv1( $a1 ) + sh $v0, POLYGT3_uv2( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYGT3_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYGT3_clut( $a1 ) + + mfc2 $v0, C2_RGB0 + lui $v1, 0x3400 + or $v0, $v1 + + swc2 C2_RGB1, POLYGT3_rgbc1( $a1 ) + swc2 C2_RGB2, POLYGT3_rgbc2( $a1 ) + + b .sort_GT3_pri + sw $v0, POLYGT3_rgbc0( $a1 ) + +.sort_F3_pri: + + swc2 C2_SXY0, POLYF3_xy0($a1) + swc2 C2_SXY1, POLYF3_xy1($a1) + swc2 C2_SXY2, POLYF3_xy2($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0500 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF3_len + +.sort_FT3_pri: + + swc2 C2_SXY0, POLYFT3_xy0( $a1 ) + swc2 C2_SXY1, POLYFT3_xy1( $a1 ) + swc2 C2_SXY2, POLYFT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT3_len + +.sort_G3_pri: + + swc2 C2_SXY0, POLYG3_xy0( $a1 ) + swc2 C2_SXY1, POLYG3_xy1( $a1 ) + swc2 C2_SXY2, POLYG3_xy2( $a1 ) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG3_len + +.sort_GT3_pri: + + swc2 C2_SXY0, POLYGT3_xy0( $a1 ) + swc2 C2_SXY1, POLYGT3_xy1( $a1 ) + swc2 C2_SXY2, POLYGT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT3_len + +## Quads + +.prim_quad: # Quad processing + + mfc2 $t6, C2_SXY0 # Retrieve first projected vertex + + lhu $t5, 6( $t4 ) # Project the last vertex + addiu $t4, 8 + sll $t5, 3 + addu $t5, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + + nRTPS + + cfc2 $v1, C2_FLAG # Get GTE flag value + + srl $v0, $t0, 16 # Get Z divisor from OT_LEN value + + bltz $v1, .skip_prim + nop + + AVSZ4 + + andi $v0, 0xff + + mfc2 $t5, C2_OTZ + + sra $v1, $t0, 24 # Get Z offset from OT_LEN value + + srl $t5, $v0 # Apply divisor and offset + sub $t5, $v1 + + blez $t5, .skip_prim # Skip primitive if less than zero + andi $v1, $t0, 0xffff + bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length + sll $t5, 2 + addu $t5, $a0 # Append OTZ to OT address + + # no touch: + # a0, a1, a2, a3, t0, t1, t2, t3, t4, t5(ot), t6(sxy0) + + ClipTestQuad + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw_q + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw_q + and $v0, $s2, $s3 # v2 & v3 + beqz $v0, .do_draw_q + and $v0, $s3, $s0 # v3 & v0 + beqz $v0, .do_draw_q + and $v0, $s0, $s2 # v0 & v2 + beqz $v0, .do_draw_q + and $v0, $s1, $s3 # v1 & v3 + beqz $v0, .do_draw_q + nop + b .skip_prim + nop + +.do_draw_q: + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F4_light + nop + + andi $v0, $a3, 0x10 # Gouraud quad + bnez $v0, .F4_gouraud + nop + + andi $v0, $a3, 0x20 # Textured quad + bnez $v0, .F4_textured + nop + + lw $v0, 0($t4) + lui $v1, 0x2800 + or $v0, $v1 + + b .sort_F4_pri + sw $v0, POLYF4_rgbc($a1) + +.F4_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3800 + or $v0, $at + .set at + sw $v0, POLYG4_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG4_rgbc1($a1) + lw $v1, 12($t4) + sw $v0, POLYG4_rgbc2($a1) + b .sort_G4_pri + sw $v1, POLYG4_rgbc3($a1) + +.F4_textured: + + lw $v0, 0($t4) + lui $v1, 0x2c00 + or $v0, $v1 + sw $v0, POLYFT4_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0($t4) # Load texture coordinates + lhu $v1, 2($t4) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_FT4_pri + sh $v0, POLYFT4_clut($a1) + +.F4_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F4_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2800 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex + nop + + swc2 C2_RGB2, POLYF4_rgbc( $a1 ) + + b .sort_F4_pri + nop + +.F4_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT4_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2c00 + or $v0, $v1 + + b .sort_FT4_pri + sw $v0, POLYFT4_rgbc( $a1 ) + +.F4_light_smt: + + lhu $v0, 2( $t4 ) # Load normals 1 and 2 + lhu $v1, 4( $t4 ) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0( $v0 ) + lwc2 C2_VZ1 , 4( $v0 ) + lwc2 C2_VXY2, 0( $v1 ) + lwc2 C2_VZ2 , 4( $v1 ) + + lw $v0, 8( $t4 ) + lui $v1, 0x3800 # Load color + or $v0, $v1 + mtc2 $v0, C2_RGB + + nNCCT + + lhu $v0, 6( $t4 ) # Load normal 3 + + addiu $t4, 12 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex_smt + nop + + swc2 C2_RGB0, POLYG4_rgbc0( $a1 ) + swc2 C2_RGB1, POLYG4_rgbc1( $a1 ) + swc2 C2_RGB2, POLYG4_rgbc2( $a1 ) + + nNCCS + + swc2 C2_RGB2, POLYG4_rgbc3( $a1 ) + + b .sort_G4_pri + nop + +.F4_light_tex_smt: + + mfc2 $v0, C2_RGB0 + lui $v1, 0x3400 + or $v0, $v1 + sw $v0, POLYGT4_rgbc0( $a1 ) + swc2 C2_RGB1, POLYGT4_rgbc1( $a1 ) + swc2 C2_RGB2, POLYGT4_rgbc2( $a1 ) + + NCCS + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYGT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYGT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYGT4_uv2( $a1 ) + sh $v1, POLYGT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + swc2 C2_RGB2, POLYGT4_rgbc3( $a1 ) + + andi $v0, $v1, 0xffff + sh $v0, POLYGT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_GT4_pri + sh $v0, POLYGT4_clut( $a1 ) + +.sort_F4_pri: + + sw $t6, POLYF4_xy0($a1) + swc2 C2_SXY0, POLYF4_xy1($a1) + swc2 C2_SXY1, POLYF4_xy2($a1) + swc2 C2_SXY2, POLYF4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0600 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF4_len + +.sort_FT4_pri: + + sw $t6, POLYFT4_xy0($a1) + swc2 C2_SXY0, POLYFT4_xy1($a1) + swc2 C2_SXY1, POLYFT4_xy2($a1) + swc2 C2_SXY2, POLYFT4_xy3($a1) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT4_len + +.sort_G4_pri: + + sw $t6, POLYG4_xy0($a1) + swc2 C2_SXY0, POLYG4_xy1($a1) + swc2 C2_SXY1, POLYG4_xy2($a1) + swc2 C2_SXY2, POLYG4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG4_len + +.sort_GT4_pri: + + sw $t6, POLYGT4_xy0($a1) + swc2 C2_SXY0, POLYGT4_xy1($a1) + swc2 C2_SXY1, POLYGT4_xy2($a1) + swc2 C2_SXY2, POLYGT4_xy3($a1) + + .set noat + + lui $v1, 0x0c00 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT4_len + +.skip_prim: + + b .sort_loop + nop + +.exit: + + lw $s0, 0( $sp ) + lw $s1, 4( $sp ) + lw $s2, 8( $sp ) + lw $s3, 12( $sp ) + addiu $sp, 16 + jr $ra + move $v0, $a1 + + +.comm _smd_tpage_base, 4, 4 + +.comm _sc_clip, 8, 4 diff --git a/examples/n00bdemo/smd_cel.s b/examples/n00bdemo/smd_cel.s new file mode 100644 index 0000000..ece0dd8 --- /dev/null +++ b/examples/n00bdemo/smd_cel.s @@ -0,0 +1,1073 @@ +.set noreorder + +.include "gtereg.h" +.include "inline_s.h" +.include "smd_s.h" + + +.section .text + +.global smdSetCelTex +.type smdSetCelTex, @function +smdSetCelTex: + # a0 - TPage value + # a1 - CLUT value + la $v0, _smd_cel_tpage + andi $a0, 0xffff + sll $a1, 16 + or $a0, $a1 + jr $ra + sw $a0, 0($v0) + + + +.global smdSetCelParam +.type smdSetCelParam, @function +smdSetCelParam: + # a0 - Shading texture U offset + # a1 - Shading texture V offset + # a2 - Shading primitive color + andi $a1, 0xff + sll $a1, 8 + andi $a0, 0xff + or $a0, $a1 + la $v0, _smd_cel_param + sw $a0, 0($v0) + la $v0, _smd_cel_col + lui $v1, 0x0200 + or $a3, $v1 + jr $ra + sw $a2, 0($v0) + + +.global smdSortModelCel +.type smdSortModelCel, @function +smdSortModelCel: + + # a0 - Pointer SC_OT structure + # a1 - Pointer to next primitive + # a2 - Pointer to SMD data address + # v0 - New pointer of primitive buffer (return) + + addiu $sp, -16 + sw $s0, 0($sp) + sw $s1, 4($sp) + sw $s2, 8($sp) + sw $s3, 12($sp) + + la $v0, _sc_clip + lw $t8, 0($v0) + lw $t9, 4($v0) + + lw $t0, OT_LEN($a0) + lw $a0, OT_ADDR($a0) + lw $t1, SMD_HEAD_PVERTS($a2) + lw $t2, SMD_HEAD_PNORMS($a2) + lw $t3, SMD_HEAD_PPRIMS($a2) + +.sort_loop: + + nop + lw $a3, 0($t3) # Get primitive ID word + move $t4, $t3 + + beqz $a3, .exit # Check if terminator (just zero) + addiu $t4, 4 + + lhu $t5, 0( $t4 ) # Load vertices + lhu $t6, 2( $t4 ) + lhu $t7, 4( $t4 ) + sll $t5, 3 + sll $t6, 3 + sll $t7, 3 + addu $t5, $t1 + addu $t6, $t1 + addu $t7, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + lwc2 C2_VXY1, 0( $t6 ) + lwc2 C2_VZ1 , 4( $t6 ) + lwc2 C2_VXY2, 0( $t7 ) + lwc2 C2_VZ2 , 4( $t7 ) + + srl $v1, $a3, 24 # Get primitive size + addu $t3, $v1 # Step main pointer to next primitive + + RTPT + + cfc2 $v0, C2_FLAG # Get GTE flag value + nop + + bltz $v0, .skip_prim # Skip primitive if Z overflow + andi $v0, $a3, 0x3 + + NCLIP # Backface culling + + srl $v1, $a3, 12 + andi $v1, 1 + + bnez $v1, .no_culling + nop + + mfc2 $v1, C2_MAC0 + nop + bltz $v1, .skip_prim + nop + +.no_culling: + + beq $v0, 0x1, .prim_tri # If primitive is a triangle + nop + beq $v0, 0x2, .prim_quad # If primitive is a quad + nop + + b .skip_prim + nop + +## Triangles + +.prim_tri: # Triangle processing + + addiu $t4, 8 # Advance from indices + + AVSZ3 # Calculate average Z + + srl $v0, $t0, 16 # Get Z divisor from OT_LEN value + andi $v0, 0xff + + mfc2 $t5, C2_OTZ # Get AVSZ3 result + + sra $v1, $t0, 24 # Get Z offset from OT_LEN value + + srl $t5, $v0 # Apply divisor and offset + sub $t5, $v1 + + blez $t5, .skip_prim # Skip primitive if less than zero + andi $v1, $t0, 0xffff + bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length + sll $t5, 2 + addu $t5, $a0 # Append OTZ to OT address + + ClipTestTri + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw + and $v0, $s2, $s0 # v2 & v0 + beqz $v0, .do_draw + nop + b .skip_prim + nop + +.do_draw: + + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F3_light + nop + + andi $v0, $a3, 0x10 # Gouraud shaded + bnez $v0, .F3_gouraud + nop + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_textured + nop + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2000 + or $v0, $v1 + + b .sort_F3_pri + sw $v0, POLYF3_rgbc( $a1 ) + +.F3_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3000 + or $v0, $at + .set at + sw $v0, POLYG3_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG3_rgbc1($a1) + b .sort_G3_pri + sw $v0, POLYG3_rgbc2($a1) + +.F3_textured: + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2400 + or $v0, $v1 + sw $v0, POLYFT3_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v0, 8( $t4 ) # Tpage + CLUT + nop + andi $v1, $v0, 0xffff + sh $v1, POLYFT3_tpage( $a1 ) + srl $v0, 16 + + b .sort_FT3_pri + sh $v0, POLYFT3_clut( $a1 ) + +.F3_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F3_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2000 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_light_tex + nop + + swc2 C2_RGB2, POLYF3_rgbc( $a1 ) + + b .sort_F3_pri + nop + +.F3_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT3_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT3_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2400 + or $v0, $v1 + + b .sort_FT3_pri + sw $v0, POLYFT3_rgbc( $a1 ) + +.F3_light_smt: + + lhu $v0, 2($t4) # Load normals 1 and 2 + lhu $v1, 4($t4) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0($v0) + lwc2 C2_VZ1 , 4($v0) + #la $v0, _smd_cel_col + #lw $v0, 0($v0) + lwc2 C2_VXY2, 0($v1) + lwc2 C2_VZ2 , 4($v1) + mtc2 $v0, C2_RGB + + swc2 C2_SXY0, POLYFT3_xy0($a1) + swc2 C2_SXY1, POLYFT3_xy1($a1) + swc2 C2_SXY2, POLYFT3_xy2($a1) + + la $v0, _smd_cel_tpage # Load cel shader TPage and CLUT values + lw $v0, 0($v0) + + NCT + + andi $v1, $v0, 0xffff + sh $v1, POLYFT3_tpage($a1) + srl $v1, $v0, 16 + sh $v1, POLYFT3_clut($a1) + + # Usable regs: v0, v1, at, t6, t7 + + .set noat + + la $at, _smd_cel_param # Load cel shader parameters + lhu $at, 0($at) + + mfc2 $t7, C2_RGB0 # Get first shaded color + andi $v1, $at, 0xff # Get U divisor value + andi $t7, 0xffff # Only keep R and G colors + + andi $v0, $t7, 0xff # U0 + srl $v0, $v1 + sb $v0, POLYFT3_uv0($a1) + srl $v0, $t7, 8 # V0 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT3_uv0+1($a1) + + mfc2 $t7, C2_RGB1 + andi $v1, $at, 0xff + andi $t7, 0xffff + andi $v0, $t7, 0xff # U1 + srl $v0, $v1 + sb $v0, POLYFT3_uv1($a1) + srl $v0, $t7, 8 # V1 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT3_uv1+1($a1) + + mfc2 $t7, C2_RGB2 + andi $v1, $at, 0xff + andi $t7, 0xffff + andi $v0, $t7, 0xff # U2 + srl $v0, $v1 + sb $v0, POLYFT3_uv2($a1) + srl $v0, $t7, 8 # V2 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT3_uv2+1($a1) + + la $v0, _smd_cel_col + lw $v0, 0($v0) + lui $v1, 0x2600 + or $v0, $v1 + sw $v0, POLYFT3_rgbc($a1) + + lw $t7, 8($t4) + addiu $t4, 12 + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $v1, $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $v1 + sw $v0, 0($t5) + + lui $v0, 0x8000 + or $a1, $v0 + addiu $a1, POLYFT3_len + + .set at + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_light_tex_smt + nop + + #swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) + #swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) + #swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) + + lui $v0, 0x2000 + or $t7, $v0 + b .sort_F3_pri + sw $t7, POLYF3_rgbc($a1) + +.F3_light_tex_smt: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT3_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT3_clut( $a1 ) + + lui $v1, 0x2400 + or $t7, $v1 + + b .sort_FT3_pri + sw $t7, POLYFT3_rgbc( $a1 ) + +.sort_F3_pri: + + swc2 C2_SXY0, POLYF3_xy0($a1) + swc2 C2_SXY1, POLYF3_xy1($a1) + swc2 C2_SXY2, POLYF3_xy2($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0500 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF3_len + +.sort_FT3_pri: + + swc2 C2_SXY0, POLYFT3_xy0( $a1 ) + swc2 C2_SXY1, POLYFT3_xy1( $a1 ) + swc2 C2_SXY2, POLYFT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT3_len + +.sort_G3_pri: + + swc2 C2_SXY0, POLYG3_xy0( $a1 ) + swc2 C2_SXY1, POLYG3_xy1( $a1 ) + swc2 C2_SXY2, POLYG3_xy2( $a1 ) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG3_len + +.sort_GT3_pri: + + swc2 C2_SXY0, POLYGT3_xy0( $a1 ) + swc2 C2_SXY1, POLYGT3_xy1( $a1 ) + swc2 C2_SXY2, POLYGT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT3_len + +## Quads + +.prim_quad: # Quad processing + + mfc2 $t6, C2_SXY0 # Retrieve first projected vertex + + lhu $t5, 6( $t4 ) # Project the last vertex + addiu $t4, 8 + sll $t5, 3 + addu $t5, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + + nRTPS + + cfc2 $v1, C2_FLAG # Get GTE flag value + + srl $v0, $t0, 16 # Get Z divisor from OT_LEN value + + bltz $v1, .skip_prim + nop + + AVSZ4 + + andi $v0, 0xff + + mfc2 $t5, C2_OTZ + + sra $v1, $t0, 24 # Get Z offset from OT_LEN value + + srl $t5, $v0 # Apply divisor and offset + sub $t5, $v1 + + blez $t5, .skip_prim # Skip primitive if less than zero + andi $v1, $t0, 0xffff + bge $t5, $v1, .skip_prim # Skip primitive if greater than OT length + sll $t5, 2 + addu $t5, $a0 # Append OTZ to OT address + + # no touch: + # a0, a1, a2, a3, t0, t1, t2, t3, t4, t5(ot), t6(sxy0) + + ClipTestQuad + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw_q + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw_q + and $v0, $s2, $s3 # v2 & v3 + beqz $v0, .do_draw_q + and $v0, $s3, $s0 # v3 & v0 + beqz $v0, .do_draw_q + and $v0, $s0, $s2 # v0 & v2 + beqz $v0, .do_draw_q + and $v0, $s1, $s3 # v1 & v3 + beqz $v0, .do_draw_q + nop + b .skip_prim + nop + +.do_draw_q: + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F4_light + nop + + andi $v0, $a3, 0x10 # Gouraud quad + bnez $v0, .F4_gouraud + nop + + andi $v0, $a3, 0x20 # Textured quad + bnez $v0, .F4_textured + nop + + lw $v0, 0($t4) + lui $v1, 0x2800 + or $v0, $v1 + + b .sort_F4_pri + sw $v0, POLYF4_rgbc($a1) + +.F4_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3800 + or $v0, $at + .set at + sw $v0, POLYG4_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG4_rgbc1($a1) + lw $v1, 12($t4) + sw $v0, POLYG4_rgbc2($a1) + b .sort_G4_pri + sw $v1, POLYG4_rgbc3($a1) + +.F4_textured: + + lw $v0, 0($t4) + lui $v1, 0x2c00 + or $v0, $v1 + sw $v0, POLYFT4_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0($t4) # Load texture coordinates + lhu $v1, 2($t4) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_FT4_pri + sh $v0, POLYFT4_clut($a1) + +.F4_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F4_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2800 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex + nop + + swc2 C2_RGB2, POLYF4_rgbc( $a1 ) + + b .sort_F4_pri + nop + +.F4_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT4_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2c00 + or $v0, $v1 + + b .sort_FT4_pri + nop + sw $v0, POLYFT4_rgbc( $a1 ) + +.F4_light_smt: + + lhu $v0, 2( $t4 ) # Load normals 1 and 2 + lhu $v1, 4( $t4 ) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0( $v0 ) + lwc2 C2_VZ1 , 4( $v0 ) + lwc2 C2_VXY2, 0( $v1 ) + lwc2 C2_VZ2 , 4( $v1 ) + + sw $t6, POLYFT4_xy0($a1) + swc2 C2_SXY0, POLYFT4_xy1($a1) + swc2 C2_SXY1, POLYFT4_xy2($a1) + swc2 C2_SXY2, POLYFT4_xy3($a1) + + la $v0, _smd_cel_tpage # Load cel shader TPage and CLUT values + lw $v0, 0($v0) + + NCT + + andi $v1, $v0, 0xffff + sh $v1, POLYFT4_tpage($a1) + srl $v1, $v0, 16 + sh $v1, POLYFT4_clut($a1) + + # Usable regs: v0, v1, at, t7 + + .set noat + + la $at, _smd_cel_param # Load cel shader parameters + lhu $at, 0($at) + + mfc2 $t7, C2_RGB0 + andi $v1, $at, 0xff # Get U divisor value + andi $t7, 0xffff # Only keep R and G colors + + andi $v0, $t7, 0xff # U0 + srl $v0, $v1 + sb $v0, POLYFT4_uv0($a1) + srl $v0, $t7, 8 # V0 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT4_uv0+1($a1) + + mfc2 $t7, C2_RGB1 + andi $v1, $at, 0xff + andi $t7, 0xffff + andi $v0, $t7, 0xff # U1 + srl $v0, $v1 + sb $v0, POLYFT4_uv1($a1) + srl $v0, $t7, 8 # V1 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT4_uv1+1($a1) + + mfc2 $t7, C2_RGB2 + andi $v1, $at, 0xff + andi $t7, 0xffff + andi $v0, $t7, 0xff # U2 + srl $v0, $v1 + sb $v0, POLYFT4_uv2($a1) + srl $v0, $t7, 8 # V2 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT4_uv2+1($a1) + + la $v0, _smd_cel_col + lw $v0, 0($v0) + lui $v1, 0x2E00 + or $v0, $v1 + sw $v0, POLYFT4_rgbc($a1) + + lw $t7, 8($t4) + + lhu $v0, 6($t4) # Load normal 3 + addiu $t4, 12 + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + nNCS + + mfc2 $s0, C2_RGB2 + andi $v1, $at, 0xff + andi $s0, 0xffff + andi $v0, $s0, 0xff # U3 + srl $v0, $v1 + sb $v0, POLYFT4_uv3($a1) + srl $v0, $s0, 8 # V3 + srl $v1, $at, 8 + srl $v0, $v1 + sb $v0, POLYFT4_uv3+1($a1) + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $v1, $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $v1 + sw $v0, 0($t5) + + lui $v0, 0x8000 + or $a1, $v0 + addiu $a1, POLYFT4_len + + .set at + + andi $v0, $a3, 0x20 # Textured quad + bnez $v0, .F4_light_tex_smt + nop + + lui $v0, 0x2800 + or $t7, $v0 + b .sort_F4_pri + sw $t7, POLYF4_rgbc($a1) + +.F4_light_tex_smt: + + lhu $v0, 0($t4) # Load texture coordinates + lhu $v1, 2($t4) + sh $v0, POLYFT4_uv0($a1) + lhu $v0, 4($t4) + sh $v1, POLYFT4_uv1($a1) + lhu $v1, 6($t4) + sh $v0, POLYFT4_uv2($a1) + sh $v1, POLYFT4_uv3($a1) + + lw $v1, 8($t4) + + lui $v0, 0x2E00 + or $t7, $v0 + sw $t7, POLYFT4_rgbc($a1) + + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage($a1) + srl $v0, $v1, 16 + + b .sort_FT4_pri + sh $v0, POLYFT4_clut($a1) + +.sort_F4_pri: + + sw $t6, POLYF4_xy0($a1) + swc2 C2_SXY0, POLYF4_xy1($a1) + swc2 C2_SXY1, POLYF4_xy2($a1) + swc2 C2_SXY2, POLYF4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0600 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF4_len + +.sort_FT4_pri: + + sw $t6, POLYFT4_xy0($a1) + swc2 C2_SXY0, POLYFT4_xy1($a1) + swc2 C2_SXY1, POLYFT4_xy2($a1) + swc2 C2_SXY2, POLYFT4_xy3($a1) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT4_len + +.sort_G4_pri: + + sw $t6, POLYG4_xy0($a1) + swc2 C2_SXY0, POLYG4_xy1($a1) + swc2 C2_SXY1, POLYG4_xy2($a1) + swc2 C2_SXY2, POLYG4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG4_len + +.sort_GT4_pri: + + sw $t6, POLYGT4_xy0($a1) + swc2 C2_SXY0, POLYGT4_xy1($a1) + swc2 C2_SXY1, POLYGT4_xy2($a1) + swc2 C2_SXY2, POLYGT4_xy3($a1) + + .set noat + + lui $v1, 0x0c00 + lw $v0, 0($t5) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($t5) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($t5) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT4_len + +.skip_prim: + + b .sort_loop + nop + +.exit: + + lw $s0, 0( $sp ) + lw $s1, 4( $sp ) + lw $s2, 8( $sp ) + lw $s3, 12( $sp ) + addiu $sp, 16 + jr $ra + move $v0, $a1 + + +.comm _smd_cel_col, 4, 4 # STP shading polygon color +.comm _smd_cel_param, 4, 4 # U divisor, V divisor, shading clip +.comm _smd_cel_tpage, 4, 4 # CEL shader texture page & CLUT + diff --git a/examples/n00bdemo/smd_flat.s b/examples/n00bdemo/smd_flat.s new file mode 100644 index 0000000..0d48c63 --- /dev/null +++ b/examples/n00bdemo/smd_flat.s @@ -0,0 +1,832 @@ +.set noreorder + +.include "gtereg.h" +.include "inline_s.h" +.include "smd_s.h" + + +.section .text + +.global smdSortModelFlat +.type smdSortModelFlat, @function +smdSortModelFlat: + # a0 - Pointer SC_OT structure + # a1 - Pointer to next primitive + # a2 - Pointer to SMD data address + # v0 - New pointer of primitive buffer (return) + + addiu $sp, -16 + sw $s0, 0( $sp ) + sw $s1, 4( $sp ) + sw $s2, 8( $sp ) + sw $s3, 12( $sp ) + + la $v0, _sc_clip + lw $t8, 0($v0) + lw $t9, 4($v0) + + lw $t1, SMD_HEAD_PVERTS( $a2 ) + lw $t2, SMD_HEAD_PNORMS( $a2 ) + lw $t3, SMD_HEAD_PPRIMS( $a2 ) + +.sort_loop: + + nop + lw $a3, 0($t3) # Get primitive ID word + move $t4, $t3 + + beqz $a3, .exit # Check if terminator (just zero) + addiu $t4, 4 + + lhu $t5, 0( $t4 ) # Load vertices + lhu $t6, 2( $t4 ) + lhu $t7, 4( $t4 ) + sll $t5, 3 + sll $t6, 3 + sll $t7, 3 + addu $t5, $t1 + addu $t6, $t1 + addu $t7, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + lwc2 C2_VXY1, 0( $t6 ) + lwc2 C2_VZ1 , 4( $t6 ) + lwc2 C2_VXY2, 0( $t7 ) + lwc2 C2_VZ2 , 4( $t7 ) + + srl $v1, $a3, 24 # Get primitive size + addu $t3, $v1 # Step main pointer to next primitive + + RTPT + + cfc2 $v0, C2_FLAG # Get GTE flag value + nop + + bltz $v0, .skip_prim # Skip primitive if Z overflow + nop + + #NCLIP # Backface culling + + #mfc2 $v1, C2_MAC0 + + andi $v0, $a3, 0x3 + + #bltz $v1, .skip_prim + #nop + + beq $v0, 0x1, .prim_tri # If primitive is a triangle + nop + beq $v0, 0x2, .prim_quad # If primitive is a quad + nop + + b .skip_prim + nop + +## Triangles + +.prim_tri: # Triangle processing + + addiu $t4, 8 # Advance from indices + + #AVSZ3 # Calculate average Z + + ClipTestTri + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw + and $v0, $s2, $s0 # v2 & v0 + beqz $v0, .do_draw + nop + b .skip_prim + nop + +.do_draw: + + #srl $v0, $a3, 2 # Lighting enabled? + #andi $v0, 0x3 + #bnez $v0, .F3_light + #nop + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F3_textured + nop + + andi $v0, $a3, 0x10 # Gouraud shaded + bnez $v0, .F3_gouraud + nop + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2000 + or $v0, $v1 + + b .sort_F3_pri + sw $v0, POLYF3_rgbc( $a1 ) + +.F3_textured: + + lw $v0, 0( $t4 ) # Flat color, no lighting + lui $v1, 0x2400 + or $v0, $v1 + sw $v0, POLYFT3_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT3_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT3_uv1( $a1 ) + sh $v0, POLYFT3_uv2( $a1 ) + + lw $v0, 8( $t4 ) # Tpage + CLUT + nop + andi $v1, $v0, 0xffff + sh $v1, POLYFT3_tpage( $a1 ) + srl $v0, 16 + + b .sort_FT3_pri + sh $v0, POLYFT3_clut( $a1 ) + +.F3_gouraud: + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3000 + or $v0, $at + .set at + sw $v0, POLYG3_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG3_rgbc1($a1) + b .sort_G3_pri + sw $v0, POLYG3_rgbc2($a1) + +#.F3_light: + + #lhu $v0, 0( $t4 ) # Load normal 0 + + #srl $v1, $a3, 2 + #andi $v1, $v1, 0x3 + + #sll $v0, 3 + #addu $v0, $t2 + #lwc2 C2_VXY0, 0( $v0 ) + #lwc2 C2_VZ0 , 4( $v0 ) + + #beq $v1, 0x2, .F3_light_smt + #nop + + #lw $v0, 4( $t4 ) + #lui $v1, 0x2000 + #or $v0, $v1 + #mtc2 $v0, C2_RGB + + #addiu $t4, 8 + #nop + + #NCCS + + #andi $v0, $a3, 0x20 # Textured triangle + #bnez $v0, .F3_light_tex + #nop + + #swc2 C2_RGB2, POLYF3_rgbc( $a1 ) + + #b .sort_F3_pri + #nop + +#.F3_light_tex: + + #lhu $v0, 0( $t4 ) # Load texture coordinates + #lhu $v1, 2( $t4 ) + #sh $v0, POLYFT3_uv0( $a1 ) + #lhu $v0, 4( $t4 ) + #sh $v1, POLYFT3_uv1( $a1 ) + #sh $v0, POLYFT3_uv2( $a1 ) + + #lw $v1, 8( $t4 ) + #nop + #andi $v0, $v1, 0xffff + #sh $v0, POLYFT3_tpage( $a1 ) + #srl $v0, $v1, 16 + #sh $v0, POLYFT3_clut( $a1 ) + + #mfc2 $v0, C2_RGB2 + #lui $v1, 0x2400 + #or $v0, $v1 + + #b .sort_FT3_pri + #sw $v0, POLYFT3_rgbc( $a1 ) + +#.F3_light_smt: + + #lhu $v0, 2( $t4 ) # Load normals 1 and 2 + #lhu $v1, 4( $t4 ) + #sll $v0, 3 + #sll $v1, 3 + #addu $v0, $t2 + #addu $v1, $t2 + #lwc2 C2_VXY1, 0( $v0 ) + #lwc2 C2_VZ1 , 4( $v0 ) + #lw $v0, 8( $t4 ) + #lwc2 C2_VXY2, 0( $v1 ) + #lwc2 C2_VZ2 , 4( $v1 ) + #lui $v1, 0x3000 # Load color + #or $v0, $v1 + #mtc2 $v0, C2_RGB + + #addiu $t4, 12 + #nop + + #NCCT + + #andi $v0, $a3, 0x20 # Textured triangle + #bnez $v0, .F3_light_tex_smt + #nop + + #swc2 C2_RGB0, POLYG3_rgbc0( $a1 ) + #swc2 C2_RGB1, POLYG3_rgbc1( $a1 ) + #swc2 C2_RGB2, POLYG3_rgbc2( $a1 ) + + #b .sort_G3_pri + #nop + +# .F3_light_tex_smt: + + # lhu $v0, 0( $t4 ) # Load texture coordinates + # lhu $v1, 2( $t4 ) + # sh $v0, POLYGT3_uv0( $a1 ) + # lhu $v0, 4( $t4 ) + # sh $v1, POLYGT3_uv1( $a1 ) + # sh $v0, POLYGT3_uv2( $a1 ) + + # lw $v1, 8( $t4 ) + # nop + # andi $v0, $v1, 0xffff + # sh $v0, POLYGT3_tpage( $a1 ) + # srl $v0, $v1, 16 + # sh $v0, POLYGT3_clut( $a1 ) + + # mfc2 $v0, C2_RGB0 + # lui $v1, 0x3400 + # or $v0, $v1 + + # swc2 C2_RGB1, POLYGT3_rgbc1( $a1 ) + # swc2 C2_RGB2, POLYGT3_rgbc2( $a1 ) + + # b .sort_GT3_pri + # sw $v0, POLYGT3_rgbc0( $a1 ) + +.sort_F3_pri: + + swc2 C2_SXY0, POLYF3_xy0($a1) + swc2 C2_SXY1, POLYF3_xy1($a1) + swc2 C2_SXY2, POLYF3_xy2($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0500 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF3_len + +.sort_FT3_pri: + + swc2 C2_SXY0, POLYFT3_xy0( $a1 ) + swc2 C2_SXY1, POLYFT3_xy1( $a1 ) + swc2 C2_SXY2, POLYFT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT3_len + +.sort_G3_pri: + + swc2 C2_SXY0, POLYG3_xy0( $a1 ) + swc2 C2_SXY1, POLYG3_xy1( $a1 ) + swc2 C2_SXY2, POLYG3_xy2( $a1 ) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG3_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0700 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG3_len + +.sort_GT3_pri: + + swc2 C2_SXY0, POLYGT3_xy0( $a1 ) + swc2 C2_SXY1, POLYGT3_xy1( $a1 ) + swc2 C2_SXY2, POLYGT3_xy2( $a1 ) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT3_len + +## Quads + +.prim_quad: # Quad processing + + mfc2 $t6, C2_SXY0 # Retrieve first projected vertex + + lhu $t5, 6( $t4 ) # Project the last vertex + addiu $t4, 8 + sll $t5, 3 + addu $t5, $t1 + lwc2 C2_VXY0, 0( $t5 ) + lwc2 C2_VZ0 , 4( $t5 ) + + nRTPS + + cfc2 $v1, C2_FLAG # Get GTE flag value + + nop + + bltz $v1, .skip_prim + nop + + ClipTestQuad + + and $v0, $s0, $s1 # v0 & v1 + beqz $v0, .do_draw_q + and $v0, $s1, $s2 # v1 & v2 + beqz $v0, .do_draw_q + and $v0, $s2, $s3 # v2 & v3 + beqz $v0, .do_draw_q + and $v0, $s3, $s0 # v3 & v0 + beqz $v0, .do_draw_q + and $v0, $s0, $s2 # v0 & v2 + beqz $v0, .do_draw_q + and $v0, $s1, $s3 # v1 & v3 + beqz $v0, .do_draw_q + nop + b .skip_prim + nop + +.do_draw_q: + + srl $v0, $a3, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, .F4_light + nop + + andi $v0, $a3, 0x10 # Gouraud quad + bnez $v0, .F4_gouraud + nop + + andi $v0, $a3, 0x20 # Textured quad + bnez $v0, .F4_textured + nop + + lw $v0, 0($t4) + lui $v1, 0x2800 + or $v0, $v1 + + b .sort_F4_pri + sw $v0, POLYF4_rgbc($a1) + +.F4_textured: + + lw $v0, 0($t4) + lui $v1, 0x2c00 + or $v0, $v1 + sw $v0, POLYFT4_rgbc( $a1 ) + addiu $t4, 4 + + lhu $v0, 0($t4) # Load texture coordinates + lhu $v1, 2($t4) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_FT4_pri + sh $v0, POLYFT4_clut($a1) + +.F4_gouraud: + + lw $v0, 0($t4) + lw $v1, 4($t4) + .set noat + lui $at, 0x3800 + or $v0, $at + .set at + sw $v0, POLYG4_rgbc0($a1) + lw $v0, 8($t4) + sw $v1, POLYG4_rgbc1($a1) + lw $v1, 12($t4) + sw $v0, POLYG4_rgbc2($a1) + b .sort_G4_pri + sw $v1, POLYG4_rgbc3($a1) + + +.F4_light: + + lhu $v0, 0( $t4 ) # Load normal 0 + + srl $v1, $a3, 2 + andi $v1, $v1, 0x3 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + beq $v1, 0x2, .F4_light_smt + nop + + lw $v0, 4( $t4 ) + lui $v1, 0x2800 + or $v0, $v1 + mtc2 $v0, C2_RGB + + addiu $t4, 8 + nop + + NCCS + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex + nop + + swc2 C2_RGB2, POLYF4_rgbc( $a1 ) + + b .sort_F4_pri + nop + +.F4_light_tex: + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYFT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYFT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYFT4_uv2( $a1 ) + sh $v1, POLYFT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + nop + andi $v0, $v1, 0xffff + sh $v0, POLYFT4_tpage( $a1 ) + srl $v0, $v1, 16 + sh $v0, POLYFT4_clut( $a1 ) + + mfc2 $v0, C2_RGB2 + lui $v1, 0x2c00 + or $v0, $v1 + + b .sort_FT4_pri + sw $v0, POLYFT4_rgbc( $a1 ) + +.F4_light_smt: + + lhu $v0, 2( $t4 ) # Load normals 1 and 2 + lhu $v1, 4( $t4 ) + sll $v0, 3 + sll $v1, 3 + addu $v0, $t2 + addu $v1, $t2 + lwc2 C2_VXY1, 0( $v0 ) + lwc2 C2_VZ1 , 4( $v0 ) + lwc2 C2_VXY2, 0( $v1 ) + lwc2 C2_VZ2 , 4( $v1 ) + + lw $v0, 8( $t4 ) + lui $v1, 0x3800 # Load color + or $v0, $v1 + mtc2 $v0, C2_RGB + + nNCCT + + lhu $v0, 6( $t4 ) # Load normal 3 + + addiu $t4, 12 + + sll $v0, 3 + addu $v0, $t2 + lwc2 C2_VXY0, 0( $v0 ) + lwc2 C2_VZ0 , 4( $v0 ) + + andi $v0, $a3, 0x20 # Textured triangle + bnez $v0, .F4_light_tex_smt + nop + + swc2 C2_RGB0, POLYG4_rgbc0( $a1 ) + swc2 C2_RGB1, POLYG4_rgbc1( $a1 ) + swc2 C2_RGB2, POLYG4_rgbc2( $a1 ) + + nNCCS + + swc2 C2_RGB2, POLYG4_rgbc3( $a1 ) + + b .sort_G4_pri + nop + +.F4_light_tex_smt: + + mfc2 $v0, C2_RGB0 + lui $v1, 0x3400 + or $v0, $v1 + sw $v0, POLYGT4_rgbc0( $a1 ) + swc2 C2_RGB1, POLYGT4_rgbc1( $a1 ) + swc2 C2_RGB2, POLYGT4_rgbc2( $a1 ) + + NCCS + + lhu $v0, 0( $t4 ) # Load texture coordinates + lhu $v1, 2( $t4 ) + sh $v0, POLYGT4_uv0( $a1 ) + lhu $v0, 4( $t4 ) + sh $v1, POLYGT4_uv1( $a1 ) + lhu $v1, 6( $t4 ) + sh $v0, POLYGT4_uv2( $a1 ) + sh $v1, POLYGT4_uv3( $a1 ) + + lw $v1, 8( $t4 ) + swc2 C2_RGB2, POLYGT4_rgbc3( $a1 ) + + andi $v0, $v1, 0xffff + sh $v0, POLYGT4_tpage( $a1 ) + srl $v0, $v1, 16 + + b .sort_GT4_pri + sh $v0, POLYGT4_clut( $a1 ) + +.sort_F4_pri: + + sw $t6, POLYF4_xy0($a1) + swc2 C2_SXY0, POLYF4_xy1($a1) + swc2 C2_SXY1, POLYF4_xy2($a1) + swc2 C2_SXY2, POLYF4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYF4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0600 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYF4_len + +.sort_FT4_pri: + + sw $t6, POLYFT4_xy0($a1) + swc2 C2_SXY0, POLYFT4_xy1($a1) + swc2 C2_SXY1, POLYFT4_xy2($a1) + swc2 C2_SXY2, POLYFT4_xy3($a1) + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYFT4_len + +.sort_G4_pri: + + sw $t6, POLYG4_xy0($a1) + swc2 C2_SXY0, POLYG4_xy1($a1) + swc2 C2_SXY1, POLYG4_xy2($a1) + swc2 C2_SXY2, POLYG4_xy3($a1) + + la $v0, _smd_tpage_base + lhu $v0, 0($v0) + srl $v1, $a3, 6 # Get blend mode + andi $v1, 0x3 + sll $v1, 5 + or $v0, $v1 + lui $v1, 0xe100 + or $v0, $v1 + sw $v0, POLYG4_tpage($a1) # Store TPage + + .set noat + + lui $v1, 0x0900 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYG4_len + +.sort_GT4_pri: + + sw $t6, POLYGT4_xy0($a1) + swc2 C2_SXY0, POLYGT4_xy1($a1) + swc2 C2_SXY1, POLYGT4_xy2($a1) + swc2 C2_SXY2, POLYGT4_xy3($a1) + + .set noat + + lui $v1, 0x0c00 + lw $v0, 0($a0) + lui $at, 0xff00 + and $v1, $at + lui $at, 0x00ff + or $at, 0xffff + and $v0, $at + or $v1, $v0 + sw $v1, 0($a1) + lw $v0, 0($a0) + and $a1, $at + lui $at, 0xff00 + and $v0, $at + or $v0, $a1 + sw $v0, 0($a0) + + .set at + + lui $v0, 0x8000 + or $a1, $v0 + + b .sort_loop + addiu $a1, POLYGT4_len + +.skip_prim: + + b .sort_loop + nop + +.exit: + + lw $s0, 0( $sp ) + lw $s1, 4( $sp ) + lw $s2, 8( $sp ) + lw $s3, 12( $sp ) + addiu $sp, 16 + jr $ra + move $v0, $a1 + \ No newline at end of file diff --git a/examples/n00bdemo/smd_s.h b/examples/n00bdemo/smd_s.h new file mode 100644 index 0000000..4dca4dd --- /dev/null +++ b/examples/n00bdemo/smd_s.h @@ -0,0 +1,336 @@ +.set OT_ADDR, 0 +.set OT_LEN, 4 +.set OT_ZDIV, 8 +.set OT_ZOFF, 10 + +.set SMD_HEAD_ID, 0 +.set SMD_HEAD_FLAG, 4 +.set SMD_HEAD_NVERTS, 6 +.set SMD_HEAD_NNORMS, 8 +.set SMD_HEAD_NPRIMS, 10 +.set SMD_HEAD_PVERTS, 12 +.set SMD_HEAD_PNORMS, 16 +.set SMD_HEAD_PPRIMS, 20 +.set SMD_HEAD_SIZE, 24 + +.set POLYF3_tag, 0 +.set POLYF3_tpage, 4 +.set POLYF3_rgbc, 8 +.set POLYF3_xy0, 12 +.set POLYF3_xy1, 16 +.set POLYF3_xy2, 20 +.set POLYF3_len, 24 + +.set POLYFT3_tag, 0 +.set POLYFT3_rgbc, 4 +.set POLYFT3_xy0, 8 +.set POLYFT3_uv0, 12 +.set POLYFT3_clut, 14 +.set POLYFT3_xy1, 16 +.set POLYFT3_uv1, 20 +.set POLYFT3_tpage, 22 +.set POLYFT3_xy2, 24 +.set POLYFT3_uv2, 28 +.set POLYFT3_pad, 30 +.set POLYFT3_len, 32 + +.set POLYG3_tag, 0 +.set POLYG3_tpage, 4 +.set POLYG3_rgbc0, 8 +.set POLYG3_xy0, 12 +.set POLYG3_rgbc1, 16 +.set POLYG3_xy1, 20 +.set POLYG3_rgbc2, 24 +.set POLYG3_xy2, 28 +.set POLYG3_len, 32 + +.set POLYGT3_tag, 0 +.set POLYGT3_rgbc0, 4 +.set POLYGT3_xy0, 8 +.set POLYGT3_uv0, 12 +.set POLYGT3_clut, 14 +.set POLYGT3_rgbc1, 16 +.set POLYGT3_xy1, 20 +.set POLYGT3_uv1, 24 +.set POLYGT3_tpage, 26 +.set POLYGT3_rgbc2, 28 +.set POLYGT3_xy2, 32 +.set POLYGT3_uv2, 36 +.set POLYGT3_pad, 38 +.set POLYGT3_len, 40 + +.set POLYF4_tag, 0 +.set POLYF4_tpage, 4 +.set POLYF4_rgbc, 8 +.set POLYF4_xy0, 12 +.set POLYF4_xy1, 16 +.set POLYF4_xy2, 20 +.set POLYF4_xy3, 24 +.set POLYF4_len, 28 + +.set POLYFT4_tag, 0 +.set POLYFT4_rgbc, 4 +.set POLYFT4_xy0, 8 +.set POLYFT4_uv0, 12 +.set POLYFT4_clut, 14 +.set POLYFT4_xy1, 16 +.set POLYFT4_uv1, 20 +.set POLYFT4_tpage, 22 +.set POLYFT4_xy2, 24 +.set POLYFT4_uv2, 28 +.set POLYFT4_pad0, 30 +.set POLYFT4_xy3, 32 +.set POLYFT4_uv3, 36 +.set POLYFT4_pad1, 38 +.set POLYFT4_len, 40 + +.set POLYG4_tag, 0 +.set POLYG4_tpage, 4 +.set POLYG4_rgbc0, 8 +.set POLYG4_xy0, 12 +.set POLYG4_rgbc1, 16 +.set POLYG4_xy1, 20 +.set POLYG4_rgbc2, 24 +.set POLYG4_xy2, 28 +.set POLYG4_rgbc3, 32 +.set POLYG4_xy3, 36 +.set POLYG4_len, 40 + +.set POLYGT4_tag, 0 +.set POLYGT4_rgbc0, 4 +.set POLYGT4_xy0, 8 +.set POLYGT4_uv0, 12 +.set POLYGT4_clut, 14 +.set POLYGT4_rgbc1, 16 +.set POLYGT4_xy1, 20 +.set POLYGT4_uv1, 24 +.set POLYGT4_tpage, 26 +.set POLYGT4_rgbc2, 28 +.set POLYGT4_xy2, 32 +.set POLYGT4_uv2, 36 +.set POLYGT4_pad0, 38 +.set POLYGT4_rgbc3, 40 +.set POLYGT4_xy3, 44 +.set POLYGT4_uv3, 48 +.set POLYGT4_pad1, 50 +.set POLYGT4_len, 52 + +.set CLIP_LEFT, 1 +.set CLIP_RIGHT, 2 +.set CLIP_TOP, 4 +.set CLIP_BOTTOM, 8 + + +# Clip routine macros, based on Cohen-Sutherland line clipping algorithm +# but only with the off-screen dectection logic extended for polygons + +.macro ClipTestTri + + # X0 clip test + mfc2 $t7, C2_SXY0 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x0 + move $s0, $0 + ori $s0, CLIP_LEFT +.no_clip_l_x0: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x0 + nop + ori $s0, CLIP_RIGHT +.no_clip_r_x0: + # Y0 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y0 + nop + ori $s0, CLIP_TOP +.no_clip_t_y0: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y0 + nop + ori $s0, CLIP_BOTTOM +.no_clip_b_y0: + + # X1 clip test + mfc2 $t7, C2_SXY1 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x1 + move $s1, $0 + ori $s1, CLIP_LEFT +.no_clip_l_x1: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x1 + nop + ori $s1, CLIP_RIGHT +.no_clip_r_x1: + # Y1 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y1 + nop + ori $s1, CLIP_TOP +.no_clip_t_y1: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y1 + nop + ori $s1, CLIP_BOTTOM +.no_clip_b_y1: + + # X2 clip test + mfc2 $t7, C2_SXY2 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x2 + move $s2, $0 + ori $s2, CLIP_LEFT +.no_clip_l_x2: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x2 + nop + ori $s2, CLIP_RIGHT +.no_clip_r_x2: + # Y2 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y2 + nop + ori $s2, CLIP_TOP +.no_clip_t_y2: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y2 + nop + ori $s2, CLIP_BOTTOM +.no_clip_b_y2: + +.endm + + +.macro ClipTestQuad + + # X0 clip test + sll $v0, $t6, 16 + sra $v0, 16 + sll $v1, $t8, 16 + sra $v1, 16 + bge $v0, $v1, .no_clip_l_x0_q + move $s0, $0 + ori $s0, CLIP_LEFT +.no_clip_l_x0_q: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x0_q + nop + ori $s0, CLIP_RIGHT +.no_clip_r_x0_q: + # Y0 clip test + sra $v0, $t6, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y0_q + nop + ori $s0, CLIP_TOP +.no_clip_t_y0_q: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y0_q + nop + ori $s0, CLIP_BOTTOM +.no_clip_b_y0_q: + + # X1 clip test + mfc2 $t7, C2_SXY0 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x1_q + move $s1, $0 + ori $s1, CLIP_LEFT +.no_clip_l_x1_q: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x1_q + nop + ori $s1, CLIP_RIGHT +.no_clip_r_x1_q: + # Y1 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y1_q + nop + ori $s1, CLIP_TOP +.no_clip_t_y1_q: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y1_q + nop + ori $s1, CLIP_BOTTOM +.no_clip_b_y1_q: + + # X2 clip test + mfc2 $t7, C2_SXY1 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x2_q + move $s2, $0 + ori $s2, CLIP_LEFT +.no_clip_l_x2_q: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x2_q + nop + ori $s2, CLIP_RIGHT +.no_clip_r_x2_q: + # Y2 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y2_q + nop + ori $s2, CLIP_TOP +.no_clip_t_y2_q: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y2_q + nop + ori $s2, CLIP_BOTTOM +.no_clip_b_y2_q: + + # X3 clip test + mfc2 $t7, C2_SXY2 + sll $v1, $t8, 16 + sra $v1, 16 + sll $v0, $t7, 16 + sra $v0, 16 + bge $v0, $v1, .no_clip_l_x3_q + move $s3, $0 + ori $s3, CLIP_LEFT +.no_clip_l_x3_q: + sll $v1, $t9, 16 + sra $v1, 16 + ble $v0, $v1, .no_clip_r_x3_q + nop + ori $s3, CLIP_RIGHT +.no_clip_r_x3_q: + # Y4 clip test + sra $v0, $t7, 16 + sra $v1, $t8, 16 + bge $v0, $v1, .no_clip_t_y3_q + nop + ori $s3, CLIP_TOP +.no_clip_t_y3_q: + sra $v1, $t9, 16 + ble $v0, $v1, .no_clip_b_y3_q + nop + ori $s3, CLIP_BOTTOM +.no_clip_b_y3_q: + +.endm diff --git a/examples/n00bdemo/smdparser.s b/examples/n00bdemo/smdparser.s new file mode 100644 index 0000000..379690f --- /dev/null +++ b/examples/n00bdemo/smdparser.s @@ -0,0 +1,129 @@ +.set noreorder + +.include "smd_s.h" + +.set SMD_PRI_ID, 0 +.set SMD_PRI_v0, 4 +.set SMD_PRI_v1, 6 +.set SMD_PRI_v2, 8 +.set SMD_PRI_v3, 10 +.set SMD_PRI_n0, 12 +.set SMD_PRI_n1, 14 +.set SMD_PRI_n2, 16 +.set SMD_PRI_n3, 18 +.set SMD_PRI_rgbc0, 20 +.set SMD_PRI_rgbc1, 24 +.set SMD_PRI_rgbc2, 28 +.set SMD_PRI_rgbc3, 32 +.set SMD_PRI_tuv0, 36 +.set SMD_PRI_tuv1, 38 +.set SMD_PRI_tuv2, 40 +.set SMD_PRI_tuv3, 42 +.set SMD_PRI_tpage, 44 +.set SMD_PRI_clut, 46 + +.section .text + + +.comm _smd_parse_addr, 4, 4 + + +.global OpenSMD +.type OpenSMD, @function +OpenSMD: + lw $v0, SMD_HEAD_ID($a0) + li $v1, 0x01444d53 + + bne $v0, $v1, .not_smd + nop + + lw $v0, SMD_HEAD_PPRIMS($a0) + la $v1, _smd_parse_addr + sw $v0, 0($v1) + + jr $ra + lhu $v0, SMD_HEAD_NPRIMS($a0) + +.not_smd: + jr $ra + move $v0, $0 + + +.global ReadSMD +.type ReadSMD, @function +ReadSMD: + + la $v0, _smd_parse_addr + lw $v0, 0($v0) + nop + + lw $a2, 0($v0) # Load primitive ID + addiu $a1, $v0, 4 + + sw $a2, SMD_PRI_ID($a0) + + beqz $a2, $end_prim + nop + + srl $v1, $a2, 24 # Get primitive size + addu $v0, $v1 + la $v1, _smd_parse_addr + sw $v0, 0($v1) + + lw $v0, 0($a1) # Copy vertex coords + lw $v1, 4($a1) + sw $v0, SMD_PRI_v0($a0) + sw $v1, SMD_PRI_v2($a0) + addiu $a1, 8 + + srl $v0, $a2, 2 # Lighting enabled? + andi $v0, 0x3 + bnez $v0, $light + nop + + b $no_light + nop + +$light: + srl $v1, $a2, 2 + lw $v0, 0($a1) # Copy vertex coords + andi $v1, 0x3 + sw $v0, SMD_PRI_n0($a0) + + bne $v1, 0x2, $light_flat + addiu $a1, 4 + + lw $v1, 0($a1) + addiu $a1, 4 + sw $v1, SMD_PRI_n2($a0) + +$light_flat: +$no_light: + + lw $v0, 0($a1) + nop + sw $v0, SMD_PRI_rgbc0($a0) + addiu $a1, 4 + + srl $v0, $a2, 5 + andi $v0, 0x1 + beqz $v0, $not_textured + nop + + lw $v0, 0($a1) + lw $v1, 4($a1) + sw $v0, SMD_PRI_tuv0($a0) + lw $v0, 8($a1) + sw $v1, SMD_PRI_tuv2($a0) + sw $v0, SMD_PRI_tpage($a0) + +$not_textured: + + jr $ra + move $v0, $a0 + +$end_prim: + + jr $ra + move $v0, $0 + \ No newline at end of file diff --git a/examples/sdk-common.mk b/examples/sdk-common.mk new file mode 100644 index 0000000..8a92dbf --- /dev/null +++ b/examples/sdk-common.mk @@ -0,0 +1,19 @@ +# Adjustable common makefile values for PSn00bSDK example programs. +# You may need to modify these values to correspond to your toolchain setup. + +# Toolchain prefix. Can include an absolute path to the toolchain executables. +PREFIX = mipsel-unknown-elf- + +# Include directories. +INCLUDE = -I../../libpsn00b/include + +# Library directories. Last entry must point to a directory containing libgcc. +LIBDIRS = -L../../libpsn00b +# Directory path for toolchain's libraries (you may need to change this) +ifeq "$(OS)" "Windows_NT" +# For Windows +LIBDIRS += -L/c/psn00bsdk/lib +else +# For Linux/BSDs +LIBDIRS += -L/usr/local/mipsel-unknown-elf/lib/gcc/mipsel-unknown-elf/6.3.0 +endif -- cgit v1.2.3