Skip to content

Commit a9a1a77

Browse files
All samples building.
MIDI still quite broken
1 parent 94a0578 commit a9a1a77

15 files changed

Lines changed: 390 additions & 1668 deletions

File tree

build.zig

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var target:std.Build.ResolvedTarget = undefined;
66
pub fn addAssetsOption(b: *std.Build, exe:anytype, assetpath:[]const u8) !void {
77
var options = b.addOptions();
88

9-
var files = std.ArrayList([]const u8).init(b.allocator);
9+
var files = std.array_list.Managed([]const u8).init(b.allocator);
1010
defer files.deinit();
1111

1212
var buf: [std.fs.max_path_bytes]u8 = undefined;
@@ -35,10 +35,11 @@ pub fn addAssetsOption(b: *std.Build, exe:anytype, assetpath:[]const u8) !void {
3535
fn addExample(b: *std.Build, comptime name: []const u8, flags: ?[]const []const u8, sources: ?[]const []const u8, includes: ?[]const []const u8) !void {
3636
const exe = b.addExecutable(.{
3737
.name = name,
38-
.root_source_file = b.path("src/" ++ name ++ "/" ++ name ++ ".zig"),
39-
.target = target,
40-
.optimize = optimize,
41-
.strip = false,
38+
.root_module = b.createModule(.{ // this line was added
39+
.root_source_file = b.path("src/" ++ name ++ "/" ++ name ++ ".zig"),
40+
.target = target,
41+
.optimize = optimize,
42+
}),
4243
});
4344
exe.entry = .disabled;
4445
exe.rdynamic = true;
@@ -82,12 +83,19 @@ fn addExample(b: *std.Build, comptime name: []const u8, flags: ?[]const []const
8283
});
8384
exe.root_module.addImport("mibu", mibu.module("mibu"));
8485

85-
// add zigtris for terminal example
86-
const zigtris = b.dependency("zigtris", .{
86+
const zlm = b.dependency("zlm", .{
8787
.target = target,
8888
.optimize = optimize,
8989
});
90-
exe.root_module.addImport("zigtris", zigtris.module("zigtris"));
90+
exe.root_module.addImport("zlm", zlm.module("zlm"));
91+
92+
const zigtris_dep = b.dependency("zigtris", .{
93+
.target = target,
94+
.optimize = optimize,
95+
});
96+
97+
const zigtris_mod = zigtris_dep.module("zigtris");
98+
exe.root_module.addImport("zigtris", zigtris_mod);
9199

92100
exe.addIncludePath(b.path("src/"));
93101

@@ -131,35 +139,35 @@ pub fn build(b: *std.Build) !void {
131139

132140
try addExample(b, "sinetone", null, null, null);
133141

134-
// try addExample(b, "synth", null, null, null);
135-
136-
// try addExample(b, "mod", &.{"-Wall"}, &.{"src/mod/pocketmod.c"}, null);
137-
138-
// try addExample(b, "bat", &.{"-Wall"}, &.{"src/mod/pocketmod.c"}, null);
139-
140-
// try addExample(b, "doom", &.{ "-Wall", "-fno-sanitize=undefined" }, &.{
141-
// "src/doom/puredoom/DOOM.c", "src/doom/puredoom/PureDOOM.c", "src/doom/puredoom/am_map.c",
142-
// "src/doom/puredoom/d_items.c", "src/doom/puredoom/d_main.c", "src/doom/puredoom/d_net.c",
143-
// "src/doom/puredoom/doomdef.c", "src/doom/puredoom/doomstat.c", "src/doom/puredoom/dstrings.c",
144-
// "src/doom/puredoom/f_finale.c", "src/doom/puredoom/f_wipe.c", "src/doom/puredoom/g_game.c",
145-
// "src/doom/puredoom/hu_lib.c", "src/doom/puredoom/hu_stuff.c", "src/doom/puredoom/i_net.c",
146-
// "src/doom/puredoom/i_sound.c", "src/doom/puredoom/i_system.c", "src/doom/puredoom/i_video.c",
147-
// "src/doom/puredoom/info.c", "src/doom/puredoom/m_argv.c", "src/doom/puredoom/m_bbox.c",
148-
// "src/doom/puredoom/m_cheat.c", "src/doom/puredoom/m_fixed.c", "src/doom/puredoom/m_menu.c",
149-
// "src/doom/puredoom/m_misc.c", "src/doom/puredoom/m_random.c", "src/doom/puredoom/m_swap.c",
150-
// "src/doom/puredoom/p_ceilng.c", "src/doom/puredoom/p_doors.c", "src/doom/puredoom/p_enemy.c",
151-
// "src/doom/puredoom/p_floor.c", "src/doom/puredoom/p_inter.c", "src/doom/puredoom/p_lights.c",
152-
// "src/doom/puredoom/p_map.c", "src/doom/puredoom/p_maputl.c", "src/doom/puredoom/p_mobj.c",
153-
// "src/doom/puredoom/p_plats.c", "src/doom/puredoom/p_pspr.c", "src/doom/puredoom/p_saveg.c",
154-
// "src/doom/puredoom/p_setup.c", "src/doom/puredoom/p_sight.c", "src/doom/puredoom/p_spec.c",
155-
// "src/doom/puredoom/p_switch.c", "src/doom/puredoom/p_telept.c", "src/doom/puredoom/p_tick.c",
156-
// "src/doom/puredoom/p_user.c", "src/doom/puredoom/r_bsp.c", "src/doom/puredoom/r_data.c",
157-
// "src/doom/puredoom/r_draw.c", "src/doom/puredoom/r_main.c", "src/doom/puredoom/r_plane.c",
158-
// "src/doom/puredoom/r_segs.c", "src/doom/puredoom/r_sky.c", "src/doom/puredoom/r_things.c",
159-
// "src/doom/puredoom/s_sound.c", "src/doom/puredoom/sounds.c", "src/doom/puredoom/st_lib.c",
160-
// "src/doom/puredoom/st_stuff.c", "src/doom/puredoom/tables.c", "src/doom/puredoom/v_video.c",
161-
// "src/doom/puredoom/w_wad.c", "src/doom/puredoom/wi_stuff.c", "src/doom/puredoom/z_zone.c",
162-
// }, null);
142+
try addExample(b, "synth", null, null, null);
143+
144+
try addExample(b, "mod", &.{"-Wall"}, &.{"src/mod/pocketmod.c"}, null);
145+
146+
try addExample(b, "bat", &.{"-Wall"}, &.{"src/mod/pocketmod.c"}, null);
147+
148+
try addExample(b, "doom", &.{ "-Wall", "-fno-sanitize=undefined" }, &.{
149+
"src/doom/puredoom/DOOM.c", "src/doom/puredoom/PureDOOM.c", "src/doom/puredoom/am_map.c",
150+
"src/doom/puredoom/d_items.c", "src/doom/puredoom/d_main.c", "src/doom/puredoom/d_net.c",
151+
"src/doom/puredoom/doomdef.c", "src/doom/puredoom/doomstat.c", "src/doom/puredoom/dstrings.c",
152+
"src/doom/puredoom/f_finale.c", "src/doom/puredoom/f_wipe.c", "src/doom/puredoom/g_game.c",
153+
"src/doom/puredoom/hu_lib.c", "src/doom/puredoom/hu_stuff.c", "src/doom/puredoom/i_net.c",
154+
"src/doom/puredoom/i_sound.c", "src/doom/puredoom/i_system.c", "src/doom/puredoom/i_video.c",
155+
"src/doom/puredoom/info.c", "src/doom/puredoom/m_argv.c", "src/doom/puredoom/m_bbox.c",
156+
"src/doom/puredoom/m_cheat.c", "src/doom/puredoom/m_fixed.c", "src/doom/puredoom/m_menu.c",
157+
"src/doom/puredoom/m_misc.c", "src/doom/puredoom/m_random.c", "src/doom/puredoom/m_swap.c",
158+
"src/doom/puredoom/p_ceilng.c", "src/doom/puredoom/p_doors.c", "src/doom/puredoom/p_enemy.c",
159+
"src/doom/puredoom/p_floor.c", "src/doom/puredoom/p_inter.c", "src/doom/puredoom/p_lights.c",
160+
"src/doom/puredoom/p_map.c", "src/doom/puredoom/p_maputl.c", "src/doom/puredoom/p_mobj.c",
161+
"src/doom/puredoom/p_plats.c", "src/doom/puredoom/p_pspr.c", "src/doom/puredoom/p_saveg.c",
162+
"src/doom/puredoom/p_setup.c", "src/doom/puredoom/p_sight.c", "src/doom/puredoom/p_spec.c",
163+
"src/doom/puredoom/p_switch.c", "src/doom/puredoom/p_telept.c", "src/doom/puredoom/p_tick.c",
164+
"src/doom/puredoom/p_user.c", "src/doom/puredoom/r_bsp.c", "src/doom/puredoom/r_data.c",
165+
"src/doom/puredoom/r_draw.c", "src/doom/puredoom/r_main.c", "src/doom/puredoom/r_plane.c",
166+
"src/doom/puredoom/r_segs.c", "src/doom/puredoom/r_sky.c", "src/doom/puredoom/r_things.c",
167+
"src/doom/puredoom/s_sound.c", "src/doom/puredoom/sounds.c", "src/doom/puredoom/st_lib.c",
168+
"src/doom/puredoom/st_stuff.c", "src/doom/puredoom/tables.c", "src/doom/puredoom/v_video.c",
169+
"src/doom/puredoom/w_wad.c", "src/doom/puredoom/wi_stuff.c", "src/doom/puredoom/z_zone.c",
170+
}, null);
163171

164172

165173
try addExample(b, "tinygl", &.{ "-Wall", "-fno-sanitize=undefined" }, &.{
@@ -182,9 +190,11 @@ pub fn build(b: *std.Build) !void {
182190
// web server
183191
const serve_exe = b.addExecutable(.{
184192
.name = "serve",
185-
.root_source_file = b.path("httpserver/serve.zig"),
186-
.target = hosttarget,
187-
.optimize = optimize,
193+
.root_module = b.createModule(.{
194+
.root_source_file = b.path("httpserver/serve.zig"),
195+
.target = target,
196+
.optimize = optimize,
197+
}),
188198
});
189199

190200
const mod_server = b.addModule("StaticHttpFileServer", .{

build.zig.zon

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,33 @@
2424
// Once all dependencies are fetched, `zig build` no longer requires
2525
// internet connectivity.
2626
.dependencies = .{
27-
.mime = .{
28-
.url = "https://github.com/andrewrk/mime/archive/refs/tags/2.0.1.tar.gz",
29-
.hash = "12209083b0c43d0f68a26a48a7b26ad9f93b22c9cff710c78ddfebb47b89cfb9c7a4",
27+
.zeptolibc = .{
28+
.url = "git+https://github.com/ringtailsoftware/zeptolibc.git#3b1a193cea41c4fd7c3e4f97171bcf233cbdaf89",
29+
.hash = "zeptolibc-0.0.1-T3flJ3U9AACUVuYXtZL3tbN9nOfY3tkGpv8Y4sYr0vkr",
3030
},
31-
.zvterm = .{
32-
.url = "git+https://github.com/ringtailsoftware/zvterm.git#7617c3610f0dd491c197ba03f3149c4040ff6845",
33-
.hash = "12207e677beeb14481d932fe7d2c97d0ae9b968053753f0639690e00d5ceaabb8800",
31+
32+
.mime = .{
33+
.url = "git+https://github.com/andrewrk/mime.git#4535b74bd5fcaa03e22f2f25af164a4c6253af00",
34+
.hash = "mime-4.0.0-zwmL--0gAACndOVlROQeDnM0chfojNDS8tpohlsBqMNy",
3435
},
35-
.zeptolibc = .{
36-
.url = "git+https://github.com/ringtailsoftware/zeptolibc.git#229791c08b4309d154e4fec3e90ab1900215c0da",
37-
.hash = "zeptolibc-0.0.1-T3flJ9w3AABROzhiPaD0vDIdsgPlgpKHNFYTBxxmrsAL",
36+
// .zvterm = .{
37+
// .url = "git+https://github.com/ringtailsoftware/zvterm.git#05cee2f1d00c7b4cec0eb9f7beef0b48918b748b",
38+
// .hash = "zvterm-0.0.1-VuAjA4JnAwAqsAyUTtgA60fx5WNSOnnO68VHq2kCdl0s",
39+
// },
40+
.zvterm = .{
41+
.path = "../zvterm",
42+
},
43+
.zigtris = .{
44+
.url = "git+https://github.com/ringtailsoftware/zigtris.git#1dc9fc4c5dae709279bfe0708e3fae5c810837f0",
45+
.hash = "zigtris-0.0.1-of0vIotsAACy777-kWnBDCH2tYIprpqXLpidQgvRF6r1",
3846
},
3947
.mibu = .{
40-
.url = "git+https://github.com/xyaman/mibu.git#b001662c929e2719ee24be585a3120640f946337",
41-
.hash = "1220d78664322b50e31a99cfb004b6fa60c43098d95abf7ec60a21ebeaf1c914edaf",
48+
.url = "git+https://github.com/xyaman/mibu.git#be3713ff04e7db3584669e679253ef388e426dc6",
49+
.hash = "mibu-0.0.1-dev-Ddr1riTEAAAYAe1TWBT--W8fPUL8UyBE7dy-yNNZ3z5V",
4250
},
43-
.zigtris = .{
44-
.url = "git+https://github.com/ringtailsoftware/zigtris.git#7563ff5421974857ee8e745f7ae020874f2954af",
45-
.hash = "122062266e1f9482cd9601be6ecb8cacc91cc8c9a912e3a8c4e48a69827869dc17ec",
51+
.zlm = .{
52+
.url = "git+https://github.com/ziglibs/zlm.git#b4fcb32f98bd895f940ef8819c375ac3f89077d7",
53+
.hash = "zlm-0.1.0-LoZ6yI2sAACW1YdckJV4qm7HXCGcRkkk_wO36dUi5qcQ",
4654
},
4755
},
4856
.paths = .{

src/mandelbrot/console.zig

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,77 @@
11
const std = @import("std");
2-
var cw = ConsoleWriter{};
3-
2+
//var cw = ConsoleWriter{};
3+
//
44
extern fn console_write(data: [*]const u8, len: usize) void;
5-
//fn console_write(data:[*]const u8, len:usize) void {
6-
// std.log.info("{s}", .{data[0..len]});
5+
//
6+
//// Implement a std.io.Writer backed by console_write()
7+
//const ConsoleWriter = struct {
8+
// const Writer = std.io.Writer(
9+
// *ConsoleWriter,
10+
// error{},
11+
// write,
12+
// );
13+
//
14+
// fn write(
15+
// self: *ConsoleWriter,
16+
// data: []const u8,
17+
// ) error{}!usize {
18+
// _ = self;
19+
// console_write(data.ptr, data.len);
20+
// return data.len;
21+
// }
22+
//
23+
// pub fn writer(self: *ConsoleWriter) Writer {
24+
// return .{ .context = self };
25+
// }
26+
//};
27+
//
28+
//pub fn getWriter() *ConsoleWriter {
29+
// return &cw;
730
//}
831

9-
// Implement a std.io.Writer backed by console_write()
10-
const ConsoleWriter = struct {
11-
const Writer = std.io.Writer(
12-
*ConsoleWriter,
13-
error{},
14-
write,
15-
);
16-
17-
fn write(
18-
self: *ConsoleWriter,
19-
data: []const u8,
20-
) error{}!usize {
21-
_ = self;
22-
console_write(data.ptr, data.len);
23-
return data.len;
32+
var wbuf:[4096]u8 = undefined;
33+
var cw = ConsoleWriter.init(&wbuf);
34+
35+
pub const WriteError = error{ Unsupported, NotConnected };
36+
37+
pub const ConsoleWriter = struct {
38+
interface: std.Io.Writer,
39+
err: ?WriteError = null,
40+
41+
fn drain(w: *std.Io.Writer, data: []const []const u8, splat: usize) std.Io.Writer.Error!usize {
42+
var ret: usize = 0;
43+
44+
const b = w.buffered();
45+
_ = console_write(b.ptr, b.len);
46+
_ = w.consume(b.len);
47+
48+
for (data) |d| {
49+
_ = console_write(d.ptr, d.len);
50+
ret += d.len;
51+
}
52+
53+
const pattern = data[data.len - 1];
54+
for (0..splat) |_| {
55+
_ = console_write(pattern.ptr, pattern.len);
56+
ret += pattern.len;
57+
}
58+
59+
return ret;
2460
}
2561

26-
pub fn writer(self: *ConsoleWriter) Writer {
27-
return .{ .context = self };
62+
pub fn init(buf: []u8) ConsoleWriter {
63+
return ConsoleWriter{
64+
.interface = .{
65+
.buffer = buf,
66+
.vtable = &.{
67+
.drain = drain,
68+
},
69+
},
70+
};
2871
}
2972
};
3073

31-
pub fn getWriter() *ConsoleWriter {
32-
return &cw;
74+
pub fn getWriter() *std.Io.Writer {
75+
return &cw.interface;
3376
}
77+

src/mandelbrot/mandelbrot.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const std = @import("std");
2-
const console = @import("console.zig").getWriter().writer();
2+
const console = @import("console.zig").getWriter();
33

44
const WIDTH = 1200;
55
const HEIGHT = 800;
@@ -25,6 +25,7 @@ pub fn logFn(
2525
_ = message_level;
2626
_ = scope;
2727
_ = console.print(format, args) catch 0;
28+
_ = console.flush() catch 0;
2829
}
2930

3031
pub const std_options: std.Options = .{
@@ -34,11 +35,10 @@ pub const std_options: std.Options = .{
3435
pub fn panic(msg: []const u8, trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn {
3536
_ = ret_addr;
3637
_ = trace;
37-
_ = console.print("PANIC: {s}", .{msg}) catch 0;
38-
//while (true) {}
38+
_ = console.print("PANIC: {s}\n", .{msg}) catch 0;
39+
_ = console.flush() catch 0;
3940
unreachable;
4041
}
41-
4242
extern fn getTimeUs() u32;
4343

4444
pub fn millis() u32 {
@@ -161,6 +161,7 @@ var frameCount: usize = 0;
161161
fn printFPS() void {
162162
if (millis() > lastFPSTime + 1000) {
163163
_ = console.print("FPS {d}\n", .{frameCount / (millis() / 1000)}) catch 0;
164+
_ = console.flush() catch 0;
164165
lastFPSTime = millis();
165166
}
166167
frameCount +%= 1;

0 commit comments

Comments
 (0)