All pastes #63625 Raw Edit

Stuff

public c v1 · immutable
#63625 ·published 2006-06-10 11:35 UTC
rendered paste body
#include <stdlib.h>#include <unistd.h>#include <stdio.h>#include <dirent.h>#include <linux/kd.h>#include <sys/ioctl.h>#include <sys/fcntl.h>#include <termios.h>#include "../hotdog/hotdog.h"uint32 *screen;static uint32 WIDTH, HEIGHT;struct termio savetty, settty;int n = 0, cur_item = 2;char ch, input = 0;fd_set rd;struct timeval tv;hd_object *obj[10];hd_engine *engine;int lskip, rskip = 0;hd_font *chicago;void create_rom_bg() {   obj[7]    = HD_PNG_Create("img/rs_bg.png");   obj[7]->x = 0;   obj[7]->y = 0;   obj[7]->w = 320;   obj[7]->h = 240;}void create_selector(int i) {   obj[1]    = HD_PNG_Create("img/black/sel.png");   obj[1]->x = obj[i]->x;   obj[1]->y = obj[i]->y;   obj[1]->w = 72;   obj[1]->h = 86;}static void update(hd_engine *e, int x, int y, int w, int h){	HD_LCD_Update (e->screen.framebuffer, 0, 0, WIDTH, HEIGHT);}void move_sel(int i) //Moves Selection to an icon!{  HD_Destroy(obj[1]);	create_selector(i);  int c = 0;  for (c = 0; c <= 6; c++) {	 HD_Register(engine, obj[c]);  }}void KB_Init(void){	int flags = fcntl(0, F_GETFL, 0);	int fd = open("/dev/console", O_NONBLOCK);	if (fd < 0)	{		printf("attention: console still active!\n");		sleep(20);		/* not _deadly_ if we can't set graphics mode */		return;	}	ioctl(fd, KDSETMODE, KD_GRAPHICS);	close(fd);    fcntl(0, F_SETFL, flags | O_NONBLOCK);    ioctl(0, TCGETA, &savetty);    ioctl(0, TCGETA, &settty);    settty.c_lflag &= ~ICANON;    settty.c_lflag &= ~ECHO;    ioctl(0, TCSETAF, &settty);}void launch_emu(char *cmd) { HD_LCD_Quit(); system(cmd); HD_LCD_Init(); move_sel(cur_item); HD_Render(engine);}int main(int argc, char **argv){	HD_LCD_Init();	KB_Init();	HD_LCD_GetInfo(0, &WIDTH, &HEIGHT, 0);	screen = malloc(WIDTH * HEIGHT * 2 * sizeof(uint32));	engine = HD_Initialize(WIDTH, HEIGHT, 16, screen, update);	chicago = HD_Font_LoadFNT("img/Chicago.fnt");		//ROM LISTING STUFF	DIR *dir = opendir("/roms/gameboy/");	struct dirent *mydir;	int xy = 0;	char gb_list, gb_roms[45];	int romselection = 0;		typedef struct { char *name; int len; } romlist;	romlist *roms;        obj[0]    = HD_PNG_Create ("img/black/bg.png");        obj[0]->x = 0;        obj[0]->y = 0;        obj[0]->w = 320;        obj[0]->h = 240;                create_selector(2);                obj[2]    = HD_PNG_Create ("img/black/scummvm.png");        obj[2]->x = 20;        obj[2]->y = 60;        obj[2]->w = 72;        obj[2]->h = 86;                obj[3]    = HD_PNG_Create ("img/black/idoom.png");        obj[3]->x = WIDTH/2-32;        obj[3]->y = 35;        obj[3]->w = 72;        obj[3]->h = 86;                obj[4]    = HD_PNG_Create ("img/black/iboy.png");        obj[4]->x = WIDTH-84;        obj[4]->y = 60;        obj[4]->w = 72;        obj[4]->h = 86;                obj[5]    = HD_PNG_Create ("img/black/quit.png");        obj[5]->x = 180;        obj[5]->y = 140;        obj[5]->w = 72;        obj[5]->h = 86;                obj[6]    = HD_PNG_Create ("img/black/mame.png");        obj[6]->x = 80;        obj[6]->y = 140;        obj[6]->w = 72;        obj[6]->h = 86;                       create_rom_bg();                        hd_surface mysrf;        mysrf = obj[0]->canvas;	int c = 0;	for (c = 0; c <= 6; c++) {	 HD_Register(engine, obj[c]);	}		HD_Render(engine);	while( romselection == 0 ) {				switch(getc(stdin)) {				case 'r':					if(rskip == 's')					{						switch(cur_item) {							case 2:								cur_item = 3;								break;							case 3:								cur_item = 4;								break;							case 4:								cur_item = 5;								break;							case 5:								cur_item = 6;								break;							case 6:								cur_item = 2;								break;							}							move_sel(cur_item);							HD_Render(engine);							rskip = 0;					}					else if(rskip == 10)					{ rskip = 's'; }					else					{ rskip++; }					break;				case 'l':					if(lskip == 's')					{						switch(cur_item) {							case 2:								cur_item = 6;								break;							case 6:								cur_item = 5;								break;							case 5:								cur_item = 4;								break;							case 4:								cur_item = 3;								break;							case 3:								cur_item = 2;								break;						}						move_sel(cur_item);							HD_Render(engine);						lskip = 0;										}					else if(lskip == 10)					{ lskip = 's'; }					else					{ lskip++; }					break;					case '\n':						switch(cur_item) {							case 4:								while (mydir = readdir(dir)) {						    	 strcat(gb_list, mydir->d_name);						    	 strcat(gb_list, "\n");						    							   		}						   		closedir(dir);								break;							case 5:					 			system("/sbin/reboot");								break;						}					romselection = 1;					HD_LCD_Quit();					break;					case 'd':					break;				}		}		while( romselection == 1 ) {		create_rom_bg();		HD_Register(engine, obj[7]);		HD_Render(engine);			switch(getc(stdin)) {				case 'r':				//Clockwise				break;				case 'l':				//Counterwise				break;				case 'm':				//MENU				break;				case '\n':				//Action				break;			}	}	return 0;}