1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-14 23:04:57 +00:00

Added KC-based scroller

This commit is contained in:
jespergravgaard 2017-10-19 01:29:44 +02:00
parent 7be265f42c
commit 5a4388d6d3
6 changed files with 5480 additions and 0 deletions

View File

@ -24,6 +24,10 @@ public class TestCompilationOutput extends TestCase {
helper = new ReferenceHelper("dk/camelot64/kickc/test/ref/");
}
public void testScroll() throws IOException, URISyntaxException {
compileAndCompare("scroll");
}
public void testConstantMin() throws IOException, URISyntaxException {
compileAndCompare("constantmin");
}

View File

@ -0,0 +1,88 @@
.const SCREEN = $400
.const RASTER = $d012
.const BGCOL = $d020
.const SCROLL = $d016
TEXT: .text "this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. "
STOP: .byte 0
jsr main
main: {
.const line = SCREEN+$28
.label nxt = 2
jsr fillscreen
lda #<TEXT
sta nxt
lda #>TEXT
sta nxt+1
ldx #7
b2:
lda RASTER
cmp #$fe
bne b2
b3:
lda RASTER
cmp #$ff
bne b3
lda BGCOL
clc
adc #1
sta BGCOL
dex
cpx #$ff
bne b4
ldx #0
b5:
lda line+1,x
sta line,x
inx
cpx #$27
bne b5
ldy #0
lda (nxt),y
cmp #0
bne b6
lda #<TEXT
sta nxt
lda #>TEXT
sta nxt+1
lda TEXT
b6:
sta line+$27
inc nxt
bne !+
inc nxt+1
!:
ldx #7
b4:
stx SCROLL
lda BGCOL
sec
sbc #1
sta BGCOL
jmp b2
rts
}
fillscreen: {
.const fill = $20
.label cursor = 2
lda #<SCREEN
sta cursor
lda #>SCREEN
sta cursor+1
b1:
ldy #0
lda #fill
sta (cursor),y
inc cursor
bne !+
inc cursor+1
!:
lda cursor+1
cmp #>SCREEN+$3e8
bcc b1
bne !+
lda cursor
cmp #<SCREEN+$3e8
bcc b1
!:
rts
}

View File

