KickC BETA

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
Oziphantom
Posts: 774
Joined: Tue Feb 07, 2017 2:03 am

KickC BETA

Post by Oziphantom » Tue Apr 23, 2019 6:41 am

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

yaros
Posts: 145
Joined: Tue Aug 28, 2018 8:54 am
Location: Edmonton, Canada

Re: KickC BETA

Post by yaros » Tue Apr 23, 2019 10:59 am

I looked over the C documentation, I did not see support for banks that are often used for NES. Am I correct?

From my understanding, even if I compile two banks as separate binaries, I would have to extract and use hardcoded address to reference data/subroutines between the bank1 and bank2.

There is support of segments in the assembler itself[0] but I'm not sure how to use them in KickC.

[0] http://theweb.dk/KickAssembler/webhelp/ ... 10s02.html

supercat
Posts: 161
Joined: Thu Apr 18, 2019 9:13 am

Re: KickC BETA

Post by supercat » Tue Apr 23, 2019 1:05 pm

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

Code: Select all

    int wow[4] = { 0xCAFE, 0xBABE, 0x1234, 0x5678};
    int foo(unsigned char __abs x, int *__zp y)
    {
       return wow[x] + *y;
    }
could yield something like:

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
Nothing insanely complicated should be required to yield that kind of generated code once the proper declarations are in place.

Oziphantom
Posts: 774
Joined: Tue Feb 07, 2017 2:03 am

Re: KickC BETA

Post by Oziphantom » Wed Apr 24, 2019 1:49 am

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.

JesperGravgaard
Posts: 1
Joined: Fri Jul 05, 2019 1:41 pm

Re: KickC BETA

Post by JesperGravgaard » Fri Jul 05, 2019 3:08 pm

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.

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

Post Reply