feat: minor performance improvements
This commit is contained in:
parent
3d61c0dba4
commit
1901a471e4
|
@ -107,8 +107,15 @@ fn DmaController(comptime id: u2) type {
|
||||||
self.writeCntHigh(@truncate(u16, word >> 16));
|
self.writeCntHigh(@truncate(u16, word >> 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn step(self: *Self, bus: *Bus) bool {
|
pub inline fn check(self: *Self, bus: *Bus) bool {
|
||||||
if (!self.enabled or !self.cnt.enabled.read()) return false;
|
if (!self.enabled) return false; // FIXME: Check CNT register?
|
||||||
|
|
||||||
|
self.step(bus);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn step(self: *Self, bus: *Bus) void {
|
||||||
|
@setCold(true);
|
||||||
|
|
||||||
const sad_adj = std.meta.intToEnum(Adjustment, self.cnt.sad_adj.read()) catch unreachable;
|
const sad_adj = std.meta.intToEnum(Adjustment, self.cnt.sad_adj.read()) catch unreachable;
|
||||||
const dad_adj = std.meta.intToEnum(Adjustment, self.cnt.dad_adj.read()) catch unreachable;
|
const dad_adj = std.meta.intToEnum(Adjustment, self.cnt.dad_adj.read()) catch unreachable;
|
||||||
|
@ -160,8 +167,6 @@ fn DmaController(comptime id: u2) type {
|
||||||
// timing window
|
// timing window
|
||||||
self.enabled = false;
|
self.enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isBlocking(self: *const Self) bool {
|
pub fn isBlocking(self: *const Self) bool {
|
||||||
|
|
18
src/cpu.zig
18
src/cpu.zig
|
@ -296,24 +296,22 @@ pub const Arm7tdmi = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleDMATransfers(self: *Self) bool {
|
fn handleDMATransfers(self: *Self) bool {
|
||||||
if (self.bus.dma._0.step(self.bus)) return self.bus.dma._0.isBlocking();
|
if (self.bus.dma._0.check(self.bus)) return self.bus.dma._0.isBlocking();
|
||||||
if (self.bus.dma._1.step(self.bus)) return self.bus.dma._1.isBlocking();
|
if (self.bus.dma._1.check(self.bus)) return self.bus.dma._1.isBlocking();
|
||||||
if (self.bus.dma._2.step(self.bus)) return self.bus.dma._2.isBlocking();
|
if (self.bus.dma._2.check(self.bus)) return self.bus.dma._2.isBlocking();
|
||||||
if (self.bus.dma._3.step(self.bus)) return self.bus.dma._3.isBlocking();
|
if (self.bus.dma._3.check(self.bus)) return self.bus.dma._3.isBlocking();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn thumbFetch(self: *Self) u16 {
|
fn thumbFetch(self: *Self) u16 {
|
||||||
const halfword = self.bus.read16(self.r[15]);
|
defer self.r[15] += 2;
|
||||||
self.r[15] += 2;
|
return self.bus.read16(self.r[15]);
|
||||||
return halfword;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch(self: *Self) u32 {
|
fn fetch(self: *Self) u32 {
|
||||||
const word = self.bus.read32(self.r[15]);
|
defer self.r[15] += 4;
|
||||||
self.r[15] += 4;
|
return self.bus.read32(self.r[15]);
|
||||||
return word;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fakePC(self: *const Self) u32 {
|
pub fn fakePC(self: *const Self) u32 {
|
||||||
|
|
47
src/ppu.zig
47
src/ppu.zig
|
@ -92,35 +92,34 @@ pub const Ppu = struct {
|
||||||
// Attributes in OAM are 6 bytes long, with 2 bytes of padding
|
// Attributes in OAM are 6 bytes long, with 2 bytes of padding
|
||||||
// Grab Attributes from OAM
|
// Grab Attributes from OAM
|
||||||
const attr0 = @bitCast(Attr0, self.oam.get16(i));
|
const attr0 = @bitCast(Attr0, self.oam.get16(i));
|
||||||
const attr1 = @bitCast(Attr1, self.oam.get16(i + 2));
|
|
||||||
const attr2 = @bitCast(Attr2, self.oam.get16(i + 4));
|
|
||||||
const sprite = Sprite.init(attr0, attr1, attr2);
|
|
||||||
|
|
||||||
// Only consider enabled sprites
|
// Only consider enabled Sprites
|
||||||
if (sprite.isDisabled()) continue;
|
if (!attr0.disabled.read()) {
|
||||||
|
const attr1 = @bitCast(Attr1, self.oam.get16(i + 2));
|
||||||
|
|
||||||
// When fetching sprites we only care about ones that could be rendered
|
// When fetching sprites we only care about ones that could be rendered
|
||||||
// on this scanline
|
// on this scanline
|
||||||
const iy = @bitCast(i8, y);
|
const iy = @bitCast(i8, y);
|
||||||
|
|
||||||
const start = sprite.y();
|
const start = attr0.y.read();
|
||||||
const istart = @bitCast(i8, start);
|
const istart = @bitCast(i8, start);
|
||||||
|
|
||||||
const end = start +% sprite.height;
|
const end = start +% spriteDimensions(attr0.shape.read(), attr1.size.read())[1];
|
||||||
const iend = @bitCast(i8, end);
|
const iend = @bitCast(i8, end);
|
||||||
|
|
||||||
// Sprites are expected to be able to wraparound, we perform the same check
|
// Sprites are expected to be able to wraparound, we perform the same check
|
||||||
// for unsigned and signed values so that we handle all valid sprite positions
|
// for unsigned and signed values so that we handle all valid sprite positions
|
||||||
if ((start <= y and y < end) or (istart <= iy and iy < iend)) {
|
if ((start <= y and y < end) or (istart <= iy and iy < iend)) {
|
||||||
for (self.scanline_sprites) |*maybe_sprite| {
|
for (self.scanline_sprites) |*maybe_sprite| {
|
||||||
if (maybe_sprite.* == null) {
|
if (maybe_sprite.* == null) {
|
||||||
maybe_sprite.* = sprite;
|
maybe_sprite.* = Sprite.init(attr0, attr1, @bitCast(Attr2, self.oam.get16(i + 4)));
|
||||||
continue :search;
|
continue :search;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
log.err("Found more than 128 sprites in OAM Search", .{});
|
log.err("Found more than 128 sprites in OAM Search", .{});
|
||||||
unreachable; // TODO: Is this truly unreachable?
|
unreachable; // TODO: Is this truly unreachable?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,10 +630,6 @@ const Sprite = struct {
|
||||||
inline fn priority(self: *const Self) u2 {
|
inline fn priority(self: *const Self) u2 {
|
||||||
return self.attr2.rel_prio.read();
|
return self.attr2.rel_prio.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fn isDisabled(self: *const Self) bool {
|
|
||||||
return self.attr0.disabled.read();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Attr0 = extern union {
|
const Attr0 = extern union {
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub const FpsAverage = struct {
|
||||||
sample_count: u64,
|
sample_count: u64,
|
||||||
|
|
||||||
pub fn init() Self {
|
pub fn init() Self {
|
||||||
return .{ .total = 0, .sample_count = 0 };
|
return .{ .total = 0, .sample_count = 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(self: *Self, sample: u64) void {
|
pub fn add(self: *Self, sample: u64) void {
|
||||||
|
|
Loading…
Reference in New Issue