int task_flash_hex(int argc, char *argv[]) { hex_t *h; if (argc < 4 || argc > 5) { warning("usage: %s %s %s <input hex filename> [<output hex filename>]\n", argv[0], argv[1], argv[2]); return EXIT_FAILURE; } h = hex_load_from_file(argv[3]); if (argc == 5) { #if 0 hex_save_to_file(h, argv[4]); #else hex_t *hout; hout = hex_from_map(h->mem, h->tag, h->total_bytes, h->min_address); hex_save_to_file(hout, argv[4]); hex_free(hout); #endif } hex_free(h); return EXIT_SUCCESS; }
void ui_run (void) { GtkWidget * box; GtkWidget * about; GtkWidget * window; int success; builder = gtk_builder_new(); success = gtk_builder_add_from_file (builder, UI_BUILDER_FILENAME, NULL); if (!success) success = gtk_builder_add_from_file (builder, UI_BUILDER_FILE, NULL); if (!success) g_error (_("User interface definition file '%s' was not found.\n")); gtk_builder_connect_signals (builder, NULL); window = GET_OBJECT("window"); box = GET_OBJECT("box"); about = GET_OBJECT ("window-about"); g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, ui_log_level_message, NULL); g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, ui_log_level_info, NULL); game = hex_new (DEFAULT_BOARD_SIZE); gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about), PACKAGE_VERSION); hexboard = hexboard_new(DEFAULT_BOARD_SIZE); filter_auto = gtk_file_filter_new (); filter_sgf = gtk_file_filter_new (); filter_lg_sgf = gtk_file_filter_new (); gtk_file_filter_set_name (filter_auto, "Select Automatically"); gtk_file_filter_set_name (filter_sgf, "Smart Game Format (SGF)"); gtk_file_filter_set_name (filter_lg_sgf, "LittleGolem's Smart Game Format (SGF)"); gtk_file_filter_add_pattern (filter_auto, "*"); gtk_file_filter_add_pattern (filter_sgf, "*.sgf"); gtk_file_filter_add_pattern (filter_lg_sgf, "*.hsgf"); gtk_file_filter_add_pattern (filter_lg_sgf, "*.sgf"); g_object_ref_sink (filter_auto); g_object_ref_sink (filter_sgf); g_object_ref_sink (filter_lg_sgf); g_signal_connect (GTK_WIDGET(hexboard), "cell_clicked", G_CALLBACK(ui_signal_cell_clicked), game); gtk_container_add (GTK_CONTAINER(box), hexboard); gtk_widget_show_all (window); update_history_buttons(); update_window_title(); gtk_main(); hex_free (game); }
int task_flash_download(int argc, char *argv[]) { flash_t f; uint8_t i, expected_sig[3]; if (argc != 7) { warning("usage: %s %s %s <sig byte 0> <sig byte 1> <sig byte 2> <hex filename>\n", argv[0], argv[1], argv[2]); return EXIT_FAILURE; } memset(&f, 0, sizeof(flash_t)); // setup the data structure from constants and arguments f.hello_retries = 10; for (i = 0; i < 3; ++i) expected_sig[i] = (uint8_t)strtoul(argv[i + 3], NULL, 16); f.addr.source = flash_pipes[0]; f.addr.target = flash_pipes[1]; printf("%s: downloading flash contents from bootloader at address: %llx\n", argv[0], f.addr.target); radio = task_radio_setup(NRF24_PA_MAX, NRF24_1MBPS, FLASH_CHANNEL, f.addr.source, f.addr.target); #ifdef PI_DEBUG nrf24_print_details(radio); #endif if (!task_flash_hello_exchange(&f, expected_sig)) { warning("%s: HELLO exchange failed!\n", argv[0]); task_flash_print_details(&f); return EXIT_FAILURE; } task_flash_print_details(&f); if (!task_flash_download_core(&f, 0, f.available_flash - 1)) { warning("%s: downloading application space failed!\n", argv[0]); } hex_save_to_file(f.hex, argv[6]); hex_free(f.hex); // send application start f.packet[0] = FLASH_DONE; if (!task_send_packet(radio, "FLASH_DONE", f.packet, FLASH_DONE_SIZE, FLASH_SEND_POST_DELAY_US, f.addr.target)) return EXIT_FAILURE; return EXIT_SUCCESS; }
void ui_signal_open (GtkMenuItem * item, gpointer data) { GtkWidget *dialog; GtkWidget *window = GET_OBJECT("window"); char * filename; Hexboard * board; dialog = gtk_file_chooser_dialog_new (_("Open"), GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); gtk_widget_set_size_request(GTK_WIDGET(dialog), 800, 600); /* Configure the previewer widget */ board = HEXBOARD (hexboard_new (10)); gtk_widget_set_size_request(GTK_WIDGET(board), 340, 240); gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER(dialog), GTK_WIDGET(board)); g_signal_connect (dialog, "update-preview", G_CALLBACK (ui_signal_open_update_preview), board); /* Set filters */ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter_auto); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter_sgf); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter_lg_sgf); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { Hexboard * board = HEXBOARD (hexboard); filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); game_file = filename; update_window_title(); hex_free (game); game_format = dialog_selected_format (dialog); game = hex_load_sgf (game_format, filename); hexboard_set_size (board, hex_size (game)); g_free (filename); history_marker = undo_history_marker = hex_history_current (game); update_hexboard_colors (); update_hexboard_sensitive(); update_history_buttons(); check_end_of_game(); } gtk_widget_destroy (dialog); }
void ui_signal_new (GtkMenuItem * item, gpointer data) { Hexboard * board = HEXBOARD (hexboard); GtkWidget * dialog = GET_OBJECT ("window-new"); GtkSpinButton * sizespin = GTK_SPIN_BUTTON (GET_OBJECT ("window-new-size")); GtkColorButton * color1 = GTK_COLOR_BUTTON (GET_OBJECT ("window-new-color1")); GtkColorButton * color2 = GTK_COLOR_BUTTON (GET_OBJECT ("window-new-color2")); gint ok; ok = gtk_dialog_run (GTK_DIALOG (dialog)); if (ok) { gint size = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON (sizespin)); GdkColor color; double r,g,b; hex_free (game); game = hex_new (size); hexboard_set_size (board, size); history_marker = undo_history_marker = 0; /* Colors */ hexboard_color[0][0] = hexboard_color[0][1] = hexboard_color[0][2] = 1; gtk_color_button_get_color (color1, &color); r = hexboard_color[1][0] = color.red / 65535.0;; g = hexboard_color[1][1] = color.green / 65535.0;; b = hexboard_color[1][2] = color.blue / 65535.0;; hexboard_border_set_color (board, HEXBOARD_BORDER_SE, r,g,b); hexboard_border_set_color (board, HEXBOARD_BORDER_NW, r,g,b); gtk_color_button_get_color (color2, &color); r = hexboard_color[2][0] = color.red / 65535.0;; g = hexboard_color[2][1] = color.green / 65535.0;; b = hexboard_color[2][2] = color.blue / 65535.0;; hexboard_border_set_color (board, HEXBOARD_BORDER_NE, r,g,b); hexboard_border_set_color (board, HEXBOARD_BORDER_SW, r,g,b); game_file = NULL; update_window_title(); update_hexboard_colors(); update_hexboard_sensitive(); update_history_buttons(); } gtk_widget_hide (dialog); }
void ui_signal_open_update_preview (GtkFileChooser *dialog, Hexboard * board) { gchar * filename; hex_t game; filename = gtk_file_chooser_get_filename (dialog); if (filename != NULL) game = hex_load_sgf (game_format, filename); else game = NULL; if (game != NULL) { size_t size = hex_size (game); hexboard_set_size (board, size); hex_to_widget (board, game); gtk_widget_set_visible (GTK_WIDGET(board), TRUE); hex_free (game); } else gtk_widget_set_visible (GTK_WIDGET(board), FALSE); }
void map_modify_column_count(Map * map, MapModify type, MapModifyColumnLocation location) { gint x; gint y; Hex *shift_hex; if (type == MAP_MODIFY_INSERT && location == MAP_MODIFY_COLUMN_LEFT) { map->shrink_left = !map->shrink_left; if (map->shrink_left) { map->x_size++; for (y = 0; y < map->y_size; y++) { shift_hex = map->grid[y][0]; while (shift_hex != NULL) { shift_hex = move_hex(shift_hex, HEX_DIR_E); }; }; }; for (y = map->shrink_left ? 1 : 0; y < map->y_size; y += 2) { map_reset_hex(map, 0, y); }; } else if (type == MAP_MODIFY_INSERT && location == MAP_MODIFY_COLUMN_RIGHT) { if (map->shrink_right) { y = 1; } else { y = 0; map->x_size++; }; x = map->x_size - 1; while (y < map->y_size) { map_reset_hex(map, x, y); y += 2; }; map->shrink_right = !map->shrink_right; } else if (type == MAP_MODIFY_REMOVE && location == MAP_MODIFY_COLUMN_LEFT) { /* Clear the hexes */ for (y = map->shrink_left ? 1 : 0; y < map->y_size; y += 2) { map_reset_hex(map, 0, y); hex_free(map->grid[y][0]); }; if (map->shrink_left) { /* The map was already shrunk, so move all to the left */ for (y = 0; y < map->y_size; y++) { x = (map->shrink_right && y % 2 == 1) ? map->x_size - 2 : map->x_size - 1; shift_hex = map->grid[y][x]; while (shift_hex != NULL) { shift_hex = move_hex(shift_hex, HEX_DIR_W); }; }; map->x_size--; }; map->shrink_left = !map->shrink_left; } else { x = map->x_size - 1; for (y = map->shrink_right ? 0 : 1; y < map->y_size; y += 2) { map_reset_hex(map, x, y); hex_free(map->grid[y][x]); }; if (map->shrink_right) { map->x_size--; }; map->shrink_right = !map->shrink_right; } }
void map_modify_row_count(Map * map, MapModify type, MapModifyRowLocation location) { gint x; gint y; gint max; gint min; Hex *shift_hex; if (type == MAP_MODIFY_INSERT && location == MAP_MODIFY_ROW_TOP) { /* Shift the map to the right, if needed */ map->shrink_left = !map->shrink_left; if (map->shrink_left) { map->x_size++; for (y = 0; y < map->y_size; y++) { shift_hex = map->grid[y][0]; while (shift_hex != NULL) { shift_hex = move_hex(shift_hex, HEX_DIR_E); }; }; }; map->y_size++; /* Move all except the top row */ min = map->shrink_right ? 2 : 1; for (y = min; y < map->y_size - 1; y += 2) { shift_hex = map->grid[y][map->x_size - 1]; while (shift_hex != NULL) { shift_hex = move_hex(shift_hex, HEX_DIR_SW); }; }; /* Move the top row */ min = 1; max = map->x_size; for (x = min; x < max; x++) { shift_hex = map->grid[0][x]; while (shift_hex != NULL) { shift_hex = move_hex(shift_hex, HEX_DIR_SW); }; }; /* Remove column, if needed */ if (map->shrink_right) { map->x_size--; } map->shrink_right = !map->shrink_right; /* Create the new hexes */ min = map->shrink_left ? 1 : 0; max = map->x_size; for (x = min; x < max; x++) { map_reset_hex(map, x, 0); }; } else if (type == MAP_MODIFY_INSERT && location == MAP_MODIFY_ROW_BOTTOM) { map->y_size++; if (map->y_size % 2 == 0) { min = 0; max = map->shrink_right ? map->x_size - 1 : map->x_size; } else { min = map->shrink_left ? 1 : 0; max = map->x_size; }; for (x = min; x < max; x++) { map_reset_hex(map, x, map->y_size - 1); }; } else if (type == MAP_MODIFY_REMOVE && location == MAP_MODIFY_ROW_TOP) { /* Remove the top row */ min = map->shrink_left ? 1 : 0; max = map->x_size; for (x = min; x < max; x++) { map_reset_hex(map, x, 0); hex_free(map->grid[0][x]); }; /* Shift the map to the right, if needed */ map->shrink_left = !map->shrink_left; if (map->shrink_left) { map->x_size++; for (y = 1; y < map->y_size; y++) { shift_hex = map->grid[y][0]; while (shift_hex != NULL) { shift_hex = move_hex(shift_hex, HEX_DIR_E); }; }; }; /* Move all except the bottom row */ min = map->shrink_right ? 2 : 1; for (y = min; y < map->y_size - 1; y += 2) { shift_hex = map->grid[y][map->x_size - 1]; while (shift_hex != NULL) { shift_hex = move_hex(shift_hex, HEX_DIR_NW); }; }; /* Move the bottom row */ if (map->y_size % 2 == 0) { min = 0; max = map->shrink_right ? map->x_size - 1 : map->x_size; } else { min = map->shrink_left ? 1 : 0; max = map->x_size; }; for (x = min; x < max; x++) { shift_hex = map->grid[map->y_size - 1][x]; while (shift_hex != NULL) { shift_hex = move_hex(shift_hex, HEX_DIR_NW); }; }; /* Remove column, if needed */ if (map->shrink_right) { map->x_size--; }; map->shrink_right = !map->shrink_right; map->y_size--; } else { if (map->y_size % 2 == 0) { min = 0; max = map->shrink_right ? map->x_size - 1 : map->x_size; } else { min = map->shrink_left ? 1 : 0; max = map->x_size; }; for (x = min; x < max; x++) { map_reset_hex(map, x, map->y_size - 1); hex_free(map->grid[map->y_size - 1][x]); }; map->y_size--; } }
static gboolean free_hex(Hex * hex, G_GNUC_UNUSED gpointer closure) { hex_free(hex); return FALSE; }
int task_flash_upload(int argc, char *argv[]) { hex_t *h; flash_t f; uint8_t expected_sig[3]; uint16_t i; if (argc != 7) { warning("usage: %s %s %s <sig byte 0> <sig byte 1> <sig byte 2> <hex filename>\n", argv[0], argv[1], argv[2]); return EXIT_FAILURE; } h = hex_load_from_file(argv[6]); memset(&f, 0, sizeof(flash_t)); // setup the data structure from constants and arguments f.hello_retries = 10; for (i = 0; i < 3; ++i) expected_sig[i] = (uint8_t)strtoul(argv[i + 3], NULL, 16); f.addr.source = flash_pipes[0]; f.addr.target = flash_pipes[1]; printf("%s: updating flash via bootloader at address: %llx\n", argv[0], f.addr.target); radio = task_radio_setup(NRF24_PA_MAX, NRF24_1MBPS, FLASH_CHANNEL, f.addr.source, f.addr.target); #ifdef PI_DEBUG nrf24_print_details(radio); #endif if (!task_flash_hello_exchange(&f, expected_sig)) { warning("%s: HELLO exchange failed!\n", argv[0]); task_flash_print_details(&f); return EXIT_FAILURE; } task_flash_print_details(&f); if (!task_flash_upload_core(&f, h)) { warning("%s: downloading application space failed!\n", argv[0]); } if (!task_flash_download_core(&f, h->min_address, h->max_address)) { warning("%s: downloading application space failed!\n", argv[0]); } // compare hex for (i = 0; i < h->total_bytes; ++i) { if (h->mem[i] != f.hex->mem[i]) { warning("%s: verification of uploaded program failed at address %d (found %hhX, expected %hhX)", argv[0], i + h->min_address, f.hex->mem[i], h->mem[i]); return EXIT_FAILURE; } } hex_free(f.hex); // send application start f.packet[0] = FLASH_DONE; if (!task_send_packet(radio, "FLASH_DONE", f.packet, FLASH_DONE_SIZE, FLASH_SEND_POST_DELAY_US, f.addr.target)) return EXIT_FAILURE; return EXIT_SUCCESS; }