diff --git a/src/screen.cpp b/src/io_device.cpp similarity index 79% rename from src/screen.cpp rename to src/io_device.cpp index aea1634..34df0dd 100644 --- a/src/screen.cpp +++ b/src/io_device.cpp @@ -1,4 +1,4 @@ -#include "screen.hpp" +#include "io_device.hpp" #include #include #include @@ -7,6 +7,7 @@ #include #include #include +#include using namespace vc5; @@ -62,11 +63,12 @@ constexpr auto charset = std::array { } -auto Screen::create(int ch_size, int ch_width, int ch_height) - -> std::expected, std::string> +auto IoDevice::create(int ch_size, int ch_width, int ch_height) + -> std::expected, std::string> { auto profile = ScreenProfile(ch_size, ch_width, ch_height); - auto [_0, _1, _2, px_width, px_height] = profile; + auto px_width= profile.px_width; + auto px_height = profile.px_height; if (!sdl_is_initialized) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { @@ -94,10 +96,10 @@ auto Screen::create(int ch_size, int ch_width, int ch_height) SDL_RenderPresent(renderer); - return std::make_unique(profile, window, renderer, texture); + return std::make_unique(profile, window, renderer, texture); } -Screen::~Screen() +IoDevice::~IoDevice() { auto lock = std::lock_guard(mx); @@ -110,7 +112,7 @@ Screen::~Screen() } } -auto Screen::set_char(uint16_t offset, uint8_t value) +auto IoDevice::set_char(uint16_t offset, uint8_t value) -> std::expected { auto lock = std::lock_guard(mx); @@ -118,7 +120,7 @@ auto Screen::set_char(uint16_t offset, uint8_t value) auto it = std::find_if(charset.begin(), charset.end(), [&](Char ch) { return ch.ch == value; }); - Char my_char = *it; + uint64_t char_data = it->to_u64(); SDL_Color* buffer; int pitch; @@ -128,19 +130,20 @@ auto Screen::set_char(uint16_t offset, uint8_t value) } auto [ch_size, ch_width, ch_height, px_width, px_height] = m_profile; + std::println("ch_size = {}, ch_width = {}, ch_height = {}, px_width = {}, px_height = {}", ch_size, ch_width, ch_height, px_width, px_height); - for (int ch_y = 0; ch_y < ch_height; ++ch_y) { - for (int ch_x = 0; ch_x < ch_width; ++ch_x) { + for (int ch_y = 0; ch_y < 8; ++ch_y) { + for (int ch_x = 0; ch_x < 8; ++ch_x) { bool ch - = my_char.to_u64() >> (ch_y * ch_width + (ch_width - ch_x - 1)) + = char_data >> (ch_y * 8 + (8 - ch_x - 1)) & 1; for (int px_y = 0; px_y < ch_size; ++px_y) { for (int px_x = 0; px_x < ch_size; ++px_x) { - int x = (offset % ch_width * ch_size + ch_x) * px_width + int x = (offset % 4 * ch_size + ch_x) * 4 + px_x; - int y = (offset / ch_height * ch_size + ch_y) * px_height + int y = (offset / 4 * ch_size + ch_y) * 4 + px_y; buffer[y * px_width + x] = ch diff --git a/src/screen.hpp b/src/io_device.hpp similarity index 81% rename from src/screen.hpp rename to src/io_device.hpp index a7bdf40..84bebe9 100644 --- a/src/screen.hpp +++ b/src/io_device.hpp @@ -17,8 +17,8 @@ struct ScreenProfile { : ch_size(ch_size) , ch_width(ch_width) , ch_height(ch_height) - , px_width(ch_size * ch_width) - , px_height(ch_size * ch_height) + , px_width(ch_size * 8 * ch_width) + , px_height(ch_size * 8 * ch_height) { } @@ -29,12 +29,12 @@ struct ScreenProfile { int px_height; }; -class Screen { +class IoDevice { public: static auto create(int ch_size, int ch_width, int ch_height) - -> std::expected, std::string>; + -> std::expected, std::string>; - explicit Screen(ScreenProfile profile, + explicit IoDevice(ScreenProfile profile, SDL_Window* window, SDL_Renderer* renderer, SDL_Texture* texture) @@ -44,7 +44,7 @@ public: , m_texture(texture) { } - ~Screen(); + ~IoDevice(); auto set_char(uint16_t offset, uint8_t value) -> std::expected; diff --git a/src/main.cpp b/src/main.cpp index db6b339..c08eef4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,26 @@ #include "builder.hpp" -#include "screen.hpp" +#include "io_device.hpp" #include #include #include #include #include +#include +#include +#include + + +using namespace std::chrono_literals; using namespace vc5; using R = Reg; int main() { - auto screen = Screen::create(4, 8 * 40, 8 * 24); - screen.value()->set_char(0, 'A'); + auto device = IoDevice::create(4, 40, 24).value(); + device->set_char(0, 'A').value(); + + std::this_thread::sleep_for(1s); constexpr R r0 = R::R0; constexpr R r1 = R::R1; @@ -69,3 +77,9 @@ int main() std::println("{: 4x}\t{}", i, vm.word(i)); } } + +extern "C" const char* __asan_default_options(void) +{ + return "detect_leaks=0"; +} +