Skip to content

Commit 3c1632a

Browse files
committed
Add option --append-headless-binary
This option is like --append-binary but with headless ones. A headless binary does not have a head in the tape file (hence loads faster).
1 parent 8b71086 commit 3c1632a

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

asmparse.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from api import global_ as gl
2727
import api.utils
2828
import zxbpp
29+
import outfmt
2930

3031
LEXER = asmlex.Lexer()
3132

@@ -1438,7 +1439,7 @@ def assemble(input_):
14381439
return gl.has_errors
14391440

14401441

1441-
def generate_binary(outputfname, format_, progname='', binary_files=None):
1442+
def generate_binary(outputfname, format_, progname='', binary_files=None, headless_binary_files=None):
14421443
""" Outputs the memory binary to the
14431444
output filename using one of the given
14441445
formats: tap, tzx or bin
@@ -1452,11 +1453,19 @@ def generate_binary(outputfname, format_, progname='', binary_files=None):
14521453
if binary_files is None:
14531454
binary_files = []
14541455

1456+
if headless_binary_files is None:
1457+
headless_binary_files = []
1458+
14551459
bin_blocks = []
14561460
for fname in binary_files:
14571461
with api.utils.open_file(fname) as f:
14581462
bin_blocks.append((os.path.basename(fname), f.read()))
14591463

1464+
headless_bin_blocks = []
1465+
for fname in headless_binary_files:
1466+
with api.utils.open_file(fname) as f:
1467+
headless_bin_blocks.append(f.read())
1468+
14601469
if AUTORUN_ADDR is None:
14611470
AUTORUN_ADDR = org
14621471

@@ -1476,29 +1485,17 @@ def generate_binary(outputfname, format_, progname='', binary_files=None):
14761485
else:
14771486
program.add_line([['REM'], ['RANDOMIZE', program.token('USR'), AUTORUN_ADDR]])
14781487

1479-
if format_ == 'tzx':
1480-
import outfmt
1481-
t = outfmt.TZX()
1482-
1483-
if OPTIONS.use_loader.value:
1484-
t.save_program('loader', program.bytes, line=1) # Put line 0 to protect against MERGE
1485-
1486-
t.save_code(progname, org, binary)
1487-
for name, block in bin_blocks:
1488-
t.save_code(name, 0, block)
1489-
1490-
t.dump(outputfname)
1491-
1492-
elif format_ == 'tap':
1493-
import outfmt
1494-
t = outfmt.TAP()
1488+
if format_ in ('tap', 'tzx'):
1489+
t = {'tap': outfmt.TAP, 'tzx': outfmt.TZX}[format_]()
14951490

14961491
if OPTIONS.use_loader.value:
14971492
t.save_program('loader', program.bytes, line=1) # Put line 0 to protect against MERGE
14981493

14991494
t.save_code(progname, org, binary)
15001495
for name, block in bin_blocks:
15011496
t.save_code(name, 0, block)
1497+
for block in headless_bin_blocks:
1498+
t.standard_block(block)
15021499

15031500
t.dump(outputfname)
15041501

zxb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ def main(args=None):
147147
parser.add_argument('--parse-only', action='store_true',
148148
help='Only parses to check for syntax and semantic errors')
149149
parser.add_argument('--append-binary', default=[], action='append',
150-
help='Appends binary to tap file (only works with -t ot -T)')
150+
help='Appends binary to tape file (only works with -t or -T)')
151+
parser.add_argument('--append-headless-binary', default=[], action='append',
152+
help='Appends binary to tape file (only works with -t or -T)')
151153

152154
options = parser.parse_args(args=args)
153155

@@ -337,7 +339,8 @@ def main(args=None):
337339
asmparse.assemble(fout.getvalue())
338340
fout.close()
339341
asmparse.generate_binary(OPTIONS.outputFileName.value, OPTIONS.output_file_type.value,
340-
binary_files=options.append_binary)
342+
binary_files=options.append_binary,
343+
headless_binary_files=options.append_headless_binary)
341344
if gl.has_errors:
342345
return 5 # Error in assembly
343346

0 commit comments

Comments
 (0)