PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
sbus_tty.c
1/*
2
3IOP->EE TTY over SBUS by Herben
4
5This file contains the file system driver and glue needed to create a TTY file file system and redirect it to EE over SBUS.
6
7Additionally it installs a Kprintf handler so you can even see the things you don't normally see like the error messages WaitSema gives
8for those naughty ps2ip modules. ;)
9
10Of course this requires that the EE-side code accept this command and output the string to screen/sio...
11
12*/
13
14#include <tamtypes.h>
15#include <stdio.h>
16#include <stdarg.h>
17#include <errno.h>
18#include <sysclib.h>
19#include <sysmem.h>
20#include <excepman.h>
21#include <intrman.h>
22#include <ioman.h>
23#include <ps2_debug.h>
24#include <ps2_sbus.h>
25
26#include "iopdebug.h"
27
28extern void sbus_tty_puts(const char *str);
29
30static int ttyfs_init()
31{
32 //DBG_puts("SIOTTY: FS Init()\n");
33 return 0;
34}
35
36static int ttyfs_deinit()
37{
38 //DBG_puts("SIOTTY: FS Deinit()\n");
39 return 0;
40}
41
42static int ttyfs_open(iop_file_t *file, const char *name, int flags)
43{
44 (void)file;
45 (void)name;
46 (void)flags;
47
48 //DBG_puts("SIOTTY: FS Open()\n");
49 return 0;
50}
51
52static int ttyfs_dopen(iop_file_t *file, const char *name)
53{
54 (void)file;
55 (void)name;
56
57 //DBG_puts("SIOTTY: FS Dopen()\n");
58 return 0;
59}
60
61static int ttyfs_close(iop_file_t *file)
62{
63 (void)file;
64
65 //DBG_puts("SIOTTY: FS Close()\n");
66 return(0);
67}
68
69static int ttyfs_write(iop_file_t *file, void *ptr, int size) {
70 char temp[65];
71 int bCount = 0;
72
73 (void)file;
74
75 //DBG_puts("SIOTTY: FS Write()\n");
76
77 while(bCount < size)
78 {
79 int toWrite;
80
81 toWrite = (size - bCount);
82 if(toWrite > 64)
83 toWrite = 64;
84
85 memcpy(temp, &(((u8 *)ptr)[bCount]), toWrite);
86 temp[toWrite] = '\0';
87 sbus_tty_puts(temp);
88
89 bCount += toWrite;
90 }
91
92 return(bCount);
93}
94
95IOMAN_RETURN_VALUE_IMPL(EPERM);
96
97static iop_device_ops_t fsd_ops =
98{
99 &ttyfs_init, // init
100 &ttyfs_deinit, // deinit
101 IOMAN_RETURN_VALUE(EPERM), // format
102 &ttyfs_open, // open
103 &ttyfs_close, // close
104 IOMAN_RETURN_VALUE(EPERM), // read
105 &ttyfs_write, // write
106 IOMAN_RETURN_VALUE(EPERM), // lseek
107 IOMAN_RETURN_VALUE(EPERM), // ioctl
108 IOMAN_RETURN_VALUE(EPERM), // remove
109 IOMAN_RETURN_VALUE(EPERM), // mkdir
110 IOMAN_RETURN_VALUE(EPERM), // rmdir
111 &ttyfs_dopen, // dopen
112 &ttyfs_close, // dclose
113 IOMAN_RETURN_VALUE(EPERM), // dread
114 IOMAN_RETURN_VALUE(EPERM), // getstat
115 IOMAN_RETURN_VALUE(EPERM), // chstat
116};
117
118static iop_device_t tty_fsd =
119{
120 "tty",
121 IOP_DT_FS,
122 1,
123 "TTY via EE SIO",
124 &fsd_ops,
125};
126
127void sprintf_putchar(void *context, int c)
128{
129 char **string = (char **)context;
130
131 if(c < 0x100) { ((*string)++)[0] = c; }
132 else { (*string)[0] = 0; }
133}
134
135extern int _vsprintf(char * str, const char * format, va_list ap);
136
137static char kprint_buffer[1024];
138
139int _kPrintf(void *context, const char * format, va_list ap)
140{
141 (void)context;
142
143 int r = prnt(&sprintf_putchar, &format, format, ap);
144 sbus_tty_puts(kprint_buffer);
145 return r;
146}
147
148int sbus_tty_init(void)
149{
150 close(0);
151 close(1);
152 DelDrv(tty_fsd.name);
153 DelDrv("dummytty");
154
155 if(AddDrv(&tty_fsd) != 0) { return(-1); }
156
157 open("tty:", O_RDONLY);
158 open("tty:", O_WRONLY);
159
160 KprintfSet(&_kPrintf, NULL);
161
162 return(0);
163}
#define EPERM
Definition errno.h:21