plat.c 4.4 KB

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