Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/dreamcast/yui.c
2 views
1
/* Copyright 2003 Guillaume Duhamel
2
Copyright 2004-2010 Lawrence Sebald
3
4
This file is part of Yabause.
5
6
Yabause is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
11
Yabause is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with Yabause; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#include <stdio.h>
22
#include <time.h>
23
#include <arch/arch.h>
24
#include <dc/video.h>
25
#include <dc/biosfont.h>
26
#include <dc/maple.h>
27
#include <dc/maple/controller.h>
28
#include <kos/fs.h>
29
30
#include "../yui.h"
31
#include "../peripheral.h"
32
#include "../cs0.h"
33
#include "../m68kcore.h"
34
#include "../m68kc68k.h"
35
#include "perdc.h"
36
#include "viddc.h"
37
#include "sh2rec/sh2rec.h"
38
39
SH2Interface_struct *SH2CoreList[] = {
40
&SH2Interpreter,
41
&SH2Dynarec,
42
NULL
43
};
44
45
PerInterface_struct *PERCoreList[] = {
46
&PERDC,
47
NULL
48
};
49
50
CDInterface *CDCoreList[] = {
51
&ArchCD,
52
&DummyCD,
53
NULL
54
};
55
56
SoundInterface_struct *SNDCoreList[] = {
57
&SNDDummy,
58
NULL
59
};
60
61
VideoInterface_struct *VIDCoreList[] = {
62
&VIDDummy,
63
&VIDDC,
64
NULL
65
};
66
67
M68K_struct * M68KCoreList[] = {
68
&M68KDummy,
69
&M68KC68K,
70
#ifdef HAVE_Q68
71
&M68KQ68,
72
#endif
73
NULL
74
};
75
76
static const char *bios = "/ram/saturn.bin";
77
static int emulate_bios = 0;
78
79
int YuiInit(int sh2core) {
80
yabauseinit_struct yinit;
81
82
yinit.percoretype = PERCORE_DC;
83
yinit.sh2coretype = sh2core;
84
yinit.vidcoretype = VIDCORE_DC;
85
yinit.m68kcoretype = M68KCORE_C68K;
86
yinit.sndcoretype = SNDCORE_DUMMY;
87
yinit.cdcoretype = CDCORE_ARCH;
88
yinit.carttype = CART_NONE;
89
yinit.regionid = REGION_AUTODETECT;
90
yinit.biospath = emulate_bios ? NULL : bios;
91
yinit.cdpath = NULL;
92
yinit.buppath = NULL;
93
yinit.mpegpath = NULL;
94
yinit.cartpath = NULL;
95
yinit.frameskip = 0;
96
yinit.videoformattype = VIDEOFORMATTYPE_NTSC;
97
yinit.clocksync = 0;
98
yinit.basetime = 0;
99
100
if(YabauseInit(&yinit) != 0)
101
return -1;
102
103
for(;;) {
104
PERCore->HandleEvents();
105
}
106
107
return 0;
108
}
109
110
void YuiErrorMsg(const char *error_text) {
111
fprintf(stderr, "Error: %s\n", error_text);
112
arch_exit();
113
}
114
115
void YuiSwapBuffers(void) {
116
/* Nothing here. */
117
}
118
119
int DoGui() {
120
struct coord {
121
int x;
122
int y;
123
};
124
125
struct coord snowflakes[1024];
126
int i;
127
int offset;
128
int start_pressed = 0;
129
int phase = 0;
130
int core = SH2CORE_INTERPRETER;
131
132
srand(time(NULL));
133
134
for(i = 0; i < 1024; ++i) {
135
snowflakes[i].x = (rand() % 640);
136
snowflakes[i].y = -(rand() % 480);
137
}
138
139
while(!start_pressed) {
140
offset = 64 * 640 + 64; /* 64 pixels in from the left, 64 down */
141
142
bfont_draw_str(vram_s + offset, 640, 0, "Yabause " VERSION);
143
offset += 640 * 128;
144
145
if(phase == 0) {
146
FILE *fp;
147
148
fp = fopen("/cd/saturn.bin", "r");
149
if(fp) {
150
fclose(fp);
151
152
fs_copy("/cd/saturn.bin", bios);
153
phase = 1;
154
continue;
155
}
156
157
bfont_draw_str(vram_s + offset, 640, 0,
158
"Please insert a CD containing the Saturn BIOS");
159
offset += 640 * 24;
160
bfont_draw_str(vram_s + offset, 640, 0,
161
"on the root of the disc, named saturn.bin.");
162
offset += 640 * 48;
163
bfont_draw_str(vram_s + offset, 640, 0,
164
"Or, to use the BIOS emulation feature, insert");
165
offset += 640 * 24;
166
bfont_draw_str(vram_s + offset, 640, 0,
167
"a Sega Saturn CD and press Start.");
168
}
169
else {
170
bfont_draw_str(vram_s + offset, 640, 0,
171
"Please insert a Sega Saturn CD");
172
offset += 640 * 24;
173
bfont_draw_str(vram_s + offset, 640, 0, "and press start.");
174
}
175
176
for(i = 0; i < 1024; ++i) {
177
int dx = 1 - (rand() % 3);
178
179
if(snowflakes[i].y >= 0)
180
vram_s[640 * snowflakes[i].y + snowflakes[i].x] = 0x0000;
181
182
snowflakes[i].x += dx;
183
snowflakes[i].y += 1;
184
185
if(snowflakes[i].x < 0)
186
snowflakes[i].x = 639;
187
else if(snowflakes[i].x > 639)
188
snowflakes[i].x = 0;
189
190
if(snowflakes[i].y > 479)
191
snowflakes[i].y = 0;
192
193
if(snowflakes[i].y >= 0)
194
vram_s[640 * snowflakes[i].y + snowflakes[i].x] = 0xD555;
195
}
196
197
MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st)
198
if(st->buttons & CONT_START) {
199
if(phase == 0) {
200
emulate_bios = 1;
201
}
202
203
start_pressed = 1;
204
}
205
206
if(st->buttons & CONT_Y) {
207
core = SH2CORE_DYNAREC;
208
209
if(phase == 0) {
210
emulate_bios = 1;
211
}
212
213
start_pressed = 1;
214
}
215
MAPLE_FOREACH_END()
216
217
vid_waitvbl();
218
vid_flip(1);
219
}
220
221
return core;
222
}
223
224
int main(int argc, char *argv[]) {
225
int core;
226
227
printf("...\n");
228
229
bfont_set_encoding(BFONT_CODE_ISO8859_1);
230
core = DoGui();
231
YuiInit(core);
232
233
return 0;
234
}
235
236