aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/wii/gecko_console.cpp
blob: c419f6e7e5cd3668ca41e4f45f28a364847d6b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*-------------------------------------------------------------

Copyright (C) 2008
Hector Martin (marcan)

This software is provided 'as-is', without any express or implied
warranty.  In no event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:

1.	The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.

2.	Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.

3.	This notice may not be removed or altered from any source
distribution.

-------------------------------------------------------------*/

#include <stdio.h>
#include <sys/iosupport.h>
#include <ogcsys.h>
#include <gccore.h>
#include <reent.h>

#include "gecko_console.h"

#ifdef __cplusplus
extern "C" {
#endif

static const devoptab_t *dotab_console;
int usb_sendbuffer_safe(s32 chn,const void *buffer,int size);
int usb_sendbuffer(s32 chn,const void *buffer,int size);

int __gecko_write(struct _reent *r,int fd,const char *ptr,int len) {
	char *tmp = (char*)ptr;
	u32 level;
	if(dotab_console)
		dotab_console->write_r(r,fd,ptr,len);
		
	if(!tmp || len<=0)
		return -1;
	level = IRQ_Disable();
	usb_sendbuffer(1, ptr, len);
	IRQ_Restore(level);
	return len;
}

const devoptab_t dotab_gecko = {
	"stdout",	// device name
	0,			// size of file structure
	NULL,		// device open
	NULL,		// device close
	__gecko_write,	// device write
	NULL,		// device read
	NULL,		// device seek
	NULL,		// device fstat
	NULL,		// device stat
	NULL,		// device link
	NULL,		// device unlink
	NULL,		// device chdir
	NULL,		// device rename
	NULL,		// device mkdir
	0,			// dirStateSize
	NULL,		// device diropen_r
	NULL,		// device dirreset_r
	NULL,		// device dirnext_r
	NULL,		// device dirclose_r
	NULL		// device statvfs_r
};

void gecko_console_init(int chain) {
	dotab_console = NULL;
	if(chain)
		dotab_console = devoptab_list[STD_OUT];
	devoptab_list[STD_OUT] = &dotab_gecko;
	devoptab_list[STD_ERR] = &dotab_gecko;
}

#ifdef __cplusplus
}
#endif