chore: tick on memory access instead of 1cpi
This commit is contained in:
parent
885f92beeb
commit
84273cbdad
16
src/Bus.zig
16
src/Bus.zig
|
@ -27,6 +27,8 @@ tim: Timers,
|
||||||
iwram: Iwram,
|
iwram: Iwram,
|
||||||
ewram: Ewram,
|
ewram: Ewram,
|
||||||
|
|
||||||
|
sched: *Scheduler,
|
||||||
|
|
||||||
io: Io,
|
io: Io,
|
||||||
|
|
||||||
pub fn init(alloc: Allocator, sched: *Scheduler, rom_path: []const u8, bios_path: ?[]const u8, save_path: ?[]const u8) !Self {
|
pub fn init(alloc: Allocator, sched: *Scheduler, rom_path: []const u8, bios_path: ?[]const u8, save_path: ?[]const u8) !Self {
|
||||||
|
@ -40,6 +42,7 @@ pub fn init(alloc: Allocator, sched: *Scheduler, rom_path: []const u8, bios_path
|
||||||
.dma = DmaControllers.init(),
|
.dma = DmaControllers.init(),
|
||||||
.tim = Timers.init(sched),
|
.tim = Timers.init(sched),
|
||||||
.io = Io.init(),
|
.io = Io.init(),
|
||||||
|
.sched = sched,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +55,8 @@ pub fn deinit(self: Self) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read32(self: *const Self, addr: u32) u32 {
|
pub fn read32(self: *const Self, addr: u32) u32 {
|
||||||
|
self.sched.tick += 1;
|
||||||
|
|
||||||
return switch (addr) {
|
return switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
0x0000_0000...0x0000_3FFF => self.bios.get32(addr),
|
0x0000_0000...0x0000_3FFF => self.bios.get32(addr),
|
||||||
|
@ -74,7 +79,7 @@ pub fn read32(self: *const Self, addr: u32) u32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write32(self: *Self, addr: u32, word: u32) void {
|
pub fn write32(self: *Self, addr: u32, word: u32) void {
|
||||||
// TODO: write32 can write to GamePak Flash
|
self.sched.tick += 1;
|
||||||
|
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
|
@ -92,6 +97,8 @@ pub fn write32(self: *Self, addr: u32, word: u32) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read16(self: *const Self, addr: u32) u16 {
|
pub fn read16(self: *const Self, addr: u32) u16 {
|
||||||
|
self.sched.tick += 1;
|
||||||
|
|
||||||
return switch (addr) {
|
return switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
0x0000_0000...0x0000_3FFF => self.bios.get16(addr),
|
0x0000_0000...0x0000_3FFF => self.bios.get16(addr),
|
||||||
|
@ -114,7 +121,8 @@ pub fn read16(self: *const Self, addr: u32) u16 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write16(self: *Self, addr: u32, halfword: u16) void {
|
pub fn write16(self: *Self, addr: u32, halfword: u16) void {
|
||||||
// TODO: write16 can write to GamePak Flash
|
self.sched.tick += 1;
|
||||||
|
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
0x0200_0000...0x02FF_FFFF => self.ewram.set16(addr & 0x3FFFF, halfword),
|
0x0200_0000...0x02FF_FFFF => self.ewram.set16(addr & 0x3FFFF, halfword),
|
||||||
|
@ -132,6 +140,8 @@ pub fn write16(self: *Self, addr: u32, halfword: u16) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read8(self: *const Self, addr: u32) u8 {
|
pub fn read8(self: *const Self, addr: u32) u8 {
|
||||||
|
self.sched.tick += 1;
|
||||||
|
|
||||||
return switch (addr) {
|
return switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
0x0000_0000...0x0000_3FFF => self.bios.get8(addr),
|
0x0000_0000...0x0000_3FFF => self.bios.get8(addr),
|
||||||
|
@ -155,6 +165,8 @@ pub fn read8(self: *const Self, addr: u32) u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write8(self: *Self, addr: u32, byte: u8) void {
|
pub fn write8(self: *Self, addr: u32, byte: u8) void {
|
||||||
|
self.sched.tick += 1;
|
||||||
|
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
// General Internal Memory
|
// General Internal Memory
|
||||||
0x0200_0000...0x02FF_FFFF => self.ewram.set8(addr & 0x3FFFF, byte),
|
0x0200_0000...0x02FF_FFFF => self.ewram.set8(addr & 0x3FFFF, byte),
|
||||||
|
|
|
@ -43,9 +43,9 @@ pub fn run(kind: RunKind, quit: *Atomic(bool), fps: *FpsAverage, sched: *Schedul
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi, bus: *Bus) void {
|
pub fn runFrame(sched: *Scheduler, cpu: *Arm7tdmi, bus: *Bus) void {
|
||||||
var cycles: u64 = 0;
|
const frame_end = sched.tick + cycles_per_frame;
|
||||||
while (cycles < cycles_per_frame) : (cycles += 1) {
|
|
||||||
sched.tick += 1;
|
while (sched.tick < frame_end) {
|
||||||
_ = cpu.step();
|
_ = cpu.step();
|
||||||
|
|
||||||
while (sched.tick >= sched.nextTimestamp()) {
|
while (sched.tick >= sched.nextTimestamp()) {
|
||||||
|
|
Loading…
Reference in New Issue