Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keyhandling on Linux. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 42 additions & 40 deletions source/linux/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}