LLVM-MOS is a new C -> 6502 compiler (and maybe C++, and Rust some day?) #6502 #Compiler #LLVM #VintageComputing #RetroCoding

https://8bitworkshop.com/docs/posts/2023/llvm-mos-sdk-6502-c-compiler.html

Exploring the New 6502 Compiler Based on LLVM

Today, homebrew developers enjoy the convenience of programming the 6502 in C. However, the 6502 is a very different architecture than modern CPUs, and was never designed for C programming. The 650...

8bitworkshop
Got the "Up, Up and Away" sprite test working -- reduced from 834 bytes (cc65) to 686 bytes (llvm-mos) but performance was about the same. Must be some missed optimization opportunity, but LLVM moves things around so much I don't know where yet :)

This might be one of the culprits. CPX #0? Who does that? :)

Anyway, CC65 is clever enough to do this shift (msb |= 1 << t) with an ASL / DEY / BPL loop, correctly deducing that it can ignore the upper 8 bits because the result eventually goes into a byte variable.

I changed it to use a lookup table, but then the program crashed. I was about to blame the compiler, but couldn't find anything wrong.

The IDE simulates typing a SYS command on the emulated keyboard to start a C64 PRG file. It was supposed to type "SYS 2133", but it only produced "SYS 213". This never came up before, because CC65 always starts at SYS 2061.

I tracked it down to the C64 emulator's "sticky counter" which keeps keypresses around a littler longer, so the BIOS has more time to scan them. So I had to call machine_exec() twice to de-stickify the key.

The moral of the story is: Sometimes the compiler is wrong, and sometimes you're wrong.

@8bitworkshop i'm actually looking for a basic->6502 as neat as Boriel's ZX-Basic Compiler is for z80...