@ -0,0 +1,69 @@
@begin: scope:[] from
[0] call main param-assignment [ ]
to:@end
@end: scope:[] from @begin
main: scope:[main] from @begin
[1] phi() [ ]
[2] call fillscreen param-assignment [ ]
to:main::@2
main::@2: scope:[main] from main main::@2 main::@4
[3] (byte*) main::nxt#3 ← phi( main::@4/(byte*) main::nxt#10 main/(const byte*) TEXT#0 ) [ main::scroll#3 main::nxt#3 ]
[3] (byte) main::scroll#3 ← phi( main::@4/(byte) main::scroll#10 main/(byte) 7 ) [ main::scroll#3 main::nxt#3 ]
[4] (byte~) main::$2 ← * (const byte*) RASTER#0 [ main::scroll#3 main::nxt#3 main::$2 ]
[5] if((byte~) main::$2!=(byte) 254) goto main::@2 [ main::scroll#3 main::nxt#3 ]
to:main::@3
main::@3: scope:[main] from main::@2 main::@3
[6] (byte~) main::$4 ← * (const byte*) RASTER#0 [ main::scroll#3 main::nxt#3 main::$4 ]
[7] if((byte~) main::$4!=(byte) 255) goto main::@3 [ main::scroll#3 main::nxt#3 ]
to:main::@8
main::@8: scope:[main] from main::@3
[8] (byte~) main::$6 ← * (const byte*) BGCOL#0 [ main::scroll#3 main::nxt#3 main::$6 ]
[9] (byte~) main::$7 ← (byte~) main::$6 + (byte) 1 [ main::scroll#3 main::nxt#3 main::$7 ]
[10] *((const byte*) BGCOL#0) ← (byte~) main::$7 [ main::scroll#3 main::nxt#3 ]
[11] (byte) main::scroll#1 ← -- (byte) main::scroll#3 [ main::nxt#3 main::scroll#1 ]
[12] if((byte) main::scroll#1!=(byte) 255) goto main::@4 [ main::nxt#3 main::scroll#1 ]
to:main::@5
main::@5: scope:[main] from main::@5 main::@8
[13] (byte) main::i#2 ← phi( main::@5/(byte) main::i#1 main::@8/(byte) 0 ) [ main::nxt#3 main::i#2 ]
[14] (byte~) main::$11 ← (const byte[]) main::line#0+(byte) 1 *idx (byte) main::i#2 [ main::nxt#3 main::i#2 main::$11 ]
[15] *((const byte[]) main::line#0 + (byte) main::i#2) ← (byte~) main::$11 [ main::nxt#3 main::i#2 ]
[16] (byte) main::i#1 ← ++ (byte) main::i#2 [ main::nxt#3 main::i#1 ]
[17] if((byte) main::i#1!=(byte) 39) goto main::@5 [ main::nxt#3 main::i#1 ]
to:main::@10
main::@10: scope:[main] from main::@5
[18] (byte) main::c#0 ← * (byte*) main::nxt#3 [ main::nxt#3 main::c#0 ]
[19] if((byte) main::c#0!=(byte) 0) goto main::@6 [ main::nxt#3 main::c#0 ]
to:main::@11
main::@11: scope:[main] from main::@10
[20] (byte) main::c#1 ← * (const byte*) TEXT#0 [ main::c#1 ]
to:main::@6
main::@6: scope:[main] from main::@10 main::@11
[21] (byte*) main::nxt#4 ← phi( main::@10/(byte*) main::nxt#3 main::@11/(const byte*) TEXT#0 ) [ main::c#2 main::nxt#4 ]
[21] (byte) main::c#2 ← phi( main::@10/(byte) main::c#0 main::@11/(byte) main::c#1 ) [ main::c#2 main::nxt#4 ]
[22] *((const byte[]) main::line#0+(byte) 39) ← (byte) main::c#2 [ main::nxt#4 ]
[23] (byte*) main::nxt#1 ← ++ (byte*) main::nxt#4 [ main::nxt#1 ]
to:main::@4
main::@4: scope:[main] from main::@6 main::@8
[24] (byte*) main::nxt#10 ← phi( main::@6/(byte*) main::nxt#1 main::@8/(byte*) main::nxt#3 ) [ main::scroll#10 main::nxt#10 ]
[24] (byte) main::scroll#10 ← phi( main::@6/(byte) 7 main::@8/(byte) main::scroll#1 ) [ main::scroll#10 main::nxt#10 ]
[25] *((const byte*) SCROLL#0) ← (byte) main::scroll#10 [ main::scroll#10 main::nxt#10 ]
[26] (byte~) main::$17 ← * (const byte*) BGCOL#0 [ main::scroll#10 main::nxt#10 main::$17 ]
[27] (byte~) main::$18 ← (byte~) main::$17 - (byte) 1 [ main::scroll#10 main::nxt#10 main::$18 ]
[28] *((const byte*) BGCOL#0) ← (byte~) main::$18 [ main::scroll#10 main::nxt#10 ]
[29] if(true) goto main::@2 [ main::scroll#10 main::nxt#10 ]
to:main::@return
main::@return: scope:[main] from main::@4
[30] return [ ]
to:@return
fillscreen: scope:[fillscreen] from main
[31] phi() [ ]
to:fillscreen::@1
fillscreen::@1: scope:[fillscreen] from fillscreen fillscreen::@1
[32] (byte*) fillscreen::cursor#2 ← phi( fillscreen/(const byte*) SCREEN#0 fillscreen::@1/(byte*) fillscreen::cursor#1 ) [ fillscreen::cursor#2 ]
[33] *((byte*) fillscreen::cursor#2) ← (const byte) fillscreen::fill#0 [ fillscreen::cursor#2 ]
[34] (byte*) fillscreen::cursor#1 ← ++ (byte*) fillscreen::cursor#2 [ fillscreen::cursor#1 ]
[35] if((byte*) fillscreen::cursor#1<(const byte*) SCREEN#0+(word) 1000) goto fillscreen::@1 [ fillscreen::cursor#1 ]
to:fillscreen::@return
fillscreen::@return: scope:[fillscreen] from fillscreen::@1
[36] return [ ]
to:@return

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
(label) @begin
(label) @end
(byte*) BGCOL
(const byte*) BGCOL#0 BGCOL = (word) 53280
(byte*) RASTER
(const byte*) RASTER#0 RASTER = (word) 53266
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (word) 1024
(byte*) SCROLL
(const byte*) SCROLL#0 SCROLL = (word) 53270
(byte[]) STOP
(const byte[]) STOP#0 STOP = { (byte) 0 }
(byte*) TEXT
(const byte*) TEXT#0 TEXT = (string) "this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. "
(void()) fillscreen((byte*) fillscreen::screen , (byte) fillscreen::fill)
(label) fillscreen::@1
(label) fillscreen::@return
(byte*) fillscreen::cursor
(byte*) fillscreen::cursor#1 cursor zp ZP_PTR_BYTE:2 16.5
(byte*) fillscreen::cursor#2 cursor zp ZP_PTR_BYTE:2 16.5
(byte) fillscreen::fill
(const byte) fillscreen::fill#0 fill = (byte) 32
(byte*) fillscreen::screen
(void()) main()
(byte~) main::$11 reg byte a 202.0
(byte~) main::$17 reg byte a 22.0
(byte~) main::$18 reg byte a 22.0
(byte~) main::$2 reg byte a 202.0
(byte~) main::$4 reg byte a 202.0
(byte~) main::$6 reg byte a 22.0
(byte~) main::$7 reg byte a 22.0
(label) main::@10
(label) main::@11
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@8
(label) main::@return
(byte) main::c
(byte) main::c#0 reg byte a 16.5
(byte) main::c#1 reg byte a 22.0
(byte) main::c#2 reg byte a 33.0
(byte) main::i
(byte) main::i#1 reg byte x 151.5
(byte) main::i#2 reg byte x 134.66666666666666
(byte[]) main::line
(const byte[]) main::line#0 line = (const byte*) SCREEN#0+(byte) 40
(byte*) main::nxt
(byte*) main::nxt#1 nxt zp ZP_PTR_BYTE:2 22.0
(byte*) main::nxt#10 nxt zp ZP_PTR_BYTE:2 5.5
(byte*) main::nxt#3 nxt zp ZP_PTR_BYTE:2 2.588235294117647
(byte*) main::nxt#4 nxt zp ZP_PTR_BYTE:2 11.0
(byte) main::scroll
(byte) main::scroll#1 reg byte x 16.5
(byte) main::scroll#10 reg byte x 5.5
(byte) main::scroll#3 reg byte x 2.75
reg byte x [ main::scroll#3 main::scroll#10 main::scroll#1 ]
reg byte x [ main::i#2 main::i#1 ]
reg byte a [ main::c#2 main::c#0 main::c#1 ]
zp ZP_PTR_BYTE:2 [ main::nxt#4 main::nxt#3 main::nxt#10 main::nxt#1 fillscreen::cursor#2 fillscreen::cursor#1 ]
reg byte a [ main::$2 ]
reg byte a [ main::$4 ]
reg byte a [ main::$6 ]
reg byte a [ main::$7 ]
reg byte a [ main::$11 ]
reg byte a [ main::$17 ]
reg byte a [ main::$18 ]

View File

@ -0,0 +1,44 @@
byte* SCREEN = $0400;
byte* RASTER = $d012;
byte* BGCOL = $d020;
byte* SCROLL = $d016;
byte* TEXT = "this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. ";
byte[] STOP = { 0 };
main();
void main() {
fillscreen(SCREEN, $20);
byte scroll = 7;
byte* nxt = TEXT;
byte[] line = SCREEN+40;
do {
// Wait for raster
do {} while(*RASTER!=$fe)
do {} while(*RASTER!=$ff)
*BGCOL = *BGCOL+1;
// Soft scroll
if(--scroll==$ff) {
scroll = 7;
// Hard scroll
for(byte i=0;i!=39;i++) {
line[i]=line[i+1];
}
// Render next char
byte c = *nxt;
if(c==0) {
nxt = TEXT;
c = *nxt;
}
line[39] = c;
nxt++;
}
*SCROLL = scroll;
*BGCOL = *BGCOL-1;
} while(true)
}
void fillscreen(byte* screen, byte fill) {
for( byte* cursor = screen; cursor < screen+1000; cursor++) {
*cursor = fill;
}
}