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
YuiInit(int sh2core)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 yinit.skip_load = 0;
100
101 if(YabauseInit(&yinit) != 0)
102 return -1;
103
104 for(;;) {
105 PERCore->HandleEvents();
106 }
107
108 return 0;
109 }
110
YuiErrorMsg(const char * error_text)111 void YuiErrorMsg(const char *error_text) {
112 fprintf(stderr, "Error: %s\n", error_text);
113 arch_exit();
114 }
115
YuiSwapBuffers(void)116 void YuiSwapBuffers(void) {
117 /* Nothing here. */
118 }
119
DoGui()120 int DoGui() {
121 struct coord {
122 int x;
123 int y;
124 };
125
126 struct coord snowflakes[1024];
127 int i;
128 int offset;
129 int start_pressed = 0;
130 int phase = 0;
131 int core = SH2CORE_INTERPRETER;
132
133 srand(time(NULL));
134
135 for(i = 0; i < 1024; ++i) {
136 snowflakes[i].x = (rand() % 640);
137 snowflakes[i].y = -(rand() % 480);
138 }
139
140 while(!start_pressed) {
141 offset = 64 * 640 + 64; /* 64 pixels in from the left, 64 down */
142
143 bfont_draw_str(vram_s + offset, 640, 0, "Yabause " VERSION);
144 offset += 640 * 128;
145
146 if(phase == 0) {
147 FILE *fp;
148
149 fp = fopen("/cd/saturn.bin", "r");
150 if(fp) {
151 fclose(fp);
152
153 fs_copy("/cd/saturn.bin", bios);
154 phase = 1;
155 continue;
156 }
157
158 bfont_draw_str(vram_s + offset, 640, 0,
159 "Please insert a CD containing the Saturn BIOS");
160 offset += 640 * 24;
161 bfont_draw_str(vram_s + offset, 640, 0,
162 "on the root of the disc, named saturn.bin.");
163 offset += 640 * 48;
164 bfont_draw_str(vram_s + offset, 640, 0,
165 "Or, to use the BIOS emulation feature, insert");
166 offset += 640 * 24;
167 bfont_draw_str(vram_s + offset, 640, 0,
168 "a Sega Saturn CD and press Start.");
169 }
170 else {
171 bfont_draw_str(vram_s + offset, 640, 0,
172 "Please insert a Sega Saturn CD");
173 offset += 640 * 24;
174 bfont_draw_str(vram_s + offset, 640, 0, "and press start.");
175 }
176
177 for(i = 0; i < 1024; ++i) {
178 int dx = 1 - (rand() % 3);
179
180 if(snowflakes[i].y >= 0)
181 vram_s[640 * snowflakes[i].y + snowflakes[i].x] = 0x0000;
182
183 snowflakes[i].x += dx;
184 snowflakes[i].y += 1;
185
186 if(snowflakes[i].x < 0)
187 snowflakes[i].x = 639;
188 else if(snowflakes[i].x > 639)
189 snowflakes[i].x = 0;
190
191 if(snowflakes[i].y > 479)
192 snowflakes[i].y = 0;
193
194 if(snowflakes[i].y >= 0)
195 vram_s[640 * snowflakes[i].y + snowflakes[i].x] = 0xD555;
196 }
197
198 MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st)
199 if(st->buttons & CONT_START) {
200 if(phase == 0) {
201 emulate_bios = 1;
202 }
203
204 start_pressed = 1;
205 }
206
207 if(st->buttons & CONT_Y) {
208 core = SH2CORE_DYNAREC;
209
210 if(phase == 0) {
211 emulate_bios = 1;
212 }
213
214 start_pressed = 1;
215 }
216 MAPLE_FOREACH_END()
217
218 vid_waitvbl();
219 vid_flip(1);
220 }
221
222 return core;
223 }
224
main(int argc,char * argv[])225 int main(int argc, char *argv[]) {
226 int core;
227
228 printf("...\n");
229
230 bfont_set_encoding(BFONT_CODE_ISO8859_1);
231 core = DoGui();
232 YuiInit(core);
233
234 return 0;
235 }
236