Compare commits
No commits in common. "4c57f0b5f4a667005acf6008691d43cc21bf2790" and "cef711a497f097353c94ccbec09312e4cf8432fb" have entirely different histories.
4c57f0b5f4
...
cef711a497
|
@ -1,6 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
/// For use with with the tiniest ROM
|
/// For use with withe tiniest ROM
|
||||||
pub const Header = extern struct {
|
pub const Header = extern struct {
|
||||||
title: [12]u8,
|
title: [12]u8,
|
||||||
game_code: [4]u8,
|
game_code: [4]u8,
|
||||||
|
@ -79,7 +79,8 @@ pub const Header = extern struct {
|
||||||
|
|
||||||
// note, we're missing some debug_ prefixed fields here
|
// note, we're missing some debug_ prefixed fields here
|
||||||
// but we want the header struct to be 0x160 bytes so that
|
// but we want the header struct to be 0x160 bytes so that
|
||||||
// the smallest NDS rom's header can be read without any specific workarounds
|
// the smallest NDS rom's header can be read without any speicifc
|
||||||
|
// workarounds
|
||||||
// TODO: Determine if we ever will need those debug fields, and if so: Implement them
|
// TODO: Determine if we ever will need those debug fields, and if so: Implement them
|
||||||
|
|
||||||
comptime {
|
comptime {
|
||||||
|
|
|
@ -3,7 +3,6 @@ const nds9 = @import("nds9.zig");
|
||||||
const nds7 = @import("nds7.zig");
|
const nds7 = @import("nds7.zig");
|
||||||
|
|
||||||
const Header = @import("cartridge.zig").Header;
|
const Header = @import("cartridge.zig").Header;
|
||||||
const SharedIo = @import("io.zig").Io;
|
|
||||||
const Arm946es = nds9.Arm946es;
|
const Arm946es = nds9.Arm946es;
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
@ -108,26 +107,3 @@ pub fn runFrame(nds7_group: nds7.Group, nds9_group: nds9.Group) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Perf win to allocating on the stack instead?
|
|
||||||
pub const SharedContext = struct {
|
|
||||||
const MiB = 0x100000;
|
|
||||||
|
|
||||||
io: *SharedIo,
|
|
||||||
main: *[4 * MiB]u8,
|
|
||||||
|
|
||||||
pub fn init(allocator: Allocator) !@This() {
|
|
||||||
const ctx = .{
|
|
||||||
.io = try allocator.create(SharedIo),
|
|
||||||
.main = try allocator.create([4 * MiB]u8),
|
|
||||||
};
|
|
||||||
ctx.io.* = .{};
|
|
||||||
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deinit(self: @This(), allocator: Allocator) void {
|
|
||||||
allocator.destroy(self.io);
|
|
||||||
allocator.destroy(self.main);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ const io = @import("io.zig");
|
||||||
|
|
||||||
const Scheduler = @import("Scheduler.zig");
|
const Scheduler = @import("Scheduler.zig");
|
||||||
const SharedIo = @import("../io.zig").Io;
|
const SharedIo = @import("../io.zig").Io;
|
||||||
const SharedContext = @import("../emu.zig").SharedContext;
|
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
||||||
|
@ -19,16 +18,20 @@ main: *[4 * MiB]u8,
|
||||||
wram: *[64 * KiB]u8,
|
wram: *[64 * KiB]u8,
|
||||||
io: io.Io,
|
io: io.Io,
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_ctx: SharedContext) !@This() {
|
pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_io: *SharedIo) !@This() {
|
||||||
|
const main_mem = try allocator.create([4 * MiB]u8);
|
||||||
|
errdefer allocator.destroy(main_mem);
|
||||||
|
@memset(main_mem, 0);
|
||||||
|
|
||||||
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 = main_mem,
|
||||||
.wram = wram,
|
.wram = wram,
|
||||||
.scheduler = scheduler,
|
.scheduler = scheduler,
|
||||||
.io = io.Io.init(shared_ctx.io),
|
.io = io.Io.init(shared_io),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ const std = @import("std");
|
||||||
|
|
||||||
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 SharedIo = @import("../io.zig").Io;
|
||||||
const io = @import("io.zig");
|
const io = @import("io.zig");
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
@ -20,7 +20,11 @@ ppu: Ppu,
|
||||||
|
|
||||||
scheduler: *Scheduler,
|
scheduler: *Scheduler,
|
||||||
|
|
||||||
pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_ctx: SharedContext) !@This() {
|
pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_io: *SharedIo) !@This() {
|
||||||
|
const main_mem = try allocator.create([4 * MiB]u8);
|
||||||
|
errdefer allocator.destroy(main_mem);
|
||||||
|
@memset(main_mem, 0);
|
||||||
|
|
||||||
const vram1_mem = try allocator.create([512 * KiB]u8);
|
const vram1_mem = try allocator.create([512 * KiB]u8);
|
||||||
errdefer allocator.destroy(vram1_mem);
|
errdefer allocator.destroy(vram1_mem);
|
||||||
@memset(vram1_mem, 0);
|
@memset(vram1_mem, 0);
|
||||||
|
@ -29,11 +33,11 @@ pub fn init(allocator: Allocator, scheduler: *Scheduler, shared_ctx: SharedConte
|
||||||
scheduler.push(.draw, 256 * dots_per_cycle);
|
scheduler.push(.draw, 256 * dots_per_cycle);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.main = shared_ctx.main,
|
.main = main_mem,
|
||||||
.vram1 = vram1_mem,
|
.vram1 = vram1_mem,
|
||||||
.ppu = try Ppu.init(allocator),
|
.ppu = try Ppu.init(allocator),
|
||||||
.scheduler = scheduler,
|
.scheduler = scheduler,
|
||||||
.io = io.Io.init(shared_ctx.io),
|
.io = io.Io.init(shared_io),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/main.zig
12
src/main.zig
|
@ -8,7 +8,7 @@ const emu = @import("core/emu.zig");
|
||||||
const IBus = @import("arm32").Bus;
|
const IBus = @import("arm32").Bus;
|
||||||
const IScheduler = @import("arm32").Scheduler;
|
const IScheduler = @import("arm32").Scheduler;
|
||||||
const Ui = @import("platform.zig").Ui;
|
const Ui = @import("platform.zig").Ui;
|
||||||
const SharedContext = @import("core/emu.zig").SharedContext;
|
const SharedIo = @import("core/io.zig").Io;
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const ClapResult = clap.Result(clap.Help, &cli_params, clap.parsers.default);
|
const ClapResult = clap.Result(clap.Help, &cli_params, clap.parsers.default);
|
||||||
|
@ -36,12 +36,14 @@ 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);
|
// FIXME: Perf win to allocating on the stack instead?
|
||||||
defer shared_ctx.deinit(allocator);
|
const shared_io = try allocator.create(SharedIo);
|
||||||
|
defer allocator.destroy(shared_io);
|
||||||
|
shared_io.* = .{};
|
||||||
|
|
||||||
const nds9_group: nds9.Group = blk: {
|
const nds9_group: nds9.Group = blk: {
|
||||||
var scheduler = try nds9.Scheduler.init(allocator);
|
var scheduler = try nds9.Scheduler.init(allocator);
|
||||||
var bus = try nds9.Bus.init(allocator, &scheduler, shared_ctx);
|
var bus = try nds9.Bus.init(allocator, &scheduler, shared_io);
|
||||||
var arm946es = nds9.Arm946es.init(IScheduler.init(&scheduler), IBus.init(&bus));
|
var arm946es = nds9.Arm946es.init(IScheduler.init(&scheduler), IBus.init(&bus));
|
||||||
|
|
||||||
break :blk .{ .cpu = &arm946es, .bus = &bus, .scheduler = &scheduler };
|
break :blk .{ .cpu = &arm946es, .bus = &bus, .scheduler = &scheduler };
|
||||||
|
@ -50,7 +52,7 @@ pub fn main() !void {
|
||||||
|
|
||||||
const nds7_group: nds7.Group = blk: {
|
const nds7_group: nds7.Group = blk: {
|
||||||
var scheduler = try nds7.Scheduler.init(allocator);
|
var scheduler = try nds7.Scheduler.init(allocator);
|
||||||
var bus = try nds7.Bus.init(allocator, &scheduler, shared_ctx);
|
var bus = try nds7.Bus.init(allocator, &scheduler, shared_io);
|
||||||
var arm7tdmi = nds7.Arm7tdmi.init(IScheduler.init(&scheduler), IBus.init(&bus));
|
var arm7tdmi = nds7.Arm7tdmi.init(IScheduler.init(&scheduler), IBus.init(&bus));
|
||||||
|
|
||||||
break :blk .{ .cpu = &arm7tdmi, .bus = &bus, .scheduler = &scheduler };
|
break :blk .{ .cpu = &arm7tdmi, .bus = &bus, .scheduler = &scheduler };
|
||||||
|
|
Loading…
Reference in New Issue