mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-08-08 13:25:12 +00:00
Added two tests.
This commit is contained in:
@@ -8,15 +8,15 @@ const byte PROCPORT_DDR_MEMORY_MASK = %00000111;
|
|||||||
// Processor Port Register controlling RAM/ROM configuration and the datasette
|
// Processor Port Register controlling RAM/ROM configuration and the datasette
|
||||||
const byte* PROCPORT = $01;
|
const byte* PROCPORT = $01;
|
||||||
// RAM in all three areas $A000, $D000, $E000
|
// RAM in all three areas $A000, $D000, $E000
|
||||||
const byte PROCPORT_RAM_ALL = %00110000;
|
const byte PROCPORT_RAM_ALL = %00000000;
|
||||||
// RAM in $A000, $E000 I/O in $D000
|
// RAM in $A000, $E000 I/O in $D000
|
||||||
const byte PROCPORT_RAM_IO = %00110101;
|
const byte PROCPORT_RAM_IO = %00000101;
|
||||||
// RAM in $A000, $E000 CHAR ROM in $D000
|
// RAM in $A000, $E000 CHAR ROM in $D000
|
||||||
const byte PROCPORT_RAM_CHARROM = %00110001;
|
const byte PROCPORT_RAM_CHARROM = %00000001;
|
||||||
// RAM in $A000, I/O in $D000, KERNEL in $E000
|
// RAM in $A000, I/O in $D000, KERNEL in $E000
|
||||||
const byte PROCPORT_KERNEL_IO = %00110110;
|
const byte PROCPORT_KERNEL_IO = %00000110;
|
||||||
// BASIC in $A000, I/O in $D000, KERNEL in $E000
|
// BASIC in $A000, I/O in $D000, KERNEL in $E000
|
||||||
const byte PROCPORT_BASIC_KERNEL_IO = %00110111;
|
const byte PROCPORT_BASIC_KERNEL_IO = %00000111;
|
||||||
|
|
||||||
// The address of the CHARGEN character set
|
// The address of the CHARGEN character set
|
||||||
const byte* CHARGEN = $d000;
|
const byte* CHARGEN = $d000;
|
||||||
|
@@ -35,6 +35,16 @@ public class TestPrograms {
|
|||||||
public TestPrograms() {
|
public TestPrograms() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testZeropageSinus() throws IOException, URISyntaxException {
|
||||||
|
compileAndCompare("zeropage-sinus");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testProcessorPortTest() throws IOException, URISyntaxException {
|
||||||
|
compileAndCompare("processor-port-test");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSieve() throws IOException, URISyntaxException {
|
public void testSieve() throws IOException, URISyntaxException {
|
||||||
compileAndCompare("sieve");
|
compileAndCompare("sieve");
|
||||||
|
89
src/test/kc/processor-port-test.kc
Normal file
89
src/test/kc/processor-port-test.kc
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
// Test the functionality of the C64 processor port ($00/$01)
|
||||||
|
// Tests by setting the value of the processor port - and then printing out values of $00/$01/$a000/$d000/$e000
|
||||||
|
|
||||||
|
import "c64"
|
||||||
|
import "print"
|
||||||
|
|
||||||
|
const char* BASIC_ROM = $a000;
|
||||||
|
const char* KERNAL_ROM = $e000;
|
||||||
|
const char* IO_RAM = $d000;
|
||||||
|
const char* SCREEN = 0x400;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// Avoid interrupts
|
||||||
|
asm { sei }
|
||||||
|
// Write recognizable values into memory
|
||||||
|
*PROCPORT_DDR = PROCPORT_DDR_MEMORY_MASK;
|
||||||
|
*PROCPORT = PROCPORT_RAM_ALL;
|
||||||
|
*BASIC_ROM = $a0;
|
||||||
|
*KERNAL_ROM = $e0;
|
||||||
|
*IO_RAM = $d0;
|
||||||
|
*PROCPORT_DDR = PROCPORT_DDR_MEMORY_MASK;
|
||||||
|
*PROCPORT = PROCPORT_BASIC_KERNEL_IO;
|
||||||
|
*IO_RAM = $dd;
|
||||||
|
|
||||||
|
print_cls();
|
||||||
|
print_str("ddr port ddr2 $00 $01 $a000 $d000 $e000");
|
||||||
|
print_ln();
|
||||||
|
testProcport(PROCPORT_DDR_MEMORY_MASK, PROCPORT_RAM_ALL, PROCPORT_DDR_MEMORY_MASK);
|
||||||
|
testProcport(PROCPORT_DDR_MEMORY_MASK, PROCPORT_RAM_IO, PROCPORT_DDR_MEMORY_MASK);
|
||||||
|
testProcport(PROCPORT_DDR_MEMORY_MASK, PROCPORT_RAM_CHARROM, PROCPORT_DDR_MEMORY_MASK);
|
||||||
|
testProcport(PROCPORT_DDR_MEMORY_MASK, PROCPORT_KERNEL_IO, PROCPORT_DDR_MEMORY_MASK);
|
||||||
|
testProcport(PROCPORT_DDR_MEMORY_MASK, PROCPORT_BASIC_KERNEL_IO, PROCPORT_DDR_MEMORY_MASK);
|
||||||
|
|
||||||
|
testProcport($00, $00, $00);
|
||||||
|
testProcport($ff, $00, $00);
|
||||||
|
testProcport($ff, $ff, $00);
|
||||||
|
|
||||||
|
testProcport($ff, $00, $ff);
|
||||||
|
testProcport($ff, $55, $ff);
|
||||||
|
testProcport($ff, $aa, $ff);
|
||||||
|
testProcport($ff, $ff, $ff);
|
||||||
|
|
||||||
|
testProcport($55, $00, $55);
|
||||||
|
testProcport($55, $55, $55);
|
||||||
|
testProcport($55, $ff, $55);
|
||||||
|
|
||||||
|
testProcport($aa, $00, $aa);
|
||||||
|
testProcport($aa, $ff, $aa);
|
||||||
|
testProcport($aa, $aa, $aa);
|
||||||
|
|
||||||
|
testProcport($ff, $d0, $00);
|
||||||
|
testProcport($ff, $55, $55);
|
||||||
|
testProcport($17, $15, $15);
|
||||||
|
testProcport($17, $15, $17);
|
||||||
|
testProcport($17, $17, $17);
|
||||||
|
|
||||||
|
// Enable interrupts
|
||||||
|
asm { cli }
|
||||||
|
// Return to normal settings
|
||||||
|
*PROCPORT_DDR = PROCPORT_DDR_MEMORY_MASK;
|
||||||
|
*PROCPORT = PROCPORT_BASIC_KERNEL_IO;
|
||||||
|
|
||||||
|
while(true) (*(SCREEN+999))++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testProcport(char ddr, char port, char ddr2) {
|
||||||
|
*PROCPORT_DDR = $ff;
|
||||||
|
*PROCPORT = $00;
|
||||||
|
*PROCPORT_DDR = ddr;
|
||||||
|
*PROCPORT = port;
|
||||||
|
*PROCPORT_DDR = ddr2;
|
||||||
|
print_str(" ");
|
||||||
|
print_byte(ddr);
|
||||||
|
print_str(" ");
|
||||||
|
print_byte(port);
|
||||||
|
print_str(" ");
|
||||||
|
print_byte(ddr2);
|
||||||
|
print_str(" ");
|
||||||
|
print_byte(*PROCPORT_DDR);
|
||||||
|
print_str(" ");
|
||||||
|
print_byte(*PROCPORT);
|
||||||
|
print_str(" ");
|
||||||
|
print_byte(*BASIC_ROM);
|
||||||
|
print_str(" ");
|
||||||
|
print_byte(*IO_RAM);
|
||||||
|
print_str(" ");
|
||||||
|
print_byte(*KERNAL_ROM);
|
||||||
|
print_ln();
|
||||||
|
}
|
97
src/test/kc/zeropage-sinus.kc
Normal file
97
src/test/kc/zeropage-sinus.kc
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
// Attempt to store and use a sinus on zeropage
|
||||||
|
// $00/$11 is carefully chosen to be $ff - which plays well with the processor port
|
||||||
|
|
||||||
|
import "c64"
|
||||||
|
|
||||||
|
// A 256-byte (co)sinus (with $ff in the first two entries)
|
||||||
|
const unsigned char[0x100] align(0x100) SINTABLE = kickasm {{
|
||||||
|
.for(var i=0;i<$100;i++)
|
||||||
|
.byte round(127.5+127.5*cos(toRadians(360*i/256)))
|
||||||
|
}};
|
||||||
|
|
||||||
|
// Storage for saving/restoring zeropage
|
||||||
|
const unsigned char[0x100] align(0x100) ZP_STORAGE;
|
||||||
|
|
||||||
|
const char* SCREEN = 0x0400;
|
||||||
|
|
||||||
|
// A single sprite to animate
|
||||||
|
const align(0x40) char[0x40] SPRITE = kickasm {{ .fill $40,$ff }};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
// Stop interrupts
|
||||||
|
asm { sei }
|
||||||
|
// Show sprite
|
||||||
|
*SPRITES_ENABLE = 1;
|
||||||
|
SPRITES_YPOS[0] = 100;
|
||||||
|
SPRITES_XPOS[0] = 100;
|
||||||
|
*(SCREEN+SPRITE_PTRS) = (byte)(SPRITE/0x40);
|
||||||
|
|
||||||
|
saveZeropage();
|
||||||
|
sinZeropage();
|
||||||
|
animSprite();
|
||||||
|
restoreZeropage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save all values on zeropage
|
||||||
|
void saveZeropage() {
|
||||||
|
asm {
|
||||||
|
ldx #0
|
||||||
|
!:
|
||||||
|
lda $00,x
|
||||||
|
sta ZP_STORAGE,x
|
||||||
|
inx
|
||||||
|
bne !-
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save all values on zeropage
|
||||||
|
void restoreZeropage() {
|
||||||
|
asm {
|
||||||
|
ldx #0
|
||||||
|
!:
|
||||||
|
lda ZP_STORAGE,x
|
||||||
|
sta $00,x
|
||||||
|
inx
|
||||||
|
bne !-
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move the SINUS values to zeropage
|
||||||
|
void sinZeropage() {
|
||||||
|
asm {
|
||||||
|
ldx #0
|
||||||
|
!:
|
||||||
|
lda SINTABLE,x
|
||||||
|
sta $00,x
|
||||||
|
inx
|
||||||
|
bne !-
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move a sprite in the sinus on zeropage
|
||||||
|
void animSprite() {
|
||||||
|
kickasm {{
|
||||||
|
ldx #$00
|
||||||
|
repeat:
|
||||||
|
lda #$fe
|
||||||
|
!:
|
||||||
|
cmp $d012
|
||||||
|
bne !-
|
||||||
|
lda #$ff
|
||||||
|
!:
|
||||||
|
cmp $d012
|
||||||
|
bne !-
|
||||||
|
.break
|
||||||
|
lda $00,x
|
||||||
|
clc
|
||||||
|
adc #$38
|
||||||
|
sta $d000
|
||||||
|
lda #0
|
||||||
|
adc #0
|
||||||
|
sta $d010
|
||||||
|
inx
|
||||||
|
jmp repeat
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user