aa3a7f2136fbff4ff626432cea8a66b79e446340
[picodrive.git] / platform / win32 / plat.c
1 /*
2  * PicoDrive
3  * (C) notaz, 2009,2010
4  *
5  * This work is licensed under the terms of MAME license.
6  * See COPYING file in the top-level directory.
7  */
8 #include <windows.h>
9 #include <stdio.h>
10
11 #include "../common/lprintf.h"
12 #include "../common/plat.h"
13 #include "../common/emu.h"
14 #include "../../pico/pico.h"
15 #include "version.h"
16 #include "direct.h"
17 #include "dsnd.h"
18 #include "main.h"
19
20 static unsigned short screen_buff[320 * 240];
21 const char *renderer_names[] = { NULL };
22 const char *renderer_names32x[] = { NULL };
23
24 void plat_init(void)
25 {
26         g_screen_ptr = (void *)screen_buff;
27 }
28
29 int plat_is_dir(const char *path)
30 {
31         return (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0;
32 }
33
34 unsigned int plat_get_ticks_ms(void)
35 {
36         return GetTickCount();
37 }
38
39 unsigned int plat_get_ticks_us(void)
40 {
41         // XXX: maybe performance counters?
42         return GetTickCount() * 1000;
43 }
44
45 void plat_wait_till_us(unsigned int us)
46 {
47         int msdiff = (int)(us - plat_get_ticks_us()) / 1000;
48         if (msdiff > 6)
49                 Sleep(msdiff - 6);
50         while (plat_get_ticks_us() < us)
51                 ;
52 }
53
54 void plat_sleep_ms(int ms)
55 {
56         Sleep(ms);
57 }
58
59 int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
60 {
61         return -1;
62 }
63
64 void pemu_prep_defconfig(void)
65 {
66         memset(&defaultConfig, 0, sizeof(defaultConfig));
67         defaultConfig.s_PicoOpt|= POPT_6BTN_PAD; // for xmen proto
68         defaultConfig.s_PicoCDBuffers = 0;
69         defaultConfig.Frameskip = 0;
70 }
71
72 void pemu_validate_config(void)
73 {
74 }
75
76 void pemu_loop_prep(void)
77 {
78         PicoDrawSetOutFormat(PDF_RGB555, 1);
79         PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
80         pemu_sound_start();
81 }
82
83 void pemu_loop_end(void)
84 {
85         pemu_sound_stop();
86 }
87
88 void pemu_forced_frame(int no_scale, int do_emu)
89 {
90 }
91
92 void pemu_finalize_frame(const char *fps, const char *notice_msg)
93 {
94 }
95
96 void plat_video_flip(void)
97 {
98         DirectScreen(g_screen_ptr);
99         DirectPresent();
100 }
101
102 void plat_video_wait_vsync(void)
103 {
104 }
105
106 void plat_video_toggle_renderer(int change, int is_menu)
107 {
108         // this will auto-select SMS/32X renderers
109         PicoDrawSetOutFormat(PDF_RGB555, 1);
110 }
111
112 void emu_video_mode_change(int start_line, int line_count, int is_32cols)
113 {
114         EmuScreenRect.left = is_32cols ? 32 : 0;
115         EmuScreenRect.right = is_32cols ? 256+32 : 320;
116         EmuScreenRect.top = start_line;
117         EmuScreenRect.bottom = start_line + line_count;
118
119         PostMessage(FrameWnd, WM_COMMAND, 0x20000 | 2000, 0);
120 }
121
122 static int sndbuff[2*44100/50/2 + 4];
123
124 static void update_sound(int len)
125 {
126         /* avoid writing audio when lagging behind to prevent audio lag */
127         if (PicoSkipFrame != 2)
128                 DSoundUpdate(sndbuff, (currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) ? 0 : 1);
129 }
130
131 void pemu_sound_start(void)
132 {
133         int ret;
134
135         PsndOut = NULL;
136         currentConfig.EmuOpt &= ~EOPT_EXT_FRMLIMIT;
137
138         // prepare sound stuff
139         if (currentConfig.EmuOpt & EOPT_EN_SOUND)
140         {
141                 PsndRerate(0);
142
143                 ret = DSoundInit(FrameWnd, PsndRate, (PicoOpt & POPT_EN_STEREO) ? 1 : 0, PsndLen);
144                 if (ret != 0) {
145                         lprintf("dsound init failed\n");
146                         return;
147                 }
148
149                 PsndOut = (void *)sndbuff;
150                 PicoWriteSound = update_sound;
151                 currentConfig.EmuOpt |= EOPT_EXT_FRMLIMIT;
152         }
153 }
154
155 void pemu_sound_stop(void)
156 {
157         DSoundExit();
158 }
159
160 void pemu_sound_wait(void)
161 {
162 }
163
164 int plat_get_root_dir(char *dst, int len)
165 {
166         int ml;
167
168         ml = GetModuleFileName(NULL, dst, len);
169         while (ml > 0 && dst[ml] != '\\')
170                 ml--;
171         if (ml != 0)
172                 ml++;
173
174         dst[ml] = 0;
175         return ml;
176 }
177
178 void plat_status_msg_busy_first(const char *msg)
179 {
180 }
181
182 void plat_status_msg_busy_next(const char *msg)
183 {
184 }
185
186 void plat_status_msg_clear(void)
187 {
188 }
189
190 void plat_video_menu_enter(int is_rom_loaded)
191 {
192 }
193
194 void plat_video_menu_begin(void)
195 {
196 }
197
198 void plat_video_menu_end(void)
199 {
200 }
201
202 void plat_update_volume(int has_changed, int is_up)
203 {
204 }
205
206 const char *plat_get_credits(void)
207 {
208         return "PicoDrive v" VERSION " minibeta (c) notaz, 2006-2009\n\n"
209                 "Credits:\n"
210                 "fDave: base code of PicoDrive\n"
211                 "Chui: Fame/C\n"
212                 "NJ: CZ80\n"
213                 "MAME devs: YM2612, SN76496 and SH2 cores\n"
214                 "Stéphane Dallongeville: base of Fame/C (C68K), CZ80\n\n"
215                 "Special thanks (ideas, valuable information and stuff):\n"
216                 "Charles MacDonald, Eke, Exophase, Haze, Lordus, Nemesis,\n"
217                 "Pierpaolo Prazzoli, Rokas, Steve Snake, Tasco Deluxe.\n";
218 }
219
220 void plat_debug_cat(char *str)
221 {
222 }
223
224 // required by pico
225 int mp3_get_bitrate(void *f, int size)
226 {
227         return 128;
228 }
229
230 void mp3_start_play(void *f, int pos)
231 {
232 }
233
234 void mp3_update(int *buffer, int length, int stereo)
235 {
236 }
237
238 // other
239 void lprintf(const char *fmt, ...)
240 {
241   char buf[512];
242   va_list val;
243
244   va_start(val, fmt);
245   vsnprintf(buf, sizeof(buf), fmt, val);
246   va_end(val);
247   OutputDebugString(buf);
248   printf("%s", buf);
249 }
250
251 // fake
252 int alphasort() { return 0; }
253 int scandir() { return 0; }
254