diff options
| author | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-01-31 10:32:23 +0100 |
|---|---|---|
| committer | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-01-31 10:32:23 +0100 |
| commit | 7c24e9a9b02b04dcaf9507acb94091ea70a2c02d (patch) | |
| tree | c28d0748652ad4b4222309e46e6cfc82c0906220 /libpsx/src/sio.c | |
| parent | a2b7b6bb1cc2f4a3258b7b2dbc92399d151f864d (diff) | |
| download | psxsdk-7c24e9a9b02b04dcaf9507acb94091ea70a2c02d.tar.gz | |
Imported pristine psxsdk-20190410 from official repo
Diffstat (limited to 'libpsx/src/sio.c')
| -rw-r--r-- | libpsx/src/sio.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libpsx/src/sio.c b/libpsx/src/sio.c new file mode 100644 index 0000000..5d399d3 --- /dev/null +++ b/libpsx/src/sio.c @@ -0,0 +1,64 @@ +/*
+ * SIO communication library for PSXSDK.
+ * Originally written by Shendo.
+ * Thanks to Martin Korth of the NO$PSX for documentation.
+ *
+ * This library is accessing SIO registers directly, no BIOS routines are used.
+ */
+
+#include <psx.h>
+#include <psxsio.h>
+#include <stdio.h>
+
+void SIOStart(int bitrate)
+{
+ /*Set to 8N1 mode with desired bitrate*/
+ SIOStartEx(bitrate, SIO_DATA_LEN_8, SIO_PARITY_NONE, SIO_STOP_BIT_1);
+}
+
+void SIOStartEx(int bitrate, int datalength, int parity, int stopbit)
+{
+ /*Set SIO_MODE register, bitrate reload factor set to MUL16 by default*/
+ SIO_MODE = SIO_REL_MUL16 | (datalength << 2) | (parity << 4) | (stopbit << 6);
+
+ /*Reset SIO_CTRL register.*/
+ SIO_CTRL = 0;
+
+ /*Set TX and RT to enabled, no handshaking signals.*/
+ SIO_CTRL = 1 | (1 << 2);
+
+ /*Calculate bitrate reload value based on the given bitrate
+ * Reload = SystemClock (33 Mhz) / (Factor (MULI16) * bitrate)*/
+ SIO_BPSV = 0x204CC00 / (16 * bitrate);
+}
+
+void SIOStop()
+{
+ /*Set all SIO related registers to zero*/
+ SIO_MODE = 0;
+ SIO_CTRL = 0;
+ SIO_BPSV = 0;
+}
+
+unsigned char SIOReadByte()
+{
+ return (unsigned char)SIO_TX_RX;
+}
+
+void SIOSendByte(unsigned char data)
+{
+ SIO_TX_RX = data;
+}
+
+int SIOCheckInBuffer()
+{
+ /*Return status of RX FIFO*/
+ return (SIO_STAT & 0x2)>0;
+}
+
+int SIOCheckOutBuffer()
+{
+ /*Return status of TX Ready flag*/
+ return (SIO_STAT & 0x4)>0;
+}
+
\ No newline at end of file |
