diff --git a/README.md b/README.md index 8fad2ccf5ae1121f672e1bcc147f97c0d845c11d..0fe7b3a06f7998e8bfea3e754a1c94219349a6e4 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,4 @@ | [zig-x11](./zig-x11) | Uses X11 to create a basic window without any bindings needed. | | [zig-http](./zig-http) | Basic example of a HTTP 1.1 server without any routing etc. | | [zig-x11-box](./zig-x11-box) | Move a box around with arrow keys with Xlib and Zig. | | [zig-kv-store](./zig-kv-store) | Simple Key-value store that mimics memcached written in Zig. | +| [zig-wad](./zig-wad) | Reads doom.wad and extracts the identification header. | diff --git a/zig-wad/Makefile b/zig-wad/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..b962fd100009f048138a340c584a6029515bab18 --- /dev/null +++ b/zig-wad/Makefile @@ -0,0 +1,2 @@ +default: + zig run main.zig diff --git a/zig-wad/doom.wad b/zig-wad/doom.wad new file mode 100644 index 0000000000000000000000000000000000000000..27b28afe4bc8282d0b27d2af99245a12c6e8614d Binary files /dev/null and b/zig-wad/doom.wad differ diff --git a/zig-wad/main.zig b/zig-wad/main.zig new file mode 100644 index 0000000000000000000000000000000000000000..4d1364e3034efd223c5b49a8bcb07275eeb0f2c7 --- /dev/null +++ b/zig-wad/main.zig @@ -0,0 +1,16 @@ +const std = @import("std"); + +const WADHeader = struct { identification: [4]u8 }; + +pub fn main() !void { + var file = try std.fs.cwd().openFile("doom.wad", .{}); + defer file.close(); + + var buffer = try std.heap.page_allocator.alignedAlloc(u8, @alignOf(WADHeader), @sizeOf(WADHeader)); + defer std.heap.page_allocator.free(buffer); + + _ = try file.read(buffer); + + var header: *const WADHeader = @as(*const WADHeader, @ptrCast(buffer.ptr)); + std.debug.print("WAD Type: {s}\n", .{header.identification}); +}