control attempt
This commit is contained in:
parent
fe80b43264
commit
0a64fcb500
1 changed files with 52 additions and 101 deletions
155
main.c
155
main.c
|
|
@ -21,8 +21,11 @@ struct priv_t {
|
|||
MwWidget *fb_widget;
|
||||
MwLLPixmap *px;
|
||||
};
|
||||
static struct gb_s gb;
|
||||
static struct priv_t priv;
|
||||
|
||||
static void key_pressed(MwWidget handle, void *client, void *user);
|
||||
|
||||
int mfb_open(const char *title, int width, int height) {
|
||||
int depth, i, formatCount, convDepth = -1;
|
||||
|
||||
|
|
@ -34,108 +37,17 @@ int mfb_open(const char *title, int width, int height) {
|
|||
priv.fb_widget =
|
||||
MwCreateWidget(MwImageClass, "fb", priv.win, 0, 0, width, height);
|
||||
|
||||
MwAddUserHandler(priv.win, MwNkeyHandler, key_pressed, NULL);
|
||||
|
||||
priv.px = NULL;
|
||||
|
||||
// XPixmapFormatValues *formats;
|
||||
// XSetWindowAttributes windowAttributes;
|
||||
// XSizeHints sizeHints;
|
||||
// Visual *visual;
|
||||
|
||||
// s_display = XOpenDisplay(0);
|
||||
|
||||
// if (!s_display)
|
||||
// return -1;
|
||||
|
||||
// s_screen = DefaultScreen(s_display);
|
||||
// visual = DefaultVisual(s_display, s_screen);
|
||||
// formats = XListPixmapFormats(s_display, &formatCount);
|
||||
// depth = DefaultDepth(s_display, s_screen);
|
||||
// Window defaultRootWindow = DefaultRootWindow(s_display);
|
||||
|
||||
// for (i = 0; i < formatCount; ++i) {
|
||||
// if (depth == formats[i].depth) {
|
||||
// convDepth = formats[i].bits_per_pixel;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// XFree(formats);
|
||||
|
||||
// // We only support 32-bit right now
|
||||
// if (convDepth != 32) {
|
||||
// XCloseDisplay(s_display);
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
// int screenWidth = DisplayWidth(s_display, s_screen);
|
||||
// int screenHeight = DisplayHeight(s_display, s_screen);
|
||||
|
||||
// windowAttributes.border_pixel = BlackPixel(s_display, s_screen);
|
||||
// windowAttributes.background_pixel = BlackPixel(s_display, s_screen);
|
||||
// windowAttributes.backing_store = NotUseful;
|
||||
|
||||
// s_window = XCreateWindow(
|
||||
// s_display, defaultRootWindow, (screenWidth - width) / 2,
|
||||
// (screenHeight - height) / 2, width, height, 0, depth, InputOutput,
|
||||
// visual, CWBackPixel | CWBorderPixel | CWBackingStore,
|
||||
// &windowAttributes);
|
||||
|
||||
// if (!s_window)
|
||||
// return 0;
|
||||
|
||||
// XSelectInput(s_display, s_window, KeyPressMask | KeyReleaseMask);
|
||||
// XStoreName(s_display, s_window, title);
|
||||
|
||||
// sizeHints.flags = PPosition | PMinSize | PMaxSize;
|
||||
// sizeHints.x = 0;
|
||||
// sizeHints.y = 0;
|
||||
// sizeHints.min_width = width;
|
||||
// sizeHints.max_width = width;
|
||||
// sizeHints.min_height = height;
|
||||
// sizeHints.max_height = height;
|
||||
|
||||
// XSetWMNormalHints(s_display, s_window, &sizeHints);
|
||||
// XClearWindow(s_display, s_window);
|
||||
// XMapRaised(s_display, s_window);
|
||||
// XFlush(s_display);
|
||||
|
||||
// s_gc = DefaultGC(s_display, s_screen);
|
||||
|
||||
// s_ximage = XCreateImage(s_display, CopyFromParent, depth, ZPixmap, 0, NULL,
|
||||
// width, height, 32, width * 4);
|
||||
|
||||
// s_width = width;
|
||||
// s_height = height;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int processEvents() {
|
||||
if (!MwPending(priv.win)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
MwStep(priv.win);
|
||||
|
||||
// if (event.type != KeyPress)
|
||||
// return 0;
|
||||
|
||||
// sym = XLookupKeysym(&event.xkey, 0);
|
||||
|
||||
// if ((sym >> 8) != KEY_FUNCTION)
|
||||
// return 0;
|
||||
|
||||
// if ((sym & 0xFF) == KEY_ESC)
|
||||
// return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mfb_update(void *buffer) {
|
||||
// if (MwPending(priv.win)) {
|
||||
// }
|
||||
|
||||
MwStep(priv.win);
|
||||
if (MwPending(priv.win)) {
|
||||
MwStep(priv.win);
|
||||
}
|
||||
|
||||
if (priv.px == NULL) {
|
||||
priv.px = MwLoadRaw(priv.win, buffer, LCD_WIDTH, LCD_HEIGHT);
|
||||
|
|
@ -148,11 +60,51 @@ int mfb_update(void *buffer) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void mfb_close(void) {
|
||||
// s_ximage->data = NULL;
|
||||
// XDestroyImage(s_ximage);
|
||||
// XDestroyWindow(s_display, s_window);
|
||||
// XCloseDisplay(s_display);
|
||||
void mfb_close(void) {}
|
||||
|
||||
static void key_pressed(MwWidget handle, void *user, void *client) {
|
||||
(void)handle;
|
||||
(void)user;
|
||||
|
||||
// int k = *(int *)client;
|
||||
|
||||
printf("%p\n", client);
|
||||
|
||||
return;
|
||||
/*
|
||||
switch (k) {
|
||||
case MwLLKeyEnter:
|
||||
gb.direct.joypad &= ~JOYPAD_START;
|
||||
break;
|
||||
|
||||
case MwLLKeyBackSpace:
|
||||
gb.direct.joypad &= ~JOYPAD_SELECT;
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
gb.direct.joypad &= ~JOYPAD_A;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
gb.direct.joypad &= ~JOYPAD_B;
|
||||
break;
|
||||
|
||||
case MwLLKeyUp:
|
||||
gb.direct.joypad &= ~JOYPAD_UP;
|
||||
break;
|
||||
|
||||
case MwLLKeyRight:
|
||||
gb.direct.joypad &= ~JOYPAD_RIGHT;
|
||||
break;
|
||||
|
||||
case MwLLKeyDown:
|
||||
gb.direct.joypad &= ~JOYPAD_DOWN;
|
||||
break;
|
||||
|
||||
case MwLLKeyLeft:
|
||||
gb.direct.joypad &= ~JOYPAD_LEFT;
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -249,7 +201,6 @@ void lcd_draw_line(struct gb_s *gb, const uint8_t pixels[160],
|
|||
int main(int argc, char **argv) {
|
||||
/* Must be freed */
|
||||
char *rom_file_name = NULL;
|
||||
static struct gb_s gb;
|
||||
enum gb_init_error_e ret;
|
||||
|
||||
switch (argc) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue