Merge pull request #58 from psyke83/master
[picodrive.git] / platform / win32 / plat.c
CommitLineData
cff531af 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 */
823b9004 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
20static unsigned short screen_buff[320 * 240];
fcdefcf6 21const char *renderer_names[] = { NULL };
22const char *renderer_names32x[] = { NULL };
823b9004 23
823b9004 24void plat_init(void)
25{
26 g_screen_ptr = (void *)screen_buff;
27}
28
29int plat_is_dir(const char *path)
30{
31 return (GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0;
32}
33
34unsigned int plat_get_ticks_ms(void)
35{
36 return GetTickCount();
37}
38
39unsigned int plat_get_ticks_us(void)
40{
41 // XXX: maybe performance counters?
42 return GetTickCount() * 1000;
43}
44
45void plat_wait_till_us(unsigned int us)
46{
47 int msdiff = (int)(us - plat_get_ticks_us()) / 1000;
48 if (msdiff > 6)
ba86b61e 49 Sleep(msdiff - 6);
823b9004 50 while (plat_get_ticks_us() < us)
51 ;
52}
53
54void plat_sleep_ms(int ms)
55{
56 Sleep(ms);
57}
58
59int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
60{
61 return -1;
62}
63
64void pemu_prep_defconfig(void)
65{
66 memset(&defaultConfig, 0, sizeof(defaultConfig));
823b9004 67 defaultConfig.s_PicoCDBuffers = 0;
68 defaultConfig.Frameskip = 0;
69}
70
697746df 71void pemu_validate_config(void)
72{
73}
74
823b9004 75void pemu_loop_prep(void)
76{
5a681086 77 PicoDrawSetOutFormat(PDF_RGB555, 1);
78 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
823b9004 79 pemu_sound_start();
80}
81
82void pemu_loop_end(void)
83{
84 pemu_sound_stop();
85}
86
45285368 87void pemu_forced_frame(int no_scale, int do_emu)
823b9004 88{
89}
90
d08e7326 91void pemu_finalize_frame(const char *fps, const char *notice_msg)
92{
93}
94
95void plat_video_flip(void)
823b9004 96{
97 DirectScreen(g_screen_ptr);
98 DirectPresent();
99}
100
101void plat_video_wait_vsync(void)
102{
103}
104
5a681086 105void plat_video_toggle_renderer(int change, int is_menu)
823b9004 106{
107 // this will auto-select SMS/32X renderers
5a681086 108 PicoDrawSetOutFormat(PDF_RGB555, 1);
823b9004 109}
110
111void emu_video_mode_change(int start_line, int line_count, int is_32cols)
112{
113 EmuScreenRect.left = is_32cols ? 32 : 0;
114 EmuScreenRect.right = is_32cols ? 256+32 : 320;
115 EmuScreenRect.top = start_line;
116 EmuScreenRect.bottom = start_line + line_count;
117
118 PostMessage(FrameWnd, WM_COMMAND, 0x20000 | 2000, 0);
119}
120
121static int sndbuff[2*44100/50/2 + 4];
122
123static void update_sound(int len)
124{
125 /* avoid writing audio when lagging behind to prevent audio lag */
126 if (PicoSkipFrame != 2)
127 DSoundUpdate(sndbuff, (currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) ? 0 : 1);
128}
129
130void pemu_sound_start(void)
131{
132 int ret;
133
134 PsndOut = NULL;
135 currentConfig.EmuOpt &= ~EOPT_EXT_FRMLIMIT;
136
137 // prepare sound stuff
138 if (currentConfig.EmuOpt & EOPT_EN_SOUND)
139 {
140 PsndRerate(0);
141
142 ret = DSoundInit(FrameWnd, PsndRate, (PicoOpt & POPT_EN_STEREO) ? 1 : 0, PsndLen);
143 if (ret != 0) {
144 lprintf("dsound init failed\n");
145 return;
146 }
147
148 PsndOut = (void *)sndbuff;
149 PicoWriteSound = update_sound;
150 currentConfig.EmuOpt |= EOPT_EXT_FRMLIMIT;
151 }
152}
153
154void pemu_sound_stop(void)
155{
156 DSoundExit();
157}
158
159void pemu_sound_wait(void)
160{
161}
162
163int plat_get_root_dir(char *dst, int len)
164{
165 int ml;
166
167 ml = GetModuleFileName(NULL, dst, len);
168 while (ml > 0 && dst[ml] != '\\')
169 ml--;
170 if (ml != 0)
171 ml++;
172
173 dst[ml] = 0;
174 return ml;
175}
176
177void plat_status_msg_busy_first(const char *msg)
178{
179}
180
181void plat_status_msg_busy_next(const char *msg)
182{
183}
184
185void plat_status_msg_clear(void)
186{
187}
188
189void plat_video_menu_enter(int is_rom_loaded)
190{
191}
192
193void plat_video_menu_begin(void)
194{
195}
196
197void plat_video_menu_end(void)
198{
199}
200
823b9004 201void plat_update_volume(int has_changed, int is_up)
202{
203}
204
205const char *plat_get_credits(void)
206{
207 return "PicoDrive v" VERSION " minibeta (c) notaz, 2006-2009\n\n"
208 "Credits:\n"
209 "fDave: base code of PicoDrive\n"
210 "Chui: Fame/C\n"
211 "NJ: CZ80\n"
212 "MAME devs: YM2612, SN76496 and SH2 cores\n"
ba86b61e 213