Merge branch 'cleanup' into 'master'

Cleanup Genesis Script, host Makefile

See merge request InfiniteNesLives/INL-retro-progdump!17
This commit is contained in:
Paul Molloy 2018-12-30 06:14:19 +00:00
commit 3b85cf152a
2 changed files with 95 additions and 163 deletions

View File

@ -1,55 +1,58 @@
#compiler flags: -Wall Warnings all, -g gdb debug markings, #compiler flags: -Wall Warnings all, -g gdb debug markings,
CFLAGS=-Wall -O CFLAGS=-Wall -O
LDFLAGS= -llua -lusb-1.0 -Lsource/lua -lm LDFLAGS= -llua -lusb-1.0 -Lsource/lua
INCLUDE= -I ./include -I ../shared INCLUDE= -I ./include -I ../shared
LDFLAGS_WINDOWS= -L ./winlib $(LDFLAGS) LDFLAGS_WINDOWS= -L ./winlib $(LDFLAGS)
LDFLAGS_UNIX= -lm $(LDFLAGS) LDFLAGS_UNIX= -lm $(LDFLAGS)
CC= gcc CC= gcc
SOURCES=$(wildcard source/*.c) SOURCES=$(wildcard source/*.c)
OBJECTS=$(SOURCES:.c=.o) OBJECTS=$(SOURCES:.c=.o)
# Use GCC preprocessor to determine dependencies for all source files. # Use GCC preprocessor to determine dependencies for all source files.
DEPS=$(OBJECTS:.o=.d) DEPS=$(OBJECTS:.o=.d)
%.d: %.c %.d: %.c
@$(CC) $(CFLAGS) $(INCLUDE) $< -MM -MT $(@:.d=.o) >$@ @$(CC) $(CFLAGS) $(INCLUDE) $< -MM -MT $(@:.d=.o) >$@
# Include generated .d Makefile fragments to manage object dependencies. # Include generated .d Makefile fragments to manage object dependencies.
-include $(DEPS) -include $(DEPS)
# Provide recipes for building all objects, dependencies managed via earlier inclusion. # Provide recipes for building all objects, dependencies managed via earlier inclusion.
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
# TODO: Pass through platform when building liblua. .PHONY: clean linux macosx
liblua:
$(MAKE) -C source/lua a # TODO: Pass through platform when building liblua.
liblua:
TARGET=inlretro $(MAKE) -C source/lua a
#default to windows build TARGET=inlretro
all: liblua $(DEPS) $(OBJECTS)
$(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_WINDOWS) #default to windows build
all: liblua $(DEPS) $(OBJECTS)
#unix build doesn't need winlib directory as libusb should be installed on OS. $(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_WINDOWS)
#sudo apt-get install libusb-1.0-0-dev
unix: liblua $(DEPS) $(OBJECTS) #unix build doesn't need winlib directory as libusb should be installed on OS.
$(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_UNIX) #sudo apt-get install libusb-1.0-0-dev
unix: liblua $(DEPS) $(OBJECTS)
linux: $(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_UNIX)
gcc source/inlprog.c source/usb_operations.c -o inlretro -lusb-1.0 -lm -L lua include
# Convienience in case its not clear Unix really means not-Windows.
# "make debug" will build program with debug print messages linux: unix
# -DDEBUG show debug logs macosx: unix
# -g build with gdb debug tags
debug: CFLAGS += -DDEBUG -g # "make debug" will build program with debug print messages
debug: all # -DDEBUG show debug logs
# -g build with gdb debug tags
#unix debug build debug: CFLAGS += -DDEBUG -g
unixdebug: CFLAGS += -DDEBUG -g debug: all
unixdebug: unix
#unix debug build
#clean on unix and windows(.exe) unixdebug: CFLAGS += -DDEBUG -g
.PHONY: clean unixdebug: unix
clean:
$(MAKE) -C source/lua clean #clean on unix and windows(.exe)
rm -f $(TARGET) $(TARGET).exe $(OBJECTS) $(DEPS) $(LUAOBJ) source/lua/liblua.a
clean:
$(MAKE) -C source/lua clean
rm -f $(TARGET) $(TARGET).exe $(OBJECTS) $(DEPS) $(LUAOBJ) source/lua/liblua.a

View File

@ -5,15 +5,15 @@ local genesis_v1 = {}
-- import required modules -- import required modules
local dict = require "scripts.app.dict" local dict = require "scripts.app.dict"
local dump = require "scripts.app.dump" local dump = require "scripts.app.dump"
local flash = require "scripts.app.flash"
local snes = require "scripts.app.snes"
local apperase = require "scripts.app.erase"
-- file constants -- file constants
-- local functions -- local functions
--dump the SNES ROM starting at the provided bank local function unsupported(operation)
print("\nUNSUPPORTED OPERATION: \"" .. operation .. "\" not implemented yet for Sega Genesis.\n")
end
--/ROMSEL is always low for this dump --/ROMSEL is always low for this dump
local function dump_rom( file, rom_size_KB, debug ) local function dump_rom( file, rom_size_KB, debug )
@ -24,19 +24,21 @@ local function dump_rom( file, rom_size_KB, debug )
local num_reads = rom_size_KB / KB_per_bank local num_reads = rom_size_KB / KB_per_bank
local read_count = 0 local read_count = 0
while ( read_count < num_reads ) do while (read_count < num_reads) do
if debug then print( "dump ROM part ", read_count, " of ", num_reads) end if debug then print( "Dumping ROM part ", read_count + 1, " of ", num_reads) end
if (read_count %8 == 0) then -- A "large" Genesis ROM is 24 banks, many are 8 and 16 - status every 4 is reasonable.
print("dumping ROM bank: ", read_count, " of ", num_reads-1) -- The largest published Genesis game is Super Street Fighter 2, which is 40 banks!
if (read_count % 4 == 0) then
print("dumping ROM bank: ", read_count, " of ", num_reads - 1)
end end
--select desired bank -- Select desired bank.
dict.sega("SET_BANK", read_count) dict.sega("SET_BANK", read_count)
dump.dumptofile( file, KB_per_bank/2, addr_base, "GENESIS_ROM_PAGE0", false ) dump.dumptofile(file, KB_per_bank/2, addr_base, "GENESIS_ROM_PAGE0", debug)
dump.dumptofile( file, KB_per_bank/2, addr_base, "GENESIS_ROM_PAGE1", false ) dump.dumptofile(file, KB_per_bank/2, addr_base, "GENESIS_ROM_PAGE1", debug)
read_count = read_count + 1 read_count = read_count + 1
end end
@ -46,129 +48,56 @@ end
--Cart should be in reset state upon calling this function --Cart should be in reset state upon calling this function
--this function processes all user requests for this specific board/mapper --this function processes all user requests for this specific board/mapper
local function process(process_opts, console_opts) local function process(process_opts, console_opts)
local test = process_opts["test"]
local read = process_opts["read"]
local erase = process_opts["erase"]
local program = process_opts["program"]
local verify = process_opts["verify"]
local dumpfile = process_opts["dump_filename"]
local flashfile = process_opts["flash_filename"]
local verifyfile = process_opts["verify_filename"]
local rv = nil
local file local file
local rom_size = console_opts["rom_size_mbit"] * 128 local rom_size = console_opts["rom_size_mbit"] * 128
local wram_size = console_opts["wram_size_kb"]
local mirror = console_opts["mirror"]
-- Initialize device i/o for SEGA
--initialize device i/o for SEGA
dict.io("IO_RESET") dict.io("IO_RESET")
dict.io("SEGA_INIT") dict.io("SEGA_INIT")
--test cart by reading manf/prod ID -- TODO: test cart by reading manf/prod ID
if test then if process_opts["test"] then
unsupported("test")
-- print("Testing SNES board");
--
-- --SNES detect HiROM or LoROM & RAM
--
-- --SNES detect if able to read flash ID's
-- if not rom_manf_id(true) then
-- print("ERROR unable to read flash ID")
-- return
-- end
end end
-- TODO: dump the ram to file
--dump the ram to file
if dumpram then if dumpram then
unsupported("dumpram")
-- print("\nDumping SAVE RAM...")
--
-- --may have to verify /RESET is high to enable SRAM
--
-- file = assert(io.open(ramdumpfile, "wb"))
--
-- --dump cart into file
-- dump_ram(file, rambank, ram_size, snes_mapping, true)
--
-- --may disable SRAM by placing /RESET low
--
-- --close file
-- assert(file:close())
--
-- print("DONE Dumping SAVE RAM")
end end
--dump the cart to dumpfile -- Dump the cart to dumpfile.
if read then if process_opts["read"] then
print("\nDumping SEGA ROM...") print("\nDumping SEGA ROM...")
file = assert(io.open(dumpfile, "wb")) file = assert(io.open(process_opts["dump_filename"], "wb"))
--dump cart into file --dump cart into file
dump_rom(file, rom_size, true) dump_rom(file, rom_size, false)
--close file --close file
assert(file:close()) assert(file:close())
print("DONE Dumping SEGA ROM") print("DONE Dumping SEGA ROM")
end end
--erase the cart -- TODO: erase the cart
if erase then if process_opts["erase"] then
unsupported("erase")
-- erase_flash()
end end
--write to wram on the cart -- TODO: write to wram on the cart
if writeram then if writeram then
unsupported("writeram")
-- print("\nWritting to SAVE RAM...")
--
-- file = assert(io.open(ramwritefile, "rb"))
--
-- --flash.write_file( file, ram_size, "NOVAR", "PRGRAM", false )
-- --flash.write_file( file, ram_size, "LOROM_3VOLT", "SNESROM", false )
-- wr_ram(file, rambank, ram_size, snes_mapping, true)
--
-- --close file
-- assert(file:close())
--
-- print("DONE Writting SAVE RAM")
end end
-- TODO: program flashfile to the cart
--program flashfile to the cart if process_opts["program"] then
if program then unsupported("program")
-- --open file
-- file = assert(io.open(flashfile, "rb"))
-- --determine if auto-doubling, deinterleaving, etc,
-- --needs done to make board compatible with rom
--
-- --flash cart
-- flash_rom(file, rom_size, snes_mapping, true)
--
-- --close file
-- assert(file:close())
end end
--verify flashfile is on the cart -- TODO: verify flashfile is on the cart
if verify then if process_opts["verify"] then
-- print("\nPost dumping SNES ROM...") unsupported("verify")
-- --for now let's just dump the file and verify manually
--
-- file = assert(io.open(verifyfile, "wb"))
--
-- --dump cart into file
-- dump_rom(file, rom_size, true)
--
-- --close file
-- assert(file:close())
-- print("DONE Post dumping SNES ROM")
end end
dict.io("IO_RESET") dict.io("IO_RESET")
@ -176,13 +105,13 @@ end
-- global variables so other modules can use them -- global variables so other modules can use them
-- NONE
-- call functions desired to run when script is called/imported -- call functions desired to run when script is called/imported
-- NONE
-- functions other modules are able to call -- functions other modules are able to call
genesis_v1.process = process genesis_v1.process = process
-- return the module's table -- return the module's table
return genesis_v1 return genesis_v1