107 char * p = strstr( originalBinaryFile,
".dsk" );
113 FILE * fh = fopen( originalBinaryFile,
"rb" );
114 int executableBinaryFileSize = 0;
116 fseek( fh, 0, SEEK_END );
117 executableBinaryFileSize = ftell( fh );
131 executableBinaryFileSize -= 5;
132 char * originalBinaryFileContent =
malloc( executableBinaryFileSize );
133 fh = fopen( originalBinaryFile,
"rb" );
134 (void)!fread( originalBinaryFileContent, 1, 5, fh);
135 (void)!fread( originalBinaryFileContent, 1, executableBinaryFileSize, fh);
138 int programExeSize = 0x4d00 - 0x2a00;
139 if ( executableBinaryFileSize < programExeSize ) {
140 programExeSize = executableBinaryFileSize;
142 char * programExe =
malloc( programExeSize );
143 memcpy( programExe, originalBinaryFileContent, programExeSize );
144 executableBinaryFileSize -= programExeSize;
148 int programDataCount = 0;
150 if ( executableBinaryFileSize ) {
151 char * originalBinaryFileContentPtr = originalBinaryFileContent + programExeSize;
152 int blockSize = 0x2000;
153 while( executableBinaryFileSize ) {
154 if ( blockSize > executableBinaryFileSize ) {
155 blockSize = executableBinaryFileSize;
156 executableBinaryFileSize = blockSize;
158 programDats[programDataCount] =
malloc( blockSize );
159 programDatsSize[programDataCount] = blockSize;
160 memcpy( programDats[programDataCount], originalBinaryFileContentPtr, blockSize );
161 executableBinaryFileSize -= blockSize;
162 originalBinaryFileContentPtr += blockSize;
169 strcat( temporaryPath,
" " );
184 sprintf( outputFileName,
"%sprogram.exe", temporaryPath);
185 fh = fopen( outputFileName,
"wb" );
187 fputc( programExeSize >> 8, fh );
188 fputc( programExeSize & 0xff, fh );
191 fwrite( programExe, 1, programExeSize, fh );
199 if ( programDataCount ) {
200 for(
int i=0; i<programDataCount; ++i ) {
212 sprintf( outputFileName,
"%sprogram.%03d", temporaryPath, i);
213 fh = fopen( outputFileName,
"wb" );
215 fputc( programDatsSize[i] >> 8, fh );
216 fputc( programDatsSize[i] & 0xff, fh );
219 fwrite( programDats[i], 1, programDatsSize[i], fh );
236 sprintf( basFileName,
"%sloader.bas", temporaryPath);
237 fh = fopen( basFileName,
"wb" );
239 fprintf( fh,
"2DATA26,80,52,16,52,6,142,14,0,159,31,31\n" );
240 fprintf( fh,
"3DATA65,16,206,15,0,16,223,33,198,255,166\n" );
241 fprintf( fh,
"4DATA133,167,229,90,38,249,53,6,53,16,28\n" );
242 fprintf( fh,
"5DATA159,57,26,80,142,42,0,16,142,42,0\n" );
243 fprintf( fh,
"6DATA183,255,223,206,16,0,166,128,167,160\n" );
244 fprintf( fh,
"7DATA51,95,17,131,0,0,38,244,183,255,222\n" );
245 fprintf( fh,
"9DATA28,159,57\n" );
246 fprintf( fh,
"10FORA=&HE00 TO&HE44:READX:POKEA,X:NEXTA\n" );
247 fprintf( fh,
"11POKE27,12:POKE28,0:POKE29,12:POKE30,172\n");
248 fprintf( fh,
"12POKE31,13:POKE32,0:POKE33,13:POKE34,64:POKE35,13:POKE36,172\n" );
249 fprintf( fh,
"13POKE37,13:POKE38,172:POKE39,13:POKE40,250:EXEC3584:? \"WAIT\";\n" );
250 for(
int i=0; i<programDataCount; ++i ) {
251 int lineNr = 14 + i*2;
252 fprintf( fh,
"%dLOADM\"P.%02d\":?\".\";\n", lineNr, i);
254 int address = 0x4d + i*32;
255 int sizeHi = ( programDatsSize[i] >> 8 ) & 0xff;
256 int sizeLo = ( programDatsSize[i] ) & 0xff;
257 fprintf( fh,
"%dPOKE3627,%d:POKE3633,%d:POKE3634,%d:EXEC3620\n", lineNr, address, sizeHi, sizeLo );
259 fprintf( fh,
"90?\"*\";:LOADM\"P.\":?\".\":EXEC10752\n" );
289 strcat( basePath, storage->
fileName );
291 strcat( basePath,
"disk%d.dsk" );
297 strcopy( filemask,
"disk%d.dsk" );
300 sprintf( buffer, filemask, 0 );
301 if ( !strstr( buffer,
".dsk" ) ) {
302 strcat( buffer,
".dsk" );
307 char * p = strstr( binaryName,
".bin" );
316 sprintf( commandLine,
"\"%s\" dskini \"%s\"", executableName, _environment->
exeFileName );
318 printf(
"The compilation of assembly program failed.\n\n");
319 printf(
"Please use option '-I' to install chain tool.\n\n");
322 sprintf( commandLine,
"\"%s\" copy -0 -t \"%s\" \"%s,LOADER.BAS\"",
327 printf(
"The compilation of assembly program failed.\n\n");
328 printf(
"Please use option '-I' to install chain tool.\n\n");
331 remove( basFileName );
333 sprintf( commandLine,
"\"%s\" copy -2 \"%sprogram.exe\" \"%s,P\"",
338 printf(
"The compilation of assembly program failed.\n\n");
339 printf(
"Please use option '-I' to install chain tool.\n\n");
342 sprintf( commandLine,
"%sprogram.exe", temporaryPath);
343 remove( commandLine );
345 if ( programDataCount ) {
346 for(
int i=0; i<programDataCount; ++i ) {
347 sprintf( commandLine,
"\"%s\" copy -2 \"%sprogram.%03d\" \"%s,P.%02d\"",
354 printf(
"The compilation of assembly program failed.\n\n");
355 printf(
"Please use option '-I' to install chain tool.\n\n");
357 sprintf( commandLine,
"%sprogram.%03d", temporaryPath, i);
358 remove( commandLine );
373 while( fileStorage ) {
380 memset( buffer, 0,
size );
381 memcpy( buffer, fileStorage->
content, fileStorage->
size );
383 FILE * file = fopen( fileStorage->
sourceName,
"rb" );
387 fseek( file, 0, SEEK_END );
388 size = ftell( file );
389 fseek( file, 0, SEEK_SET );
391 memset( buffer, 0,
size + 2 );
392 (void)!fread( buffer,
size, 1, file );
396 sprintf( dataFilename,
"%s%s", temporaryPath, fileStorage->
targetName );
397 FILE * fileOut = fopen( dataFilename,
"wb" );
399 fwrite( buffer, 1,
size, fileOut );
402 sprintf( commandLine,
"\"%s\" copy -1 -b \"%s\" \"%s,%s\"",
408 printf(
"The compilation of assembly program failed.\n\n");
409 printf(
"Please use option '-I' to install chain tool.\n\n");
412 remove( dataFilename );
413 fileStorage = fileStorage->
next;
416 storage = storage->
next;
428 strcat( basePath, storage->
fileName );
430 strcat( basePath,
"disk%d.dsk" );
436 strcopy( filemask,
"disk%d.dsk" );
439 sprintf( buffer, filemask, i );
440 if ( !strstr( buffer,
".dsk" ) ) {
441 strcat( buffer,
".dsk" );
444 sprintf( commandLine,
"\"%s\" dskini \"%s\"", executableName, buffer );
446 printf(
"The compilation of assembly program failed.\n\n");
447 printf(
"Please use option '-I' to install chain tool.\n\n");
456 remove( originalBinaryFile );