Hacker News new | ask | show | jobs
by mlang23 1727 days ago
A rust port for the gameboy, that would have been impressive...
3 comments

There's some ongoing work on a LLVM whole-program backend for the MOS 6502, which can already compile some Rust code (discussed https://news.ycombinator.com/item?id=28581812 ). If that's successful (it does require lots of new optimization passes to match the effectiveness of hand-written code), it would be quite easy to have a backend for the Z80 as well.
A Z80 backend could probably reuse our static stack allocation, but that's about it. It's definitely useful, but the time-consuming part of writing LLVM-MOS's code generator has ended up being... writing LLVM-MOS's code generator. The static stack stuff is maybe like 250 lines of code, and I haven't had to touch it in months.
There is a rust port for the game boy advance https://github.com/rust-console/gba
there's only a barely working, undocumented backend for LLVM on the z80.

You could probably do this with mrustc.

You could, but given that even C and Pascal hardly take advantage of Z80, and have to be used as some kind of fancy macro Assembler, better just deal with Z80 Assembly directly.

But then I am biased, having the Z80 opcodes burned in my brain due to the Speccy days.

I believe it also tosses everything on the stack which is certainly not optimal for the z80
The Game Boy doesn't use a Z80 though. It's based on a SM83 core, an obscure Sharp design.
It's essentially a stripped Z80 without the DD-, ED- and FD-prefix instruction ranges. The core instruction block and CB-prefix range is (nearly) the same.
See the other responses, but my comment was really suggesting that if LLVM barely supports Z80 then the GameBoy CPU is a hopeless lost cause.
True, but the instruction set is very close, so a Z80 implementation is a good starting point.