/****************************************************************************** * * project name: TI-68k Developer Utilities * file name: ttbin2str.c * initial date: 13/08/2000 * author: thomas.nussbaumer@gmx.net * description: enwraps inputfile into TI89 and TI92 strings * ******************************************************************************/ /* This file is part of TI-68k Developer Utilities. This file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. As a special exception, UNMODIFIED copies of ttbin2str may also be redistributed or sold without source code, for any purpose. (The Lesser General Public License restrictions do apply in other respects; for example, they cover modification of the program.) This exception notice must be removed on modified copies of this file. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include "ttversion.h" #include "revtools.h" #include "tt.h" #include "strhead.h" #ifdef FILE_REVISION #undef FILE_REVISION #endif #define FILE_REVISION "1.8" //============================================================================= // outputs usage information of this tool //============================================================================= void PrintUsage() { fprintf(USAGE_OUT, "Usage: ttbin2str <-s89 | -s92> [folder]\n\n" \ " -s89 .... generate TI89 string\n" \ " -s92 .... generate TI92 string\n" \ " -f .... don't print a warning if the string contains at least one 0x00\n" \ " (strings containing 0x00 may prove problematic to transfer using TI-Connect)\n\n" \ " enwraps any file into a TI89 or TI92 string variable\n"); } //============================================================================= // this routine is very similar to the Data2OTH routine, but it will a string // variable (now-a-days OTH types are preferred) //============================================================================= int Data2Str(FILE* fp, int calctype, char* folder, char* name, unsigned int length, unsigned char* data, int force) { StrHeader header; unsigned int i; unsigned int checksum; unsigned char* ptr; int size = sizeof(StrHeader)+length+5; int retval = size; unsigned char c; static int contains0x00 = 0; memset(&header,0,sizeof(StrHeader)); if (calctype == CALC_TI89) strncpy(header.signature,SIGNATURE_TI89,8); else strncpy(header.signature,SIGNATURE_TI92P,8); header.fill1[0] = 1; header.fill1[1] = 0; if (!folder) strcpy(header.folder,DEFAULT_FOLDER); else strncpy(header.folder,folder,8); header.fill2[0] = 0x01; header.fill2[1] = 0x00; header.fill2[2] = 0x52; header.fill2[3] = 0x00; header.fill2[4] = 0x00; header.fill2[5] = 0x00; strncpy(header.name,name,8); header.type[0] = 0x0c; // 0c header.type[1] = 0x00; header.type[2] = 0x03; header.type[3] = 0x00; header.size[0] = size & 0xff; header.size[1] = (size >> 8) & 0xff; header.size[2] = (size >> 16) & 0xff; header.size[3] = (size >> 24) & 0xff; header.fill3[0] = 0xA5; header.fill3[1] = 0x5A; header.fill3[2] = 0x00; header.fill3[3] = 0x00; header.fill3[4] = 0x00; header.fill3[5] = 0x00; size -= sizeof(StrHeader); size -= 2; header.datasize[0] = (size >> 8) & 0xff; header.datasize[1] = size & 0xff; checksum = header.datasize[0]; checksum += header.datasize[1]; ptr = (unsigned char*)&header; for (i=0;i