#include #include /* Copyright (C) 1992,2006 Bisqwit (http://iki.fi/bisqwit/) */ unsigned char* KeyState=NULL; int main(void) { FILE* fp; SDL_Init(SDL_INIT_VIDEO); SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_SetVideoMode(300,1,8,0); SDL_WM_SetCaption("Inputter",0); fp = fopen("/tmp/fceuinput.dat", "rb+"); if(!fp) fp = fopen("/tmp/fceuinput.dat", "wb"); unlink("/tmp/fceuinput-new.dat"); unlink("/tmp/fceuinput-1.dat"); unlink("/tmp/fceuinput-2.dat"); unlink("/tmp/fceuinput-1ok.dat"); unlink("/tmp/fceuinput-2ok.dat"); for(;;) { int numkeys; SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: goto QuitQuit; } } KeyState = SDL_GetKeyState(&numkeys); if(KeyState) { rewind(fp); fwrite(KeyState, 1, numkeys, fp); fflush(fp); } /* Give the emulators (all of them) permission to go ahead */ link("/tmp/fceuinput.dat", "/tmp/fceuinput-new.dat"); if(1) { int ok1 = 0, ok2 = 0; unlink("/tmp/fceuinput-1ok.dat"); unlink("/tmp/fceuinput-2ok.dat"); /* Wait until all emulators have confirmed */ while(!ok1 || !ok2) { if(!ok1 && !link("/tmp/fceuinput-1.dat", "/tmp/fceuinput-1ok.dat")) ok1=1; if(!ok2 && !link("/tmp/fceuinput-2.dat", "/tmp/fceuinput-2ok.dat")) ok2=1; usleep(1); } //printf("Both confirmed\n-----------\n"); fflush(stdout); /* Prevent them from interpreting the same frame twice */ unlink("/tmp/fceuinput-new.dat"); /* Delete the confirm-flags */ unlink("/tmp/fceuinput-1.dat"); unlink("/tmp/fceuinput-2.dat"); } usleep(1); //1000000/10); } QuitQuit: puts("Quit"); fclose(fp); unlink("/tmp/fceuinput.dat"); SDL_QuitSubSystem(SDL_INIT_VIDEO); return 0; }