diff --git a/.gitignore b/.gitignore index 5c4af9b..a1248b8 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ host/source/lua/liblua.a host/inlretro # OS X Metadata -.DS_Store \ No newline at end of file +.DS_Store diff --git a/host/scripts/app/dump.lua b/host/scripts/app/dump.lua index 0bda6a1..95863bf 100644 --- a/host/scripts/app/dump.lua +++ b/host/scripts/app/dump.lua @@ -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 diff --git a/host/scripts/inlretro2.lua b/host/scripts/inlretro2.lua index 3402d9f..3706484 100644 --- a/host/scripts/inlretro2.lua +++ b/host/scripts/inlretro2.lua @@ -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() \ No newline at end of file +main() diff --git a/host/scripts/nes/unrom.lua b/host/scripts/nes/unrom.lua index 2d4b8e9..7f2cf5f 100644 --- a/host/scripts/nes/unrom.lua +++ b/host/scripts/nes/unrom.lua @@ -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)