Skip to content

Commit

Permalink
desktop-ui: enable loading rom folders from the cmd line (ares-emulat…
Browse files Browse the repository at this point in the history
…or#1656)

Needs to merge ares-emulator#1654 first.

Enables loading folders instead files from cmd line.
Removes loading firmware files from rom folders in sfc mia (firmware
data would be loaded twice, db hashes would not match anymore).
  • Loading branch information
hackgrid authored Oct 1, 2024
1 parent 0337526 commit ea77623
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ares/sfc/coprocessor/dip/dip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct DIP {
//serialization.cpp
auto serialize(serializer&) -> void;

n8 value = 0x00;
n8 value = 0x03; // default game time used for the competition is 6 minutes
};

extern DIP dip;
2 changes: 1 addition & 1 deletion desktop-ui/desktop-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ auto nall::main(Arguments arguments) -> void {

program.startGameLoad.reset();
for(auto argument : arguments) {
if(file::exists(argument)) program.startGameLoad.append(argument);
if(file::exists(argument) || directory::exists(argument)) program.startGameLoad.append(argument);
}

Instances::presentation.construct();
Expand Down
2 changes: 1 addition & 1 deletion mia/Database/Super Famicom Boards.bml
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ board: EVENT-CC92
memory type=ROM content=Level-3
dip
processor manufacturer=NEC architecture=uPD7725
map address=20-3f,a0-bf:8000-ffff mask=0x7fff
map address=20-3f,a0-bf:8000-ffff mask=0x3fff
memory type=ROM content=Program architecture=uPD7725
memory type=ROM content=Data architecture=uPD7725
memory type=RAM content=Data architecture=uPD7725
Expand Down
108 changes: 108 additions & 0 deletions mia/Database/Super Famicom.bml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,60 @@ game
size: 0x80000
content: Download

//sha256 is without firmware
game
sha256: 67c1a4917f4cd0fd704b83330a7e91763736c2d2a10a7e12318fdac54cd9c6c6
title: Campus Challenge '92
name: Super Nintendo Campus Challenge 1992
region: Japan
revision: 1.0
board: EVENT-CC92
memory
type: ROM
size: 0x40000
content: Program
memory
type: ROM
size: 0x80000
content: Level-1
memory
type: ROM
size: 0x80000
content: Level-2
memory
type: ROM
size: 0x80000
content: Level-3
memory
type: RAM
size: 0x2000
content: Save
volatile
memory
type: ROM
size: 0x1800
content: Program
manufacturer: NEC
architecture: uPD7725
identifier: DSP1
memory
type: ROM
size: 0x800
content: Data
manufacturer: NEC
architecture: uPD7725
identifier: DSP1
memory
type: RAM
size: 0x200
content: Data
manufacturer: NEC
architecture: uPD7725
identifier: DSP1
volatile
oscillator
frequency: 8000000

game
sha256: 6e7dcbb4df32903d6ff5da1e308342c0a72f5af3f11479cf49391dc3a17d5d7b
title: キャプテンコマンドー
Expand Down Expand Up @@ -12126,6 +12180,60 @@ game
size: 0x200000
content: Program

//sha256 is without firmware
game
sha256: 5443a97e9c40e25821a8fb8c91b63c7bd8c3060d9ff888ee6c573b87b53935f4
title: PowerFest '94
name: PowerFest '94
region: USA
revision: 1.0
board: EVENT-PF94
memory
type: ROM
size: 0x40000
content: Program
memory
type: ROM
size: 0x80000
content: Level-1
memory
type: ROM
size: 0x80000
content: Level-2
memory
type: ROM
size: 0x100000
content: Level-3
memory
type: RAM
size: 0x2000
content: Save
volatile
memory
type: ROM
size: 0x1800
content: Program
manufacturer: NEC
architecture: uPD7725
identifier: DSP1
memory
type: ROM
size: 0x800
content: Data
manufacturer: NEC
architecture: uPD7725
identifier: DSP1
memory
type: RAM
size: 0x200
content: Data
manufacturer: NEC
architecture: uPD7725
identifier: DSP1
volatile
oscillator
frequency: 8000000

game
sha256: 06c8fc466805f97c9147711b2d8370d4f4d05d9fa3a916f17aa1682f73c9a63b
title: Power Instinct
Expand Down
59 changes: 42 additions & 17 deletions mia/medium/super-famicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,13 @@ struct SuperFamicom : Cartridge {
auto SuperFamicom::load(string location) -> bool {
vector<u8> rom;
string directory = location;
if(directory::exists(location)) {
auto files = directory::files(location, "*.rom");
append(rom, {location, "program.rom" });
append(rom, {location, "data.rom" });
append(rom, {location, "expansion.rom"});
for(auto& file : files.match("*.program.rom")) append(rom, {location, file});
for(auto& file : files.match("*.data.rom" )) append(rom, {location, file});
for(auto& file : files.match("*.boot.rom" )) append(rom, {location, file});
} else if(rom = Medium::read(location)) {
directory = Location::dir(location);
//append firmware to the ROM if it is missing
auto manifest = analyze(rom);
auto document = BML::unserialize(manifest);
bool local_firmware = false;
bool folder = false;

auto append_missing_firmware = [&](auto document)
{
if(auto identifier = document["game/board/memory/identifier"]) {
if(!firmwareRomSize()) {
if(!firmwareRomSize() && !local_firmware) {
auto id = identifier.string();
array_view<u8> view;
if(id == "Cx4" ) view = Resource::SuperFamicom::Cx4;
Expand All @@ -66,15 +58,48 @@ auto SuperFamicom::load(string location) -> bool {
if(id == "ST018") view = Resource::SuperFamicom::ST018;
while(view) rom.append(*view++);
}
}
}
};

if(directory::exists(location)) {
auto files = directory::files(location, "*.rom");
append(rom, {location, "program.rom" });
append(rom, {location, "data.rom" });
append(rom, {location, "expansion.rom"});
for(auto& file : files.match("slot-*.rom" )) { append(rom, {location, file}); }
for(auto& file : files.match("*.program.rom")) { append(rom, {location, file}); local_firmware = true; }
for(auto& file : files.match("*.data.rom" )) { append(rom, {location, file}); local_firmware = true; }
for(auto& file : files.match("*.boot.rom" )) { append(rom, {location, file}); }
folder = true;
} else if(rom = Medium::read(location)) {
directory = Location::dir(location);
}

if(!rom) return false;


//append firmware to the ROM if it is missing
auto tmp_manifest = analyze(rom);
auto document = BML::unserialize(tmp_manifest);
append_missing_firmware(document);

this->sha256 = Hash::SHA256(rom).digest();
this->location = location;
this->manifest = Medium::manifestDatabase(sha256);

if(!manifest) {
auto local_manifest = location.replace({".", location.split(".").last()}, ".bml");
if (folder)
local_manifest = directory.append("manifest.bml");
if(file::exists(local_manifest)) {
manifest = file::read(local_manifest);
}
}

document = BML::unserialize(manifest);
append_missing_firmware(document); // if auto-detect failed, use chips from the manifest

if(!manifest) manifest = analyze(rom);
auto document = BML::unserialize(manifest);
document = BML::unserialize(manifest);
if(!document) return false;

pak = new vfs::directory;
Expand Down

0 comments on commit ea77623

Please sign in to comment.