Skip to content

Commit

Permalink
Update to ares v112 release.
Browse files Browse the repository at this point in the history
  - Nintendo 64: emulation core started
  • Loading branch information
byuu committed Apr 28, 2020
1 parent 470c2ec commit c43fc28
Show file tree
Hide file tree
Showing 46 changed files with 759 additions and 7 deletions.
4 changes: 4 additions & 0 deletions ares/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ ifneq ($(filter $(cores),sfc),)
include $(ares.path)/sfc/GNUmakefile
endif

ifneq ($(filter $(cores),n64),)
include $(ares.path)/n64/GNUmakefile
endif

ifneq ($(filter $(cores),sg),)
include $(ares.path)/sg/GNUmakefile
endif
Expand Down
Empty file.
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions ares/ares/information.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ares {
static const string Name = "ares";
static const string Version = "111.22";
static const string Version = "112";
static const string License = "GPLv3+";
static const string Website = "https://ares.dev";

//incremented only when serialization format changes
static const string SerializerVersion = "111";
static const string SerializerVersion = "112";
}
2 changes: 2 additions & 0 deletions ares/component/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ares.objects += $(if $(findstring spc700,$(ares.components)),ares-processor-spc7
ares.objects += $(if $(findstring tlcs900h,$(ares.components)),ares-processor-tlcs900h)
ares.objects += $(if $(findstring upd96050,$(ares.components)),ares-processor-upd96050)
ares.objects += $(if $(findstring v30mz,$(ares.components)),ares-processor-v30mz)
ares.objects += $(if $(findstring vr4300,$(ares.components)),ares-processor-vr4300)
ares.objects += $(if $(findstring wdc65816,$(ares.components)),ares-processor-wdc65816)
ares.objects += $(if $(findstring z80,$(ares.components)),ares-processor-z80)

Expand Down Expand Up @@ -48,6 +49,7 @@ $(object.path)/ares-processor-spc700.o: $(ares.path)/component/processor/spc70
$(object.path)/ares-processor-tlcs900h.o: $(ares.path)/component/processor/tlcs900h/tlcs900h.cpp
$(object.path)/ares-processor-upd96050.o: $(ares.path)/component/processor/upd96050/upd96050.cpp
$(object.path)/ares-processor-v30mz.o: $(ares.path)/component/processor/v30mz/v30mz.cpp
$(object.path)/ares-processor-vr4300.o: $(ares.path)/component/processor/vr4300/vr4300.cpp
$(object.path)/ares-processor-wdc65816.o: $(ares.path)/component/processor/wdc65816/wdc65816.cpp
$(object.path)/ares-processor-z80.o: $(ares.path)/component/processor/z80/z80.cpp

Expand Down
2 changes: 2 additions & 0 deletions ares/component/processor/vr4300/serialization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
auto VR4300::serialize(serializer& s) -> void {
}
11 changes: 11 additions & 0 deletions ares/component/processor/vr4300/vr4300.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <ares/ares.hpp>
#include "vr4300.hpp"

namespace ares {

#include "serialization.cpp"

auto VR4300::power() -> void {
}

}
15 changes: 15 additions & 0 deletions ares/component/processor/vr4300/vr4300.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

//NEC VR4300

namespace ares {

struct VR4300 {
//vr4300.cpp
auto power() -> void;

//serialization.cpp
auto serialize(serializer&) -> void;
};

}
4 changes: 2 additions & 2 deletions ares/msx/cartridge/cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ auto Cartridge::connect() -> void {
}

auto document = BML::unserialize(information.manifest);
information.name = document["game/label"].text();
information.region = document["game/region"].text();
information.name = document["game/label"].string();
information.region = document["game/region"].string();

if(auto memory = document["game/board/memory(type=ROM,content=Program)"]) {
rom.allocate(memory["size"].natural());
Expand Down
13 changes: 13 additions & 0 deletions ares/n64/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ares.components += vr4300

ares.objects += ares-n64-interface ares-n64-system
ares.objects += ares-n64-cartridge ares-n64-controller
ares.objects += ares-n64-cpu ares-n64-rdp ares-n64-rsp

$(object.path)/ares-n64-interface.o: $(ares.path)/n64/interface/interface.cpp
$(object.path)/ares-n64-system.o: $(ares.path)/n64/system/system.cpp
$(object.path)/ares-n64-cartridge.o: $(ares.path)/n64/cartridge/cartridge.cpp
$(object.path)/ares-n64-controller.o: $(ares.path)/n64/controller/controller.cpp
$(object.path)/ares-n64-cpu.o: $(ares.path)/n64/cpu/cpu.cpp
$(object.path)/ares-n64-rdp.o: $(ares.path)/n64/rdp/rdp.cpp
$(object.path)/ares-n64-rsp.o: $(ares.path)/n64/rsp/rsp.cpp
49 changes: 49 additions & 0 deletions ares/n64/cartridge/cartridge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <n64/n64.hpp>

namespace ares::Nintendo64 {

Cartridge& cartridge = cartridgeSlot.cartridge;
#include "slot.cpp"
#include "serialization.cpp"

auto Cartridge::allocate(Node::Port parent) -> Node::Peripheral {
return node = parent->append<Node::Peripheral>(interface->name());
}

auto Cartridge::connect() -> void {
node->setManifest([&] { return information.manifest; });

information = {};

if(auto fp = platform->open(node, "manifest.bml", File::Read, File::Required)) {
information.manifest = fp->reads();
}

auto document = BML::unserialize(information.manifest);
information.name = document["game/label"].string();

if(auto memory = document["game/board/memory(type=ROM,content=Program)"]) {
rom.allocate(memory["size"].natural());
if(auto fp = platform->open(node, "program.rom", File::Read, File::Required)) {
rom.load(fp);
}
}

power();
}

auto Cartridge::disconnect() -> void {
if(!node) return;
save();
node = {};
}

auto Cartridge::save() -> void {
if(!node) return;
auto document = BML::unserialize(information.manifest);
}

auto Cartridge::power() -> void {
}

}
27 changes: 27 additions & 0 deletions ares/n64/cartridge/cartridge.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
struct Cartridge {
Node::Peripheral node;
Memory::Readable<uint8> rom;

auto manifest() const -> string { return information.manifest; }
auto name() const -> string { return information.name; }

//cartridge.cpp
auto allocate(Node::Port) -> Node::Peripheral;
auto connect() -> void;
auto disconnect() -> void;

auto save() -> void;
auto power() -> void;

//serialization.cpp
auto serialize(serializer&) -> void;

private:
struct Information {
string manifest;
string name;
} information;
};

#include "slot.hpp"
extern Cartridge& cartridge;
2 changes: 2 additions & 0 deletions ares/n64/cartridge/serialization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
auto Cartridge::serialize(serializer& s) -> void {
}
18 changes: 18 additions & 0 deletions ares/n64/cartridge/slot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CartridgeSlot cartridgeSlot{"Cartridge Slot"};

CartridgeSlot::CartridgeSlot(string name) : name(name) {
}

auto CartridgeSlot::load(Node::Object parent) -> void {
port = parent->append<Node::Port>(name);
port->setFamily(interface->name());
port->setType("Cartridge");
port->setAllocate([&](auto name) { return cartridge.allocate(port); });
port->setConnect([&] { return cartridge.connect(); });
port->setDisconnect([&] { return cartridge.disconnect(); });
}

auto CartridgeSlot::unload() -> void {
cartridge.disconnect();
port = {};
}
13 changes: 13 additions & 0 deletions ares/n64/cartridge/slot.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct CartridgeSlot {
Node::Port port;
Cartridge cartridge;

//slot.cpp
CartridgeSlot(string name);
auto load(Node::Object) -> void;
auto unload() -> void;

const string name;
};

extern CartridgeSlot cartridgeSlot;
8 changes: 8 additions & 0 deletions ares/n64/controller/controller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <n64/n64.hpp>

namespace ares::Nintendo64 {

#include "port.cpp"
#include "gamepad/gamepad.cpp"

}
8 changes: 8 additions & 0 deletions ares/n64/controller/controller.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct Controller {
Node::Peripheral node;

virtual ~Controller() = default;
};

#include "port.hpp"
#include "gamepad/gamepad.hpp"
3 changes: 3 additions & 0 deletions ares/n64/controller/gamepad/gamepad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Gamepad::Gamepad(Node::Port parent) {
node = parent->append<Node::Peripheral>("Gamepad");
}
3 changes: 3 additions & 0 deletions ares/n64/controller/gamepad/gamepad.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct Gamepad : Controller {
Gamepad(Node::Port);
};
29 changes: 29 additions & 0 deletions ares/n64/controller/port.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ControllerPort controllerPort1{"Controller Port 1"};
ControllerPort controllerPort2{"Controller Port 2"};
ControllerPort controllerPort3{"Controller Port 3"};
ControllerPort controllerPort4{"Controller Port 4"};

ControllerPort::ControllerPort(string name) : name(name) {
}

auto ControllerPort::load(Node::Object parent) -> void {
port = parent->append<Node::Port>(name);
port->setFamily("Nintendo 64");
port->setType("Controller");
port->setHotSwappable(true);
port->setAllocate([&](auto name) { return allocate(name); });
}

auto ControllerPort::unload() -> void {
device = {};
port = {};
}

auto ControllerPort::allocate(string name) -> Node::Peripheral {
if(name == "Gamepad") device = new Gamepad(port);
if(device) return device->node;
return {};
}

auto ControllerPort::serialize(serializer& s) -> void {
}
19 changes: 19 additions & 0 deletions ares/n64/controller/port.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
struct ControllerPort {
Node::Port port;
unique_pointer<Controller> device;

//port.cpp
ControllerPort(string name);
auto load(Node::Object) -> void;
auto unload() -> void;
auto allocate(string name) -> Node::Peripheral;

auto serialize(serializer&) -> void;

const string name;
};

extern ControllerPort controllerPort1;
extern ControllerPort controllerPort2;
extern ControllerPort controllerPort3;
extern ControllerPort controllerPort4;
30 changes: 30 additions & 0 deletions ares/n64/cpu/cpu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <n64/n64.hpp>

namespace ares::Nintendo64 {

CPU cpu;
#include "serialization.cpp"

auto CPU::load(Node::Object parent) -> void {
node = parent->append<Node::Component>("CPU");
}

auto CPU::unload() -> void {
node = {};
}

auto CPU::main() -> void {
step(20);
}

auto CPU::step(uint clocks) -> void {
Thread::step(clocks);
Thread::synchronize();
}

auto CPU::power() -> void {
VR4300::power();
Thread::create(93'750'000, {&CPU::main, this});
}

}
19 changes: 19 additions & 0 deletions ares/n64/cpu/cpu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//NEC VR4300

struct CPU : VR4300, Thread {
Node::Component node;

//cpu.cpp
auto load(Node::Object) -> void;
auto unload() -> void;

auto main() -> void;
auto step(uint clocks) -> void;

auto power() -> void;

//serialization.cpp
auto serialize(serializer&) -> void;
};

extern CPU cpu;
4 changes: 4 additions & 0 deletions ares/n64/cpu/serialization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
auto CPU::serialize(serializer& s) -> void {
VR4300::serialize(s);
Thread::serialize(s);
}
48 changes: 48 additions & 0 deletions ares/n64/interface/interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <n64/n64.hpp>

namespace ares::Nintendo64 {

Interface* interface = nullptr;

auto Nintendo64Interface::game() -> string {
if(cartridge.node) {
return cartridge.name();
}

return "(no cartridge connected)";
}

auto Nintendo64Interface::root() -> Node::Object {
return system.node;
}

auto Nintendo64Interface::load(Node::Object& root) -> void {
interface = this;
system.load(root);
}

auto Nintendo64Interface::unload() -> void {
system.unload();
}

auto Nintendo64Interface::save() -> void {
system.save();
}

auto Nintendo64Interface::power() -> void {
system.power(false);
}

auto Nintendo64Interface::run() -> void {
system.run();
}

auto Nintendo64Interface::serialize(bool synchronize) -> serializer {
return system.serialize(synchronize);
}

auto Nintendo64Interface::unserialize(serializer& s) -> bool {
return system.unserialize(s);
}

}
Loading

0 comments on commit c43fc28

Please sign in to comment.