emu.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * PicoDrive
  3. * (C) notaz, 2006-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 <stdio.h>
  9. #include <unistd.h>
  10. #include "../libpicofe/menu.h"
  11. #include "../libpicofe/plat.h"
  12. #include "../common/emu.h"
  13. #include "../common/arm_utils.h"
  14. #include "../common/version.h"
  15. #include <pico/pico_int.h>
  16. const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };
  17. const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };
  18. enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
  19. void pemu_prep_defconfig(void)
  20. {
  21. }
  22. void pemu_validate_config(void)
  23. {
  24. #if !defined(__arm__) && !defined(__i386__) && !defined(__x86_64__)
  25. PicoIn.opt &= ~POPT_EN_DRC;
  26. #endif
  27. }
  28. static void draw_cd_leds(void)
  29. {
  30. int led_reg, pitch, scr_offs, led_offs;
  31. led_reg = Pico_mcd->s68k_regs[0];
  32. pitch = 320;
  33. led_offs = 4;
  34. scr_offs = pitch * 2 + 4;
  35. if (currentConfig.renderer != RT_16BIT) {
  36. #define p(x) px[(x) >> 2]
  37. // 8-bit modes
  38. unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);
  39. unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;
  40. unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;
  41. p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
  42. p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
  43. #undef p
  44. } else {
  45. #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]
  46. // 16-bit modes
  47. unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);
  48. unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;
  49. unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;
  50. p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
  51. p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
  52. #undef p
  53. }
  54. }
  55. void pemu_finalize_frame(const char *fps, const char *notice)
  56. {
  57. if (currentConfig.renderer != RT_16BIT && !(PicoIn.AHW & PAHW_32X)) {
  58. unsigned short *pd = (unsigned short *)g_screen_ptr + 8 * g_screen_width;
  59. unsigned char *ps = Pico.est.Draw2FB + 328*8 + 8;
  60. unsigned short *pal = Pico.est.HighPal;
  61. int i, x;
  62. if (Pico.m.dirtyPal)
  63. PicoDrawUpdateHighPal();
  64. for (i = 0; i < 224; i++, ps += 8)
  65. for (x = 0; x < 320; x++)
  66. *pd++ = pal[*ps++];
  67. }
  68. if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) {
  69. if (notice)
  70. emu_osd_text16(4, g_screen_height - 8, notice);
  71. if (currentConfig.EmuOpt & EOPT_SHOW_FPS)
  72. emu_osd_text16(g_screen_width - 60, g_screen_height - 8, fps);
  73. }
  74. if ((PicoIn.AHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))
  75. draw_cd_leds();
  76. }
  77. static void apply_renderer(void)
  78. {
  79. switch (currentConfig.renderer) {
  80. case RT_16BIT:
  81. PicoIn.opt &= ~POPT_ALT_RENDERER;
  82. PicoDrawSetOutFormat(PDF_RGB555, 0);
  83. PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
  84. break;
  85. case RT_8BIT_ACC:
  86. PicoIn.opt &= ~POPT_ALT_RENDERER;
  87. PicoDrawSetOutFormat(PDF_8BIT, 0);
  88. PicoDrawSetOutBuf(Pico.est.Draw2FB + 8, 328);
  89. break;
  90. case RT_8BIT_FAST:
  91. PicoIn.opt |= POPT_ALT_RENDERER;
  92. PicoDrawSetOutFormat(PDF_NONE, 0);
  93. break;
  94. }
  95. if (PicoIn.AHW & PAHW_32X)
  96. PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
  97. }
  98. void plat_video_toggle_renderer(int change, int is_menu)
  99. {
  100. currentConfig.renderer += change;
  101. if (currentConfig.renderer >= RT_COUNT)
  102. currentConfig.renderer = 0;
  103. else if (currentConfig.renderer < 0)
  104. currentConfig.renderer = RT_COUNT - 1;
  105. if (!is_menu)
  106. apply_renderer();
  107. emu_status_msg(renderer_names[currentConfig.renderer]);
  108. }
  109. void plat_status_msg_clear(void)
  110. {
  111. unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_width * g_screen_height;
  112. int l = g_screen_width * 8;
  113. memset32((int *)(d - l), 0, l * 2 / 4);
  114. }
  115. void plat_status_msg_busy_next(const char *msg)
  116. {
  117. plat_status_msg_clear();
  118. pemu_finalize_frame("", msg);
  119. plat_video_flip();
  120. emu_status_msg("");
  121. reset_timing = 1;
  122. }
  123. void plat_status_msg_busy_first(const char *msg)
  124. {
  125. // memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
  126. plat_status_msg_busy_next(msg);
  127. }
  128. void plat_update_volume(int has_changed, int is_up)
  129. {
  130. }
  131. void pemu_forced_frame(int no_scale, int do_emu)
  132. {
  133. PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
  134. PicoDrawSetCallbacks(NULL, NULL);
  135. Pico.m.dirtyPal = 1;
  136. emu_cmn_forced_frame(no_scale, do_emu);
  137. g_menubg_src_ptr = g_screen_ptr;
  138. }
  139. void pemu_sound_start(void)
  140. {
  141. emu_sound_start();
  142. }
  143. void plat_debug_cat(char *str)
  144. {
  145. }
  146. void emu_video_mode_change(int start_line, int line_count, int is_32cols)
  147. {
  148. // clear whole screen in all buffers
  149. memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
  150. }
  151. void pemu_loop_prep(void)
  152. {
  153. apply_renderer();
  154. }
  155. void pemu_loop_end(void)
  156. {
  157. /* do one more frame for menu bg */
  158. pemu_forced_frame(0, 1);
  159. }
  160. void plat_wait_till_us(unsigned int us_to)
  161. {
  162. unsigned int now;
  163. now = plat_get_ticks_us();
  164. while ((signed int)(us_to - now) > 512)
  165. {
  166. usleep(1024);
  167. now = plat_get_ticks_us();
  168. }
  169. }
  170. void *plat_mem_get_for_drc(size_t size)
  171. {
  172. return NULL;
  173. }