Write symbol table to .dbg file when assembling player

Add explicit end_{opcode} labels to mark (1 byte past) end of opcode.

Rename op_done to op_terminate to match opcode name in encoder.

Extract symbol table in encoder and use this to populate the opcode
start/end addresses.
This commit is contained in:
kris 2019-02-27 12:10:14 +00:00
parent 86066fec61
commit c139e8bf1b
4 changed files with 84 additions and 9 deletions

View File

@ -78,7 +78,10 @@ SRCDIRS+=
# If you want to add arguments to the link commandline, add them to
# this variable:
# LDFLAGS += -v
#
# Write out a debug file containing symbol table, so we can parse the opcode
# offsets in the video encoder.
LDFLAGS += -Wl --dbgfile,ethernet.dbg
# If you want to add arguments to the BASIC tokenizer commandline,
# add them to this valiable:

View File

@ -8,6 +8,9 @@
.include "apple2.inc"
; Write symbol table to object file
.DEBUGINFO
.org $8000
.proc main
; TCP SOCKET DEMO FOR W5100/UTHERNET II
@ -330,7 +333,8 @@ op_nop: ; 11
LDY WDATA ; 4
STY @D+1 ; 4
@D:
BRA op_done ; 3
BRA op_terminate ; 3
end_nop:
op_store: ; 20
LDY WDATA ; 4
@ -339,14 +343,16 @@ store1:
LDY WDATA ; 4
STY @D+1 ; 4
@D:
BRA op_done ; 3
BRA op_terminate ; 3
end_store:
op_set_content: ; 15
LDA WDATA ; 4
LDY WDATA ; 4
STY @D+1 ; 4
@D:
BRA op_done ; 3
BRA op_terminate ; 3
end_set_content:
op_set_page: ; 27
LDY WDATA ; 4
@ -356,7 +362,8 @@ op_set_page: ; 27
LDY WDATA ; 4
STY @D+1 ; 4
@D:
BRA op_done ; 3
BRA op_terminate ; 3
end_set_page:
op_rle: ; 12 + N (2 + 5 + 3) + (-1 + 4 + 4 + 3) = 22 + 10N
LDY WDATA ; 4 start offset
@ -370,7 +377,8 @@ rle2:
LDY WDATA ; 4
STY @D+1 ; 4
@D:
BRA op_done ; 3
BRA op_terminate ; 3
end_rle:
;op_batch_store: ; 4 + N(4 + 5 + 2 + 3) + -1 + 4 + 4 + 3 = 14 + 14 N
; LDX WDATA ; 4 number of stores
@ -383,7 +391,7 @@ rle2:
; LDY WDATA ; 4
; STY @D+1 ; 4
;@D:
; BRA op_done ; 3
; BRA op_terminate ; 3
; tick with cycle padding, 15 .. 35 duty cycle in increments of 2 cycles
; 20 cycles of NOP
@ -402,10 +410,12 @@ op_tick:
LDY WDATA ; 4
STY @D+1 ; 4
@D:
BRA op_done ; 3
BRA op_terminate ; 3
end_tick:
op_done:
op_terminate:
RTS
end_terminate:
op_ack:
; MOVE ADDRESS POINTER 1 page further in socket buffer

31
symbol_table.py Normal file
View File

@ -0,0 +1,31 @@
from typing import Dict
class SymbolTable:
"""Parse cc65 debug file to extract symbol table."""
def __init__(self, debugfile: str = None):
self.debugfile = debugfile
def parse(self, iostream=None) -> Dict:
syms = {}
if not iostream:
iostream = open(self.debugfile, "r")
with iostream as f:
for line in f.read().split("\n"):
if not line.startswith("sym"):
continue
sym = {}
data = line.split()[1].split(",")
for kv in data:
k, v = kv.split("=")
sym[k] = v
name = sym["name"]
syms[name] = sym
return syms

31
symbol_table_test.py Normal file
View File

@ -0,0 +1,31 @@
import io
import unittest
import symbol_table
DEBUG_FILE = """
version major=2,minor=0
info csym=0,file=594,lib=1,line=420,mod=2,scope=2,seg=7,span=255,sym=151,type=5
file id=0,name="main.s",size=10297,mtime=0x5C766D92,mod=0
file id=1,name="/usr/local/share/cc65/asminc/apple2.inc",size=2348,mtime=0x5AA06221,mod=0
file id=2,name="apple2/exehdr.s",size=1848,mtime=0x5AA06221,mod=1
lib id=0,name="/usr/local/share/cc65/lib/apple2enh.lib"
line id=0,file=1,line=60
[...]
sym id=8,name="op_ack",addrsize=absolute,scope=1,def=195,val=0x81FA,type=lab
sym id=10,name="op_tick",addrsize=absolute,scope=1,def=6,val=0x81EE,type=lab
sym id=12,name="rle1",addrsize=absolute,scope=1,def=135,ref=373,val=0x81D6,type=lab
[...]
"""
class TestSymbolTable(unittest.TestCase):
def test_parse(self):
dbg = io.StringIO(DEBUG_FILE)
s = symbol_table.SymbolTable()
self.assertEqual({"\"op_ack\"", "\"op_tick\"", "\"rle1\""},
s.parse(dbg).keys())
if __name__ == '__main__':
unittest.main()