This weekly debrief is for paying supporters of my work. Please only read if you’ve paid. Thanks!
→ Click here if you've paid ←
I went away camping for a week, stressed out about uni a bit, and dug into writing some cool code for Bedrock.
Programming
I’ve started writing Bedrock code again, it’s been a long time since I last actually used the system. It’s so easy to get caught up in the high-level documentation/implementation/strategy stuff and forget the reason why you’re doing all of that in the first place. It’s just so much fun to use. I’ve been having a blast.
I’ve been working on building up a ‘standard library’ of functions that build on one another, functions that do things like printing a string or drawing a sprite or working with arrays. It’s the array stuff that I’m most excited about, I didn’t realise just how powerful they’d be and how much easier they’d make things. Lots of the cooler graphical demos I can think of all lean on arrays.
Working with arrays
The way they work is that you set aside a block of memory to hold a length byte (number of elements in the array), a stride byte (size of each element in the array), and then all of the array elements. Every function that works on arrays takes an address to this memory, and that’s it, the function handles all of the iteration and tricky stuff for you. I might need to change the length value from a byte to a double in the future. The stride value is stored as an exponent of two, so a stride of 1 is stored as 00 and a stride of 8 is stored as 03; this makes math a lot easier because I can use it to do bit-shifts.
This is a short program that applies a function to every element in an array, multiplying each element by 2. It uses stuff from the standard library, so you can’t run it in-browser yet, but you’ll be able to eventually. Cool stuff.
*:my-array *:multiply-by-two CALL:apply-array HLT @multiply-by-two ( addr* -- ) DUP* LDA* MUL2* SWP* STA* RETURN @my-array 04 STRIDE-02 0001 0002 0003 0004
The apply-array function performs both mapping and applying depending on which function you pass in, just because everything is mutable in Bedrock. There’s also a filter-array function where the function you pass in returns a truth byte that controls whether each element is kept or removed, and a basic reverse-array function.
Array demos
Have a look at the two programs below, they’re running live on the page. Give them a poke with your mouse or finger to make them do stuff. The pentagon one is 492 bytes and the hello one is 773 bytes, so they’re very very small.
The pentagon program stores the points of the pentagon as an array, converting between polar and rectangular coordinates using the math device so that I can easily spin and scale the whole shape. I wanted to make the shape be a bird or something sillier but I ran out of time.
The hello program stores the points of the curve as an array, using a apply-array-pairs function from the standard library to apply an apply-line function to each pair of neighbouring points. This apply-line function in turn applies a passed function to every point on a line, which in this example draws the coloured circles that form the curve. The colour changes after every few circles based on an incrementing counter, and the counter is in turn offset by the number of frames rendered to make the colours slide around the curve. Very cool stuff.
University
I’ve received my final results for the courses I took last semester, now I’m just waiting for an email to tell me whether my application to transfer into the engineering programme next semester has been successful. I should hear back by this Wednesday, since there’s only a week remaining until the semester starts. My chances are looking good, I earned three A+ grades and an A, but there are only thirty spots up for grabs. If I’m successful then I’ll get to do some electronics and programming courses next semester, which will be a lot of fun.
Thanks
Thanks for your support on these projects, it’s cool to finally have something visual to show for once. Have a great week!