Skip to content
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

Added Pencil II support. #1637

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions ares/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ ifneq ($(filter $(cores),cv),)
include $(ares.path)/cv/GNUmakefile
endif

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

ifneq ($(filter $(cores),myvision),)
include $(ares.path)/myvision/GNUmakefile
endif
Expand Down
17 changes: 17 additions & 0 deletions ares/pencil2/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ares.components += z80
ares.components += tms9918
ares.components += sn76489

ares.objects += ares-pencil2-cpu
ares.objects += ares-pencil2-vdp
ares.objects += ares-pencil2-psg
ares.objects += ares-pencil2-system
ares.objects += ares-pencil2-cartridge
ares.objects += ares-pencil2-controller

$(object.path)/ares-pencil2-cpu.o: $(ares.path)/pencil2/cpu/cpu.cpp
$(object.path)/ares-pencil2-vdp.o: $(ares.path)/pencil2/vdp/vdp.cpp
$(object.path)/ares-pencil2-psg.o: $(ares.path)/pencil2/psg/psg.cpp
$(object.path)/ares-pencil2-system.o: $(ares.path)/pencil2/system/system.cpp
$(object.path)/ares-pencil2-cartridge.o: $(ares.path)/pencil2/cartridge/cartridge.cpp
$(object.path)/ares-pencil2-controller.o: $(ares.path)/pencil2/controller/controller.cpp
31 changes: 31 additions & 0 deletions ares/pencil2/cartridge/board/board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Board {

#include "pencil2.cpp"

auto Interface::load(Memory::Readable<n8>& memory, string name) -> bool {
if(auto fp = pak->read(name)) {
memory.allocate(fp->size());
memory.load(fp);
return true;
}
return false;
}

auto Interface::load(Memory::Writable<n8>& memory, string name) -> bool {
if(auto fp = pak->read(name)) {
memory.allocate(fp->size());
memory.load(fp);
return true;
}
return false;
}

auto Interface::save(Memory::Writable<n8>& memory, string name) -> bool {
if(auto fp = pak->write(name)) {
memory.save(fp);
return true;
}
return false;
}

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

struct Interface {
VFS::Pak pak;

Interface(Cartridge& cartridge) : cartridge(cartridge) {}
virtual ~Interface() = default;
virtual auto load() -> void {}
virtual auto save() -> void {}
virtual auto unload() -> void {}
virtual auto read(n16 address) -> n8 { return 0; }
virtual auto write(n16 address, n8 data) -> void {}
virtual auto power() -> void {}
virtual auto serialize(serializer&) -> void {}

auto load(Memory::Readable<n8>&, string name) -> bool;
auto load(Memory::Writable<n8>&, string name) -> bool;
auto save(Memory::Writable<n8>&, string name) -> bool;

Cartridge& cartridge;
};

}
25 changes: 25 additions & 0 deletions ares/pencil2/cartridge/board/pencil2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
struct pencil2 : Interface {
using Interface::Interface;
Memory::Readable<n8> rom;

auto load() -> void override {
Interface::load(rom, "program.rom");
}

auto save() -> void override {}

auto unload() -> void override {}

auto read(n16 address) -> n8 override {
return rom.read(address);
}

auto write(n16 address, n8 data) -> void override {
return;
}

auto power() -> void override {}

auto serialize(serializer& s) -> void override {}

};
57 changes: 57 additions & 0 deletions ares/pencil2/cartridge/cartridge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <pencil2/pencil2.hpp>

namespace ares::Pencil2 {

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

auto Cartridge::allocate(Node::Port parent) -> Node::Peripheral {
return node = parent->append<Node::Peripheral>(string{system.name(), " Cartridge"});
}

auto Cartridge::connect() -> void {
if(!node->setPak(pak = platform->pak(node))) return;

information = {};
information.title = pak->attribute("title");
information.region = pak->attribute("region");
information.board = pak->attribute("board");

if(information.board == "pencil2") board = new Board::pencil2{*this};


if(!board) board = new Board::Interface{*this};
board->pak = pak;
board->load();
power();
}

auto Cartridge::disconnect() -> void {
if(!node || !board) return;
board->unload();
board->pak.reset();
board.reset();
node.reset();
}

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

auto Cartridge::power() -> void {
if(board) board->power();
}

auto Cartridge::read(n16 address) -> n8 {
if(board) return board->read(address);
return 0;
}

auto Cartridge::write(n16 address, n8 data) -> void {
if(board) return board->write(address, data);
}

}
36 changes: 36 additions & 0 deletions ares/pencil2/cartridge/cartridge.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
struct Cartridge;
#include "board/board.hpp"

