Merge branch 'master' into 'master'

Add GBA, Sega, N64 to inlretro2/CLI support + minor cleanup.

See merge request InfiniteNesLives/INL-retro-progdump!13
This commit is contained in:
Paul Molloy 2018-12-10 05:44:19 +00:00
commit e8058e4da1
6 changed files with 167 additions and 111 deletions

View File

@ -87,7 +87,7 @@ local function process(process_opts, console_opts)
local rv = nil
local file
local rom_size = console_opts["prg_rom_size_kb"]
local rom_size = console_opts["rom_size_mbit"] * 128
local wram_size = console_opts["wram_size_kb"]
local mirror = console_opts["mirror"]

View File

@ -61,7 +61,7 @@ function main ()
--cart/mapper specific scripts
--NES mappers
local curcart = require "scripts.nes.nrom"
--local curcart = require "scripts.nes.nrom"
--local curcart = require "scripts.nes.mmc1"
--local curcart = require "scripts.nes.unrom"
--local curcart = require "scripts.nes.cnrom"
@ -97,15 +97,15 @@ function main ()
--local curcart = require "scripts.sega.genesis_v1"
--N64
--local curcart = require "scripts.n64.basic"
local curcart = require "scripts.n64.basic"
-- =====================================================
-- USERS: set cart_console to the to point to the mapper script you would like to use here.
-- =====================================================
local cart_console = "NES" --includes Famicom
--local cart_console = "NES" --includes Famicom
--local cart_console = "SNES"
--local cart_console = "SEGA"
--local cart_console = "N64"
local cart_console = "N64"
--local cart_console = "DMG"
--local cart_console = "GBA"
--local cart_console = "SMS"
@ -136,10 +136,10 @@ function main ()
-- =====================================================
local console_opts = {
mirror = nil, -- Only used by latest INL discrete flash boards, set to "H" or "V" to change board mirroring
prg_rom_size_kb = 32, -- Size of NES PRG-ROM in KByte
--prg_rom_size_kb = 8*1024, -- 8MByte ROM size example
chr_rom_size_kb = 8, -- Size of NES CHR-ROM in KByte
wram_size_kb = 0, -- Size of NES PRG-RAM/WRAM in KByte
prg_rom_size_kb = 256 * 128, -- Size of NES PRG-ROM in KByte
chr_rom_size_kb = 8, -- Size of NES CHR-ROM in KByte
wram_size_kb = 0, -- Size of NES PRG-RAM/WRAM in KByte
rom_size_mbit = 8, -- Size of ROM in Megabits, used for non-NES consoles.
}

View File

