1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-17 16:31:34 +00:00

Added a lot of signed word and boolean fragments from Travis Fisher.

This commit is contained in:
Jesper Gravgaard 2019-03-16 17:54:38 +01:00
parent ba560796dd
commit dc76b2bed0
24 changed files with 2864 additions and 4 deletions

View File

@ -0,0 +1,4 @@
lda {c2}
sta {c1}
lda {c2}+1
sta {c1}+1

View File

@ -0,0 +1,9 @@
sec
stx $ff
tax
lda {c1},x
sbc $ff
sta {c1},x
bcs !+
dec {c1}+1,x
!:

View File

@ -0,0 +1,9 @@
sec
sty $ff
tay
lda {c1},y
sbc $ff
sta {c1},y
lda {c1}+1,y
sbc #$00
sta {c1}+1,y

View File

@ -0,0 +1,9 @@
clc
sbc {c1},x
eor #$ff
sta {c1},x
bcc !+
lda {c1}+1,x
sbc #$01
sta {c1}+1,x
!:

View File

@ -2,6 +2,6 @@ sec
lda {c1},x
sbc {z1}
sta {c1},x
lda {c1}+1,x
sbc #0
sta {c1}+1,x
bcs !+
dec {c1}+1,x
!:

View File

@ -0,0 +1,4 @@
lda #<{c2}
sta {c1},x
lda #>{c2}
sta {c1}+1,x

View File

@ -0,0 +1,4 @@
lda #<{c2}
sta {c1},y
lda #>{c2}
sta {c1}+1,y

View File

@ -0,0 +1,5 @@
eor {c1},x
beq !+
lda #1
!:
eor #1

View File

@ -0,0 +1,4 @@
eor {c1},x
beq !+
lda #1
!:

View File

@ -0,0 +1,5 @@
eor {c1},y
beq !+
lda #1
!:
eor #1

View File

@ -0,0 +1,4 @@
eor {c1},y
beq !+
lda #1
!:

View File

@ -1,4 +1,4 @@
cmp #{c1}
eor #{c1}
beq !+
lda #1
!:

View File

@ -1,3 +1,4 @@
lda #0
cpx #{c1}
beq !+
lda #1

View File

@ -1,3 +1,4 @@
lda #0
cpy #{c1}
beq !+
lda #1

View File

@ -0,0 +1 @@
ldx {c1},y

View File

@ -0,0 +1,7 @@
clc
sbc {z1}
eor #$ff
sta {z1}
bcc !+
dec {z1}+1
!:

View File

@ -0,0 +1,7 @@
sec
lda {z1}
sbc #{c1}
sta {z1}
bcs !+
dec {z1}+1
!:

View File

