platforms, revisit Pico ptr handling

This commit is contained in:
kub 2024-01-07 10:59:24 +01:00
parent 724db457da
commit dca20effa2
11 changed files with 147 additions and 90 deletions

View file

@ -1043,8 +1043,6 @@ void emu_reset_game(void)
void run_events_pico(unsigned int events)
{
int lim_x;
if (events & PEV_PICO_SWINP) {
pico_inp_mode++;
if (pico_inp_mode > 2)
@ -1069,6 +1067,10 @@ void run_events_pico(unsigned int events)
PicoPicohw.page = 6;
emu_status_msg("Page %i", PicoPicohw.page);
}
if (events & PEV_PICO_PEN) {
currentConfig.EmuOpt ^= EOPT_PICO_PEN;
emu_status_msg("%s Pen", currentConfig.EmuOpt & EOPT_PICO_PEN ? "Show" : "Hide");
}
if (pico_inp_mode == 0)
return;
@ -1080,20 +1082,16 @@ void run_events_pico(unsigned int events)
if (PicoIn.pad[0] & 8) pico_pen_x++;
PicoIn.pad[0] &= ~0x0f; // release UDLR
lim_x = (Pico.video.reg[12]&1) ? 319 : 255;
if (pico_pen_y < 8)
pico_pen_y = 8;
if (pico_pen_y < PICO_PEN_ADJUST_Y)
pico_pen_y = PICO_PEN_ADJUST_Y;
if (pico_pen_y > 224 - PICO_PEN_ADJUST_Y)
pico_pen_y = 224 - PICO_PEN_ADJUST_Y;
if (pico_pen_x < 0)
pico_pen_x = 0;
if (pico_pen_x > lim_x - PICO_PEN_ADJUST_X)
pico_pen_x = lim_x - PICO_PEN_ADJUST_X;
if (pico_pen_x < PICO_PEN_ADJUST_X)
pico_pen_x = PICO_PEN_ADJUST_X;
if (pico_pen_x > 320 - PICO_PEN_ADJUST_X)
pico_pen_x = 320 - PICO_PEN_ADJUST_X;
PicoPicohw.pen_pos[0] = pico_pen_x;
if (!(Pico.video.reg[12] & 1))
PicoPicohw.pen_pos[0] += pico_pen_x / 4;
PicoPicohw.pen_pos[0] += 0x3c;
PicoPicohw.pen_pos[0] = 0x03c + pico_pen_x;
PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);
}

View file

