// Example showing how to perform linking using a linker-file
// The linker file is created using KickAssembler segments.
// See the KickAssembler manual for description of the format http://theweb.dk/KickAssembler/
// Specifying the linker script file is done using the #pragma link(<file>)
// It can also be specified using kickc command line option -T <file>

#pragma link("xmega65.ld")

void main() {
    char i=0;
    while(true) {
        unsigned int fn = CALLS[i*2];
        void()* f = (void()*)fn;
        (*f)();
        if(++i==2) i=0;
    }
}

void fn1() {
    const char* BORDERCOL = $d020;
    (*BORDERCOL)++;
}

void fn2() {
    const char* BGCOL = $d021;
    (*BGCOL)++;
}

#pragma data_seg(Syscall)

const char JMP = 0x4c;
const char NOP = 0xea;

char[] SYSCALLS = {
    JMP, <&fn1, >&fn1, NOP,
    JMP, <&fn2, >&fn2, NOP,
    JMP, <&main, >&main, NOP
    };

const unsigned int* CALLS = (unsigned int*)(SYSCALLS+1);
