|
Nugget
Bare-metal libraries and examples for the original PlayStation
|
#include "common/hardware/hwregs.h"#include "common/hardware/irq.h"#include "common/hardware/sio.h"#include "common/syscalls/syscalls.h"#include "exotic/cester.h"
Macros | |
| #define | PCSX_TESTS 0 |
| #define | CESTER_NO_SIGNAL |
| #define | CESTER_NO_TIME |
| #define | EXIT_SUCCESS 0 |
| #define | EXIT_FAILURE 1 |
Functions | |
| CESTER_BODY (static int s_interruptsWereEnabled;static int s_host;static int s_req1;static uint8_t s_reply;static uint8_t s_ack;static void settle(int n) { for(;n > 0;n--) __asm__ volatile("");} static void padSelect(int port) { SIOS[0].ctrl=SIO_CTRL_DTR|(port ? SIO_CTRL_PORTSEL :0);SIOS[0].baudRate=0x88;SIOS[0].mode=0xd;while(SIOS[0].stat &SIO_STAT_RXRDY) {(void) SIOS[0].fifo;} SIOS[0].ctrl|=SIO_CTRL_TXEN|SIO_CTRL_ACKIRQEN;settle(100);} static void padDeselect(void) { SIOS[0].ctrl=0;settle(100);} static uint8_t padTransceive(uint8_t out, uint8_t *ack) { int i;uint8_t in;SIOS[0].ctrl|=SIO_CTRL_ERRRES;IREG=~IRQ_CONTROLLER;SIOS[0].fifo=out;while(!(SIOS[0].stat &SIO_STAT_RXRDY)) __asm__ volatile("");in=SIOS[0].fifo;*ack=0;for(i=0;i< 4000;i++) { if(IREG &IRQ_CONTROLLER) { *ack=1;break;} } return in;} static void padFrame(int port, const uint8_t *out, int n) { int i;padSelect(port);for(i=0;i< n;i++) s_reply[i]=padTransceive(out[i], &s_ack[i]);padDeselect();} static void padRead(int port, uint8_t addr, uint8_t req, int n) { uint8_t out[40];int i;for(i=0;i< n;i++) out[i]=0;out[0]=addr;out[1]=0x42;out[2]=req;padFrame(port, out, n);} static void padReadLong(uint8_t req) { uint8_t out[35];int i;for(i=0;i< 35;i++) out[i]=0;out[0]=0x01;out[1]=0x42;out[2]=req;for(i=0;i< 4;i++) out[3+i *8]=0x42;padFrame(0, out, 35);} static void dumpReply(const char *what, int n) { int i;ramsyscall_printf("%s:", what);for(i=0;i< n;i++) ramsyscall_printf(" %02x%s", s_reply[i], s_ack[i] ? "" :"!");ramsyscall_printf("\n");}[40][40]) | |
| if (s_req1) | |
| cester_assert_uint_eq (s_reply[1], 0x80) | |
| cester_assert_uint_eq (s_reply[2], 0x5a) | |
| for (i=0;i< 32;i++) | |
| cester_assert_uint_eq (s_ack[34], 0) | |
| padRead (0, 0x01, 0x00, 5) | |
| dumpReply ("after long, REQ=0", 5) | |
| cester_assert_uint_eq (s_reply[1], 0x41) | |
| CESTER_TEST (multitapRequestDuringLongRead, CESTER_TEST(multitap_tests, if(s_req1) return;padRead(0, 0x01, 0x01, 5);padReadLong(0x01);cester_assert_uint_eq(s_reply[1], s_host ? 0x80 :0x41);padReadLong(0x00);dumpReply("long after long", 35);cester_assert_uint_eq(s_reply[1], s_host ? 0x80 :0x41);if(s_host) { cester_assert_uint_eq(s_reply[11], 0x41);cester_assert_uint_eq(s_reply[14], 0xef);}) | |
| padRead (0, 0x04, 0x00, 5) | |
| dumpReply ("04 42 00", 5) | |
| if (s_host) | |
| padRead (0, 0x03, 0x00, 5) | |
| dumpReply ("03 42 00", 5) | |
| cester_assert_uint_eq (s_ack[0], 0) | |
| CESTER_TEST (multitapAbsentOnPort2, CESTER_TEST(multitap_tests, if(s_req1) return;padRead(1, 0x02, 0x00, 5);dumpReply("port 2: 02 42 00", 5);cester_assert_uint_eq(s_ack[0], 0);) | |
Variables | |
| int | i |
| else | |
| #define CESTER_NO_SIGNAL |
| #define CESTER_NO_TIME |
| #define EXIT_FAILURE 1 |
| #define EXIT_SUCCESS 0 |
| #define PCSX_TESTS 0 |
| cester_assert_uint_eq | ( | s_ack | [0], |
| 0 | |||
| ) |
| cester_assert_uint_eq | ( | s_ack | [34], |
| 0 | |||
| ) |
| cester_assert_uint_eq | ( | s_reply | [1], |
| 0x41 | |||
| ) |
| cester_assert_uint_eq | ( | s_reply | [1], |
| 0x80 | |||
| ) |
| cester_assert_uint_eq | ( | s_reply | [2], |
| 0x5a | |||
| ) |
| CESTER_BODY | ( | static int s_interruptsWereEnabled;static int s_host;static int s_req1;static uint8_t s_reply;static uint8_t s_ack;static void settle(int n) { for(;n > 0;n--) __asm__ volatile("");} static void padSelect(int port) { SIOS[0].ctrl=SIO_CTRL_DTR|(port ? SIO_CTRL_PORTSEL :0);SIOS[0].baudRate=0x88;SIOS[0].mode=0xd;while(SIOS[0].stat &SIO_STAT_RXRDY) {(void) SIOS[0].fifo;} SIOS[0].ctrl|=SIO_CTRL_TXEN|SIO_CTRL_ACKIRQEN;settle(100);} static void padDeselect(void) { SIOS[0].ctrl=0;settle(100);} static uint8_t padTransceive(uint8_t out, uint8_t *ack) { int i;uint8_t in;SIOS[0].ctrl|=SIO_CTRL_ERRRES;IREG=~IRQ_CONTROLLER;SIOS[0].fifo=out;while(!(SIOS[0].stat &SIO_STAT_RXRDY)) __asm__ volatile("");in=SIOS[0].fifo; *ack=0;for(i=0;i< 4000;i++) { if(IREG &IRQ_CONTROLLER) { *ack=1;break;} } return in;} static void padFrame(int port, const uint8_t *out, int n) { int i;padSelect(port);for(i=0;i< n;i++) s_reply[i]=padTransceive(out[i], &s_ack[i]);padDeselect();} static void padRead(int port, uint8_t addr, uint8_t req, int n) { uint8_t out[40];int i;for(i=0;i< n;i++) out[i]=0;out[0]=addr;out[1]=0x42;out[2]=req;padFrame(port, out, n);} static void padReadLong(uint8_t req) { uint8_t out[35];int i;for(i=0;i< 35;i++) out[i]=0;out[0]=0x01;out[1]=0x42;out[2]=req;for(i=0;i< 4;i++) out[3+i *8]=0x42;padFrame(0, out, 35);} static void dumpReply(const char *what, int n) { int i;ramsyscall_printf("%s:", what);for(i=0;i< n;i++) ramsyscall_printf(" %02x%s", s_reply[i], s_ack[i] ? "" :"!");ramsyscall_printf("\n");} | [40][40] | ) |
| CESTER_TEST | ( | multitapAbsentOnPort2 | , |
| CESTER_TEST( | multitap_tests, | ||
| if(s_req1) return;padRead(1, 0x02, 0x00, 5);dumpReply("port 2: 02 42 00", 5);cester_assert_uint_eq(s_ack[0], 0); | |||
| ) |
| CESTER_TEST | ( | multitapRequestDuringLongRead | , |
| CESTER_TEST( | multitap_tests, | ||
| if(s_req1) return;padRead(0, 0x01, 0x01, 5);padReadLong(0x01);cester_assert_uint_eq(s_reply[1], s_host ? 0x80 :0x41);padReadLong(0x00);dumpReply("long after long", 35);cester_assert_uint_eq(s_reply[1], s_host ? 0x80 :0x41);if(s_host) { cester_assert_uint_eq(s_reply[11], 0x41);cester_assert_uint_eq(s_reply[14], 0xef);} | |||
| ) |
| dumpReply | ( | "03 42 00" | , |
| 5 | |||
| ) |
| dumpReply | ( | "04 42 00" | , |
| 5 | |||
| ) |
| dumpReply | ( | "after long | ) |
| for | ( | ) |
| if | ( | s_host | ) |
| if | ( | s_req1 | ) |
| padRead | ( | 0 | , |
| 0x01 | , | ||
| 0x00 | , | ||
| 5 | |||
| ) |
| padRead | ( | 0 | , |
| 0x03 | , | ||
| 0x00 | , | ||
| 5 | |||
| ) |
| padRead | ( | 0 | , |
| 0x04 | , | ||
| 0x00 | , | ||
| 5 | |||
| ) |
| else |
| int i |