Skip to content

Commit

Permalink
build system changes to support different submodels
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Aug 2, 2024
1 parent 11af2d1 commit 868b6a3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
23 changes: 19 additions & 4 deletions emus/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ const ResolvedTarget = Build.ResolvedTarget;
const OptimizeMode = std.builtin.OptimizeMode;
const Module = Build.Module;

const Model = enum {
NONE,
KC852,
KC853,
KC854,
};

const emulators = .{
.{ .name = "pacman", .path = "pacman/pacman.zig" },
.{ .name = "pengo", .path = "pengo/pengo.zig" },
.{ .name = "bombjack", .path = "bombjack/bombjack.zig" },
.{ .name = "kc853", .path = "kc85/kc853.zig" },
.{ .name = "pacman", .path = "pacman/pacman.zig", .model = .NONE },
.{ .name = "pengo", .path = "pengo/pengo.zig", .model = .NONE },
.{ .name = "bombjack", .path = "bombjack/bombjack.zig", .model = .NONE },
.{ .name = "kc852", .path = "kc85/kc85.zig", .model = .KC852 },
.{ .name = "kc853", .path = "kc85/kc85.zig", .model = .KC853 },
};

pub const Options = struct {
Expand Down Expand Up @@ -37,6 +45,7 @@ pub fn build(b: *Build, opts: Options) void {
inline for (emulators) |emu| {
addEmulator(b, .{
.name = emu.name,
.model = emu.model,
.src = b.fmt("{s}/{s}", .{ opts.src_dir, emu.path }),
.target = opts.target,
.optimize = opts.optimize,
Expand All @@ -49,6 +58,7 @@ pub fn build(b: *Build, opts: Options) void {

const EmuOptions = struct {
name: []const u8,
model: Model,
src: []const u8,
target: ResolvedTarget,
optimize: OptimizeMode,
Expand All @@ -64,6 +74,11 @@ fn addEmulator(b: *Build, opts: EmuOptions) void {
.target = opts.target,
.optimize = opts.optimize,
});
if (opts.model != .NONE) {
const options = b.addOptions();
options.addOption(Model, "model", opts.model);
exe.root_module.addOptions("build_options", options);
}
exe.root_module.addImport("chipz", opts.mod_chipz);
exe.root_module.addImport("host", opts.mod_host);
exe.root_module.addImport("sokol", opts.mod_sokol);
Expand Down
34 changes: 26 additions & 8 deletions emus/kc85/kc853.zig → emus/kc85/kc85.zig
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const build_options = @import("build_options");
const std = @import("std");
const sokol = @import("sokol");
const sapp = sokol.app;
const slog = sokol.log;
const host = @import("host");
const kc85 = @import("chipz").systems.kc85;

const KC853 = kc85.Type(.KC853);
const model: kc85.Model = switch (build_options.model) {
.KC852 => .KC852,
.KC853 => .KC853,
.KC854 => .KKC85,
else => @compileError("unknown KC85 model"),
};
const name = switch (model) {
.KC852 => "KC85/2",
.KC853 => "KC85/3",
.KC854 => "KC85/4",
};
const KC85 = kc85.Type(model);

var sys: KC853 = undefined;
var sys: KC85 = undefined;

export fn init() void {
host.audio.init(.{});
Expand All @@ -19,9 +31,15 @@ export fn init() void {
.volume = 0.5,
.callback = host.audio.push,
},
.roms = .{
.caos31 = @embedFile("roms/caos31.853"),
.kcbasic = @embedFile("roms/basic_c0.853"),
.roms = switch (model) {
.KC852 => .{
.caos22 = @embedFile("roms/caos22.852"),
},
.KC853 => .{
.caos31 = @embedFile("roms/caos31.853"),
.kcbasic = @embedFile("roms/basic_c0.853"),
},
else => @panic("FIXME"),
},
});
host.gfx.init(.{ .display = sys.displayInfo() });
Expand All @@ -36,7 +54,7 @@ export fn frame() void {
host.gfx.draw(.{
.display = sys.displayInfo(),
.status = .{
.name = "KC85/3",
.name = name,
.num_ticks = num_ticks,
.frame_stats = host.prof.stats(.FRAME),
.emu_stats = host.prof.stats(.EMU),
Expand Down Expand Up @@ -116,7 +134,7 @@ export fn input(ev: ?*const sapp.Event) void {
}

pub fn main() void {
const display = KC853.displayInfo(null);
const display = KC85.displayInfo(null);
const border = host.gfx.DEFAULT_BORDER;
const width = 2 * display.view.width + border.left + border.right;
const height = 2 * display.view.height + border.top + border.bottom;
Expand All @@ -125,7 +143,7 @@ pub fn main() void {
.frame_cb = frame,
.event_cb = input,
.cleanup_cb = cleanup,
.window_title = "KC85/3 (chipz)",
.window_title = name ++ "(chipz)",
.width = width,
.height = height,
.icon = .{ .sokol_default = true },
Expand Down

0 comments on commit 868b6a3

Please sign in to comment.