void gp_initGraphics(unsigned short bpp, int flip, int applyMmuHack) { int x = 0; unsigned int key = 0; unsigned int offset = 0; char buf[256]; struct fb_fix_screeninfo info; int fb_fd; int f; gp_setClipping(0, 0, 319, 239); #ifdef DEBUG printf("Entering gp_initGraphics....\r\n"); #endif /* First check that frame buffer memory has not already been setup */ if (!InitFramebuffer) { #ifdef DEBUG sprintf(buf, "Initing buffer\r\n"); printf(buf); #endif wiz_dev[0] = open("/dev/mem", O_RDWR); if(wiz_dev[0] < 0) { printf("Could not open /dev/mem\n"); return; } #ifdef DEBUG sprintf(buf, "Devices opened\r\n"); printf(buf); sprintf(buf, "/dev/mem: %x \r\n", wiz_dev[0]); printf(buf); #endif memregs32 = (volatile unsigned int *)mmap(0, 0x20000, PROT_READ|PROT_WRITE, MAP_SHARED, wiz_dev[0], 0xC0000000); if(memregs32 == (volatile unsigned int *)0xFFFFFFFF) { printf("Could not mmap hardware registers\n"); return; } memregs16 = (volatile unsigned short *)memregs32; memregs8 = (volatile unsigned char *)memregs32; /* backup old register values to restore upon exit */ bkregs32[0] = MLCADDRESS0; bkregs32[1] = MLCADDRESS1; bkregs32[2] = MLCCONTROL0; bkregs32[3] = MLCCONTROL1; bkregs32[4] = MLCLEFTRIGHT0; bkregs32[5] = MLCTOPBOTTOM0; bkregs32[6] = MLCLEFTRIGHT1; bkregs32[7] = MLCTOPBOTTOM1; bkregs32[8] = MLCBGCOLOR; bkregs32[9] = MLCHSTRIDE0; bkregs32[10] = MLCVSTRIDE0; bkregs32[11] = MLCHSTRIDE1; bkregs32[12] = MLCVSTRIDE1; bkregs32[13] = DPCCTRL1; bkregs32[14] = MLCSCREENSIZE; bkregs32[15] = PLLSETREG0; // Get frame buffer address, do not hardcode them, for tv-out compatibility fb_fd = open("/dev/fb0", O_RDWR); if ((!fb_fd) || (ioctl(fb_fd, FBIOGET_FSCREENINFO, &info) < 0)) return; wiz_physvram[0] = info.smem_start; framebuffer_mmap[0] = (void *)mmap(0, fb_size * BUFFERS, PROT_READ|PROT_WRITE, MAP_SHARED, wiz_dev[0], wiz_physvram[0]); for (f = 1; f < BUFFERS; f++) { framebuffer_mmap[f] = framebuffer_mmap[f-1] + (fb_size / sizeof(unsigned short)); wiz_physvram[f] = wiz_physvram[f-1] + fb_size; } close(fb_fd); if (applyMmuHack) { warm_init(); warm_change_cb_upper(WCB_C_BIT|WCB_B_BIT, 1); } // Init and clear the frame buffers for (f = 0; f < BUFFERS; f++) { memset(framebuffer_mmap[f], 0, fb_size); framebuffer16[f] = framebuffer_mmap[f]; } /* Not working well with TV-Out // offset externally visible buffers by 8 // this allows DrMD to not worry about clipping framebuffer16[0]=framebuffer_mmap[0]+8; framebuffer16[1]=framebuffer_mmap[1]+8; framebuffer16[2]=framebuffer_mmap[2]+8; framebuffer16[3]=framebuffer_mmap[3]+8; //ofset physical buffer as well wiz_physvram[0]+=16; wiz_physvram[1]+=16; wiz_physvram[2]+=16; wiz_physvram[3]+=16; */ InitFramebuffer=1; } // Set graphics mode lc_screensize(320, 240); lc_setbgcol(0x000000); /* set default background colour */ lc_layerpos(0, 0, 0, 319, 239); /* set default layer positions */ lc_layerpos(1, 0, 0, 319, 239); lc_setlayer(0, 0, 0, 0, 0, RGB565); /* set default layer settings */ lc_setlayer(1, 1, 0, 0, 0, RGB565); gp_setFramebuffer(flip,1); usleep(100000); pollux_set(memregs16, "lcd_timings=397,1,37,277,341,0,17,337;dpc_clkdiv0=9"); pollux_set(memregs16, "ram_timings=2,9,4,1,1,1,1"); #ifdef DEBUG printf("Leaving gp_initGraphics....\r\n"); #endif }
void gp_initGraphics(unsigned short bpp, int flip, int applyMmuHack) { int x = 0; unsigned int key = 0; unsigned int offset = 0; char buf[256]; #ifdef DEBUG printf("Entering gp_initGraphics....\r\n"); #endif /* First check that frame buffer memory has not already been setup */ if (!InitFramebuffer) { #ifdef DEBUG sprintf(buf, "Initing buffer\r\n"); printf(buf); #endif wiz_dev[0] = open("/dev/mem", O_RDWR); if(wiz_dev[0] < 0) { printf("Could not open /dev/mem\n"); return; } #ifdef DEBUG sprintf(buf, "Devices opened\r\n"); printf(buf); sprintf(buf, "/dev/mem: %x \r\n", wiz_dev[0]); printf(buf); #endif memregs32 = (volatile unsigned int *)mmap(0, 0x20000, PROT_READ|PROT_WRITE, MAP_SHARED, wiz_dev[0], 0xC0000000); if(memregs32 == (volatile unsigned int *)0xFFFFFFFF) { printf("Could not mmap hardware registers\n"); return; } memregs16 = (volatile unsigned short *)memregs32; memregs8 = (volatile unsigned char *)memregs32; /* backup old register values to restore upon exit */ bkregs32[0] = MLCADDRESS0; bkregs32[1] = MLCADDRESS1; bkregs32[2] = MLCCONTROL0; bkregs32[3] = MLCCONTROL1; bkregs32[4] = MLCLEFTRIGHT0; bkregs32[5] = MLCTOPBOTTOM0; bkregs32[6] = MLCLEFTRIGHT1; bkregs32[7] = MLCTOPBOTTOM1; bkregs32[8] = MLCBGCOLOR; bkregs32[9] = MLCHSTRIDE0; bkregs32[10] = MLCVSTRIDE0; bkregs32[11] = MLCHSTRIDE1; bkregs32[12] = MLCVSTRIDE1; bkregs32[13] = DPCCTRL1; bkregs32[14] = MLCSCREENSIZE; bkregs32[15] = PLLSETREG0; if (!framebuffer_mmap[0]) framebuffer_mmap[0]=(void *)mmap(0, fb_size, PROT_READ|PROT_WRITE, MAP_SHARED, wiz_dev[0], (wiz_physvram[0]=0x04000000-(0x26000*4) )); if (!framebuffer_mmap[1]) framebuffer_mmap[1]=(void *)mmap(0, fb_size, PROT_READ|PROT_WRITE, MAP_SHARED, wiz_dev[0], (wiz_physvram[1]=0x04000000-(0x26000*3) )); if (!framebuffer_mmap[2]) framebuffer_mmap[2]=(void *)mmap(0, fb_size, PROT_READ|PROT_WRITE, MAP_SHARED, wiz_dev[0], (wiz_physvram[2]=0x04000000-(0x26000*2) )); if (!framebuffer_mmap[3]) framebuffer_mmap[3]=(void *)mmap(0, fb_size, PROT_READ|PROT_WRITE, MAP_SHARED, wiz_dev[0], (wiz_physvram[3]=0x04000000-(0x26000*1) )); if (applyMmuHack) { warm_init(); warm_change_cb_upper(WCB_C_BIT|WCB_B_BIT, 1); } // Clear the frame buffers memset(framebuffer_mmap[0],0,fb_size); memset(framebuffer_mmap[1],0,fb_size); memset(framebuffer_mmap[2],0,fb_size); memset(framebuffer_mmap[3],0,fb_size); // offset externally visible buffers by 8 // this allows DrMD to not worry about clipping framebuffer16[0]=framebuffer_mmap[0]+8; framebuffer16[1]=framebuffer_mmap[1]+8; framebuffer16[2]=framebuffer_mmap[2]+8; framebuffer16[3]=framebuffer_mmap[3]+8; //ofset physical buffer as well wiz_physvram[0]+=16; wiz_physvram[1]+=16; wiz_physvram[2]+=16; wiz_physvram[3]+=16; InitFramebuffer=1; //gp2x_memregs[0x0F16>>1] = 0x830a; //usleep(1000000); //gp2x_memregs[0x0F58>>1] = 0x100c; //usleep(1000000); } // Set graphics mode lc_screensize(320, 240); lc_setbgcol(0x000000); /* set default background colour */ lc_layerpos(0, 0, 0, 319, 239); /* set default layer positions */ lc_layerpos(1, 0, 0, 319, 239); lc_setlayer(0, 0, 0, 0, 0, RGB565); /* set default layer settings */ lc_setlayer(1, 1, 0, 0, 0, RGB565); gp_setFramebuffer(flip,1); usleep(100000); pollux_set(memregs16, "lcd_timings=397,1,37,277,341,0,17,337;dpc_clkdiv0=9"); pollux_set(memregs16, "ram_timings=2,9,4,1,1,1,1"); #ifdef DEBUG printf("Leaving gp_initGraphics....\r\n"); #endif }