ref: 6c1dd85c9a742589d2142be72257a7380a4786dd
parent: 7d0dd140c3f81fa903f8becfb8981bbe8943a076
author: Anthony Bentley <[email protected]>
date: Sat Sep 12 14:46:08 EDT 2009
add support for partial binary includes (from lmod00)
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -959,3 +959,52 @@
} else
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");
+}
+
--- a/src/asm/yaccprt3.y
+++ b/src/asm/yaccprt3.y
@@ -274,6 +274,10 @@
incbin : T_POP_INCBIN string
{ out_BinaryFile( $2 ); }
+ | T_POP_INCBIN string ',' const ',' const
+ {
+ out_BinaryFileSlice( $2, $4, $6 );
+ }
;
printt : T_POP_PRINTT string