Compare commits

..

No commits in common. "0d203543cad85c06f6911758ead0580580a84657" and "568c3741316aed11d90ffe13a192d7181d6d87e2" have entirely different histories.

5 changed files with 6 additions and 63 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "lib/SDL.zig"]
path = lib/SDL.zig
url = https://github.com/MasterQ32/SDL.zig

View File

@ -1,5 +1,4 @@
const std = @import("std"); const std = @import("std");
const Sdk = @import("lib/SDL.zig/Sdk.zig");
pub fn build(b: *std.build.Builder) void { pub fn build(b: *std.build.Builder) void {
// Standard target options allows the person running `zig build` to choose // Standard target options allows the person running `zig build` to choose
@ -15,13 +14,7 @@ pub fn build(b: *std.build.Builder) void {
const exe = b.addExecutable("zba", "src/main.zig"); const exe = b.addExecutable("zba", "src/main.zig");
// Bitfield type from FlorenceOS: https://github.com/FlorenceOS/ // Bitfield type from FlorenceOS: https://github.com/FlorenceOS/
exe.addPackage(.{ .name = "bitfield", .path = .{ .path = "lib/util/bitfield.zig" } }); exe.addPackage(.{ .name = "bitfield", .path = .{ .path = "./lib/util/bitfield.zig" } });
// Zig SDL Bindings: https://github.com/MasterQ32/SDL.zig
const sdk = Sdk.init(b);
sdk.link(exe, .dynamic);
exe.addPackage(sdk.getNativePackage("sdl2"));
exe.setTarget(target); exe.setTarget(target);
exe.setBuildMode(mode); exe.setBuildMode(mode);

@ -1 +0,0 @@
Subproject commit d3a764869b31575d3d73cc874b1ff27879407b5a

View File

@ -1,18 +1,15 @@
const std = @import("std"); const std = @import("std");
const SDL = @import("sdl2");
const emu = @import("emu.zig"); const emu = @import("emu.zig");
const Bus = @import("Bus.zig"); const Bus = @import("Bus.zig");
const Arm7tdmi = @import("cpu.zig").Arm7tdmi; const Arm7tdmi = @import("cpu.zig").Arm7tdmi;
const Scheduler = @import("scheduler.zig").Scheduler; const Scheduler = @import("scheduler.zig").Scheduler;
pub fn main() anyerror!void { pub fn main() anyerror!void {
// Allocator for Emulator + CLI Aruments
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator(); const alloc = gpa.allocator();
defer std.debug.assert(!gpa.deinit()); defer std.debug.assert(!gpa.deinit());
// Handle CLI Arguments
const args = try std.process.argsAlloc(alloc); const args = try std.process.argsAlloc(alloc);
defer std.process.argsFree(alloc, args); defer std.process.argsFree(alloc, args);
@ -26,7 +23,6 @@ pub fn main() anyerror!void {
return; return;
} }
// Initialize Emulator
var scheduler = Scheduler.init(alloc); var scheduler = Scheduler.init(alloc);
defer scheduler.deinit(); defer scheduler.deinit();
@ -34,55 +30,14 @@ pub fn main() anyerror!void {
defer bus.deinit(); defer bus.deinit();
var cpu = Arm7tdmi.init(&scheduler, &bus); var cpu = Arm7tdmi.init(&scheduler, &bus);
cpu.skipBios(); cpu.skipBios();
// Initialize SDL while (true) {
const status = SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_EVENTS | SDL.SDL_INIT_AUDIO);
if (status < 0) sdlPanic();
defer SDL.SDL_Quit();
var window = SDL.SDL_CreateWindow(
"Gameboy Advance Emulator",
SDL.SDL_WINDOWPOS_CENTERED,
SDL.SDL_WINDOWPOS_CENTERED,
240 * 3,
160 * 3,
SDL.SDL_WINDOW_SHOWN,
) orelse sdlPanic();
defer SDL.SDL_DestroyWindow(window);
var renderer = SDL.SDL_CreateRenderer(window, -1, SDL.SDL_RENDERER_ACCELERATED) orelse sdlPanic();
defer SDL.SDL_DestroyRenderer(renderer);
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); emu.runFrame(&scheduler, &cpu, &bus);
var event: SDL.SDL_Event = undefined;
_ = SDL.SDL_PollEvent(&event);
switch (event.type) {
SDL.SDL_QUIT => break :emu_loop,
else => {},
}
_ = SDL.SDL_UpdateTexture(texture, null, &white_heap, buf_pitch);
_ = SDL.SDL_RenderCopy(renderer, texture, null, null);
SDL.SDL_RenderPresent(renderer);
} }
} }
fn sdlPanic() noreturn { test "basic test" {
const str = @as(?[*:0]const u8, SDL.SDL_GetError()) orelse "unknown error"; try std.testing.expectEqual(10, 3 + 7);
@panic(std.mem.sliceTo(str, 0));
} }

View File

@ -23,7 +23,6 @@ pub const Ppu = struct {
pub fn deinit(self: @This()) void { pub fn deinit(self: @This()) void {
self.vram.deinit(); self.vram.deinit();
self.palette.deinit();
} }
}; };