static int send_var (CalcHandle* handle, CalcMode mode, FileContent* content) { int i; uint8_t rej_code; uint16_t status; char *utf8; update_->cnt2 = 0; update_->max2 = content->num_entries; for (i = 0; i < content->num_entries; i++) { VarEntry *entry = content->entries[i]; if(entry->action == ACT_SKIP) continue; TRYF(ti85_send_RTS((uint16_t)entry->size, entry->type, entry->name)); TRYF(ti85_recv_ACK(&status)); TRYF(ti85_recv_SKP(&rej_code)); TRYF(ti85_send_ACK()); switch (rej_code) { case REJ_EXIT: return ERR_ABORT; case REJ_SKIP: continue; case REJ_MEMORY: return ERR_OUT_OF_MEMORY; default: // RTS break; } utf8 = ticonv_varname_to_utf8(handle->model, entry->name, entry->type); g_snprintf(update_->text, sizeof(update_->text), "%s", utf8); g_free(utf8); update_label(); TRYF(ti85_send_XDP(entry->size, entry->data)); TRYF(ti85_recv_ACK(&status)); TRYF(ti85_send_EOT()); ticalcs_info("\n"); update_->cnt2 = i+1; update_->max2 = content->num_entries; update_->pbar(); } return 0; }
static int send_key (CalcHandle* handle, uint16_t key) { TRYF(ti85_send_KEY(key)); TRYF(ti85_recv_ACK(&key)); return 0; }
static int recv_backup (CalcHandle* handle, BackupContent* content) { char varname[9] = { 0 }; g_snprintf(update_->text, sizeof(update_->text), _("Waiting for backup...")); update_label(); content->model = CALC_TI86; strcpy(content->comment, tifiles_comment_set_backup()); TRYF(ti85_recv_VAR(&(content->data_length1), &content->type, varname)); content->data_length2 = (uint8_t)varname[0] | ((uint8_t)varname[1] << 8); content->data_length3 = (uint8_t)varname[2] | ((uint8_t)varname[3] << 8); content->data_length4 = (uint8_t)varname[4] | ((uint8_t)varname[5] << 8); TRYF(ti85_send_ACK()); TRYF(ti85_send_CTS()); TRYF(ti85_recv_ACK(NULL)); strcpy(update_->text, ""); update_label(); update_->cnt2 = 0; update_->max2 = 4; update_->pbar(); content->data_part1 = tifiles_ve_alloc_data(65536); TRYF(ti85_recv_XDP(&content->data_length1, content->data_part1)); TRYF(ti85_send_ACK()); update_->cnt2++; update_->pbar(); content->data_part2 = tifiles_ve_alloc_data(65536); TRYF(ti85_recv_XDP(&content->data_length2, content->data_part2)); TRYF(ti85_send_ACK()); update_->cnt2++; update_->pbar(); if (content->data_length3) { content->data_part3 = tifiles_ve_alloc_data(65536); TRYF(ti85_recv_XDP(&content->data_length3, content->data_part3)); TRYF(ti85_send_ACK()); } else content->data_part3 = NULL; update_->cnt2++; update_->pbar(); content->data_part4 = tifiles_ve_alloc_data(65536); TRYF(ti85_recv_XDP(&content->data_length4, content->data_part4)); TRYF(ti85_send_ACK()); update_->cnt2++; update_->pbar(); return 0; }
static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr) { uint16_t unused; VarEntry *ve; char *utf8; uint16_t ve_size; content->model = CALC_TI86; strcpy(content->comment, tifiles_comment_set_single()); content->num_entries = 1; content->entries = tifiles_ve_create_array(1); ve = content->entries[0] = tifiles_ve_create(); memcpy(ve, vr, sizeof(VarEntry)); utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type); g_snprintf(update_->text, sizeof(update_->text), "%s", utf8); g_free(utf8); update_label(); // silent request TRYF(ti85_send_REQ((uint16_t)vr->size, vr->type, vr->name)); TRYF(ti85_recv_ACK(&unused)); TRYF(ti85_recv_VAR(&ve_size, &ve->type, ve->name)); ve->size = ve_size; TRYF(ti85_send_ACK()); TRYF(ti85_send_CTS()); TRYF(ti85_recv_ACK(NULL)); ve->data = tifiles_ve_alloc_data(ve->size); TRYF(ti85_recv_XDP(&ve_size, ve->data)); ve->size = ve_size; TRYF(ti85_send_ACK()); return 0; }
static int get_memfree (CalcHandle* handle, uint32_t* ram, uint32_t* flash) { uint16_t unused; uint8_t hl, ll, lh; uint8_t mem[8]; TRYF(ti85_send_REQ(0x0000, TI86_DIR, "")); TRYF(ti85_recv_ACK(&unused)); TRYF(ti85_recv_XDP(&unused, mem)); TRYF(ti85_send_EOT()); hl = mem[0]; ll = mem[1]; lh = mem[2]; *ram = (hl << 16) | (lh << 8) | ll; *flash = -1; return 0; }
static int recv_screen (CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap) { uint16_t max_cnt; int err; uint8_t buf[TI86_COLS * TI86_ROWS / 8]; sc->width = TI86_COLS; sc->height = TI86_ROWS; sc->clipped_width = TI86_COLS; sc->clipped_height = TI86_ROWS; TRYF(ti85_send_SCR()); TRYF(ti85_recv_ACK(NULL)); err = ti85_recv_XDP(&max_cnt, buf); // pb with checksum if (err != ERR_CHECKSUM) { TRYF(err) }; TRYF(ti85_send_ACK()); *bitmap = (uint8_t *)g_malloc(TI86_COLS * TI86_ROWS / 8); if(*bitmap == NULL) return ERR_MALLOC; memcpy(*bitmap, buf, TI86_COLS * TI86_ROWS / 8); return 0; }
static int get_dirlist (CalcHandle* handle, GNode** vars, GNode** apps) { TreeInfo *ti; GNode *folder; uint16_t unused; uint8_t hl, ll, lh; uint8_t mem[8]; char *utf8; // get list of folders & FLASH apps (*vars) = g_node_new(NULL); ti = (TreeInfo *)g_malloc(sizeof(TreeInfo)); ti->model = handle->model; ti->type = VAR_NODE_NAME; (*vars)->data = ti; (*apps) = g_node_new(NULL); ti = (TreeInfo *)g_malloc(sizeof(TreeInfo)); ti->model = handle->model; ti->type = APP_NODE_NAME; (*apps)->data = ti; TRYF(ti85_send_REQ(0x0000, TI86_DIR, "")); TRYF(ti85_recv_ACK(&unused)); TRYF(ti85_recv_XDP(&unused, mem)); TRYF(ti85_send_ACK()); hl = mem[0]; ll = mem[1]; lh = mem[2]; ti->mem_free = (hl << 16) | (lh << 8) | ll; folder = g_node_new(NULL); g_node_append(*vars, folder); // Add permanent variables (Func, Pol, Param, DifEq, ZRCL as WIND, WIND, WIND, WIND, WIND) { GNode *node; VarEntry *ve; ve = tifiles_ve_create(); ve->type = TI86_FUNC; node = g_node_new(ve); g_node_append(folder, node); ve = tifiles_ve_create(); ve->type = TI86_POL; node = g_node_new(ve); g_node_append(folder, node); ve = tifiles_ve_create(); ve->type = TI86_PARAM; node = g_node_new(ve); g_node_append(folder, node); ve = tifiles_ve_create(); ve->type = TI86_DIFEQ; node = g_node_new(ve); g_node_append(folder, node); ve = tifiles_ve_create(); ve->type = TI86_ZRCL; node = g_node_new(ve); g_node_append(folder, node); } for (;;) { VarEntry *ve = tifiles_ve_create(); GNode *node; int err; uint16_t ve_size; err = ti85_recv_VAR(&ve_size, &ve->type, ve->name); ve->size = ve_size; TRYF(ti85_send_ACK()); if (err == ERR_EOT) break; else if (err != 0) return err; node = g_node_new(ve); g_node_append(folder, node); utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); g_snprintf(update_->text, sizeof(update_->text), _("Parsing %s"), utf8); g_free(utf8); update_label(); } return 0; }
static int send_backup (CalcHandle* handle, BackupContent* content) { int err = 0; uint16_t length; char varname[9] = { 0 }; uint8_t rej_code; uint16_t status; length = content->data_length1; varname[0] = LSB(content->data_length2); varname[1] = MSB(content->data_length2); varname[2] = LSB(content->data_length3); varname[3] = MSB(content->data_length3); varname[4] = LSB(content->data_length4); varname[5] = MSB(content->data_length4); TRYF(ti85_send_VAR(content->data_length1, TI86_BKUP, varname)); TRYF(ti85_recv_ACK(&status)); g_snprintf(update_->text, sizeof(update_->text), _("Waiting for user's action...")); update_label(); do { // wait user's action if (update_->cancel) return ERR_ABORT; err = ti85_recv_SKP(&rej_code); } while (err == ERROR_READ_TIMEOUT); TRYF(ti85_send_ACK()); switch (rej_code) { case REJ_EXIT: case REJ_SKIP: return ERR_ABORT; case REJ_MEMORY: return ERR_OUT_OF_MEMORY; default: // RTS break; } strcpy(update_->text, ""); update_label(); update_->cnt2 = 0; update_->max2 = 4; TRYF(ti85_send_XDP(content->data_length1, content->data_part1)); TRYF(ti85_recv_ACK(&status)); update_->cnt2++; update_->pbar(); TRYF(ti85_send_XDP(content->data_length2, content->data_part2)); TRYF(ti85_recv_ACK(&status)); update_->cnt2++; update_->pbar(); if (content->data_length3) { TRYF(ti85_send_XDP(content->data_length3, content->data_part3)); TRYF(ti85_recv_ACK(&status)); } update_->cnt2++; update_->pbar(); TRYF(ti85_send_XDP(content->data_length4, content->data_part4)); TRYF(ti85_recv_ACK(&status)); update_->cnt2++; update_->pbar(); return 0; }
static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr) { int nvar = 0; int err = 0; char *utf8; uint16_t ve_size; g_snprintf(update_->text, sizeof(update_->text), _("Waiting for var(s)...")); update_label(); content->model = CALC_TI85; for (nvar = 0;; nvar++) { VarEntry *ve; content->entries = tifiles_ve_resize_array(content->entries, nvar+1); ve = content->entries[nvar] = tifiles_ve_create();; do { update_refresh(); if (update_->cancel) return ERR_ABORT; err = ti85_recv_VAR(&ve_size, &(ve->type), ve->name); ve->size = ve_size; } while (err == ERROR_READ_TIMEOUT); TRYF(ti85_send_ACK()); if (err == ERR_EOT) goto exit; TRYF(err); TRYF(ti85_send_CTS()); TRYF(ti85_recv_ACK(NULL)); utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type); g_snprintf(update_->text, sizeof(update_->text), "%s", utf8); g_free(utf8); update_label(); ve->data = tifiles_ve_alloc_data(ve->size); TRYF(ti85_recv_XDP(&ve_size, ve->data)); ve->size = ve_size; TRYF(ti85_send_ACK()); } exit: content->num_entries = nvar; if(nvar == 1) { strcpy(content->comment, tifiles_comment_set_single()); *vr = tifiles_ve_dup(content->entries[0]); } else { strcpy(content->comment, tifiles_comment_set_group()); *vr = NULL; } return 0; }
static int send_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content) { int i; int err; uint8_t rej_code; uint16_t status; char *utf8; update_->cnt2 = 0; update_->max2 = content->num_entries; for (i = 0; i < content->num_entries; i++) { VarEntry *entry = content->entries[i]; TRYF(ti85_send_VAR((uint16_t)entry->size, entry->type, entry->name)); TRYF(ti85_recv_ACK(&status)); g_snprintf(update_->text, sizeof(update_->text), _("Waiting for user's action...")); update_label(); do { // wait user's action update_refresh(); if (update_->cancel) return ERR_ABORT; err = ti85_recv_SKP(&rej_code); } while (err == ERROR_READ_TIMEOUT); TRYF(ti85_send_ACK()); switch (rej_code) { case REJ_EXIT: return ERR_ABORT; case REJ_SKIP: continue; case REJ_MEMORY: return ERR_OUT_OF_MEMORY; default: // RTS break; } utf8 = ticonv_varname_to_utf8(handle->model, entry->name, entry->type); g_snprintf(update_->text, sizeof(update_->text), "%s", utf8); g_free(utf8); update_label(); TRYF(ti85_send_XDP(entry->size, entry->data)); TRYF(ti85_recv_ACK(&status)); update_->cnt2 = i+1; update_->max2 = content->num_entries; update_->pbar(); } if ((mode & MODE_SEND_ONE_VAR) || (mode & MODE_SEND_LAST_VAR)) { TRYF(ti85_send_EOT()); TRYF(ti85_recv_ACK(NULL)); } return 0; }