diff --git a/docs/introduction/hello.zig b/docs/introduction/hello.zig index b6b49c0..b87b3ea 100644 --- a/docs/introduction/hello.zig +++ b/docs/introduction/hello.zig @@ -3,8 +3,8 @@ const cart = @import("cart-api"); export fn update() void { // Set background to a nice gray @memset(cart.framebuffer, cart.DisplayColor{ - .red = 10, - .green = 20, - .blue = 10, + .r = 10, + .g = 20, + .b = 10, }); } diff --git a/samples/feature_test.zig b/samples/feature_test.zig index 8822b03..c389e3d 100644 --- a/samples/feature_test.zig +++ b/samples/feature_test.zig @@ -67,27 +67,27 @@ export fn update() void { for (0..cart.screen_height) |y| { for (0..cart.screen_width) |x| { cart.framebuffer[y * cart.screen_width + x] = .{ - .red = @intFromFloat(@as(f32, @floatFromInt(x)) / cart.screen_width * 31), - .green = green_565, - .blue = @intFromFloat(@as(f32, @floatFromInt(y)) / cart.screen_height * 31), + .r = @intFromFloat(@as(f32, @floatFromInt(x)) / cart.screen_width * 31), + .g = green_565, + .b = @intFromFloat(@as(f32, @floatFromInt(y)) / cart.screen_height * 31), }; } } for (cart.neopixels, 0..) |*np, i| { np.* = .{ - .red = @intFromFloat(@as(f32, @floatFromInt(i)) / 5 * 255), - .green = @intFromFloat(@as(f32, @floatFromInt(cart.light_level.*)) / std.math.maxInt(u12) * 255), - .blue = @intFromFloat(@as(f32, @floatFromInt(i)) / 5 * 255), + .r = @intFromFloat(@as(f32, @floatFromInt(i)) / 5 * 255), + .g = @intFromFloat(@as(f32, @floatFromInt(cart.light_level.*)) / std.math.maxInt(u12) * 255), + .b = @intFromFloat(@as(f32, @floatFromInt(i)) / 5 * 255), }; } cart.blit(.{ .sprite = &.{ - .{ .red = 31, .green = 0, .blue = 0 }, - .{ .red = 0, .green = 0, .blue = 31 }, - .{ .red = 31, .green = 0, .blue = 0 }, - .{ .red = 0, .green = 0, .blue = 31 }, + .{ .r = 31, .g = 0, .b = 0 }, + .{ .r = 0, .g = 0, .b = 31 }, + .{ .r = 31, .g = 0, .b = 0 }, + .{ .r = 0, .g = 0, .b = 31 }, }, .x = 40, .y = 40, @@ -101,21 +101,21 @@ export fn update() void { .y1 = 50, .x2 = 70, .y2 = 70, - .color = .{ .red = 0, .green = 63, .blue = 0 }, + .color = .{ .r = 0, .g = 63, .b = 0 }, }); cart.hline(.{ .x = 30, .y = 30, .len = 20, - .color = .{ .red = 31, .green = 0, .blue = 0 }, + .color = .{ .r = 31, .g = 0, .b = 0 }, }); cart.vline(.{ .x = 30, .y = 30, .len = 20, - .color = .{ .red = 31, .green = 0, .blue = 0 }, + .color = .{ .r = 31, .g = 0, .b = 0 }, }); cart.oval(.{ @@ -123,8 +123,8 @@ export fn update() void { .y = 80, .width = 10, .height = 10, - .stroke_color = .{ .red = 0, .green = 0, .blue = 31 }, - .fill_color = .{ .red = 31, .green = 0, .blue = 31 }, + .stroke_color = .{ .r = 0, .g = 0, .b = 31 }, + .fill_color = .{ .r = 31, .g = 0, .b = 31 }, }); cart.rect(.{ @@ -132,23 +132,23 @@ export fn update() void { .y = 100, .width = 10, .height = 10, - .stroke_color = .{ .red = 31, .green = 31, .blue = 31 }, - .fill_color = .{ .red = 0, .green = 63, .blue = 31 }, + .stroke_color = .{ .r = 31, .g = 31, .b = 31 }, + .fill_color = .{ .r = 0, .g = 63, .b = 31 }, }); cart.text(.{ .str = fbs.getWritten(), .x = 0, .y = 0, - .text_color = .{ .red = 0, .green = 0, .blue = 0 }, - .background_color = .{ .red = 31, .green = 63, .blue = 31 }, + .text_color = .{ .r = 0, .g = 0, .b = 0 }, + .background_color = .{ .r = 31, .g = 63, .b = 31 }, }); cart.text(.{ .str = "\x80\x81\x82\x83\x84\x85\x86\x87\x88", .x = 0, .y = 120, - .text_color = .{ .red = 0, .green = 0, .blue = 0 }, - .background_color = .{ .red = 31, .green = 63, .blue = 31 }, + .text_color = .{ .r = 0, .g = 0, .b = 0 }, + .background_color = .{ .r = 31, .g = 63, .b = 31 }, }); } diff --git a/samples/zeroman/build/convert_gfx.zig b/samples/zeroman/build/convert_gfx.zig index c4042de..f69551f 100644 --- a/samples/zeroman/build/convert_gfx.zig +++ b/samples/zeroman/build/convert_gfx.zig @@ -80,7 +80,7 @@ fn convert(args: ConvertFile, writer: std.fs.File.Writer) !void { try writer.writeAll(" pub const colors = [_]DisplayColor{\n"); for (colors.items) |c| { - try writer.print(" .{{ .red = {}, .green = {}, .blue = {} }},\n", .{ c.r, c.g, c.b }); + try writer.print(" .{{ .r = {}, .g = {}, .b = {} }},\n", .{ c.r, c.g, c.b }); } try writer.writeAll(" };\n"); diff --git a/src/cart/api.zig b/src/cart/api.zig index 85632fc..31ebacf 100644 --- a/src/cart/api.zig +++ b/src/cart/api.zig @@ -19,16 +19,16 @@ pub const screen_height: u32 = 128; const base = if (builtin.target.isWasm()) 0 else 0x20000000; /// RGB888, true color -pub const NeopixelColor = packed struct(u24) { blue: u8, green: u8, red: u8 }; +pub const NeopixelColor = packed struct(u24) { b: u8, g: u8, r: u8 }; /// RGB565, high color pub const DisplayColor = packed struct(u16) { /// 0-31 - blue: u5, + b: u5, /// 0-63 - green: u6, + g: u6, /// 0-31 - red: u5, + r: u5, const Optional = enum(i32) { none = -1, @@ -40,7 +40,7 @@ pub const DisplayColor = packed struct(u16) { }; }; -pub const Controls = packed struct { +pub const Controls = packed struct(u9) { /// START button start: bool, /// SELECT button @@ -81,7 +81,7 @@ const platform_specific = if (builtin.target.isWasm()) extern fn line(color: DisplayColor, x1: i32, y1: i32, x2: i32, y2: i32) void; extern fn oval(stroke_color: DisplayColor.Optional, fill_color: DisplayColor.Optional, x: i32, y: i32, width: u32, height: u32) void; extern fn rect(stroke_color: DisplayColor.Optional, fill_color: DisplayColor.Optional, x: i32, y: i32, width: u32, height: u32) void; - extern fn text(text_color: DisplayColor, background_color: DisplayColor.Optional, str_ptr: [*]const u8, str_len: usize, x: i32, y: i32) void; + extern fn text(text_color: DisplayColor.Optional, background_color: DisplayColor.Optional, str_ptr: [*]const u8, str_len: usize, x: i32, y: i32) void; extern fn vline(color: DisplayColor, x: i32, y: i32, len: u32) void; extern fn hline(color: DisplayColor, x: i32, y: i32, len: u32) void; extern fn tone(frequency: u32, duration: u32, volume: u32, flags: ToneOptions.Flags) void; @@ -115,12 +115,12 @@ pub const BlitOptions = struct { width: u32, height: u32, /// x within the sprite atlas. - src_x: i32 = 0, + src_x: u32 = 0, /// y within the sprite atlas. - src_y: i32 = 0, + src_y: u32 = 0, /// Width of the entire sprite atlas. stride: ?u32 = null, - flags: Flags, + flags: Flags = .{}, }; /// Copies pixels to the framebuffer. @@ -187,8 +187,8 @@ pub const OvalOptions = struct { y: i32, width: u32, height: u32, - stroke_color: ?DisplayColor, - fill_color: ?DisplayColor, + stroke_color: ?DisplayColor = null, + fill_color: ?DisplayColor = null, }; /// Draws an oval (or circle). @@ -219,8 +219,8 @@ pub const RectOptions = struct { y: i32, width: u32, height: u32, - stroke_color: ?DisplayColor, - fill_color: ?DisplayColor, + stroke_color: ?DisplayColor = null, + fill_color: ?DisplayColor = null, }; /// Draws a rectangle. @@ -250,15 +250,15 @@ pub const TextOptions = struct { str: []const u8, x: i32, y: i32, - text_color: DisplayColor, - background_color: ?DisplayColor, + text_color: ?DisplayColor = null, + background_color: ?DisplayColor = null, }; /// Draws text using the built-in system font. pub inline fn text(options: TextOptions) void { if (comptime builtin.target.isWasm()) { platform_specific.text( - options.text_color, + DisplayColor.Optional.from(options.text_color), DisplayColor.Optional.from(options.background_color), options.str.ptr, options.str.len, @@ -353,8 +353,9 @@ pub const ToneOptions = struct { }; channel: Channel, - duty_cycle: DutyCycle, - panning: Panning, + /// `duty_cycle` is only used when `channel` is set to `pulse1` or `pulse2` + duty_cycle: DutyCycle = .@"1/8", + panning: Panning = .stereo, padding: u26 = undefined, };