diff --git a/source/linux/main.c b/source/linux/main.c index cbfb6d9..d3bcfe9 100644 --- a/source/linux/main.c +++ b/source/linux/main.c @@ -40,121 +40,123 @@ void quit(void) { int main(int argc, char **argv) { char *filename = NULL; - + printf("Starting...\n"); - + dpy = XOpenDisplay(NULL); - + if(dpy == NULL) { printf("Cannot connect to X server!\n"); exit(0); } - + root = DefaultRootWindow(dpy); - + vi = glXChooseVisual(dpy, 0, att); - + if(vi == NULL) { printf("No appropriate visual found!\n"); exit(0); } - + cmap = XCreateColormap(dpy, root, vi->visual, AllocNone); - + swa.colormap = cmap; swa.event_mask = ExposureMask | KeyPressMask; - + win = XCreateWindow(dpy, root, 0, 0, 160, 144, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa); - + XMapWindow(dpy, win); XStoreName(dpy, win, "Cinoop"); - + glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); glXMakeCurrent(dpy, win, glc); - + printf("argc = %d\n", argc); int i; for(i = 1; i < argc; i++) { filename = argv[i]; } - + if(filename == NULL) { printf("No ROM input\n"); - + quit(); return 1; } - + printf("Loading file \"%s\"...\n", filename); - + if(!loadROM(filename)) { printf("Failed!\n"); - + quit(); return 1; } - + printf("Passed!\n"); - + srand(time(NULL)); reset(); - + + XSelectInput(dpy, win, KeyPressMask | KeyReleaseMask); + while(1) { if(XPending(dpy)) { XNextEvent(dpy, &xev); - + if(xev.type == KeyPress || xev.type == KeyRelease) { - //printf("%d\n", xev.xkey.keycode); + //printf("%d\n", xev.xkey.keycode); switch(xev.xkey.keycode) { //case XK_BackSpace: case 22: - keys.select = (xev.type == KeyPress); + keys.select = (xev.type == KeyRelease); break; - + //case XK_Return: case 36: - keys.start = (xev.type == KeyPress); + keys.start = (xev.type == KeyRelease); break; - + //case XK_z: case 52: - keys.b = (xev.type == KeyPress); + keys.b = (xev.type == KeyRelease); break; - + //case XK_x: case 53: - keys.a = (xev.type == KeyPress); + keys.a = (xev.type == KeyRelease); break; - + //case XK_Left: case 113: - keys.left = (xev.type == KeyPress); + keys.left = (xev.type == KeyRelease); break; - + //case XK_Right: case 114: - keys.right = (xev.type == KeyPress); + keys.right = (xev.type == KeyRelease); break; - + //case XK_Up: case 111: - keys.up = (xev.type == KeyPress); + keys.up = (xev.type == KeyRelease); break; - + //case XK_Down: case 116: - keys.down = (xev.type == KeyPress); + keys.down = (xev.type == KeyRelease); break; } } } - + cpuStep(); gpuStep(); interruptStep(); } - + quit(); - + return 0; }