fix: allocate framebuf on heap

This commit is contained in:
2022-01-08 20:30:57 -04:00
parent 0d203543ca
commit 581285a434
2 changed files with 18 additions and 9 deletions

View File

@@ -6,6 +6,8 @@ const Bus = @import("Bus.zig");
const Arm7tdmi = @import("cpu.zig").Arm7tdmi;
const Scheduler = @import("scheduler.zig").Scheduler;
const buf_pitch = @import("ppu.zig").buf_pitch;
pub fn main() anyerror!void {
// Allocator for Emulator + CLI Aruments
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
@@ -57,14 +59,6 @@ pub fn main() anyerror!void {
const texture = SDL.SDL_CreateTexture(renderer, SDL.SDL_PIXELFORMAT_BGR555, SDL.SDL_TEXTUREACCESS_STREAMING, 240, 160) orelse sdlPanic();
defer SDL.SDL_DestroyTexture(texture);
const buf_pitch = 240 * @sizeOf(u16);
const buf_len = buf_pitch * 160;
var white: [buf_len]u8 = [_]u8{ 0xFF, 0x7F } ** (buf_len / 2);
var white_heap = try alloc.alloc(u8, buf_len);
for (white) |b, i| white_heap[i] = b;
defer alloc.free(white_heap);
emu_loop: while (true) {
emu.runFrame(&scheduler, &cpu, &bus);
@@ -76,7 +70,8 @@ pub fn main() anyerror!void {
else => {},
}
_ = SDL.SDL_UpdateTexture(texture, null, &white_heap, buf_pitch);
const buf_ptr = bus.ppu.frame_buf.ptr;
_ = SDL.SDL_UpdateTexture(texture, null, buf_ptr, buf_pitch);
_ = SDL.SDL_RenderCopy(renderer, texture, null, null);
SDL.SDL_RenderPresent(renderer);
}