People here seem to enjoy using C to make 6502 content, so this might be of interest. Camelot have released a new KickC which is a slight variant of C rather than ANSI C to help with optimizing 6502 code
https://csdb.dk/release/?id=176985
It is a pre pass system, similar to my MLA, so it generates a Kick Assembler file for you to then assemble using Kick Assembler http://theweb.dk/KickAssembler/Main.html#frontpage
KickC BETA
Moderator: Moderators
Re: KickC BETA
Developers of compilers for the 6502 could benefit from seeing how Keil's compiler for the 8051 handled the quirks of that architecture. Perhaps most importantly, automatic objects are statically overlaid so that they behave like automatic variables except that recursion is not allowed, and qualifiers can place objects in either fast storage (which is limited to about 120 bytes on that platform) or larger storage areas. If one adds qualifiers for integer arrays whose address will never be taken and whose size will be known even on extern declarations, something like:Oziphantom wrote:People here seem to enjoy using C to make 6502 content, so this might be of interest. Camelot have released a new KickC which is a slight variant of C rather than ANSI C to help with optimizing 6502 code
Code: Select all
int wow[4] = { 0xCAFE, 0xBABE, 0x1234, 0x5678};
int foo(unsigned char __abs x, int *__zp y)
{
return wow[x] + *y;
}
Code: Select all
.function foo 2,1 ; Uses two bytes of automatic objects in ZP; 1 in non-ZP storae
foo:
ldx ?foo_abs+0
lda __lo_wow,x
clc
ldy #0
adc (?foo_zp+0),y
sta __retval
lda __hi_wow,x
iny
adc (?foo_zp+0),y
sta __retval+1
rts
__lo_wow: .byte $FE, $BE, $34, $78
__hi_wow: .byte $CA, $BA, $12, $56
-
- Posts: 1565
- Joined: Tue Feb 07, 2017 2:03 am
Re: KickC BETA
I've not looked at in depth, however you don't have to live with its hardcoded offsets. It does not make a binary file, it makes KickAssembler .asm files. So you are able to put them in segments etc as you please. The C code won't automatically handle the bank switching for you though, so you will probably need to add it by hand, with inline asm.
-
- Posts: 15
- Joined: Fri Jul 05, 2019 1:41 pm
Re: KickC BETA
Hi there,
I am the author of KickC.
The ASM generated by the KickC-compiler for supercat's foo()-function example is pretty similar to what you are hoping for. Here it is copied straight from the compiler output.
If you are interested in coding 6502 using a C-family language that produces efficient ASM have a look at KickC https://gitlab.com/camelot/kickc
Kind regards,
Jesper Gravgaard
Rex/Camelot
I am the author of KickC.
The ASM generated by the KickC-compiler for supercat's foo()-function example is pretty similar to what you are hoping for. Here it is copied straight from the compiler output.
Code: Select all
// foo(byte register(X) x, signed word* zeropage(2) y)
foo: {
.label return = 2
.label y = 2
txa
asl
tax
clc
ldy #0
lda wow,x
adc (return),y
pha
iny
lda wow+1,x
adc (return),y
sta return+1
pla
sta return
rts
}
wow: .word $cafe, $babe, $1234, $5678
Kind regards,
Jesper Gravgaard
Rex/Camelot