Skip to content

Commit

Permalink
platform linux, 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 20, 2024
1 parent 0ef1674 commit e9f7e47
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 6 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;
}
2 changes: 1 addition & 1 deletion platform/libpicofe
Submodule libpicofe updated 2 files
+37 −0 readpng.c
+1 −0 readpng.h
90 changes: 87 additions & 3 deletions platform/linux/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/mman.h>

#include "../libpicofe/menu.h"
#include "../libpicofe/readpng.h"
#include "../libpicofe/plat.h"
#include "../common/emu.h"
#include "../common/arm_utils.h"
Expand Down Expand Up @@ -92,9 +93,12 @@ 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;
// storyware pages are actually squished, 2:1
u64 h = (pico_inp_mode == 1 ? 160 : out_h);
if (h < 224) y++;

x = (x * out_w * ((1ULL<<32) / 320 + 1)) >> 32;
y = (y * out_h * ((1ULL<<32) / 224 + 1)) >> 32;
y = (y * h * ((1ULL<<32) / 224 + 1)) >> 32;
p += (screen_y+y)*pitch + (screen_x+x);

p[-pitch-1] ^= _; p[-pitch] ^= o; p[-pitch+1] ^= _;
Expand Down Expand Up @@ -172,6 +176,38 @@ void screen_blit(u16 *pd, int pp, u8* ps, int ss, u16 *pal)
upscale[currentConfig.filter & 0x3](pd, pp, ps, ss, out_w, out_h, pal);
}

static int pico_page;
static u16 *pico_pagebuf;

static const char *pic_exts[] = { "png", "PNG" };
static char static_buff[512];

char *find_pico_file()
{
char *ext = strrchr(rom_fname_loaded, '.');
int extpos = ext ? ext-rom_fname_loaded : strlen(rom_fname_loaded);
int i;

strcpy(static_buff, rom_fname_loaded);
static_buff[extpos++] = '_';
if (pico_inp_mode == 2) {
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);
return static_buff;
}
}
return NULL;
}

void pemu_finalize_frame(const char *fps, const char *notice)
{
if (!is_16bit_mode()) {
Expand All @@ -194,6 +230,7 @@ void pemu_finalize_frame(const char *fps, const char *notice)
u16 *ps = ghost_buf;
int y, h = currentConfig.vscaling == EOPT_SCALE_SW ? 240:out_h;
int w = currentConfig.scaling == EOPT_SCALE_SW ? 320:out_w;

if (currentConfig.ghosting == 1)
for (y = 0; y < h; y++) {
v_blend((u32 *)pd, (u32 *)ps, w/2, p_075_round);
Expand All @@ -208,8 +245,48 @@ 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 (PicoIn.AHW & PAHW_PICO) {
u16 *pd = screen_buffer(g_screen_ptr) +
out_y * g_screen_ppitch + out_x;
int y, h = currentConfig.vscaling == EOPT_SCALE_SW ? 240:out_h;
int w = currentConfig.scaling == EOPT_SCALE_SW ? 320:out_w;

if (pico_inp_mode == 1 && pico_page != PicoPicohw.page) {
char *fname = find_pico_file();
pico_pagebuf = realloc(pico_pagebuf, 320*160*2);
memset(pico_pagebuf, 0, 320*160*2);
if (!fname ||
readpng(pico_pagebuf, fname, READPNG_SCALE, w, w/2)) {
if (pico_pagebuf)
free(pico_pagebuf);
pico_pagebuf = NULL;
} else {
pico_page = PicoPicohw.page;
}
}
if (pico_inp_mode == 2 && pico_page != -1) {
char *fname = find_pico_file();
pico_pagebuf = realloc(pico_pagebuf, 320*240*2);
memset(pico_pagebuf, 0, 320*240*2);
if (!fname ||
readpng(pico_pagebuf, fname, READPNG_SCALE, w, h)) {
if (pico_pagebuf)
free(pico_pagebuf);
pico_pagebuf = NULL;
} else
pico_page = -1;
}
// copy image onto buffer
if (pico_inp_mode == 1 && pico_pagebuf)
for (y = 0; y < w/2; y++)
memcpy(pd + w*y, pico_pagebuf + w*y, w*2);
if (pico_inp_mode == 2 && pico_pagebuf)
for (y = 0; y < h; y++)
memcpy(pd + w*y, pico_pagebuf + w*y, w*2);

if (pico_inp_mode && (currentConfig.EmuOpt & EOPT_PICO_PEN))
draw_pico_ptr();
}
if (notice)
emu_osd_text16(4, g_screen_height - 8, notice);
if (currentConfig.EmuOpt & EOPT_SHOW_FPS)
Expand Down Expand Up @@ -446,6 +523,9 @@ void emu_video_mode_change(int start_line, int line_count, int start_col, int co
memset(ghost_buf, 0, w * h * 2);
}

free(pico_pagebuf);
pico_pagebuf = NULL;

// clear whole screen in all buffers
if (!is_16bit_mode())
memset32(Pico.est.Draw2FB, 0xe0e0e0e0, (320+8) * (8+240+8) / 4);
Expand All @@ -470,6 +550,10 @@ void pemu_loop_end(void)
free(ghost_buf);
ghost_buf = NULL;
}
if (pico_pagebuf) {
free(pico_pagebuf);
pico_pagebuf = NULL;
}
}

void plat_wait_till_us(unsigned int us_to)
Expand Down

0 comments on commit e9f7e47

Please sign in to comment.