Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.bin
*.hex
*.o
zig-cache
zig-out
30 changes: 15 additions & 15 deletions lib_basics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 });
}
}

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 |_| {};
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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) {}
Expand All @@ -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", .{});
Expand Down Expand Up @@ -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});
}
Expand Down
4 changes: 2 additions & 2 deletions makehex.zig
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions mission0_mission_selector.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
);
}

Expand Down
6 changes: 3 additions & 3 deletions mission2_model_railroad_pwm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down