From 6c1dd85c9a742589d2142be72257a7380a4786dd Mon Sep 17 00:00:00 2001 From: Anthony Bentley Date: Sat, 12 Sep 2009 18:46:08 -0600 Subject: [PATCH] add support for partial binary includes (from lmod00) --- src/asm/output.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ src/asm/yaccprt3.y | 4 ++++ 2 files changed, 53 insertions(+) diff --git a/src/asm/output.c b/src/asm/output.c index 8ae0a878..d4de5217 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -959,3 +959,52 @@ void out_BinaryFile(char *s) } 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"); +} + diff --git a/src/asm/yaccprt3.y b/src/asm/yaccprt3.y index b88be6d5..bf8df711 100644 --- a/src/asm/yaccprt3.y +++ b/src/asm/yaccprt3.y @@ -274,6 +274,10 @@ include : T_POP_INCLUDE string incbin : T_POP_INCBIN string { out_BinaryFile( $2 ); } + | T_POP_INCBIN string ',' const ',' const + { + out_BinaryFileSlice( $2, $4, $6 ); + } ; printt : T_POP_PRINTT string