@ -34,6 +34,7 @@ extern int g_screen_ppitch; // pitch in pixels
#define EOPT_NO_FRMLIMIT (1<<18)
#define EOPT_WIZ_TEAR_FIX (1<<19)
#define EOPT_EXT_FRMLIMIT (1<<20) // no internal frame limiter (limited by snd, etc)
#define EOPT_PICO_PEN (1<<21)
enum {
EOPT_SCALE_NONE = 0,
@ -106,7 +107,7 @@ extern unsigned char *movie_data;
extern int reset_timing;
extern int flip_after_sync;
#define PICO_PEN_ADJUST_X 4
#define PICO_PEN_ADJUST_X 2
#define PICO_PEN_ADJUST_Y 2
extern int pico_pen_x, pico_pen_y;
extern int pico_inp_mode;

View file

@ -28,7 +28,8 @@
#define PEVB_PICO_PNEXT 21
#define PEVB_PICO_PPREV 20
#define PEVB_PICO_SWINP 19
#define PEVB_RESET 18
#define PEVB_PICO_PEN 18
#define PEVB_RESET 17
#define PEV_VOL_DOWN (1 << PEVB_VOL_DOWN)
#define PEV_VOL_UP (1 << PEVB_VOL_UP)
@ -42,8 +43,9 @@
#define PEV_PICO_PNEXT (1 << PEVB_PICO_PNEXT)
#define PEV_PICO_PPREV (1 << PEVB_PICO_PPREV)
#define PEV_PICO_SWINP (1 << PEVB_PICO_SWINP)
#define PEV_PICO_PEN (1 << PEVB_PICO_PEN)
#define PEV_RESET (1 << PEVB_RESET)
#define PEV_MASK 0x7ffc0000
#define PEV_MASK 0x7ffe0000
#endif /* INCLUDE_c48097f3ff2a6a9af1cce8fd7a9b3f0c */

View file

@ -30,6 +30,7 @@ const struct in_default_bind in_sdl_defbinds[] = {
{ SDLK_F6, IN_BINDTYPE_EMU, PEVB_PICO_PPREV },
{ SDLK_F7, IN_BINDTYPE_EMU, PEVB_PICO_PNEXT },
{ SDLK_F8, IN_BINDTYPE_EMU, PEVB_PICO_SWINP },
{ SDLK_F9, IN_BINDTYPE_EMU, PEVB_PICO_PEN },
{ SDLK_BACKSPACE, IN_BINDTYPE_EMU, PEVB_FF },
{ 0, 0, 0 }
};

View file

@ -366,6 +366,7 @@ me_bind_action emuctrl_actions[] =
{ "Pico Next page ", PEV_PICO_PNEXT },
{ "Pico Prev page ", PEV_PICO_PPREV },
{ "Pico Switch input", PEV_PICO_SWINP },
{ "Pico Display pen ", PEV_PICO_PEN },
{ NULL, 0 }
};
@ -473,6 +474,7 @@ static menu_entry e_menu_md_options[] =
mee_onoff_h ("FM audio", MA_OPT2_ENABLE_YM2612, PicoIn.opt, POPT_EN_FM, h_fmsound),
mee_onoff_h ("FM filter", MA_OPT_FM_FILTER, PicoIn.opt, POPT_EN_FM_FILTER, h_fmfilter),
mee_onoff_h ("FM DAC noise", MA_OPT2_ENABLE_YM_DAC, PicoIn.opt, POPT_EN_FM_DAC, h_dacnoise),
mee_onoff ("Show Pico pen", MA_OPT_PICO_PEN, currentConfig.EmuOpt, EOPT_PICO_PEN),
mee_end,
};
@ -928,14 +930,6 @@ static const char *mgn_opt_region(int id, int *offs)
}
}
static const char *mgn_saveloadcfg(int id, int *offs)
{
strcpy(static_buff, " ");
if (config_slot != 0)
sprintf(static_buff, "[%i]", config_slot);
return static_buff;
}
static const char h_hotkeysvld[] = "Slot used for save/load by emulator hotkey";
static menu_entry e_menu_options[] =
@ -1289,6 +1283,34 @@ static int main_menu_handler(int id, int keys)
return 0;
}
static const char *mgn_picopage(int id, int *offs)
{
strcpy(static_buff, " ");
sprintf(static_buff, "%i", PicoPicohw.page);
return static_buff;
}
static int mh_picopage(int id, int keys)
{
int ret;
if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
PicoPicohw.page += (keys & PBTN_LEFT) ? -1 : 1;
if (PicoPicohw.page < 0) PicoPicohw.page = 6;
else if (PicoPicohw.page > 6) PicoPicohw.page = 0;
return 0;
}
return 1;
}
static const char *mgn_saveloadcfg(int id, int *offs)
{
strcpy(static_buff, " ");
if (config_slot != 0)
sprintf(static_buff, "[%i]", config_slot);
return static_buff;
}
static int mh_saveloadcfg(int id, int keys)
{
int ret;
@ -1330,10 +1352,11 @@ static menu_entry e_menu_main[] =
mee_label (""),
mee_label (""),
mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
mee_handler_id("Save state", MA_MAIN_SAVE_STATE, main_menu_handler),
mee_handler_id("Load state", MA_MAIN_LOAD_STATE, main_menu_handler),
mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
mee_handler_id("Change CD", MA_MAIN_CHANGE_CD, main_menu_handler),
mee_cust_s_h ("Storyware page", MA_MAIN_PICO_PAGE, 0,mh_picopage, mgn_picopage, NULL),
mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
mee_handler_id("Load new game", MA_MAIN_LOAD_ROM, main_menu_handler),
mee_handler ("Change options", menu_loop_options),
@ -1354,6 +1377,7 @@ void menu_loop(void)
me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
me_enable(e_menu_main, MA_MAIN_CHANGE_CD, PicoIn.AHW & PAHW_MCD);
me_enable(e_menu_main, MA_MAIN_PICO_PAGE, PicoIn.AHW & PAHW_PICO);
me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
me_enable(e_menu_main, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
me_enable(e_menu_main, MA_OPT_LOADCFG, PicoGameLoaded && config_slot != config_slot_current);

View file

@ -12,6 +12,7 @@ typedef enum
MA_MAIN_RESET_GAME,
MA_MAIN_LOAD_ROM,
MA_MAIN_CHANGE_CD,
MA_MAIN_PICO_PAGE,
MA_MAIN_CONTROLS,
MA_MAIN_CREDITS,
MA_MAIN_PATCHES,
@ -49,6 +50,7 @@ typedef enum
MA_OPT_SOUND_FILTER,
MA_OPT_SOUND_ALPHA,
MA_OPT_FM_FILTER,
MA_OPT_PICO_PEN,
MA_OPT2_GAMMA,
MA_OPT2_A_SN_GAMMA,
MA_OPT2_DBLBUFF, /* giz */

View file

@ -46,6 +46,10 @@ const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast
const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };
enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
static int is_1stblanked;
static int firstline, linecount;
static int firstcol, colcount;
static int (*emu_scan_begin)(unsigned int num) = NULL;
static int (*emu_scan_end)(unsigned int num) = NULL;
@ -190,29 +194,30 @@ static void draw_cd_leds(void)
static void draw_pico_ptr(void)
{
unsigned short *p = (unsigned short *)g_screen_ptr;
int x, y, pitch = 320;
int x, y, pitch = 320, offs;
// only if pen enabled and for 16bit modes
if (pico_inp_mode == 0 || !is_16bit_mode())
return;
x = pico_pen_x + PICO_PEN_ADJUST_X;
y = pico_pen_y + PICO_PEN_ADJUST_Y;
if (!(Pico.video.reg[12]&1) && !(PicoIn.opt & POPT_DIS_32C_BORDER))
x += 32;
x = ((pico_pen_x * colcount * ((1ULL<<32) / 320)) >> 32) + firstcol;
y = ((pico_pen_y * linecount * ((1ULL<<32) / 224)) >> 32) + firstline;
if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
pitch = 240;
p += (319 - x) * pitch + y;
offs = (319 - x) * pitch + y;
} else
p += x + y * pitch;
offs = x + y * pitch;
p[0] ^= 0xffff;
p[pitch-1] ^= 0xffff;
p[pitch] ^= 0xffff;
p[pitch+1] ^= 0xffff;
p[pitch*2] ^= 0xffff;
if (is_16bit_mode()) {
unsigned short *p = (unsigned short *)g_screen_ptr + offs;
p[0] ^= 0xffff;
p[pitch-1] ^= 0xffff; p[pitch] ^= 0xffff; p[pitch+1] ^= 0xffff;
p[pitch*2] ^= 0xffff;
} else {
unsigned char *p = (unsigned char *)g_screen_ptr + offs;
p[-1] = 0xe0; p[0] = 0xf0; p[1] = 0xe0;
p[pitch-1] = 0xf0; p[pitch] = 0xf0; p[pitch+1] = 0xf0;
p[2*pitch-1] = 0xe0; p[2*pitch] = 0xf0; p[2*pitch+1] = 0xe0;
}
}
static void clear_1st_column(int firstcol, int firstline, int linecount)
@ -389,10 +394,6 @@ static int make_local_pal_sms(int fast_mode)
return (Pico.est.SonicPalCount+1)*0x40;
}
static int is_1stblanked;
static int firstline, linecount;
static int firstcol, colcount;
void pemu_finalize_frame(const char *fps, const char *notice)
{
int emu_opt = currentConfig.EmuOpt;
@ -430,8 +431,8 @@ void pemu_finalize_frame(const char *fps, const char *notice)
osd_text(osd_fps_x, osd_y, fps);
if ((PicoIn.AHW & PAHW_MCD) && (emu_opt & EOPT_EN_CD_LEDS))
draw_cd_leds();
if (PicoIn.AHW & PAHW_PICO)
draw_pico_ptr();
if ((PicoIn.AHW & PAHW_PICO) && (currentConfig.EmuOpt & EOPT_PICO_PEN))
if (pico_inp_mode) draw_pico_ptr();
}
void plat_video_flip(void)

View file

@ -2086,12 +2086,12 @@ void run_events_pico(unsigned int events)
PicoIn.pad[0] &= ~0x0f; // release UDLR
lim_x = (Pico.video.reg[12]&1) ? 319 : 255;
if (pico_pen_y < 8)
pico_pen_y = 8;
if (pico_pen_y < PICO_PEN_ADJUST_Y)
pico_pen_y = PICO_PEN_ADJUST_Y;
if (pico_pen_y > 224 - PICO_PEN_ADJUST_Y)
pico_pen_y = 224 - PICO_PEN_ADJUST_Y;
if (pico_pen_x < 0)
pico_pen_x = 0;
if (pico_pen_x < PICO_PEN_ADJUST_X)
pico_pen_x = PICO_PEN_ADJUST_X;
if (pico_pen_x > lim_x - PICO_PEN_ADJUST_X)
pico_pen_x = lim_x - PICO_PEN_ADJUST_X;

View file

@ -85,6 +85,21 @@ static void draw_cd_leds(void)
#undef p
}
static void draw_pico_ptr(void)
{
int pitch = g_screen_ppitch;
u16 *p = g_screen_ptr;
int x = pico_pen_x, y = pico_pen_y;
x = (x * out_w * ((1ULL<<32) / 320)) >> 32;
y = (y * out_h * ((1ULL<<32) / 224)) >> 32;
p += (screen_y+y)*pitch + (screen_x+x);
p[-pitch] ^= 0xffff;
p[-1] ^= 0xffff; p[0] ^= 0xffff; p[1] ^= 0xffff;
p[pitch] ^= 0xffff;
}
/* render/screen buffer handling:
* In 16 bit mode, render output is directly placed in the screen buffer.
* SW scaling is handled in renderer (x) and in vscaling callbacks here (y).
@ -191,6 +206,8 @@ void pemu_finalize_frame(const char *fps, const char *notice)
}
}
if ((PicoIn.AHW & PAHW_PICO) && (currentConfig.EmuOpt & EOPT_PICO_PEN))
if (pico_inp_mode) draw_pico_ptr();
if (notice)
emu_osd_text16(4, g_screen_height - 8, notice);
if (currentConfig.EmuOpt & EOPT_SHOW_FPS)

View file

@ -76,6 +76,7 @@ static struct in_default_bind in_evdev_defbinds[] =
{ KEY_5, IN_BINDTYPE_EMU, PEVB_PICO_PPREV },
{ KEY_6, IN_BINDTYPE_EMU, PEVB_PICO_PNEXT },
{ KEY_7, IN_BINDTYPE_EMU, PEVB_PICO_SWINP },
{ KEY_8, IN_BINDTYPE_EMU, PEVB_PICO_PEN },
{ 0, 0, 0 }
};
@ -126,29 +127,33 @@ static void draw_cd_leds(void)
int old_reg;
old_reg = Pico_mcd->s68k_regs[0];
if (0) {
// 8-bit modes
unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;
unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;
*(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+ 4) =
*(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+ 4) =
*(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+ 4) = col_g;
*(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+12) =
*(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+12) =
*(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+12) = col_r;
} else {
// 16-bit modes
unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4);
unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;
unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;
}
// 16-bit modes
unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4);
unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;
unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;
*p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;
}
static void draw_pico_ptr(void)
{
int x = pico_pen_x, y = pico_pen_y, pitch = g_screen_ppitch;
unsigned short *p = (unsigned short *)g_screen_ptr;
x = (x * saved_col_count * ((1ULL<<32) / 320)) >> 32;
y = (y * saved_line_count * ((1ULL<<32) / 224)) >> 32;
p += (saved_start_col+x) + (saved_start_line+y) * pitch;
p[-pitch] ^= 0xffff;
p[-1] ^= 0xffff; p[0] ^= 0xffff; p[1] ^= 0xffff;
p[pitch] ^= 0xffff;
}
void pemu_finalize_frame(const char *fps, const char *notice)
{
if ((PicoIn.AHW & PAHW_PICO) && (currentConfig.EmuOpt & EOPT_PICO_PEN))
if (pico_inp_mode) draw_pico_ptr();
if (notice && notice[0])
emu_osd_text16(2 + g_osd_start_x, g_osd_y, notice);
if (fps && fps[0] && (currentConfig.EmuOpt & EOPT_SHOW_FPS))

View file

@ -36,9 +36,6 @@
int engineStateSuspend;
#define PICO_PEN_ADJUST_X 4
#define PICO_PEN_ADJUST_Y 2
struct Vertex
{
short u,v;
@ -372,19 +369,26 @@ void blitscreen_clut(void)
static void draw_pico_ptr(void)
{
unsigned char *p = (unsigned char *)g_screen_ptr + 8;
int x = pico_pen_x, y = pico_pen_y, offs;
// only if pen enabled and for 8bit mode
if (pico_inp_mode == 0 || is_16bit_mode()) return;
x = (x * out_w * ((1ULL<<32) / 320)) >> 32;
y = (y * out_h * ((1ULL<<32) / 224)) >> 32;
p += 512 * (pico_pen_y + PICO_PEN_ADJUST_Y);
p += pico_pen_x + PICO_PEN_ADJUST_X;
if (!(Pico.video.reg[12]&1) && !(PicoIn.opt & POPT_DIS_32C_BORDER))
p += 32;
offs = 512 * (out_y+y) + (out_x+x);
p[ -1] = 0xe0; p[ 0] = 0xf0; p[ 1] = 0xe0;
p[ 511] = 0xf0; p[ 512] = 0xf0; p[ 513] = 0xf0;
p[1023] = 0xe0; p[1024] = 0xf0; p[1025] = 0xe0;
if (is_16bit_mode()) {
unsigned short *p = (unsigned short *)g_screen_ptr + offs;
p[ -1] = 0x0000; p[ 0] = 0x001f; p[ 1] = 0x0000;
p[ 511] = 0x001f; p[ 512] = 0x001f; p[ 513] = 0x001f;
p[1023] = 0x0000; p[1024] = 0x001f; p[1025] = 0x0000;
} else {
unsigned char *p = (unsigned char *)g_screen_ptr + offs + 8;
p[ -1] = 0xe0; p[ 0] = 0xf0; p[ 1] = 0xe0;
p[ 511] = 0xf0; p[ 512] = 0xf0; p[ 513] = 0xf0;
p[1023] = 0xe0; p[1024] = 0xf0; p[1025] = 0xe0;
}
}
@ -630,15 +634,17 @@ void pemu_finalize_frame(const char *fps, const char *notice)
{
int emu_opt = currentConfig.EmuOpt;
if (PicoIn.AHW & PAHW_PICO)
draw_pico_ptr();
if ((PicoIn.AHW & PAHW_PICO) && (currentConfig.EmuOpt & EOPT_PICO_PEN))
if (pico_inp_mode) draw_pico_ptr();
osd_buf_cnt = 0;
if (notice) osd_text(4, notice);
if (emu_opt & 2) osd_text(OSD_FPS_X, fps);
if (notice)
osd_text(4, notice);
if (emu_opt & EOPT_SHOW_FPS)
osd_text(OSD_FPS_X, fps);
osd_cdleds = 0;
if ((emu_opt & 0x400) && (PicoIn.AHW & PAHW_MCD))
if ((emu_opt & EOPT_EN_CD_LEDS) && (PicoIn.AHW & PAHW_MCD))
cd_leds();
sceKernelDcacheWritebackAll();