Compare commits

..

No commits in common. "50adb5fbac6588dcfe9cf7f3b12e2b62d4b0b76d" and "12c138364d31a5cbebc1eb710dc8d2edc51a0588" have entirely different histories.

4 changed files with 8 additions and 30 deletions

View File

@ -6,8 +6,6 @@ const Bit = @import("bitfield").Bit;
const Bitfield = @import("bitfield").Bitfield; const Bitfield = @import("bitfield").Bitfield;
const Backup = @import("backup.zig").Backup; const Backup = @import("backup.zig").Backup;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const force_rtc = @import("../emu.zig").force_rtc;
const log = std.log.scoped(.GamePak); const log = std.log.scoped(.GamePak);
const Self = @This(); const Self = @This();
@ -24,9 +22,7 @@ pub fn init(allocator: Allocator, cpu: *Arm7tdmi, rom_path: []const u8, save_pat
const file_buf = try file.readToEndAlloc(allocator, try file.getEndPos()); const file_buf = try file.readToEndAlloc(allocator, try file.getEndPos());
const title = file_buf[0xA0..0xAC].*; const title = file_buf[0xA0..0xAC].*;
const kind = Backup.guessKind(file_buf); const kind = Backup.guessKind(file_buf) orelse .None;
const device = if (force_rtc) .Rtc else guessDevice(file_buf);
logHeader(file_buf, &title); logHeader(file_buf, &title);
return .{ return .{
@ -34,26 +30,10 @@ pub fn init(allocator: Allocator, cpu: *Arm7tdmi, rom_path: []const u8, save_pat
.allocator = allocator, .allocator = allocator,
.title = title, .title = title,
.backup = try Backup.init(allocator, kind, title, save_path), .backup = try Backup.init(allocator, kind, title, save_path),
.gpio = try Gpio.init(allocator, cpu, device), .gpio = try Gpio.init(allocator, cpu, .Rtc),
}; };
} }
/// Searches the ROM to see if it can determine whether the ROM it's searching uses
/// any GPIO device, like a RTC for example.
fn guessDevice(buf: []const u8) Gpio.Device.Kind {
// Try to Guess if ROM uses RTC
const needle = "RTC_V"; // I was told SIIRTC_V, though Pokemen Firered (USA) is a false negative
var i: usize = 0;
while ((i + needle.len) < buf.len) : (i += 1) {
if (std.mem.eql(u8, needle, buf[i..(i + needle.len)])) return .Rtc;
}
// TODO: Detect other GPIO devices
return .None;
}
fn logHeader(buf: []const u8, title: *const [12]u8) void { fn logHeader(buf: []const u8, title: *const [12]u8) void {
const code = buf[0xAC..0xB0]; const code = buf[0xAC..0xB0];
const maker = buf[0xB0..0xB2]; const maker = buf[0xB0..0xB2];
@ -278,9 +258,8 @@ const Gpio = struct {
}; };
fn init(allocator: Allocator, cpu: *Arm7tdmi, kind: Device.Kind) !*This { fn init(allocator: Allocator, cpu: *Arm7tdmi, kind: Device.Kind) !*This {
log.info("Device: {}", .{kind});
const self = try allocator.create(This); const self = try allocator.create(This);
self.* = .{ self.* = .{
.data = 0b0000, .data = 0b0000,
.direction = 0b1111, // TODO: What is GPIO DIrection set to by default? .direction = 0b1111, // TODO: What is GPIO DIrection set to by default?
@ -526,8 +505,8 @@ pub const Clock = struct {
cpu.sched.push(.RealTimeClock, 1 << 24); // Every Second cpu.sched.push(.RealTimeClock, 1 << 24); // Every Second
} }
pub fn updateTime(self: *This, late: u64) void { pub fn updateTime(self: *This) void {
self.cpu.sched.push(.RealTimeClock, (1 << 24) -| late); // Reschedule self.cpu.sched.push(.RealTimeClock, 1 << 24); // Reschedule
const now = DateTime.now(); const now = DateTime.now();
self.year = toBcd(u8, @intCast(u8, now.date.year - 2000)); self.year = toBcd(u8, @intCast(u8, now.date.year - 2000));

View File

@ -61,7 +61,7 @@ pub const Backup = struct {
return backup; return backup;
} }
pub fn guessKind(rom: []const u8) Kind { pub fn guessKind(rom: []const u8) ?Kind {
for (backup_kinds) |needle| { for (backup_kinds) |needle| {
const needle_len = needle.str.len; const needle_len = needle.str.len;
@ -71,7 +71,7 @@ pub const Backup = struct {
} }
} }
return .None; return null;
} }
pub fn deinit(self: *Self) void { pub fn deinit(self: *Self) void {

View File

@ -18,7 +18,6 @@ const sync_video: RunKind = .LimitedFPS; // Configure Video Sync
pub const win_scale = 3; // 1x, 2x, 3x, etc. Window Scaling pub const win_scale = 3; // 1x, 2x, 3x, etc. Window Scaling
pub const cpu_logging = false; // Enable detailed CPU logging pub const cpu_logging = false; // Enable detailed CPU logging
pub const allow_unhandled_io = true; // Only relevant in Debug Builds pub const allow_unhandled_io = true; // Only relevant in Debug Builds
pub const force_rtc = false;
// 228 Lines which consist of 308 dots (which are 4 cycles long) // 228 Lines which consist of 308 dots (which are 4 cycles long)
const cycles_per_frame: u64 = 228 * (308 * 4); //280896 const cycles_per_frame: u64 = 228 * (308 * 4); //280896

View File

@ -66,7 +66,7 @@ pub const Scheduler = struct {
if (device.kind != .Rtc or device.ptr == null) return; if (device.kind != .Rtc or device.ptr == null) return;
const clock = @ptrCast(*Clock, @alignCast(@alignOf(*Clock), device.ptr.?)); const clock = @ptrCast(*Clock, @alignCast(@alignOf(*Clock), device.ptr.?));
clock.updateTime(late); clock.updateTime();
}, },
.FrameSequencer => cpu.bus.apu.tickFrameSequencer(late), .FrameSequencer => cpu.bus.apu.tickFrameSequencer(late),
.SampleAudio => cpu.bus.apu.sampleAudio(late), .SampleAudio => cpu.bus.apu.sampleAudio(late),