diff --git a/src/preprocess.c b/src/preprocess.c index d44295fc..39aa3c7c 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -22,6 +22,9 @@ typedef struct source_file { int low_addr; int high_addr; int size; + + // For knowing when we have output the various routines + int written; } source_file; source_file source_files[MAX_FILES]; @@ -174,8 +177,81 @@ int main(int argc,char **argv) } fclose(out); + fprintf(stderr,"Got routine sizes:\n"); for(int i=0;iaddress) + if (source_files[i].addressbiggest_size) { + if (source_files[i].size<=space) { + biggest_size=source_files[i].size; + biggest=i; + } + } + } + } + + fprintf(stderr,"At address $%04x, next allocated address is $%04X. Current space is %d bytes\n", + address,next_allocated_address,space); + if (biggest>-1) + fprintf(stderr,"Biggest floating routine that fits is '%s' (%d bytes)\n", + source_files[biggest].file,biggest_size); + if (biggest==-1) { + // Nothing else fits here. So write next_fixed_routine + fprintf(stderr,"Writing file %s\n",source_files[next_fixed_routine].file); + fprintf(out,"; Source file %s\n",source_files[next_fixed_routine].file); + fprintf(out,"\t.checkpc $%04x\n\t.advance $%04x,$00\n", + next_allocated_address,next_allocated_address); + char filename[8192]; + snprintf(filename,8192,"%s/%s",directory,source_files[next_fixed_routine].file); + if (dump_file(out,filename)) DO_ERROR("Could not dump fixed address routine"); + source_files[next_fixed_routine].written=1; + address=next_allocated_address+source_files[next_fixed_routine].size; + } else { + fprintf(out,"; Source file %s\n",source_files[biggest].file); + fprintf(stderr,"Writing file %s\n",source_files[biggest].file); + char filename[8192]; + snprintf(filename,8192,"%s/%s",directory,source_files[biggest].file); + if (dump_file(out,filename)) DO_ERROR("Could not dump floating routine"); + source_files[biggest].written=1; + address+=source_files[biggest].size; + } + } + fclose(out); if (retVal) break;