Tonight, at roughly 8:30 PM Eastern, I'll be going live to continue work on my 6502 #emulator!
Come for the #Zig stay for the. . .Zig. :D
You can check out the progress so far on Codeberg: https://codeberg.org/b4ux1t3/zigsty-five-oh-two
THAT SAID. . .
I can't get #Zig's document generator to generate stuff for all of my zig files. Which, I guess, is fine, I know it's in preview, technically, but. . .ugh. It's SO CLOSE TO AWESOME.
Holy crap, #Zig documentation comments are awesome, too.
One of my favorite parts of the #DotNet ecosystem is the documentation system, where you get XMLdocs for free, and they have a first party tool for generating a docs web site.
For a while, though, I've been lamenting that weird HTML-based DSL from dotnet.
Not only do I not need to use another tool for Zig docs, I get to use MARKDOWN, like the gods intended.
Ooooooooooooh.
#Zig files are, themselves, structs.
This is awesome, and explains some of my confusion around namespacing and stuff.
Also: custom formatters for structs? So nice. Love the member accessing syntax.
Hot damn I haven't been this excited about a language in a few years.
Okay, Ziguanas, is this really the best we can do for "interfaces" in #Zig?
I can't think of another way to do it.
```zig
// The interface
pub const BusDevice = struct {
ptr: *anyopaque,
min_address: u16,
max_address: u16,
readFn: *const fn (ptr: *anyopaque, addr: u16) u8,
writeFn: *const fn (ptr: *anyopaque, addr: u16, value: u8) void,
fn read(self: BusDevice, addr: u16) u8 {
return self.readFn(self.ptr, addr);
}
fn write(self: BusDevice, addr: u16, value: u8) void {
self.writeFn(self.ptr, addr, value);
}
};
// The implementation
pub const Memory = struct {
min_address: u16,
max_address: u16,
physical_memory: []u8,
pub fn new(allocator: Allocator, min_address: u16, max_address: u16) !Memory {
const phys_mem = try allocator.alloc(u8, max_address - min_address);
for (phys_mem) |*address| {
address.* = 0;
}
return Memory{
.min_address = min_address,
.max_address = max_address,
.physical_memory = phys_mem,
};
}
pub fn write(self: *Memory, address: u16, value: u8) void {
self.physical_memory[address] = value;
}
pub fn read(self: *Memory, address: u16) u8 {
return self.physical_memory[address - self.min_address];
}
pub fn busDevice(self: *Memory) BusDevice {
return BusDevice{ .ptr = self, .min_address = self.min_address, .max_address = self.max_address, .readFn = self.read, .writeFn = self.write };
}
};
```
Going live! Rebuilding my 6502 #emulator in #Zig!
Come for the bad #CSharp, stay for the worse Zig!
#LiveCoding #RetroTech #RetroComputing
Slight plug: Support me on Ko-Fi! https://ko-fi.com/b4ux1t3
Okay, so, tonight's stream is going to be one of two things:
Me doing https://codeberg.org/ziglings/exercises
Or Me starting the porting of my 6502 #emulator to #Zig
I'm going to start with the latter, but if I run into any roadblocks I'm going to default to the former.
This will be a temporary thing, I'm just a little burned out on my C# projects right now and need something fresh.
If you'd like to support my shameless pursuance of useless programming language knowledge, head on over to https://twitch.tv/b4ux1t3 tonight at roughly 8:30 PM Eastern!
. . .
That's the end of the post, really. Just want to push the next bit below the fold.
. . .
On a more personal note, the proceeds from my channel are currently being put toward buying a new water heater. So, like, if you wanna help someone out for free, feel free to hop on the stream and leave it running in the background while you do much more important things like, I dunno, sleeping ;)
Additionally, I do have a neglected ko-fi account that I need to revamp: https://ko-fi.com/b4ux1t3
Generally the ko-fi is supposed to be for my kids' education, but we're making an exception since "hot water" is kind of important.
Thanks for reading below the fold. You are beautiful and worthy, and I hope you have a wonderful day.
#Zig is the language teenage me would have written if teenage me had been any good at writing languages.
It literally addresses all of the problems I had with C.
Well, so far.
So. . .if I print a pointer for an array in #Zig, I can see the whole array. If I print an individual value, I see the address (And datatype, which is cool).
Do arrays work significantly differently in zig from C? Like, i the pointer to the array the same as the pointer to the value, but the compiler is injecting some magic into the format string?
@sushee nice, I recently updated few days ago the #zig slackbuild script.
https://gitlab.com/slackware-brazil/slackbuilds/-/commit/6beeae327c8d582fc2d732187ddce7467622a8dd
crabtime [crates.io] is a procedural macro for writing macros that look like Rust code.
It reminds me of homoiconicity of lisp and the comptime feature in zig.
I'm gonna try a thing:
I've been letting a few projects languish for a while now. One of them is my 6502 emulator, which I ported from c++ to #CSharp a few years ago.
I kind of want to port it again, or maybe just reimplement it.
The top of my list is a real grab bag of languages:
I may just get some of the basic addressing logic done in each of them and see what sticks.
They're in rough order of "what I want to play with", though of all of them I have the most familiarity with rust. With Zig I have practically zero experience, and the other two sit somewhere in between.
The point here is not to start language wars, and I'll straight up mute anyone who tries, but I'd love to hear folks' thoughts.
If you want to make the case for another language, feel free to drop them in the replies! Really only looking for statically-compiled languages, and I'm not writing it in Java. ;)
Edit: Oh, and, boosts appreciated!
Lightpanda: A new browser built for machines https://lobste.rs/s/yt4vlb #ai #browsers #zig
https://lightpanda.io/
Practical #Data Oriented Design talk by Andrew Kelley — https://www.youtube.com/watch?v=IroPQ150F6c #youtube #video #programming #memory #zig #performance