plat.c 4.8 KB

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