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