From f0dcdfeaa74265549cda58c32fa5589010b9ee7f Mon Sep 17 00:00:00 2001 From: g012 Date: Sun, 24 Sep 2017 16:05:37 +0200 Subject: [PATCH] Added more VCS mapper stubs. --- 6502.lua | 16 +++++--- vcs.lua | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 118 insertions(+), 13 deletions(-) diff --git a/6502.lua b/6502.lua index 6a0b59c..f1296d1 100644 --- a/6502.lua +++ b/6502.lua @@ -223,11 +223,12 @@ M.genbin = function(filler) local ins,mov = table.insert,table.move table.sort(locations, function(a,b) return a.start < b.start end) local of0 = locations[1].start + local fill for _,location in ipairs(locations) do if location.start < #bin then error(string.format("location [%04x,%04x] overlaps another", location.start, location.finish)) end - for i=#bin+of0,location.start-1 do ins(bin, filler) end + if fill then for i=#bin+of0,location.start-1 do ins(bin, filler) end end M.size=0 M.cycles=0 local sections = location.sections table.sort(sections, function(a,b) return a.org < b.org end) @@ -242,7 +243,8 @@ M.genbin = function(filler) M.size=#bin M.cycles=M.cycles+(instruction.cycles or 0) end end - if location.finish then + fill = not location.nofill + if location.finish and fill then for i=#bin+of0,location.finish do ins(bin, filler) end end end @@ -302,8 +304,10 @@ stats.__tostring = function() end M.location = function(start, finish) - local location = { type='location', start=start, finish=finish, sections={} } - if type(start) == 'table' then + local location + if type(start) ~= 'table' then + location = { type='location', start=start, finish=finish } + else if start.type == 'location' then for _,v in ipairs(locations) do if v == start then M.location_current = start @@ -311,15 +315,15 @@ M.location = function(start, finish) end end error("unable to find reference to location [" .. (start.start or '?') .. ", " .. (start.finish or '?') .. "]") end + location = start location.start = start[1] location.finish = start[2] - location.name = start.name - location.rorg = start.rorg if type(location.rorg) == 'number' then local offset = location.rorg - location.start location.rorg = function(x) return x+offset end end end + location.sections = {} if not location.rorg then location.rorg = function(x) return x end end local size = (location.finish or math.huge) - location.start + 1 location.chunks={ { start=location.start, size=size } } diff --git a/vcs.lua b/vcs.lua index 7022d22..218d30b 100644 --- a/vcs.lua +++ b/vcs.lua @@ -85,18 +85,119 @@ do end --[[ TODO enable this when lua load() is changed -function bank_stubs(count, hotspot) - function switchbank(i) bit 0x1000+hotspot+i end + +mappers = {} + +mappers['2K'] = function() + rom0 = location(0xf800, 0xffff) + section{"vectors", org=0xfffc} word(main,main) +end +mappers.CV = mappers['2K'] + +mappers['4K'] = function() + rom0 = location(0xf000, 0xffff) + section{"vectors", org=0xfffc} word(main,main) +end + +local bank_stubs = function(count, hotspot) + function switchrom(i) assert(i>=0 and i=0 and i=0 and i<7) bit 0x1fe0+i end + function enableram() bit 0x1fe7 end + function switchram(i) assert(i>=0 and i<4) bit 0x1fe8+i end + for bi=0,6 do + local o = bi*0x800 + _ENV['rom' .. bi] = location{o+0xc000, o+0xc7ff, rorg=0xf000} + end + rom7 = location{0xf800, 0xffff, rorg=0xf800} + section{"switchtab", org=0xffe0} for i=1,12 do byte(0) end + section{"vectors", org=0xfffc} word(main,main) +end + +mappers.F0 = function() + function switchrom() lda 0x1ff0 end + for bi=0,15 do + local o = bi*0x1000 + 0x1000 + _ENV['rom' .. bi] = location{o, o+0xfff, rorg=0xf000} + local start=section{"entry"..bi} + @_loop switchrom() bne _loop + if bi==0 then jmp main end + section{"switchtab"..bi, org=o+0xff0} byte(0) + section{"vectors"..bi, org=o+0xffc} word(start,start) + end +end + +local function bank_stubs2 = function(hotspot0, hotspot1) + function switchrom(i) + if i==0 then bit hotspot0 + elseif i==1 then bit hotspot1 + else error("invalid rom index: " .. i) end + end + local base = 0xe000 + for bi=0,1 do + local o = base+(bi<<12) + _ENV['rom' .. bi] = location{o, o+0xfff, rorg=0xf000} + local start=section{"entry"..bi, org=o+0xffc-6} switchrom(0) if bi==0 then jmp main end + section{"vectors"..bi, org=o+0xffc} word(start,start) + end +end +mappers.UA = function() bank_stubs2(0x220, 0x240) end +mappers.['0840'] = function() bank_stubs2(0x800, 0x840) end + +mappers['3E'] = function(rom_count, ram_count) + mappers['3F'](rom_count) + function switchram(i) assert(i>=0 and i