diff --git a/.gitignore b/.gitignore index 19e3127..267a2b3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.bin *.hex *.o +zig-cache +zig-out \ No newline at end of file diff --git a/lib_basics.zig b/lib_basics.zig index 869114c..eeb96aa 100644 --- a/lib_basics.zig +++ b/lib_basics.zig @@ -511,7 +511,7 @@ pub const lib = struct { Uart.writeText(csi ++ "?25l"); } - pub fn line(comptime fmt: []const u8, args: var) void { + pub fn line(comptime fmt: []const u8, args: anytype) void { format(fmt, args); pair(0, 0, "K"); Uart.writeText("\n"); @@ -523,13 +523,13 @@ pub const lib = struct { pub fn pair(a: u32, b: u32, letter: []const u8) void { if (a <= 1 and b <= 1) { - format("{}{}", .{ csi, letter }); + format("{s}{s}", .{ csi, letter }); } else if (b <= 1) { - format("{}{}{}", .{ csi, a, letter }); + format("{s}{}{s}", .{ csi, a, letter }); } else if (a <= 1) { - format("{};{}{}", .{ csi, b, letter }); + format("{s};{}{s}", .{ csi, b, letter }); } else { - format("{}{};{}{}", .{ csi, a, b, letter }); + format("{s}{};{}{s}", .{ csi, a, b, letter }); } } @@ -569,16 +569,16 @@ pub const lib = struct { return self.capture() -% self.start_time; } - fn prepare(self: *TimeKeeper, duration: u32) void { + pub fn prepare(self: *TimeKeeper, duration: u32) void { self.duration = duration; self.reset(); } - fn isFinished(self: *TimeKeeper) bool { + pub fn isFinished(self: *TimeKeeper) bool { return self.elapsed() >= self.duration; } - fn reset(self: *TimeKeeper) void { + pub fn reset(self: *TimeKeeper) void { self.start_time = self.capture(); } @@ -645,7 +645,7 @@ pub const lib = struct { } pub const Uart = struct { - var stream: std.io.OutStream(Uart, stream_error, writeTextError) = undefined; + var stream: std.io.Writer(Uart, stream_error, writeTextError) = undefined; var tx_busy: bool = undefined; var tx_queue: [3]u8 = undefined; var tx_queue_read: usize = undefined; @@ -675,7 +675,7 @@ pub const lib = struct { return events.rx_ready == 1; } - pub fn format(comptime fmt: []const u8, args: var) void { + pub fn format(comptime fmt: []const u8, args: anytype) void { std.fmt.format(stream, fmt, args) catch |_| {}; } @@ -691,7 +691,7 @@ pub const lib = struct { } } - pub fn log(comptime fmt: []const u8, args: var) void { + pub fn log(comptime fmt: []const u8, args: anytype) void { format(fmt ++ "\n", args); } @@ -798,7 +798,7 @@ pub const lib = struct { }); }; - pub fn hangf(comptime fmt: []const u8, args: var) noreturn { + pub fn hangf(comptime fmt: []const u8, args: anytype) noreturn { log(fmt, args); Uart.drainTxQueue(); while (true) {} @@ -812,11 +812,11 @@ pub const lib = struct { if (Exceptions.panic_handler) |handler| { handler(message, trace); } else { - panicf("panic(): {}", .{message}); + panicf("panic(): {s}", .{message}); } } - pub fn panicf(comptime fmt: []const u8, args: var) noreturn { + pub fn panicf(comptime fmt: []const u8, args: anytype) noreturn { @setCold(true); if (Exceptions.already_panicking) { hangf("\npanicked during panic", .{}); @@ -848,7 +848,7 @@ pub const lib = struct { i = j + 1; } if (line.len >= 3) { - log("{x:5} in {}", .{ return_address, line[3..] }); + log("{x:5} in {s}", .{ return_address, line[3..] }); } else { log("{x:5}", .{return_address}); } diff --git a/makehex.zig b/makehex.zig index 8af1509..9b995f8 100644 --- a/makehex.zig +++ b/makehex.zig @@ -1,6 +1,6 @@ pub fn main() !void { const cwd = fs.cwd(); - const image = try cwd.openFile("zig-cache/bin/main.img", fs.File.OpenFlags{}); + const image = try cwd.openFile("zig-out/bin/main.img", fs.File.OpenFlags{}); defer image.close(); const hex = try cwd.createFile("main.hex", fs.File.CreateFlags{}); defer hex.close(); @@ -40,7 +40,7 @@ fn writeRecord(file: fs.File, offset: usize, code: u8, bytes: []u8) !void { } record[record.len - 1] = checksum; var line_buf: [1 + record_buf.len * 2 + 1]u8 = undefined; - _ = try file.write(try fmt.bufPrint(&line_buf, ":{X}\n", .{record})); + _ = try file.write(try fmt.bufPrint(&line_buf, ":{s}\n", .{std.fmt.fmtSliceHexUpper(record)})); } const assert = std.debug.assert; diff --git a/mission0_mission_selector.zig b/mission0_mission_selector.zig index 6127b31..c078248 100644 --- a/mission0_mission_selector.zig +++ b/mission0_mission_selector.zig @@ -17,7 +17,7 @@ export fn mission0_main() noreturn { Mission.register(&mission3_vector_table, "sensors - temperature, orientation", "mission3_sensors.zig"); log("available missions:", .{}); for (Mission.missions) |*m, i| { - log("{}. {}", .{ i + 1, m.title }); + log("{}. {s}", .{ i + 1, m.title }); } while (true) { @@ -149,7 +149,7 @@ const Mission = struct { \\ bx %[reset_pc] : : [reset_pc] "{r0}" (reset_pc), - [reset_sp] "{r1}" (reset_sp) + [reset_sp] "{r1}" (reset_sp), ); } diff --git a/mission2_model_railroad_pwm.zig b/mission2_model_railroad_pwm.zig index 0c882c7..a1b2715 100644 --- a/mission2_model_railroad_pwm.zig +++ b/mission2_model_railroad_pwm.zig @@ -208,7 +208,7 @@ const ThrottleActivity = struct { if (displayed_percent == 0) { log("scrolling '0' just once", .{}); } else { - log("scrolling '{}' repeatedly", .{text}); + log("scrolling '{s}' repeatedly", .{text}); } } else if (displayed_percent == 0) { return; @@ -247,9 +247,9 @@ const ThrottleActivity = struct { fn setPercent(message: []const u8, new: i32) void { const new_percent = @intCast(u32, math.min(math.max(new, 0), 100)); if (new_percent != percent) { - log("{}: throttle changed from {} to {}", .{ message, percent, new_percent }); + log("{s}: throttle changed from {} to {}", .{ message, percent, new_percent }); } else { - log("{}: throttle remains at {}%", .{ message, percent }); + log("{s}: throttle remains at {}%", .{ message, percent }); } percent = new_percent; Timer1.tasks.stop = 1;