Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I grew up in the 2000s: No assembly hacking for me. And even if you learn assembly, you're essentially just doing a C compiler's job.

...Which is why I'm building a Z80 machine. It won't be complicated (no monitor, just a DB9 cable connected to a Z19 (and yes, I have a Z19: my father's actually)), but it will be programmable from the ground up. It will be something that I can learn from.

But no way am I implementing BASIC. Sorry, it's complicated and not actually all that good a language. So I'm implementing FORTH. Simpler, and the stack might be a pain, but I'll learn something from that, too.



I wrote a Basic interpreter once (for Infocom's Z-machine). Holy cow, that's an ugly language to parse. It's all ad-hoc rules and heuristics and endless weird edge cases. It just wasn't fun.

Forth's a good choice, and will teach you lots of assembly, but it's not really a compiler, and Z80 Forth's been done to death.

But... and I should point out that where I am it's half past midnight and I'm going weird and random... if you want an off-the-wall but useful language to do an actual compiler for, you might want to check out B. It's like a typeless simplified C (although it's really the other way round), and is eminently suited to tiny architectures.

Tiny example:

http://www.99-bottles-of-beer.net/language-b-1247.html

x86 B compiler written in C, containing links to the language reference:

https://github.com/aap/abc


>Forth's a good choice, and will teach you lots of assembly, but it's not really a compiler, and Z80 Forth's been done to death.

The Z80 itself's been done to death. If I wanted to go super far off the beaten path, I'd build a 6809 computer (something I actually do want to do, but it's hard to get 6809s). But this is good, because I can base it largely on other's designs, which helps me get to the software bit faster (which is the part that actually excites me), although I will have to make some modifications. This is also good because I suck at electronics. Hopefully, I may suck a bit less by the time this project is done, but that's not the point, really.

But yes, a B compiler might be fun. I'm sure I can at least take it as far as assembler. Mind, it will probably suck, but I'm fairly confident I can make it work.

Provided, of course, that I put in the effort, which isn't a given: a lot of what I set out to do doesn't happen, because I got distracted by something else. The comparison to Leonard of Quirm is obvious, but unfair: he's a genius, and fictional: I'm real, and no genius, just easily distractable.


Yes, fair enough; you should do what you want to do, not what I say you should do. But I like compilers, so... (And the B compiler is beautifully simple and is probably really easy to port.)

Re Forth, you might be interested in this:

http://fruttenboel.verhoeven272.nl/Langs/ace.html

It's an annotated disassembly of the Jupiter Ace ROM; the Ace was a ZX80-like Z80 machine which was unique among the 8-bit computers in that it had Forth in ROM rather than Basic. It's a beautiful implementation, and includes everything from keyboard mapping to the character generator to an interactive Forth sort-of-IDE.

Also, there's no modern 6809 variant? There ain't no justice.


Thanks for the tip on that!

As for the 6809, it was out of production for a while. But allegedly, Rochester Electronics is making new ones now. They even seem to have them, if you look on their site. However, they won't sell them to you.


You can get used pulls from Jameco, Unicorn Electronics or eBay.

AFTER you finish your z80 thing, of course.


Oh, and the RS08 and 68HCxx are the modern 6809 offshoots, and they're still in production, but they're not quite the same as the 6809, and the 68HCxx's days may be numbered.


Oh. Thanks.

But neither of them really scratch the 6809 itch: They're closer to the 6800 and the 6502, whereas the 6809 was closer to m68k.


A few years back I too built my own Z80 based machine, and considered FORTH, but ended up writing a LISP-like language for it, including (very primitive) turtle graphics. You could do things like:

  (define (square n)
    (repeat 4 (fd n) (rt 90))
  )
  (square 50)


I could never do this. Because I would want a real Lisp. And that means things like GC.

Do you want to implement GC in 64k?

Also, I don't know compilers super well. And you have to know compilers to actually write an efficient lisp. I plan on learning that, at some point, but while I'm also writing an OS (or at least a monitor) for a Z80? Nope, forth it is.


Yes, my LISP(-like) did have a primitive GC.

The heap consisted of fixed 4-byte cons cells (2 byte car, 2 byte cdr). The cdr value was assumed to always be a pointer, which meant that since the cells were aligned at a 4-byte boundary, I had a few spare bits to implement mark-and-sweep GC and track which data type the car value was (number, atom, list or function).

Edit: I got curious and dug up the code. The entire GC code is less than 100 lines of Z80 assembler (admittedly some of the hairiest code in the interpreter, though)


Huh. Not so bad after all. Ah well.

The other problem becomes space efficiency, but that's not unsolvable.


> Do you want to implement GC in 64k?

Why not? The IBM 704 had around 18k and yet it was good enough for a full Lisp system.

Sometimes I think that people don't really grasp how constrained the computers using Lisp, Smalltalk and memory safe systems programming languages were and yet those systems were already there running, being used to doing actual work.

Somehow C's adoption has created a strange distortion of what those computers were actually capable of, in spite of their resource constraints.


Yeah, but the 704 was a 36-bit machine, and was otherwise well-suited to the task.

Still, I might give it a shot. Once I get the damn thing working, that is.


Those BASICs have GC in <= 64K. (Well, for just character strings.)

How about that IBM 704 from which we have the terms CAR and CDR?

"The 737 Magnetic Core Storage Unit had 4,096 36-bit words, the equivalent of 18,432 bytes and served as RAM."

[Wikipedia]


I didn't say it was impossible. But do you want to implement it?

Besides, the 704 had some helpful features the micros didn't. Also, it was a 36-bit machine. That's a massive advantage.


If I could relive the 80-s, that might be something I would work on.


There actually was a Z80-based computer with built-in FORTH rather than BASIC -- the Jupiter Ace (1982). It was just too weird for the general public, though and didn't do very well.

https://en.wikipedia.org/wiki/Jupiter_Ace


I know. There's even instructions for how to build one online (http://searle.hostei.com/grant/JupiterAce/JupiterAce.html, the very site that I used as a basis for my design, no less) But that has (gasp!) a screen, and while I could no doubt program it (with some trial and error, because I suck), I very much doubt I could actually build it. Maybe if this design works (dubious, but perhaps eventually), I'll give it a shot.


I agree with you. I so wish that the microcomputer culture was based on Forth rather than BASIC. BASIC is a terrible language, but people do like it more than Forth for some weird reason.

(I started on ZX Spectrum in late 80s. If it had Forth, it could fit twice as much stuff into its ROM than it actually did.)

But, we live in a world where Javascript is having Haskell for a dinner. So I am not really sure why I am surprised.

(On the other hand, at least Python is a decent language, even though Lisp should have won in that particular space.)


In case you haven't seen it, Factor is a modern FORTH-like language:

http://factorcode.org/

Funnily enough the most I've ever played with FORTH was inside of Minecraft on an in-world computer:

http://technicpack.wikia.com/wiki/Forth_language


I am aware of Factor, although I believe that conceptually, FORTH can only work in small systems. In a larger system, you can afford yourself something like Haskell (or at least Lisp) and the extensibility and proximity to hardware of FORTH will diminish in value, while the disadvantages will remain. In other words, with a bigger machine, you can go with more abstract language (distancing from hardware but keeping the extensibility), because the compiler/interpreter can be made more powerful.

I also played with FORTH mostly in Minecraft Redpower 2 (but before that I also read Jones Forth, which is excellent), unfortunately, to prove my original point, people didn't like it and longed for BASIC.


Ah, RP2. On of the finest mods that ever came out of the fantastic modding scene around Minecraft. It was one of the four foundational mods in the scene: BuildCraft, IndustrialCraft (and later IC2), Better Than Wolves, and RedPower2.

Sadly, RP2 is dead, and with it the RP2 computer model, the likes of which will likely never be seen again (for those not in the know: most mincraft mods adding computers of some sort essentially allow scripting in some HLL, and maybe a primitive DOS-style prompt, akin to ComputerCraft. Not so in RP2. RP2 computers were actually full emulated 6502s, with a FORTH monitor built in (although you could, of course, write your own). This should give you an idea of what made RP2 so special). Except not quite, because Eloraam is now working on RP3, which will actually be its own game, because she got sick of putting up with MC's limitations. Knowing Eloraam, it will be done by 2030.


Related to RedPower: OpenComputers. While it does come with Lua as the default OS / platform but it has support for arbritary computing architectures - both real and fake. I'm not sure if any has matured to the point of RP2 though (I know someome at least attempted a 6502 architecture at: https://github.com/gamax92/ocsymon)


Forth is still used in places like the bootstrap of FreeBSD 11.

* https://github.com/freebsd/freebsd/tree/release/11.0.1/sys/b...

Some people want to replace this with Lua.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: