aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-10-11 10:04:28 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-10-11 10:04:28 +0800
commitd80d92e13330d527ddb94420b19f9e21bf0e74eb (patch)
treee65c35da97b547f974020fe3f9e429cd9c26e865
parent7d001b2a757383665ef3151ed961d921640e00bf (diff)
downloadpsn00bsdk-d80d92e13330d527ddb94420b19f9e21bf0e74eb.tar.gz
Added FntOpen(), FntPrint() and FntFlush(), fixed termPrim() typo, fixed negative values in vsprintf(), added billboard sprites example
-rw-r--r--changelog.txt33
-rw-r--r--doc/LibPSn00b Reference.odtbin105194 -> 113754 bytes
-rw-r--r--examples/billboard/billboard.c260
-rw-r--r--examples/billboard/makefile39
-rw-r--r--examples/billboard/texture64.timbin0 -> 2112 bytes
-rw-r--r--examples/billboard/tim.s7
-rw-r--r--examples/fpscam/main.c24
-rw-r--r--examples/fpscam/makefile6
-rw-r--r--examples/n00bdemo/plasma_tbl.c2
-rw-r--r--libpsn00b/include/psxetc.h3
-rw-r--r--libpsn00b/include/psxgpu.h2
-rw-r--r--libpsn00b/libc/makefile2
-rw-r--r--libpsn00b/libc/putchar.s (renamed from libpsn00b/psxapi/stdio/putchar.s)0
-rw-r--r--libpsn00b/libc/vsprintf.c12
-rw-r--r--libpsn00b/lzp/makefile3
-rw-r--r--libpsn00b/psxetc/font.c190
-rw-r--r--libpsn00b/psxetc/makefile4
-rw-r--r--libpsn00b/psxetc/readme.txt4
-rw-r--r--libpsn00b/psxgpu/makefile2
-rw-r--r--libpsn00b/psxgte/makefile2
-rw-r--r--libpsn00b/psxsio/makefile2
-rw-r--r--libpsn00b/psxspu/makefile4
22 files changed, 571 insertions, 30 deletions
diff --git a/changelog.txt b/changelog.txt
index be481d1..806e4b3 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -2,6 +2,27 @@ PSn00bSDK changelog
Items that are lower in the log are more recently implemented.
+10-11-2019 by Lameguy64:
+
+* psxetc: Added FntOpen(), FntPrint() and FntFlush() functions.
+
+* psxgpu: Fixed typo in termPrim() macro (value too long).
+
+* examples: Added billboarding sprites example.
+
+* psxapi: Transferred putchar() BIOS function to libc.
+
+* libpsn00b: Updated makefiles adding -fdata-sections and -ffunction-sections
+ so unused functions will be stripped out, which yields smaller executables.
+
+* libc: Fixed negative integers not displaying properly in vsprintf()/vsnprintf().
+
+* libc: Fixed zero padding not working in vsprintf()/vsnprintf().
+
+* fpscam: Added debug text using FntOpen(), FntPrint() and FntFlush(). Also added
+ _boot() call for returning to CD based serial loaders.
+
+
09-23-2019 by Lameguy64:
* libc: Added strcat() function.
@@ -179,14 +200,12 @@ Items that are lower in the log are more recently implemented.
SDK is currently unknown.
-
06-07-2019 by qbradq:
* lzpack: Swapped a buffer length litteral with sizeof operator, fixing a
stack overflow bug in some instances.
-
05-23-2019 by Lameguy64:
* Added dev notes.txt file in docs that includes notes about the many
@@ -200,11 +219,11 @@ Items that are lower in the log are more recently implemented.
* Added rgb24 example.
* Got custom exit handler set using SetCustomExitFromException() (BIOS
- function B(19h)) working. Currently used to acknowledge VSync IRQ but
- actual VSync handling is still done with events and needs to be
- transferred to the custom exit handler. At least it lets BIOS
- controller functions to work now. See doc/dev notes.txt for details
- on how this handler behaves.
+ function B(19h)) working. Currently used to acknowledge VSync IRQ but
+ actual VSync handling is still done with events and needs to be
+ transferred to the custom exit handler. At least it lets BIOS
+ controller functions to work now. See doc/dev notes.txt for details
+ on how this handler behaves.
* Made stack usage in ResetGraph() less wasteful. You only need to
allocate N words on stack based on N arguments of the function
diff --git a/doc/LibPSn00b Reference.odt b/doc/LibPSn00b Reference.odt
index 30d0058..ab305d3 100644
--- a/doc/LibPSn00b Reference.odt
+++ b/doc/LibPSn00b Reference.odt
Binary files differ
diff --git a/examples/billboard/billboard.c b/examples/billboard/billboard.c
new file mode 100644
index 0000000..bba5dda
--- /dev/null
+++ b/examples/billboard/billboard.c
@@ -0,0 +1,260 @@
+/*
+ * LibPSn00b Example Programs
+ *
+ * GTE Billboarding Sprites Example
+ * 2019 Meido-Tek Productions / PSn00bSDK Project
+ *
+ * Displays a bunch of sprites placed on the screen using 3D coordinates
+ * that scale according to the distance from the screen. This is a quick
+ * modification of the GTE cube example.
+ *
+ * Billboard sprites are useful for 2D projectiles flying across 3D space,
+ * particle effects such as smoke as well as characters and objects
+ * represented as 2D sprites.
+ *
+ * Example by Lameguy64
+ *
+ * Changelog:
+ *
+ * Sep 24, 2019 - Initial version.
+ *
+ */
+
+#include <stdio.h>
+#include <psxgpu.h>
+#include <psxgte.h>
+#include <inline_c.h>
+
+/* 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;
+
+extern int tim_image[];
+TIM_IMAGE tim;
+
+/* For easier handling of vertex indices */
+typedef struct {
+ short v0,v1,v2,v3;
+} INDEX;
+
+/* Sprite position vertices */
+SVECTOR verts[] = {
+ { -50, -50, -50, 0 },
+ { 50, -50, -50, 0 },
+ { -50, 50, -50, 0 },
+ { 50, 50, -50, 0 },
+ { 50, -50, 50, 0 },
+ { -50, -50, 50, 0 },
+ { 50, 50, 50, 0 },
+ { -50, 50, 50, 0 }
+};
+
+
+/* Function declarations */
+void init();
+void display();
+
+
+/* Main function */
+int main() {
+
+ int i,p,sz;
+
+ SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */
+ VECTOR pos = { 0, 0, 160 }; /* Translation vector for TransMatrix */
+ MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */
+
+ POLY_FT4 *quad; /* Flat shaded quad primitive pointer */
+ SVECTOR spos;
+
+ /* Init graphics and GTE */
+ init();
+
+
+ /* Main loop */
+ while( 1 ) {
+
+ /* Set rotation and translation to the matrix */
+ RotMatrix( &rot, &mtx );
+ TransMatrix( &mtx, &pos );
+
+ /* Set rotation and translation matrix */
+ gte_SetRotMatrix( &mtx );
+ gte_SetTransMatrix( &mtx );
+
+ /* Make the sprites revolve around */
+ rot.vy += 16;
+ rot.vz += 16;
+
+ /* Draw the sprites */
+ quad = (POLY_FT4*)db_nextpri;
+
+ for( i=0; i<8; i++ ) {
+
+ // Load the 3D coordinate of the sprite to GTE
+ gte_ldv0(&verts[i]);
+
+ // Rotation, Translation and Perspective Single
+ gte_rtps();
+
+ // Store depth
+ gte_stsz(&p);
+
+ // Don't sort sprite if depth is zero
+ // (or divide by zero will happen later)
+ if( p > 0 ) {
+
+ // Store result to position vector
+ gte_stsxy2(&spos);
+
+ // Calculate sprite size, the divide operation might be a
+ // performance killer but it's likely faster than performing
+ // a lookat operation between sprite and camera, which some
+ // billboard sprite implementations use.
+ sz = (16*CENTERX)/p;
+
+ // Prepare quad primitive
+ setPolyFT4(quad);
+
+ // Set quad coordinates
+ setXY4(quad,
+ spos.vx-sz, spos.vy-sz,
+ spos.vx+sz, spos.vy-sz,
+ spos.vx-sz, spos.vy+sz,
+ spos.vx+sz, spos.vy+sz);
+
+ // Set color
+ setRGB0(quad, 128, 128, 128);
+
+ // Set tpage
+ quad->tpage = getTPage(tim.mode&0x8, 0, tim.prect->x, tim.prect->y);
+
+ // Set CLUT
+ setClut(quad, tim.crect->x, tim.crect->y);
+
+ // Set texture coordinates
+ setUVWH(quad, 0, 0, 64, 64);
+
+ /* Sort primitive to the ordering table */
+ addPrim(db[db_active].ot+(p>>2), quad);
+
+ /* Advance to make another primitive */
+ quad++;
+
+ }
+ }
+
+ /* Update nextpri variable */
+ /* (IMPORTANT if you plan to sort more primitives after this) */
+ db_nextpri = (char*)quad;
+
+ /* 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 );
+
+ GetTimInfo(tim_image, &tim);
+
+ LoadImage(tim.prect, tim.paddr);
+ DrawSync(0);
+
+ LoadImage(tim.crect, tim.caddr);
+ DrawSync(0);
+
+}
+
+void display() {
+
+ /* Wait for GPU to finish drawing and vertical retrace */
+ DrawSync( 0 );
+ VSync( 0 );
+
+ /* 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/billboard/makefile b/examples/billboard/makefile
new file mode 100644
index 0000000..4c22b0c
--- /dev/null
+++ b/examples/billboard/makefile
@@ -0,0 +1,39 @@
+include ../sdk-common.mk
+
+TARGET = billboard.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 = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc
+
+CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
+CPPFLAGS = $(CFLAGS) -fno-exceptions
+AFLAGS = -g -msoft-float
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+
+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/billboard/texture64.tim b/examples/billboard/texture64.tim
new file mode 100644
index 0000000..d3aff3a
--- /dev/null
+++ b/examples/billboard/texture64.tim
Binary files differ
diff --git a/examples/billboard/tim.s b/examples/billboard/tim.s
new file mode 100644
index 0000000..1fa8d69
--- /dev/null
+++ b/examples/billboard/tim.s
@@ -0,0 +1,7 @@
+.section .data
+
+.global tim_image
+.type tim_image, @object
+tim_image:
+ .incbin "texture64.tim"
+ \ No newline at end of file
diff --git a/examples/fpscam/main.c b/examples/fpscam/main.c
index 32c8de4..9dedf06 100644
--- a/examples/fpscam/main.c
+++ b/examples/fpscam/main.c
@@ -21,6 +21,7 @@
* R1 - Slide up
* R2 - Slide down
* L1 - Look at cube
+ * Select - Exit program (only works with CD loaders)
*
*
* Example by Lameguy64
@@ -29,6 +30,8 @@
*
* July 18, 2019 - Initial version.
*
+ * Sep 24, 2019 - Added camera position display and _boot() exit.
+ *
*/
#include <stdio.h>
@@ -36,6 +39,7 @@
#include <psxgte.h>
#include <psxpad.h>
#include <psxapi.h>
+#include <psxetc.h>
#include <inline_c.h>
#include "clip.h"
@@ -290,6 +294,10 @@ int main() {
}
+ if( !(pad->btn&PAD_SELECT) ) {
+ _boot();
+ }
+
}
// For dual-analog and dual-shock (analog input)
@@ -324,6 +332,15 @@ int main() {
}
+ // Print out some info
+ FntPrint(-1, "BUTTONS=%04x\n", pad->btn);
+ FntPrint(-1, "X=%d Y=%d Z=%d\n",
+ cam_pos.vx>>12,
+ cam_pos.vy>>12,
+ cam_pos.vz>>12);
+ FntPrint(-1, "RX=%d RY=%d\n",
+ cam_rot.vx>>12,
+ cam_rot.vy>>12);
// First-person camera mode
if( cam_mode == 0 ) {
@@ -439,6 +456,9 @@ int main() {
rot.vy += 8;
+ // Flush text to drawing area
+ FntFlush(-1);
+
// Swap buffers and draw the primitives
display();
@@ -625,6 +645,10 @@ void init() {
// Don't make pad driver acknowledge V-Blank IRQ (recommended)
ChangeClearPAD(0);
+ // Load font and open a text stream
+ FntLoad(960, 0);
+ FntOpen(0, 8, 320, 216, 0, 100);
+
}
void display() {
diff --git a/examples/fpscam/makefile b/examples/fpscam/makefile
index 7175c98..67fe7c2 100644
--- a/examples/fpscam/makefile
+++ b/examples/fpscam/makefile
@@ -11,7 +11,13 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o)
INCLUDE +=
LIBDIRS +=
+<<<<<<< .mine
+LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc
+||||||| .r23
LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lgcc
+=======
+LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc
+>>>>>>> .r27
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
diff --git a/examples/n00bdemo/plasma_tbl.c b/examples/n00bdemo/plasma_tbl.c
index 2cbd9b6..af6654a 100644
--- a/examples/n00bdemo/plasma_tbl.c
+++ b/examples/n00bdemo/plasma_tbl.c
@@ -1,4 +1,4 @@
-// These are from Meido-Menu which was a very simple demo I made back in 2013
+// These are from Meido-Demo which was a very simple demo I made back in 2013
// Man, time sure does fly. - Lameguy64
unsigned int plasma_colors[256] = {
diff --git a/libpsn00b/include/psxetc.h b/libpsn00b/include/psxetc.h
index 67df29f..d0c8bc1 100644
--- a/libpsn00b/include/psxetc.h
+++ b/libpsn00b/include/psxetc.h
@@ -7,6 +7,9 @@ extern "C" {
void FntLoad(int x, int y);
char *FntSort(unsigned int *ot, char *pri, int x, int y, const char *text);
+int FntOpen(int x, int y, int w, int h, int isbg, int n);
+int FntPrint(int id, const char *fmt, ...);
+char *FntFlush(int id);
#ifdef __cplusplus
}
diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h
index 215b59b..230775f 100644
--- a/libpsn00b/include/psxgpu.h
+++ b/libpsn00b/include/psxgpu.h
@@ -129,7 +129,7 @@
#define addPrims(ot, p0, p1) setaddr( p1, getaddr( ot ) ), setaddr( ot, p0 )
#define catPrim( p0, p1 ) setaddr( p0, p1 )
-#define termPrim( p ) setaddr( p, 0xffffffff )
+#define termPrim( p ) setaddr( p, 0xffffff )
#define setSemiTrans( p, abe ) \
( (abe)?setcode( p, getcode( p )|0x2 ):setcode( p, getcode( p )&~0x2 ) )
diff --git a/libpsn00b/libc/makefile b/libpsn00b/libc/makefile
index 67f2284..c925b53 100644
--- a/libpsn00b/libc/makefile
+++ b/libpsn00b/libc/makefile
@@ -12,7 +12,7 @@ AFILES = $(notdir $(wildcard ./*.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CXXFILES:.cxx=.o) $(AFILES:.s=.o))
CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute
-AFLAGS = -g -msoft-float -Wa,--strip-local-absolute
+AFLAGS = -g -msoft-float -Wa,-strip-local-absolute
CC = $(PREFIX)gcc
CXX = $(PREFIX)g++
diff --git a/libpsn00b/psxapi/stdio/putchar.s b/libpsn00b/libc/putchar.s
index a3f6c57..a3f6c57 100644
--- a/libpsn00b/psxapi/stdio/putchar.s
+++ b/libpsn00b/libc/putchar.s
diff --git a/libpsn00b/libc/vsprintf.c b/libpsn00b/libc/vsprintf.c
index 153ca21..361b24e 100644
--- a/libpsn00b/libc/vsprintf.c
+++ b/libpsn00b/libc/vsprintf.c
@@ -51,7 +51,7 @@
#define calculate_real_padding_hex() \
last = 0; \
- for (x = 0; x < 16; x++) \
+ for (x = 0; x < 8; x++) \
if((arg >> (x * 4)) & 0xf) \
last = x; \
\
@@ -125,15 +125,15 @@ unsigned int get_arg_in_size(int size, unsigned long *arg, unsigned int check_si
case SPRINTF_SIZE_LONG:
*arg &= 0xffffffff;
- /*if(check_sign)
+ if(check_sign)
{
if(*arg & (1<<31))
{
- *arg |= (long long)0xffffffff00000000;
+ //*arg |= (long long)0xffffffff00000000;
*arg = ~(*arg - 1);
s = 1;
}
- }*/
+ }
break;
/*case SPRINTF_SIZE_LONG_LONG:
@@ -440,7 +440,7 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap)
//printf("argsize = %d\n", argsize);
//if(argsize < SPRINTF_SIZE_LONG_LONG)
- arg = (unsigned long)va_arg(ap, unsigned int);
+ arg = (unsigned long)va_arg(ap, unsigned long);
//else
// arg = va_arg(ap, unsigned long);
@@ -527,7 +527,7 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap)
empty_digit = 1;
//if(argsize < SPRINTF_SIZE_LONG_LONG)
- arg = (unsigned long)va_arg(ap, unsigned int);
+ arg = (unsigned long)va_arg(ap, unsigned int);
//else
//arg = va_arg(ap, unsigned long long);
diff --git a/libpsn00b/lzp/makefile b/libpsn00b/lzp/makefile
index 1560302..aa495b5 100644
--- a/libpsn00b/lzp/makefile
+++ b/libpsn00b/lzp/makefile
@@ -5,8 +5,7 @@ TARGET = ../liblzp.a
CFILES = $(notdir $(wildcard ./*.c))
OFILES = $(addprefix build/,$(CFILES:.c=.o))
-CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -Wa,--strip-local-absolute
-AFLAGS = -g -msoft-float --strip-local-absolute
+CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections -ffunction-sections -Wa,--strip-local-absolute
CC = $(PREFIX)gcc
AR = $(PREFIX)ar
diff --git a/libpsn00b/psxetc/font.c b/libpsn00b/psxetc/font.c
index 46718d0..cd4acab 100644
--- a/libpsn00b/psxetc/font.c
+++ b/libpsn00b/psxetc/font.c
@@ -1,12 +1,27 @@
#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
#include <ctype.h>
#include <psxgpu.h>
-extern unsigned char dbugfont[];
+typedef struct _fnt_stream {
+ char *txtbuff;
+ char *txtnext;
+ char *pribuff;
+ short x,y;
+ short w,h;
+ int bg;
+ int maxchars;
+} _fnt_stream;
+
+static _fnt_stream _stream[8];
+static int _nstreams = 0;
unsigned short _font_tpage;
unsigned short _font_clut;
+extern unsigned char dbugfont[];
+
void FntLoad(int x, int y) {
RECT pos;
@@ -34,4 +49,177 @@ void FntLoad(int x, int y) {
LoadImage( &pos, tim.caddr );
DrawSync(0);
+ // Clear previously opened text streams
+ if( _nstreams ) {
+
+ int i;
+
+ for( i=0; i<_nstreams; i++ ) {
+ free(_stream[i].txtbuff);
+ free(_stream[i].pribuff);
+ }
+
+ _nstreams = 0;
+
+ }
+
+}
+
+int FntOpen(int x, int y, int w, int h, int isbg, int n) {
+
+ int i;
+
+ // Initialize a text stream
+ _stream[_nstreams].x = x;
+ _stream[_nstreams].y = y;
+ _stream[_nstreams].w = w;
+ _stream[_nstreams].h = h;
+
+ _stream[_nstreams].txtbuff = (char*)malloc(n+1);
+
+ i = (sizeof(SPRT_8)*n)+sizeof(DR_TPAGE);
+
+ if( isbg ) {
+ i += sizeof(TILE);
+ }
+
+ _stream[_nstreams].pribuff = (char*)malloc(i);
+ _stream[_nstreams].maxchars = n;
+
+ _stream[_nstreams].txtbuff[0] = 0x0;
+ _stream[_nstreams].txtnext = _stream[_nstreams].txtbuff;
+ _stream[_nstreams].bg = isbg;
+
+ n = _nstreams;
+ _nstreams++;
+
+ return n;
+
+}
+
+int FntPrint(int id, const char *fmt, ...) {
+
+ int n;
+ va_list ap;
+
+ if( id < 0 )
+ id = _nstreams-1;
+
+ n = strlen(_stream[id].txtbuff);
+
+ if( n >= _stream[id].maxchars ) {
+ return n;
+ }
+
+ va_start(ap, fmt);
+
+ n = vsnprintf(_stream[id].txtnext, _stream[id].maxchars-n, fmt, ap);
+
+ _stream[id].txtnext += n;
+
+ va_end(ap);
+
+ return strlen(_stream[id].txtbuff);
+
}
+
+char *FntFlush(int id) {
+
+ char *opri;
+ SPRT_8 *sprt;
+ DR_TPAGE *tpage;
+ char *text;
+ int i,sx,sy;
+
+ if( id < 0 )
+ id = _nstreams-1;
+
+ sx = _stream[id].x;
+ sy = _stream[id].y;
+
+ text = _stream[id].txtbuff;
+
+ opri = _stream[id].pribuff;
+
+ // Create TPage primitive
+ tpage = (DR_TPAGE*)opri;
+ setDrawTPage(tpage, 0, 0, _font_tpage);
+
+ // Create a black rectangle background when enabled
+ if( _stream[id].bg ) {
+
+ TILE *tile;
+ opri += sizeof(DR_TPAGE);
+ tile = (TILE*)opri;
+
+ setTile(tile);
+
+ if( _stream[id].bg == 2 )
+ setSemiTrans(tile, 1);
+
+ setXY0(tile, _stream[id].x, _stream[id].y);
+ setWH(tile, _stream[id].w, _stream[id].h);
+ setRGB0(tile, 0, 0, 0);
+ setaddr(tpage, tile);
+ opri = (char*)tile;
+
+ sprt = (SPRT_8*)(opri+sizeof(TILE));
+
+ } else {
+
+ sprt = (SPRT_8*)(opri+sizeof(DR_TPAGE));
+
+ }
+
+ // Create the sprite primitives
+ while( *text != 0 ) {
+
+ if( ( *text == '\n' ) || ( ( sx-_stream[id].x ) > _stream[id].w-8 ) ) {
+ sx = _stream[id].x;
+ sy += 8;
+
+ if( *text == '\n' )
+ text++;
+
+ continue;
+ }
+
+ if( ( sy-_stream[id].y ) > _stream[id].h-8 ) {
+ break;
+ }
+
+ i = toupper( *text )-32;
+
+ if( i > 0 ) {
+
+ i--;
+ setSprt8( sprt );
+ setRGB0( sprt, 128, 128, 128 );
+ setXY0( sprt, sx, sy );
+ setUV0( sprt, (i%16)<<3, (i>>4)<<3 );
+ sprt->clut = _font_clut;
+ setaddr(opri, sprt);
+ opri = (char*)sprt;
+ sprt++;
+
+ }
+
+ sx += 8;
+ text++;
+
+ }
+
+ // Set a terminator value to the last primitive
+ termPrim(opri);
+
+ // Draw the primitives
+ DrawSync(0);
+ DrawOTag((unsigned int*)_stream[id].pribuff);
+ DrawSync(0);
+
+ _stream[id].txtnext = _stream[id].txtbuff;
+ _stream[id].txtbuff[0] = 0;
+
+ return _stream[id].pribuff;
+
+} \ No newline at end of file
diff --git a/libpsn00b/psxetc/makefile b/libpsn00b/psxetc/makefile
index 56bdce7..399fb91 100644
--- a/libpsn00b/psxetc/makefile
+++ b/libpsn00b/psxetc/makefile
@@ -10,8 +10,8 @@ CFILES = $(notdir $(wildcard ./*.c))
AFILES = $(notdir $(wildcard ./*.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o))
-CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -Wa,--strip-local-absolute
-AFLAGS = -g -msoft-float --strip-local-absolute
+CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections -ffunction-sections -Wa,--strip-local-absolute
+AFLAGS = -g -msoft-float -strip-local-absolute
CC = $(PREFIX)gcc
AS = $(PREFIX)as
diff --git a/libpsn00b/psxetc/readme.txt b/libpsn00b/psxetc/readme.txt
index ba4db50..f2e7649 100644
--- a/libpsn00b/psxetc/readme.txt
+++ b/libpsn00b/psxetc/readme.txt
@@ -16,7 +16,3 @@ Library header(s):
psxetc.h
-
-Changelog:
-
- None thus far...
diff --git a/libpsn00b/psxgpu/makefile b/libpsn00b/psxgpu/makefile
index 7a7de5d..980e311 100644
--- a/libpsn00b/psxgpu/makefile
+++ b/libpsn00b/psxgpu/makefile
@@ -10,7 +10,7 @@ CFILES = $(notdir $(wildcard ./*.c))
AFILES = $(notdir $(wildcard ./*.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o))
-CFLAGS = -g -O2 -msoft-float -fno-builtin -Wa,--strip-local-absolute
+CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute
AFLAGS = -g -msoft-float -Wa,--strip-local-absolute
CC = $(PREFIX)gcc
diff --git a/libpsn00b/psxgte/makefile b/libpsn00b/psxgte/makefile
index f460a44..270f719 100644
--- a/libpsn00b/psxgte/makefile
+++ b/libpsn00b/psxgte/makefile
@@ -11,7 +11,7 @@ AFILES = $(notdir $(wildcard ./*.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o))
CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute
-AFLAGS = -g -msoft-float --strip-local-absolute
+AFLAGS = -g -msoft-float -strip-local-absolute
CC = $(PREFIX)gcc
AS = $(PREFIX)as
diff --git a/libpsn00b/psxsio/makefile b/libpsn00b/psxsio/makefile
index b59f3c6..67ea93b 100644
--- a/libpsn00b/psxsio/makefile
+++ b/libpsn00b/psxsio/makefile
@@ -10,7 +10,7 @@ CFILES = $(notdir $(wildcard ./*.c))
AFILES = $(notdir $(wildcard ./*.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o))
-CFLAGS = -g -O2 -msoft-float -fno-builtin -Wa,--strip-local-absolute
+CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute
AFLAGS = -g -msoft-float -Wa,--strip-local-absolute
CC = $(PREFIX)gcc
diff --git a/libpsn00b/psxspu/makefile b/libpsn00b/psxspu/makefile
index 661a32b..c492ffe 100644
--- a/libpsn00b/psxspu/makefile
+++ b/libpsn00b/psxspu/makefile
@@ -6,8 +6,8 @@ CFILES = $(notdir $(wildcard ./*.c))
AFILES = $(notdir $(wildcard ./*.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o))
-CFLAGS = -g -O2 -msoft-float -Wa,--strip-local-absolute
-AFLAGS = -g -msoft-float --strip-local-absolute
+CFLAGS = -g -O2 -msoft-float -fdata-sections -ffunction-sections -Wa,--strip-local-absolute
+AFLAGS = -g -msoft-float -strip-local-absolute
CC = $(PREFIX)gcc
AS = $(PREFIX)as