Skip to content

Commit

Permalink
show 565 directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Jun 11, 2024
1 parent 22ed7b8 commit 4a7cf51
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 3 additions & 8 deletions cxxrtl/src/SimThread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SimThread = @This();

pub const WIDTH = 320;
pub const HEIGHT = 240;
pub const Color = packed struct(u32) { r: u8, g: u8, b: u8, a: u8 };
pub const Color = packed struct(u16) { r: u5, g: u6, b: u5 };
pub const ImgData = [HEIGHT * WIDTH]Color;

sim_controller: *SimController,
Expand All @@ -24,7 +24,7 @@ reset: Cxxrtl.Object(bool),
spi_connector: SpiConnector,
uart_connector: UartConnector,

img_data: ImgData = [_]Color{.{ .r = 0, .g = 0, .b = 0, .a = 255 }} ** (HEIGHT * WIDTH),
img_data: ImgData = [_]Color{.{ .r = 0, .g = 0, .b = 0 }} ** (HEIGHT * WIDTH),
img_data_new: bool = true,

pub fn init(alloc: std.mem.Allocator, sim_controller: *SimController) SimThread {
Expand Down Expand Up @@ -151,12 +151,7 @@ pub fn run(self: *SimThread) !void {
const g: u6 = @truncate(((data0 & 0b111) << 3) | (data >> 5));
const b: u5 = @truncate(data & 0b00011111);

self.img_data[@as(usize, pag) * WIDTH + col] = .{
.r = @as(u8, r) << 3,
.g = @as(u8, g) << 2,
.b = @as(u8, b) << 3,
.a = 255,
};
self.img_data[@as(usize, pag) * WIDTH + col] = .{ .r = r, .g = g, .b = b };
self.img_data_new = true;

state = .MemoryWriteA;
Expand Down
4 changes: 2 additions & 2 deletions cxxrtl/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn main() !void {
});
defer renderer.destroy();

var itexture = try SDL.createTexture(renderer, .abgr8888, .streaming, SimThread.WIDTH, SimThread.HEIGHT);
var itexture = try SDL.createTexture(renderer, .bgr565, .streaming, SimThread.WIDTH, SimThread.HEIGHT);
defer itexture.destroy();

var ticks_last = SDL.getTicks64();
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn main() !void {
var pix = try itexture.lock(null);
defer pix.release();

std.debug.assert(pix.stride == SimThread.WIDTH * 4);
std.debug.assert(pix.stride == SimThread.WIDTH * 2);
@memcpy(@as(*SimThread.ImgData, @ptrCast(@alignCast(pix.pixels))), &img_data);
}

Expand Down

0 comments on commit 4a7cf51

Please sign in to comment.