Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MOS format for testing using ugly hack. Bumped to 3.03.06mosfix1 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sbapack/dec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Default values
# ------------------------------------------------------------------------------

VERSION = "3.03.06"
VERSION = "3.03.06mosfix1"
DEF_ENV = "SBASM"
ERRLVL_OK = 0 # No errors
ERRLVL_PASS1 = 1 # Errors found during pass 1
Expand All @@ -37,6 +37,7 @@
COMMENT1 = ";*#@" # Legal comment delimiters on beginning of the line
COMMENT2 = ";" # Legal comment delimiters anywhere else on the line
EOL = '\n' # System dependant end of line character
XOFF = '\x13' # XOFF char 0x13 = dec(19) = ctrl+S
MAX8 = (1 << 8)-1 # Max value for 8 bit numbers
MAX16 = (1 << 16)-1 # Max value for 16 bit numbers
MAX32 = (1 << 32)-1 # Max value for 32 bit numbers
Expand Down Expand Up @@ -96,6 +97,7 @@ class Struct: # General data structure class
Asm.Code_Tfile = None # File handle for code target file
Asm.Code_Tbuffer = [] # Line buffer for code target file
Asm.Code_Tformat = '' # Code file's format
Asm.Code_TformatMOS_records = 0 # static record/line counter for TformatMOS()
Asm.Code_Tfunc = None # Indirect function handler
Asm.Code_Tlength = 0 # Wanted target record length
Asm.Code_Twrap = False # Set if wrap warning already given
Expand Down
21 changes: 20 additions & 1 deletion sbapack/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,13 @@ def TformatMOS(buffer, memory, last=False):

"""
Format a MOS technology target file.
Implement MOS format from here:
https://archive.org/details/KIM-1_Users_Manual/page/n98/mode/1up
https://srecord.sourceforge.net/man/man5/srec_mos_tech.5.html
"""

if len(buffer) > 0:
dec.Asm.Code_TformatMOS_records += 1 # count record/line
address = buffer[0]
length = len(buffer) - 1
checksum = length + ((address >> 8) & 0xFF) + (address & 0xFF)
Expand All @@ -444,7 +448,22 @@ def TformatMOS(buffer, memory, last=False):
line = ''

if last:
line = line + ';00' + dec.EOL
# Checked KIM-ROM how last line is processed
# after ';' it read the length and the address (as usual including calc the checksum)
# For lastline length=0 then only the checksum of address counts
# no more data read because of length=0
# next 2 byte are read and compared against the checksum (as usual nothing special except length=0 does not count)
# !!! for the first 255 lines address and checksum have the same value
# example: ";0000090009" or ";000230023" but ";0001230024"
# checksum == bad => print from offset 0x11 to TOP "\r ERR\r KIM\r\n" + 6 zero bytes
# checksum == good => print from offset 0x0c to TOP "\r KIM\r\n" + 6 zero bytes
# It will not expect or read further data like XOFF or EOL
# after print it will directly "JMP START" for further processing
# The XOFF and EOL are added to not confuse editor
line = line + ';00' # length = 0
address = dec.Asm.Code_TformatMOS_records
checksum = ((address >> 8) & 0xFF) + (address & 0xFF) # length = 0
line = line + ToHex(address, 2) + ToHex(checksum, 2) + dec.XOFF + dec.EOL

return line.upper()

Expand Down