I never really spent time studying C and ASM.
So, a few weeks ago, I started my deep dive.
I started tinkering around ASM, understanding registers and flags, the stack pointer and the base pointer, the different operations (and their effect on different registers), syscalls, etc. I work a lot with the Rosetta Stone method (and LLM tbh). I write some simple programs, then compile them to see the objdump and understand how things can be done.
One night before going to sleep, my brain figured out almost all the low-level functioning of a snake. So I wrote some code to start a snake, but it (as expected) did not work on the first run, so I had to learn some bare fundamentals of gdb to debug an assembly program.
That was great time but I ended up slowly giving up on it, which is ok: toy projects are here to be learnt from.
A week or so after, I woke up with the idea of a snake who eats its own code, and that’s what I’ve been working on till now.
I chose to use C as it is on my bucket list since a while now. I did not want to bother raw-dogging a graphic lib just for a dumb snake, so I went for SDL because it looks pretty simple.
I first thought it would stay a little silly project so I planned to write it entirely in one file and to build it in wasm to display it here. I have done it as a POC and it is dead simple to compile C to wasm with Emscripten; I found it really more enjoyable than Rust. The text display is done using a font atlas at fixed height; it allows computing only once the few ASCII chars, then sampling directly from a texture.
It is a really interesting journey; I really enjoy C for its absolute tranquility. It is so pleasant to be able to intuit the machine code (without any obscure closed-source V8 engine interpreter that stores booleans in 64 bits) and to do whatever you want with it (without any absolutely ball-crushing borrow checker).
Turns out that I like this project so much that I decided to give it a try as a mid-long-term project. Shit’s getting semi-serious.