aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b
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 /libpsn00b
parent7d001b2a757383665ef3151ed961d921640e00bf (diff)
downloadpsn00bsdk-d80d92e13330d527ddb94420b19f9e21bf0e74eb.tar.gz
Added FntOpen(), FntPrint() and FntFlush(), fixed termPrim() typo, fixed negative values in vsprintf(), added billboard sprites example
Diffstat (limited to 'libpsn00b')
-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
13 files changed, 208 insertions, 22 deletions
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