47 lines
1.1 KiB
Zig
47 lines
1.1 KiB
Zig
pub const WIDTH: usize = 64;
|
|
pub const HEIGHT: usize = 32;
|
|
pub const PIXELBUF_LEN = WIDTH * HEIGHT * @sizeOf(u32);
|
|
pub const SCALE = 10;
|
|
|
|
pub const Display = struct {
|
|
buf: [WIDTH * HEIGHT]u8,
|
|
|
|
pub fn new() Display {
|
|
return .{ .buf = [_]u8{0x00} ** (HEIGHT * WIDTH) };
|
|
}
|
|
};
|
|
|
|
pub const Point = struct {
|
|
x: u16,
|
|
y: u16,
|
|
};
|
|
|
|
pub fn drawSprite(disp: *Display, pos: *const Point, data: *const []u8) bool {
|
|
var set_vf: bool = false;
|
|
|
|
for (data.*) |byte, y_offset| {
|
|
var offset_count: u8 = 0;
|
|
|
|
while (offset_count < 8) : (offset_count += 1) {
|
|
const x_bit_offset = @intCast(u3, offset_count);
|
|
const x = @intCast(u8, pos.x + (7 - x_bit_offset));
|
|
const y = @intCast(u8, pos.y + y_offset);
|
|
|
|
const temp = (byte >> x_bit_offset) & 0x01;
|
|
const bit = @intCast(u1, temp);
|
|
|
|
const i = WIDTH * y + x;
|
|
|
|
if (i >= disp.buf.len) break;
|
|
|
|
if (bit == 0x1 and disp.buf[i] == 0x01) {
|
|
set_vf = true;
|
|
}
|
|
|
|
disp.buf[i] ^= bit;
|
|
}
|
|
}
|
|
|
|
return set_vf;
|
|
}
|