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 main(int argc, char** argv) { if(argc != 6) return syntax(); return !!raw2wav(argv[1], argv[2], atoi(argv[3]), atoi(argv[4]), atoi(argv[5])); }
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 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); }