diff --git a/examples/graphics.cpp b/examples/graphics.cpp index 222ae12..6b9223c 100644 --- a/examples/graphics.cpp +++ b/examples/graphics.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "chargen.hpp" @@ -285,6 +286,7 @@ struct SimpleSprite } }; + struct Screen { void load(std::uint8_t x, std::uint8_t y, auto &s) { @@ -405,10 +407,36 @@ int main() { std::uint8_t stamina{max_stamina()}; std::uint16_t cash{100}; - constexpr std::uint8_t max_stamina() const { + Clock game_clock{}; + + constexpr std::uint8_t max_stamina() const noexcept { return endurance * 5; } + struct JoyStickStateChanged + { + std::uint8_t state; + }; + + struct TimeElapsed + { + Clock::milliseconds us; + }; + + using Event = std::variant; + + std::uint8_t last_joystick_state = peek(0xDC00); + + Event next_event() noexcept { + const auto new_joystick_state = peek(0xDC00); + + if (new_joystick_state != last_joystick_state) { + last_joystick_state = new_joystick_state; + return JoyStickStateChanged{new_joystick_state}; + } + + return TimeElapsed{game_clock.restart()}; + } }; GameState game; @@ -428,22 +456,33 @@ int main() { put_hex(12,23, cur_game.cash); }; - Clock game_clock{}; Screen screen; show_stats(game); std::uint8_t x = 0; + struct HandleEvents { + + void operator()(const GameState::JoyStickStateChanged &e) { + put_hex(36, 1, e.state); + } + + void operator()(const GameState::TimeElapsed &e) { + put_hex(36, 0, e.us.count()); + } + + }; + + HandleEvents eventHandler; + while (true) { - const auto us_elapsed = game_clock.restart().count(); -// show_stats(game); - put_hex(36, 0, us_elapsed); + std::visit(eventHandler, game.next_event()); screen.show(x++, 10, character); - if (x == 36) { - x = 0; + if (x == 11) { + x = 10; } increment_border_color(); } diff --git a/include/6502.hpp b/include/6502.hpp index a0ee577..f3e7d41 100644 --- a/include/6502.hpp +++ b/include/6502.hpp @@ -264,7 +264,7 @@ struct mos6502 : ASMLine return text;// + ':'; case ASMLine::Type::Directive: case ASMLine::Type::Instruction: { - return fmt::format("\t{} {:15}; {}", text, op.value, comment); + return fmt::format("\t{} {:15}\t; {}", text, op.value, comment); } } throw std::runtime_error("Unable to render: " + text); diff --git a/src/6502-c++.cpp b/src/6502-c++.cpp index 74a4ba6..47547ef 100644 --- a/src/6502-c++.cpp +++ b/src/6502-c++.cpp @@ -47,6 +47,16 @@ std::string_view strip_negate(std::string_view s) return s; } +std::string_view strip_gs(std::string_view s) +{ + const auto matcher = ctre::match; + + if (const auto results = matcher(s); results) { + return results.get<1>(); + } + + return s; +} std::string_view strip_offset(std::string_view s) { @@ -64,8 +74,8 @@ std::string fixup_8bit_literal(const std::string &s) if (s.starts_with("0x")) { return "#$" + s.substr(2); } - if (s.starts_with("lo8(")) { return fmt::format("#<{}", strip_lo_hi(s)); } - if (s.starts_with("hi8(")) { return fmt::format("#>{}", strip_lo_hi(s)); } + if (s.starts_with("lo8(")) { return fmt::format("#<{}", strip_gs(strip_lo_hi(s))); } + if (s.starts_with("hi8(")) { return fmt::format("#>{}", strip_gs(strip_lo_hi(s))); } const auto is_num = std::all_of(begin(s), end(s), [](const auto c) { return (c >= '0' && c <= '9') || c == '-'; }); @@ -955,8 +965,8 @@ std::vector run(const Personality &personality, std::istream &input, co check_label(i.operand1.value); check_label(i.operand2.value); - check_label(std::string{ strip_offset(strip_negate(strip_lo_hi(i.operand1.value))) }); - check_label(std::string{ strip_offset(strip_negate(strip_lo_hi(i.operand2.value))) }); + check_label(std::string{ strip_gs(strip_offset(strip_negate(strip_lo_hi(i.operand1.value)))) }); + check_label(std::string{ strip_gs(strip_offset(strip_negate(strip_lo_hi(i.operand2.value)))) }); } else if (i.type == ASMLine::Type::Directive) { const auto matcher = ctre::match; @@ -976,12 +986,18 @@ std::vector run(const Personality &personality, std::istream &input, co // newl.erase(std::remove_if(newl.begin(), newl.end(), [](const auto c) { return !std::isalnum(c); }), // std::end(newl)); - // strip just first \. - if (l[0] == '.') { - result.emplace(std::make_pair(l, l.substr(1))); - } else { - result.emplace(std::make_pair(l, l)); - } + const auto new_label = [](auto label) -> std::string { + if (label[0] == '.') { + label.erase(0,1); + } + + for (auto &c : label) { if (c == '.') { c = '_'; } + } + + return label; + }; + + result.emplace(std::make_pair(l, new_label(l))); } return result; }();