TIEXPORT3 int TICALL ti89_send_RTS(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); len = 17; } buffer[0] = LSB(LSW(varsize)); buffer[1] = MSB(LSW(varsize)); buffer[2] = LSB(MSW(varsize)); buffer[3] = MSB(MSW(varsize)); buffer[4] = vartype; buffer[5] = len; memcpy(buffer + 6, varname, len); buffer[6 + len] = 0x00; len += 6 + 1; // used by AMS <= 2.09 ? //if ((vartype == TI89_AMS) || (vartype == TI89_APPL)) len--; ticalcs_info(" PC->TI: RTS (size=0x%08X=%i, id=%02X, name=%s)", varsize, varsize, vartype, varname); return dbus_send(handle, ti68k_handle_to_dbus_mid(handle), DBUS_CMD_RTS, len, buffer); }
int ti82_send_SCR_h(CalcHandle* handle) { ticalcs_info(" PC->TI: SCR"); TRYF(dbus_send(handle, PC_TI8283, CMD_SCR, 2, NULL)); return 0; }
/* Request to send (std var header: NUL padded, fixed length) */ int ti82_send_RTS_h(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[16]; char trans[9]; buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; memcpy(buffer + 3, varname, 8); ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: RTS (size=0x%04X=%i, id=%02X, name=%s)", varsize, varsize, vartype, trans); if (vartype != TI8283_BKUP) { // backup: special header pad_buffer(buffer + 3, '\0'); TRYF(dbus_send(handle, PC_TI8283, CMD_RTS, 11, buffer)); } else { TRYF(dbus_send(handle, PC_TI8283, CMD_RTS, 9, buffer)); } return 0; }
int ti85_send_CTS(CalcHandle* handle) { ticalcs_info(" PC->TI: CTS"); TRYF(dbus_send(handle, PC_TI8586, CMD_CTS, 0, NULL)); return 0; }
/* Skip variable - rej_code [in]: a rejection code - int [out]: an error code */ int ti85_send_SKP(CalcHandle* handle, uint8_t rej_code) { TRYF(dbus_send(handle, PC_TI8586, CMD_SKP, 1, &rej_code)); ticalcs_info(" PC->TI: SKP (rejection code = %i)", rej_code); return 0; }
// 0xBB00: delay acknowledgement TIEXPORT3 int TICALL dusb_cmd_r_delay_ack(CalcHandle *handle) { DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); retval = dusb_recv_data(handle, pkt); if (!retval) { if (pkt->type == DUSB_VPKT_ERROR) { retval = ERR_CALC_ERROR2 + err_code_pkt(pkt); } else if (pkt->type != DUSB_VPKT_DELAY_ACK) { ticalcs_info("cmd_r_data_ack: expected type 0x%4X, received type 0x%4X", DUSB_VPKT_DELAY_ACK, pkt->type); retval = ERR_INVALID_PACKET; } } PAUSE(100); dusb_vtl_pkt_del(handle, pkt); return retval; }
/* Variable request (var header: NUL padded, fixed length) */ int ti85_send_REQ(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[16] = { 0 }; char trans[9]; buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; buffer[3] = strlen(varname); memcpy(buffer + 4, varname, 8); ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: REQ (size=0x%04X, id=%02X, name=%s)", varsize, vartype, trans); if ((handle->model == CALC_TI86) && (vartype >= TI86_DIR) && (vartype <= TI86_ZRCL)) { memset(buffer, 0, 9); buffer[2] = vartype; TRYF(dbus_send(handle, PC_TI86, CMD_REQ, 5, buffer)); } else if((handle->model == CALC_TI86) && (vartype == TI86_BKUP)) { memset(buffer, 0, 12); buffer[2] = vartype; TRYF(dbus_send(handle, PC_TI86, CMD_REQ, 11, buffer)); } else { pad_buffer_to_8_chars(buffer + 4, '\0'); TRYF(dbus_send(handle, PC_TI8586, CMD_REQ, 4 + strlen(varname), buffer)); } return 0; }
TIEXPORT3 int TICALL ti68k_send_VAR(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname, uint8_t target) { uint8_t buffer[32]; char trans[127]; uint8_t extra = (target == DBUS_MID_PC_TI92) ? 0 : ((vartype == TI89_BKUP) ? 0 : 1); uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); len = 17; } ticonv_varname_to_utf8_sn(handle->model, varname, trans, sizeof(trans), vartype); buffer[0] = LSB(LSW(varsize)); buffer[1] = MSB(LSW(varsize)); buffer[2] = LSB(MSW(varsize)); buffer[3] = MSB(MSW(varsize)); buffer[4] = vartype; buffer[5] = len; memcpy(buffer + 6, varname, len); buffer[6 + len] = 0x03; ticalcs_info(" PC->TI: VAR (size=0x%08X=%i, id=%02X, name=%s)", varsize, varsize, vartype, trans); return dbus_send(handle, target, DBUS_CMD_VAR, 6 + len + extra, buffer); }
int cmd_r_dir_enum_next(CalcHandle *h, char* name, uint32_t *size, uint8_t *type) { VirtualPacket* pkt = nsp_vtl_pkt_new(); uint8_t data_size; uint32_t date; int o; ticalcs_info(" next directory entry:"); TRYF(nsp_recv_data(h, pkt)); if(pkt->cmd != CMD_FM_DIRLIST_ENT) { if(pkt->data[0] == ERR_NO_MORE_TO_LIST) { nsp_vtl_pkt_del(pkt); return ERR_EOT; } else return ERR_CALC_ERROR3 + err_code(pkt->data[0]); } data_size = pkt->data[1] + 2; strcpy(name, (char *)pkt->data + 2); o = data_size - 10; if(size) *size = GUINT32_FROM_BE(*((uint32_t *)(pkt->data + o))); date = GUINT32_FROM_BE(*((uint32_t *)(pkt->data + o + 4))); if(type) *type = pkt->data[o + 8]; nsp_vtl_pkt_del(pkt); return 0; }
static inline int ti68k_send_simple_cmd(CalcHandle * handle, uint8_t target, uint8_t cmd, const char * cmdname, uint16_t length, const uint8_t* data) { VALIDATE_HANDLE(handle); ticalcs_info(" PC->TI: %s", cmdname); return dbus_send(handle, target, cmd, length, data); }
TIEXPORT3 int TICALL ti68k_recv_CNT(CalcHandle* handle) { uint8_t host, cmd; uint16_t sts; int ret; VALIDATE_HANDLE(handle); ret = dbus_recv(handle, &host, &cmd, &sts, NULL); if (ret) { return ret; } if (cmd == DBUS_CMD_EOT) { return ERR_EOT; // not really an error } if (cmd != DBUS_CMD_CNT) { return ERR_INVALID_CMD; } ticalcs_info(" TI->PC: CNT"); return 0; }
static int ti68k_recv_CTS(CalcHandle* handle, uint8_t is_92) { uint8_t host, cmd; uint16_t length; uint8_t *buffer; int ret; VALIDATE_HANDLE(handle); buffer = (uint8_t *)handle->buffer; ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; } if (cmd == DBUS_CMD_SKP) { return is_92 ? ERR_VAR_REJECTED : ERR_CALC_ERROR1 + err_code(buffer); } else if (cmd != DBUS_CMD_CTS) { return ERR_INVALID_CMD; } if (length != 0x0000) { return ERR_CTS_ERROR; } ticalcs_info(" TI->PC: CTS"); return 0; }
TIEXPORT3 int TICALL ti89_send_DEL(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); len = 17; } buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; buffer[3] = 0; buffer[4] = 0; buffer[5] = len; memcpy(buffer + 6, varname, len); ticalcs_info(" PC->TI: DEL (size=0x%08X=%i, id=%02X, name=%s)", varsize, varsize, vartype, varname); return dbus_send(handle, ti68k_handle_to_dbus_mid(handle), DBUS_CMD_DEL, 6 + len, buffer); }
TIEXPORT3 int TICALL ti92_send_RTS(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); len = 17; } buffer[0] = LSB(LSW(varsize)); buffer[1] = MSB(LSW(varsize)); buffer[2] = LSB(MSW(varsize)); buffer[3] = MSB(MSW(varsize)); buffer[4] = vartype; buffer[5] = len; memcpy(buffer + 6, varname, len); ticalcs_info(" PC->TI: RTS (size=0x%08X=%i, id=%02X, name=%s)", varsize, varsize, vartype, varname); return dbus_send(handle, DBUS_MID_PC_TI92, DBUS_CMD_RTS, 6 + len, buffer); }
// 0x0007: parameter request TIEXPORT3 int TICALL dusb_cmd_s_param_request(CalcHandle *handle, unsigned int npids, const uint16_t *pids) { DUSBVirtualPacket* pkt; unsigned int i; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_ATTRS(npids, pids); pkt = dusb_vtl_pkt_new_ex(handle, 2 + npids * sizeof(uint16_t), DUSB_VPKT_PARM_REQ, dusb_vtl_pkt_alloc_data(2 + npids * sizeof(uint16_t))); pkt->data[0] = MSB(npids); pkt->data[1] = LSB(npids); for (i = 0; i < npids; i++) { pkt->data[2*(i+1) + 0] = MSB(pids[i]); pkt->data[2*(i+1) + 1] = LSB(pids[i]); } retval = dusb_send_data(handle, pkt); dusb_vtl_pkt_del(handle, pkt); ticalcs_info(" npids=%i", npids); return retval; }
int ti73_send_RDY_h(CalcHandle* handle) { ticalcs_info(" PC->TI: RDY?"); TRYF(dbus_send(handle, PC_TI7383, CMD_RDY, 2, NULL)); return 0; }
// 0x0009: request directory listing TIEXPORT3 int TICALL dusb_cmd_s_dirlist_request(CalcHandle *handle, unsigned int naids, const uint16_t *aids) { DUSBVirtualPacket* pkt; unsigned int i; unsigned int j = 0; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_ATTRS(naids, aids); pkt = dusb_vtl_pkt_new_ex(handle, 4 + 2 * naids + 7, DUSB_VPKT_DIR_REQ, dusb_vtl_pkt_alloc_data(4 + 2 * naids + 7)); pkt->data[j++] = MSB(MSW(naids)); pkt->data[j++] = LSB(MSW(naids)); pkt->data[j++] = MSB(LSW(naids)); pkt->data[j++] = LSB(LSW(naids)); for (i = 0; i < naids; i++) { pkt->data[j++] = MSB(aids[i]); pkt->data[j++] = LSB(aids[i]); } pkt->data[j++] = 0x00; pkt->data[j++] = 0x01; pkt->data[j++] = 0x00; pkt->data[j++] = 0x01; pkt->data[j++] = 0x00; pkt->data[j++] = 0x01; pkt->data[j++] = 0x01; retval = dusb_send_data(handle, pkt); dusb_vtl_pkt_del(handle, pkt); ticalcs_info(" naids=%i", naids); return retval; }
/* Request variable (std var header: NUL padded, fixed length) */ int ti73_send_REQ_h(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname, uint8_t varattr) { uint8_t buffer[16] = { 0 }; char trans[17]; buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; memcpy(buffer + 3, varname, 8); pad_buffer(buffer + 3, '\0'); buffer[11] = 0x00; buffer[12] = (varattr == ATTRB_ARCHIVED) ? 0x80 : 0x00; ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: REQ (size=0x%04X, id=%02X, name=%s, attr=%i)", varsize, vartype, trans, varattr); if (vartype != TI83p_IDLIST && vartype != TI83p_GETCERT) { TRYF(dbus_send(handle, PC_TI7383, CMD_REQ, 11 + EXTRAS, buffer)); } else if(vartype != TI83p_GETCERT && handle->model != CALC_TI73) { TRYF(dbus_send(handle, PC_TI7383, CMD_REQ, 11, buffer)); } else { TRYF(dbus_send(handle, PC_TI73, CMD_REQ, 3, buffer)); } return 0; }
int ti85_send_ERR(CalcHandle* handle) { ticalcs_info(" PC->TI: ERR"); TRYF(dbus_send(handle, PC_TI8586, CMD_ERR, 2, NULL)); return 0; }
int ti73_send_VER_h(CalcHandle* handle) { ticalcs_info(" PC->TI: VER"); TRYF(dbus_send(handle, PC_TI7383, CMD_VER, 2, NULL)); return 0; }
/* Variable (std var header: NUL padded, variable length) */ int ti85_send_VAR(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[16]; char trans[17]; buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; ticonv_varname_to_utf8_s(handle->model, varname, trans, vartype); ticalcs_info(" PC->TI: VAR (size=0x%04X, id=%02X, name=%s)", varsize, vartype, trans); if (vartype != TI8586_BKUP) { // backup: special header buffer[3] = strlen(varname); memcpy(buffer + 4, varname, 8); TRYF(dbus_send(handle, PC_TI8586, CMD_VAR, 4 + strlen(varname), buffer)); } else { memcpy(buffer + 3, varname, 6); TRYF(dbus_send(handle, PC_TI8586, CMD_VAR, 9, buffer)); } return 0; }
int ti73_recv_VAR_h(CalcHandle* handle, uint16_t * varsize, uint8_t * vartype, char *varname, uint8_t * varattr) { uint8_t host, cmd; uint8_t *buffer = (uint8_t *)handle->priv2; uint16_t length; char trans[9]; TRYF(dbus_recv(handle, &host, &cmd, &length, buffer)); if (cmd == CMD_EOT) return ERR_EOT; // not really an error if (cmd == CMD_SKP) return ERR_VAR_REJECTED; if (cmd != CMD_VAR) return ERR_INVALID_CMD; if(length < 9 || length > 13) //if ((length != (11 + EXTRAS)) && (length != 9)) return ERR_INVALID_PACKET; *varsize = buffer[0] | (buffer[1] << 8); *vartype = buffer[2]; memcpy(varname, buffer + 3, 8); varname[8] = '\0'; *varattr = (buffer[12] & 0x80) ? ATTRB_ARCHIVED : ATTRB_NONE; ticonv_varname_to_utf8_s(handle->model, varname, trans, *vartype); ticalcs_info(" TI->PC: VAR (size=0x%04X, id=%02X, name=%s, attrb=%i)", *varsize, *vartype, trans, *varattr); return 0; }
int ti85_send_XDP(CalcHandle* handle, int length, uint8_t * data) { ticalcs_info(" PC->TI: XDP (0x%04X bytes)", length); TRYF(dbus_send(handle, PC_TI8586, CMD_XDP, length, data)); return 0; }
/* FLASH (special var header: size, id, flag, offset, page) */ int ti73_recv_VAR2_h(CalcHandle* handle, uint16_t * length, uint8_t * type, char *name, uint16_t * offset, uint16_t * page) { uint8_t host, cmd; uint8_t *buffer = (uint8_t *)handle->priv2; uint16_t len; TRYF(dbus_recv(handle, &host, &cmd, &len, buffer)); if (cmd == CMD_EOT) return ERR_EOT; // not really an error if (cmd == CMD_SKP) return ERR_VAR_REJECTED; if (cmd != CMD_VAR) return ERR_INVALID_CMD; if (len != 10) return ERR_INVALID_PACKET; *length = buffer[0] | (buffer[1] << 8); *type = buffer[2]; memcpy(name, buffer + 3, 3); name[3] = '\0'; *offset = buffer[6] | (buffer[7] << 8); *page = buffer[8] | (buffer[9] << 8); *page &= 0xff; ticalcs_info(" TI->PC: VAR (size=0x%04X, type=%02X, name=%s, offset=%04X, page=%02X)", *length, *type, name, *offset, *page); return 0; }
int ti82_send_ACK_h(CalcHandle* handle) { ticalcs_info(" PC->TI: ACK"); TRYF(dbus_send(handle, PC_TI8283, CMD_ACK, 2, NULL)); return 0; }
/* Variable (std var header: NUL padded, fixed length) */ int ti73_send_VAR_h(CalcHandle* handle, uint16_t varsize, uint8_t vartype, const char *varname, uint8_t varattr) { uint8_t buffer[16]; buffer[0] = LSB(varsize); buffer[1] = MSB(varsize); buffer[2] = vartype; memcpy(buffer + 3, varname, 8); buffer[11] = 0x00; buffer[12] = (varattr == ATTRB_ARCHIVED) ? 0x80 : 0x00; ticalcs_info(" PC->TI: VAR (size=0x%04X, id=%02X, name=%s, attr=%i)", varsize, vartype, varname, varattr); if (vartype != TI7383_BKUP) { // backup: special header pad_buffer(buffer + 3, '\0'); TRYF(dbus_send(handle, PC_TI7383, CMD_VAR, 11 + EXTRAS, buffer)); } else { TRYF(dbus_send(handle, PC_TI7383, CMD_VAR, 9, buffer)); } return 0; }
int ti82_send_EOT_h(CalcHandle* handle) { ticalcs_info(" PC->TI: EOT"); TRYF(dbus_send(handle, PC_TI8283, CMD_EOT, 2, NULL)); return 0; }
int ti73_send_CTS_h(CalcHandle* handle) { ticalcs_info(" PC->TI: CTS"); TRYF(dbus_send(handle, PC_TI7383, CMD_CTS, 0, NULL)); return 0; }
int ti82_recv_VAR_h(CalcHandle* handle, uint16_t * varsize, uint8_t * vartype, char *varname) { uint8_t host, cmd; uint8_t *buffer = (uint8_t *)handle->priv2; uint16_t length; char trans[9]; TRYF(dbus_recv(handle, &host, &cmd, &length, buffer)); if (cmd == CMD_EOT) return ERR_EOT; // not really an error if (cmd == CMD_SKP) return ERR_VAR_REJECTED; if (cmd != CMD_VAR) return ERR_INVALID_CMD; if ((length != 11) && (length != 9)) return ERR_INVALID_PACKET; *varsize = buffer[0] | (buffer[1] << 8); *vartype = buffer[2]; memcpy(varname, buffer + 3, 8); varname[8] = '\0'; ticonv_varname_to_utf8_s(handle->model, varname, trans, *vartype); ticalcs_info(" TI->PC: VAR (size=0x%04X=%i, id=%02X, name=%s)", *varsize, *varsize, *vartype, trans); return 0; }
TIEXPORT3 int TICALL ti92_send_SKP(CalcHandle* handle, uint8_t rej_code) { VALIDATE_HANDLE(handle); ticalcs_info(" PC->TI: SKP (rejection code = %i)", rej_code); return dbus_send(handle, DBUS_MID_PC_TI92, DBUS_CMD_SKP, 1, &rej_code); }