-
Notifications
You must be signed in to change notification settings - Fork 0
/
sioload.C
143 lines (116 loc) · 2.52 KB
/
sioload.C
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* sioloader.c by danhans42
simple sio loader - modded version of serial 1.3 by hitmen
*/
#define STACKP 0x801ffff0
#include <sys\types.h>
#include <libsn.h>
#include <libetc.h>
#include <libgte.h>
#include <libsio.h>
#include <kernel.h>
char read_sio (void);
void write_sio (char);
void init_sio (void);
void initt_sio (void);
void initu_sio (void);
u_long GetLongData(void);
void DispInit();
void sioload();
u_char header[2048];
static struct XF_HDR * head;
int id;
int i=0;
u_long sync;
u_long f_len;
u_long x_addr;
u_long count;
u_long padRead;
char * write_addr;
main()
{
PadInit(0);
DelSIO();
StopCallback();
DispInit();
FntPrint("\nSIOLOAD V1.0\n");
FntPrint("Videomode : ");
if (*(char *)0xbfc7ff52=='E')
FntPrint("PAL\n");
else
FntPrint("NTSC\n");
FntPrint("\n\n\n\n\n\n\n\n\n\n\n WAITING FOR CLIENT\n");
FntFlush(-1);
init_sio();
sioload();
}
char read_sio(void)
{
char c;
long sts;
sts = _sio_control(0,1,0);
_sio_control(1,1,sts|CR_RTS); /* RTS:on */
while(!(_sio_control(0,0,0)&SR_RXRDY));
c = _sio_control(0,4,0)&0xff;
sts = _sio_control(0,1,0);
_sio_control(1,1,sts&(~CR_RTS)); /* RTS:off */
return c;
}
void write_sio(char c)
{
while((_sio_control(0,0,0)&(SR_TXU|SR_TXRDY))!=(SR_TXU|SR_TXRDY));
_sio_control(1,4,c);
}
void init_sio(void)
{
_sio_control(1,2,MR_SB_01|MR_CHLEN_8|0x02); /* 8bit, no-parity, 1 stop-bit */
_sio_control(1,3,1036800);
_sio_control(1,1,CR_RXEN|CR_TXEN); /* RTS:off DTR:off */
}
u_long GetLongData(void)
{
u_long dat;
dat = (read_sio());
dat |= (read_sio()) <<8;
dat |= (read_sio()) <<16;
dat |= (read_sio()) << 24;
return (dat);
}
void DispInit() {
if (*(char *)0xbfc7ff52=='E')
SetVideoMode(MODE_PAL);
else
SetVideoMode(MODE_NTSC);
ResetGraph (0) ;
GsInitGraph(512,240,0,0,0);
GsDefDispBuff(0,0,0,240);
GsInit3D();
SetDispMask(1);
FntLoad (960,256);
SetDumpFnt(id = FntOpen(0,0,512,240,1,1024));
}
void sioload() {
PadStop();
while (sync != 99){
sync = read_sio();
}
FntPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n Receiving Data..\n");
FntFlush(-1);
for (i=0;i<2048;i++){
header[i] = read_sio();
}
x_addr = GetLongData();
write_addr =(char *) GetLongData();
f_len = GetLongData();
for (count=0;count<f_len;count++){
*write_addr = read_sio();
write_addr++;
}
PadStop();
ResetGraph(3);
StopCallback();
head = (struct XF_HDR *)header;
head->exec.s_addr = STACKP;
head->exec.s_size = 0;
EnterCriticalSection();
Exec(&(head->exec),1,0);
}