1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-11 20:30:08 +00:00

Added some fragments and tests for 65CE02.

This commit is contained in:
jespergravgaard 2020-07-30 01:20:41 +02:00
parent e66705c103
commit 88cdba9d0c
39 changed files with 416 additions and 7 deletions

View File

@ -0,0 +1 @@
inw {z1}

View File

@ -0,0 +1 @@
neg

View File

@ -0,0 +1 @@
neg

View File

@ -0,0 +1 @@
asr

View File

@ -0,0 +1,2 @@
asr
asr

View File

@ -0,0 +1,4 @@
asr
asr
asr
asr

View File

@ -0,0 +1,7 @@
cpx #0
beq !e+
!l:
asr
dex
bne !l-
!e:

View File

@ -0,0 +1,7 @@
cpy #0
beq !e+
!l:
asr
dey
bne !l-
!e:

View File

@ -0,0 +1,8 @@
txa
cpx #0
beq !e+
!l:
asr
dex
bne !l-
!e:

View File

@ -0,0 +1,8 @@
tya
cpy #0
beq !e+
!l:
asr
dey
bne !l-
!e:

View File

@ -0,0 +1 @@
neg

View File

@ -0,0 +1,2 @@
txa
neg

View File

@ -0,0 +1,2 @@
tya
neg

View File

@ -0,0 +1,2 @@
neg
tax

View File

@ -0,0 +1,2 @@
neg
tay

View File

@ -0,0 +1 @@
asw {m1}

View File

@ -0,0 +1,2 @@
asw {m1}
asw {m1}

View File

@ -0,0 +1,3 @@
asw {m1}
asw {m1}
asw {m1}

View File

@ -0,0 +1,4 @@
asw {m1}
asw {m1}
asw {m1}
asw {m1}

View File

@ -0,0 +1 @@
dew {z1}

View File

@ -0,0 +1 @@
inw {z1}

View File

@ -0,0 +1 @@
asw {m1}

View File

@ -0,0 +1,2 @@
asw {m1}
asw {m1}

View File

@ -0,0 +1,3 @@
asw {m1}
asw {m1}
asw {m1}

View File

@ -0,0 +1,4 @@
asw {m1}
asw {m1}
asw {m1}
asw {m1}

View File

@ -0,0 +1,5 @@
asw {m1}
asw {m1}
asw {m1}
asw {m1}
asw {m1}

View File

@ -0,0 +1 @@
dew {z1}

View File

@ -0,0 +1 @@
inw {z1}

View File

@ -0,0 +1 @@
inw {z1}

View File

@ -1,4 +1,8 @@
lsr
lsr
lsr
lsr
cmp #$80
ror
cmp #$80
ror
cmp #$80
ror
cmp #$80
ror

View File

@ -17,6 +17,8 @@ public class Cpu45GS02 extends Cpu65xx {
public Cpu45GS02() {
super(NAME, Cpu65CE02.INSTANCE);
// TODO: Add 45GS02 instructions
// TODO: Disable NOP?
}
}

View File

