chore: rename struct
This commit is contained in:
parent
ea3b6ba8fd
commit
fed7e6d8aa
|
@ -1,7 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const Header = @import("cartridge.zig").Header;
|
const Header = @import("cartridge.zig").Header;
|
||||||
const SharedIo = @import("io.zig").Io;
|
|
||||||
const Scheduler = @import("Scheduler.zig");
|
const Scheduler = @import("Scheduler.zig");
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
@ -90,13 +89,14 @@ pub fn runFrame(scheduler: *Scheduler, system: System) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Perf win to allocating on the stack instead?
|
// FIXME: Perf win to allocating on the stack instead?
|
||||||
pub const SharedContext = struct {
|
pub const SharedCtx = struct {
|
||||||
const MiB = 0x100000;
|
const MiB = 0x100000;
|
||||||
const KiB = 0x400;
|
const KiB = 0x400;
|
||||||
|
|
||||||
|
pub const Io = @import("io.zig").Io;
|
||||||
const Vram = @import("ppu.zig").Vram;
|
const Vram = @import("ppu.zig").Vram;
|
||||||
|
|
||||||
io: *SharedIo,
|
io: *Io,
|
||||||
main: *[4 * MiB]u8,
|
main: *[4 * MiB]u8,
|
||||||
wram: *Wram,
|
wram: *Wram,
|
||||||
vram: *Vram,
|
vram: *Vram,
|
||||||
|
@ -112,7 +112,7 @@ pub const SharedContext = struct {
|
||||||
|
|
||||||
const ctx = .{
|
const ctx = .{
|
||||||
.io = blk: {
|
.io = blk: {
|
||||||
const io = try allocator.create(SharedIo);
|
const io = try allocator.create(Io);
|
||||||
io.* = .{};
|
io.* = .{};
|
||||||
|
|
||||||
break :blk io;
|
break :blk io;
|
||||||
|
|
|
@ -2,8 +2,7 @@ const std = @import("std");
|
||||||
const io = @import("io.zig");
|
const io = @import("io.zig");
|
||||||
|
|
||||||
const Scheduler = @import("../Scheduler.zig");
|
const Scheduler = @import("../Scheduler.zig");
|
||||||
const SharedIo = @import("../io.zig").Io;
|
const SharedCtx = @import("../emu.zig").SharedCtx;
|
||||||
const SharedContext = @import("../emu.zig").SharedContext;
|
|
||||||
const Wram = @import("../emu.zig").Wram;
|
const Wram = @import("../emu.zig").Wram;
|
||||||
const Vram = @import("../ppu.zig").Vram;
|
const Vram = @import("../ppu.zig").Vram;
|
||||||
const forceAlign = @import("../emu.zig").forceAlign;
|
const forceAlign = @import("../emu.zig").forceAlign;
|
||||||
|
@ -23,18 +22,18 @@ wram: *[64 * KiB]u8,
|
||||||
vram: *Vram,
|
vram: *Vram,
|
||||||
io: io.Io,
|
io: io.Io,
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_ctx: SharedContext) !@This() {
|
pub fn init(allocator: Allocator, scheduler: *Scheduler, ctx: SharedCtx) !@This() {
|
||||||
const wram = try allocator.create([64 * KiB]u8);
|
const wram = try allocator.create([64 * KiB]u8);
|
||||||
errdefer allocator.destroy(wram);
|
errdefer allocator.destroy(wram);
|
||||||
@memset(wram, 0);
|
@memset(wram, 0);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.main = shared_ctx.main,
|
.main = ctx.main,
|
||||||
.wram_shr = shared_ctx.wram,
|
.wram_shr = ctx.wram,
|
||||||
.vram = shared_ctx.vram,
|
.vram = ctx.vram,
|
||||||
.wram = wram,
|
.wram = wram,
|
||||||
.scheduler = scheduler,
|
.scheduler = scheduler,
|
||||||
.io = io.Io.init(shared_ctx.io),
|
.io = io.Io.init(ctx.io),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,15 @@ const Bitfield = @import("bitfield").Bitfield;
|
||||||
const Bit = @import("bitfield").Bit;
|
const Bit = @import("bitfield").Bit;
|
||||||
|
|
||||||
const Bus = @import("Bus.zig");
|
const Bus = @import("Bus.zig");
|
||||||
const SharedIo = @import("../io.zig").Io;
|
const SharedCtx = @import("../emu.zig").SharedCtx;
|
||||||
const masks = @import("../io.zig").masks;
|
const masks = @import("../io.zig").masks;
|
||||||
|
|
||||||
const log = std.log.scoped(.nds7_io);
|
const log = std.log.scoped(.nds7_io);
|
||||||
|
|
||||||
pub const Io = struct {
|
pub const Io = struct {
|
||||||
shared: *SharedIo,
|
shared: *SharedCtx.Io,
|
||||||
|
|
||||||
pub fn init(io: *SharedIo) @This() {
|
pub fn init(io: *SharedCtx.Io) @This() {
|
||||||
return .{ .shared = io };
|
return .{ .shared = io };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ const io = @import("io.zig");
|
||||||
|
|
||||||
const Ppu = @import("../ppu.zig").Ppu;
|
const Ppu = @import("../ppu.zig").Ppu;
|
||||||
const Scheduler = @import("../Scheduler.zig");
|
const Scheduler = @import("../Scheduler.zig");
|
||||||
const SharedContext = @import("../emu.zig").SharedContext;
|
const SharedCtx = @import("../emu.zig").SharedCtx;
|
||||||
const Wram = @import("../emu.zig").Wram;
|
const Wram = @import("../emu.zig").Wram;
|
||||||
const forceAlign = @import("../emu.zig").forceAlign;
|
const forceAlign = @import("../emu.zig").forceAlign;
|
||||||
|
|
||||||
|
@ -22,16 +22,16 @@ ppu: Ppu,
|
||||||
|
|
||||||
scheduler: *Scheduler,
|
scheduler: *Scheduler,
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_ctx: SharedContext) !@This() {
|
pub fn init(allocator: Allocator, scheduler: *Scheduler, ctx: SharedCtx) !@This() {
|
||||||
const dots_per_cycle = 3; // ARM946E-S runs twice as fast as the ARM7TDMI
|
const dots_per_cycle = 3; // ARM946E-S runs twice as fast as the ARM7TDMI
|
||||||
scheduler.push(.{ .nds9 = .draw }, 256 * dots_per_cycle);
|
scheduler.push(.{ .nds9 = .draw }, 256 * dots_per_cycle);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.main = shared_ctx.main,
|
.main = ctx.main,
|
||||||
.wram = shared_ctx.wram,
|
.wram = ctx.wram,
|
||||||
.ppu = try Ppu.init(allocator, shared_ctx.vram),
|
.ppu = try Ppu.init(allocator, ctx.vram),
|
||||||
.scheduler = scheduler,
|
.scheduler = scheduler,
|
||||||
.io = io.Io.init(shared_ctx.io),
|
.io = io.Io.init(ctx.io),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ const Bitfield = @import("bitfield").Bitfield;
|
||||||
const Bit = @import("bitfield").Bit;
|
const Bit = @import("bitfield").Bit;
|
||||||
|
|
||||||
const Bus = @import("Bus.zig");
|
const Bus = @import("Bus.zig");
|
||||||
const SharedIo = @import("../io.zig").Io;
|
const SharedCtx = @import("../emu.zig").SharedCtx;
|
||||||
const masks = @import("../io.zig").masks;
|
const masks = @import("../io.zig").masks;
|
||||||
|
|
||||||
const sext = @import("../../util.zig").sext;
|
const sext = @import("../../util.zig").sext;
|
||||||
|
@ -12,7 +12,7 @@ const sext = @import("../../util.zig").sext;
|
||||||
const log = std.log.scoped(.nds9_io);
|
const log = std.log.scoped(.nds9_io);
|
||||||
|
|
||||||
pub const Io = struct {
|
pub const Io = struct {
|
||||||
shared: *SharedIo,
|
shared: *SharedCtx.Io,
|
||||||
|
|
||||||
/// POWCNT1 - Graphics Power Control
|
/// POWCNT1 - Graphics Power Control
|
||||||
/// Read / Write
|
/// Read / Write
|
||||||
|
@ -25,7 +25,7 @@ pub const Io = struct {
|
||||||
div: Divisor = .{},
|
div: Divisor = .{},
|
||||||
sqrt: SquareRootUnit = .{},
|
sqrt: SquareRootUnit = .{},
|
||||||
|
|
||||||
pub fn init(io: *SharedIo) @This() {
|
pub fn init(io: *SharedCtx.Io) @This() {
|
||||||
return .{ .shared = io };
|
return .{ .shared = io };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
10
src/main.zig
10
src/main.zig
|
@ -4,7 +4,7 @@ const clap = @import("zig-clap");
|
||||||
const emu = @import("core/emu.zig");
|
const emu = @import("core/emu.zig");
|
||||||
|
|
||||||
const Ui = @import("platform.zig").Ui;
|
const Ui = @import("platform.zig").Ui;
|
||||||
const SharedContext = @import("core/emu.zig").SharedContext;
|
const SharedCtx = @import("core/emu.zig").SharedCtx;
|
||||||
const System = @import("core/emu.zig").System;
|
const System = @import("core/emu.zig").System;
|
||||||
const Scheduler = @import("core/Scheduler.zig");
|
const Scheduler = @import("core/Scheduler.zig");
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ pub fn main() !void {
|
||||||
const rom_file = try std.fs.cwd().openFile(rom_path, .{});
|
const rom_file = try std.fs.cwd().openFile(rom_path, .{});
|
||||||
defer rom_file.close();
|
defer rom_file.close();
|
||||||
|
|
||||||
const shared_ctx = try SharedContext.init(allocator);
|
const ctx = try SharedCtx.init(allocator);
|
||||||
defer shared_ctx.deinit(allocator);
|
defer ctx.deinit(allocator);
|
||||||
|
|
||||||
var scheduler = try Scheduler.init(allocator);
|
var scheduler = try Scheduler.init(allocator);
|
||||||
defer scheduler.deinit();
|
defer scheduler.deinit();
|
||||||
|
@ -47,8 +47,8 @@ pub fn main() !void {
|
||||||
|
|
||||||
var cp15 = System.Cp15{};
|
var cp15 = System.Cp15{};
|
||||||
|
|
||||||
var bus7 = try System.Bus7.init(allocator, &scheduler, shared_ctx);
|
var bus7 = try System.Bus7.init(allocator, &scheduler, ctx);
|
||||||
var bus9 = try System.Bus9.init(allocator, &scheduler, shared_ctx);
|
var bus9 = try System.Bus9.init(allocator, &scheduler, ctx);
|
||||||
|
|
||||||
var arm7tdmi = System.Arm7tdmi.init(IScheduler.init(&scheduler), IBus.init(&bus7));
|
var arm7tdmi = System.Arm7tdmi.init(IScheduler.init(&scheduler), IBus.init(&bus7));
|
||||||
var arm946es = System.Arm946es.init(IScheduler.init(&scheduler), IBus.init(&bus9), ICoprocessor.init(&cp15));
|
var arm946es = System.Arm946es.init(IScheduler.init(&scheduler), IBus.init(&bus9), ICoprocessor.init(&cp15));
|
||||||
|
|
Loading…
Reference in New Issue