fix: implement proper SRAM mirroring and stub Flash

This commit is contained in:
2022-03-15 21:54:55 -03:00
parent 04d54ec97a
commit 40968f0990
4 changed files with 106 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
const std = @import("std");
const Sram = @import("Sram.zig");
const Backup = @import("backup.zig").Backup;
const Allocator = std.mem.Allocator;
const log = std.log.scoped(.GamePak);
const Self = @This();
@@ -8,7 +8,7 @@ const Self = @This();
title: [12]u8,
buf: []u8,
alloc: Allocator,
sram: Sram,
backup: Backup,
pub fn init(alloc: Allocator, path: []const u8) !Self {
const file = try std.fs.cwd().openFile(path, .{});
@@ -18,11 +18,13 @@ pub fn init(alloc: Allocator, path: []const u8) !Self {
const buf = try file.readToEndAlloc(alloc, len);
const title = parseTitle(buf);
const kind = Backup.guessKind(buf) orelse .Sram;
const pak = Self{
.buf = buf,
.alloc = alloc,
.title = title,
.sram = try Sram.init(alloc),
.backup = try Backup.init(alloc, kind),
};
pak.parseHeader();
@@ -55,7 +57,7 @@ fn lookupMaker(slice: *const [2]u8) ?[]const u8 {
pub fn deinit(self: Self) void {
self.alloc.free(self.buf);
self.sram.deinit();
self.backup.deinit();
}
pub fn get32(self: *const Self, idx: usize) u32 {