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