// parse a hex record and write the contents to flash if appropriate // return 1 if EOF, 0 otherwise extern u8 flash_write_hex_record(u8* data) { static hexRecord_t rec; static u32 addrOff = 0; static u32 dst; static char hexBuf[9] = {0,0,0,0,0,0,0,0,0}; int err; err = parse_raw_hex_record(data, &rec); if(err) { // print_dbg("\r\n failure parsing hex record: \r\n"); // print_dbg((const char*)data); screen_line(0, 6, "WARNING:", 0xf); screen_line(0, 7, "error parsing hex record!", 0xf); screen_refresh(); } else { switch(rec.type) { case HEX_EXT_LINEAR_ADDRESS: addrOff = rec.address; break; case HEX_DATA: /* // print_dbg("\r\n writing firmware to flash at address: "); */ /* // print_dbg_hex(addrOff + rec.address); */ dst = addrOff + rec.address; /// TEST!! if(dst < FIRMWARE_FLASH_ADDRESS) { // if(0) { // don't allow writes to anything below the runtime location! // this is where the bootloader lives! // app data goes at the end of flash. screen_line(0, 6, "WARNING:", 0xf); screen_line(0, 7, "scary address! ", 0xf); uint_to_hex_ascii( hexBuf, dst); screen_line(64, 7, hexBuf, 0xf); } else { flashc_memcpy( (void*)(dst), rec.data, rec.count, 1); } break; default: ;; } } return 0; }
void ui_state_game(void) { int i, x, y, go_x, go_y, result; int aimline_x1 = SCREEN_WIDTH - UI_TILE_WIDTH / 2, aimline_y1 = UI_Y_OFFSET + UI_TILE_HEIGHT / 2, aimline_x2, aimline_y2, strengthbar_width; int play_explosion = 0; int tank_direction, tank_strength, meter_direction; double radians; game_position_t result_pos; image_t *tile; led_clear(); for (i = 0; i < game_soldier_score; i++) led_set(7 - i, 1); for (i = 0; i < game_tank_score; i++) led_set(i, 1); if (game_soldier_score >= UI_MAX_POINTS || game_tank_score >= UI_MAX_POINTS) { ui_state = UI_SCOREBOARD; return; } game_reset(); while (1) { screen_clear(color_black); for (x = 0; x < GAME_WIDTH; x++) for (y = 0; y < GAME_HEIGHT; y++) { tile = game_is_scorched[y][x] ? img_dirt : img_grass; image_draw(x * UI_TILE_WIDTH, y * UI_TILE_HEIGHT + UI_Y_OFFSET, tile); } go_x = game_player.x; go_y = game_player.y; switch (ui_player_direction) { case GAME_NORTH: go_y--; break; case GAME_SOUTH: go_y++; break; case GAME_WEST: go_x--; break; case GAME_EAST: go_x++; break; } switch (ui_state) { case UI_GAME_SOLDIER: if (go_x >= 0 && go_x < GAME_WIDTH && go_y >= 0 && go_y < GAME_HEIGHT) { screen_rectangle( go_x * UI_TILE_WIDTH, go_y * UI_TILE_HEIGHT + UI_Y_OFFSET, UI_TILE_WIDTH, UI_TILE_HEIGHT, color_blue); } if (ui_play_point_sound) snd_play("sounds/point.raw"); else if (play_explosion) snd_play("sounds/eksplosjon.raw"); ui_play_point_sound = 0; play_explosion = 0; if (btn_is_pushed(7)) { result = game_move_player(ui_player_direction); if (result == GAME_MOVE_TANK) { ui_play_point_sound = 1; return; } if (result == GAME_MOVE_OK) { tank_direction = GAME_MIN_DIRECTION; meter_direction = UI_DIRECTION_SPEED; ui_state = UI_GAME_DIRECTION; } } if (btn_is_pushed(6)) { ui_player_direction = ((int)ui_player_direction + 1) % 4; } break; case UI_GAME_DIRECTION: if (btn_is_pushed(0)) { tank_strength = GAME_MIN_STRENGTH; meter_direction = UI_STRENGTH_SPEED; ui_state = UI_GAME_STRENGTH; break; } radians = tank_direction * M_PI / 180; aimline_x2 = aimline_x1 - (int)(cos(radians) * UI_TILE_WIDTH * 3); aimline_y2 = aimline_y1 + (int)(sin(radians) * UI_TILE_HEIGHT * 3); screen_line(aimline_x1, aimline_y1, aimline_x2, aimline_y2, color_red); if (tank_direction >= GAME_MAX_DIRECTION) meter_direction = -UI_DIRECTION_SPEED; if (tank_direction <= GAME_MIN_DIRECTION) meter_direction = UI_DIRECTION_SPEED; tank_direction += meter_direction; tank_direction = MAX(GAME_MIN_DIRECTION, tank_direction); tank_direction = MIN(GAME_MAX_DIRECTION, tank_direction); break; case UI_GAME_STRENGTH: if (btn_is_pushed(0)) { snd_play_wait("sounds/skyte.raw"); result_pos = game_shoot_bullet(tank_direction, tank_strength); ui_state = UI_GAME_SOLDIER; play_explosion = !game_position_equals(result_pos, GAME_SHOT_OOB); if (result_pos.x < 0 && result_pos.y < 0) { ui_play_point_sound = 1; return; } break; } screen_line(aimline_x1, aimline_y1, aimline_x2, aimline_y2, color_red); strengthbar_width = tank_strength * (SCREEN_WIDTH - UI_TILE_WIDTH) / GAME_MAX_STRENGTH; screen_fill_rectangle( SCREEN_WIDTH - UI_TILE_WIDTH / 2 - strengthbar_width, UI_TILE_HEIGHT / 2, strengthbar_width, UI_TILE_HEIGHT, color_red); if (tank_strength >= GAME_MAX_STRENGTH) meter_direction = -UI_STRENGTH_SPEED; if (tank_strength <= GAME_MIN_STRENGTH) meter_direction = UI_STRENGTH_SPEED; tank_strength += meter_direction; tank_strength = MAX(GAME_MIN_STRENGTH, tank_strength); tank_strength = MIN(GAME_MAX_STRENGTH, tank_strength); break; } image_draw( (GAME_WIDTH - 2) * UI_TILE_WIDTH, UI_Y_OFFSET, img_tank); image_draw( game_player.x * UI_TILE_WIDTH, game_player.y * UI_TILE_HEIGHT + UI_Y_OFFSET, img_soldier); screen_show_buffer(); } }