Skip to content

Commit

Permalink
zig fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ringtailsoftware committed Dec 3, 2024
1 parent 3541088 commit f1aba1e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 31 deletions.
28 changes: 12 additions & 16 deletions src/agnes/agnes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const agnes = @cImport({
@cInclude("agnes.h");
});

var ag:?*agnes.agnes_t = null;
var ag_input:agnes.agnes_input_t = undefined;
var ag: ?*agnes.agnes_t = null;
var ag_input: agnes.agnes_input_t = undefined;

const romData = @embedFile("croom.nes");

Expand Down Expand Up @@ -70,7 +70,7 @@ export fn agnes_memcpy(dst: [*]u8, src: [*]u8, size: c_int) callconv(.C) [*]u8 {
return dst;
}

export fn agnes_memset(dst: [*]u8, val:u8, size: c_int) callconv(.C) void {
export fn agnes_memset(dst: [*]u8, val: u8, size: c_int) callconv(.C) void {
@memset(dst[0..@intCast(size)], val);
}

Expand All @@ -79,13 +79,13 @@ export fn agnes_malloc(size: c_int) callconv(.C) ?[*]u8 {
_ = console.print("ALLOCFAIL", .{}) catch 0;
return null;
};
const sz:*usize = @ptrCast(@alignCast(mem.ptr));
const sz: *usize = @ptrCast(@alignCast(mem.ptr));
sz.* = @intCast(size);
return mem.ptr + @sizeOf(usize);
}

export fn agnes_free(ptr: [*]u8) callconv(.C) void {
const sz:*const usize = @ptrCast(@alignCast(ptr - @sizeOf(usize)));
const sz: *const usize = @ptrCast(@alignCast(ptr - @sizeOf(usize)));
const p = ptr - @sizeOf(usize);
allocator.free(p[0 .. sz.* + @sizeOf(usize)]);
}
Expand All @@ -95,31 +95,29 @@ pub fn millis() u32 {
return (getTimeUs() - startTime) / 1000;
}


