diff options
| author | John Wilbert M. Villamor <lameguy64@gmail.com> | 2021-01-05 10:58:04 +0800 |
|---|---|---|
| committer | John Wilbert M. Villamor <lameguy64@gmail.com> | 2021-01-05 10:58:04 +0800 |
| commit | 974b17fad06cef4b304645b8a9dd92ac91ebb749 (patch) | |
| tree | 1db281d9cac9bb4e80ae17dc731f1a3241c787f6 /examples | |
| parent | f048f87b445942f961d225348e2af1113e544d23 (diff) | |
| download | psn00bsdk-974b17fad06cef4b304645b8a9dd92ac91ebb749.tar.gz | |
Added updated library reference, added struct names in psxgpu.h, defined GTE squareroot functions and added C++ demo example.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/beginner/cppdemo/main.cpp | 152 | ||||
| -rw-r--r-- | examples/beginner/cppdemo/makefile | 54 |
2 files changed, 206 insertions, 0 deletions
diff --git a/examples/beginner/cppdemo/main.cpp b/examples/beginner/cppdemo/main.cpp new file mode 100644 index 0000000..1a98cac --- /dev/null +++ b/examples/beginner/cppdemo/main.cpp @@ -0,0 +1,152 @@ +/* Work in progress example, need to add comments. + * + * Basically a quick little example that showcases C++ classes are + * functioning in PSn00bSDK. - Lameguy64 + * + * Written in December 18, 2020. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <malloc.h> +#include <psxgte.h> +#include <psxgpu.h> + +class GraphClass +{ + u_int *_ot[2]; + u_char *_pri[2]; + u_char *_nextpri; + + int _ot_count; + int _db; + + DISPENV _disp[2]; + DRAWENV _draw[2]; + +public: + + GraphClass( int ot_len = 8, int pri_len = 8192 ) + { + _ot[0] = (u_int*)malloc( sizeof(u_int)*ot_len ); + _ot[1] = (u_int*)malloc( sizeof(u_int)*ot_len ); + + _db = 0; + _ot_count = ot_len; + ClearOTagR( _ot[0], _ot_count ); + ClearOTagR( _ot[1], _ot_count ); + + _pri[0] = (u_char*)malloc( pri_len ); + _pri[1] = (u_char*)malloc( pri_len ); + + _nextpri = _pri[0]; + + printf( "GraphClass::GraphClass: Buffers allocated.\n" ); + + } /* GraphClass */ + + virtual ~GraphClass() + { + /* free the OTs and primitive buffers */ + free( _ot[0] ); + free( _ot[1] ); + + free( _pri[0] ); + free( _pri[1] ); + + printf( "GraphClass::GraphClass: Buffers freed.\n" ); + + } /* ~GraphClass */ + + void SetRes( int w, int h ) + { + SetDefDispEnv( &_disp[0], 0, h, w, h ); + SetDefDispEnv( &_disp[1], 0, 0, w, h ); + + SetDefDrawEnv( &_draw[0], 0, 0, w, h ); + SetDefDrawEnv( &_draw[1], 0, h, w, h ); + + setRGB0( &_draw[0], 63, 0, 127 ); + _draw[0].isbg = 1; + _draw[0].dtd = 1; + setRGB0( &_draw[1], 63, 0, 127 ); + _draw[1].isbg = 1; + _draw[1].dtd = 1; + + PutDispEnv( &_disp[0] ); + PutDrawEnv( &_draw[0] ); + + } /* SetRes */ + + void IncPri( int bytes ) + { + _nextpri += bytes; + + } /* IncPri */ + + void SetPri( u_char *ptr ) + { + _nextpri = ptr; + + } /* SetPri */ + + u_char *GetNextPri( void ) + { + return( _nextpri ); + + } /* GetNextPri */ + + u_int *GetOt( void ) + { + return( _ot[_db] ); + + } /* GetOt */ + + void Display( void ) + { + VSync( 0 ); + DrawSync( 0 ); + SetDispMask( 1 ); + + _db = !_db; + + PutDispEnv( &_disp[_db] ); + PutDrawEnv( &_draw[_db] ); + + DrawOTag( _ot[!_db]+(_ot_count-1) ); + + ClearOTagR( _ot[_db], _ot_count ); + _nextpri = _pri[_db]; + + } /* Display */ + +}; /* GraphClass */ + +GraphClass *otable; + +int main( int argc, const char *argv[] ) +{ + TILE *tile; + + ResetGraph( 0 ); + + otable = new GraphClass(); + + otable->SetRes( 320, 240 ); + + while( 1 ) + { + tile = (TILE*)otable->GetNextPri(); + setTile( tile ); + setXY0( tile, 32, 32 ); + setWH( tile, 128, 128 ); + setRGB0( tile, 255, 255, 0 ); + addPrim( otable->GetOt(), tile ); + otable->IncPri( sizeof(TILE) ); + + otable->Display(); + } + + return( 0 ); + +} /* main */
\ No newline at end of file diff --git a/examples/beginner/cppdemo/makefile b/examples/beginner/cppdemo/makefile new file mode 100644 index 0000000..6a29033 --- /dev/null +++ b/examples/beginner/cppdemo/makefile @@ -0,0 +1,54 @@ +include ../../examples-setup.mk + +# Project target name +TARGET = cppdemo.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 = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc + +# C compiler flags +CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections + +# C++ compiler flags +CPPFLAGS = $(CFLAGS) -fno-builtin -fno-rtti -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 + +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) $(CPPFLAGS) $(INCLUDE) -c $< -o $@ + +build/%.o: %.s + @mkdir -p $(dir $@) + $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ + +clean: + rm -rf build $(TARGET) $(TARGET:.elf=.exe) |
