From: David C. <dch...@nw...> - 2006-02-23 09:50:58
|
Does anyone read bit.listserv.calc-ti? 'Cause I posted this experimental code. I do not think i heard back on gnu.gcc.help why every single program i use fopen() in segmentation faults: which is preventing testing this. The idea is make this because it is not in Tilp, but ATE needs it. My code is also attached if someone wants it that way nowadays. from David "Darwin" Chmelik //8xt.C //an .8xp <-> pc file converter //licence: gpl & Bsd (Berkeley "socialist digger", not: "software distribution." Digger is an old word like "hippy.") /* notes: .86p & basically .85p format: 0-7: "**TI86**" 8-A 1A 0A 00 B-34 comment 35-52 data length (57d less than file) 55... data last 2 cksum (lower 16 bits of... sum of ... data section") */ //#include <iostream> //std::cin() #include "posix.h" //personal: clrscr()... #include <stdio.h> //for file functions #include <stdlib.h> //for atoi() #include <string.h> //for strcat() int C_to_8xp(char *,char *,char *, char *,FILE *,FILE *); int Bxp_to_C(char *,char *,char *, char *,FILE *,FILE *); //"Bxp" is .8xp int main(void) { clrscr(); FILE * C, * Bxp; char ch,*input=(char *)malloc(255); char IsoAsc[95]={13,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126}; char TiAsc[95]={32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,214}; char range_TiAsc[95]={214,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126}; char codom_IsoAsc[95]={13,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126}; //codomain of Ti characters mapped Ascii:Ti_Ascii. maybe move 13 to end. do{ printf("%s","0 quit 1 open asm txt or C 2 save 85p or 86p\n"); ch=getchar(); if(ch=1) { printf("%c%s","enter file to open: "); fgets(input,255,stdin); //std::cin>>input; if(!(C=fopen(input,"a+"))) printf("%s","C file error\n"); else Bxp_to_C(IsoAsc,TiAsc,range_TiAsc,codom_IsoAsc,C,Bxp); } else if(ch=2) { printf("%c%s","enter file to save: "); fgets(input,255,stdin); //std::cin>>input; if(!(C=fopen(input,"a+"))) printf("%s","file error\n"); else C_to_8xp(IsoAsc,TiAsc,range_TiAsc,codom_IsoAsc,C,Bxp); } }while(ch); } //x86 data to .8xp int C_to_8xp(char *IsoAsc,char *TiAsc,char *range_TiAsc,char *codom_IsoAsc,FILE *C, FILE *Bxp) { char bufC[65535],buf8xp[65536]; //for files into mem int i=0,j=0,ck=0,ckcomment=0,ckdata=0; //loops, cksums while(sizeof(bufC[i]=fgetc(C))==sizeof(C)-(i-65535)){ ck+=bufC[i]; i++; } if(sizeof(bufC)!=sizeof(C)) return -1; for(i=53;i<sizeof(C);i++) { buf8xp[i]=range_TiAsc[bufC[i]]; ck+=buf8xp[i]; } fputs("**TI86**",Bxp); // fputc(26100,Bxp); //see if ok or mustbe \26\10\00 for(i=10;i<41;i++) fputc(buf8xp[i],Bxp); //no comment i=52; fputs(buf8xp,Bxp); //save .8xp data ck=atoi("**TI86**")+26+ckcomment+strlen(bufC); i=0; while(ckdata+=bufC[i++]); fputc(ck,Bxp); //write .8xp cksum return !(ck==buf8xp[sizeof(buf8xp-1)]*10+buf8xp[sizeof(buf8xp)]); } //.8xp file to pc int Bxp_to_C(char *IsoAsc,char *TiAsc,char *range_TiAsc,char *codom_IsoAsc,FILE *C,FILE *Bxp) { char bufC[65535],buf8xp[65536]; //for files into mem int i=53,ck=0,ckbuf8xp=0; //loop, cksums //either get .8xp header or exit if(!((buf8xp[0]=fgetc(Bxp)=='*')&&(buf8xp[1]=fgetc(Bxp)=='*')&&(buf8xp[2]=fgetc(Bxp)=='T')&&(buf8xp[3]=fgetc(Bxp)=='I')&&(buf8xp[4]=fgetc(Bxp)=='8')&&(buf8xp[5]=fgetc(Bxp)=='6')&&(buf8xp[6]=fgetc(Bxp)==26)&&(buf8xp[7]=fgetc(Bxp)=='*')&&(buf8xp[8]=fgetc(Bxp)=='*')&&(buf8xp[9]=fgetc(Bxp)==10)&&(buf8xp[10]=fgetc(Bxp)==0))) return 0; fread(&buf8xp[11],42,1,Bxp); //get comment, and next; data: for(i=53;i<sizeof(Bxp);i++){ buf8xp[i]=fgetc(Bxp); ckbuf8xp+=buf8xp[i]; } //either cksum right or halt int ck8xp=buf8xp[sizeof(buf8xp-1)]*10+buf8xp[sizeof(buf8xp)]; i=0; if(ck8xp!=ckbuf8xp) return 0; while(bufC[i]=IsoAsc[buf8xp[i]]){ ck+=buf8xp[i]; if(ck8xp!=ck) return -1; i++; }; if(!sizeof(buf8xp)+52!=sizeof(bufC)) return -1; fwrite(&bufC[53],sizeof(bufC)-52,1,C); //write to pc file } |