gl.c
3.01 KB
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
144
145
#include <stdlib.h>
#ifdef WIN32
#define DEV_U64_DATA "PARTNER-N64"
#include <direct.h>
#else
#include <sys/u64gio.h>
#include <unistd.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <ultrahost.h>
#include <dirent.h>
static void usage(void)
{
fprintf(stderr, "gload for PARTNER Ver.0.10 1998 (C) Nintendo Co.,Ltd.\n");
fprintf(stderr, "usage: gl <romfile>\n");
}
int fd;
int main(int argc, char **argv)
{
unsigned char fname[128];
unsigned char cmd[256];
unsigned char buf[256];
unsigned char path[128];
unsigned char tmpfile[128];
unsigned char *p;
int flag = 0;
FILE *fp1, *fp2;
DIR *dp;
struct dirent *entry;
if (argc == 1) {
dp = opendir(".");
while ((entry = readdir(dp))!=NULL) {
if (strcmp(entry->d_name, "gwrite")==0 ||
strcmp(entry->d_name, "GWRITE")==0) {
flag = 2;
break;
}
}
if (flag == 0 ){
rewinddir(dp);
while ((entry = readdir(dp))!=NULL) {
if (strcmp(entry->d_name, "rom")==0) {
flag = 1;
strcpy(fname, "rom");
break;
}
}
if (flag == 0 ){
rewinddir(dp);
while ((entry = readdir(dp))!=NULL) {
if (strstr(entry->d_name, ".n64")!=NULL ||
strstr(entry->d_name, ".N64")!=NULL){
flag = 1;
strcpy(fname, entry->d_name);
break;
}
}
}
}
closedir(dp);
if (flag == 0) {
usage();
return(1);
}
} else if (argc != 2) {
usage();
return (2);
} else {
strcpy(fname, argv[1]);
}
strcpy(cmd, "esc\n");
#ifdef PARTNER_OLD_VERSION
getcwd(path, sizeof(path));
strcat(cmd, "cd ");
strcat(cmd, path);
strcat(cmd, "\n");
#endif
if ((fd = uhOpenGame(DEV_U64_DATA)) == -1) {
fprintf(stderr, "gl: Unable to open %s : %s\n",
DEV_U64_DATA, sys_errlist[errno]);
return(3);
}
if (flag == 2) {
getcwd(path, sizeof(path));
if (path[0]!=NULL && path[strlen(path)-1] != '/') {
strcat(path, "/");
}
tmpfile[0]=NULL;
if (getenv("TEMP") != NULL ) {
strcpy(tmpfile, getenv("TEMP"));
} else if (getenv("TMP") != NULL ) {
strcpy(tmpfile, getenv("TMP"));
} else {
strcpy(tmpfile, path);
}
if (tmpfile[0]!=NULL && tmpfile[strlen(tmpfile)-1] != '/') {
strcat(tmpfile, "/");
}
strcat(tmpfile, "tmpgw");
if ((fp1 = fopen("gwrite", "r")) == NULL) {
fprintf(stderr, "gl: cannot open gwrite!\n");
return(-1);
}
if ((fp2 = fopen(tmpfile, "w")) == NULL) {
fprintf(stderr, "gl: cannot open temporary gwrite!\n");
return(-1);
}
while (fgets(buf, sizeof(buf), fp1)) {
p = strrchr(buf, ' ');
if (*(p+1) != '/') {
strcpy(fname, p+1);
*(p+1) = '\0';
strcat(buf, path);
strcat(buf, fname);
}
fputs(buf, fp2);
}
fclose(fp1);
fclose(fp2);
strcat(cmd,"<");
strcat(cmd, tmpfile);
strcat(cmd,"\nresetdd\ng\n");
uhPartnerCmd(fd, cmd);
} else {
if (uhGload(fd, fname) != 0) {
fprintf(stderr, "gl: gload failed\n");
return(4);
}
}
return(0);
}