1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-25 11:32:07 +00:00

Added plus/4 keyboard tester.

This commit is contained in:
jespergravgaard 2020-05-16 12:45:35 +02:00
parent d9fdaca1b0
commit 969301af0f
5 changed files with 1485 additions and 0 deletions

View File

@ -44,6 +44,11 @@ public class TestPrograms {
public TestPrograms() {
}
@Test
public void testPlus4KeyboardTest() throws IOException, URISyntaxException {
compileAndCompare("plus4-keyboard-test.c")
}
@Test
public void testPlus4Kbhit() throws IOException, URISyntaxException {
compileAndCompare("plus4-kbhit.c");

View File

@ -0,0 +1,120 @@
// Test reading keyboard port on the TED of the Plus/4
.pc = $1001 "Basic"
:BasicUpstart(main)
.pc = $100d "Program"
// Keyboard latch
.label KEYBOARD_INPUT = $ff08
// Keyboard scan
.label KEYBOARD_SCAN = $fd30
// Default address of screen character matrix
.label DEFAULT_SCREEN = $c00
main: {
.label row = 3
.label y = 2
// asm
sei
// memset(DEFAULT_SCREEN, ' ', 0x0400)
jsr memset
__b1:
// for(char y=0;y<8;y++)
lda.z y
cmp #8
bcc __b2
lda #<DEFAULT_SCREEN
sta.z row
lda #>DEFAULT_SCREEN
sta.z row+1
lda #0
sta.z y
jmp __b1
__b2:
// 1<<y
lda #1
ldy.z y
cpy #0
beq !e+
!:
asl
dey
bne !-
!e:
// 0xff^(1<<y)
eor #$ff
// *KEYBOARD_SCAN = 0xff^(1<<y)
sta KEYBOARD_SCAN
// *KEYBOARD_INPUT = 0
lda #0
sta KEYBOARD_INPUT
// key_bit = *KEYBOARD_INPUT^0xff
lda #$ff
eor KEYBOARD_INPUT
tax
ldy #0
__b3:
// for(char x=0;x<8;x++)
cpy #8
bcc __b4
// row += 40
lda #$28
clc
adc.z row
sta.z row
bcc !+
inc.z row+1
!:
// for(char y=0;y<8;y++)
inc.z y
jmp __b1
__b4:
// key_bit&0x80
txa
and #$80
// if(key_bit&0x80)
cmp #0
beq __b6
// row[x] = '*'
lda #'*'
sta (row),y
__b6:
// key_bit <<= 1
txa
asl
tax
// for(char x=0;x<8;x++)
iny
jmp __b3
}
// Copies the character c (an unsigned char) to the first num characters of the object pointed to by the argument str.
memset: {
.const c = ' '
.const num = $400
.label str = DEFAULT_SCREEN
.label end = str+num
.label dst = 5
lda #<str
sta.z dst
lda #>str
sta.z dst+1
__b1:
// for(char* dst = str; dst!=end; dst++)
lda.z dst+1
cmp #>end
bne __b2
lda.z dst
cmp #<end
bne __b2
// }
rts
__b2:
// *dst = c
lda #c
ldy #0
sta (dst),y
// for(char* dst = str; dst!=end; dst++)
inc.z dst
bne !+
inc.z dst+1
!:
jmp __b1
}

View File

@ -0,0 +1,63 @@
@begin: scope:[] from
[0] phi()
to:@1
@1: scope:[] from @begin
[1] phi()
[2] call main
to:@end
@end: scope:[] from @1
[3] phi()
(void()) main()
main: scope:[main] from @1
asm { sei }
[5] call memset
to:main::@1
main::@1: scope:[main] from main main::@1 main::@5
[6] (byte*) main::row#6 ← phi( main::@1/(const nomodify byte*) DEFAULT_SCREEN main::@5/(byte*) main::row#1 )
[6] (byte) main::y#2 ← phi( main::@1/(byte) 0 main::@5/(byte) main::y#1 )
[7] if((byte) main::y#2<(byte) 8) goto main::@2
to:main::@1
main::@2: scope:[main] from main::@1
[8] (byte~) main::$2 ← (byte) 1 << (byte) main::y#2
[9] (byte~) main::$3 ← (byte) $ff ^ (byte~) main::$2
[10] *((const nomodify byte*) KEYBOARD_SCAN) ← (byte~) main::$3
[11] *((const nomodify byte*) KEYBOARD_INPUT) ← (byte) 0
[12] (byte) main::key_bit#0 ← *((const nomodify byte*) KEYBOARD_INPUT) ^ (byte) $ff
to:main::@3
main::@3: scope:[main] from main::@2 main::@6
[13] (byte) main::key_bit#2 ← phi( main::@2/(byte) main::key_bit#0 main::@6/(byte) main::key_bit#1 )
[13] (byte) main::x#2 ← phi( main::@2/(byte) 0 main::@6/(byte) main::x#1 )
[14] if((byte) main::x#2<(byte) 8) goto main::@4
to:main::@5
main::@5: scope:[main] from main::@3
[15] (byte*) main::row#1 ← (byte*) main::row#6 + (byte) $28
[16] (byte) main::y#1 ← ++ (byte) main::y#2
to:main::@1
main::@4: scope:[main] from main::@3
[17] (byte~) main::$6 ← (byte) main::key_bit#2 & (byte) $80
[18] if((byte) 0==(byte~) main::$6) goto main::@6
to:main::@7
main::@7: scope:[main] from main::@4
[19] *((byte*) main::row#6 + (byte) main::x#2) ← (byte) '*'
to:main::@6
main::@6: scope:[main] from main::@4 main::@7
[20] (byte) main::key_bit#1 ← (byte) main::key_bit#2 << (byte) 1
[21] (byte) main::x#1 ← ++ (byte) main::x#2
to:main::@3
(void*()) memset((void*) memset::str , (byte) memset::c , (word) memset::num)
memset: scope:[memset] from main
[22] phi()
to:memset::@1
memset::@1: scope:[memset] from memset memset::@2
[23] (byte*) memset::dst#2 ← phi( memset/(byte*)(const void*) memset::str#0 memset::@2/(byte*) memset::dst#1 )
[24] if((byte*) memset::dst#2!=(const byte*) memset::end#0) goto memset::@2
to:memset::@return
memset::@return: scope:[memset] from memset::@1
[25] return
to:@return
memset::@2: scope:[memset] from memset::@1
[26] *((byte*) memset::dst#2) ← (const byte) memset::c#0
[27] (byte*) memset::dst#1 ← ++ (byte*) memset::dst#2
to:memset::@1

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,55 @@
(label) @1
(label) @begin
(label) @end
(const nomodify byte*) DEFAULT_SCREEN = (byte*) 3072
(const nomodify byte*) KEYBOARD_INPUT = (byte*) 65288
(const nomodify byte*) KEYBOARD_SCAN = (byte*) 64816
(void()) main()
(byte~) main::$2 reg byte a 202.0
(byte~) main::$3 reg byte a 202.0
(byte~) main::$6 reg byte a 2002.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@7
(byte) main::key_bit
(byte) main::key_bit#0 reg byte x 202.0
(byte) main::key_bit#1 reg byte x 1001.0
(byte) main::key_bit#2 reg byte x 620.8
(byte*) main::row
(byte*) main::row#1 row zp[2]:3 101.0
(byte*) main::row#6 row zp[2]:3 85.92857142857143
(byte) main::x
(byte) main::x#1 reg byte y 2002.0
(byte) main::x#2 reg byte y 667.3333333333334
(byte) main::y
(byte) main::y#1 y zp[1]:2 202.0
(byte) main::y#2 y zp[1]:2 86.93333333333334
(void*()) memset((void*) memset::str , (byte) memset::c , (word) memset::num)
(label) memset::@1
(label) memset::@2
(label) memset::@return
(byte) memset::c
(const byte) memset::c#0 c = (byte) ' '
(byte*) memset::dst
(byte*) memset::dst#1 dst zp[2]:5 2002.0
(byte*) memset::dst#2 dst zp[2]:5 1334.6666666666667
(byte*) memset::end
(const byte*) memset::end#0 end = (byte*)(const void*) memset::str#0+(const word) memset::num#0
(word) memset::num
(const word) memset::num#0 num = (word) $400
(void*) memset::return
(void*) memset::str
(const void*) memset::str#0 str = (void*)(const nomodify byte*) DEFAULT_SCREEN
zp[1]:2 [ main::y#2 main::y#1 ]
zp[2]:3 [ main::row#6 main::row#1 ]
reg byte y [ main::x#2 main::x#1 ]
reg byte x [ main::key_bit#2 main::key_bit#0 main::key_bit#1 ]
zp[2]:5 [ memset::dst#2 memset::dst#1 ]
reg byte a [ main::$2 ]
reg byte a [ main::$3 ]
reg byte a [ main::$6 ]