add support for partial binary includes (from lmod00)

This commit is contained in:
Anthony Bentley
2009-09-12 18:46:08 -06:00
parent 7d0dd140c3
commit 6c1dd85c9a
2 changed files with 53 additions and 0 deletions

View File

@@ -959,3 +959,52 @@ void out_BinaryFile(char *s)
} else } else
fatalerror("File not found"); fatalerror("File not found");
} }
void out_BinaryFileSlice(char *s, SLONG start_pos, SLONG length)
{
FILE *f;
if (start_pos < 0)
fatalerror("Start position cannot be negative");
if (length < 0)
fatalerror("Number of bytes to read must be greater than zero");
fstk_FindFile (s);
if( (f=fopen(s,"rb"))!=NULL )
{
SLONG fsize;
fseek (f, 0, SEEK_END);
fsize = ftell (f);
if (start_pos >= fsize)
fatalerror("Specified start position is greater than length of file");
if( (start_pos + length) > fsize )
fatalerror("Specified range in INCBIN is out of bounds");
fseek (f, start_pos, SEEK_SET);
checkcodesection (length);
if (nPass == 2)
{
SLONG dest = nPC;
SLONG todo = length;
while (todo--)
pCurrentSection->tData[dest++] = fgetc (f);
}
pCurrentSection->nPC += length;
nPC += length;
pPCSymbol->nValue += length;
fclose (f);
}
else
fatalerror ("File not found");
}

View File

@@ -274,6 +274,10 @@ include : T_POP_INCLUDE string
incbin : T_POP_INCBIN string incbin : T_POP_INCBIN string
{ out_BinaryFile( $2 ); } { out_BinaryFile( $2 ); }
| T_POP_INCBIN string ',' const ',' const
{
out_BinaryFileSlice( $2, $4, $6 );
}
; ;
printt : T_POP_PRINTT string printt : T_POP_PRINTT string