All pastes #65480 Raw Edit

Something

public c v1 · immutable
#65480 ·published 2006-06-14 14:32 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 <sys/stat.h>#include <termios.h>#include "../hotdog/hotdog.h"uint32 *screen;static uint32 WIDTH, HEIGHT;struct termio savetty, settty;int e = 1, count, n = 0, cur_item = 2;char ch, input = 0;fd_set rd;struct timeval tv;hd_object *obj[10];hd_engine *engine;int mame_max = 0, lskip, rskip = 0;hd_font *chicago;struct stat st;//MAME Variableschar *mame_path[15] = { "/roms/hellopac", "/roms/matrxpac", "/roms/aarmada", "/roms/mspacmab", "/roms/pacman", "/roms/nibbler", "/roms/pengo2u", "/roms/congo", "/roms/zaxxon", "/roms/centiped", "/roms/milliped", "/roms/gberet", "/roms/rushatk", "/roms/mrdo", "/roms/ladybug"};char *mame_name[15] = {"Hellopac", "Matrxpac", "Aarmada", "Miss Pacman", "Pacman", "Nibbler", "Pengo", "Congo", "Zaxxon", "Centiped", "Millped", "GBeret", "Rush Attack", "MRDO", "Ladybug"};char *mame_exename[15] = {"/ipodmame/mame-hellopac", "/ipodmame/mame-matrxpac", "/ipodmame/mame-aarmada", "/ipodmame/mame-mspacmab", "/ipodmame/mame-pacman", "/ipodmame/mame-nibbler", "/ipodmame/mame-pengo2u", "/ipodmame/mame-congo", "/ipodmame/mame-zaxxon", "/ipodmame/mame-centiped", "/ipodmame/mame-milliped", "/ipodmame/mame-gberet", "/ipodmame/mame-rushatk", "/ipodmame/mame-mrdo", "/ipodmame/mame-ladybug"};int mc_item = 0;char *mame_rpath[];char *mame_ry[];char *mame_rexename[];//MAME Variables ENDvoid 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;      obj[8]    = HD_PNG_Create("img/rs_bar.png");   obj[8]->x = 0;   obj[8]->y = 0;   obj[8]->w = 320;   obj[8]->h = 15;}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;	char gb_list, rom_title;	int xy, roms, romselection = 0;        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[7]->canvas;	int c = 0;	for (c = 0; c <= 6; c++) {	 HD_Register(engine, obj[c]);	}		HD_Render(engine);		move_sel(cur_item);	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 2:							rom_title = "ScummVM Game Selection";								break;							case 3:							rom_title = "iDoom WAD Selection";								break;							case 4:							rom_title = "iBoy Rom Selection";								break;							case 5:								HD_LCD_Quit();					 			system("/sbin/reboot");								break;							case 6:							rom_title = "iPodMAME Rom Selection";								break;							}					roms = 0;					romselection = 1;					break;					case 'd':					break;				}		}				while( romselection == 1 ) {	if ( roms == 0 ) {		HD_Destroy(obj[1]);		HD_Register(engine, obj[7]);		HD_Register(engine, obj[8]);		switch(cur_item) {			case 2:				HD_Font_Draw(mysrf, chicago, 25, 8, 0xFFFFFFFF, "ScummVM Game Selection");				break;			case 3:				HD_Font_Draw(mysrf, chicago, 25, 8, 0xFFFFFFFF, "iDoom WAD Selection");				break;			case 4:				HD_Font_Draw(mysrf, chicago, 25, 8, 0xFFFFFFFF, "iBoy Rom Selection");				break;			case 6:				HD_Font_Draw(mysrf, chicago, 25, 8, 0xFFFFFFFF, "iPodMAME Rom Selection");				count = 20;				for (xy=0;xy<=14;xy++) {				 if ( stat(mame_path[xy], &st) >= 0 ) {				   mame_rexename[e] = mame_exename[xy];				   mame_rpath[e] = mame_path[xy];				   mame_ry[e] = count+13;				   count = count+15;				   HD_Font_Draw(mysrf, chicago, 25, count, 0xFFFFFFFF, mame_name[xy]);				  }				}				mc_item = 1;				obj[8]->y = mame_ry[1];				break;		}		HD_Render(engine);		roms = 1;	}			switch(getc(stdin)) {				case 'r':			if(rskip == 's')			{				if ( mc_item == e ) {				 obj[8]->y = mame_ry[1];				 mc_item = 1;				} else {				obj[8]->y = mame_ry[mc_item+1];				mc_item++;				}				rskip = 0;								}			else if(rskip == 10)			{ rskip = 's'; }			else			{ rskip++; }				HD_Render(engine);					break;				case 'l':			if(lskip == 's')			{				if ( mc_item == 1 ) {				 obj[8]->y = mame_ry[e];				 mc_item = e;				} else {				 obj[8]->y = mame_ry[mc_item-1];				 mc_item--;				}				lskip = 0;								}			else if(lskip == 10)			{ lskip = 's'; }			else			{ lskip++; }				HD_Render(engine);					break;				case 'd':					break;				case '\n':				HD_LCD_Quit();				system(mame_exename[mc_item]);					break;			}	}	return 0;}