io device
This commit is contained in:
parent
bc79410a77
commit
9fab1ca0cf
@ -1,4 +1,4 @@
|
|||||||
#include "screen.hpp"
|
#include "io_device.hpp"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_error.h>
|
#include <SDL2/SDL_error.h>
|
||||||
#include <SDL2/SDL_render.h>
|
#include <SDL2/SDL_render.h>
|
||||||
@ -7,6 +7,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <print>
|
||||||
|
|
||||||
using namespace vc5;
|
using namespace vc5;
|
||||||
|
|
||||||
@ -62,11 +63,12 @@ constexpr auto charset = std::array {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Screen::create(int ch_size, int ch_width, int ch_height)
|
auto IoDevice::create(int ch_size, int ch_width, int ch_height)
|
||||||
-> std::expected<std::unique_ptr<Screen>, std::string>
|
-> std::expected<std::unique_ptr<IoDevice>, std::string>
|
||||||
{
|
{
|
||||||
auto profile = ScreenProfile(ch_size, ch_width, ch_height);
|
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_is_initialized) {
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
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);
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
return std::make_unique<Screen>(profile, window, renderer, texture);
|
return std::make_unique<IoDevice>(profile, window, renderer, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
Screen::~Screen()
|
IoDevice::~IoDevice()
|
||||||
{
|
{
|
||||||
auto lock = std::lock_guard(mx);
|
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<void, std::string>
|
-> std::expected<void, std::string>
|
||||||
{
|
{
|
||||||
auto lock = std::lock_guard(mx);
|
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) {
|
auto it = std::find_if(charset.begin(), charset.end(), [&](Char ch) {
|
||||||
return ch.ch == value;
|
return ch.ch == value;
|
||||||
});
|
});
|
||||||
Char my_char = *it;
|
uint64_t char_data = it->to_u64();
|
||||||
|
|
||||||
SDL_Color* buffer;
|
SDL_Color* buffer;
|
||||||
int pitch;
|
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;
|
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_y = 0; ch_y < 8; ++ch_y) {
|
||||||
for (int ch_x = 0; ch_x < ch_width; ++ch_x) {
|
for (int ch_x = 0; ch_x < 8; ++ch_x) {
|
||||||
bool ch
|
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;
|
& 1;
|
||||||
|
|
||||||
for (int px_y = 0; px_y < ch_size; ++px_y) {
|
for (int px_y = 0; px_y < ch_size; ++px_y) {
|
||||||
for (int px_x = 0; px_x < ch_size; ++px_x) {
|
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;
|
+ px_x;
|
||||||
int y = (offset / ch_height * ch_size + ch_y) * px_height
|
int y = (offset / 4 * ch_size + ch_y) * 4
|
||||||
+ px_y;
|
+ px_y;
|
||||||
|
|
||||||
buffer[y * px_width + x] = ch
|
buffer[y * px_width + x] = ch
|
||||||
@ -17,8 +17,8 @@ struct ScreenProfile {
|
|||||||
: ch_size(ch_size)
|
: ch_size(ch_size)
|
||||||
, ch_width(ch_width)
|
, ch_width(ch_width)
|
||||||
, ch_height(ch_height)
|
, ch_height(ch_height)
|
||||||
, px_width(ch_size * ch_width)
|
, px_width(ch_size * 8 * ch_width)
|
||||||
, px_height(ch_size * ch_height)
|
, px_height(ch_size * 8 * ch_height)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,12 +29,12 @@ struct ScreenProfile {
|
|||||||
int px_height;
|
int px_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Screen {
|
class IoDevice {
|
||||||
public:
|
public:
|
||||||
static auto create(int ch_size, int ch_width, int ch_height)
|
static auto create(int ch_size, int ch_width, int ch_height)
|
||||||
-> std::expected<std::unique_ptr<Screen>, std::string>;
|
-> std::expected<std::unique_ptr<IoDevice>, std::string>;
|
||||||
|
|
||||||
explicit Screen(ScreenProfile profile,
|
explicit IoDevice(ScreenProfile profile,
|
||||||
SDL_Window* window,
|
SDL_Window* window,
|
||||||
SDL_Renderer* renderer,
|
SDL_Renderer* renderer,
|
||||||
SDL_Texture* texture)
|
SDL_Texture* texture)
|
||||||
@ -44,7 +44,7 @@ public:
|
|||||||
, m_texture(texture)
|
, m_texture(texture)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~Screen();
|
~IoDevice();
|
||||||
|
|
||||||
auto set_char(uint16_t offset, uint8_t value)
|
auto set_char(uint16_t offset, uint8_t value)
|
||||||
-> std::expected<void, std::string>;
|
-> std::expected<void, std::string>;
|
||||||
20
src/main.cpp
20
src/main.cpp
@ -1,18 +1,26 @@
|
|||||||
#include "builder.hpp"
|
#include "builder.hpp"
|
||||||
#include "screen.hpp"
|
#include "io_device.hpp"
|
||||||
#include <SDL2/SDL_main.h>
|
#include <SDL2/SDL_main.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <print>
|
#include <print>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
using namespace vc5;
|
using namespace vc5;
|
||||||
using R = Reg;
|
using R = Reg;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
auto screen = Screen::create(4, 8 * 40, 8 * 24);
|
auto device = IoDevice::create(4, 40, 24).value();
|
||||||
screen.value()->set_char(0, 'A');
|
device->set_char(0, 'A').value();
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(1s);
|
||||||
|
|
||||||
constexpr R r0 = R::R0;
|
constexpr R r0 = R::R0;
|
||||||
constexpr R r1 = R::R1;
|
constexpr R r1 = R::R1;
|
||||||
@ -69,3 +77,9 @@ int main()
|
|||||||
std::println("{: 4x}\t{}", i, vm.word(i));
|
std::println("{: 4x}\t{}", i, vm.word(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" const char* __asan_default_options(void)
|
||||||
|
{
|
||||||
|
return "detect_leaks=0";
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user