// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! Klaus Dormann's functional tests, run against both eight-bit cores. //! //! A subproject of its own for the same reason the corpus next door is one: //! what it needs is fetched rather than kept here, and nothing that merely //! builds the emulator should have to pull a test suite along with it. The //! library comes from the checkout this sits inside, by path, so the two are //! always the same code. const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const zig65 = b.dependency("zig65", .{ .target = target, .optimize = optimize, }); const exe = b.addExecutable(.{ .name = "functional", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "zig65", .module = zig65.module("zig65") }, }, }), }); b.installArtifact(exe); const run = b.addRunArtifact(exe); run.stdio = .inherit; if (b.lazyDependency("functional_tests", .{})) |tests| { // Two of the four ship assembled, in `bin_files`. run.addDirectoryArg(tests.path("bin_files")); // The other two ship as source, because Dormann's own build uses a DOS // assembler and he says in as many words that he will not switch to // another one. He does not have to: `as65`'s dialect has been // reimplemented, so the sources assemble unaltered, and assembling // them here rather than committing the result means what is tested is // what he published. if (b.lazyDependency("aigrette65", .{ .target = target, .optimize = optimize, })) |aigrette| { const assembler = aigrette.artifact("aigrette65"); for ([_][]const u8{ "6502_decimal_test", "6502_interrupt_test" }) |name| { const assemble = b.addRunArtifact(assembler); // Quietly, with no listing: the source sits in the package // cache, which is read only, and a listing is written beside // it. `-w` is the wide format and `-h0` turns off page // headers, which are the switches the sources themselves ask // for. assemble.addArgs(&.{ "-q", "-w", "-h0" }); const object = assemble.addPrefixedOutputFileArg( "-o", b.fmt("{s}.bin", .{name}), ); assemble.addFileArg(tests.path(b.fmt("{s}.a65", .{name}))); run.addFileArg(object); } } } if (b.args) |args| run.addArgs(args); const step = b.step("run", "Run Klaus Dormann's functional tests"); step.dependOn(&run.step); b.default_step.dependOn(&exe.step); }