Skip to content

Add GameShark and Game Booster emulation #1916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ares/gb/cartridge/cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Cartridge& cartridge = cartridgeSlot.cartridge;

auto Cartridge::allocate(Node::Port parent) -> Node::Peripheral {
auto system = (Node::System)parent->parent();
transferPak = system->name() == "Transfer Pak";
transferPak = (system->name() == "Transfer Pak") || (system->name() == "Nintendo 64 Cartridge");
return node = parent->append<Node::Peripheral>(string{parent->family(), " Cartridge"});
}

Expand Down
2 changes: 2 additions & 0 deletions ares/gb/cartridge/slot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ struct CartridgeSlot {
Node::Port port;
Cartridge cartridge;

auto connected() const -> bool { return (bool)cartridge.node; }

//slot.cpp
CartridgeSlot(string name);
auto load(Node::Object) -> void;
Expand Down
20 changes: 15 additions & 5 deletions ares/n64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,24 @@ ares_add_sources(
n64
INCLUDED #
cartridge/cartridge.hpp
cartridge/debugger.cpp
cartridge/flash.cpp
cartridge/isviewer.cpp
cartridge/joybus.cpp
cartridge/rtc.cpp
cartridge/serialization.cpp
cartridge/slot.cpp
cartridge/slot.hpp
cartridge/board/board.cpp
cartridge/board/board.hpp
cartridge/board/flash.cpp
cartridge/board/flash.hpp
cartridge/board/isviewer.cpp
cartridge/board/isviewer.hpp
cartridge/board/rtc.cpp
cartridge/board/rtc.hpp
cartridge/board/gs-eeprom.cpp
cartridge/board/gs-eeprom.hpp
cartridge/board/generic.cpp
cartridge/board/nus-01a.cpp
cartridge/board/nus-07a.cpp
cartridge/board/datel-ref1256.cpp
cartridge/board/datel-ref1329.cpp
)

ares_add_sources(
Expand Down
5 changes: 5 additions & 0 deletions ares/n64/accuracy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ struct Accuracy {
// Emulate the PIF's checksum security check
static constexpr bool IPL2Checksum = true;
};

struct Cartridge {
// Don't clear the base address of an inserted GameShark when resetting
static constexpr bool GameSharkReset = 0 | Reference;
};
};
83 changes: 83 additions & 0 deletions ares/n64/cartridge/board/board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace Board {

#include "nus-01a.cpp"
#include "nus-07a.cpp"
#if defined(CORE_GB)
#include "datel-ref1256.cpp"
#endif
#include "datel-ref1329.cpp"
#include "generic.cpp"

auto Interface::title() const -> string {
return cartridge.information.title;
}

auto Interface::cic() const -> string {
return cartridge.information.cic;
}

template<typename T>
auto Interface::load(T& rom, string name) -> bool {
rom.reset();
if(auto fp = pak->read(name)) {
rom.allocate(fp->size());
rom.load(fp);
return true;
}
return false;
}

template<typename T>
auto Interface::save(T& rom, string name) -> bool {
if(auto fp = pak->write(name)) {
rom.save(fp);
return true;
}
return false;
}

auto Interface::joybusEeprom(Memory::Writable16& eeprom, n8 send, n8 recv, n8 input[], n8 output[]) -> n1 {
n1 valid = 0;

//status
if(input[0] == 0x00 || input[0] == 0xff) {
//cartridge EEPROM (4kbit)
if(eeprom.size == 512) {
output[0] = 0x00;
output[1] = 0x80;
output[2] = 0x00;
valid = 1;
}

//cartridge EEPROM (16kbit)
if(eeprom.size == 2048) {
output[0] = 0x00;
output[1] = 0xc0;
output[2] = 0x00;
valid = 1;
}
}

//read EEPROM
if(input[0] == 0x04 && send >= 2) {
u32 address = input[1] * 8;
for(u32 index : range(recv)) {
output[index] = eeprom.read<Byte>(address++);
}
valid = 1;
}

//write EEPROM
if(input[0] == 0x05 && send >= 2 && recv >= 1) {
u32 address = input[1] * 8;
for(u32 index : range(send - 2)) {
eeprom.write<Byte>(address++, input[2 + index]);
}
output[0] = 0x00;
valid = 1;
}

return valid;
}

}
32 changes: 32 additions & 0 deletions ares/n64/cartridge/board/board.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Board {

struct Interface {
VFS::Pak pak;

Interface(Cartridge& cartridge) : cartridge(cartridge) {}
virtual ~Interface() = default;
virtual auto load(Node::Object) -> void {}
virtual auto unload(Node::Object) -> void {}
virtual auto save() -> void {}
virtual auto readBus(u32 address) -> u16 { return (address & 0xFFFF); };
virtual auto writeBus(u32 address, u16 data) -> void {};
virtual auto joybusComm(n8 send, n8 recv, n8 input[], n8 output[]) -> n2 { return 0; };
virtual auto tickRTC() -> void {}
virtual auto clock() -> void {}
virtual auto title() const -> string;
virtual auto cic() const -> string;
virtual auto power(bool reset) -> void {}
virtual auto serialize(serializer&) -> void {}

template<typename T>
auto load(T& rom, string name) -> bool;
template<typename T>
auto save(T& rom, string name) -> bool;

//there isn't really a better place to put this
auto joybusEeprom(Memory::Writable16& eeprom, n8 send, n8 recv, n8 input[], n8 output[]) -> n1;

Cartridge& cartridge;
};

}
Loading