void save_block(long filesize, char *base, char *ext) { char name[FILENAME_MAX+1]; char buffer[LINEMAX+1]; FILE *fp; strcpy(name,base); suffix_change(name,ext); if ( (fp=fopen(name,"wb"))==NULL) { snprintf(buffer,sizeof(buffer),"Can't open output file %s\n",name); myexit(buffer,1); } if (fwrite(memory,1,filesize,fp) != filesize ) { snprintf(buffer,sizeof(buffer),"Can't write to output file %s\n",name); myexit(buffer,1); } fclose(fp); }
int mameql_exec(char *target) { char filename[FILENAME_MAX+1]; struct stat binname_sb; FILE *fpin; FILE *fpout; int i,c; if ( help ) return -1; if ( binname == NULL ) { return -1; } if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".ql"); } else { strcpy(filename,outfile); } if ( description == NULL ) { description = binname; } if ((origin == -1) && ((crtfile == NULL) || ((origin = get_org_addr(crtfile)) == -1))) { origin = 0; } if ( exec == -1 ) { exec = origin; } if ( stat(binname, &binname_sb) < 0 || ( (fpin=fopen_bin(binname, NULL) ) == NULL )) { exit_log(1,"Can't open input file %s\n",binname); } if ( ( fpout = fopen(binname, "rb")) == NULL ) { exit_log(1,"Can't open input file %s\n", binname); } if ( ( fpout = fopen(filename, "wb")) == NULL ) { exit_log(1,"Can't open output file %s\n", filename); } /* Header */ writebyte(0xfd, fpout); writebyte(0x00, fpout); writebyte(0x80, fpout); writebyte(0x00, fpout); writebyte(0x00, fpout); writebyte(0xf9, fpout); writebyte(0x01, fpout); // Varies, what is it? /* Write the program name */ for ( i = 0; i < strlen(description); i++ ) { writebyte(description[i], fpout); } // Description terminator writebyte(0x1a, fpout); // Exec address writeword(exec, fpout); // Start address writeword(origin, fpout); // End address writeword(origin + binname_sb.st_size - 1, fpout); for ( i = 0; i < binname_sb.st_size; i++) { c = getc(fpin); writebyte(c,fpout); } fclose(fpin); fclose(fpout); return 0; }
int svi_exec(char *target) { char filename[FILENAME_MAX+1]; char name[11]; FILE *fpin, *fpout; int c; int i; int len; if ( help || binname == NULL ) return -1; if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".cas"); } else { strcpy(filename,outfile); } if ( (fpin=fopen(binname,"rb") ) == NULL ) { printf("Can't open input file\n"); exit(1); } /* * Now we try to determine the size of the file * to be converted */ if (fseek(fpin,0,SEEK_END)) { printf("Couldn't determine size of file\n"); fclose(fpin); exit(1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); if ( (fpout=fopen(filename,"wb") ) == NULL ) { printf("Can't open output file\n"); exit(1); } /* Write out the header file */ headtune (fpout); for (i=0; i<10;i++) writebyte(208,fpout); /* Deal with the filename */ if (strlen(binname) >= 6 ) { strncpy(name,binname,6); } else { strcpy(name,binname); strncat(name," ",6-strlen(binname)); } for (i=0;i<6;i++) writebyte(name[i],fpout); writeword(0,fpout); /* Now, the body */ headtune (fpout); writeword(34816,fpout); /* Start Address */ writeword(34816+len+1,fpout); /* End Address */ writeword(34816,fpout); /* Call Address */ /* (58 bytes written so far...) */ /* We append the binary file */ for (i=0; i<len;i++) { c=getc(fpin); writebyte(c,fpout); } /* Append some zeros, just to be sure not to get an error*/ for (i=0; i<16384;i++) writebyte(0,fpout); fclose(fpin); fclose(fpout); }
int gal_exec(char *target) { char filename[FILENAME_MAX+1]; char wavfile[FILENAME_MAX+1]; int c,i,j; int len; unsigned long checksum; FILE *fpin, *fpout; char basicdef[] = "\001\000A=USR(&2C3A)\015"; int basicdeflen=15; int datalen; if ( help ) return -1; if ( binname == NULL || !dumb && ( crtfile == NULL && origin == -1 ) ) { return -1; } if (loud) { gal_h_lvl = 0xFF; gal_l_lvl = 0; } else { gal_h_lvl = 0xe0; gal_l_lvl = 0x20; } if (dumb) { strcpy(filename,binname); } else { if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".gtp"); } else { strcpy(filename,outfile); } if ( blockname == NULL ) blockname = binname; /* Tomaz's code insertion starts here */ #if 0 /* basic start addr */ h2le_short(0x2c3a+len, &data[0]); /* basic end addr */ h2le_short(0x2c3a+len+basiclen, &data[2]); #endif if ( (fpin=fopen(binname,"rb") ) == NULL ) { myexit("File open error\n",1); } if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); datalen=4+len+basicdeflen; if ( (fpout=fopen(filename,"wb") ) == NULL ) { printf("Can't open output file %s\n",filename); myexit(NULL,1); } /* **** GTP Header **** */ /* *** Name block *** */ fputc(GTP_BLOCK_NAME,fpout); /* Block ID: NAME */ writeword(strlen(blockname)+1,fpout); /* NAME block size */ fputc(0,fpout); fputc(0,fpout); for (i=0; i<=strlen(blockname);i++) { /* block name string */ fputc(blockname[i],fpout); } /* *** Data block *** */ fputc(GTP_BLOCK_STANDARD,fpout); /* Block ID: STD SPEED DATA */ writeword(datalen+6,fpout); /* block size */ fputc(0,fpout); fputc(0,fpout); checksum=0; /* Init checksum */ writebyte_cksum(0xa5,fpout, &checksum); writeword_cksum(0x2c36,fpout, &checksum); /* ORG address */ writeword_cksum(0x2c36+datalen,fpout, &checksum); /* block end location */ writeword_cksum(0x2c36+4+len,fpout, &checksum); /* BASIC start address */ writeword_cksum(0x2c36+datalen,fpout, &checksum); /* block end location */ /* binary file */ for (i=0; i<len;i++) { c=getc(fpin); writebyte_cksum(c, fpout, &checksum); /* fputc(c,fpout);*/ } /* basic */ for (i=0; i<basicdeflen;i++) { /* block name string */ writebyte_cksum(basicdef[i], fpout, &checksum); /*fputc(basicdef[i],fpout);*/ } writebyte(255-(checksum%256),fpout); /* data checksum */ fclose(fpin); fclose(fpout); } /* ***************************************** */ /* Now, if requested, create the audio file */ /* ***************************************** */ if (( audio ) || ( fast ) || (loud)) { if ( (fpin=fopen(filename,"rb") ) == NULL ) { fprintf(stderr,"Can't open file %s for wave conversion\n",filename); myexit(NULL,1); } if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0,SEEK_SET); strcpy(wavfile,filename); suffix_change(wavfile,".RAW"); if ( (fpout=fopen(wavfile,"wb") ) == NULL ) { fprintf(stderr,"Can't open output raw audio file %s\n",wavfile); myexit(NULL,1); } /* leading silence and tone*/ for (i=0; i < 0x5000; i++) fputc(0x80, fpout); /* sync */ gal_rawout(fpout,0); /* program block */ if (len > 0) { for (i=0; i<len;i++) { c=getc(fpin); gal_rawout(fpout,c); } } /* trailing tone and silence (probably not necessary) */ /* gal_bit(fpout,0); gal_tone(fpout); for (i=0; i < 0x10000; i++) fputc(0x80, fpout); */ fclose(fpin); fclose(fpout); /* Now complete with the WAV header */ raw2wav(wavfile); } /* END of WAV CONVERSION BLOCK */ exit(0); }
int sc3000_exec(char *target) { char filename[FILENAME_MAX+1]; char wavfile[FILENAME_MAX+1]; char name[17]; FILE *fpin, *fpout; long pos, value; int c, i, len, blocklen; int screen_size; if ( help ) return -1; if ( binname == NULL || ( crtfile == NULL && origin == -1 ) ) { return -1; } if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".tap"); } else { strcpy(filename,outfile); } if ( blockname == NULL ) blockname = binname; if ( origin != -1 ) { pos = origin; } else { if ( !sf7000 ) if ( ( pos = parameter_search(crtfile,".sym","myzorg") ) == -1 ) { myexit("Could not find parameter ZORG (not z88dk compiled?)\n",1); } } if ( (fpin=fopen(binname,"rb") ) == NULL ) { fprintf(stderr,"Can't open input file %s\n",binname); myexit(NULL,1); } /* * Now we try to determine the size of the file * to be converted */ if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0,SEEK_SET); if ( (fpout=fopen(filename,"wb") ) == NULL ) { fprintf(stderr,"Can't open output file %s\n",filename); myexit(NULL,1); } /* Write out the .tap file */ if ( sf7000 ) { /* CLOADM mode header type */ writeword(24,fpout); /* header block size */ fputc(0x26,fpout); /* M/C header type (SF-7000 only) */ /* Deal with the filename */ checksum = 255; if (strlen(blockname) >= 16 ) { strncpy(name,blockname,16); } else { strcpy(name,blockname); strncat(name," ",16-strlen(blockname)); } for (i=0;i<=15;i++) writebyte_cksum(name[i],fpout,&checksum); /* len */ writebyte_cksum(len/256,fpout,&checksum); /* MSB */ writebyte_cksum(len%256,fpout,&checksum); /* LSB */ /* start */ writebyte_cksum(pos/256,fpout,&checksum); /* MSB */ writebyte_cksum(pos%256,fpout,&checksum); /* LSB */ fputc((checksum%256)^0xff,fpout); /* extra dummy data to prevent read overflows */ fputc(0,fpout); fputc(0,fpout); /* CLOADM object file body*/ writeword(len+4,fpout); /* header block size */ fputc(0x27,fpout); /* M/C data block type */ checksum = 255; for (i=0; i<len;i++) { c=getc(fpin); writebyte_cksum(c,fpout,&checksum); } fputc((checksum%256)^0xff,fpout); /* extra dummy data to prevent read overflows */ fputc(0,fpout); fputc(0,fpout); fclose(fpin); fclose(fpout); } else { /* BASIC loader header */ writeword(22,fpout); /* header block size */ fputc(0x16,fpout); /* BASIC header type */ /* Deal with the filename */ checksum = 255; if (strlen(blockname) >= 16 ) { strncpy(name,blockname,16); } else { strcpy(name,blockname); strncat(name," ",16-strlen(blockname)); } for (i=0;i<=15;i++) writebyte_cksum(name[i],fpout,&checksum); /* len */ writebyte_cksum((24+len)/256,fpout,&checksum); /* MSB */ writebyte_cksum((24+len)%256,fpout,&checksum); /* LSB */ fputc((checksum%256)^0xff,fpout); /* extra dummy data to prevent read overflows */ fputc(0,fpout); fputc(0,fpout); /* BASIC loader body */ writeword(24+len+4,fpout); /* header block size */ fputc(0x17,fpout); /* BASIC block type */ checksum = 255; /* PROGRAM LINE #1 */ writebyte_cksum(8,fpout,&checksum); /* prg line length */ writebyte_cksum(1,fpout,&checksum); /* prg line number */ writebyte_cksum(0,fpout,&checksum); writebyte_cksum(0,fpout,&checksum); writebyte_cksum(0,fpout,&checksum); /* Line size count starts here */ writebyte_cksum(174,fpout,&checksum); /* CALL */ writebyte_cksum(' ',fpout,&checksum); writebyte_cksum('&',fpout,&checksum); writebyte_cksum('H',fpout,&checksum); writebyte_cksum('9',fpout,&checksum); writebyte_cksum('8',fpout,&checksum); writebyte_cksum('1',fpout,&checksum); writebyte_cksum('7',fpout,&checksum); writebyte_cksum(':',fpout,&checksum); writebyte_cksum(151,fpout,&checksum); /* STOP */ /* Line size count ends here */ writebyte_cksum(13,fpout,&checksum); /* CR */ /* PROGRAM LINE #2 (code inside) */ writebyte_cksum(6,fpout,&checksum); /* prg line length (just a fake value) */ writebyte_cksum(2,fpout,&checksum); /* prg line number */ writebyte_cksum(0,fpout,&checksum); writebyte_cksum(0,fpout,&checksum); writebyte_cksum(0,fpout,&checksum); /* Line size count starts here */ writebyte_cksum(144,fpout,&checksum); /* REM */ writebyte_cksum(' ',fpout,&checksum); /* CODE (location $9817) */ for (i=0; i<len;i++) { c=getc(fpin); writebyte_cksum(c,fpout,&checksum); } /* Line size count ends here */ writebyte_cksum(13,fpout,&checksum); /* CR */ fputc((checksum%256)^0xff,fpout); /* extra dummy data to prevent read overflows */ fputc(0,fpout); fputc(0,fpout); } fclose(fpin); fclose(fpout); /* ***************************************** */ /* Now, if requested, create the audio file */ /* ***************************************** */ if (( audio ) || ( fast )) { if ( (fpin=fopen(filename,"rb") ) == NULL ) { fprintf(stderr,"Can't open file %s for wave conversion\n",filename); myexit(NULL,1); } if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0,SEEK_SET); strcpy(wavfile,filename); if ( survivors ) suffix_change(wavfile,".bit"); else suffix_change(wavfile,".RAW"); if ( (fpout=fopen(wavfile,"wb") ) == NULL ) { fprintf(stderr,"Can't open output raw audio file %s\n",wavfile); myexit(NULL,1); } /* leading silence */ if ( survivors ) { for (i=0; i < 30; i++) fputc(' ', fpout); } else { for (i=0; i < 0x3000; i++) fputc(0x20, fpout); } /* Data blocks */ while (ftell(fpin) < len) { /* leader tone (3600 records of bit 1) */ for (i=0; i < 3600; i++) sc3000_bit (fpout,1); /* data block */ blocklen = (getc(fpin) + 256 * getc(fpin)); for (i=0; (i < blocklen); i++) { c=getc(fpin); sc3000_rawout(fpout,c); } } /* trailing silence */ if ( survivors ) { for (i=0; i < 100; i++) fputc(' ', fpout); } else { for (i=0; i < 0x10000; i++) fputc(0x20, fpout); } fclose(fpin); fclose(fpout); /* Now complete with the WAV header */ if ( !survivors ) raw2wav(wavfile); } exit(0); }
int msx_exec(char* target) { char filename[FILENAME_MAX + 1]; char wavfile[FILENAME_MAX + 1]; FILE *fpin, *fpout; char name[11]; int c; int i; int pos; int len; if (help) return -1; if (binname == NULL || (!dumb && (crtfile == NULL && origin == -1))) { return -1; } if (origin != -1) { pos = origin; } else { if ((pos = get_org_addr(crtfile)) == -1) { myexit("Could not find parameter ZORG (not z88dk compiled?)\n", 1); } } if (loud) { msx_h_lvl = 0xFd; msx_l_lvl = 2; } else { msx_h_lvl = 0xe0; msx_l_lvl = 0x20; } if (dumb) { strcpy(filename, binname); } else { if (outfile == NULL) { strcpy(filename, binname); if (fmsx) suffix_change(filename, ".cas"); else suffix_change(filename, ".msx"); } else { strcpy(filename, outfile); } if ((fpin = fopen_bin(binname, crtfile)) == NULL) { printf("Can't open input file %s\n", binname); exit(1); } /* * Now we try to determine the size of the file * to be converted */ if (fseek(fpin, 0, SEEK_END)) { printf("Couldn't determine size of file\n"); fclose(fpin); exit(1); } len = ftell(fpin); fseek(fpin, 0L, SEEK_SET); if ((fpout = fopen(filename, "wb")) == NULL) { printf("Can't open output file\n"); exit(1); } /* Write out the header file */ if (fmsx) { /* Block identifier in a CAS file */ for (i = 0; i < 8; i++) fputc(blockid[i], fpout); for (i = 0; i < 10; i++) fputc(0xd0, fpout); /* Deal with the filename */ if (strlen(binname) >= 6) { strncpy(name, binname, 6); } else { strcpy(name, binname); strncat(name, " ", 6 - strlen(binname)); } for (i = 0; i < 6; i++) writebyte(name[i], fpout); /* Block identifier in a CAS file */ for (i = 0; i < 8; i++) fputc(blockid[i], fpout); } else fputc(254, fpout); writeword(pos, fpout); /* Start Address */ writeword(pos + len + 1, fpout); /* End Address */ writeword(pos, fpout); /* Call Address */ /* We append the binary file */ for (i = 0; i < len; i++) { c = getc(fpin); writebyte(c, fpout); } if (fmsx) { writeword(0, fpout); } fclose(fpin); fclose(fpout); } if ( disk ) { return fat_write_file_to_image("msxbasic", "raw", NULL, filename, NULL, NULL); } /* ***************************************** */ /* Now, if requested, create the audio file */ /* ***************************************** */ if ((audio) || (fast) || (loud)) { if ((fpin = fopen(filename, "rb")) == NULL) { fprintf(stderr, "Can't open file %s for wave conversion\n", filename); myexit(NULL, 1); } if (fseek(fpin, 0, SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n", 1); } len = ftell(fpin); fseek(fpin, 0, SEEK_SET); strcpy(wavfile, filename); suffix_change(wavfile, ".RAW"); if ((fpout = fopen(wavfile, "wb")) == NULL) { fprintf(stderr, "Can't open output raw audio file %s\n", wavfile); myexit(NULL, 1); } /* leading silence and tone*/ for (i = 0; i < 0x3000; i++) fputc(0x80, fpout); for (i = 0; (i < 8000); i++) msx_bit(fpout, 1); /* Skip the block id bytes */ if (fmsx) { for (i = 0; (i < 8); i++) c = getc(fpin); len -= 8; /* Copy the header */ if (dumb) printf("\nInfo: Program Name found in header: "); for (i = 0; (i < 16); i++) { c = getc(fpin); if (dumb && i > 10 && i < 17) printf("%c", c); msx_rawout(fpout, c); } len -= 16; } /* leading silence and tone*/ for (i = 0; i < 0x8000; i++) fputc(0, fpout); for (i = 0; (i < 2000); i++) msx_bit(fpout, 1); /* Skip the block id bytes */ if (fmsx) { for (i = 0; (i < 8); i++) c = getc(fpin); len -= 8; } /* program block */ if (len > 0) { for (i = 0; i < len; i++) { c = getc(fpin); msx_rawout(fpout, c); } } fclose(fpin); fclose(fpout); /* Now complete with the WAV header */ raw2wav(wavfile); } /* END of WAV CONVERSION BLOCK */ return 0; }
int nascom_exec(char *target) { char filename[FILENAME_MAX+1]; FILE *fpin, *fpout; int c; int i; int len; if ( help ) return -1; if ( binname == NULL ) { return -1; } if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".nas"); } else { strcpy(filename,outfile); } if ( origin == -1 ) { origin = 0xc80; } if ( (fpin=fopen(binname,"rb") ) == NULL ) { fprintf(stderr,"Can't open input file %s\n",binname); myexit(NULL,1); } /* * Now we try to determine the size of the file * to be converted */ if (fseek(fpin,0,SEEK_END)) { fprintf(stderr,"Couldn't determine size of file\n"); fclose(fpin); myexit(NULL,1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); if ( (fpout=fopen(filename,"wb") ) == NULL ) { myexit("Can't open output file\n",1); exit(1); } writehexword(origin,fpout); for (i=0; i<len;i++) { if ((i>0) && ((i%8)==0)) { fprintf(fpout, "%c%c\n",8,8); writehexword(origin,fpout); } c=getc(fpin); fputc(' ',fpout); writehex(c,fpout); origin++; } /* Padding the last 8 bytes block*/ if ( (i % 8) != 0 ) { while ( (i % 8) != 0 ) { fprintf(fpout, " 00"); i++; } fprintf(fpout, "%c%c\n",8,8); } fprintf(fpout, ".\n"); fclose(fpin); fclose(fpout); return 0; }
int enterprise_exec(char *target) { char filename[FILENAME_MAX+1]; FILE *fpin; FILE *fpout; int len; int c,i; if ( help ) return -1; if ( binname == NULL ) { return -1; } if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename, extfile); } else { strcpy(filename,outfile); } if ( (fpin=fopen_bin(binname, NULL) ) == NULL ) { fprintf(stderr,"Can't open input file %s\n",binname); myexit(NULL,1); } if (fseek(fpin,0,SEEK_END)) { fprintf(stderr,"Couldn't determine size of file\n"); fclose(fpin); myexit(NULL,1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); if ( (fpout=fopen(filename,"wb") ) == NULL ) { fclose(fpin); myexit("Can't open output file\n",1); } writebyte(0,fpout); writebyte(5,fpout); writeword(len,fpout); for (i=1;i<=12;i++) writebyte(0,fpout); for ( i = 0; i < len; i++) { c = getc(fpin); writebyte(c,fpout); } fclose(fpin); fclose(fpout); return 0; }
int trs80_exec() { char filename[FILENAME_MAX+1]; char wavfile[FILENAME_MAX+1]; char name[11]; FILE *fpin, *fpout; int c; int i; int len; int pos; unsigned char cksum; char ckflag; if ( help || binname == NULL || !dumb && ( crtfile == NULL ) ) { return -1; } if ( origin != -1 ) { pos = origin; } else { if ( ( pos = parameter_search(crtfile,".sym","myzorg") ) == -1 ) { myexit("Could not find parameter ZORG (not z88dk compiled?)\n",1); } } if ( audio ) cmd = 0; if (( blocksz < 10 ) || ( blocksz > 256 )) { myexit("Invalid block size: %d\n",blocksz); } if ( cmd ) blocksz-=2; if (dumb) { strcpy(filename,binname); } else { if ( outfile == NULL ) { strcpy(filename,binname); if ( cmd ) suffix_change(filename,".cmd"); else suffix_change(filename,".cas"); } else { strcpy(filename,outfile); } if ( (fpin=fopen(binname,"rb") ) == NULL ) { fprintf(stderr,"Can't open input file %s\n",binname); myexit(NULL,1); } /* * Now we try to determine the size of the file * to be converted */ if ( fseek(fpin,0,SEEK_END) ) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); /* * CMD file creation */ if ( (fpout=fopen(filename,"wb") ) == NULL ) { fprintf(stderr,"Can't open output CMD file %s\n",filename); myexit(NULL,1); } if ( !cmd ) { /* * CAS file mode */ for (i=0; i<256; i++) fputc( 0, fpout); fputc( 0xA5, fpout ); fputc( 0x55, fpout ); /* Deal with the filename */ if (strlen(binname) >= 6 ) { strncpy(name,binname,6); } else { strcpy(name,binname); strncat(name," ",6-strlen(binname)); } for (i=0;i<6;i++) writebyte(toupper(name[i]),fpout); } /* * Main loop */ for (i=0; i<len; i++) { if ( (i%blocksz)== 0 ) { if ( cmd ) writebyte (1,fpout); /* Block signature byte in CMD mode */ else writebyte (0x3c,fpout); /* Escape char for block signature in CAS mode */ if ( (i+blocksz) > len ) if ( cmd ) writebyte (len-i+2,fpout); /* last block length (remainder) */ else writebyte (len-i,fpout); /* last block length (remainder) */ else if ( cmd ) if (blocksz == 254) writebyte (0,fpout); /* block length (256 bytes) */ else writebyte (blocksz+2,fpout); /* block length */ else if (blocksz == 256) writebyte (0,fpout); /* block length (256 bytes) */ else writebyte (blocksz,fpout); /* block length (CAS mode)*/ writeword (pos+i,fpout); /* block memory location */ cksum=(pos+i)%256+(pos+i)/256; /* Checksum (for CAS mode) */ } c=getc(fpin); cksum +=c; /* Checksum (for CAS mode) */ fputc(c,fpout); ckflag=1; if ( !cmd && ( (i+1)%blocksz == 0 ) ) { writebyte (cksum,fpout); /* Checksum (for CAS mode) */ ckflag=0; } } if ( cmd ) { writebyte (2,fpout); /* Two bytes end marker in CMD mode*/ writebyte (2,fpout); } else { if ( ckflag ) writebyte (cksum,fpout); /* Checksum */ writebyte (0x78,fpout); /* Escape char for EOF in CAS mode */ } writeword (pos,fpout); /* Start address */ fclose(fpin); fclose(fpout); } /* ***************************************** */ /* Now, if requested, create the audio file */ /* ***************************************** */ if (( audio ) || ( fast ) || (loud)) { if ( (fpin=fopen(filename,"rb") ) == NULL ) { fprintf(stderr,"Can't open file %s for wave conversion\n",filename); myexit(NULL,1); } if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0,SEEK_SET); strcpy(wavfile,filename); suffix_change(wavfile,".RAW"); if ( (fpout=fopen(wavfile,"wb") ) == NULL ) { fprintf(stderr,"Can't open output raw audio file %s\n",wavfile); myexit(NULL,1); } /* leading silence */ for (i=0; i < 0x3000; i++) fputc(0x80, fpout); /* Skip the tone leader bytes */ do { len--; c=getc(fpin); } while ((c == 0) && (len >0)); if ( len < 10 ) { fprintf(stderr,"Invalid .CAS file %s\n",filename); myexit(NULL,1); } if ( c != 0xA5 ) { fprintf(stderr,"Header marker not found:0xA5\n"); myexit(NULL,1); } len--; c=getc(fpin); /* if ( c != 0x55 ) { fprintf(stderr,"Header marker not found:0x55\n"); myexit(NULL,1); } */ for (i=0; i<600;i++) { trs80_rawout(fpout,0); } trs80_rawout(fpout,0xa5); trs80_rawout(fpout,c); /* Show filename */ if (dumb) printf("\nInfo: Program Name found in header: "); for (i=0; (i < 6); i++) { c=getc(fpin); if (dumb) printf("%c",c); trs80_rawout(fpout,c); } if (dumb) printf("\n"); /* Short extra pause */ for ( i=0; i < 48; i++ ) fputc (0x80,fpout); if (len > 0) { for (i=0; i<len;i++) { c=getc(fpin); trs80_rawout(fpout,c); } } fclose(fpin); fclose(fpout); /* Now complete with the WAV header */ raw2wav(wavfile); } /* END of WAV CONVERSION BLOCK */ return 0; }
int sos_exec(char *target) { char filename[FILENAME_MAX+1]; FILE *fpin; FILE *fpout; int len; long pos; int c,i; if ( help ) return -1; if ( binname == NULL || ( crtfile == NULL && origin == -1 ) ) { return -1; } if ( origin != -1 ) { pos = origin; } else { if ( ( pos = parameter_search(crtfile,".sym","myzorg") ) == -1 ) { myexit("Could not find parameter ZORG (not z88dk compiled?)\n",1); } } if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".obj"); } else { strcpy(filename,outfile); } if ( (fpin=fopen(binname,"rb") ) == NULL ) { fprintf(stderr,"Can't open input file %s\n",binname); myexit(NULL,1); } if (fseek(fpin,0,SEEK_END)) { fprintf(stderr,"Couldn't determine size of file\n"); fclose(fpin); myexit(NULL,1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); if ( (fpout=fopen(filename,"wb") ) == NULL ) { fclose(fpin); myexit("Can't open output file\n",1); } fprintf(fpout,"_SOS 01 %4X %4X%c",pos,pos,10); for ( i = 0; i < len; i++) { c = getc(fpin); writebyte(c,fpout); } fclose(fpin); fclose(fpout); return 0; }
int mz_exec(char *target) { char filename[FILENAME_MAX+1]; char name[11]; FILE *fpin, *fpout; int c; int i; int len; if ( help || binname == NULL ) return -1; if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".m12"); } else { strcpy(filename,outfile); } if ( (fpin=fopen(binname,"rb") ) == NULL ) { printf("Can't open input file %s\n",binname); exit(1); } /* * Now we try to determine the size of the file * to be converted */ if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); if ( (fpout=fopen(filename,"wb") ) == NULL ) { fclose(fpin); printf("Can't open output file %s\n",filename); myexit(NULL,1); } /* Write out the MZ file */ fputc(1,fpout); /* MZ80K M/C file */ fputc('P',fpout); fputc('R',fpout); fputc('G',fpout); for (i=0;i<14;i++) fputc(13,fpout); writeword(len,fpout); writeword(4608,fpout); writeword(4608,fpout); for (i=0;i<104;i++) fputc(0,fpout); /* ... M/C ...*/ for (i=0; i<len;i++) { c=getc(fpin); fputc(c,fpout); } fclose(fpin); fclose(fpout); }
int nec_exec(char *target) { char filename[FILENAME_MAX+1]; char wavfile[FILENAME_MAX+1]; char name[12]; FILE *fpin, *fpout; int c, i, j; int len, stage; int zerocount; unsigned char* prefix; int prefix_length; int codeseg; if ( binname == NULL ) { return -1; } // if (dumb) { // strcpy(filename,binname); // } else { if (origin == -1) { if ( ( origin = parameter_search(crtfile,".sym","myzorg") ) == -1 ) { fprintf(stderr,"Warning: could not get the 'myzorg' value, ORG defaults to MODE1 ($C437)\n"); origin = 0xC437; } } if (mode == -1) { switch (origin) { case MODE1_ADDRESS_CODESEG: mode=MODE1; break; case MODE2_ADDRESS_CODESEG: mode=MODE2; break; case MODE5_ADDRESS_CODESEG: mode=MODE5; break; case MODEROM_ADDRESS_CODESEG: mode=MODEROM; break; case MODEN88_ADDRESS_CODESEG: mode=MODEN88; break; default: fprintf(stderr,"Unhandled value for ORG: %i\n",origin); return -1; } } //fprintf(stderr,"Mode: %i\n",mode); if ( strcmp(binname,filename) == 0 ) { fprintf(stderr,"Input and output file names must be different\n"); myexit(NULL,1); } if ( (fpin=fopen(binname,"rb") ) == NULL ) { fprintf(stderr,"Can't open input file %s\n",binname); myexit(NULL,1); } /* * Now we try to determine the size of the file * to be converted */ if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".cas"); } else { strcpy(filename,outfile); } if ( (fpout=fopen(filename,"wb") ) == NULL ) { fclose(fpin); fprintf(stderr,"Can't open output file %s\n",filename); myexit(NULL,1); } // MSB of BASIC RAM start address switch (mode) { case MODE1: prefix = prefix_p6; prefix_length = prefix_length_p6; prefix[17] = 0xc4; prefix[46] = 0xc4; prefix[23] = 'C'; prefix[24] = '4'; prefix[48] = len%256; prefix[49] = len/256; codeseg = MODE1_ADDRESS_CODESEG; break; case MODE5: prefix = prefix_p6; prefix_length = prefix_length_p6; prefix[17] = 0x80; prefix[46] = 0x80; prefix[23] = '8'; prefix[24] = '0'; prefix[48] = len%256; prefix[49] = len/256; codeseg = MODE5_ADDRESS_CODESEG; break; case MODEN88: prefix = prefix_p88; prefix_length = prefix_length_p88; codeseg = MODEN88_ADDRESS_CODESEG; break; case MODEROM: prefix = prefix_rom; prefix_length = prefix_length_rom; codeseg = MODEROM_ADDRESS_CODESEG; break; case MODE2: default: prefix = prefix_p6; prefix_length = prefix_length_p6; //prefix[23] = '8'; //prefix[24] = '4'; prefix[48] = len%256; prefix[49] = len/256; codeseg = MODE2_ADDRESS_CODESEG; break; } // set p6 file name for (i = 0; i < 6; i++) { prefix[i + 0x0a] = filename[i]; } // write prefix for (i = 0; i < prefix_length; i++) { fputc(prefix[i],fpout); } /* ... M/C ...*/ for (i=0; i<len;i++) { c=getc(fpin); fputc(c,fpout); } if (mode != MODEROM) { // write suffix for (i = 0; i < 12; i++) { fputc(0,fpout); } } else { // write trailing bytes for (; i < (0x8000-MODEROM_ADDRESS_CODESEG); i++) { //putc(memory[i], out); fputc(0,fpout); } } fclose(fpin); fclose(fpout); // } /* ***************************************** */ /* Now, if requested, create the audio file */ /* ***************************************** */ if (( audio ) || ( fast )) { if ( (fpin=fopen(filename,"rb") ) == NULL ) { fprintf(stderr,"Can't open file %s for wave conversion\n",filename); myexit(NULL,1); } if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0,SEEK_SET); strcpy(wavfile,filename); suffix_change(wavfile,".RAW"); if ( (fpout=fopen(wavfile,"wb") ) == NULL ) { fprintf(stderr,"Can't open output raw audio file %s\n",wavfile); myexit(NULL,1); } /* leading silence */ for (i=0; i < 0x3000; i++) fputc(0x20, fpout); /* leading tone */ for (i=0; i < 3600; i++) nec_bit (fpout,1); stage=0; for (i=0; (i < len); i++) { c=getc(fpin); switch(stage) { // BASIC Header: seek for the filename termination case 0: if (c==0) { nec_rawout(fpout,0); stage++; for (j=0; j < 600; j++) nec_bit (fpout,1); c=getc(fpin); } break; // BASIC Block + MC stub: seek for more than 3 zeroes in sequence case 1: if ((c==0) && (zerocount == 3) ) { stage++; while ((c=getc(fpin)) == 0) zerocount++; for (j=3; j <= zerocount; j++) nec_rawout(fpout,0); zerocount = 0; // Not necessary for (j=0; j < 600; j++) nec_bit (fpout,1); } break; default: break; //fprintf(stderr,"Problems",origin); //return -1; } nec_rawout(fpout,c); if (c) zerocount = 0; else zerocount++; } // tail for (j=0; j < 200; j++) nec_bit (fpout,1); /* Data blocks */ //while (ftell(fpin) < len) { /* leader tone (3600 records of bit 1) */ // for (i=0; i < 3600; i++) // nec_bit (fpout,1); /* data block */ // blocklen = (getc(fpin) + 256 * getc(fpin)); // for (i=0; (i < blocklen); i++) { // c=getc(fpin); // nec_rawout(fpout,c); // } //} /* trailing silence */ for (i=0; i < 0x10000; i++) fputc(0x20, fpout); fclose(fpin); fclose(fpout); /* Now complete with the WAV header */ raw2wav(wavfile); } exit(0); }
int newbrain_exec() { char filename[FILENAME_MAX+1]; FILE *fpin, *fpout, *fpout2; int pos; int c; int i,p,l,b; int len; int lnum; int blocks; int blcount; unsigned long checksum; if ( help || binname == NULL || ( crtfile == NULL && origin == -1 ) ) { return -1; } if ( blockname == NULL ) blockname = binname; if ( outfile == NULL ) { strcpy(filename,binname); suffix_change(filename,".txt"); } else { strcpy(filename,outfile); } if ( origin != -1 ) { pos = origin; } else { if ( ( pos = parameter_search(crtfile,".sym","MYZORG") ) == -1 ) { myexit("Could not find parameter ZORG (not z88dk compiled?)\n",1); } } if ( (fpin=fopen(binname,"rb") ) == NULL ) { fprintf(stderr,"Can't open input file %s\n",binname); myexit(NULL,1); } /* * Now we try to determine the size of the file * to be converted */ if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of file\n",1); } len=ftell(fpin); fseek(fpin,0L,SEEK_SET); if ( ascii ) { /* All in a BASIC program */ if ( (fpout=fopen(filename,"w") ) == NULL ) { printf("Can't open output text format file %s\n",filename); myexit(NULL,1); } fprintf(fpout,"10 IF TOP>%i THEN RESERVE TOP-%i\n",pos-1,pos-1); fprintf(fpout,"20 FOR i=0TO%i:READa:POKE%i+i,a:NEXT i\n",len-1,pos); fprintf(fpout,"30 CALL%i\n",pos); fprintf(fpout,"40 END",pos); lnum=100; /* ... M/C ...*/ for (i=0; i<len;i++) { if ((i % 60) == 0) { fprintf(fpout,"\n"); fprintf(fpout,"%i DATA ",lnum); lnum=lnum+2; } else fputc(',',fpout); c=getc(fpin); fprintf(fpout,"%i",c); } fprintf(fpout,"\n"); fclose(fpin); fclose(fpout); } else /* Much more efficient LOADER */ { /* binary block */ suffix_change(filename,".dat"); if ( (fpout2=fopen(filename,"wb") ) == NULL ) { printf("Can't open output dat Binary file %s\n",filename); myexit(NULL,1); } checksum=0x3b; /* Init checksum */ fputc (0,fpout2); writeword_cksum(strlen(blockname), fpout2, &checksum); for (i=0; i<strlen(blockname); i++) { fputc (blockname[i],fpout2); checksum += blockname[i]; } writebyte_cksum(0x81, fpout2, &checksum); writeword((checksum%65536),fpout2); /* name checksum */ /* Block */ for (b=0; b<=(len/1024); b++) { for (i=0; i<10;i++) /* block leading zeroes */ fputc (0,fpout2); checksum=0x3b; /* Init checksum */ p = (b * 1024) + 1024 -1; /* set the pointer at the end of the block */ l = 1024; if ( p > (len - 1) ) { /* is last block smaller ? */ p = len - 1; l = len - (b * 1024); } /* Block length*/ writeword_cksum(l, fpout2, &checksum); for (i=p; i>(p-l); i--) { fseek(fpin, i, SEEK_SET); c = getc(fpin); writebyte_cksum(c, fpout2, &checksum); } writebyte_cksum(b+1, fpout2, &checksum); writeword((checksum%65536), fpout2); } for (i=0; i<9;i++) /* tail */ fputc (0,fpout2); fclose(fpin); fclose(fpout2); /* TEMP BASIC loader */ suffix_change(filename,".tmp"); if ( (fpout=fopen(filename,"wb") ) == NULL ) { printf("Can't open temp output file %s\n",filename); myexit(NULL,1); } fputc(0x0d,fpout); fprintf(fpout,"10 "); fputc(0xAC,fpout); /* RESERVE */ fputc(0xA8,fpout); /* TOP */ fputc(0x82,fpout); /* - */ fprintf(fpout,"%i",pos); /* memory location */ fputc(0x0d,fpout); fprintf(fpout,"20 "); fputc('b',fpout); fputc(0x8c,fpout); /* = */ fprintf(fpout,"121:"); /* 121 */ fputc(0x89,fpout); /* IF */ fputc(0xa4,fpout); /* PEEK */ fprintf(fpout,"(51)"); fputc(0x8d,fpout); /* > */ fprintf(fpout,"127"); fputc(0xb4,fpout); /* THEN */ fprintf(fpout,"b"); fputc(0x8c,fpout); /* = */ fputc(0xa4,fpout); /* PEEK */ fprintf(fpout,"(168)"); fputc(0x81,fpout); /* + */ fprintf(fpout,"256"); fputc(0x83,fpout); /* * */ fputc(0xa4,fpout); /* PEEK */ fprintf(fpout,"(169):"); fputc(0x9e,fpout); /* POKE */ fprintf(fpout,"169,"); fputc(0x96,fpout); /* INT */ fprintf(fpout,"((b"); fputc(0x81,fpout); /* + */ fprintf(fpout,"23)"); fputc(0x84,fpout); /* / */ fprintf(fpout,"256):"); fputc(0x9e,fpout); /* POKE */ fprintf(fpout,"168,b"); fputc(0x81,fpout); /* + */ fprintf(fpout,"23"); fputc(0x82,fpout); /* - */ fprintf(fpout,"256"); fputc(0x83,fpout); /* * */ fputc(0xa4,fpout); /* PEEK */ fprintf(fpout,"(169)"); fputc(0x0d,fpout); fprintf(fpout,"30 "); fputc(0x8b,fpout); /* FOR */ fprintf(fpout," i "); fputc(0x8c,fpout); /* = */ fprintf(fpout," 0 "); fputc(0xb6,fpout); /* TO */ fprintf(fpout," 22:"); fputc(0x9c,fpout); /* READ */ fprintf(fpout," c:"); fputc(0x9e,fpout); /* POKE */ fprintf(fpout," b"); fputc(0x81,fpout); /* + */ fprintf(fpout,"i,c:"); fputc(0x8c,fpout); /* NEXT */ fprintf(fpout," i:"); fputc(0x9d,fpout); /* DATA */ fprintf(fpout," 253,110,32,253,102,33,22,0,30,1,1,"); fprintf(fpout,"%i",len%256); /* LSB for Length */ fputc(',',fpout); fprintf(fpout,"%i",len/256); /* MSB for Length */ fprintf(fpout,",231,49,119,35,11,120,177,200,24,246"); fputc(0x0d,fpout); fprintf(fpout,"40 "); fputc(0x97,fpout); /* OPEN */ //fputc(' ',fpout); fputc(0xb3,fpout); /* # */ fprintf(fpout,"1,"); fputc('"',fpout); fprintf(fpout,"%s",blockname); fputc('"',fpout); fputc(0x0d,fpout); fprintf(fpout,"50 "); fputc(0x9f,fpout); /* CALL */ fprintf(fpout," b : "); fputc(0x9f,fpout); /* CALL */ fprintf(fpout," %i",pos); fputc(0x0d,fpout); fputc(0x04,fpout); fputc(0x0d,fpout); fclose(fpout); /* Now convert in tape format */ if ( (fpin=fopen(filename,"rb") ) == NULL ) { fprintf(stderr,"Can't read temp file%s\n",binname); myexit(NULL,1); } if (fseek(fpin,0,SEEK_END)) { fclose(fpin); myexit("Couldn't determine size of temp file\n",1); } len=ftell(fpin); suffix_change(filename,".bas"); if ( (fpout2=fopen(filename,"wb") ) == NULL ) { printf("Can't open output BASIC Binary file %s\n",filename); myexit(NULL,1); } /* header for binary block */ checksum=0x3b; /* Init checksum */ fputc (0,fpout2); writeword_cksum(strlen(filename), fpout2, &checksum); for (i=0; i<strlen(filename); i++) { fputc (filename[i],fpout2); // +1 ?? checksum += filename[i]; } writebyte_cksum(0x81, fpout2, &checksum); writeword((checksum%65536),fpout2); /* name checksum */ for (i=0; i<10;i++) /* zero filling the next part */ fputc (0,fpout2); checksum=0x3b; /* Init checksum */ /* Block length*/ writeword_cksum(len, fpout2, &checksum); /* Block */ for (i=len-1; i>=0; i--) { fseek(fpin, i, SEEK_SET); c=getc(fpin); writebyte_cksum(c, fpout2, &checksum); } writebyte_cksum(0x41, fpout2, &checksum); writeword((checksum%65536),fpout2); /* block checksum */ for (i=0; i<9;i++) /* tail */ fputc (0,fpout2); fclose(fpin); fclose(fpout2); /* TAPE directory */ if ( (fpout=fopen("_dir.txt","w") ) == NULL ) { printf("Can't open output text format file %s\n",filename); myexit(NULL,1); } fprintf(fpout,"%s\n",filename); suffix_change(filename,".dat"); fprintf(fpout,"%s\n",filename); fclose(fpout); suffix_change(filename,".tmp"); remove(filename); } }