From b843ba9ba966f68029e920308451e02fa84b44cd Mon Sep 17 00:00:00 2001 From: Cat's Eye Technologies Date: Tue, 8 May 2012 18:12:28 -0500 Subject: [PATCH] Have .incbin take an optional offset and length for source bytes. --- src/Ophis/CorePragmas.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Ophis/CorePragmas.py b/src/Ophis/CorePragmas.py index d5faea7..5876c16 100644 --- a/src/Ophis/CorePragmas.py +++ b/src/Ophis/CorePragmas.py @@ -38,11 +38,20 @@ def pragmaRequire(ppt, line, result): def pragmaIncbin(ppt, line, result): "Includes a binary file" filename = line.expect("STRING").value + offset = 0 + size = -1 + if str(line.lookahead(0)) == ",": + line.pop() + offset = line.expect("NUM").value + if str(line.lookahead(0)) == ",": + line.pop() + size = line.expect("NUM").value line.expect("EOL") if type(filename)==str: try: f = file(filename, "rb") - bytes = f.read() + f.seek(offset) + bytes = f.read(size) f.close() except IOError: Err.log ("Could not read "+filename)