chore: update to latest zig master

This commit is contained in:
Rekai Nyangadzayi Musuka 2023-02-22 14:46:46 -06:00
parent e380af7056
commit 024151a5c1
11 changed files with 32 additions and 44 deletions

@ -1 +1 @@
Subproject commit 272d8e2088b2cae037349fb260dc05ec46bba422
Subproject commit 861de651f3e1314973b1273ac7856e96b2625ff3

@ -1 +1 @@
Subproject commit 932d2845210644ca736faf35f5bea31eb1a15465
Subproject commit bf0ae0c27cfe92fdd9a92c8f1ac6d1939ae60c77

View File

@ -105,7 +105,7 @@ pub fn deinit(self: *Self) void {
fn fillReadTable(self: *Self, table: *[table_len]?*const anyopaque) void {
const vramMirror = @import("ppu/Vram.zig").mirror;
for (table) |*ptr, i| {
for (table, 0..) |*ptr, i| {
const addr = @intCast(u32, page_size * i);
ptr.* = switch (addr) {
@ -132,7 +132,7 @@ fn fillWriteTable(self: *Self, comptime T: type, table: *[table_len]?*const anyo
comptime std.debug.assert(T == u32 or T == u16 or T == u8);
const vramMirror = @import("ppu/Vram.zig").mirror;
for (table) |*ptr, i| {
for (table, 0..) |*ptr, i| {
const addr = @intCast(u32, page_size * i);
ptr.* = switch (addr) {

View File

@ -213,6 +213,7 @@ 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
// TODO: Use new for loop syntax?
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;

View File

@ -137,6 +137,7 @@ pub const Backup = struct {
for (backup_kinds) |needle| {
const needle_len = needle.str.len;
// TODO: Use new for loop syntax?
var i: usize = 0;
while ((i + needle_len) < rom.len) : (i += 1) {
if (std.mem.eql(u8, needle.str, rom[i..][0..needle_len])) return needle.kind;

View File

@ -339,10 +339,7 @@ fn DmaController(comptime id: u2) type {
}
pub fn onBlanking(bus: *Bus, comptime kind: DmaKind) void {
comptime var i: usize = 0;
inline while (i < 4) : (i += 1) {
bus.dma[i].poll(kind);
}
inline for (0..4) |i| bus.dma[i].poll(kind);
}
const Adjustment = enum(u2) {

View File

@ -39,13 +39,12 @@ pub const arm = struct {
}
fn populate() [0x1000]InstrFn {
return comptime {
comptime {
@setEvalBranchQuota(0xE000);
var ret = [_]InstrFn{und} ** 0x1000;
var table = [_]InstrFn{und} ** 0x1000;
var i: usize = 0;
while (i < ret.len) : (i += 1) {
ret[i] = switch (@as(u2, i >> 10)) {
for (&table, 0..) |*handler, i| {
handler.* = switch (@as(u2, i >> 10)) {
0b00 => if (i == 0x121) blk: {
break :blk branchExchange;
} else if (i & 0xFCF == 0x009) blk: {
@ -107,8 +106,8 @@ pub const arm = struct {
};
}
return ret;
};
return table;
}
}
};
@ -136,13 +135,12 @@ pub const thumb = struct {
}
fn populate() [0x400]InstrFn {
return comptime {
comptime {
@setEvalBranchQuota(5025); // This is exact
var ret = [_]InstrFn{und} ** 0x400;
var table = [_]InstrFn{und} ** 0x400;
var i: usize = 0;
while (i < ret.len) : (i += 1) {
ret[i] = switch (@as(u3, i >> 7 & 0x7)) {
for (&table, 0..) |*handler, i| {
handler.* = switch (@as(u3, i >> 7 & 0x7)) {
0b000 => if (i >> 5 & 0x3 == 0b11) blk: {
const I = i >> 4 & 1 == 1;
const is_sub = i >> 3 & 1 == 1;
@ -230,8 +228,8 @@ pub const thumb = struct {
};
}
return ret;
};
return table;
}
}
};
@ -385,8 +383,7 @@ pub const Arm7tdmi = struct {
const now = getModeChecked(self, self.cpsr.mode.read());
// Bank R8 -> r12
var i: usize = 0;
while (i < 5) : (i += 1) {
for (0..5) |i| {
self.bank.fiq[Bank.fiqIdx(i, now)] = self.r[8 + i];
}
@ -404,8 +401,7 @@ pub const Arm7tdmi = struct {
}
// Grab R8 -> R12
i = 0;
while (i < 5) : (i += 1) {
for (0..5) |i| {
self.r[8 + i] = self.bank.fiq[Bank.fiqIdx(i, next)];
}
@ -470,8 +466,7 @@ pub const Arm7tdmi = struct {
}
pub fn stepDmaTransfer(self: *Self) bool {
comptime var i: usize = 0;
inline while (i < 4) : (i += 1) {
inline for (0..4) |i| {
if (self.bus.dma[i].in_progress) {
self.bus.dma[i].step(self);
return true;

View File

@ -92,8 +92,7 @@ pub fn fmt15(comptime L: bool, comptime rb: u3) InstrFn {
inline fn countRlist(opcode: u16) u32 {
var count: u32 = 0;
comptime var i: u4 = 0;
inline while (i < 8) : (i += 1) {
inline for (0..8) |i| {
if (opcode >> (7 - i) & 1 == 1) count += 1;
}

View File

@ -146,9 +146,8 @@ fn sleep(timer: *Timer, wake_time: u64) ?u64 {
const step = 2 * std.time.ns_per_ms; // Granularity of 2ms
const times = sleep_for / step;
var i: usize = 0;
while (i < times) : (i += 1) {
for (0..times) |_| {
std.time.sleep(step);
// Upon wakeup, check to see if this particular sleep was longer than expected

View File

@ -625,8 +625,7 @@ pub const Ppu = struct {
const framebuf_base = width * @as(usize, scanline);
if (obj_enable) self.fetchSprites();
var layer: usize = 0;
while (layer < 4) : (layer += 1) {
for (0..4) |layer| {
self.drawSprites(@truncate(u2, layer));
if (layer == self.bg[0].cnt.priority.read() and bg_enable & 1 == 1) self.drawBackground(0);
if (layer == self.bg[1].cnt.priority.read() and bg_enable >> 1 & 1 == 1) self.drawBackground(1);
@ -640,8 +639,7 @@ pub const Ppu = struct {
const framebuf_base = width * @as(usize, scanline);
if (obj_enable) self.fetchSprites();
var layer: usize = 0;
while (layer < 4) : (layer += 1) {
for (0..4) |layer| {
self.drawSprites(@truncate(u2, layer));
if (layer == self.bg[0].cnt.priority.read() and bg_enable & 1 == 1) self.drawBackground(0);
if (layer == self.bg[1].cnt.priority.read() and bg_enable >> 1 & 1 == 1) self.drawBackground(1);
@ -654,8 +652,7 @@ pub const Ppu = struct {
const framebuf_base = width * @as(usize, scanline);
if (obj_enable) self.fetchSprites();
var layer: usize = 0;
while (layer < 4) : (layer += 1) {
for (0..4) |layer| {
self.drawSprites(@truncate(u2, layer));
if (layer == self.bg[2].cnt.priority.read() and bg_enable >> 2 & 1 == 1) self.drawAffineBackground(2);
if (layer == self.bg[3].cnt.priority.read() and bg_enable >> 3 & 1 == 1) self.drawAffineBackground(3);
@ -671,7 +668,7 @@ pub const Ppu = struct {
const vram_buf = @ptrCast([*]const u16, @alignCast(@alignOf(u16), self.vram.buf));
const framebuf = @ptrCast([*]u32, @alignCast(@alignOf(u32), self.framebuf.get(.Emulator)));
for (vram_buf[vram_base .. vram_base + width]) |bgr555, i| {
for (vram_buf[vram_base .. vram_base + width], 0..) |bgr555, i| {
framebuf[framebuf_base + i] = rgba888(bgr555);
}
},
@ -685,7 +682,7 @@ pub const Ppu = struct {
const pal_buf = @ptrCast([*]const u16, @alignCast(@alignOf(u16), self.palette.buf));
const framebuf = @ptrCast([*]u32, @alignCast(@alignOf(u32), self.framebuf.get(.Emulator)));
for (self.vram.buf[vram_base .. vram_base + width]) |pal_id, i| {
for (self.vram.buf[vram_base .. vram_base + width], 0..) |pal_id, i| {
framebuf[framebuf_base + i] = rgba888(pal_buf[pal_id]);
}
},
@ -701,8 +698,7 @@ pub const Ppu = struct {
const vram_buf = @ptrCast([*]const u16, @alignCast(@alignOf(u16), self.vram.buf));
const framebuf = @ptrCast([*]u32, @alignCast(@alignOf(u32), self.framebuf.get(.Emulator)));
var i: usize = 0;
while (i < width) : (i += 1) {
for (0..width) |i| {
const bgr555 = if (scanline < m5_height and i < m5_width) vram_buf[vram_base + i] else self.palette.backdrop();
framebuf[framebuf_base + i] = rgba888(bgr555);
}
@ -718,7 +714,7 @@ pub const Ppu = struct {
// FIXME: @ptrCast between slices changing the length isn't implemented yet
const framebuf = @ptrCast([*]u32, @alignCast(@alignOf(u32), self.framebuf.get(.Emulator)));
for (self.scanline.top()) |maybe_top, i| {
for (self.scanline.top(), 0..) |maybe_top, i| {
const maybe_btm = self.scanline.btm()[i];
const bgr555 = self.getBgr555(maybe_top, maybe_btm);

View File

@ -73,7 +73,7 @@ pub const Scheduler = struct {
/// Removes the **first** scheduled event of type `needle`
pub fn removeScheduledEvent(self: *Self, needle: EventKind) void {
for (self.queue.items) |event, i| {
for (self.queue.items, 0..) |event, i| {
if (std.meta.eql(event.kind, needle)) {
// invalidates the slice we're iterating over