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
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
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.