1
0
mirror of https://github.com/rzzzwilson/pymlac.git synced 2025-06-10 09:32:41 +00:00

Moving toward new blockloader code

This commit is contained in:
Ross Wilson
2016-02-04 15:37:27 +07:00
parent f5ed1a6b9c
commit 0f026b295b
4 changed files with 91 additions and 45 deletions

View File

@@ -75,6 +75,9 @@ BlockBufferBase = None # base address of the block
# mask for 16bit values
WordMask = 0xFFFF
# high bit in 16-bit word
HighBit = 0x8000
# the output PTP filename extension
PTPExtension = '.ptp'
@@ -237,7 +240,7 @@ BlockLoader = [
# ; integers, incrementing the sum whenever the 16bit value overflows.
# ;
# ; The end of the load is signalled by a block with a
# ; starting address 0177777.
# ; starting address WordMask.
# ;
# ; Disassembled from the 40tp_simpleDisplay.ptp image file.
# ;
@@ -267,7 +270,7 @@ BlockLoader = [
0102001, # 003725 asn ;
0013746, # 003726 jmp newblk ;if same, get next block
0000000, # 003727 hlt ;if not same, ERROR
0177777, # 003730 neg1 data 0177777 ;
WordMask, # 003730 neg1 data WordMask ;
# ;------------------------
# ;Compute checksum. Word to sum in AC.
# ;------------------------
@@ -367,17 +370,18 @@ def write_word(word):
write_byte(word >> 8)
write_byte(word)
def write_endload():
"""Write the special 'end of load' block."""
def write_start(address, ac=None):
"""Write the start block.
write_byte(1)
write_word(0xffff)
Add the AC contents word if passed.
"""
def write_start(address):
"""Write the start block."""
if ac is None:
ac = 0
start_block(address)
write_block()
write_word(address + HighBit)
if address != 0 and ac is not None:
write_word(ac & WordMask)
def write_leader(size=ZeroLeaderSize):
"""Write the papertape leader."""
@@ -393,8 +397,6 @@ def write_block_loader():
for word in BlockLoader:
write_word(word)
write_leader()
def start_block(addr):
"""Prepare next block to start at 'addr'"""
@@ -426,15 +428,17 @@ def write_block():
# block buffer is empty, do nothing
return
# emit the block size and load address
write_byte(code_block_size)
# emit the block size and data word count (negated)
write_word(BlockBufferBase)
for word in BlockBuffer:
write_word(word)
write_word((~code_block_size+1) & WordMask)
# calculate and write the checksum
checksum = sum(BlockBuffer) & WordMask
write_word(checksum)
checksum = (BlockBufferBase + ((~code_block_size+1) & WordMask) + sum(BlockBuffer))
write_word((~checksum+1) & WordMask)
# finally, write out data words
for word in BlockBuffer:
write_word(word)
# reset the code buffer
start_block(None)
@@ -774,9 +778,8 @@ def pass_2(lines):
# write the final block of code and optional start address
write_block()
# if StartAddress is not None:
# write_start(StartAddress)
write_endload()
if StartAddress is not None:
write_start(StartAddress, ac=0177777)
write_leader()
# check nothing after END