This question is about cc65, which is a toolkit including a C compiler, assembler, linker, etc. All targeting various 6502 computers, like the various 8 bit commodores, the Apple II and whatever else. In particular, I am using the cl65
command-line tool, which is a frontend to the compiler, to target the Commodore 64.
The thing is that this compiler depends very heavily on a library of little functions, that do simple things like push a 16-bit value onto a software stack (not the CPU stack!) or multiply two 16 bit values together. I am trying to get my program into a single, independent assembly, which does not rely on external subroutines.
Here is the contents of hello.c
:
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
}
Here is how I compile it:
cl65 -l hello.asm hello.c
Here is the contents of hello.asm
.
ca65 V2.13.9 - (C) Copyright 1998-2011 Ullrich von Bassewitz
Main file : hello.s
Current file: hello.s
000000r 1 ;
000000r 1 ; File generated by cc65 v 2.13.9
000000r 1 ;
000000r 1 .fopt compiler,"cc65 v 2.13.9"
000000r 1 .setcpu "6502"
000000r 1 .smart on
000000r 1 .autoimport on
000000r 1 .case on
000000r 1 .debuginfo off
000000r 1 .importzp sp, sreg, regsave, regbank
000000r 1 .importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
000000r 1 .macpack longbranch
000000r 1 .forceimport __STARTUP__
000000r 1 .import _printf
000000r 1 .export _main
000000r 1
000000r 1 .segment "RODATA"
000000r 1
000000r 1 L0003:
000000r 1 C8 45 4C 4C .byte $C8,$45,$4C,$4C,$4F,$2C,$20,$D7,$4F,$52,$4C,$44,$21,$0D,$00
000004r 1 4F 2C 20 D7
000008r 1 4F 52 4C 44
00000Fr 1
00000Fr 1 ; ---------------------------------------------------------------
00000Fr 1 ; int __near__ main (void)
00000Fr 1 ; ---------------------------------------------------------------
00000Fr 1
00000Fr 1 .segment "CODE"
000000r 1
000000r 1 .proc _main: near
000000r 1
000000r 1 .segment "CODE"
000000r 1
000000r 1 A9 rr lda #<(L0003)
000002r 1 A2 rr ldx #>(L0003)
000004r 1 20 rr rr jsr pushax
000007r 1 A0 02 ldy #$02
000009r 1 20 rr rr jsr _printf
00000Cr 1 60 rts
00000Dr 1
00000Dr 1 .endproc
00000Dr 1
00000Dr 1
You can see that this file includes references to things like pushax
and _printf
. This is only a simple example. tosmulax
and many others don't appear in this one. I was hoping to have these subroutines either inlined, or appended to the source, so that I end up with a file that can be independently assembled.
Is there a way to achieve this?