Merge branch 'unrom-find-banktable' into 'master'

UNROM: automatically find banktable

See merge request InfiniteNesLives/INL-retro-progdump!10
This commit is contained in:
Paul Molloy 2018-12-01 18:33:52 +00:00
commit c9e2d643ee
4 changed files with 60 additions and 9 deletions

2
.gitignore vendored
View File

@ -23,4 +23,4 @@ host/source/lua/liblua.a
host/inlretro
# OS X Metadata
.DS_Store
.DS_Store

View File

@ -10,7 +10,7 @@ local snes = require "scripts.app.snes"
-- file constants
-- local functions
local function dumptofile( file, sizeKB, map, mem, debug )
local function dumptocallback( callback, sizeKB, map, mem, debug )
local buff0 = 0
local buff1 = 1
@ -94,7 +94,7 @@ local function dumptofile( file, sizeKB, map, mem, debug )
--need to setup buffer manager to nak anytime something like this happens
--the following setup slows down everything due to status waits..
-- buffers.status_wait({buff0}, {"DUMPED"})
-- file:write( dict.buffer_payload_in( buff_size ))
-- callback( dict.buffer_payload_in( buff_size ))
-- buffers.status_wait({buff1}, {"DUMPED"})
--stm adapter having issues with race situation..
@ -106,7 +106,7 @@ local function dumptofile( file, sizeKB, map, mem, debug )
--print(nak, "cur_buff->status: ", cur_buff_status)
cur_buff_status = dict.buffer("GET_CUR_BUFF_STATUS")
end
file:write( dict.buffer_payload_in( buff_size ))
callback( dict.buffer_payload_in( buff_size ))
-- print("dumped page:", i)
--if ( (i % (1024*1024/buff_size/16)) == 0) then
@ -143,6 +143,15 @@ local function dumptofile( file, sizeKB, map, mem, debug )
dict.buffer("RAW_BUFFER_RESET")
end
local function dumptofile( file, sizeKB, map, mem, debug )
dumptocallback(
function (data)
file:write(data)
end,
sizeKB, map, mem, debug
)
end
--//main collected as much data about cart as possible without reading roms
--//now it's time to start running CRC's to try and finalize mapper/config
@ -507,6 +516,7 @@ end
dump.dump_nes = dump_nes
dump.dump_snes = dump_snes
dump.dumptofile = dumptofile
dump.dumptocallback = dumptocallback
-- return the module's table
return dump

View File

@ -31,7 +31,8 @@ function nes_exec(mapper, dump_filename, flash_filename, verify_filename)
local mappers = {
mmc1 = require "scripts.nes.mmc1",
mmc3 = require "scripts.nes.mmc3",
nrom = require "scripts.nes.nrom"
nrom = require "scripts.nes.nrom",
unrom = require "scripts.nes.unrom"
}
dict.io("IO_RESET")
@ -72,4 +73,4 @@ function main()
end
-- Don't do this. Next iteration will call a function, not the whole script.
main()
main()

View File

@ -10,8 +10,8 @@ local flash = require "scripts.app.flash"
-- file constants & variables
local mapname = "UxROM"
local banktable_base = 0xCC84 --Nomolos
--Nomolos' bank table is at $CC84 so hard code that for now
local banktable_base = nil
--Nomolos' bank table is at $CC84
--wr_bank_table(0xCC84, 32)
--Owlia bank table
--wr_bank_table(0xE473, 32)
@ -67,6 +67,35 @@ local function prgrom_manf_id( debug )
end
--find a viable banktable location
local function find_banktable( banktable_size )
local search_base = 0x0C -- search in $C000-$F000, the fixed bank
local KB_search_space = 16
--get the fixed bank's content
local search_data = ""
dump.dumptocallback(
function (data)
search_data = search_data .. data
end,
KB_search_space, search_base, "NESCPU_4KB", false
)
--construct the byte sequence that we need
local searched_sequence = ""
while ( searched_sequence:len() < banktable_size ) do
searched_sequence = searched_sequence .. string.char(searched_sequence:len())
end
--search for the banktable in the fixed bank
position_in_fixed_bank = string.find( search_data, searched_sequence, 1, true )
if ( position_in_fixed_bank == nil ) then
return nil
end
--compute the cpu offset of this data
return 0xC000 + position_in_fixed_bank - 1
end
--dump the PRG ROM
local function dump_prgrom( file, rom_size_KB, debug )
@ -279,7 +308,18 @@ local function process( test, read, erase, program, verify, dumpfile, flashfile,
print("\nDumping PRG-ROM...")
file = assert(io.open(dumpfile, "wb"))
--TODO find bank table to avoid bus conflicts!
--find bank table to avoid bus conflicts
if ( banktable_base == nil ) then
local KB_per_bank = 16
banktable_base = find_banktable( prg_size / KB_per_bank )
if ( banktable_base == nil ) then
print( "BANKTABLE NOT FOUND" )
return
else
print( "found banktable addr = " .. banktable_base )
end
end
--dump cart into file
--dump.dumptofile( file, prg_size, "UxROM", "PRGROM", true )
dump_prgrom(file, prg_size, false)