X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=frontend%2Fplat_pollux.c;h=fd9c32595922b9f41acb48b49ae66cd306616487;hp=4983ec770a4fcadef735ff4f4f76ad0b50e18651;hb=478216725b77d1c7fd45d972e3c596134633adba;hpb=d3f3bf09b5b3f1d8b025cc9dbd902eb157aae0b7 diff --git a/frontend/plat_pollux.c b/frontend/plat_pollux.c index 4983ec77..fd9c3259 100644 --- a/frontend/plat_pollux.c +++ b/frontend/plat_pollux.c @@ -21,6 +21,8 @@ #include "warm/warm.h" #include "plugin_lib.h" #include "cspace.h" +#include "blit320.h" +#include "in_tsbutton.h" #include "main.h" #include "menu.h" #include "plat.h" @@ -32,11 +34,14 @@ static volatile unsigned int *memregl; static void *fb_vaddrs[2]; static unsigned int fb_paddrs[2]; static int fb_work_buf; -static int cpu_clock_allowed; +static int cpu_clock_allowed, have_warm; +static unsigned int saved_video_regs[2][6]; +#define FB_VRAM_SIZE (320*240*2*2*2) // 2 buffers with space for 24bpp mode static unsigned short *psx_vram; static unsigned int psx_vram_padds[512]; -static int psx_offset, psx_step, psx_width, psx_height, psx_bpp; +static int psx_step, psx_width, psx_height, psx_bpp; +static int psx_offset_x, psx_offset_y; static int fb_offset_x, fb_offset_y; // TODO: get rid of this @@ -51,8 +56,9 @@ int omap_enable_layer(int enabled) static void *fb_flip(void) { - memregl[0x406C>>2] = fb_paddrs[fb_work_buf]; + memregl[0x406C>>2] = memregl[0x446C>>2] = fb_paddrs[fb_work_buf]; memregl[0x4058>>2] |= 0x10; + memregl[0x4458>>2] |= 0x10; fb_work_buf ^= 1; return fb_vaddrs[fb_work_buf]; } @@ -86,12 +92,17 @@ static void pollux_changemode(int bpp, int is_bgr) return; } - memregl[0x405c>>2] = bytes; - memregl[0x4060>>2] = 320 * bytes; + // program both MLCs so that TV-out works + memregl[0x405c>>2] = memregl[0x445c>>2] = bytes; + memregl[0x4060>>2] = memregl[0x4460>>2] = 320 * bytes; r = memregl[0x4058>>2]; r = (r & 0xffff) | (code << 16) | 0x10; memregl[0x4058>>2] = r; + + r = memregl[0x4458>>2]; + r = (r & 0xffff) | (code << 16) | 0x10; + memregl[0x4458>>2] = r; } /* note: both PLLs are programmed the same way, @@ -233,6 +244,15 @@ void plat_video_menu_leave(void) pollux_changemode(psx_bpp, 1); } +void *plat_prepare_screenshot(int *w, int *h, int *bpp) +{ + bgr555_to_rgb565(pl_vout_buf, pl_vout_buf, 320*240*2); + *w = 320; + *h = 240; + *bpp = psx_bpp; + return pl_vout_buf; +} + static void pl_vout_set_raw_vram(void *vram) { int i; @@ -251,51 +271,6 @@ static void pl_vout_set_raw_vram(void *vram) } } -static void *pl_vout_set_mode(int w, int h, int bpp) -{ - static int old_w, old_h, old_bpp; - int poff_w, poff_h; - - if (!w || !h || !bpp || (w == old_w && h == old_h && bpp == old_bpp)) - return NULL; - - printf("psx mode: %dx%d@%d\n", w, h, bpp); - - psx_step = 1; - if (h > 256) { - psx_step = 2; - h /= 2; - } - - poff_w = poff_h = 0; - if (w > 320) { - poff_w = w / 2 - 320/2; - w = 320; - } - if (h > 240) { - poff_h = h / 2 - 240/2; - h = 240; - } - fb_offset_x = 320/2 - w / 2; - fb_offset_y = 240/2 - h / 2; - - psx_offset = poff_h * 1024 + poff_w; - psx_width = w; - psx_height = h; - psx_bpp = bpp; - - if (fb_offset_x || fb_offset_y) { - // not fullscreen, must clear borders - memset(g_menuscreen_ptr, 0, 320*240 * psx_bpp/8); - g_menuscreen_ptr = fb_flip(); - memset(g_menuscreen_ptr, 0, 320*240 * psx_bpp/8); - } - - pollux_changemode(bpp, 1); - - return NULL; -} - static void spend_cycles(int loops) { asm volatile ( @@ -313,11 +288,10 @@ static void raw_flip_dma(int x, int y) { unsigned int dst = fb_paddrs[fb_work_buf] + (fb_offset_y * 320 + fb_offset_x) * psx_bpp / 8; - int spsx_line = y + (psx_offset >> 10); - int spsx_offset = (x + psx_offset) & 0x3f8; + int spsx_line = y + psx_offset_y; + int spsx_offset = (x + psx_offset_x) & 0x3f8; int dst_stride = 320 * psx_bpp / 8; int len = psx_width * psx_bpp / 8; - //unsigned int st = timer_get(); int i; warm_cache_op_all(WOP_D_CLEAN); @@ -347,8 +321,6 @@ static void raw_flip_dma(int x, int y) DMA_REG(0x1c) = 0x80000; // go } - //printf("d %d\n", timer_get() - st); - if (psx_bpp == 16) { pl_vout_buf = g_menuscreen_ptr; pl_print_hud(320, fb_offset_y + psx_height, fb_offset_x); @@ -360,28 +332,106 @@ static void raw_flip_dma(int x, int y) pcnt_end(PCNT_BLIT); } -static void raw_flip_soft(int x, int y) +#define make_flip_func(name, blitfunc) \ +static void name(int x, int y) \ +{ \ + unsigned short *vram = psx_vram; \ + unsigned char *dst = (unsigned char *)g_menuscreen_ptr + \ + (fb_offset_y * 320 + fb_offset_x) * psx_bpp / 8; \ + unsigned int src = (y + psx_offset_y) * 1024 + x + psx_offset_x; \ + int dst_stride = 320 * psx_bpp / 8; \ + int len = psx_width * psx_bpp / 8; \ + int i; \ + \ + pcnt_start(PCNT_BLIT); \ + \ + for (i = psx_height; i > 0; i--, src += psx_step * 1024, dst += dst_stride) { \ + src &= 1024*512-1; \ + blitfunc(dst, vram + src, len); \ + } \ + \ + if (psx_bpp == 16) { \ + pl_vout_buf = g_menuscreen_ptr; \ + pl_print_hud(320, fb_offset_y + psx_height, fb_offset_x); \ + } \ + \ + g_menuscreen_ptr = fb_flip(); \ + pl_flip_cnt++; \ + \ + pcnt_end(PCNT_BLIT); \ +} + +make_flip_func(raw_flip_soft, memcpy) +make_flip_func(raw_flip_soft_368, blit320_368) +make_flip_func(raw_flip_soft_512, blit320_512) +make_flip_func(raw_flip_soft_640, blit320_640) + +static void *pl_vout_set_mode(int w, int h, int bpp) { - unsigned short *src = psx_vram + y * 1024 + x + psx_offset; - unsigned char *dst = (unsigned char *)g_menuscreen_ptr + - (fb_offset_y * 320 + fb_offset_x) * psx_bpp / 8; - int dst_stride = 320 * psx_bpp / 8; - int len = psx_width * psx_bpp / 8; - //unsigned int st = timer_get(); - int i; + static int old_w, old_h, old_bpp; + int poff_w, poff_h, w_max; - for (i = psx_height; i > 0; i--, src += psx_step * 1024, dst += dst_stride) - memcpy(dst, src, len); + if (!w || !h || !bpp || (w == old_w && h == old_h && bpp == old_bpp)) + return NULL; - //printf("s %d\n", timer_get() - st); + printf("psx mode: %dx%d@%d\n", w, h, bpp); - if (psx_bpp == 16) { - pl_vout_buf = g_menuscreen_ptr; - pl_print_hud(320, fb_offset_y + psx_height, fb_offset_x); + switch (w + (bpp != 16)) { + case 640: + pl_rearmed_cbs.pl_vout_raw_flip = raw_flip_soft_640; + w_max = 640; + break; + case 512: + pl_rearmed_cbs.pl_vout_raw_flip = raw_flip_soft_512; + w_max = 512; + break; + case 384: + case 368: + pl_rearmed_cbs.pl_vout_raw_flip = raw_flip_soft_368; + w_max = 368; + break; + default: + pl_rearmed_cbs.pl_vout_raw_flip = have_warm ? raw_flip_dma : raw_flip_soft; + w_max = 320; + break; } - g_menuscreen_ptr = fb_flip(); - pl_flip_cnt++; + psx_step = 1; + if (h > 256) { + psx_step = 2; + h /= 2; + } + + poff_w = poff_h = 0; + if (w > w_max) { + poff_w = w / 2 - w_max / 2; + w = w_max; + } + fb_offset_x = 0; + if (w < 320) + fb_offset_x = 320/2 - w / 2; + if (h > 240) { + poff_h = h / 2 - 240/2; + h = 240; + } + fb_offset_y = 240/2 - h / 2; + + psx_offset_x = poff_w; + psx_offset_y = poff_h; + psx_width = w; + psx_height = h; + psx_bpp = bpp; + + if (fb_offset_x || fb_offset_y) { + // not fullscreen, must clear borders + memset(g_menuscreen_ptr, 0, 320*240 * psx_bpp/8); + g_menuscreen_ptr = fb_flip(); + memset(g_menuscreen_ptr, 0, 320*240 * psx_bpp/8); + } + + pollux_changemode(bpp, 1); + + return NULL; } static void *pl_vout_flip(void) @@ -389,6 +439,24 @@ static void *pl_vout_flip(void) return NULL; } +static void save_multiple_regs(unsigned int *dest, int base, int count) +{ + const volatile unsigned int *regs = memregl + base / 4; + int i; + + for (i = 0; i < count; i++) + dest[i] = regs[i]; +} + +static void restore_multiple_regs(int base, const unsigned int *src, int count) +{ + volatile unsigned int *regs = memregl + base / 4; + int i; + + for (i = 0; i < count; i++) + regs[i] = src[i]; +} + void plat_init(void) { const char *main_fb_name = "/dev/fb0"; @@ -409,6 +477,10 @@ void plat_init(void) } memregl = (volatile void *)memregs; + // save video regs of both MLCs + save_multiple_regs(saved_video_regs[0], 0x4058, ARRAY_SIZE(saved_video_regs[0])); + save_multiple_regs(saved_video_regs[1], 0x4458, ARRAY_SIZE(saved_video_regs[1])); + fbdev = open(main_fb_name, O_RDWR); if (fbdev == -1) { fprintf(stderr, "%s: ", main_fb_name); @@ -425,7 +497,7 @@ void plat_init(void) fb_paddrs[0] = fbfix.smem_start; fb_paddrs[1] = fb_paddrs[0] + 320*240*4; // leave space for 24bpp - fb_vaddrs[0] = mmap(0, 320*240*2*4, PROT_READ|PROT_WRITE, + fb_vaddrs[0] = mmap(0, FB_VRAM_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, fb_paddrs[0]); if (fb_vaddrs[0] == MAP_FAILED) { perror("mmap(fb_vaddrs) failed"); @@ -445,6 +517,7 @@ void plat_init(void) } warm_ret = warm_init(); + have_warm = warm_ret == 0; warm_change_cb_upper(WCB_B_BIT, 1); /* some firmwares have sys clk on PLL0, we can't adjust CPU clock @@ -492,31 +565,33 @@ void plat_init(void) if (battdev < 0) perror("Warning: could't open pollux_batt"); - // hmh - plat_rescan_inputs(); - pl_rearmed_cbs.pl_vout_flip = pl_vout_flip; - pl_rearmed_cbs.pl_vout_raw_flip = warm_ret == 0 ? raw_flip_dma : raw_flip_soft; + pl_rearmed_cbs.pl_vout_raw_flip = have_warm ? raw_flip_dma : raw_flip_soft; pl_rearmed_cbs.pl_vout_set_mode = pl_vout_set_mode; pl_rearmed_cbs.pl_vout_set_raw_vram = pl_vout_set_raw_vram; psx_width = 320; psx_height = 240; psx_bpp = 16; + + in_tsbutton_init(); } void plat_finish(void) { warm_finish(); timer_cleanup(); - pollux_changemode(16, 0); - fb_work_buf = 0; - fb_flip(); + + memset(fb_vaddrs[0], 0, FB_VRAM_SIZE); + restore_multiple_regs(0x4058, saved_video_regs[0], ARRAY_SIZE(saved_video_regs[0])); + restore_multiple_regs(0x4458, saved_video_regs[1], ARRAY_SIZE(saved_video_regs[1])); + memregl[0x4058>>2] |= 0x10; + memregl[0x4458>>2] |= 0x10; + munmap(fb_vaddrs[0], FB_VRAM_SIZE); + close(fbdev); if (battdev >= 0) close(battdev); - munmap(fb_vaddrs[0], 320*240*2*2); - close(fbdev); munmap((void *)memregs, 0x20000); close(memdev); }