X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Fgp2x.c;h=482eb17f753f7acd94ffcb05dc2bcedc8ba99284;hb=5a01fba679330353ce293b2c744f55b2e51bea7d;hp=88f17313fe138ac0f6388e6b49c4063409649636;hpb=4742480dcabcbd9d23fd8cb9a655fc8c9c314513;p=gpsp.git diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index 88f1731..482eb17 100644 --- a/gp2x/gp2x.c +++ b/gp2x/gp2x.c @@ -19,16 +19,17 @@ */ +#define _BSD_SOURCE +#define _GNU_SOURCE #include #include #include +#include +#include #include "../common.h" #include "gp2x.h" #include "warm.h" -extern int main_cpuspeed(int argc, char *argv[]); -extern SDL_Surface* screen; - u32 gp2x_audio_volume = 74/2; u32 gpsp_gp2x_dev_audio = 0; u32 gpsp_gp2x_dev = 0; @@ -36,59 +37,166 @@ u32 gpsp_gp2x_gpiodev = 0; static volatile u16 *gpsp_gp2x_memregs; static volatile u32 *gpsp_gp2x_memregl; -unsigned short *gp2x_memregs; -static volatile u16 *MEM_REG; +#ifdef WIZ_BUILD +#include +void *gpsp_gp2x_screen; +#define fb_buf_count 4 +static u32 fb_paddr[fb_buf_count]; +static void *fb_vaddr[fb_buf_count]; +static u32 fb_work_buf; +static int fb_buf_use; -s32 gp2x_load_mmuhack() +static void fb_video_init() { - s32 mmufd = open("/dev/mmuhack", O_RDWR); + struct fb_fix_screeninfo fbfix; + int i, ret; + int fbdev; + + fbdev = open("/dev/fb0", O_RDWR); + if (fbdev < 0) { + perror("can't open fbdev"); + exit(1); + } - if(mmufd < 0) + ret = ioctl(fbdev, FBIOGET_FSCREENINFO, &fbfix); + if (ret == -1) { - system("/sbin/insmod mmuhack.o"); - mmufd = open("/dev/mmuhack", O_RDWR); + perror("ioctl(fbdev) failed"); + exit(1); } - if(mmufd < 0) + printf("framebuffer: \"%s\" @ %08lx\n", fbfix.id, fbfix.smem_start); + fb_paddr[0] = fbfix.smem_start; + close(fbdev); + + fb_vaddr[0] = mmap(0, 320*240*2*fb_buf_count, PROT_READ|PROT_WRITE, + MAP_SHARED, gpsp_gp2x_dev, fb_paddr[0]); + if (fb_vaddr[0] == MAP_FAILED) + { + perror("mmap(fb_vaddr) failed"); + exit(1); + } + memset(fb_vaddr[0], 0, 320*240*2*fb_buf_count); + + printf(" %p -> %08x\n", fb_vaddr[0], fb_paddr[0]); + for (i = 1; i < fb_buf_count; i++) + { + fb_paddr[i] = fb_paddr[i-1] + 320*240*2; + fb_vaddr[i] = (char *)fb_vaddr[i-1] + 320*240*2; + printf(" %p -> %08x\n", fb_vaddr[i], fb_paddr[i]); + } + fb_work_buf = 0; + fb_buf_use = fb_buf_count; + + pollux_video_flip(); + warm_change_cb_upper(WCB_C_BIT|WCB_B_BIT, 1); +} + +void pollux_video_flip() +{ + warm_cache_op_all(WOP_D_CLEAN); + gpsp_gp2x_memregl[0x406C>>2] = fb_paddr[fb_work_buf]; + gpsp_gp2x_memregl[0x4058>>2] |= 0x10; + fb_work_buf++; + if (fb_work_buf >= fb_buf_use) + fb_work_buf = 0; + gpsp_gp2x_screen = fb_vaddr[fb_work_buf]; +} + +void fb_use_buffers(int count) +{ + if (count < 1) + count = 1; + else if (count > fb_buf_count) + count = fb_buf_count; + fb_buf_use = count; + memset(fb_vaddr[0], 0, 320*240*2*count); +} + +static void fb_video_exit() +{ + /* switch to default fb mem */ + gpsp_gp2x_memregl[0x406C>>2] = fb_paddr[0]; + gpsp_gp2x_memregl[0x4058>>2] |= 0x10; +} +#endif + +static int get_romdir(char *buff, size_t size) +{ + FILE *f; + char *s; + int r = -1; + + f = fopen("romdir.txt", "r"); + if (f == NULL) return -1; - close(mmufd); - return 0; + s = fgets(buff, size, f); + if (s) + { + r = strlen(s); + while (r > 0 && isspace(buff[r-1])) + buff[--r] = 0; + } + + fclose(f); + return r; } void gp2x_init() { + char buff[256]; + gpsp_gp2x_dev = open("/dev/mem", O_RDWR); gpsp_gp2x_dev_audio = open("/dev/mixer", O_RDWR); gpsp_gp2x_memregl = (unsigned long *)mmap(0, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, gpsp_gp2x_dev, 0xc0000000); gpsp_gp2x_memregs = (unsigned short *)gpsp_gp2x_memregl; + warm_init(); #ifdef WIZ_BUILD gpsp_gp2x_gpiodev = open("/dev/GPIO", O_RDONLY); + fb_video_init(); #endif - warm_init(); - clear_screen(0); -// main_cpuspeed(0, NULL); - gp2x_memregs = (void *)gpsp_gp2x_memregs; - cpuctrl_init(); + if (get_romdir(buff, sizeof(buff)) > 0) + chdir(buff); + gp2x_sound_volume(1); } void gp2x_quit() { - munmap((void *)gpsp_gp2x_memregl, 0x10000); - close(gpsp_gp2x_dev_audio); - close(gpsp_gp2x_dev); + char buff1[256], buff2[256]; + + getcwd(buff1, sizeof(buff1)); + chdir(main_path); + if (get_romdir(buff2, sizeof(buff2)) >= 0 && + strcmp(buff1, buff2) != 0) + { + FILE *f = fopen("romdir.txt", "w"); + if (f != NULL) + { + printf("writing romdir: %s\n", buff1); + fprintf(f, "%s", buff1); + fclose(f); + } + } + + warm_finish(); #ifdef WIZ_BUILD close(gpsp_gp2x_gpiodev); + fb_video_exit(); #endif + munmap((void *)gpsp_gp2x_memregl, 0x10000); + close(gpsp_gp2x_dev_audio); + close(gpsp_gp2x_dev); - //chdir("/usr/gp2x"); - //execl("gp2xmenu", "gp2xmenu", NULL); - exit(0); + fcloseall(); + sync(); + chdir("/usr/gp2x"); + execl("gp2xmenu", "gp2xmenu", NULL); } void gp2x_sound_volume(u32 volume_up) @@ -136,13 +244,31 @@ u32 gpsp_gp2x_joystick_read(void) #endif } -#ifdef WIZ_BUILD -void cpuctrl_init(void) -{ -} - +// Fout = (m * Fin) / (p * 2^s) void set_FCLK(u32 MHZ) { -} + u32 v; + u32 mdiv, pdiv, sdiv = 0; +#ifdef WIZ_BUILD + #define SYS_CLK_FREQ 27 + // m = MDIV, p = PDIV, s = SDIV + pdiv = 9; + mdiv = (MHZ * pdiv) / SYS_CLK_FREQ; + mdiv &= 0x3ff; + v = (pdiv<<18) | (mdiv<<8) | sdiv; + + gpsp_gp2x_memregl[0xf004>>2] = v; + gpsp_gp2x_memregl[0xf07c>>2] |= 0x8000; + while (gpsp_gp2x_memregl[0xf07c>>2] & 0x8000) + ; +#else + #define SYS_CLK_FREQ 7372800 + // m = MDIV + 8, p = PDIV + 2, s = SDIV + pdiv = 3; + mdiv = (MHZ * pdiv * 1000000) / SYS_CLK_FREQ; + mdiv &= 0xff; + v = ((mdiv-8)<<8) | ((pdiv-2)<<2) | sdiv; + gpsp_gp2x_memregs[0x910>>1] = v; #endif +}