42 lines
961 B
Zig
42 lines
961 B
Zig
const std = @import("std");
|
|
|
|
const Frequency = 500;
|
|
const Mods = .{
|
|
@import("Mem.zig"),
|
|
@import("Cpu.zig"),
|
|
@import("Time.zig"),
|
|
};
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
defer _ = gpa.deinit();
|
|
const alloc = gpa.allocator();
|
|
|
|
var mods: std.meta.Tuple(&Mods) = undefined;
|
|
inline for (&mods) |*mod| {
|
|
try mod.init(alloc);
|
|
}
|
|
defer {
|
|
inline for (&mods) |*mod| {
|
|
mod.deinit(alloc);
|
|
}
|
|
}
|
|
|
|
const stdout = std.io.getStdOut();
|
|
const buffer = try alloc.alloc(u8, 512);
|
|
defer alloc.free(buffer);
|
|
|
|
var outputs: [Mods.len][]const u8 = undefined;
|
|
|
|
while (true) {
|
|
std.time.sleep(Frequency * std.time.ns_per_ms);
|
|
|
|
inline for (&mods, &outputs) |*mod, *out| {
|
|
out.* = try mod.update();
|
|
}
|
|
|
|
const output = try std.fmt.bufPrint(buffer, "{s}\n", .{outputs});
|
|
try stdout.writeAll(output);
|
|
}
|
|
}
|