minor drawing code cleanup
[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_PicoOpt|= POPT_6BTN_PAD; // for xmen proto
823b9004 68 defaultConfig.s_PicoCDBuffers = 0;
69 defaultConfig.Frameskip = 0;
70}
71
697746df 72void pemu_validate_config(void)
73{
74}
75
823b9004 76void pemu_loop_prep(void)
77{
5a681086 78 PicoDrawSetOutFormat(PDF_RGB555, 1);
79 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
823b9004 80 pemu_sound_start();
81}
82
83void pemu_loop_end(void)
84{
85 pemu_sound_stop();
86}
87
45285368 88void pemu_forced_frame(int no_scale, int do_emu)
823b9004 89{
90}
91
d08e7326 92void pemu_finalize_frame(const char *fps, const char *notice_msg)
93{
94}
95
96void plat_video_flip(void)
823b9004 97{
98 DirectScreen(g_screen_ptr);
99 DirectPresent();
100}
101
102void plat_video_wait_vsync(void)
103{
104}
105
5a681086 106void plat_video_toggle_renderer(int change, int is_menu)
823b9004 107{
108 // this will auto-select SMS/32X renderers
5a681086 109 PicoDrawSetOutFormat(PDF_RGB555, 1);
823b9004 110}
111
112void 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
122static int sndbuff[2*44100/50/2 + 4];
123
124static 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
131void 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
155void pemu_sound_stop(void)
156{
157 DSoundExit();
158}
159
160void pemu_sound_wait(void)
161{
162}
163
164int 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
178void plat_status_msg_busy_first(const char *msg)
179{
180}
181
182void plat_status_msg_busy_next(const char *msg)
183{
184}
185
186void plat_status_msg_clear(void)
187{
188}
189
190void plat_video_menu_enter(int is_rom_loaded)
191{
192}
193
194void plat_video_menu_begin(void)
195{
196}
197
198void plat_video_menu_end(void)
199{
200}
201
823b9004 202void plat_update_volume(int has_changed, int is_up)
203{
204}
205
206const 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"
ba86b61e 214