int main(int argc, char **argv) { const char *vc; char *vc_keymap = NULL; char *vc_keymap_toggle = NULL; char *vc_font = NULL; char *vc_font_map = NULL; char *vc_font_unimap = NULL; int fd = -1; bool utf8; pid_t font_pid = 0, keymap_pid = 0; bool font_copy = false; int r = EXIT_FAILURE; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); if (argv[1]) vc = argv[1]; else { vc = "/dev/tty0"; font_copy = true; } fd = open_terminal(vc, O_RDWR|O_CLOEXEC); if (fd < 0) { log_error("Failed to open %s: %m", vc); goto finish; } if (!is_vconsole(fd)) { log_error("Device %s is not a virtual console.", vc); goto finish; } utf8 = is_locale_utf8(); r = parse_env_file("/etc/vconsole.conf", NEWLINE, "KEYMAP", &vc_keymap, "KEYMAP_TOGGLE", &vc_keymap_toggle, "FONT", &vc_font, "FONT_MAP", &vc_font_map, "FONT_UNIMAP", &vc_font_unimap, NULL); if (r < 0 && r != -ENOENT) log_warning("Failed to read /etc/vconsole.conf: %s", strerror(-r)); /* Let the kernel command line override /etc/vconsole.conf */ if (detect_container(NULL) <= 0) { r = parse_env_file("/proc/cmdline", WHITESPACE, "vconsole.keymap", &vc_keymap, "vconsole.keymap.toggle", &vc_keymap_toggle, "vconsole.font", &vc_font, "vconsole.font.map", &vc_font_map, "vconsole.font.unimap", &vc_font_unimap, NULL); if (r < 0 && r != -ENOENT) log_warning("Failed to read /proc/cmdline: %s", strerror(-r)); } if (utf8) enable_utf8(fd); else disable_utf8(fd); r = EXIT_FAILURE; if (keymap_load(vc, vc_keymap, vc_keymap_toggle, utf8, &keymap_pid) >= 0 && font_load(vc, vc_font, vc_font_map, vc_font_unimap, &font_pid) >= 0) r = EXIT_SUCCESS; finish: if (keymap_pid > 0) wait_for_terminate_and_warn(KBD_LOADKEYS, keymap_pid); if (font_pid > 0) { wait_for_terminate_and_warn(KBD_SETFONT, font_pid); if (font_copy) font_copy_to_all_vcs(fd); } free(vc_keymap); free(vc_font); free(vc_font_map); free(vc_font_unimap); safe_close(fd); return r; }
int hid_init(void) { // Found a PC keyboard keymap match_keymap(tihw.calc_type); // Load kbd keymap if(keymap_load(options.keys_file) == -1) { gchar *s = g_strdup_printf("unable to load this keymap: <%s>\n", options.keys_file); tiemu_error(0, s); g_free(s); return -1; } // Found a skin match_skin(tihw.calc_type); // Load skin (2 parts) if(skin_load(&skin_infos, options.skin_file) == -1) { gchar *s = g_strdup_printf("unable to load this skin: <%s>\n", options.skin_file); tiemu_error(0, s); g_free(s); return -1; } // Allocate the skn pixbuf (if needed) skn = skin_infos.image; // Set skin keymap depending on calculator type switch(tihw.calc_type) { case TI92: case TI92p: case V200: skn_keymap = sknKey92; break; case TI89: case TI89t: skn_keymap = sknKey89; break; default: { gchar *s = g_strdup_printf("no skin found for this calc\n"); tiemu_error(0, s); g_free(s); return -1; } } // Set window/LCD sizes set_scale(options.view); set_infos(); // Allocate the TI screen buffer lcd_bytmap = (uint32_t *)malloc(LCDMEM_W * LCDMEM_H); // Allocate the lcd pixbuf lcd = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, si.t * LCDMEM_W, si.t * LCDMEM_H); if(lcd == NULL) { gchar *s = g_strdup_printf("unable to create LCD pixbuf.\n"); tiemu_error(0, s); g_free(s); return -1; } // Used by TI89 (the LCD view is clipped from memory view) si.l = gdk_pixbuf_new_subpixbuf(lcd, 0, 0, tihw.lcd_w, tihw.lcd_h); // Constants for LCD update (speed-up) li.n_channels = gdk_pixbuf_get_n_channels (lcd); li.width = gdk_pixbuf_get_width (lcd); li.height = gdk_pixbuf_get_height (lcd); li.rowstride = gdk_pixbuf_get_rowstride (lcd); li.pixels = gdk_pixbuf_get_pixels (lcd); // Create main window display_main_wnd(); // Allocate the backing pixmap (used for drawing and refresh) pixmap = gdk_pixmap_new(main_wnd->window, wr.w, wr.h, -1); if(pixmap == NULL) { gchar *s = g_strdup_printf("unable to create backing pixbuf.\n"); tiemu_error(0, s); g_free(s); return -1; } // Draw the skin and compute grayscale palette redraw_skin(); compute_grayscale(); // Init the planar/chunky conversion table for LCD compute_convtable(); // Install LCD refresh: 100 FPS (10 ms) tid = g_timeout_add((params.lcd_rate == -1) ? 50 : params.lcd_rate, (GtkFunction)hid_refresh, NULL); gtk_widget_show(main_wnd); // show wnd here if(options.view == VIEW_FULL) gdk_window_fullscreen(main_wnd->window); return 0; }