aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/psxsio
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-06-23 07:42:16 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2019-06-23 07:42:16 +0800
commit7be9178c0f9b0e698a305ecc5c0c41fcc596a4fc (patch)
treee98c627e1da5c764563774b89b0c06d7ac5ad0a4 /libpsn00b/psxsio
parentae9e545c3ed33d39ce21ae13ceb8337fa34901b8 (diff)
downloadpsn00bsdk-7be9178c0f9b0e698a305ecc5c0c41fcc596a4fc.tar.gz
LibPSn00b officially v0.10b, added psxsio library, better DrawSync() and VSync(), better reference manual.
Diffstat (limited to 'libpsn00b/psxsio')
-rw-r--r--libpsn00b/psxsio/_sio_control.s182
-rw-r--r--libpsn00b/psxsio/makefile38
-rw-r--r--libpsn00b/psxsio/siocons.c137
3 files changed, 357 insertions, 0 deletions
diff --git a/libpsn00b/psxsio/_sio_control.s b/libpsn00b/psxsio/_sio_control.s
new file mode 100644
index 0000000..bae7822
--- /dev/null
+++ b/libpsn00b/psxsio/_sio_control.s
@@ -0,0 +1,182 @@
+.set noreorder
+
+.include "hwregs_a.h"
+
+.section .text
+
+# Currently implemented serial control functions:
+#
+# cmd(a0) sub(a1)
+# 0 0 Get serial status
+# 0 1 Get control line status
+# 0 2 Get serial mode
+# 0 3 Get baud rate
+# 0 4 Read 1 byte
+# 1 1 Set serial control
+# 1 2 Set serial mode
+# 1 3 Set baud rate
+# 1 4 Write 1 byte
+# 2 0 Reset serial
+# 2 1 Acknowledge serial
+
+.global _sio_control
+.type _sio_control, @function
+_sio_control:
+
+ # a0 - command
+ # a1 - subcommand
+ # a2 - argument
+
+ lui $a3, IOBASE
+
+ beq $a0, $0, .Lcmd0
+ nop
+ beq $a0, 1, .Lcmd1
+ nop
+ beq $a0, 2, .Lcmd2
+ nop
+ jr $ra
+ nop
+
+
+.Lcmd0:
+
+ beq $a1, $0, .Lcmd0arg0
+ nop
+ beq $a1, 1, .Lcmd0arg1
+ nop
+ beq $a1, 2, .Lcmd0arg2
+ nop
+ beq $a1, 3, .Lcmd0arg3
+ nop
+ beq $a1, 4, .Lcmd0arg4
+ nop
+ jr $ra
+ nop
+
+.Lcmd0arg0: # Get SIO status
+
+ lhu $v0, SIO_STAT($a3)
+ nop
+
+ jr $ra
+ andi $v0, 0x3FF
+
+.Lcmd0arg1: # Get control line status
+
+ lhu $v1, SIO_CTRL($a3)
+ nop
+ srl $v0, $v1, 1
+ andi $v0, 0x1
+ srl $v1, 4
+ andi $v1, 0x2
+
+ jr $ra
+ or $v0, $v1
+
+
+.Lcmd0arg2: # Get serial mode
+
+ lhu $v0, SIO_MODE($a3)
+ nop
+ jr $ra
+ andi $v0, 0xFF
+
+.Lcmd0arg3:
+
+ lui $v1, 0x1f
+ lhu $v0, SIO_BAUD($a3)
+ ori $v1, 0xa400
+ div $v1, $v0
+ nop
+ nop
+ jr $ra
+ mflo $v0
+
+.Lcmd0arg4: # Serial RX read
+
+ lbu $v0, SIO_TXRX($a3)
+ nop
+ jr $ra
+ nop
+
+
+.Lcmd1:
+
+ beq $a1, 1, .Lcmd1arg1
+ nop
+ beq $a1, 2, .Lcmd1arg2
+ nop
+ beq $a1, 3, .Lcmd1arg3
+ nop
+ beq $a1, 4, .Lcmd1arg4
+ nop
+ jr $ra
+ nop
+
+.Lcmd1arg1:
+
+ andi $v0, $a2, 0x1CFF
+
+ jr $ra
+ sh $a2, SIO_CTRL($a3)
+
+.Lcmd1arg2:
+
+ jr $ra
+ sh $a2, SIO_MODE($a3)
+
+.Lcmd1arg3:
+
+ lui $v0, 0x1f
+ ori $v0, 0xa400
+ divu $v0, $a2
+ bnez $a2, .Lgood_baud
+ nop
+ jr $ra
+ nop
+
+.Lgood_baud:
+
+ mflo $v0
+ sh $v0, SIO_BAUD($a3)
+ nop
+ jr $ra
+ nop
+
+.Lcmd1arg4:
+
+ sb $a2, SIO_TXRX($a3)
+ nop
+ jr $ra
+ nop
+
+.Lcmd2:
+
+ beq $a1, $0 , .Lcmd2arg0
+ li $v0, 1
+ beq $a1, $v0, .Lcmd2arg1
+ nop
+ jr $ra
+ nop
+
+.Lcmd2arg0:
+
+ li $v0, 0x40
+ sh $v0, SIO_CTRL($a3)
+ sh $0 , SIO_MODE($a3)
+ sh $0 , SIO_BAUD($a3)
+ nop
+ jr $ra
+ nop
+
+.Lcmd2arg1:
+
+ lhu $v0, SIO_CTRL($a3)
+ nop
+ ori $v0, 0x10
+ sh $v0, SIO_CTRL($a3)
+ jr $ra
+ nop
+
+ \ No newline at end of file
diff --git a/libpsn00b/psxsio/makefile b/libpsn00b/psxsio/makefile
new file mode 100644
index 0000000..ecd6c65
--- /dev/null
+++ b/libpsn00b/psxsio/makefile
@@ -0,0 +1,38 @@
+# Run using make (Linux) or gmake (BSD)
+# Part of the PSn00bSDK Project
+# 2019 Lameguy64 / Meido-Tek Productions
+
+PREFIX = mipsel-unknown-elf-
+
+TARGET = ../libpsxsio.a
+
+CFILES = $(notdir $(wildcard ./*.c))
+AFILES = $(notdir $(wildcard ./*.s))
+OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o))
+
+INCLUDE = -I../include
+
+CFLAGS = -O2 -msoft-float -fno-builtin -Wa,--strip-local-absolute
+AFLAGS = -msoft-float -Wa,--strip-local-absolute
+
+CC = $(PREFIX)gcc
+AS = $(PREFIX)as
+AR = $(PREFIX)ar
+RANLIB = $(PREFIX)ranlib
+
+all: $(TARGET)
+
+$(TARGET): $(OFILES)
+ $(AR) cr $(TARGET) $(OFILES)
+ $(RANLIB) $(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)
diff --git a/libpsn00b/psxsio/siocons.c b/libpsn00b/psxsio/siocons.c
new file mode 100644
index 0000000..cd99d68
--- /dev/null
+++ b/libpsn00b/psxsio/siocons.c
@@ -0,0 +1,137 @@
+#include <stdio.h>
+#include <psxapi.h>
+#include <psxgpu.h>
+#include <psxsio.h>
+
+static void _sio_init() {
+}
+
+static int _sio_open(FCB *fcb, const char* file, int mode) {
+
+ fcb->diskid = 1;
+
+ return 0;
+
+}
+
+static int _sio_inout(FCB *fcb, int cmd) {
+
+ int i;
+
+ if(cmd == 2) { // Write
+
+ for(i=0; i<fcb->trns_len; i++) {
+ while(!(_sio_control(0, 0, 0) & SR_TXU));
+ _sio_control(1, 4, ((char*)fcb->trns_addr)[i]);
+ }
+
+ return fcb->trns_len;
+
+ } else if (cmd == 1) { // Read
+
+ for(i=0; i<fcb->trns_len; i++) {
+ while(!(_sio_control(0, 0, 0) & SR_RXRDY));
+ ((char*)fcb->trns_addr)[i] = _sio_control(0, 4, 0);
+ }
+
+ return fcb->trns_len;
+
+ }
+
+ return 0;
+
+}
+
+static int _sio_close(int h) {
+
+ return h;
+
+}
+
+static DCB _sio_dcb = {
+ "tty",
+ 0x3,
+ 0x1,
+ 0x0,
+ (void*)_sio_init, // init
+ (void*)_sio_open, // open
+ (void*)_sio_inout, // inout
+ _sio_close, // close
+ NULL, // ioctl
+ NULL, // read
+ NULL, // write
+ NULL, // erase
+ NULL, // undelete
+ NULL, // firstfile
+ NULL, // nextfile
+ NULL, // format
+ NULL, // chdir
+ NULL, // rename
+ NULL, // remove
+ NULL // testdevice
+};
+
+
+volatile void (*_sio_callback)(void) = NULL;
+
+extern void _sio_irq_handler(void);
+
+
+void AddSIO(int baud) {
+
+ _sio_control(2, 0, 0);
+ _sio_control(1, 2, MR_SB_01|MR_CHLEN_8|0x02);
+ _sio_control(1, 3, baud);
+ _sio_control(1, 1, CR_RXEN|CR_TXEN);
+
+ close(0);
+ close(1);
+
+ DelDev(_sio_dcb.name);
+ AddDev(&_sio_dcb);
+
+ open(_sio_dcb.name, 2);
+ open(_sio_dcb.name, 1);
+
+}
+
+void DelSIO(void) {
+
+ // Reset serial interface
+ _sio_control(2, 0, 0);
+
+ // Remove TTY device
+ DelDev(_sio_dcb.name);
+
+}
+
+void WaitSIO(void) {
+
+ while((_sio_control(0, 0, 0)&(SR_RXRDY)) != (SR_RXRDY));
+ _sio_control(0, 4, NULL);
+
+}
+
+void *Sio1Callback(void (*func)()) {
+
+ void *old_isr; //= *((int*)&_sio_callback);
+
+ EnterCriticalSection();
+
+ if( func ) {
+
+ old_isr = InterruptCallback(8, func);
+ //_sio_callback = func;
+
+ } else {
+
+ old_isr = InterruptCallback(8, NULL);
+ //_sio_callback = NULL;
+
+ }
+
+ ExitCriticalSection();
+
+ return old_isr;
+
+} \ No newline at end of file