2020-04-28 20:19

I started building a little computer this week. The idea/constraint is: what if we built a late-70s-early-80s-style 8-bit computer in 2020

This pic is extremely early, mostly just getting a toolchain and workflow into place

2020-05-03 21:16

While I wait for some parts to arrive, I’ve been working on the BASIC interpreter, and have gained an appreciation for the people writing firmware back in the 70s, often without actual hardware. I’ve got it easy!

(check out @adventofcomp for these stories, its a great listen)

2020-05-04 14:22

The 2s pause tells you that this is successfully running its first BASIC program:

10 ON 20 SLEEP 30 OFF 40 SLEEP 50 GOTO 10

2020-05-08 21:40

usb serial doober was delivered to the office, so I went and picked it up last night. this evening, wired up, wrote some string handling code, and hello there!

2020-05-09 00:02

a decent evening of work and I have a working input look and a nice hex dumper. type things, hit enter, get the contents of the input buffer back (you can see the ASCII codes right there)

2020-05-09 14:35

ASCII number string -> actual value parser is working nicely. Will be used for BASIC line numbers and I guess some math stuff. 16 bits should be enough for anyone.

2020-05-12 21:55

nothing of note to show, but

  1. couch dev rig is awkward but workable
  2. I bought some new LEDs and holy shit they’re bright

2020-05-13 15:28

wrote half the statement parser last night, then got cranky at the assembler, found a different one, papered over a couple of bugs, and then finished the parser. here’s statement->opcode mapping. by modern standards of string lookups its bloody awful 😎️

2020-05-14 13:13

new toy! existing PL2303 serial bridge (top) is apparently a sketchy knock-off chip, and quite unstable (starts dropping frames after a while and needs reset). New is a CH340 breakout, which have a much better track record. will add a pin header and make go this afternoon!

2020-05-14 15:17

extremely boring

2020-05-15 17:50

wrote an error handler. anywhere, anytime, stick the error code in r25 and return, and the mainloop will print something nice. there’s a reason unix has a global errno and you just check it and bail out if you see it set: it’s the cheapest and easiest way to do it

2020-05-15 21:35

ahaha immediate mode is working for simple (no args) statements this is rad

2020-05-17 22:28

yes friends, that is a STORED PROGRAM COMPUTER (and yes I am just a little bit excited)

2020-05-18 14:23

adding small niceties like handling whitespace and runtime errors while avoiding writing the expression parser

2020-05-19 13:23

here’s program storage and memory management in action. the program is an array of variable-length data sequences: one byte of length, two bytes of line number, 1+ bytes of opcode and args. they remain sorted by line number; insertions move the whole program up in memory

2020-05-19 13:32

removing a line closes the gap, replacing a line adjusts the existing gap. the relative expense of moving the entire program space around sucks, but a true linked list is harder to code and uses more memory. the common case of append is fast though, no moves required!

2020-05-20 15:24

expression parser is in! converts infix→postfix for the four basic operations and parens. operands get prefixed with a “type”, which will allow variable lookups and functions to just work in the evaluator (which doesn’t exist yet heh 🤷‍♂️)

the entire parser is 89 instructions 😎

2020-05-21 11:31

alright, there’s the first cut expression evaluator, and I’ve got myself a little calculator. alas, I forgot that numbers less than zero exist

2020-05-22 16:27

a day later, and I think we’ve got full 16-bit signed math going. uncovered a bunch of bugs along the way, not least of which was total confusion ‘-’ as minus and ‘-’ as negation. just a couple more edge cases to smooth out and then we can move on to the next thing!

2020-05-22 23:29

solid evening! visit a friend, have a few glasses of wine, get home and still a enough time to drop in some sneaky string support and write the classic BASIC starter program

2020-05-23 23:41

variables! we’re almost at the point where you could write a useful program with this thing!

2020-05-23 23:46

omg I typed in a program from a programming book and it work ahahahaha I’m living the dream

2020-05-25 00:42

huge day: added subroutines (GOSUB/RETURN), conditionals (IF/THEN) and user input (uh, INPUT). put it all together, and here’s our first actual useful(-ish) program: factorial calculator, via recursion

2020-05-25 20:59

lets print and input multiple things! BASIC’s separators are kinda bonkers

2020-05-25 22:54

lots of loose ends tidied. can now replace and delete existing lines, NEW and CLEAR work. can’t put it off any longer: this most trivial of programs is gonna need string variable support, so that’s next. oof.

2020-05-30 17:13

several days later, and a usable amount of string variables is in. it got kinda bonkers, mainly around memory management for variable storage (strings don’t fit in registers!) and tracking separate types. still some kinks to sort out but I think the shapes are mostly right

2020-05-31 20:06

space monsters, Xtra good

2020-06-01 22:52

string comparisons

originally posted on twitter at: