Skip to content

Commit

Permalink
platforms, display pad overlay and storyware pages for Pico
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Mar 25, 2024
1 parent da41488 commit 4e123ca
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 98 deletions.
3 changes: 1 addition & 2 deletions pico/pico/pico.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@ PICO_INTERNAL void PicoInitPico(void)

PicoIn.AHW = PAHW_PICO;
memset(&PicoPicohw, 0, sizeof(PicoPicohw));
PicoPicohw.pen_pos[0] = 0x03c + 320/2;
PicoPicohw.pen_pos[1] = 0x200 + 240/2;
PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;
}
117 changes: 98 additions & 19 deletions platform/common/emu.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* PicoDrive
* (C) notaz, 2007-2010
* (C) irixxxx, 2019-2024
*
* This work is licensed under the terms of MAME license.
* See COPYING file in the top-level directory.
Expand All @@ -19,6 +20,7 @@
#include "../libpicofe/fonts.h"
#include "../libpicofe/sndout.h"
#include "../libpicofe/lprintf.h"
#include "../libpicofe/readpng.h"
#include "../libpicofe/plat.h"
#include "emu.h"
#include "input_pico.h"
Expand Down Expand Up @@ -618,7 +620,7 @@ void emu_prep_defconfig(void)
{
memset(&defaultConfig, 0, sizeof(defaultConfig));
defaultConfig.EmuOpt = EOPT_EN_SRAM | EOPT_EN_SOUND | EOPT_16BPP |
EOPT_EN_CD_LEDS | EOPT_GZIP_SAVES | 0x10/*?*/;
EOPT_EN_CD_LEDS | EOPT_GZIP_SAVES | EOPT_PICO_PEN;
defaultConfig.s_PicoOpt = POPT_EN_SNDFILTER|POPT_EN_GG_LCD|POPT_EN_YM2413 |
POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 |
POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX |
Expand Down Expand Up @@ -1041,19 +1043,76 @@ void emu_reset_game(void)
reset_timing = 1;
}

void run_events_pico(unsigned int events)
static int pico_page;
static int pico_w, pico_h;
static u16 *pico_overlay;

static u16 *load_pico_overlay(int page, int w, int h)
{
if (events & PEV_PICO_SWINP) {
pico_inp_mode++;
if (pico_inp_mode > 2)
pico_inp_mode = 0;
switch (pico_inp_mode) {
case 2: emu_status_msg("Input: Pen on Pad"); break;
case 1: emu_status_msg("Input: Pen on Storyware"); break;
case 0: emu_status_msg("Input: Joystick"); break;
static const char *pic_exts[] = { "png", "PNG" };
char *ext, *fname = NULL;
int extpos, i;

if (pico_page == page && pico_w == w && pico_h == h)
return pico_overlay;
pico_page = page;
pico_w = w, pico_h = h;

ext = strrchr(rom_fname_loaded, '.');
extpos = ext ? ext-rom_fname_loaded : strlen(rom_fname_loaded);
strcpy(static_buff, rom_fname_loaded);
static_buff[extpos++] = '_';
if (page < 0) {
static_buff[extpos++] = 'p';
static_buff[extpos++] = 'a';
static_buff[extpos++] = 'd';
} else
static_buff[extpos++] = '0'+PicoPicohw.page;
static_buff[extpos++] = '.';

for (i = 0; i < ARRAY_SIZE(pic_exts); i++) {
strcpy(static_buff+extpos, pic_exts[i]);
if (access(static_buff, R_OK) == 0) {
printf("found Pico file: %s\n", static_buff);
fname = static_buff;
break;
}
PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;
}

pico_overlay = realloc(pico_overlay, w*h*2);
memset(pico_overlay, 0, w*h*2);
if (!fname || !pico_overlay || readpng(pico_overlay, fname, READPNG_SCALE, w, h)) {
if (pico_overlay)
free(pico_overlay);
pico_overlay = NULL;
}

return pico_overlay;
}

void emu_pico_overlay(u16 *pd, int w, int h, int pitch)
{
u16 *overlay = NULL;
int y, oh = h;

// get overlay
if (pico_inp_mode == 1) {
oh = (w/2 < h ? w/2 : h); // storyware has squished h
overlay = load_pico_overlay(PicoPicohw.page, w, oh);
} else if (pico_inp_mode == 2)
overlay = load_pico_overlay(-1, w, oh);

// copy overlay onto buffer
if (overlay) {
for (y = 0; y < oh; y++)
memcpy(pd + y*pitch, overlay + y*w, w*2);
if (y < h)
memset(pd + y*pitch, 0, w*2);
}
}

void run_events_pico(unsigned int events)
{
if (events & PEV_PICO_PPREV) {
PicoPicohw.page--;
if (PicoPicohw.page < 0)
Expand All @@ -1066,16 +1125,35 @@ void run_events_pico(unsigned int events)
PicoPicohw.page = 6;
emu_status_msg("Page %i", PicoPicohw.page);
}
if (events & PEV_PICO_SHPEN) {
currentConfig.EmuOpt ^= EOPT_PICO_PEN;
emu_status_msg("%s Pen", currentConfig.EmuOpt & EOPT_PICO_PEN ? "Show" : "Hide");
if (events & PEV_PICO_STORY) {
if (pico_inp_mode == 1) {
pico_inp_mode = 0;
emu_status_msg("Input: D-Pad");
} else {
pico_inp_mode = 1;
emu_status_msg("Input: Pen on Storyware");
}
}
if (events & PEV_PICO_PAD) {
if (pico_inp_mode == 2) {
pico_inp_mode = 0;
emu_status_msg("Input: D-Pad");
} else {
pico_inp_mode = 2;
emu_status_msg("Input: Pen on Pad");
}
}
if (events & PEV_PICO_PPOSV) {
if (events & PEV_PICO_PENST) {
PicoPicohw.pen_pos[0] ^= 0x8000;
PicoPicohw.pen_pos[1] ^= 0x8000;
emu_status_msg("Pen %s", PicoPicohw.pen_pos[0] & 0x8000 ? "Up" : "Down");
}

if ((currentConfig.EmuOpt & EOPT_PICO_PEN) &&
(PicoIn.pad[0]&0x20) && pico_inp_mode && pico_overlay) {
pico_inp_mode = 0;
emu_status_msg("Input: D-Pad");
}
if (pico_inp_mode == 0)
return;

Expand All @@ -1086,14 +1164,15 @@ void run_events_pico(unsigned int events)
if (PicoIn.pad[0] & 8) pico_pen_x++;
PicoIn.pad[0] &= ~0x0f; // release UDLR

/* cursor position, cursor drawing must not cross screen borders */
if (pico_pen_y < PICO_PEN_ADJUST_Y)
pico_pen_y = PICO_PEN_ADJUST_Y;
if (pico_pen_y > 224-1 - PICO_PEN_ADJUST_Y)
pico_pen_y = 224-1 - PICO_PEN_ADJUST_Y;
if (pico_pen_y > 223-1 - PICO_PEN_ADJUST_Y)
pico_pen_y = 223-1 - PICO_PEN_ADJUST_Y;
if (pico_pen_x < PICO_PEN_ADJUST_X)
pico_pen_x = PICO_PEN_ADJUST_X;
if (pico_pen_x > 320-1 - PICO_PEN_ADJUST_X)
pico_pen_x = 320-1 - PICO_PEN_ADJUST_X;
if (pico_pen_x > 319-1 - PICO_PEN_ADJUST_X)
pico_pen_x = 319-1 - PICO_PEN_ADJUST_X;

PicoPicohw.pen_pos[0] &= 0x8000;
PicoPicohw.pen_pos[1] &= 0x8000;
Expand Down
2 changes: 2 additions & 0 deletions platform/common/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ void emu_get_game_name(char *str150);
void emu_set_fastforward(int set_on);
void emu_status_msg(const char *format, ...);

void emu_pico_overlay(unsigned short *pd, int w, int h, int pitch);

/* default sound code */
void emu_sound_start(void);
void emu_sound_stop(void);
Expand Down
12 changes: 6 additions & 6 deletions platform/common/input_pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#define PEVB_FF 22
#define PEVB_PICO_PNEXT 21
#define PEVB_PICO_PPREV 20
#define PEVB_PICO_SWINP 19
#define PEVB_PICO_SHPEN 18
#define PEVB_PICO_PPOSV 17
#define PEVB_PICO_STORY 19
#define PEVB_PICO_PAD 18
#define PEVB_PICO_PENST 17
#define PEVB_RESET 16

#define PEV_VOL_DOWN (1 << PEVB_VOL_DOWN)
Expand All @@ -43,9 +43,9 @@
#define PEV_FF (1 << PEVB_FF)
#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_SHPEN (1 << PEVB_PICO_SHPEN)
#define PEV_PICO_PPOSV (1 << PEVB_PICO_PPOSV)
#define PEV_PICO_STORY (1 << PEVB_PICO_STORY)
#define PEV_PICO_PAD (1 << PEVB_PICO_PAD)
#define PEV_PICO_PENST (1 << PEVB_PICO_PENST)
#define PEV_RESET (1 << PEVB_RESET)

#define PEV_MASK 0x7fff0000
Expand Down
6 changes: 3 additions & 3 deletions platform/common/inputmap_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const struct in_default_bind in_sdl_defbinds[] = {
{ SDLK_F5, IN_BINDTYPE_EMU, PEVB_SWITCH_RND },
{ 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_SHPEN },
{ SDLK_F10, IN_BINDTYPE_EMU, PEVB_PICO_PPOSV },
{ SDLK_F8, IN_BINDTYPE_EMU, PEVB_PICO_STORY },
{ SDLK_F9, IN_BINDTYPE_EMU, PEVB_PICO_PAD },
{ SDLK_F10, IN_BINDTYPE_EMU, PEVB_PICO_PENST },
{ SDLK_BACKSPACE, IN_BINDTYPE_EMU, PEVB_FF },
{ 0, 0, 0 }
};
Expand Down
47 changes: 24 additions & 23 deletions platform/common/menu_pico.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* PicoDrive
* (C) notaz, 2010,2011
* (C) irixxxx, 2023,2024
*
* This work is licensed under the terms of MAME license.
* See COPYING file in the top-level directory.
Expand Down Expand Up @@ -349,21 +350,21 @@ me_bind_action me_ctrl_actions[] =

me_bind_action emuctrl_actions[] =
{
{ "Load State ", PEV_STATE_LOAD },
{ "Save State ", PEV_STATE_SAVE },
{ "Prev Save Slot ", PEV_SSLOT_PREV },
{ "Next Save Slot ", PEV_SSLOT_NEXT },
{ "Switch Renderer ", PEV_SWITCH_RND },
{ "Volume Down ", PEV_VOL_DOWN },
{ "Volume Up ", PEV_VOL_UP },
{ "Fast forward ", PEV_FF },
{ "Reset Game ", PEV_RESET },
{ "Enter Menu ", PEV_MENU },
{ "Pico Next page ", PEV_PICO_PNEXT },
{ "Pico Prev page ", PEV_PICO_PPREV },
{ "Pico Switch input", PEV_PICO_SWINP },
{ "Pico Pen sensor ", PEV_PICO_PPOSV },
{ "Pico Show pen ", PEV_PICO_SHPEN },
{ "Load State ", PEV_STATE_LOAD },
{ "Save State ", PEV_STATE_SAVE },
{ "Prev Save Slot ", PEV_SSLOT_PREV },
{ "Next Save Slot ", PEV_SSLOT_NEXT },
{ "Switch Renderer", PEV_SWITCH_RND },
{ "Volume Down ", PEV_VOL_DOWN },
{ "Volume Up ", PEV_VOL_UP },
{ "Fast forward ", PEV_FF },
{ "Reset Game ", PEV_RESET },
{ "Enter Menu ", PEV_MENU },
{ "Pico Next page ", PEV_PICO_PNEXT },
{ "Pico Prev page ", PEV_PICO_PPREV },
{ "Pico Storyware ", PEV_PICO_STORY },
{ "Pico Pad ", PEV_PICO_PAD },
{ "Pico Pen state ", PEV_PICO_PENST },
{ NULL, 0 }
};

Expand Down Expand Up @@ -463,15 +464,17 @@ static const char h_fmsound[] = "Disabling improves performance, but breaks sou
static const char h_dacnoise[] = "FM chips in the 1st Mega Drive model have DAC noise,\n"
"newer models used different chips without this";
static const char h_fmfilter[] = "Improves sound accuracy but is noticeably slower,\n"
"best´quality if native rate isn't working";
"best quality if native rate isn't working";
static const char h_picopen[] = "Enabling resets Pico display and d-pad input back to\n"
"screen if the Pico pen button is pressed";

static menu_entry e_menu_md_options[] =
{
mee_enum_h ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names, h_renderer),
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_enum_h ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names, h_renderer),
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_h ("Pen button shows screen", MA_OPT_PICO_PEN, currentConfig.EmuOpt, EOPT_PICO_PEN, h_picopen),
mee_end,
};

Expand Down Expand Up @@ -1295,8 +1298,6 @@ static const char *mgn_picopage(int id, int *offs)

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;
Expand Down
30 changes: 21 additions & 9 deletions platform/gp2x/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,12 @@ static void draw_pico_ptr(void)
{
int up = (PicoPicohw.pen_pos[0]|PicoPicohw.pen_pos[1]) & 0x8000;
int x, y, pitch = 320, offs;
// storyware pages are actually squished, 2:1
int h = (pico_inp_mode == 1 ? 160 : linecount);
if (h < 224) y++;

x = ((pico_pen_x * colcount * ((1ULL<<32)/320 + 1)) >> 32) + firstcol;
y = ((pico_pen_y * linecount * ((1ULL<<32)/224 + 1)) >> 32) + firstline;
y = ((pico_pen_y * h * ((1ULL<<32)/224 + 1)) >> 32) + firstline;

if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) {
pitch = 240;
Expand All @@ -210,16 +213,18 @@ static void draw_pico_ptr(void)
unsigned short *p = (unsigned short *)g_screen_ptr + offs;
int o = (up ? 0x0000 : 0xffff), _ = (up ? 0xffff : 0x0000);

p[-pitch-1] ^= _; p[-pitch] ^= o; p[-pitch+1] ^= _;
p[1] ^= o; p[0] ^= o; p[1] ^= o;
p[pitch-1] ^= _; p[pitch] ^= o; p[pitch+1] ^= _;
p[-pitch-1] ^= o; p[-pitch] ^= _; p[-pitch+1] ^= _; p[-pitch+2] ^= o;
p[-1] ^= _; p[0] ^= o; p[1] ^= o; p[2] ^= _;
p[pitch-1] ^= _; p[pitch] ^= o; p[pitch+1] ^= o; p[pitch+2] ^= _;
p[2*pitch-1]^= o; p[2*pitch]^= _; p[2*pitch+1]^= _; p[2*pitch+2]^= o;
} else {
unsigned char *p = (unsigned char *)g_screen_ptr + offs;
int o = (up ? 0xe0 : 0xf0), _ = (up ? 0xf0 : 0xe0);

p[-pitch-1] = _; p[-pitch] = o; p[-pitch+1] = _;
p[-1] = o; p[0] = o; p[1] = o;
p[pitch-1] = _; p[pitch] = o; p[pitch+1] = _;
p[-pitch-1] = o; p[-pitch] = _; p[-pitch+1] = _; p[-pitch+2] = o;
p[-1] = _; p[0] = o; p[1] = o; p[2] = _;
p[pitch-1] = _; p[pitch] = o; p[pitch+1] = o; p[pitch+2] = _;
p[2*pitch-1]= o; p[2*pitch]= _; p[2*pitch+1]= _; p[2*pitch+2]= o;
}
}

Expand Down Expand Up @@ -434,8 +439,15 @@ 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) && (currentConfig.EmuOpt & EOPT_PICO_PEN))
if (pico_inp_mode) draw_pico_ptr();
if (PicoIn.AHW & PAHW_PICO) {
int h = linecount, w = colcount;
u16 *pd = g_screen_ptr + firstline*g_screen_ppitch + firstcol;

if (pico_inp_mode && is_16bit_mode())
emu_pico_overlay(pd, w, h, g_screen_ppitch);
if (pico_inp_mode /*== 2 || overlay*/)
draw_pico_ptr();
}
}

void plat_video_flip(void)
Expand Down
2 changes: 1 addition & 1 deletion platform/libpicofe
Submodule libpicofe updated 2 files
+37 −0 readpng.c
+1 −0 readpng.h
1 change: 1 addition & 0 deletions platform/linux/blit.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* PicoDrive
* (C) notaz, 2006,2009
* (C) irixxxx, 2022
*
* This work is licensed under the terms of MAME license.
* See COPYING file in the top-level directory.
Expand Down
Loading

0 comments on commit 4e123ca

Please sign in to comment.