Lurker News
Release early, release often. Don't worry, be crappy. Fail fast. Iterate.

Show us your half baked, not really ready for prime time projects.
Also, if you need any help with a project, a startup, or an idea, just post it here.

Comments (820) 521 threads

Show all comments

Showing thread 43 of 521

mysterymath1 reply#
I'm porting LLVM/Clang to the 6502. Notoriously difficult project, attempted dozens of times by as many folks.

https://github.com/mysterymath/clang6502
My take generates pretty darn good assembly for the cases it handles, but it's absurdly incomplete. Still, a huge amount of risk factors have already been addressed, and there's only a few big known unknowns left.
Example input:

  void print_int(char x) {
    if (x < 10) {
      x += '0';
      asm volatile ("JSR\t$FFD2" : "+a"(x));
      return;
    }
    print_int(x / 10);
    print_int(x % 10);
  }
Example output:

  .code
  .global print__int                      ; -- Begin function print_int
  print__int:                             ; @print_int
  ; %bb.0:                                ; %entry
    CMP #10
    BMI LBB0__2
  ; %bb.1:                                ; %if.end.preheader
    LDX #10
    PHA                                     ; 1-byte Folded Spill
    JSR ____udivqi3
    JSR print__int
    PLA                                     ; 1-byte Folded Reload
    LDX #10
    JSR ____umodqi3
  LBB0__2:                                ; %if.then
    CLC
    ADC #48
    ;APP
    JSR $FFD2
    ;NO_APP
    RTS
                                        ; -- End function
  .global ____udivqi3
  .global ____umodqi3
rzzzt1 reply#
OMF:2097 profile picture spotted! Loved the game as a child.

Will the compiler support 65C02 instructions?

mysterymath#
Shouldn't be too hard to add later, since they're mostly just swizzles onto the existing instructions, and LLVM already has good support for registering slightly different versions of a target (subtargeting).

For now, I'm targeting the plain-jane MOS chip, since it's the buggiest and least capable, and thus the most difficult.