@ -7,12 +7,102 @@ local function isempty(s)
return s == nil or s == ''
end
-- Wrapper for managing GBA operations.
function gba_exec(process_opts, console_opts)
local gba = require "scripts.gba.basic"
-- Defensively filter out any console options that are irrelevant to GBA support.
local gba_opts = {
rom_size_mbit = console_opts["rom_size_mbit"],
wram_size_kb = console_opts["wram_size_kb"],
}
gba.process(process_opts, gba_opts)
end
-- Wrapper for managing Sega Genesis operations.
function genesis_exec(process_opts, console_opts)
local genesis = require "scripts.sega.genesis_v1"
-- Defensively filter out any console options that are irrelevant to Genesis support.
local genesis_opts = {
rom_size_mbit = console_opts["rom_size_mbit"],
wram_size_kb = console_opts["wram_size_kb"],
}
genesis.process(process_opts, genesis_opts)
end
-- Wrapper for managing N64 operations.
function n64_exec(process_opts, console_opts)
local n64 = require "scripts.n64.basic"
-- Defensively filter out any console options that are irrelevant to N64 support.
local n64_opts = {
rom_size_mbit = console_opts["rom_size_mbit"],
wram_size_kb = console_opts["wram_size_kb"],
}
n64.process(process_opts, n64_opts)
end
-- Wrapper for managing NES/Famicom operations.
function nes_exec(mapper, dump_filename, flash_filename, verify_filename, ramdump_filename, ramwrite_filename, console_opts)
function nes_exec(process_opts, console_opts)
local dict = require "scripts.app.dict"
local nes = require "scripts.app.nes"
-- Defensively filter out any console options that are irrelevant to NES support.
-- This will matter more when software support exists for other consoles.
local nes_opts = {
wram_size_kb = console_opts["wram_size_kb"],
prg_rom_size_kb = console_opts["prg_rom_size_kb"],
chr_rom_size_kb = console_opts["chr_rom_size_kb"],
mirror = nil -- Used by NROM mapper only, "H" or "V".
}
local mappers = {
action53_tsop = require "scripts.nes.action53_tsop",
action53 = require "scripts.nes.action53",
bnrom = require "scripts.nes.bnrom",
cdream = require "scripts.nes.cdream",
cninja = require "scripts.nes.cninja",
cnrom = require "scripts.nes.cnrom",
dualport = require "scripts.nes.dualport",
easynsf = require "scripts.nes.easyNSF",
fme7 = require "scripts.nes.fme7",
mapper30 = require "scripts.nes.mapper30",
mmc1 = require "scripts.nes.mmc1",
mmc3 = require "scripts.nes.mmc3",
mmc4 = require "scripts.nes.mmc4",
nrom = require "scripts.nes.nrom",
unrom = require "scripts.nes.unrom"
}
dict.io("IO_RESET")
dict.io("NES_INIT")
nes.detect_mapper_mirroring(true)
m = mappers[console_opts[mapper]]
if m == nil then
print("UNSUPPORTED MAPPER")
else
-- Attempt requested operations with hardware!
-- TODO: Do plumbing for interacting with RAM.
m.process(process_opts, console_opts)
end
end
-- Point of entry from C language half of program.
function main()
-- Globals passed in from C:
-- console_name: string, name of console.
-- mapper_name: string, name of mapper.
-- dump_filename: string, filename used for writing dumped data.
-- flash_filename: string, filename containing data to write cartridge.
-- verify_filename: string, filename used for writing back data written to cartridge for verification.
-- nes_prg_rom_size_kb: int, size of cartridge PRG-ROM in kb.
-- nes_chr_rom_size_kb: int, size of cartridge CHR-ROM in kb.
-- nes_wram_size_kb: int, size of cartridge WRAM in kb.
-- TODO: This should probably be one level up.
-- TODO: Ram probably needs a verify file as well?
@ -51,64 +141,12 @@ function nes_exec(mapper, dump_filename, flash_filename, verify_filename, ramdum
writeram_filename = ramwrite_filename,
}
-- Defensively filter out any console options that are irrelevant to NES support.
-- This will matter more when software support exists for other consoles.
local nes_opts = {
wram_size_kb = console_opts["wram_size_kb"],
prg_rom_size_kb = console_opts["prg_rom_size_kb"],
chr_rom_size_kb = console_opts["chr_rom_size_kb"],
mirror = nil -- Used by NROM mapper only, "H" or "V".
}
local mappers = {
action53_tsop = require "scripts.nes.action53_tsop",
action53 = require "scripts.nes.action53",
bnrom = require "scripts.nes.bnrom",
cdream = require "scripts.nes.cdream",
cninja = require "scripts.nes.cninja",
cnrom = require "scripts.nes.cnrom",
dualport = require "scripts.nes.dualport",
easynsf = require "scripts.nes.easyNSF",
fme7 = require "scripts.nes.fme7",
mapper30 = require "scripts.nes.mapper30",
mmc1 = require "scripts.nes.mmc1",
mmc3 = require "scripts.nes.mmc3",
mmc4 = require "scripts.nes.mmc4",
nrom = require "scripts.nes.nrom",
unrom = require "scripts.nes.unrom"
}
dict.io("IO_RESET")
dict.io("NES_INIT")
nes.detect_mapper_mirroring(true)
m = mappers[mapper]
if m == nil then
print("UNSUPPORTED MAPPER")
else
-- Attempt requested operations with hardware!
-- TODO: Do plumbing for interacting with RAM.
m.process(process_opts, console_opts)
end
end
-- Point of entry from C language half of program.
function main()
-- Globals passed in from C:
-- console_name: string, name of console.
-- mapper_name: string, name of mapper.
-- dump_filename: string, filename used for writing dumped data.
-- flash_filename: string, filename containing data to write cartridge.
-- verify_filename: string, filename used for writing back data written to cartridge for verification.
-- nes_prg_rom_size_kb: int, size of cartridge PRG-ROM in kb.
-- nes_chr_rom_size_kb: int, size of cartridge CHR-ROM in kb.
-- nes_wram_size_kb: int, size of cartridge WRAM in kb.
-- TODO: Add SNES support, as it appears to be currently usable?
local consoles = {
GBA = gba_exec,
GENESIS = genesis_exec,
NES = nes_exec,
N64 = n64_exec,
}
f = consoles[console_name]
if f == nil then
@ -118,10 +156,12 @@ function main()
local console_opts = {
wram_size_kb = nes_wram_size_kb,
prg_rom_size_kb = nes_prg_rom_size_kb,
chr_rom_size_kb = nes_chr_rom_size_kb
chr_rom_size_kb = nes_chr_rom_size_kb,
rom_size_mbit = rom_size_mbit,
mapper = mapper,
}
f(mapper_name, dump_filename, flash_filename, verify_filename, ramdump_filename, ramwrite_filename, console_opts)
f(process_opts, console_opts)
end
end

