Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DVD: Fix framebuffer writes; remove extra write #68

Merged
merged 1 commit into from
May 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions showcase/carts/dvd/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const gfx = @import("gfx");

export fn start() void {
// Clear garbage bytes from framebuffer at init since the whole screen is not cleared otherwise.
for (cart.framebuffer[0..]) |*pos| {
pos.* = .{ .r = 0, .b = 0, .g = 0 };
for (cart.framebuffer) |*col| {
for (col) |*pos| {
pos.* = cart.Pixel.fromColor(.{ .r = 0, .b = 0, .g = 0 });
}
}
}

Expand Down Expand Up @@ -66,11 +68,11 @@ pub fn drawDvd(sprite: anytype, pos_x: usize, pos_y: usize, color: Rgb) void {
const dst_y = pos_y + y;
const index = y * sprite.width + x;
const src = sprite.colors[sprite.indices.get(index)];
var dst = &cart.framebuffer[dst_y * cart.screen_width + dst_x];
dst.r = @intFromFloat(@as(f32, @floatFromInt(src.r)) * color.r);
dst.g = @intFromFloat(@as(f32, @floatFromInt(src.g)) * color.g);
dst.b = @intFromFloat(@as(f32, @floatFromInt(src.b)) * color.b);
cart.framebuffer[dst_y * cart.screen_width + dst_x] = dst.*;
cart.framebuffer[dst_x][dst_y] = cart.Pixel.fromColor(.{
.r = @intFromFloat(@as(f32, @floatFromInt(src.r)) * color.r),
.g = @intFromFloat(@as(f32, @floatFromInt(src.g)) * color.g),
.b = @intFromFloat(@as(f32, @floatFromInt(src.b)) * color.b),
});
}
}
}
Expand Down
Loading