Making The Screen White


andrew_j_w

Still Fresh
Joined
Sep 18, 2005
Messages
59
Hi all,

I've been banging my head against a break wall for the past day and I can't get the program below to work. It should just set the screen to white then quit. Problem is I see nothing when it run. The screen remains black.

If someone could point out where I've gone wrong that would be extremely appreciated.

Code:
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <sys/time.h> 

unsigned short* GP2x_registers;
unsigned long GP2x_screen_addr;
void* GP2x_screen;

int main(int argc, char* argv[]) {
	struct fb_fix_screeninfo fixed_info;

	int fd_memory = open("/dev/mem", O_RDWR);
	int fd_fb0 = open("/dev/fb0", O_RDWR);

	GP2x_registers = (unsigned short*)mmap(0, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd_memory, 0xc0000000);
	GP2x_screen = (unsigned short*)mmap(0, 320*240*2, PROT_WRITE, MAP_SHARED, fd_fb0, 0);

	GP2x_registers[0x290C>>1]= (unsigned short)0x04ab; /* set RGB bpp (8,15/16); enable RGB window 1 */
	GP2x_registers[0x28DA>>1]= (unsigned short)0x0280; /* hex(640) */

	/* Get the memory locations of the framebuffers. */
	ioctl(fd_fb0, FBIOGET_FSCREENINFO, &fixed_info);
	GP2x_screen_addr = fixed_info.smem_start;

	memset(GP2x_screen, 255, 320*240*2);

	GP2x_registers[(0x290E)>>1] = GP2x_registers[(0x2912)>>1] = (unsigned short)(GP2x_screen_addr & 0xFFFF);
	GP2x_registers[(0x2910)>>1] = GP2x_registers[(0x2914)>>1] = (unsigned short)(GP2x_screen_addr >> 16);
}

Many thanks,
Andrew
 
It's probably segfaulting - have you tried running it via telnet? Also, some error checking would be nice - you don't know if the open/mmap/etc is failing.

Also, there's no need of the GP2x_registers setups your doing - there's automatically a single rgb window already open at approximately 0x03101000 or something like that if you want to mmap that instead of opening fb0 or as an alternative.
 
Try getting the screen's physical address first and pass it as the last parameter to mmap (and also mmap from fd_memory not fd_fb0.)
Altered and slightly re-ordered code:
Code:
	int fd_memory = open("/dev/mem", O_RDWR);
	int fd_fb0 = open("/dev/fb0", O_RDWR);

	/* Get the memory locations of the framebuffers. */
	ioctl(fd_fb0, FBIOGET_FSCREENINFO, &fixed_info);
	GP2x_screen_addr = fixed_info.smem_start;

	GP2x_screen = (unsigned short*)mmap(0, 320*240*2, PROT_WRITE, MAP_SHARED, fd_memory, GP2X_screen_addr);

	memset(GP2x_screen, 255, 320*240*2);
 
If you're in 16-bit mode, try using 65535 instead of 255 when memset-ing. And perhaps try using some data type other than void for the screen, like short or something.
 
Thanks for the replies guys.

@Blah: memset sets each byte individually so setting 2**16 rather than 2**8 would have no effect.

@Squidge: I should have mentioned that I've always run it under telnet and even tried stepping through the code in gdb to see what was going wrong. Nothing seemed to be the matter.

Following Squidge's suggestion I tried commenting out the register set up and it works fine now. Very odd. I wonder what I'm doing wrong. As is probably apparent most of this code is 'borrowed' from rlyeh's minimal lib.

Thanks for the idea paeryn, I can see how that would work, but as I tried squidge's suggestion first and that worked I'll keep using /dev/fb* for now.

Cheers!
Andrew
 
Back
Top