From bf8b162c90c7218656045f916b1e9068e3a15df9 Mon Sep 17 00:00:00 2001 From: g012 Date: Thu, 21 Sep 2017 16:02:26 +0200 Subject: [PATCH] Reformatted stats printing, and moved it to __tostring. --- 6502.lua | 19 ++++++++++--------- asm.l65 | 9 ++++++++- asm.lua | 9 ++++++++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/6502.lua b/6502.lua index bc37157..323964d 100644 --- a/6502.lua +++ b/6502.lua @@ -2,7 +2,7 @@ local M = {} local symbols={} M.symbols=symbols local locations={} M.locations=locations -local stats={} M.stats=stats +local stats={} M.stats=stats setmetatable(stats, stats) M.__index = M symbols.__index = symbols @@ -105,11 +105,11 @@ M.link = function() if cross_count_new < cross_count_cur then goto select_pos end align = align>>1 until align==1 - -- if cross count is same, take the one with the most LSB count + -- if cross count is same, take the one with the most set LSB count (eg. select 11 over 10) local lsb_cur,lsb_new=0,0 for i=0,15 do if rposition&(1<= lsb_new then goto constraints_not_met end + if lsb_cur <= lsb_new then goto constraints_not_met end end ::select_pos:: waste=w position=address position_end=address_end @@ -229,21 +229,22 @@ M.writesym = function(filename) f:close() end -M.getstats = function() +stats.__tostring = function() local s,ins={},table.insert - -- TODO allow set name for location - ins(s, " START END SIZE USED FREE") + ins(s, " Free Used Area") for _,location in ipairs(locations) do if location.finish then local size = location.finish-location.start+1 - ins(s, string.format(" %04X %04X %04X %04X %04X (%d)", - location.start, location.finish, size, size-location.unused, location.unused, location.unused)) + local name = (location.name or ''):sub(1,16) + name = string.rep(' ', 16-#name) .. name + ins(s, string.format("%s %5d %5d %6d [%04X-%04X]", name, + location.unused, size-location.unused, size, location.start, location.finish)) else ins(s, string.format(" %04X -- -- %06X --", location.start, 0)) -- TODO test infinite locations end end - ins(s, string.format("FREE ROM: %08X (%d)", stats.unused, stats.unused)) + ins(s, string.format("FREE ROM: %04X (%d)", stats.unused, stats.unused)) return table.concat(s, '\n') end diff --git a/asm.l65 b/asm.l65 index c7ad26c..8cdf448 100644 --- a/asm.l65 +++ b/asm.l65 @@ -14,6 +14,13 @@ for bi=0,7,1 do section{"vectors"..bi, org=0x8ffc+o} word(start,start) end +--[[ +location(0x15000) +@test3 +lda #15 +]] + +bank0.name = 'core' location(bank0) --location(0xf000, 0xffff) @@ -130,7 +137,7 @@ ptr_table("ptrs", message, data, 0) local filename=string.match(arg[0], ".-([^\\/]-)%.?[^%.\\/]*$") writebin(filename..'.bin') writesym(filename..'.sym') -print(getstats()) +print(stats) --[[ section "doOverscan" diff --git a/asm.lua b/asm.lua index fc7d2e8..bf5f285 100644 --- a/asm.lua +++ b/asm.lua @@ -14,6 +14,13 @@ for bi=0,7,1 do section{"vectors"..bi, org=0x8ffc+o} word(start,start) end +--[[ +location(0x15000) +@test3 +lda #15 +]] + +bank0.name = 'core' location(bank0) --location(0xf000, 0xffff) @@ -128,7 +135,7 @@ label("_toto") local filename=string.match(arg[0], ".-([^\\/]-)%.?[^%.\\/]*$") writebin(filename..'.bin') writesym(filename..'.sym') -print(getstats()) +print(stats) --[[ section "doOverscan"