export fn keyevent(keycode: u32, down: bool) void {
//_ = console.print("keycode {d} {any}\n", .{keycode, down}) catch 0;
//_ = console.print("keycode {d} {any}\n", .{keycode, down}) catch 0;
ag_input.a = false;
ag_input.b = false;
ag_input.left = false;
ag_input.right = false;
ag_input.up = false;
ag_input.down = false;
ag_input.select = false; // shift
ag_input.start = false; // enter
ag_input.select = false; // shift
ag_input.start = false; // enter

switch(keycode) {
switch (keycode) {
90 => ag_input.a = down,
88 => ag_input.b = down,
37 => ag_input.left = down,
39 => ag_input.right = down,
38 => ag_input.up = down,
40 => ag_input.down = down,
17 => ag_input.select = down, // shift
13 => ag_input.start = down, // enter
17 => ag_input.select = down, // shift
13 => ag_input.start = down, // enter
else => {},
}
agnes.agnes_set_input(ag, &ag_input, 0);

}

export fn getGfxBufPtr() [*]u8 {
Expand All @@ -138,8 +136,7 @@ export fn getRightBufPtr() [*]u8 {
return @ptrCast(&mix_right);
}

export fn renderSoundQuantum() void {
}
export fn renderSoundQuantum() void {}

export fn init() void {
startTime = getTimeUs();
Expand Down Expand Up @@ -186,7 +183,6 @@ fn printFPS() void {
lastTime = millis();
}


export fn renderGfx() void {
// background
printFPS();
Expand Down
8 changes: 4 additions & 4 deletions src/bat/bat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export fn renderSoundQuantum() void {
var bytes: usize = RENDER_QUANTUM_FRAMES * 4 * 2;

// pocketmod produces interleaved l/r/l/r data, so fetch a double batch
const lrbuf:[*]u8 = @ptrCast(&music_leftright);
const lrbuf: [*]u8 = @ptrCast(&music_leftright);
bytes = RENDER_QUANTUM_FRAMES * 4 * 2;
var i: usize = 0;
while (i < bytes) {
Expand Down Expand Up @@ -326,9 +326,9 @@ fn HSVtoRGB(h: f32, s: f32, v: f32) u32 {
const rf = std.math.round(r * 255);
const gf = std.math.round(g * 255);
const bf = std.math.round(b * 255);
const r8:u8 = @intFromFloat(rf);
const g8:u8 = @intFromFloat(gf);
const b8:u8 = @intFromFloat(bf);
const r8: u8 = @intFromFloat(rf);
const g8: u8 = @intFromFloat(gf);
const b8: u8 = @intFromFloat(bf);
const colour: u32 = 0xFF000000 | @as(u32, b8) << 16 | @as(u32, g8) << 8 | @as(u32, r8);
return colour;
}
Expand Down
5 changes: 2 additions & 3 deletions src/doom/doom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export fn doom_malloc_impl(size: c_int) callconv(.C) ?[*]u8 {
_ = console.print("ALLOCFAIL", .{}) catch 0;
return null;
};
const sz:*usize = @ptrCast(@alignCast(mem.ptr));
const sz: *usize = @ptrCast(@alignCast(mem.ptr));
sz.* = @intCast(size);
return mem.ptr + @sizeOf(usize);
}

export fn doom_free_impl(ptr: [*]u8) callconv(.C) void {
const sz:*const usize = @ptrCast(@alignCast(ptr - @sizeOf(usize)));
const sz: *const usize = @ptrCast(@alignCast(ptr - @sizeOf(usize)));
const p = ptr - @sizeOf(usize);
allocator.free(p[0 .. sz.* + @sizeOf(usize)]);
}
Expand Down Expand Up @@ -279,7 +279,6 @@ export fn renderGfx() void {
const fb: [*]const u8 = pd.doom_get_framebuffer(4);
const fb32 = @as([*]const u32, @ptrCast(@alignCast(fb)))[0 .. WIDTH * HEIGHT];
@memcpy(&gfxFramebuffer, fb32);

}

fn keycodeToDoomKey(keycode: u32) pd.doom_key_t {
Expand Down
4 changes: 2 additions & 2 deletions src/mandelbrot/mandelbrot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export fn mouseClickEvent(x: f32, y: f32, down: bool) void {
const end_pix_x = @max(x1, x2);
const end_pix_y = @max(y1, y2);

const w:f32 = @floatFromInt(WIDTH);
const h:f32 = @floatFromInt(HEIGHT);
const w: f32 = @floatFromInt(WIDTH);
const h: f32 = @floatFromInt(HEIGHT);

const imag_w = (zoom.right - zoom.left);
const imag_h = (zoom.top - zoom.bottom);
Expand Down
2 changes: 1 addition & 1 deletion src/mod/mod.zig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export fn renderSoundQuantum() void {
var bytes: usize = RENDER_QUANTUM_FRAMES * 4 * 2;

// pocketmod produces interleaved l/r/l/r data, so fetch a double batch
const lrbuf:[*]u8 = @ptrCast(&leftright);
const lrbuf: [*]u8 = @ptrCast(&leftright);
bytes = RENDER_QUANTUM_FRAMES * 4 * 2;
var i: usize = 0;
while (i < bytes) {
Expand Down
1 change: 0 additions & 1 deletion src/olive/olive.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export fn init() void {
}
}


var buf: [16]u8 = undefined;

export fn update(deltaMs: u32) void {
Expand Down
2 changes: 1 addition & 1 deletion src/olive/zlm-generic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ pub fn SpecializeOn(comptime Real: type) type {
/// only works on float matrices
pub fn invert(src: Self) ?Self {
// https://github.com/stackgl/gl-mat4/blob/master/invert.js
const a:[16]Real = @bitCast(src.fields);
const a: [16]Real = @bitCast(src.fields);

const a00 = a[0];
const a01 = a[1];
Expand Down
6 changes: 3 additions & 3 deletions src/tinygl/tinygl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,22 @@ export fn gl_malloc(size: c_int) callconv(.C) ?[*]u8 {
_ = console.print("ALLOCFAIL", .{}) catch 0;
return null;
};
const sz:*usize = @ptrCast(@alignCast(mem.ptr));
const sz: *usize = @ptrCast(@alignCast(mem.ptr));
sz.* = @intCast(size);
return mem.ptr + @sizeOf(usize);
}

export fn gl_zalloc(size: c_int) callconv(.C) ?[*]u8 {
const mem: ?[*]u8 = gl_malloc(size);
if (mem != null) {
const mems = mem.?[0 .. @intCast(size)];
const mems = mem.?[0..@intCast(size)];
@memset(mems, 0x00);
}
return mem;
}

export fn gl_free(ptr: [*]u8) callconv(.C) void {
const sz:*const usize = @ptrCast(@alignCast(ptr - @sizeOf(usize)));
const sz: *const usize = @ptrCast(@alignCast(ptr - @sizeOf(usize)));
const p = ptr - @sizeOf(usize);
allocator.free(p[0 .. sz.* + @sizeOf(usize)]);
}
Expand Down

0 comments on commit f1aba1e

Please sign in to comment.