View File

@ -1,6 +1,6 @@
-- create the module's table
local genesis_v1 = {}
local n64 = {}
-- import required modules
local dict = require "scripts.app.dict"
@ -72,7 +72,7 @@ local function process(process_opts, console_opts)
local rv = nil
local file
local rom_size = console_opts["prg_rom_size_kb"]
local rom_size = console_opts["rom_size_mbit"] * 128
local wram_size = console_opts["wram_size_kb"]
local mirror = console_opts["mirror"]
@ -197,7 +197,7 @@ end
-- functions other modules are able to call
genesis_v1.process = process
n64.process = process
-- return the module's table
return genesis_v1
return n64

View File

@ -57,7 +57,7 @@ local function process(process_opts, console_opts)
local rv = nil
local file
local rom_size = console_opts["prg_rom_size_kb"]
local rom_size = console_opts["rom_size_mbit"] * 128
local wram_size = console_opts["wram_size_kb"]
local mirror = console_opts["mirror"]

View File

@ -34,7 +34,8 @@ const char *HELP = "Usage: inlretro [options]\n\n"\
" -v [verify_filename]\tIf provided, writeback written rom to this filename\n"
" -w [wram_size_kb]\tNES-only, size of WRAM in kb\n"\
" -x [prg_rom_size_kb]\tNES-only, size of PRG-ROM in kb\n"\
" -y [chr_rom_size_kb]\tNES-only, size of CHR-ROM in kb\n";
" -y [chr_rom_size_kb]\tNES-only, size of CHR-ROM in kb\n"\
" -z [rom_size_mbit]\tSize of ROM in megabits, non-NES systems.";
// Struct used to control functionality.
typedef struct {
@ -47,6 +48,8 @@ typedef struct {
int prg_rom_size_kb;
int wram_size_kb;
// General Functionality
int rom_size_mbit;
char *dump_filename;
char *program_filename;
char *ramdump_filename;
@ -66,13 +69,22 @@ int isValidROMSize(int x, int min) {
INLOptions* parseOptions(int argc, char *argv[]) {
// lower case flags suggested for average user
const char *FLAG_FORMAT = "a:b:hc:d:m:p:s:v:w:x:y:";
const char *FLAG_FORMAT = "a:b:hc:d:m:p:s:v:w:x:y:z:";
int index = 0;
int rv = 0;
// opterr = 0;
// Create options struct.
INLOptions *opts = calloc(1, sizeof(INLOptions));
opts->console_name = "";
opts->ramdump_filename = "";
opts->ramwrite_filename = "";
opts->dump_filename = "";
opts->mapper_name = "";
opts->program_filename = "";
opts->lua_filename = "";
opts->verify_filename = "";
//getopt returns args till done then returns -1
//string of possible args : denotes 1 required additional arg
//:: denotes optional additional arg follows
@ -92,6 +104,7 @@ INLOptions* parseOptions(int argc, char *argv[]) {
case 'w': opts->wram_size_kb = atoi(optarg); break;
case 'x': opts->prg_rom_size_kb = atoi(optarg); break;
case 'y': opts->chr_rom_size_kb = atoi(optarg); break;
case 'z': opts->rom_size_mbit = atoi(optarg); break;
case '?':
if(
( optopt == 'c' )
@ -158,13 +171,48 @@ void load (lua_State *L, const char *fname, int *w, int *h) {
}
// Setup Lua environment.
lua_State *lua_init() {
lua_State *lua_init(INLOptions *opts) {
lua_State *L = luaL_newstate(); //opens Lua
luaL_openlibs(L); //opens the standard libraries
// Register C functions that can be called from Lua.
lua_pushcfunction(L, lua_usb_vend_xfr);
lua_setglobal(L, "usb_vend_xfr");
// Pass args to Lua
// TODO: Do this in a less terrible way / don't register a million globals.
lua_pushstring(L, opts->console_name);
lua_setglobal(L, "console_name");
lua_pushstring(L, opts->mapper_name);
lua_setglobal(L, "mapper_name");
lua_pushstring(L, opts->dump_filename);
lua_setglobal(L, "dump_filename");
lua_pushstring(L, opts->program_filename);
lua_setglobal(L, "flash_filename");
lua_pushstring(L, opts->verify_filename);
lua_setglobal(L, "verify_filename");
lua_pushstring(L, opts->ramdump_filename);
lua_setglobal(L, "ramdump_filename");
lua_pushstring(L, opts->ramwrite_filename);
lua_setglobal(L, "ramwrite_filename");
lua_pushinteger(L, opts->rom_size_mbit);
lua_setglobal(L, "rom_size_mbit");
lua_pushinteger(L, opts->wram_size_kb);
lua_setglobal(L, "nes_wram_size_kb");
lua_pushinteger(L, opts->prg_rom_size_kb);
lua_setglobal(L, "nes_prg_rom_size_kb");
lua_pushinteger(L, opts->chr_rom_size_kb);
lua_setglobal(L, "nes_chr_rom_size_kb");
return L;
}
@ -239,8 +287,8 @@ int main(int argc, char *argv[])
}
}
// Start up Lua
L = lua_init();
// Start up Lua.
L = lua_init(opts);
// Setup and check connection to USB Device.
// TODO get usb device settings from usb_device.lua
@ -258,43 +306,11 @@ int main(int argc, char *argv[])
check_mem(transfer);
check(transfer->handle != NULL, "Unable to open INL retro-prog usb device handle.");
// Pass args to Lua
// TODO: Move to luainit
lua_pushstring(L, opts->console_name);
lua_setglobal(L, "console_name");
lua_pushstring(L, opts->mapper_name);
lua_setglobal(L, "mapper_name");
lua_pushstring(L, opts->dump_filename);
lua_setglobal(L, "dump_filename");
lua_pushstring(L, opts->program_filename);
lua_setglobal(L, "flash_filename");
lua_pushstring(L, opts->verify_filename);
lua_setglobal(L, "verify_filename");
lua_pushstring(L, opts->ramdump_filename);
lua_setglobal(L, "ramdump_filename");
lua_pushstring(L, opts->ramwrite_filename);
lua_setglobal(L, "ramwrite_filename");
lua_pushinteger(L, opts->wram_size_kb);
lua_setglobal(L, "nes_wram_size_kb");
lua_pushinteger(L, opts->prg_rom_size_kb);
lua_setglobal(L, "nes_prg_rom_size_kb");
lua_pushinteger(L, opts->chr_rom_size_kb);
lua_setglobal(L, "nes_chr_rom_size_kb");
// USB device is open, pass args and control over to Lua.
// If lua_filename isn't set from args, use default script.
char *DEFAULT_SCRIPT = "scripts/inlretro.lua";
char *script = DEFAULT_SCRIPT;
if (opts->lua_filename) {
if (strlen(opts->lua_filename)) {
script = opts->lua_filename;
}
check(!(luaL_loadfile(L, script) || lua_pcall(L, 0, 0, 0)),