Skip to content
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
5 changes: 2 additions & 3 deletions ares/ares/ares.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
#include <vector>
#include <ranges>
#include <algorithm>
#include <array>
#include <unordered_map>

#include <nall/platform.hpp>
#include <nall/adaptive-array.hpp>
#include <nall/any.hpp>
#include <nall/array.hpp>
#include <nall/bump-allocator.hpp>
#include <nall/case-range.hpp>
#include <nall/chrono.hpp>
#include <nall/directory.hpp>
#include <nall/dl.hpp>
#include <nall/endian.hpp>
#include <nall/hashset.hpp>
#include <nall/image.hpp>
#include <nall/instruction-set.hpp>
#include <nall/literals.hpp>
#include <nall/priority-queue.hpp>
#include <nall/queue.hpp>
#include <nall/random.hpp>
#include <nall/serializer.hpp>
#include <nall/set.hpp>
#include <nall/span-helpers.hpp>
#include <nall/string.hpp>
#include <nall/terminal.hpp>
Expand Down
22 changes: 9 additions & 13 deletions ares/ares/node/debugger/tracer/instruction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Instruction : Tracer {

auto setMask(bool mask) -> void {
_mask = mask;
_masks.reset();
_masks.clear();
}

auto setDepth(u32 depth) -> void {
Expand All @@ -34,9 +34,9 @@ struct Instruction : Tracer {
address >>= _addressMask; //clip unneeded alignment bits (to reduce _masks size)

if(_mask) {
auto mask = _masks.find(address);
if(!mask) mask = _masks.insert(address);
if(mask->visit(address)) return false; //do not trace twice
auto key = address >> 6;
auto [it, inserted] = _masks.try_emplace(key);
if(it->second.visit(address)) return false;
}

if(_depth) {
Expand All @@ -62,8 +62,9 @@ struct Instruction : Tracer {
address &= ~0ull >> (64 - _addressBits);
address >>= _addressMask;

auto mask = _masks.find(address);
if(mask) mask->unvisit(address);
auto key = address >> 6;
auto it = _masks.find(key);
if(it != _masks.end()) it->second.unvisit(address);
}
}

Expand Down Expand Up @@ -107,10 +108,6 @@ struct Instruction : Tracer {

protected:
struct VisitMask {
VisitMask(u64 address) : upper(address >> 6), mask(0) {}
auto operator==(const VisitMask& source) const -> bool { return upper == source.upper; }
auto hash() const -> u32 { return upper; }

auto visit(u64 address) -> bool {
const u64 bit = 1ull << (address & 0x3f);
if(mask & bit) return true;
Expand All @@ -124,8 +121,7 @@ struct Instruction : Tracer {
}

private:
u64 upper;
u64 mask;
u64 mask = 0;
};

u32 _addressBits = 32;
Expand All @@ -137,5 +133,5 @@ struct Instruction : Tracer {
n64 _address = 0;
n64 _omitted = 0;
std::vector<u64> _history;
hashset<VisitMask> _masks;
std::unordered_map<u64, VisitMask> _masks;
};
23 changes: 11 additions & 12 deletions ares/ares/node/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,26 @@ struct Object : std::enable_shared_from_this<Object> {

template<typename T = string>
auto attribute(const string& name) const -> T {
if(auto attribute = _attributes.find(name)) {
if(attribute->value.is<T>()) return attribute->value.get<T>();
}
auto it = _attributes.find({name});
if(it != _attributes.end()) if(it->value.is<T>()) return it->value.get<T>();
return {};
}

template<typename T = string>
auto hasAttribute(const string& name) const -> bool {
if(auto attribute = _attributes.find(name)) {
if(attribute->value.is<T>()) return true;
}
auto it = _attributes.find({name});
if(it != _attributes.end()) if(it->value.is<T>()) return true;
return false;
}

template<typename T = string, typename U = string>
auto setAttribute(const string& name, const U& value = {}) -> void {
if constexpr(is_same_v<T, string> && !is_same_v<U, string>) return setAttribute(name, string{value});
if(auto attribute = _attributes.find(name)) {
if((const T&)value) attribute->value = (const T&)value;
else _attributes.remove(*attribute);
} else {
auto it = _attributes.find({name});
if(it != _attributes.end()) {
if((const T&)value) const_cast<any&>(it->value) = (const T&)value;
else _attributes.erase(it);
} else {
if((const T&)value) _attributes.insert({name, (const T&)value});
}
}
Expand Down Expand Up @@ -207,7 +206,7 @@ struct Object : std::enable_shared_from_this<Object> {
virtual auto unserialize(Markup::Node markup) -> void {
if(!markup) return;
_name = markup["name"].string();
_attributes.reset();
_attributes.clear();
for(auto& attribute : markup.find("attribute")) {
_attributes.insert({attribute["name"].string(), attribute["value"].string()});
}
Expand Down Expand Up @@ -236,7 +235,7 @@ struct Object : std::enable_shared_from_this<Object> {
protected:
string _name;
VFS::Pak _pak;
set<Attribute> _attributes;
std::set<Attribute> _attributes;
std::weak_ptr<Object> _parent;
std::vector<Node::Object> _nodes;
};
4 changes: 2 additions & 2 deletions ares/component/audio/ay38910/ay38910.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace ares {

#include "serialization.cpp"

auto AY38910::clock() -> array<n4[3]> {
auto AY38910::clock() -> std::array<n4, 3> {
toneA.clock();
toneB.clock();
toneC.clock();
noise.clock();
envelope.clock();

array<n4[3]> output;
std::array<n4, 3> output{};
if((toneA.output | channelA.tone) & (noise.output | channelA.noise)) {
output[0] = channelA.envelope ? envelope.output : channelA.volume;
}
Expand Down
2 changes: 1 addition & 1 deletion ares/component/audio/ay38910/ay38910.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct AY38910 {
virtual auto writeIO(n1 port, n8 data) -> void {}

//ay38910.cpp
auto clock() -> array<n4[3]>;
auto clock() -> std::array<n4, 3>;
auto read() -> n8;
auto write(n8 data) -> void;
auto select(n4 data) -> void;
Expand Down
6 changes: 3 additions & 3 deletions ares/component/audio/sn76489/sn76489.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace ares {

#include "serialization.cpp"

auto SN76489::clock() -> array<n4[4]> {
auto SN76489::clock() -> std::array<n4, 4> {
tone0.clock();
tone1.clock();
tone2.clock();
noise.clock();

array<n4[4]> output{15, 15, 15, 15};
std::array<n4, 4> output{15, 15, 15, 15};
if(tone0.output) output[0] = tone0.volume;
if(tone1.output) output[1] = tone1.volume;
if(tone2.output) output[2] = tone2.volume;
Expand All @@ -28,7 +28,7 @@ auto SN76489::Tone::clock() -> void {

auto SN76489::Noise::clock() -> void {
if(!counter || !--counter) {
counter = array<n10[4]>{0x10, 0x20, 0x40, pitch}[rate];
counter = std::array<n10, 4>{0x10, 0x20, 0x40, pitch}[rate];
if(flip ^= 1) { //0->1 transition
output = lfsr.bit(0);
lfsr = (lfsr.bit(0) ^ lfsr.bit(3) & enable) << 15 | lfsr >> 1;
Expand Down
2 changes: 1 addition & 1 deletion ares/component/audio/sn76489/sn76489.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ares {

struct SN76489 {
//sn76489.cpp
auto clock() -> array<n4[4]>;
auto clock() -> std::array<n4, 4>;
auto write(n8 data) -> void;
auto power() -> void;

Expand Down
6 changes: 3 additions & 3 deletions ares/component/audio/t6w28/t6w28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace ares {

#include "serialization.cpp"

auto T6W28::clock() -> array<n4[8]> {
auto T6W28::clock() -> std::array<n4, 8> {
tone0.clock();
tone1.clock();
tone2.clock();
noise.clock();

array<n4[8]> output{15, 15, 15, 15, 15, 15, 15, 15};
std::array<n4, 8> output{15, 15, 15, 15, 15, 15, 15, 15};
if(tone0.output) output[0] = tone0.volume.left, output[4] = tone0.volume.right;
if(tone1.output) output[1] = tone1.volume.left, output[5] = tone1.volume.right;
if(tone2.output) output[2] = tone2.volume.left, output[6] = tone2.volume.right;
Expand All @@ -28,7 +28,7 @@ auto T6W28::Tone::clock() -> void {

auto T6W28::Noise::clock() -> void {
if(!counter--) {
counter = array<n10[4]>{0x10, 0x20, 0x40, pitch}[rate];
counter = std::array<n10, 4>{0x10, 0x20, 0x40, pitch}[rate];
if(flip ^= 1) { //0->1 transition
output = !lfsr.bit(0);
lfsr = (lfsr.bit(0) ^ lfsr.bit(2) & enable) << 14 | lfsr >> 1;
Expand Down
2 changes: 1 addition & 1 deletion ares/component/audio/t6w28/t6w28.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct T6W28 {
virtual auto writePitch(u32) -> void = 0;

//t6w28.cpp
auto clock() -> array<n4[8]>;
auto clock() -> std::array<n4, 8>;
auto writeLeft(n8 data) -> void;
auto writeRight(n8 data) -> void;
auto power() -> void;
Expand Down
4 changes: 2 additions & 2 deletions ares/component/audio/ym2149/ym2149.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace ares {

#include "serialization.cpp"

auto YM2149::clock() -> array<n5[3]> {
auto YM2149::clock() -> std::array<n5, 3> {
toneA.clock();
toneB.clock();
toneC.clock();
noise.clock();
envelope.clock();

array<n5[3]> output;
std::array<n5, 3> output{};
if((toneA.output | channelA.tone) & (noise.output | channelA.noise)) {
output[0] = channelA.envelope ? envelope.output : n5(channelA.volume << 1 | 1);
}
Expand Down
2 changes: 1 addition & 1 deletion ares/component/audio/ym2149/ym2149.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ares {

struct YM2149 {
//ym2149.cpp
auto clock() -> array<n5[3]>;
auto clock() -> std::array<n5, 3>;
auto read() -> n8;
auto write(n8 data) -> void;
auto select(n4 data) -> void;
Expand Down
2 changes: 1 addition & 1 deletion ares/component/audio/ym2612/ym2612.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ares {
#include "constants.cpp"
#include "serialization.cpp"

auto YM2612::clock() -> array<i16[2]> {
auto YM2612::clock() -> std::array<i16, 2> {
s32 left = 0;
s32 right = 0;

Expand Down
2 changes: 1 addition & 1 deletion ares/component/audio/ym2612/ym2612.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ares {

struct YM2612 {
//ym2612.cpp
auto clock() -> array<i16[2]>;
auto clock() -> std::array<i16, 2>;
auto power() -> void;

//io.cpp
Expand Down
12 changes: 5 additions & 7 deletions ares/component/processor/sh2/recompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,20 @@ auto SH2::Recompiler::block(u32 address) -> Block* {
auto size = measure(address);
auto hashcode = hash(address, size);

BlockHashPair pair;
pair.hashcode = hashcode;
if(auto result = blocks.find(pair)) {
auto it = blocks.find(hashcode);
if(it != blocks.end()) {
memory::jitprotect(false);
pool(address)->blocks[address >> 1 & 0x7f] = result->block;
pool(address)->blocks[address >> 1 & 0x7f] = it->second;
memory::jitprotect(true);
return result->block;
return it->second;
}

auto block = emit(address);
assert(block->size == size);
pool(address)->blocks[address >> 1 & 0x7f] = block;
memory::jitprotect(true);

pair.block = block;
blocks.insert(pair);
blocks.emplace(hashcode, block);

return block;
}
Expand Down
12 changes: 3 additions & 9 deletions ares/component/processor/sh2/sh2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,11 @@ struct SH2 {
Block* blocks[1 << 7];
};

struct BlockHashPair {
auto operator==(const BlockHashPair& source) const -> bool { return hashcode == source.hashcode; }
auto hash() const -> u32 { return hashcode; }

Block* block;
u64 hashcode;
};


auto reset() -> void {
generation = 0;
blocks.reset();
blocks.clear();
pools.resize(1 << 24);
std::ranges::fill(pools, nullptr);
}
Expand Down Expand Up @@ -310,7 +304,7 @@ struct SH2 {
bool inDelaySlot;
u32 generation;
bump_allocator allocator;
hashset<BlockHashPair> blocks;
std::unordered_map<u64, Block*> blocks;
u16 instructions[1 << 7];
std::vector<Pool*> pools;
} recompiler{*this};
Expand Down
8 changes: 4 additions & 4 deletions ares/component/processor/tlcs900h/disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ NALL_NOINLINE auto TLCS900H::disassembleInstruction() -> string {
natural _immediate;
natural _displacement;

static auto lookup(natural size, n3 register) -> n8 {
if(size == 8) return from_array<0xe1,0xe0,0xe5,0xe4,0xe9,0xe8,0xed,0xec>(register);
if(size == 16) return from_array<0xe0,0xe4,0xe8,0xec,0xf0,0xf4,0xf8,0xfc>(register);
if(size == 32) return from_array<0xe0,0xe4,0xe8,0xec,0xf0,0xf4,0xf8,0xfc>(register);
static auto lookup(natural size, n3 reg) -> n8 {
if(size == 8) { static const u8 t[8] = {0xe1,0xe0,0xe5,0xe4,0xe9,0xe8,0xed,0xec}; return (n8)t[(u32)reg]; }
if(size == 16) { static const u8 t[8] = {0xe0,0xe4,0xe8,0xec,0xf0,0xf4,0xf8,0xfc}; return (n8)t[(u32)reg]; }
if(size == 32) { static const u8 t[8] = {0xe0,0xe4,0xe8,0xec,0xf0,0xf4,0xf8,0xfc}; return (n8)t[(u32)reg]; }
return 0;
}
} lhs, rhs;
Expand Down
4 changes: 2 additions & 2 deletions ares/n64/controller/gamepad/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ auto Gamepad::formatControllerPak() -> void {
n6 fieldA = random();
n19 fieldB = random();
n27 fieldC = random();
for(u32 area : array<u8[4]>{1,3,4,6}) {
for(u32 area : std::array<u8,4>{1,3,4,6}) {
ram.write<Byte>(area * 0x20 + 0x01, fieldA); //unknown
ram.write<Word>(area * 0x20 + 0x04, fieldB); //serial# hi
ram.write<Word>(area * 0x20 + 0x08, fieldC); //serial# lo
Expand All @@ -480,7 +480,7 @@ auto Gamepad::formatControllerPak() -> void {
u32 inodeTableCopyPage = 1 + nBanks;
for(u32 bank : range(0,nBanks)) {
u32 firstDataPage = bank == 0 ? (3 + nBanks * 2) : 1; //first bank has 3 + bank * 2 system pages, other banks have 127.
for(u32 page : array<u32[2]>{inodeTablePage + bank, inodeTableCopyPage + bank}) {
for(u32 page : std::array<u32,2>{inodeTablePage + bank, inodeTableCopyPage + bank}) {
for(u32 slot : range(firstDataPage,128)) {
ram.write<Byte>(0x100 * page + slot * 2 + 0x01, 0x03); //0x01 = stop, 0x03 = empty
}
Expand Down
1 change: 0 additions & 1 deletion ares/n64/n64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <float.h>
#include <ares/ares.hpp>
#include <nall/float-env.hpp>
#include <nall/hashset.hpp>
#include <nall/queue.hpp>
#include <nall/recompiler/generic/generic.hpp>
#include <component/processor/sm5k/sm5k.hpp>
Expand Down
Loading
Loading