@ -44,6 +44,18 @@ public class TestPrograms {
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
}
/*
@Test
public void testConstSignedPromotion() throws IOException, URISyntaxException {
compileAndCompare("const-signed-promotion");
}
*/
@Test
public void testSignedIndexedSubtract() throws IOException, URISyntaxException {
compileAndCompare("signed-indexed-subtract");
}
@Test
public void testInlineAsmRefScoped() throws IOException, URISyntaxException {
compileAndCompare("inline-asm-ref-scoped");

View File

@ -0,0 +1,11 @@
// Test fragment promotion of a constant (400) to signed word even if it also matches an unsigned word
signed word[3] world ;
void main() {
for(byte i:0..2) {
world[i<<1]= 400;
}
signed word* screen = $400;
*screen = world[0];
}

View File

@ -0,0 +1,25 @@
// Tests that signed indexed subtract works as intended
import "print"
signed word[] words = {-$6000, -$600, -$60, -6, 0, 6, $60, $600, $6000};
void main() {
for(byte i: 0..8) {
byte idx = i<<1;
sub(idx, $80);
sub(idx, $40);
sub(idx, $40);
}
print_cls();
for(byte j: 0..8) {
print_sword(words[j<<1]);
print_ln();
}
}
void sub(byte idx, byte s) {
words[idx] -= s;
}

View File

@ -0,0 +1,171 @@
// Tests that signed indexed subtract works as intended
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label print_line_cursor = 2
.label print_char_cursor = 7
main: {
ldy #0
b1:
tya
asl
tax
lda #$80
jsr sub
lda #$40
jsr sub
lda #$40
jsr sub
iny
cpy #9
bne b1
jsr print_cls
lda #<$400
sta print_line_cursor
lda #>$400
sta print_line_cursor+1
lda #<$400
sta print_char_cursor
lda #>$400
sta print_char_cursor+1
ldx #0
b2:
txa
asl
tay
lda words,y
sta print_sword.w
lda words+1,y
sta print_sword.w+1
jsr print_sword
jsr print_ln
inx
cpx #9
bne b12
rts
b12:
lda print_line_cursor
sta print_char_cursor
lda print_line_cursor+1
sta print_char_cursor+1
jmp b2
}
// Print a newline
print_ln: {
b1:
lda print_line_cursor
clc
adc #$28
sta print_line_cursor
bcc !+
inc print_line_cursor+1
!:
lda print_line_cursor+1
cmp print_char_cursor+1
bcc b1
bne !+
lda print_line_cursor
cmp print_char_cursor
bcc b1
!:
rts
}
// Print a signed word as HEX
// print_sword(signed word zeropage(4) w)
print_sword: {
.label w = 4
lda w+1
bpl b1
lda #'-'
jsr print_char
sec
lda w
eor #$ff
adc #0
sta w
lda w+1
eor #$ff
adc #0
sta w+1
b1:
jsr print_word
rts
}
// Print a word as HEX
print_word: {
lda print_sword.w+1
sta print_byte.b
jsr print_byte
lda print_sword.w
sta print_byte.b
jsr print_byte
rts
}
// Print a byte as HEX
// print_byte(byte zeropage(6) b)
print_byte: {
.label b = 6
lda b
lsr
lsr
lsr
lsr
tay
lda print_hextab,y
jsr print_char
lda #$f
and b
tay
lda print_hextab,y
jsr print_char
rts
}
// Print a single char
// print_char(byte register(A) ch)
print_char: {
ldy #0
sta (print_char_cursor),y
inc print_char_cursor
bne !+
inc print_char_cursor+1
!:
rts
}
// Clear the screen. Also resets current line/char cursor.
print_cls: {
.label sc = 2
lda #<$400
sta sc
lda #>$400
sta sc+1
b1:
lda #' '
ldy #0
sta (sc),y
inc sc
bne !+
inc sc+1
!:
lda sc+1
cmp #>$400+$3e8
bne b1
lda sc
cmp #<$400+$3e8
bne b1
rts
}
// sub(byte register(X) idx, byte register(A) s)
sub: {
clc
sbc words,x
eor #$ff
sta words,x
bcc !+
lda words+1,x
sbc #1
sta words+1,x
!:
rts
}
print_hextab: .text "0123456789abcdef"
words: .word -$6000, -$600, -$60, -6, 0, 6, $60, $600, $6000

View File

@ -0,0 +1,140 @@
@begin: scope:[] from
[0] phi()
to:@21
@21: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @21
[3] phi()
main: scope:[main] from @21
[4] phi()
to:main::@1
main::@1: scope:[main] from main main::@7
[5] (byte) main::i#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@7/(byte) main::i#1 )
[6] (byte) main::idx#0 ← (byte) main::i#2 << (byte/signed byte/word/signed word/dword/signed dword) 1
[7] (byte) sub::idx#0 ← (byte) main::idx#0
[8] call sub
to:main::@5
main::@5: scope:[main] from main::@1
[9] (byte) sub::idx#1 ← (byte) main::idx#0
[10] call sub
to:main::@6
main::@6: scope:[main] from main::@5
[11] (byte) sub::idx#2 ← (byte) main::idx#0
[12] call sub
to:main::@7
main::@7: scope:[main] from main::@6
[13] (byte) main::i#1 ← ++ (byte) main::i#2
[14] if((byte) main::i#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@1
to:main::@3
main::@3: scope:[main] from main::@7
[15] phi()
[16] call print_cls
to:main::@2
main::@2: scope:[main] from main::@12 main::@3
[17] (byte*) print_line_cursor#19 ← phi( main::@12/(byte*) print_line_cursor#1 main::@3/((byte*))(word/signed word/dword/signed dword) $400 )
[17] (byte*) print_char_cursor#46 ← phi( main::@12/(byte*~) print_char_cursor#56 main::@3/((byte*))(word/signed word/dword/signed dword) $400 )
[17] (byte) main::j#2 ← phi( main::@12/(byte) main::j#1 main::@3/(byte/signed byte/word/signed word/dword/signed dword) 0 )
[18] (byte~) main::$6 ← (byte) main::j#2 << (byte/signed byte/word/signed word/dword/signed dword) 1
[19] (signed word) print_sword::w#1 ← *((const signed word[]) words#0 + (byte~) main::$6)
[20] call print_sword
to:main::@9
main::@9: scope:[main] from main::@2
[21] phi()
[22] call print_ln
to:main::@10
main::@10: scope:[main] from main::@9
[23] (byte) main::j#1 ← ++ (byte) main::j#2
[24] if((byte) main::j#1!=(byte/signed byte/word/signed word/dword/signed dword) 9) goto main::@12
to:main::@return
main::@return: scope:[main] from main::@10
[25] return
to:@return
main::@12: scope:[main] from main::@10
[26] (byte*~) print_char_cursor#56 ← (byte*) print_line_cursor#1
to:main::@2
print_ln: scope:[print_ln] from main::@9
[27] phi()
to:print_ln::@1
print_ln::@1: scope:[print_ln] from print_ln print_ln::@1
[28] (byte*) print_line_cursor#9 ← phi( print_ln/(byte*) print_line_cursor#19 print_ln::@1/(byte*) print_line_cursor#1 )
[29] (byte*) print_line_cursor#1 ← (byte*) print_line_cursor#9 + (byte/signed byte/word/signed word/dword/signed dword) $28
[30] if((byte*) print_line_cursor#1<(byte*) print_char_cursor#12) goto print_ln::@1
to:print_ln::@return
print_ln::@return: scope:[print_ln] from print_ln::@1
[31] return
to:@return
print_sword: scope:[print_sword] from main::@2
[32] if((signed word) print_sword::w#1>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto print_sword::@1
to:print_sword::@2
print_sword::@2: scope:[print_sword] from print_sword
[33] phi()
[34] call print_char
to:print_sword::@4
print_sword::@4: scope:[print_sword] from print_sword::@2
[35] (signed word) print_sword::w#0 ← - (signed word) print_sword::w#1
to:print_sword::@1
print_sword::@1: scope:[print_sword] from print_sword print_sword::@4
[36] (byte*) print_char_cursor#41 ← phi( print_sword/(byte*) print_char_cursor#46 print_sword::@4/(byte*) print_char_cursor#12 )
[36] (signed word) print_sword::w#3 ← phi( print_sword/(signed word) print_sword::w#1 print_sword::@4/(signed word) print_sword::w#0 )
[37] call print_word
to:print_sword::@return
print_sword::@return: scope:[print_sword] from print_sword::@1
[38] return
to:@return
print_word: scope:[print_word] from print_sword::@1
[39] (byte) print_byte::b#0 ← > (word)(signed word) print_sword::w#3
[40] call print_byte
to:print_word::@1
print_word::@1: scope:[print_word] from print_word
[41] (byte) print_byte::b#1 ← < (word)(signed word) print_sword::w#3
[42] call print_byte
to:print_word::@return
print_word::@return: scope:[print_word] from print_word::@1
[43] return
to:@return
print_byte: scope:[print_byte] from print_word print_word::@1
[44] (byte*) print_char_cursor#44 ← phi( print_word/(byte*) print_char_cursor#41 print_word::@1/(byte*) print_char_cursor#12 )
[44] (byte) print_byte::b#2 ← phi( print_word/(byte) print_byte::b#0 print_word::@1/(byte) print_byte::b#1 )
[45] (byte~) print_byte::$0 ← (byte) print_byte::b#2 >> (byte/signed byte/word/signed word/dword/signed dword) 4
[46] (byte) print_char::ch#1 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$0)
[47] call print_char
to:print_byte::@1
print_byte::@1: scope:[print_byte] from print_byte
[48] (byte~) print_byte::$2 ← (byte) print_byte::b#2 & (byte/signed byte/word/signed word/dword/signed dword) $f
[49] (byte) print_char::ch#2 ← *((const byte[]) print_hextab#0 + (byte~) print_byte::$2)
[50] call print_char
to:print_byte::@return
print_byte::@return: scope:[print_byte] from print_byte::@1
[51] return
to:@return
print_char: scope:[print_char] from print_byte print_byte::@1 print_sword::@2
[52] (byte*) print_char_cursor#32 ← phi( print_byte/(byte*) print_char_cursor#44 print_byte::@1/(byte*) print_char_cursor#12 print_sword::@2/(byte*) print_char_cursor#46 )
[52] (byte) print_char::ch#3 ← phi( print_byte/(byte) print_char::ch#1 print_byte::@1/(byte) print_char::ch#2 print_sword::@2/(byte) '-' )
[53] *((byte*) print_char_cursor#32) ← (byte) print_char::ch#3
[54] (byte*) print_char_cursor#12 ← ++ (byte*) print_char_cursor#32
to:print_char::@return
print_char::@return: scope:[print_char] from print_char
[55] return
to:@return
print_cls: scope:[print_cls] from main::@3
[56] phi()
to:print_cls::@1
print_cls::@1: scope:[print_cls] from print_cls print_cls::@1
[57] (byte*) print_cls::sc#2 ← phi( print_cls/((byte*))(word/signed word/dword/signed dword) $400 print_cls::@1/(byte*) print_cls::sc#1 )
[58] *((byte*) print_cls::sc#2) ← (byte) ' '
[59] (byte*) print_cls::sc#1 ← ++ (byte*) print_cls::sc#2
[60] if((byte*) print_cls::sc#1!=((byte*))(word/signed word/dword/signed dword) $400+(word/signed word/dword/signed dword) $3e8) goto print_cls::@1
to:print_cls::@return
print_cls::@return: scope:[print_cls] from print_cls::@1
[61] return
to:@return
sub: scope:[sub] from main::@1 main::@5 main::@6
[62] (byte) sub::s#3 ← phi( main::@1/(byte/word/signed word/dword/signed dword) $80 main::@5/(byte/signed byte/word/signed word/dword/signed dword) $40 main::@6/(byte/signed byte/word/signed word/dword/signed dword) $40 )
[62] (byte) sub::idx#3 ← phi( main::@1/(byte) sub::idx#0 main::@5/(byte) sub::idx#1 main::@6/(byte) sub::idx#2 )
[63] *((const signed word[]) words#0 + (byte) sub::idx#3) ← *((const signed word[]) words#0 + (byte) sub::idx#3) - (byte) sub::s#3
to:sub::@return
sub::@return: scope:[sub] from sub
[64] return
to:@return

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,99 @@
(label) @21
(label) @begin
(label) @end
(void()) main()
(byte~) main::$6 reg byte a 22.0
(label) main::@1
(label) main::@10
(label) main::@12
(label) main::@2
(label) main::@3
(label) main::@5
(label) main::@6
(label) main::@7
(label) main::@9
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte y 16.5
(byte) main::i#2 reg byte y 4.125
(byte) main::idx
(byte) main::idx#0 reg byte x 8.8
(byte) main::j
(byte) main::j#1 reg byte x 11.0
(byte) main::j#2 reg byte x 5.5
(void()) print_byte((byte) print_byte::b)
(byte~) print_byte::$0 reg byte a 4.0
(byte~) print_byte::$2 reg byte a 4.0
(label) print_byte::@1
(label) print_byte::@return
(byte) print_byte::b
(byte) print_byte::b#0 b zp ZP_BYTE:6 4.0
(byte) print_byte::b#1 b zp ZP_BYTE:6 4.0
(byte) print_byte::b#2 b zp ZP_BYTE:6 2.0
(void()) print_char((byte) print_char::ch)
(label) print_char::@return
(byte) print_char::ch
(byte) print_char::ch#1 reg byte a 4.0
(byte) print_char::ch#2 reg byte a 4.0
(byte) print_char::ch#3 reg byte a 6.0
(byte*) print_char_cursor
(byte*) print_char_cursor#12 print_char_cursor zp ZP_WORD:7 5.190476190476189
(byte*) print_char_cursor#32 print_char_cursor zp ZP_WORD:7 5.0
(byte*) print_char_cursor#41 print_char_cursor zp ZP_WORD:7 3.0
(byte*) print_char_cursor#44 print_char_cursor zp ZP_WORD:7 2.0
(byte*) print_char_cursor#46 print_char_cursor zp ZP_WORD:7 3.0
(byte*~) print_char_cursor#56 print_char_cursor zp ZP_WORD:7 22.0
(void()) print_cls()
(label) print_cls::@1
(label) print_cls::@return
(byte*) print_cls::sc
(byte*) print_cls::sc#1 sc zp ZP_WORD:2 16.5
(byte*) print_cls::sc#2 sc zp ZP_WORD:2 16.5
(byte[]) print_hextab
(const byte[]) print_hextab#0 print_hextab = (string) "0123456789abcdef"
(byte*) print_line_cursor
(byte*) print_line_cursor#1 print_line_cursor zp ZP_WORD:2 46.42857142857143
(byte*) print_line_cursor#19 print_line_cursor zp ZP_WORD:2 2.1666666666666665
(byte*) print_line_cursor#9 print_line_cursor zp ZP_WORD:2 204.0
(void()) print_ln()
(label) print_ln::@1
(label) print_ln::@return
(byte*) print_screen
(void()) print_sword((signed word) print_sword::w)
(label) print_sword::@1
(label) print_sword::@2
(label) print_sword::@4
(label) print_sword::@return
(signed word) print_sword::w
(signed word) print_sword::w#0 w zp ZP_WORD:4 4.0
(signed word) print_sword::w#1 w zp ZP_WORD:4 4.25
(signed word) print_sword::w#3 w zp ZP_WORD:4 1.3333333333333333
(void()) print_word((word) print_word::w)
(label) print_word::@1
(label) print_word::@return
(word) print_word::w
(void()) sub((byte) sub::idx , (byte) sub::s)
(label) sub::@return
(byte) sub::idx
(byte) sub::idx#0 reg byte x 22.0
(byte) sub::idx#1 reg byte x 22.0
(byte) sub::idx#2 reg byte x 22.0
(byte) sub::idx#3 reg byte x 37.0
(byte) sub::s
(byte) sub::s#3 reg byte a 2.0
(signed word[]) words
(const signed word[]) words#0 words = { -(word/signed word/dword/signed dword) $6000, -(word/signed word/dword/signed dword) $600, -(byte/signed byte/word/signed word/dword/signed dword) $60, -(byte/signed byte/word/signed word/dword/signed dword) 6, (byte/signed byte/word/signed word/dword/signed dword) 0, (byte/signed byte/word/signed word/dword/signed dword) 6, (byte/signed byte/word/signed word/dword/signed dword) $60, (word/signed word/dword/signed dword) $600, (word/signed word/dword/signed dword) $6000 }
reg byte y [ main::i#2 main::i#1 ]
reg byte x [ main::j#2 main::j#1 ]
zp ZP_WORD:2 [ print_line_cursor#9 print_line_cursor#19 print_line_cursor#1 print_cls::sc#2 print_cls::sc#1 ]
zp ZP_WORD:4 [ print_sword::w#3 print_sword::w#1 print_sword::w#0 ]
zp ZP_BYTE:6 [ print_byte::b#2 print_byte::b#0 print_byte::b#1 ]
reg byte a [ print_char::ch#3 print_char::ch#1 print_char::ch#2 ]
zp ZP_WORD:7 [ print_char_cursor#32 print_char_cursor#44 print_char_cursor#41 print_char_cursor#46 print_char_cursor#56 print_char_cursor#12 ]
reg byte x [ sub::idx#3 sub::idx#0 sub::idx#1 sub::idx#2 ]
reg byte a [ sub::s#3 ]
reg byte x [ main::idx#0 ]
reg byte a [ main::$6 ]
reg byte a [ print_byte::$0 ]
reg byte a [ print_byte::$2 ]