chore: rename struct
This commit is contained in:
parent
ea3b6ba8fd
commit
fed7e6d8aa
|
@ -1,7 +1,6 @@
|
|||
const std = @import("std");
|
||||
|
||||
const Header = @import("cartridge.zig").Header;
|
||||
const SharedIo = @import("io.zig").Io;
|
||||
const Scheduler = @import("Scheduler.zig");
|
||||
|
||||
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?
|
||||
pub const SharedContext = struct {
|
||||
pub const SharedCtx = struct {
|
||||
const MiB = 0x100000;
|
||||
const KiB = 0x400;
|
||||
|
||||
pub const Io = @import("io.zig").Io;
|
||||
const Vram = @import("ppu.zig").Vram;
|
||||
|
||||
io: *SharedIo,
|
||||
io: *Io,
|
||||
main: *[4 * MiB]u8,
|
||||
wram: *Wram,
|
||||
vram: *Vram,
|
||||
|
@ -112,7 +112,7 @@ pub const SharedContext = struct {
|
|||
|
||||
const ctx = .{
|
||||
.io = blk: {
|
||||
const io = try allocator.create(SharedIo);
|
||||
const io = try allocator.create(Io);
|
||||
io.* = .{};
|
||||
|
||||
break :blk io;
|
||||
|
|
|
@ -2,8 +2,7 @@ const std = @import("std");
|
|||
const io = @import("io.zig");
|
||||
|
||||
const Scheduler = @import("../Scheduler.zig");
|
||||
const SharedIo = @import("../io.zig").Io;
|
||||
const SharedContext = @import("../emu.zig").SharedContext;
|
||||
const SharedCtx = @import("../emu.zig").SharedCtx;
|
||||
const Wram = @import("../emu.zig").Wram;
|
||||
const Vram = @import("../ppu.zig").Vram;
|
||||
const forceAlign = @import("../emu.zig").forceAlign;
|
||||
|
@ -23,18 +22,18 @@ wram: *[64 * KiB]u8,
|
|||
vram: *Vram,
|
||||
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);
|
||||
errdefer allocator.destroy(wram);
|
||||
@memset(wram, 0);
|
||||
|
||||
return .{
|
||||
.main = shared_ctx.main,
|
||||
.wram_shr = shared_ctx.wram,
|
||||
.vram = shared_ctx.vram,
|
||||
.main = ctx.main,
|
||||
.wram_shr = ctx.wram,
|
||||
.vram = ctx.vram,
|
||||
.wram = wram,
|
||||
.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 Bus = @import("Bus.zig");
|
||||
const SharedIo = @import("../io.zig").Io;
|
||||
const SharedCtx = @import("../emu.zig").SharedCtx;
|
||||
const masks = @import("../io.zig").masks;
|
||||
|
||||
const log = std.log.scoped(.nds7_io);
|
||||
|
||||
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 };
|
||||
}
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ const io = @import("io.zig");
|
|||
|
||||
const Ppu = @import("../ppu.zig").Ppu;
|
||||
const Scheduler = @import("../Scheduler.zig");
|
||||
const SharedContext = @import("../emu.zig").SharedContext;
|
||||
const SharedCtx = @import("../emu.zig").SharedCtx;
|
||||
const Wram = @import("../emu.zig").Wram;
|
||||
const forceAlign = @import("../emu.zig").forceAlign;
|
||||
|
||||
|
@ -22,16 +22,16 @@ ppu: Ppu,
|
|||
|
||||
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
|
||||
scheduler.push(.{ .nds9 = .draw }, 256 * dots_per_cycle);
|
||||
|
||||
return .{
|
||||
.main = shared_ctx.main,
|
||||
.wram = shared_ctx.wram,
|
||||
.ppu = try Ppu.init(allocator, shared_ctx.vram),
|
||||
.main = ctx.main,
|
||||
.wram = ctx.wram,
|
||||
.ppu = try Ppu.init(allocator, ctx.vram),
|
||||
.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 Bus = @import("Bus.zig");
|
||||
const SharedIo = @import("../io.zig").Io;
|
||||
const SharedCtx = @import("../emu.zig").SharedCtx;
|
||||
const masks = @import("../io.zig").masks;
|
||||
|
||||
const sext = @import("../../util.zig").sext;
|
||||
|
@ -12,7 +12,7 @@ const sext = @import("../../util.zig").sext;
|
|||
const log = std.log.scoped(.nds9_io);
|
||||
|
||||
pub const Io = struct {
|
||||
shared: *SharedIo,
|
||||
shared: *SharedCtx.Io,
|
||||
|
||||
/// POWCNT1 - Graphics Power Control
|
||||
/// Read / Write
|
||||
|
@ -25,7 +25,7 @@ pub const Io = struct {
|
|||
div: Divisor = .{},
|
||||
sqrt: SquareRootUnit = .{},
|
||||
|
||||
pub fn init(io: *SharedIo) @This() {
|
||||
pub fn init(io: *SharedCtx.Io) @This() {
|
||||
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 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 Scheduler = @import("core/Scheduler.zig");
|
||||
|
||||
|
@ -34,8 +34,8 @@ pub fn main() !void {
|
|||
const rom_file = try std.fs.cwd().openFile(rom_path, .{});
|
||||
defer rom_file.close();
|
||||
|
||||
const shared_ctx = try SharedContext.init(allocator);
|
||||
defer shared_ctx.deinit(allocator);
|
||||
const ctx = try SharedCtx.init(allocator);
|
||||
defer ctx.deinit(allocator);
|
||||
|
||||
var scheduler = try Scheduler.init(allocator);
|
||||
defer scheduler.deinit();
|
||||
|
@ -47,8 +47,8 @@ pub fn main() !void {
|
|||
|
||||
var cp15 = System.Cp15{};
|
||||
|
||||
var bus7 = try System.Bus7.init(allocator, &scheduler, shared_ctx);
|
||||
var bus9 = try System.Bus9.init(allocator, &scheduler, shared_ctx);
|
||||
var bus7 = try System.Bus7.init(allocator, &scheduler, ctx);
|
||||
var bus9 = try System.Bus9.init(allocator, &scheduler, ctx);
|
||||
|
||||
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));
|
||||
|
|
Loading…
Reference in New Issue