emu.c 5.1 KB

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