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