Skip to content

Commit 8b71086

Browse files
committed
Add option to append binary files
Using the `--append-binary=fname.ext` append binary file at the end of the .TAP or .TZX file. This option can be repeated several times.
1 parent e9b5344 commit 8b71086

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

asmparse.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ def assemble(input_):
14381438
return gl.has_errors
14391439

14401440

1441-
def generate_binary(outputfname, format_, progname=''):
1441+
def generate_binary(outputfname, format_, progname='', binary_files=None):
14421442
""" Outputs the memory binary to the
14431443
output filename using one of the given
14441444
formats: tap, tzx or bin
@@ -1449,6 +1449,14 @@ def generate_binary(outputfname, format_, progname=''):
14491449
if gl.has_errors:
14501450
return
14511451

1452+
if binary_files is None:
1453+
binary_files = []
1454+
1455+
bin_blocks = []
1456+
for fname in binary_files:
1457+
with api.utils.open_file(fname) as f:
1458+
bin_blocks.append((os.path.basename(fname), f.read()))
1459+
14521460
if AUTORUN_ADDR is None:
14531461
AUTORUN_ADDR = org
14541462

@@ -1476,6 +1484,9 @@ def generate_binary(outputfname, format_, progname=''):
14761484
t.save_program('loader', program.bytes, line=1) # Put line 0 to protect against MERGE
14771485

14781486
t.save_code(progname, org, binary)
1487+
for name, block in bin_blocks:
1488+
t.save_code(name, 0, block)
1489+
14791490
t.dump(outputfname)
14801491

14811492
elif format_ == 'tap':
@@ -1486,6 +1497,9 @@ def generate_binary(outputfname, format_, progname=''):
14861497
t.save_program('loader', program.bytes, line=1) # Put line 0 to protect against MERGE
14871498

14881499
t.save_code(progname, org, binary)
1500+
for name, block in bin_blocks:
1501+
t.save_code(name, 0, block)
1502+
14891503
t.dump(outputfname)
14901504

14911505
else:

zxb.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ def main(args=None):
145145
help='Header-less mode: omit asm prologue and epilogue')
146146
parser.add_argument('--version', action='version', version='%(prog)s {0}'.format(VERSION))
147147
parser.add_argument('--parse-only', action='store_true',
148-
help="Only parses to check for syntax and semantic errors")
148+
help='Only parses to check for syntax and semantic errors')
149+
parser.add_argument('--append-binary', default=[], action='append',
150+
help='Appends binary to tap file (only works with -t ot -T)')
149151

150152
options = parser.parse_args(args=args)
151153

@@ -201,6 +203,10 @@ def main(args=None):
201203
parser.error('Option --BASIC and --autorun requires --tzx or tap format')
202204
return 4
203205

206+
if options.append_binary and not options.tzx and not options.tap:
207+
parser.error('Option --append-binary needs either --tap or --tzx')
208+
return 5
209+
204210
OPTIONS.use_loader.value = options.basic
205211
OPTIONS.autorun.value = options.autorun
206212

@@ -330,7 +336,8 @@ def main(args=None):
330336
output(asm_output, fout)
331337
asmparse.assemble(fout.getvalue())
332338
fout.close()
333-
asmparse.generate_binary(OPTIONS.outputFileName.value, OPTIONS.output_file_type.value)
339+
asmparse.generate_binary(OPTIONS.outputFileName.value, OPTIONS.output_file_type.value,
340+
binary_files=options.append_binary)
334341
if gl.has_errors:
335342
return 5 # Error in assembly
336343

0 commit comments

Comments
 (0)