-
Notifications
You must be signed in to change notification settings - Fork 1
/
vgs2i.c
214 lines (193 loc) · 4.38 KB
/
vgs2i.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* (C)2015, SUZUKI PLAN.
*----------------------------------------------------------------------------
* Description: VGS mk-II SR - emulator
* Platform: iOS
* Author: Yoji Suzuki (SUZUKI PLAN)
*----------------------------------------------------------------------------
*/
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "vgs2.h"
/*
*-----------------------------------------------------------------------------
* Variables
*-----------------------------------------------------------------------------
*/
unsigned short ADPAL[256];
static char pathbuf[4096];
int isIphone5;
/*
*-----------------------------------------------------------------------------
* Initialize procedure of VGS
*-----------------------------------------------------------------------------
*/
int vgsint_init(const char* rompath)
{
char log[1024];
static char* rom=NULL;
char* bin;
FILE* fp;
int fsize;
int i,j,size;
int cn,pn,bn;
unsigned char s[4];
char path[80];
struct stat stbuf;
/* initialize mutex */
pthread_mutex_init(&sndLock,NULL);
/* get rom file size */
stat(rompath,&stbuf);
fsize=(int)stbuf.st_size;
/* open */
fp=fopen(rompath,"rb");
if(NULL==fp) {
return -1;
}
/* allocate buffer */
rom=(char*)malloc(fsize);
if(NULL==rom) {
fclose(fp);
return -1;
}
/* read */
fread(rom,fsize,1,fp);
fclose(fp);
bin=rom;
/* get the records number */
memcpy(&BN,bin,4);
bin+=4;
/* get records buffer */
BR=(struct _BINREC*)malloc(BN*sizeof(struct _BINREC));
if(NULL==BR) {
return -1;
}
memset(BR,0,BN*sizeof(struct _BINREC));
/* set record name */
for(i=0;i<BN;i++) {
memset(BR[i].name,0,16);
memcpy(BR[i].name,bin,16);
bin+=16;
for(j=0;'\0'!=BR[i].name[j];j++) {
if(15==j) {
return -1;
}
BR[i].name[j]^=0xAA;
}
}
/* set record buffer */
for(i=0;i<BN;i++) {
memcpy(s,bin,4);
bin+=4;
size=s[0];
size<<=8;
size|=s[1];
size<<=8;
size|=s[2];
size<<=8;
size|=s[3];
BR[i].size=size;
BR[i].data=(char*)malloc(BR[i].size);
if(NULL==BR[i].data) {
return -1;
}
memcpy(BR[i].data,bin,BR[i].size);
bin+=BR[i].size;
}
/* load to slot */
cn=0;
pn=0;
bn=0;
for(i=0;i<256;i++) {
sprintf(path,"GSLOT%03d.CHR",i);
if(0==gload(i,path)) cn++;
sprintf(path,"ESLOT%03d.PCM",i);
if(0==eload(i,path)) pn++;
sprintf(path,"BSLOT%03d.BGM",i);
if(0==bload(i,path)) bn++;
}
sprintf(log,"Data has extracted. (CHR=%d, PCM=%d, BGM=%d)",cn,pn,bn);
puts(log);
/* initialize UP */
vgs2_pallet(7);
if(0!=vgs2_init()) {
return -1;
}
/* create 16bit color palette */
make_pallet();
/* initialize OpenAL */
if(0!=init_sound()) {
return -1;
}
return 0;
}
/*
*----------------------------------------------------------------------------
* make 16bit pallet table (24bit -> 15bit/5:5:5)
*----------------------------------------------------------------------------
*/
void make_pallet()
{
int i,j;
int r,g,b;
for(j=0,i=0;i<256;i++) {
r=(_PAL[i]&0x00FF0000)>>16;
g=(_PAL[i]&0x0000FF00)>>8;
b=(_PAL[i]&0x000000FF);
r&=0xF8;
r>>=3;
g&=0xFC;
g>>=3;
b&=0xF8;
b>>=3;
ADPAL[i]=r;
ADPAL[i]<<=5;
ADPAL[i]|=g;
ADPAL[i]<<=5;
ADPAL[i]|=b;
}
ADPAL[0]=0x5;
}
/*
*-----------------------------------------------------------------------------
* set data directory
*-----------------------------------------------------------------------------
*/
void vgsint_setdir(const char* dir)
{
strcpy(pathbuf,dir);
strcat(pathbuf,"/");
}
/*
*-----------------------------------------------------------------------------
* fopen
*-----------------------------------------------------------------------------
*/
FILE* vgs2_fopen(const char* fname,const char* mode)
{
char path[4096];
strcpy(path,pathbuf);
strcat(path,fname);
return fopen(path,mode);
}
/*
*-----------------------------------------------------------------------------
* delete ads (*no operation)
*-----------------------------------------------------------------------------
*/
void vgs2_deleteAds()
{
;
}
/*
*-----------------------------------------------------------------------------
* show ads (*no operation)
*-----------------------------------------------------------------------------
*/
void vgs2_showAds()
{
;
}