mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-23 23:32:55 +00:00
Working helloworld for XMega65 Xemu.
This commit is contained in:
parent
c82234db19
commit
7484e27a32
@ -4,36 +4,56 @@
|
||||
|
||||
#pragma link("xmega65.ld")
|
||||
|
||||
const char* VIC_MEMORY = 0xd018;
|
||||
const char* SCREEN = 0x0400;
|
||||
const char* COLS = 0xd800;
|
||||
const char WHITE = 1;
|
||||
|
||||
char[] MESSAGE = "hello world!";
|
||||
|
||||
void main() {
|
||||
char i=0;
|
||||
// Call SYSCALL functions one at a time
|
||||
// Initialize screen memory
|
||||
*VIC_MEMORY = 0x14;
|
||||
|
||||
// Print message in white
|
||||
char* sc = SCREEN;
|
||||
char* cols = COLS;
|
||||
for(char* msg = MESSAGE; *msg; msg++, sc++, cols++) {
|
||||
*sc = *msg;
|
||||
*cols = WHITE;
|
||||
}
|
||||
|
||||
// Loop forever
|
||||
while(true) {
|
||||
void()* fsyscall = FSYSCALLS[i*2];
|
||||
(*fsyscall)();
|
||||
if(++i==2) i=0;
|
||||
}
|
||||
}
|
||||
|
||||
void fn1() {
|
||||
void syscall1() {
|
||||
const char* BORDERCOL = $d020;
|
||||
(*BORDERCOL)++;
|
||||
}
|
||||
|
||||
void fn2() {
|
||||
void syscall2() {
|
||||
const char* BGCOL = $d021;
|
||||
(*BGCOL)++;
|
||||
}
|
||||
|
||||
#pragma data_seg(Syscall)
|
||||
|
||||
struct SysCall {
|
||||
char xjmp;
|
||||
void()* syscall;
|
||||
char xnop;
|
||||
};
|
||||
|
||||
const char JMP = 0x4c;
|
||||
const char NOP = 0xea;
|
||||
|
||||
export char[] SYSCALLS = {
|
||||
JMP, <&fn1, >&fn1, NOP,
|
||||
JMP, <&fn2, >&fn2, NOP
|
||||
export struct SysCall[] SYSCALLS = {
|
||||
{ JMP, &syscall1, NOP },
|
||||
{ JMP, &syscall2, NOP }
|
||||
};
|
||||
|
||||
export align(0x100) char[] SYSCALL_RESET = { JMP, <&main, >&main, NOP };
|
||||
|
||||
const void()** FSYSCALLS = (void()**)(SYSCALLS+1);
|
||||
export align(0x100) struct SysCall[] SYSCALL_RESET = {
|
||||
{ JMP, &main, NOP }
|
||||
};
|
||||
|
@ -8,46 +8,83 @@
|
||||
.segmentdef Data [startAfter="Code", min=$8200, max=$bdff]
|
||||
.segmentdef Stack [min=$be00, max=$beff, fill]
|
||||
.segmentdef Zeropage [min=$bf00, max=$bfff, fill]
|
||||
.label VIC_MEMORY = $d018
|
||||
.label SCREEN = $400
|
||||
.label COLS = $d800
|
||||
.const WHITE = 1
|
||||
.const JMP = $4c
|
||||
.const NOP = $ea
|
||||
.label FSYSCALLS = SYSCALLS+1
|
||||
.segment Code
|
||||
main: {
|
||||
.label fsyscall = 3
|
||||
.label i = 2
|
||||
.label msg = 2
|
||||
.label sc = 4
|
||||
.label cols = 6
|
||||
// Initialize screen memory
|
||||
lda #$14
|
||||
sta VIC_MEMORY
|
||||
lda #<COLS
|
||||
sta.z cols
|
||||
lda #>COLS
|
||||
sta.z cols+1
|
||||
lda #<SCREEN
|
||||
sta.z sc
|
||||
lda #>SCREEN
|
||||
sta.z sc+1
|
||||
lda #<MESSAGE
|
||||
sta.z msg
|
||||
lda #>MESSAGE
|
||||
sta.z msg+1
|
||||
b1:
|
||||
lda #0
|
||||
sta.z i
|
||||
// Call SYSCALL functions one at a time
|
||||
b2:
|
||||
lda.z i
|
||||
asl
|
||||
asl
|
||||
tay
|
||||
lda FSYSCALLS,y
|
||||
sta.z fsyscall
|
||||
lda FSYSCALLS+1,y
|
||||
sta.z fsyscall+1
|
||||
jsr bi_fsyscall
|
||||
inc.z i
|
||||
lda #2
|
||||
cmp.z i
|
||||
ldy #0
|
||||
lda (msg),y
|
||||
cmp #0
|
||||
bne b2
|
||||
b3:
|
||||
// Loop forever
|
||||
jmp b3
|
||||
b2:
|
||||
ldy #0
|
||||
lda (msg),y
|
||||
sta (sc),y
|
||||
lda #WHITE
|
||||
sta (cols),y
|
||||
inc.z msg
|
||||
bne !+
|
||||
inc.z msg+1
|
||||
!:
|
||||
inc.z sc
|
||||
bne !+
|
||||
inc.z sc+1
|
||||
!:
|
||||
inc.z cols
|
||||
bne !+
|
||||
inc.z cols+1
|
||||
!:
|
||||
jmp b1
|
||||
bi_fsyscall:
|
||||
jmp (fsyscall)
|
||||
}
|
||||
fn2: {
|
||||
syscall2: {
|
||||
.label BGCOL = $d021
|
||||
inc BGCOL
|
||||
rts
|
||||
}
|
||||
fn1: {
|
||||
syscall1: {
|
||||
.label BORDERCOL = $d020
|
||||
inc BORDERCOL
|
||||
rts
|
||||
}
|
||||
.segment Data
|
||||
MESSAGE: .text "hello world!"
|
||||
.byte 0
|
||||
.segment Syscall
|
||||
SYSCALLS: .byte JMP, <fn1, >fn1, NOP, JMP, <fn2, >fn2, NOP
|
||||
SYSCALLS:
|
||||
.byte JMP
|
||||
.word syscall1
|
||||
.byte NOP
|
||||
.byte JMP
|
||||
.word syscall2
|
||||
.byte NOP
|
||||
.align $100
|
||||
SYSCALL_RESET: .byte JMP, <main, >main, NOP
|
||||
SYSCALL_RESET:
|
||||
.byte JMP
|
||||
.word main
|
||||
.byte NOP
|
||||
|
@ -8,31 +8,33 @@
|
||||
@end: scope:[] from @1
|
||||
[3] phi()
|
||||
main: scope:[main] from @1
|
||||
[4] phi()
|
||||
[4] *((const byte*) VIC_MEMORY#0) ← (byte) $14
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@2 main::@3
|
||||
[5] (byte) main::i#3 ← phi( main/(byte) 0 main::@3/(byte) main::i#1 main::@2/(byte) 0 )
|
||||
to:main::@2
|
||||
main::@1: scope:[main] from main main::@2
|
||||
[5] (byte*) main::cols#2 ← phi( main/(const byte*) COLS#0 main::@2/(byte*) main::cols#1 )
|
||||
[5] (byte*) main::sc#2 ← phi( main/(const byte*) SCREEN#0 main::@2/(byte*) main::sc#1 )
|
||||
[5] (byte*) main::msg#2 ← phi( main/(const byte[]) MESSAGE#0 main::@2/(byte*) main::msg#1 )
|
||||
[6] if((byte) 0!=*((byte*) main::msg#2)) goto main::@2
|
||||
to:main::@3
|
||||
main::@3: scope:[main] from main::@1 main::@3
|
||||
[7] phi()
|
||||
to:main::@3
|
||||
main::@2: scope:[main] from main::@1
|
||||
[6] (byte~) main::$0 ← (byte) main::i#3 << (byte) 1
|
||||
[7] (byte~) main::$4 ← (byte~) main::$0 << (byte) 1
|
||||
[8] (void()*) main::fsyscall#0 ← *((const void()**) FSYSCALLS#0 + (byte~) main::$4)
|
||||
[9] call *((void()*) main::fsyscall#0)
|
||||
[10] (byte) main::i#1 ← ++ (byte) main::i#3
|
||||
[11] if((byte) main::i#1!=(byte) 2) goto main::@3
|
||||
[8] *((byte*) main::sc#2) ← *((byte*) main::msg#2)
|
||||
[9] *((byte*) main::cols#2) ← (const byte) WHITE#0
|
||||
[10] (byte*) main::msg#1 ← ++ (byte*) main::msg#2
|
||||
[11] (byte*) main::sc#1 ← ++ (byte*) main::sc#2
|
||||
[12] (byte*) main::cols#1 ← ++ (byte*) main::cols#2
|
||||
to:main::@1
|
||||
main::@3: scope:[main] from main::@2
|
||||
[12] phi()
|
||||
to:main::@1
|
||||
fn2: scope:[fn2] from
|
||||
[13] *((const byte*) fn2::BGCOL#0) ← ++ *((const byte*) fn2::BGCOL#0)
|
||||
to:fn2::@return
|
||||
fn2::@return: scope:[fn2] from fn2
|
||||
syscall2: scope:[syscall2] from
|
||||
[13] *((const byte*) syscall2::BGCOL#0) ← ++ *((const byte*) syscall2::BGCOL#0)
|
||||
to:syscall2::@return
|
||||
syscall2::@return: scope:[syscall2] from syscall2
|
||||
[14] return
|
||||
to:@return
|
||||
fn1: scope:[fn1] from
|
||||
[15] *((const byte*) fn1::BORDERCOL#0) ← ++ *((const byte*) fn1::BORDERCOL#0)
|
||||
to:fn1::@return
|
||||
fn1::@return: scope:[fn1] from fn1
|
||||
syscall1: scope:[syscall1] from
|
||||
[15] *((const byte*) syscall1::BORDERCOL#0) ← ++ *((const byte*) syscall1::BORDERCOL#0)
|
||||
to:syscall1::@return
|
||||
syscall1::@return: scope:[syscall1] from syscall1
|
||||
[16] return
|
||||
to:@return
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,37 +1,49 @@
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()**) FSYSCALLS
|
||||
(const void()**) FSYSCALLS#0 FSYSCALLS = (void()**)(const byte[]) SYSCALLS#0+(byte) 1
|
||||
(byte*) COLS
|
||||
(const byte*) COLS#0 COLS = (byte*) 55296
|
||||
(byte) JMP
|
||||
(const byte) JMP#0 JMP = (byte) $4c
|
||||
(byte[]) MESSAGE
|
||||
(const byte[]) MESSAGE#0 MESSAGE = (string) "hello world!"
|
||||
(byte) NOP
|
||||
(const byte) NOP#0 NOP = (byte) $ea
|
||||
(byte[]) SYSCALLS
|
||||
(const byte[]) SYSCALLS#0 SYSCALLS = { (const byte) JMP#0, <&(void()) fn1(), >&(void()) fn1(), (const byte) NOP#0, (const byte) JMP#0, <&(void()) fn2(), >&(void()) fn2(), (const byte) NOP#0 }
|
||||
(byte[]) SYSCALL_RESET
|
||||
(const byte[]) SYSCALL_RESET#0 SYSCALL_RESET = { (const byte) JMP#0, <&(void()) main(), >&(void()) main(), (const byte) NOP#0 }
|
||||
(void()) fn1()
|
||||
(label) fn1::@return
|
||||
(byte*) fn1::BORDERCOL
|
||||
(const byte*) fn1::BORDERCOL#0 BORDERCOL = (byte*) 53280
|
||||
(void()) fn2()
|
||||
(label) fn2::@return
|
||||
(byte*) fn2::BGCOL
|
||||
(const byte*) fn2::BGCOL#0 BGCOL = (byte*) 53281
|
||||
(byte*) SCREEN
|
||||
(const byte*) SCREEN#0 SCREEN = (byte*) 1024
|
||||
(struct SysCall[]) SYSCALLS
|
||||
(const struct SysCall[]) SYSCALLS#0 SYSCALLS = { { xjmp: (const byte) JMP#0, syscall: &(void()) syscall1(), xnop: (const byte) NOP#0 }, { xjmp: (const byte) JMP#0, syscall: &(void()) syscall2(), xnop: (const byte) NOP#0 } }
|
||||
(struct SysCall[]) SYSCALL_RESET
|
||||
(const struct SysCall[]) SYSCALL_RESET#0 SYSCALL_RESET = { { xjmp: (const byte) JMP#0, syscall: &(void()) main(), xnop: (const byte) NOP#0 } }
|
||||
(void()*) SysCall::syscall
|
||||
(byte) SysCall::xjmp
|
||||
(byte) SysCall::xnop
|
||||
(byte*) VIC_MEMORY
|
||||
(const byte*) VIC_MEMORY#0 VIC_MEMORY = (byte*) 53272
|
||||
(byte) WHITE
|
||||
(const byte) WHITE#0 WHITE = (byte) 1
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 202.0
|
||||
(byte~) main::$4 reg byte a 202.0
|
||||
(label) main::@1
|
||||
(label) main::@2
|
||||
(label) main::@3
|
||||
(void()*) main::fsyscall
|
||||
(void()*) main::fsyscall#0 fsyscall zp ZP_WORD:3 101.0
|
||||
(byte) main::i
|
||||
(byte) main::i#1 i zp ZP_BYTE:2 71.0
|
||||
(byte) main::i#3 i zp ZP_BYTE:2 42.599999999999994
|
||||
(byte*) main::cols
|
||||
(byte*) main::cols#1 cols zp ZP_WORD:6 22.0
|
||||
(byte*) main::cols#2 cols zp ZP_WORD:6 5.5
|
||||
(byte*) main::msg
|
||||
(byte*) main::msg#1 msg zp ZP_WORD:2 7.333333333333333
|
||||
(byte*) main::msg#2 msg zp ZP_WORD:2 11.0
|
||||
(byte*) main::sc
|
||||
(byte*) main::sc#1 sc zp ZP_WORD:4 11.0
|
||||
(byte*) main::sc#2 sc zp ZP_WORD:4 6.6000000000000005
|
||||
(void()) syscall1()
|
||||
(label) syscall1::@return
|
||||
(byte*) syscall1::BORDERCOL
|
||||
(const byte*) syscall1::BORDERCOL#0 BORDERCOL = (byte*) 53280
|
||||
(void()) syscall2()
|
||||
(label) syscall2::@return
|
||||
(byte*) syscall2::BGCOL
|
||||
(const byte*) syscall2::BGCOL#0 BGCOL = (byte*) 53281
|
||||
|
||||
zp ZP_BYTE:2 [ main::i#3 main::i#1 ]
|
||||
reg byte a [ main::$0 ]
|
||||
reg byte a [ main::$4 ]
|
||||
zp ZP_WORD:3 [ main::fsyscall#0 ]
|
||||
zp ZP_WORD:2 [ main::msg#2 main::msg#1 ]
|
||||
zp ZP_WORD:4 [ main::sc#2 main::sc#1 ]
|
||||
zp ZP_WORD:6 [ main::cols#2 main::cols#1 ]
|
||||
|
Loading…
Reference in New Issue
Block a user