X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Flinux%2Femu.c;h=c470a7717b3cc4c3a85e7393b5bd2a461ab1e00a;hb=898d51a7fd1c090799ac88869fa0daf096fd702f;hp=aa5185f51e323c2612a335e87931529a2c590fdf;hpb=697746df021a83dcb556afdb36abc6977780985c;p=picodrive.git diff --git a/platform/linux/emu.c b/platform/linux/emu.c index aa5185f..c470a77 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -1,74 +1,37 @@ -// (c) Copyright 2006-2009 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. +/* + * PicoDrive + * (C) notaz, 2006-2010 + * + * This work is licensed under the terms of MAME license. + * See COPYING file in the top-level directory. + */ #include #include +#include "../libpicofe/menu.h" +#include "../libpicofe/plat.h" #include "../common/emu.h" -#include "../common/menu.h" -#include "../common/plat.h" #include "../common/arm_utils.h" -#include "../linux/sndout_oss.h" -#include "version.h" +#include "../common/version.h" #include -static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; -unsigned char temp_frame[320 * 240 * 2]; -unsigned char *PicoDraw2FB = temp_frame; -static int osd_fps_x; -char cpu_clk_name[] = "unused"; - -extern void update_screen(void); +const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; +const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL }; +enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT }; void pemu_prep_defconfig(void) { - // XXX: move elsewhere - g_menubg_ptr = temp_frame; } void pemu_validate_config(void) { - extern int PicoOpt; -// PicoOpt &= ~POPT_EXT_FM; - PicoOpt &= ~POPT_EN_SVP_DRC; -} - -// FIXME: dupes from GP2X, need cleanup -static void (*osd_text)(int x, int y, const char *text); - -static void osd_text8(int x, int y, const char *text) -{ - int len = strlen(text)*8; - int *p, i, h, offs; - - len = (len+3) >> 2; - for (h = 0; h < 8; h++) { - offs = (x + g_screen_width * (y+h)) & ~3; - p = (int *) ((char *)g_screen_ptr + offs); - for (i = len; i; i--, p++) - *p = 0xe0e0e0e0; - } - emu_text_out8(x, y, text); -} - -static void osd_text16(int x, int y, const char *text) -{ - int len = strlen(text)*8; - int *p, i, h, offs; - - len = (len+1) >> 1; - for (h = 0; h < 8; h++) { - offs = (x + g_screen_width * (y+h)) & ~1; - p = (int *) ((short *)g_screen_ptr + offs); - for (i = len; i; i--, p++) - *p = (*p >> 2) & 0x39e7; - } - emu_text_out16(x, y, text); +#if !defined(__arm__) && !defined(__i386__) && !defined(__x86_64__) + PicoIn.opt &= ~POPT_EN_DRC; +#endif } static void draw_cd_leds(void) @@ -80,7 +43,7 @@ static void draw_cd_leds(void) led_offs = 4; scr_offs = pitch * 2 + 4; - if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) { + if (currentConfig.renderer != RT_16BIT) { #define p(x) px[(x) >> 2] // 8-bit modes unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs); @@ -101,45 +64,65 @@ static void draw_cd_leds(void) } } -static int EmuScanBegin16(unsigned int num) +void pemu_finalize_frame(const char *fps, const char *notice) { - DrawLineDest = (unsigned short *)g_screen_ptr + num * g_screen_width; - - return 0; -} + if (currentConfig.renderer != RT_16BIT && !(PicoIn.AHW & PAHW_32X)) { + unsigned short *pd = (unsigned short *)g_screen_ptr + 8 * g_screen_width; + unsigned char *ps = Pico.est.Draw2FB + 328*8 + 8; + unsigned short *pal = Pico.est.HighPal; + int i, x; + if (Pico.m.dirtyPal) + PicoDrawUpdateHighPal(); + for (i = 0; i < 224; i++, ps += 8) + for (x = 0; x < 320; x++) + *pd++ = pal[*ps++]; + } -void pemu_update_display(const char *fps, const char *notice) -{ if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) { if (notice) - osd_text(4, g_screen_height - 8, notice); + emu_osd_text16(4, g_screen_height - 8, notice); if (currentConfig.EmuOpt & EOPT_SHOW_FPS) - osd_text(osd_fps_x, g_screen_height - 8, fps); + emu_osd_text16(g_screen_width - 60, g_screen_height - 8, fps); } - if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS)) + if ((PicoIn.AHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS)) draw_cd_leds(); - - update_screen(); } -void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu) -{ - // this will auto-select SMS/32X renderers - PicoDrawSetColorFormat(1); -} +static void apply_renderer(void) +{ + switch (currentConfig.renderer) { + case RT_16BIT: + PicoIn.opt &= ~POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_RGB555, 0); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); + break; + case RT_8BIT_ACC: + PicoIn.opt &= ~POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_8BIT, 0); + PicoDrawSetOutBuf(Pico.est.Draw2FB + 8, 328); + break; + case RT_8BIT_FAST: + PicoIn.opt |= POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_NONE, 0); + break; + } -void plat_video_menu_enter(int is_rom_loaded) -{ + if (PicoIn.AHW & PAHW_32X) + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); } -void plat_video_menu_begin(void) +void plat_video_toggle_renderer(int change, int is_menu) { - memcpy32(g_screen_ptr, g_menubg_ptr, g_screen_width * g_screen_height * 2 / 4); -} + currentConfig.renderer += change; + if (currentConfig.renderer >= RT_COUNT) + currentConfig.renderer = 0; + else if (currentConfig.renderer < 0) + currentConfig.renderer = RT_COUNT - 1; -void plat_video_menu_end(void) -{ - update_screen(); + if (!is_menu) + apply_renderer(); + + emu_status_msg(renderer_names[currentConfig.renderer]); } void plat_status_msg_clear(void) @@ -152,7 +135,8 @@ void plat_status_msg_clear(void) void plat_status_msg_busy_next(const char *msg) { plat_status_msg_clear(); - pemu_update_display("", msg); + pemu_finalize_frame("", msg); + plat_video_flip(); emu_status_msg(""); reset_timing = 1; } @@ -167,74 +151,20 @@ void plat_update_volume(int has_changed, int is_up) { } -void pemu_forced_frame(int opts) +void pemu_forced_frame(int no_scale, int do_emu) { - int po_old = PicoOpt; - int eo_old = currentConfig.EmuOpt; - - PicoOpt &= ~POPT_ALT_RENDERER; - PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites - currentConfig.EmuOpt |= EOPT_16BPP; - - PicoDrawSetColorFormat(1); - PicoScanBegin = EmuScanBegin16; - + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); + PicoDrawSetCallbacks(NULL, NULL); Pico.m.dirtyPal = 1; - PicoFrameDrawOnly(); - PicoOpt = po_old; - currentConfig.EmuOpt = eo_old; -} - -static void updateSound(int len) -{ - len <<= 1; - if (PicoOpt & POPT_EN_STEREO) - len <<= 1; - - if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len)) - return; + emu_cmn_forced_frame(no_scale, do_emu); - /* avoid writing audio when lagging behind to prevent audio lag */ - if (PicoSkipFrame != 2) - sndout_oss_write(PsndOut, len); + g_menubg_src_ptr = g_screen_ptr; } void pemu_sound_start(void) { - static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0; - int target_fps = Pico.m.pal ? 50 : 60; - - PsndOut = NULL; - - if (currentConfig.EmuOpt & EOPT_EN_SOUND) - { - int snd_excess_add; - if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old) - PsndRerate(Pico.m.frame_count ? 1 : 0); - - snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps; - printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", - PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); - sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3); - sndout_oss_setvol(currentConfig.volume, currentConfig.volume); - PicoWriteSound = updateSound; - plat_update_volume(0, 0); - memset(sndBuffer, 0, sizeof(sndBuffer)); - PsndOut = sndBuffer; - PsndRate_old = PsndRate; - PicoOpt_old = PicoOpt; - pal_old = Pico.m.pal; - } -} - -void pemu_sound_stop(void) -{ -} - -void pemu_sound_wait(void) -{ - // don't need to do anything, writes will block by themselves + emu_sound_start(); } void plat_debug_cat(char *str) @@ -243,40 +173,19 @@ void plat_debug_cat(char *str) void emu_video_mode_change(int start_line, int line_count, int is_32cols) { - osd_fps_x = 260; - // clear whole screen in all buffers memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4); } void pemu_loop_prep(void) { - PicoDrawSetColorFormat(1); - PicoScanBegin = EmuScanBegin16; - osd_text = osd_text16; - - pemu_sound_start(); + apply_renderer(); } void pemu_loop_end(void) { - int po_old = PicoOpt; - int eo_old = currentConfig.EmuOpt; - - pemu_sound_stop(); - memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4); - /* do one more frame for menu bg */ - PicoOpt &= ~POPT_ALT_RENDERER; - PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES; - currentConfig.EmuOpt |= EOPT_16BPP; - - PicoDrawSetColorFormat(1); - Pico.m.dirtyPal = 1; - PicoFrame(); - - PicoOpt = po_old; - currentConfig.EmuOpt = eo_old; + pemu_forced_frame(0, 1); } void plat_wait_till_us(unsigned int us_to) @@ -292,28 +201,7 @@ void plat_wait_till_us(unsigned int us_to) } } -void plat_video_wait_vsync(void) -{ -} - -const char *plat_get_credits(void) +void *plat_mem_get_for_drc(size_t size) { - return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n" - "Credits:\n" - "fDave: Cyclone 68000 core,\n" - " base code of PicoDrive\n" - "Reesy & FluBBa: DrZ80 core\n" - "MAME devs: YM2612 and SN76496 cores\n" - "rlyeh and others: minimal SDK\n" - "Squidge: mmuhack\n" - "Dzz: ARM940 sample\n" - "GnoStiC / Puck2099: USB joy code\n" - "craigix: GP2X hardware\n" - "ketchupgun: skin design\n" - "\n" - "special thanks (for docs, ideas):\n" - " Charles MacDonald, Haze,\n" - " Stephane Dallongeville,\n" - " Lordus, Exophase, Rokas,\n" - " Nemesis, Tasco Deluxe"; + return NULL; }