diff options
| author | John Wilbert M. Villamor <lameguy64@gmail.com> | 2020-04-24 19:01:28 +0800 |
|---|---|---|
| committer | John Wilbert M. Villamor <lameguy64@gmail.com> | 2020-04-24 19:01:28 +0800 |
| commit | 1aa0e17df7c325a41de8cf8a57f52ed853f08bf3 (patch) | |
| tree | 5ec7f69ca0104f2b0a41e2ee7d3cb0cf0c9c54c5 /examples/balls | |
| parent | e82da2abe4c264d4b48a48d79cf9b8e4c4fb8ab6 (diff) | |
| download | psn00bsdk-1aa0e17df7c325a41de8cf8a57f52ed853f08bf3.tar.gz | |
Refined toolchain instructions, organized examples, added automatic retry for CdRead(), added FIOCSCAN ioctl in psxsio TTY driver, added tty and console examples.
Diffstat (limited to 'examples/balls')
| -rw-r--r-- | examples/balls/ball16c.h | 16 | ||||
| -rw-r--r-- | examples/balls/ball16c.tim | bin | 192 -> 0 bytes | |||
| -rw-r--r-- | examples/balls/main.c | 228 | ||||
| -rw-r--r-- | examples/balls/makefile | 60 |
4 files changed, 0 insertions, 304 deletions
diff --git a/examples/balls/ball16c.h b/examples/balls/ball16c.h deleted file mode 100644 index c79f273..0000000 --- a/examples/balls/ball16c.h +++ /dev/null @@ -1,16 +0,0 @@ -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 Binary files differdeleted file mode 100644 index e2a5d17..0000000 --- a/examples/balls/ball16c.tim +++ /dev/null diff --git a/examples/balls/main.c b/examples/balls/main.c deleted file mode 100644 index 89c8063..0000000 --- a/examples/balls/main.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * LibPSn00b Example Programs - * - * Balls Example - * 2019 Meido-Tek Productions / PSn00bSDK Project - * - * Draws a bunch of ball sprites that bounce around the screen, - * along with a ball snake that might be difficult to see. - * - * - * Example by Lameguy64 - * - * Changelog: - * - * November 20, 2018 - Initial version. - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <psxetc.h> -#include <psxgte.h> -#include <psxgpu.h> -#include "ball16c.h" - - -#define MAX_BALLS 1024 - -#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<MAX_BALLS; i++) { - - balls[i].x = (rand()%624); - balls[i].y = (rand()%464); - balls[i].xdir = 1-(rand()%3); - balls[i].ydir = 1-(rand()%3); - if( !balls[i].xdir ) balls[i].xdir = 1; - if( !balls[i].ydir ) balls[i].ydir = 1; - balls[i].xdir *= 2; - balls[i].ydir *= 2; - balls[i].r = (rand()%256); - balls[i].g = (rand()%256); - balls[i].b = (rand()%256); - - } - - printf("Done.\n"); - -} - -int main(int argc, const char* argv[]) { - - SPRT_16 *sprt; - DR_TPAGE *tpri; - - int i,counter=0; - - - /* Init graphics and stuff before doing anything else */ - init(); - - - /* Main loop */ - printf("Entering loop...\n"); - - while(1) { - - /* Clear ordering table and set start address of primitive */ - /* buffer for next frame */ - ClearOTagR( ot[db], OT_LEN ); - nextpri = pribuff[db]; - - /* Sort a balls snake */ - sprt = (SPRT_16*)nextpri; - srand( 64 ); - for( i=0; i<32; i++ ) { - - setSprt16( sprt ); - setXY0( sprt, - (CENTER_X-8)+(isin((counter-(i<<4))<<3)>>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; i<MAX_BALLS; i++ ) { - - setSprt16( sprt ); - setXY0( sprt, balls[i].x, balls[i].y ); - setRGB0( sprt, balls[i].r, balls[i].g, balls[i].b ); - setUV0( sprt, 0, 0 ); - setClut( sprt, tim.crect->x, 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, - getTPage(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( 0 ); - VSync( 0 ); - - /* 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 deleted file mode 100644 index e0f6bc3..0000000 --- a/examples/balls/makefile +++ /dev/null @@ -1,60 +0,0 @@ -include ../sdk-common.mk - -# Project target name -TARGET = balls.elf - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES = $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Determine object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.o)) \ - $(addprefix build/,$(AFILES:.s=.o)) - -# Project specific include and library directories -# (use -I for include dirs, -L for library dirs) -INCLUDE += -LIBDIRS += - -# Libraries to link -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc - -# C compiler flags -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections - -# C++ compiler flags -CPPFLAGS = $(CFLAGS) -fno-exceptions - -# Assembler flags -AFLAGS = -g -msoft-float - -# Linker flags -LDFLAGS = -g -Ttext=0x80010000 -gc-sections \ - -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x - -# Toolchain programs -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: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build $(TARGET) $(TARGET:.elf=.exe) |