struct Cartridge {
Node::Peripheral node;
VFS::Pak pak;

auto title() const -> string { return information.title; }
auto region() const -> string { return information.region; }

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

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

auto read(n16 address) -> n8;
auto write(n16 address, n8 data) -> void;

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

unique_pointer<Board::Interface> board;

//private:
struct Information {
string title;
string region;
string board;
} information;
};

#include "slot.hpp"
extern Cartridge& cartridge;
2 changes: 2 additions & 0 deletions ares/pencil2/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/pencil2/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(system.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/pencil2/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/pencil2/controller/controller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <pencil2/pencil2.hpp>

namespace ares::Pencil2 {

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

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

virtual ~Controller() = default;

virtual auto read() -> n8 { return 0xff; }
virtual auto write(n8 data) -> void {}
};

#include "port.hpp"
#include "gamepad/gamepad.hpp"
83 changes: 83 additions & 0 deletions ares/pencil2/controller/gamepad/gamepad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Gamepad::Gamepad(Node::Port parent) {
node = parent->append<Node::Peripheral>("Gamepad");

up = node->append<Node::Input::Button>("Up");
down = node->append<Node::Input::Button>("Down");
left = node->append<Node::Input::Button>("Left");
right = node->append<Node::Input::Button>("Right");
l = node->append<Node::Input::Button>("L");
r = node->append<Node::Input::Button>("R");
one = node->append<Node::Input::Button>("1");
two = node->append<Node::Input::Button>("2");
three = node->append<Node::Input::Button>("3");
four = node->append<Node::Input::Button>("4");
five = node->append<Node::Input::Button>("5");
six = node->append<Node::Input::Button>("6");
seven = node->append<Node::Input::Button>("7");
eight = node->append<Node::Input::Button>("8");
nine = node->append<Node::Input::Button>("9");
star = node->append<Node::Input::Button>("*");
zero = node->append<Node::Input::Button>("0");
pound = node->append<Node::Input::Button>("#");
}

auto Gamepad::read() -> n8 {
platform->input(up);
platform->input(down);
platform->input(left);
platform->input(right);
platform->input(l);
platform->input(r);
platform->input(one);
platform->input(two);
platform->input(three);
platform->input(four);
platform->input(five);
platform->input(six);
platform->input(seven);
platform->input(eight);
platform->input(nine);
platform->input(star);
platform->input(zero);
platform->input(pound);

if(!(up->value() & down->value())) {
yHold = 0, upLatch = up->value(), downLatch = down->value();
} else if(!yHold) {
yHold = 1, swap(upLatch, downLatch);
}

if(!(left->value() & right->value())) {
xHold = 0, leftLatch = left->value(), rightLatch = right->value();
} else if(!xHold) {
xHold = 1, swap(leftLatch, rightLatch);
}

n8 data = 0x7f;
if(select == 0) {
if(one->value ()) data.bit(0,3) = 0b1101;
else if(two->value ()) data.bit(0,3) = 0b0111;
else if(three->value()) data.bit(0,3) = 0b1100;
else if(four->value ()) data.bit(0,3) = 0b0010;
else if(five->value ()) data.bit(0,3) = 0b0011;
else if(six->value ()) data.bit(0,3) = 0b1110;
else if(seven->value()) data.bit(0,3) = 0b0101;
else if(eight->value()) data.bit(0,3) = 0b0001;
else if(nine->value ()) data.bit(0,3) = 0b1011;
else if(star->value ()) data.bit(0,3) = 0b1001;
else if(zero->value ()) data.bit(0,3) = 0b1010;
else if(pound->value()) data.bit(0,3) = 0b0110;
data.bit(6) = !r->value();
} else {
data.bit(0) = !upLatch;
data.bit(1) = !rightLatch;
data.bit(2) = !downLatch;
data.bit(3) = !leftLatch;
data.bit(6) = !l->value();
}
return data;
}

auto Gamepad::write(n8 data) -> void {
select = data.bit(0);
}
35 changes: 35 additions & 0 deletions ares/pencil2/controller/gamepad/gamepad.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
struct Gamepad : Controller {
Node::Input::Button up;
Node::Input::Button down;
Node::Input::Button left;
Node::Input::Button right;
Node::Input::Button l;
Node::Input::Button r;
Node::Input::Button one;
Node::Input::Button two;
Node::Input::Button three;
Node::Input::Button four;
Node::Input::Button five;
Node::Input::Button six;
Node::Input::Button seven;
Node::Input::Button eight;
Node::Input::Button nine;
Node::Input::Button star;
Node::Input::Button zero;
Node::Input::Button pound;

Gamepad(Node::Port);

auto read() -> n8 override;
auto write(n8 data) -> void override;

n1 select;

private:
b1 yHold;
b1 upLatch;
b1 downLatch;
b1 xHold;
b1 leftLatch;
b1 rightLatch;
};
Loading