@ -56,7 +56,7 @@ public class Cpu65CE02 extends Cpu65xx {
addOpcode(0xB3, "lbcs", CpuAddressingMode.REL, 3, "P");
addOpcode(0xBB, "ldz", CpuAddressingMode.ABS, 4, "Znz");
addOpcode(0xC2, "cpz", CpuAddressingMode.IMM, 2, "cnz");
addOpcode(0xC3, "dew", CpuAddressingMode.ABS, 5, "nz");
addOpcode(0xC3, "dew", CpuAddressingMode.ZP, 5, "nz");
addOpcode(0xCB, "asw", CpuAddressingMode.ABS, 7, "cnz");
addOpcode(0xD2, "cmp", CpuAddressingMode.IZZ, 5, "cnz");
addOpcode(0xD3, "lbne", CpuAddressingMode.REL, 3, "P");
@ -64,7 +64,7 @@ public class Cpu65CE02 extends Cpu65xx {
addOpcode(0xDB, "phz", CpuAddressingMode.NON, 3, "S");
addOpcode(0xDC, "cpz", CpuAddressingMode.ABS, 4, "cnz");
addOpcode(0xE2, "lda", CpuAddressingMode.ISY, 6, "Anz");
addOpcode(0xE3, "inw", CpuAddressingMode.ABS, 5, "nz");
addOpcode(0xE3, "inw", CpuAddressingMode.ZP, 5, "nz");
addOpcode(0xEA, "eom", CpuAddressingMode.NON, 1, "");
addOpcode(0xEB, "row", CpuAddressingMode.ABS, 6, "cnz");
addOpcode(0xF2, "sbc", CpuAddressingMode.IZZ, 5, "Acvnz");

View File

@ -62,6 +62,11 @@ public class TestPrograms {
compileAndCompare("cpu-45gs02.c");
}
@Test
public void testCpu65CE02() throws IOException, URISyntaxException {
compileAndCompare("cpu-65ce02.c", log());
}
@Test
public void testCpu65C02() throws IOException, URISyntaxException {
compileAndCompare("cpu-65c02.c");

View File

@ -7,5 +7,5 @@ char* const SCREEN = 0x0400;
void main() {
char a = SCREEN[0];
SCREEN[1] = a+1;
SCREEN[1] = a+1; // will use INC A
}

13
src/test/kc/cpu-65ce02.c Normal file
View File

@ -0,0 +1,13 @@
// Test the 65CE02 CPU
// A program that uses 65CE02 instructions
#pragma cpu(CSG65CE02)
signed char* const SCREEN = 0x0400;
void main() {
signed char a = SCREEN[0];
a = -a;
SCREEN[1] = a; // Becomes a NEG
SCREEN[2] = a/4; // Becomes ASR
}

View File

@ -0,0 +1,23 @@
// Test the 65CE02 CPU
// A program that uses 65CE02 instructions
.cpu _65ce02
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
main: {
// a = SCREEN[0]
lda SCREEN
// a = -a
neg
// SCREEN[1] = a
sta SCREEN+1
// a/4
asr
asr
// SCREEN[2] = a/4
// Becomes a NEG
sta SCREEN+2
// }
rts
}

View File

@ -0,0 +1,12 @@
(void()) main()
main: scope:[main] from
[0] (signed byte) main::a#0 ← *((const nomodify signed byte*) SCREEN)
[1] (signed byte) main::a#1 ← - (signed byte) main::a#0
[2] *((const nomodify signed byte*) SCREEN+(byte) 1) ← (signed byte) main::a#1
[3] (signed byte~) main::$1 ← (signed byte) main::a#1 >> (byte) 2
[4] *((const nomodify signed byte*) SCREEN+(byte) 2) ← (signed byte~) main::$1
to:main::@return
main::@return: scope:[main] from main
[5] return
to:@return

260
src/test/ref/cpu-65ce02.log Normal file
View File

@ -0,0 +1,260 @@
CONTROL FLOW GRAPH SSA
(void()) main()
main: scope:[main] from __start
(signed byte) main::a#0 ← *((const nomodify signed byte*) SCREEN + (number) 0)
(signed byte~) main::$0 ← - (signed byte) main::a#0
(signed byte) main::a#1 ← (signed byte~) main::$0
*((const nomodify signed byte*) SCREEN + (number) 1) ← (signed byte) main::a#1
(number~) main::$1 ← (signed byte) main::a#1 / (number) 4
*((const nomodify signed byte*) SCREEN + (number) 2) ← (number~) main::$1
to:main::@return
main::@return: scope:[main] from main
return
to:@return
(void()) __start()
__start: scope:[__start] from
call main
to:__start::@1
__start::@1: scope:[__start] from __start
to:__start::@return
__start::@return: scope:[__start] from __start::@1
return
to:@return
SYMBOL TABLE SSA
(const nomodify signed byte*) SCREEN = (signed byte*)(number) $400
(void()) __start()
(label) __start::@1
(label) __start::@return
(void()) main()
(signed byte~) main::$0
(number~) main::$1
(label) main::@return
(signed byte) main::a
(signed byte) main::a#0
(signed byte) main::a#1
Adding number conversion cast (unumber) 0 in (signed byte) main::a#0 ← *((const nomodify signed byte*) SCREEN + (number) 0)
Adding number conversion cast (unumber) 1 in *((const nomodify signed byte*) SCREEN + (number) 1) ← (signed byte) main::a#1
Adding number conversion cast (snumber) 4 in (number~) main::$1 ← (signed byte) main::a#1 / (number) 4
Adding number conversion cast (snumber) main::$1 in (number~) main::$1 ← (signed byte) main::a#1 / (snumber)(number) 4
Adding number conversion cast (unumber) 2 in *((const nomodify signed byte*) SCREEN + (number) 2) ← (snumber~) main::$1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (signed byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 4
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized signed number type (signed byte) 4
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to signed byte in (snumber~) main::$1 ← (signed byte) main::a#1 / (signed byte) 4
Alias main::a#1 = main::$0
Successful SSA optimization Pass2AliasElimination
Simplifying expression containing zero SCREEN in [0] (signed byte) main::a#0 ← *((const nomodify signed byte*) SCREEN + (byte) 0)
Successful SSA optimization PassNSimplifyExpressionWithZero
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Rewriting division to use shift [3] (signed byte~) main::$1 ← (signed byte) main::a#1 / (signed byte) 4
Successful SSA optimization Pass2MultiplyToShiftRewriting
Consolidated array index constant in *(SCREEN+1)
Consolidated array index constant in *(SCREEN+2)
Successful SSA optimization Pass2ConstantAdditionElimination
CALL GRAPH
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
FINAL CONTROL FLOW GRAPH
(void()) main()
main: scope:[main] from
[0] (signed byte) main::a#0 ← *((const nomodify signed byte*) SCREEN)
[1] (signed byte) main::a#1 ← - (signed byte) main::a#0
[2] *((const nomodify signed byte*) SCREEN+(byte) 1) ← (signed byte) main::a#1
[3] (signed byte~) main::$1 ← (signed byte) main::a#1 >> (byte) 2
[4] *((const nomodify signed byte*) SCREEN+(byte) 2) ← (signed byte~) main::$1
to:main::@return
main::@return: scope:[main] from main
[5] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(signed byte~) main::$1 4.0
(signed byte) main::a
(signed byte) main::a#0 4.0
(signed byte) main::a#1 3.0
Initial phi equivalence classes
Added variable main::a#0 to live range equivalence class [ main::a#0 ]
Added variable main::a#1 to live range equivalence class [ main::a#1 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Complete equivalence classes
[ main::a#0 ]
[ main::a#1 ]
[ main::$1 ]
Allocated zp[1]:2 [ main::a#0 ]
Allocated zp[1]:3 [ main::a#1 ]
Allocated zp[1]:4 [ main::$1 ]
INITIAL ASM
Target platform is c64basic / CSG65CE02
// File Comments
// Test the 65CE02 CPU
// A program that uses 65CE02 instructions
// Upstart
.cpu _65ce02
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// main
main: {
.label __1 = 4
.label a = 2
.label a_1 = 3
// [0] (signed byte) main::a#0 ← *((const nomodify signed byte*) SCREEN) -- vbsz1=_deref_pbsc1
lda SCREEN
sta.z a
// [1] (signed byte) main::a#1 ← - (signed byte) main::a#0 -- vbsz1=_neg_vbsz2
lda.z a
neg
sta.z a_1
// [2] *((const nomodify signed byte*) SCREEN+(byte) 1) ← (signed byte) main::a#1 -- _deref_pbsc1=vbsz1
lda.z a_1
sta SCREEN+1
// [3] (signed byte~) main::$1 ← (signed byte) main::a#1 >> (byte) 2 -- vbsz1=vbsz2_ror_2
lda.z a_1
asr
asr
sta.z __1
// [4] *((const nomodify signed byte*) SCREEN+(byte) 2) ← (signed byte~) main::$1 -- _deref_pbsc1=vbsz1
// Becomes a NEG
lda.z __1
sta SCREEN+2
jmp __breturn
// main::@return
__breturn:
// [5] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] (signed byte) main::a#1 ← - (signed byte) main::a#0 [ main::a#1 ] ( [ main::a#1 ] { } ) always clobbers reg byte a
Statement [3] (signed byte~) main::$1 ← (signed byte) main::a#1 >> (byte) 2 [ main::$1 ] ( [ main::$1 ] { } ) always clobbers reg byte a
Potential registers zp[1]:2 [ main::a#0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:3 [ main::a#1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:4 [ main::$1 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp[1]:2 [ main::a#0 ] 4: zp[1]:4 [ main::$1 ] 3: zp[1]:3 [ main::a#1 ]
Uplift Scope []
Uplifting [main] best 27 combination reg byte a [ main::a#0 ] reg byte a [ main::$1 ] reg byte a [ main::a#1 ]
Uplifting [] best 27 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test the 65CE02 CPU
// A program that uses 65CE02 instructions
// Upstart
.cpu _65ce02
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// main
main: {
// [0] (signed byte) main::a#0 ← *((const nomodify signed byte*) SCREEN) -- vbsaa=_deref_pbsc1
lda SCREEN
// [1] (signed byte) main::a#1 ← - (signed byte) main::a#0 -- vbsaa=_neg_vbsaa
neg
// [2] *((const nomodify signed byte*) SCREEN+(byte) 1) ← (signed byte) main::a#1 -- _deref_pbsc1=vbsaa
sta SCREEN+1
// [3] (signed byte~) main::$1 ← (signed byte) main::a#1 >> (byte) 2 -- vbsaa=vbsaa_ror_2
asr
asr
// [4] *((const nomodify signed byte*) SCREEN+(byte) 2) ← (signed byte~) main::$1 -- _deref_pbsc1=vbsaa
// Becomes a NEG
sta SCREEN+2
jmp __breturn
// main::@return
__breturn:
// [5] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(const nomodify signed byte*) SCREEN = (signed byte*) 1024
(void()) main()
(signed byte~) main::$1 reg byte a 4.0
(label) main::@return
(signed byte) main::a
(signed byte) main::a#0 reg byte a 4.0
(signed byte) main::a#1 reg byte a 3.0
reg byte a [ main::a#0 ]
reg byte a [ main::a#1 ]
reg byte a [ main::$1 ]
FINAL ASSEMBLER
Score: 24
// File Comments
// Test the 65CE02 CPU
// A program that uses 65CE02 instructions
// Upstart
.cpu _65ce02
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// main
main: {
// a = SCREEN[0]
// [0] (signed byte) main::a#0 ← *((const nomodify signed byte*) SCREEN) -- vbsaa=_deref_pbsc1
lda SCREEN
// a = -a
// [1] (signed byte) main::a#1 ← - (signed byte) main::a#0 -- vbsaa=_neg_vbsaa
neg
// SCREEN[1] = a
// [2] *((const nomodify signed byte*) SCREEN+(byte) 1) ← (signed byte) main::a#1 -- _deref_pbsc1=vbsaa
sta SCREEN+1
// a/4
// [3] (signed byte~) main::$1 ← (signed byte) main::a#1 >> (byte) 2 -- vbsaa=vbsaa_ror_2
asr
asr
// SCREEN[2] = a/4
// [4] *((const nomodify signed byte*) SCREEN+(byte) 2) ← (signed byte~) main::$1 -- _deref_pbsc1=vbsaa
// Becomes a NEG
sta SCREEN+2
// main::@return
// }
// [5] return
rts
}
// File Data

View File

@ -0,0 +1,11 @@
(const nomodify signed byte*) SCREEN = (signed byte*) 1024
(void()) main()
(signed byte~) main::$1 reg byte a 4.0
(label) main::@return
(signed byte) main::a
(signed byte) main::a#0 reg byte a 4.0
(signed byte) main::a#1 reg byte a 3.0
reg byte a [ main::a#0 ]
reg byte a [ main::a#1 ]
reg byte a [ main::$1 ]