feat(bus): emu is now able to read from user-provided BIOS
This commit is contained in:
30
src/bus/bios.zig
Normal file
30
src/bus/bios.zig
Normal file
@@ -0,0 +1,30 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
pub const Bios = struct {
|
||||
buf: []u8,
|
||||
|
||||
pub fn fromPath(alloc: Allocator, path: []const u8) !@This() {
|
||||
const file = try std.fs.cwd().openFile(path, .{ .read = true });
|
||||
defer file.close();
|
||||
|
||||
const len = try file.getEndPos();
|
||||
|
||||
return @This(){
|
||||
.buf = try file.readToEndAlloc(alloc, len),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn get32(self: *const @This(), idx: usize) u32 {
|
||||
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
|
||||
}
|
||||
|
||||
pub inline fn get16(self: *const @This(), idx: usize) u16 {
|
||||
return (@as(u16, self.buf[idx + 1]) << 8) | @as(u16, self.buf[idx]);
|
||||
}
|
||||
|
||||
pub inline fn get8(self: *const @This(), idx: usize) u8 {
|
||||
return self.buf[idx];
|
||||
}
|
||||
};
|
30
src/bus/pak.zig
Normal file
30
src/bus/pak.zig
Normal file
@@ -0,0 +1,30 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
pub const GamePak = struct {
|
||||
buf: []u8,
|
||||
|
||||
pub fn fromPath(alloc: Allocator, path: []const u8) !@This() {
|
||||
const file = try std.fs.cwd().openFile(path, .{ .read = true });
|
||||
defer file.close();
|
||||
|
||||
const len = try file.getEndPos();
|
||||
|
||||
return @This(){
|
||||
.buf = try file.readToEndAlloc(alloc, len),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn get32(self: *const @This(), idx: usize) u32 {
|
||||
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
|
||||
}
|
||||
|
||||
pub inline fn get16(self: *const @This(), idx: usize) u16 {
|
||||
return (@as(u16, self.buf[idx + 1]) << 8) | @as(u16, self.buf[idx]);
|
||||
}
|
||||
|
||||
pub inline fn get8(self: *const @This(), idx: usize) u8 {
|
||||
return self.buf[idx];
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user