1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-04-08 14:37:40 +00:00

Merge branch 'master_upstream' into CX16_VERA

# Conflicts:
#	src/main/fragment/cache/fragment-cache-wdc65c02.asm
#	src/main/fragment/mos6502-common/pduc1_derefidx_vbuxx=vdum1.asm
#	src/main/fragment/mos6502-common/vdum1=vdum1_ror_1.asm
#	src/test/ref/examples/cx16/cx16-sprites.asm
#	src/test/ref/examples/cx16/cx16-sprites.cfg
#	src/test/ref/examples/cx16/cx16-sprites.log
#	src/test/ref/examples/cx16/cx16-sprites.sym
#	src/test/ref/examples/cx16/cx16-tilemap.asm
#	src/test/ref/examples/cx16/cx16-tilemap.cfg
#	src/test/ref/examples/cx16/cx16-tilemap.log
#	src/test/ref/examples/cx16/cx16-tilemap.sym
#	src/test/ref/examples/cx16/cx16-veralayers.asm
#	src/test/ref/examples/cx16/cx16-veralayers.cfg
#	src/test/ref/examples/cx16/cx16-veralayers.log
#	src/test/ref/examples/cx16/cx16-veralayers.sym
This commit is contained in:
FlightControl 2021-01-21 04:49:08 +01:00
commit 962c5f0e17
313 changed files with 64962 additions and 23215 deletions

View File

@ -1,8 +1,22 @@
# KickC - Optimizing C-compiler for 6502
# KickC - Optimizing C-compiler for 6502 platforms
KickC is a C-compiler for creating optimized and readable 6502 assembler code.
KickC is a C-compiler for 6502-based platforms creating optimized and readable assembler code.
The KickC language is classic C with some limitations, some modifications and some extensions to ensure an optimal fit for creating 6502 assembler code.
The language is 95% standard C with a few limitations, and a few extensions to ensure an optimal fit for creating 6502 assembler code.
The KickC-compiler includes all necessary linker and header files to makes it easy to create and test binaries for the following 6502-based platforms out-of-the-box:
- Commodore VIC 20
- Commodore 64
- Commodore Plus/4 (Commodore 16 , Commodore 116)
- Atari 2600
- Atari XL/XE
- Nintendo NES
- MEGA65
- Commander X16
KickC uses the very versatile [Kick Assembler](http://theweb.dk/KickAssembler). The KickC Compiler produces assembler code for the MOS Technology 6502 processor family. Specifically the compiler supports 6502, 65C02, 65CE02 and 45GS02 CPUs.
## Resources
* [Download](https://gitlab.com/camelot/kickc/-/releases) the newest Release
@ -10,7 +24,7 @@ The KickC language is classic C with some limitations, some modifications and so
* [Look](https://gitlab.com/camelot/kickc/tree/master) through the Source Code
* [Follow](https://gitlab.com/camelot/kickc/issues) the open/closed features being developed
* [Follow](https://gitlab.com/camelot/kickc/issues) the features being developed
* [Discuss](https://www.facebook.com/groups/302286200587943/) the compiler and receive news on facebook

View File

@ -48,13 +48,14 @@
<directory>src/test/kc/examples</directory>
<outputDirectory>examples</outputDirectory>
<includes>
<include>*/*.c</include>
<include>*/*.h</include>
<include>*/*.ld</include>
<include>*/*.png</include>
<include>*/*.sid</include>
<include>*/*.bin</include>
<include>*/*.prg</include>
<include>**/*.c</include>
<include>**/*.h</include>
<include>**/*.asm</include>
<include>**/*.ld</include>
<include>**/*.png</include>
<include>**/*.sid</include>
<include>**/*.bin</include>
<include>**/*.prg</include>
</includes>
</fileSet>
<fileSet>

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE 12f875813f 12f8759f70
//KICKC FRAGMENT CACHE 11327739d8 113277581a
//FRAGMENT vbuz1=vbuc1
lda #{c1}
sta {z1}

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE 12f875813f 12f8759f70
//KICKC FRAGMENT CACHE 11327739d8 113277581a
//FRAGMENT _deref_pbuc1=vbuc2
lda #{c2}
sta {c1}

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE 12f875813f 12f8759f70
//KICKC FRAGMENT CACHE 11327739d8 113277581a
//FRAGMENT vbuz1=vbuc1
lda #{c1}
sta {z1}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
//KICKC FRAGMENT CACHE 12f875813f 12f8759f70
//KICKC FRAGMENT CACHE 11327739d8 113277581a
//FRAGMENT _deref_pbuc1=_inc__deref_pbuc1
inc {c1}
//FRAGMENT isr_hardware_all_entry

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
ldy #0
lda {m2}
sta ({z1}),y
iny
lda {m2}+1
sta ({z1}),y
iny
lda {m2}+2
sta ({z1}),y
iny
lda {m2}+3
sta ({z1}),y

View File

@ -0,0 +1 @@
jmp $fcc3

View File

@ -0,0 +1 @@
jmp $eb18

View File

@ -0,0 +1 @@
jmp $ce0e

View File

@ -0,0 +1 @@
jmp $eabf

View File

@ -5,4 +5,4 @@ sta {c1}+1,x
lda {m1}+2
sta {c1}+2,x
lda {m1}+3
sta {c1}+3,x
sta {c1}+3,x

View File

@ -0,0 +1,8 @@
lda {m1}
sta {c1},y
lda {m1}+1
sta {c1}+1,y
lda {m1}+2
sta {c1}+2,y
lda {m1}+3
sta {c1}+3,y

View File

@ -0,0 +1,8 @@
ldy #0
sty {m1}+2
sty {m1}+3
lda ({z2}),y
sta {m1}
iny
lda ({z2}),y
sta {m1}+1

View File

@ -1,4 +1,4 @@
lsr {m1}+3
ror {m1}+2
ror {m1}+1
ror {m1}
ror {m1}

View File

@ -251,6 +251,7 @@ public class Compiler {
}
new Pass1AddressOfHandling(program).execute();
new Pass1AsmUsesHandling(program).execute();
new Pass1FixLValuesLoHi(program).execute();
new Pass1AssertNoLValueIntermediate(program).execute();
new PassNAddTypeConversionAssignment(program, true).execute();
@ -282,7 +283,6 @@ public class Compiler {
new PassNAddTypeConversionAssignment(program, true).execute();
new Pass1EarlyConstantIdentification(program).execute();
new Pass1AsmUsesHandling(program).execute();
new PassNAssertConstantModification(program).execute();
new PassNAssertTypeDeref(program).check();

View File

@ -92,9 +92,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
*/
private Variable addIntermediateVar() {
Scope currentScope = getCurrentScope();
if(ScopeRef.ROOT.equals(currentScope.getRef())) {
Procedure initProc = program.getScope().getLocalProcedure(SymbolRef.INIT_PROC_NAME);
currentScope = initProc;
if(currentScope==null || ScopeRef.ROOT.equals(currentScope.getRef())) {
currentScope = getInitProc();
}
return currentScope.addVariableIntermediate();
}
@ -105,23 +104,28 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
void addStatement(Statement statement) {
ProcedureCompilation procedureCompilation = getCurrentProcedureCompilation();
if(procedureCompilation == null) {
// Statement outside procedure declaration - put into the _init procedure
Procedure initProc = program.getScope().getLocalProcedure(SymbolRef.INIT_PROC_NAME);
if(initProc == null) {
// Create the _init() procedure
initProc = new Procedure(SymbolRef.INIT_PROC_NAME, SymbolType.VOID, program.getScope(), Scope.SEGMENT_CODE_DEFAULT, Scope.SEGMENT_DATA_DEFAULT, Procedure.CallingConvention.PHI_CALL);
initProc.setDeclaredInline(true);
initProc.setParameters(new ArrayList<>());
program.getScope().add(initProc);
program.createProcedureCompilation(initProc.getRef());
program.getProcedureCompilation(initProc.getRef()).getStatementSequence().addStatement(new StatementProcedureBegin(initProc.getRef(), new StatementSource(RuleContext.EMPTY), Comment.NO_COMMENTS));
}
Procedure initProc = getInitProc();
procedureCompilation = program.getProcedureCompilation(initProc.getRef());
}
final StatementSequence statementSequence = procedureCompilation.getStatementSequence();
statementSequence.addStatement(statement);
}
private Procedure getInitProc() {
// Statement outside procedure declaration - put into the _init procedure
Procedure initProc = program.getScope().getLocalProcedure(SymbolRef.INIT_PROC_NAME);
if(initProc == null) {
// Create the _init() procedure
initProc = new Procedure(SymbolRef.INIT_PROC_NAME, SymbolType.VOID, program.getScope(), Scope.SEGMENT_CODE_DEFAULT, Scope.SEGMENT_DATA_DEFAULT, Procedure.CallingConvention.PHI_CALL);
initProc.setDeclaredInline(true);
initProc.setParameters(new ArrayList<>());
program.getScope().add(initProc);
program.createProcedureCompilation(initProc.getRef());
program.getProcedureCompilation(initProc.getRef()).getStatementSequence().addStatement(new StatementProcedureBegin(initProc.getRef(), new StatementSource(RuleContext.EMPTY), Comment.NO_COMMENTS));
}
return initProc;
}
public void generate() {
this.visit(fileCtx);
@ -1107,7 +1111,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
throw new CompileError("Variable used before being defined " + initValue.toString(), statementSource);
}
if(!(initValue instanceof ConstantValue))
throw new CompileError("Initializer is not a constant value " + initValue.toString(), statementSource);
throw new CompileError("Initializer is not a constant value.", statementSource);
return (ConstantValue) initValue;
}

View File

@ -32,14 +32,14 @@
// - If block 6 ($c000-$dfff) is remapped it will point to upperPageOffset*$100 + $c000.
// - If block 7 ($e000-$ffff) is remapped it will point to upperPageOffset*$100 + $e000.
void memoryRemap(unsigned char remapBlocks, unsigned int lowerPageOffset, unsigned int upperPageOffset) {
char * aVal = 0xfc;
char * xVal = 0xfd;
char * yVal = 0xfe;
char * zVal = 0xff;
*aVal = <lowerPageOffset;
*xVal = (remapBlocks << 4) | (>lowerPageOffset & 0xf);
*yVal = <upperPageOffset;
*zVal = (remapBlocks & 0xf0) | (>upperPageOffset & 0xf);
// lower blocks offset page low
char aVal = <lowerPageOffset;
// lower blocks to map + lower blocks offset high nibble
char xVal = (remapBlocks << 4) | (>lowerPageOffset & 0xf);
// upper blocks offset page
char yVal = <upperPageOffset;
// upper blocks to map + upper blocks offset page high nibble
char zVal = (remapBlocks & 0xf0) | (>upperPageOffset & 0xf);
asm {
lda aVal // lower blocks offset page low
ldx xVal // lower blocks to map + lower blocks offset high nibble
@ -90,18 +90,18 @@ void memoryRemapBlock(unsigned char blockPage, unsigned int memoryPage) {
// - If block 6 ($c000-$dfff) is remapped it will point to upperPageOffset*$100 + $c000.
// - If block 7 ($e000-$ffff) is remapped it will point to upperPageOffset*$100 + $e000.
void memoryRemap256M(unsigned char remapBlocks, unsigned long lowerPageOffset, unsigned long upperPageOffset) {
char * lMb = 0xfa;
char * uMb = 0xfb;
char * aVal = 0xfc;
char * xVal = 0xfd;
char * yVal = 0xfe;
char * zVal = 0xff;
*lMb = >((unsigned int)(lowerPageOffset>>4));
*uMb = >((unsigned int)(upperPageOffset>>4));
*aVal = < <lowerPageOffset;
*xVal = (remapBlocks << 4) | (> <lowerPageOffset & 0xf);
*yVal = < <upperPageOffset;
*zVal = (remapBlocks & 0xf0) | (> <upperPageOffset & 0xf);
// lower blocks offset megabytes
char lMb = >((unsigned int)(lowerPageOffset>>4));
// upper blocks offset megabytes
char uMb = >((unsigned int)(upperPageOffset>>4));
// lower blocks offset page low
char aVal = < <lowerPageOffset;
// lower blocks to map + lower blocks offset high nibble
char xVal = (remapBlocks << 4) | (> <lowerPageOffset & 0xf);
// upper blocks offset page
char yVal = < <upperPageOffset;
// upper blocks to map + upper blocks offset page high nibble
char zVal = (remapBlocks & 0xf0) | (> <upperPageOffset & 0xf);
asm {
lda lMb // lower blocks offset megabytes
ldx #$0f // lower signal for MB offset

View File

@ -84,6 +84,10 @@ public class TestPrograms {
compileAndCompare("missing-band.c");
}
@Test
public void testUnknownVarProblem2() throws IOException, URISyntaxException {
assertError("unknown-var-problem-2.c", "error: Initializer is not a constant value.");
}
// https://gitlab.com/camelot/kickc/-/issues/564
//@Test
@ -443,6 +447,11 @@ public class TestPrograms {
compileAndCompare("minus-precedence-problem.c");
}
@Test
public void testRom() throws IOException, URISyntaxException {
compileAndCompare("examples/rom/rom.c");
}
@Test
public void testNesDxycp() throws IOException, URISyntaxException {
compileAndCompare("examples/nes/nes-dxycp.c");
@ -460,28 +469,27 @@ public class TestPrograms {
@Test
public void testCx16VeraLayers() throws IOException, URISyntaxException {
compileAndCompare("examples/cx16/veralayers.c");
compileAndCompare("examples/cx16/cx16-veralayers.c");
}
@Test
public void testCx16TileMap() throws IOException, URISyntaxException {
compileAndCompare("examples/cx16/tilemap.c");
compileAndCompare("examples/cx16/cx16-tilemap.c");
}
@Test
public void testCx16Sprites() throws IOException, URISyntaxException {
compileAndCompare("examples/cx16/sprites.c");
compileAndCompare("examples/cx16/cx16-sprites.c");
}
@Test
public void testCx16Text() throws IOException, URISyntaxException {
compileAndCompare("examples/cx16/text.c");
compileAndCompare("examples/cx16/cx16-text.c");
}
@Test
public void testCx16Rasterbars() throws IOException, URISyntaxException {
compileAndCompare("examples/cx16/rasterbars.c");
compileAndCompare("examples/cx16/cx16-rasterbars.c");
}
@Test
@ -556,17 +564,17 @@ public class TestPrograms {
@Test
public void testAtariXlConioTest() throws IOException, URISyntaxException {
compileAndCompare("examples/atarixl/conio-test.c");
compileAndCompare("examples/atarixl/atarixl-conio.c");
}
@Test
public void testAtariXlRasterbars() throws IOException, URISyntaxException {
compileAndCompare("examples/atarixl/rasterbars.c");
compileAndCompare("examples/atarixl/atarixl-rasterbars.c");
}
@Test
public void testAtariXlHello() throws IOException, URISyntaxException {
compileAndCompare("examples/atarixl/helloxl.c");
compileAndCompare("examples/atarixl/atarixl-hello.c");
}
@Test
@ -621,7 +629,7 @@ public class TestPrograms {
@Test
public void testPlus4Walk() throws IOException, URISyntaxException {
compileAndCompare("examples/plus4walk/plus4walk.c");
compileAndCompare("examples/plus4/plus4-randomwalk.c");
}
@Test
@ -1169,12 +1177,12 @@ public class TestPrograms {
@Test
public void testKernalLoad() throws IOException, URISyntaxException {
compileAndCompare("examples/kernalload/kernalload.c");
compileAndCompare("examples/c64/kernalload/kernalload.c");
}
@Test
public void testKrillLoad() throws IOException, URISyntaxException {
compileAndCompare("examples/krillload/krillload.c");
compileAndCompare("examples/c64/krillload/krillload.c");
}
@Test
@ -1348,7 +1356,7 @@ public class TestPrograms {
@Test
public void testZpCode() throws IOException, URISyntaxException {
compileAndCompare("examples/zpcode/zpcode.c");
compileAndCompare("examples/c64/zpcode/zpcode.c");
}
// Fix parameter type problem - https://gitlab.com/camelot/kickc/issues/299
@ -1452,11 +1460,6 @@ public class TestPrograms {
compileAndCompare("parse-negated-struct-ref.c");
}
@Test
public void testLongPointer1() throws IOException, URISyntaxException {
compileAndCompare("long-pointer-1.c");
}
@Test
public void testLongPointer0() throws IOException, URISyntaxException {
compileAndCompare("long-pointer-0.c");
@ -1567,6 +1570,11 @@ public class TestPrograms {
assertError("cast-error.c", "Type mismatch");
}
@Test
public void testInlineAsmUses1() throws IOException, URISyntaxException {
compileAndCompare("inline-asm-uses-1.c");
}
@Test
public void testInlineAsmMaVar() throws IOException, URISyntaxException {
compileAndCompare("inline-asm-ma-var.c");
@ -1594,12 +1602,12 @@ public class TestPrograms {
@Test
public void testLinking() throws IOException, URISyntaxException {
compileAndCompare("examples/linking/linking.c");
compileAndCompare("examples/c64/linking/linking.c");
}
@Test
public void testNmiSamples() throws IOException, URISyntaxException {
compileAndCompare("examples/nmisamples/nmisamples.c");
compileAndCompare("examples/c64/nmisamples/nmisamples.c");
}
@Test
@ -3078,12 +3086,12 @@ public class TestPrograms {
@Test
public void testFire() throws IOException, URISyntaxException {
compileAndCompare("examples/fire/fire.c");
compileAndCompare("examples/c64/fire/fire.c");
}
@Test
public void testFont2x2() throws IOException, URISyntaxException {
compileAndCompare("examples/font-2x2/font-2x2.c");
compileAndCompare("examples/c64/font-2x2/font-2x2.c");
}
@Test
@ -3098,12 +3106,12 @@ public class TestPrograms {
@Test
public void testPlasmaUnroll() throws IOException, URISyntaxException {
compileAndCompare("examples/plasma/plasma-unroll.c");
compileAndCompare("examples/c64/plasma/plasma-unroll.c");
}
@Test
public void testPlasma() throws IOException, URISyntaxException {
compileAndCompare("examples/plasma/plasma.c");
compileAndCompare("examples/c64/plasma/plasma.c");
}
// TODO: Fix bool auto-conversion type conversion https://gitlab.com/camelot/kickc/issues/199
@ -3321,22 +3329,22 @@ public class TestPrograms {
@Test
public void testMusicIrq() throws IOException, URISyntaxException {
compileAndCompare("examples/music/music_irq.c");
compileAndCompare("examples/c64/music/music_irq.c");
}
@Test
public void testCrunchingExomizer() throws IOException, URISyntaxException {
compileAndCompare("examples/crunching/test-exomizer.c");
compileAndCompare("examples/c64/crunching/test-exomizer.c");
}
@Test
public void testCrunchingByteboozer() throws IOException, URISyntaxException {
compileAndCompare("examples/crunching/test-byteboozer.c");
compileAndCompare("examples/c64/crunching/test-byteboozer.c");
}
@Test
public void testMusic() throws IOException, URISyntaxException {
compileAndCompare("examples/music/music.c");
compileAndCompare("examples/c64/music/music.c");
}
@Test
@ -3651,17 +3659,17 @@ public class TestPrograms {
@Test
public void testFastMultiply8() throws IOException, URISyntaxException {
compileAndCompare("examples/fastmultiply/fastmultiply8.c");
compileAndCompare("examples/c64/fastmultiply/fastmultiply8.c");
}
@Test
public void test3DPerspective() throws IOException, URISyntaxException {
compileAndCompare("examples/3d/perspective.c");
compileAndCompare("examples/c64/3d/perspective.c");
}
@Test
public void test3D() throws IOException, URISyntaxException {
compileAndCompare("examples/3d/3d.c");
compileAndCompare("examples/c64/3d/3d.c");
}
@Test
@ -3671,7 +3679,7 @@ public class TestPrograms {
@Test
public void testRotate() throws IOException, URISyntaxException {
compileAndCompare("examples/rotate/rotate.c");
compileAndCompare("examples/c64/rotate/rotate.c");
}
@Test
@ -3781,7 +3789,7 @@ public class TestPrograms {
@Test
public void testIrqHyperscreen() throws IOException, URISyntaxException {
compileAndCompare("examples/irq/irq-hyperscreen.c");
compileAndCompare("examples/c64/irq/irq-hyperscreen.c");
}
@Test
@ -3806,7 +3814,7 @@ public class TestPrograms {
@Test
public void testMultiplexer() throws IOException, URISyntaxException {
compileAndCompare("examples/multiplexer/simple-multiplexer.c", 10);
compileAndCompare("examples/c64/multiplexer/simple-multiplexer.c", 10);
}
@Test
@ -3836,17 +3844,17 @@ public class TestPrograms {
@Test
public void testSinePlotter() throws IOException, URISyntaxException {
compileAndCompare("examples/sinplotter/sine-plotter.c");
compileAndCompare("examples/c64/sinplotter/sine-plotter.c");
}
@Test
public void testScrollLogo() throws IOException, URISyntaxException {
compileAndCompare("examples/scrolllogo/scrolllogo.c");
compileAndCompare("examples/c64/scrolllogo/scrolllogo.c");
}
@Test
public void testShowLogo() throws IOException, URISyntaxException {
compileAndCompare("examples/showlogo/showlogo.c");
compileAndCompare("examples/c64/showlogo/showlogo.c");
}
@Test
@ -4081,7 +4089,7 @@ public class TestPrograms {
@Test
public void testChargenAnalysis() throws IOException, URISyntaxException {
compileAndCompare("examples/chargen/chargen-analysis.c");
compileAndCompare("examples/c64/chargen/chargen-analysis.c");
}
@Test
@ -4221,7 +4229,7 @@ public class TestPrograms {
@Test
public void testRasterBars() throws IOException, URISyntaxException {
compileAndCompare("examples/rasterbars/raster-bars.c");
compileAndCompare("examples/c64/rasterbars/raster-bars.c");
}
@Test
@ -4321,7 +4329,7 @@ public class TestPrograms {
@Test
public void testSinusSprites() throws IOException, URISyntaxException {
compileAndCompare("examples/sinsprites/sinus-sprites.c");
compileAndCompare("examples/c64/sinsprites/sinus-sprites.c");
}
@Test
@ -4426,7 +4434,7 @@ public class TestPrograms {
@Test
public void testScrollBig() throws IOException, URISyntaxException {
compileAndCompare("examples/scrollbig/scrollbig.c");
compileAndCompare("examples/c64/scrollbig/scrollbig.c");
}
@Test
@ -4456,7 +4464,7 @@ public class TestPrograms {
@Test
public void testBitmapBresenham() throws IOException, URISyntaxException {
compileAndCompare("examples/bresenham/bitmap-bresenham.c");
compileAndCompare("examples/c64/bresenham/bitmap-bresenham.c");
}
@Test
@ -4502,7 +4510,7 @@ public class TestPrograms {
@Test
public void testScroll() throws IOException, URISyntaxException {
compileAndCompare("examples/scroll/scroll.c");
compileAndCompare("examples/c64/scroll/scroll.c");
}
@Test

View File

@ -67,7 +67,7 @@ void move16Left(uint8_t *p) {
*(p + 3) = t;
}
void rotateLeft(__ma uint8_t *p, __ma uint8_t r) {
void rotateLeft(uint8_t * const p, uint8_t r) {
kickasm(
clobbers "AX",
uses p,

View File

@ -6,18 +6,18 @@
#include <print.h>
// The rotated point - updated by calling rotate_matrix()
signed char* xr = $f0;
signed char* yr = $f1;
signed char* zr = $f2;
signed char xr;
signed char yr;
signed char zr;
// The rotated point with perspective
signed char* pp = $f3;
signed char* xp = $f4;
signed char* yp = $f5;
signed char pp;
signed char xp;
signed char yp;
// Pointers used to multiply perspective (d/z0-z) onto x- & y-coordinates. Points into mulf_sqr1 / mulf_sqr2
unsigned int* psp1 = $f6;
unsigned int* psp2 = $f8;
unsigned int psp1;
unsigned int psp2;
char* SCREEN = $400;
@ -25,8 +25,8 @@ void main() {
asm { sei }
sprites_init();
//mulf_init();
*psp1 = (unsigned int)mulf_sqr1;
*psp2 = (unsigned int)mulf_sqr2;
psp1 = (unsigned int)mulf_sqr1;
psp2 = (unsigned int)mulf_sqr2;
debug_print_init();
@ -65,15 +65,15 @@ void anim() {
for(char i: 0..7) {
(VICII->BORDER_COLOR)++;
rotate_matrix(xs[i], ys[i], zs[i]);
xrs[i] = *xr;
yrs[i] = *yr;
zrs[i] = *zr;
pps[i] = *pp;
xps[i] = *xp;
yps[i] = *yp;
xrs[i] = xr;
yrs[i] = yr;
zrs[i] = zr;
pps[i] = pp;
xps[i] = xp;
yps[i] = yp;
char i2 = i*2;
SPRITES_XPOS[i2] = $80+(char)((*xp));
SPRITES_YPOS[i2] = $80+(char)((*yp));
SPRITES_XPOS[i2] = $80+(char)(xp);
SPRITES_YPOS[i2] = $80+(char)(yp);
}
VICII->BORDER_COLOR = LIGHT_GREY;
debug_print();
@ -295,9 +295,9 @@ void store_matrix() {
// The passed points must be in the interval [-$3f;$3f].
// Implemented in assembler to utilize seriously fast multiplication
void rotate_matrix(signed char x, signed char y, signed char z) {
*xr = x;
*yr = y;
*zr = z;
xr = x;
yr = y;
zr = z;
asm {
ldx zr //z
// C*z

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -6,19 +6,19 @@
#include <print.h>
// The rotated point - updated by calling rotate()
signed char* xr = $f0;
signed char* yr = $f1;
signed char* zr = $f2;
signed char xr;
signed char yr;
signed char zr;
// Pointers used to multiply perspective (d/z0-z) onto x- & y-coordinates. Points into mulf_sqr1 / mulf_sqr2.
unsigned int* psp1 = $f3;
unsigned int* psp2 = $f5;
unsigned int psp1;
unsigned int psp2;
void main() {
asm { sei }
mulf_init();
*psp1 = (unsigned int)mulf_sqr1;
*psp2 = (unsigned int)mulf_sqr2;
psp1 = (unsigned int)mulf_sqr1;
psp2 = (unsigned int)mulf_sqr2;
print_cls();
do_perspective($39, -$47, $36);
/*
@ -45,9 +45,9 @@ void do_perspective(signed char x, signed char y, signed char z) {
print_schar(z);
print_str(") -> (");
perspective(x, y, z);
print_uchar((byte)*xr);
print_uchar((char)xr);
print_str(",");
print_uchar((byte)*yr);
print_uchar((char)yr);
print_str(")");
print_ln();
}
@ -56,9 +56,9 @@ void do_perspective(signed char x, signed char y, signed char z) {
// Apply perspective to a 3d-point. Result is returned in (*xr,*yr)
// Implemented in assembler to utilize seriously fast multiplication
void perspective(signed char x, signed char y, signed char z) {
*xr = x;
*yr = y;
*zr = z;
xr = x;
yr = y;
zr = z;
asm {
// Update index in perspective lookup

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -47,26 +47,20 @@ void init_screen() {
}
// Pointers to a, b and c=a*b
signed char* ap = $fd;
signed char* bp = $fe;
signed char* cp = $ff;
signed char fmul8(signed char a, signed char b) {
*ap = a;
*bp = b;
signed char fmul8(signed char aa, signed char bb) {
signed char cc;
asm {
lda ap
lda aa
sta A1+1
eor #$ff
sta A2+1
ldx bp
ldx bb
sec
A1: lda mulf_sqr1,x
A2: sbc mulf_sqr2,x
sta cp
sta cc
}
return *cp;
return cc;
}
// mulf_sqr tables will contain f(x)=int(x*x) and g(x) = f(1-x).

View File

@ -47,18 +47,16 @@ void main() {
char loadFileToMemory( char device, char* filename, char* address) {
setnam(filename);
setlfs(device);
return load(address, false);
return load(address, 0);
}
// Basic ERROR function
// ERROR. Show error.
void error(char err) {
char* const errCode = 0xff;
*errCode = err;
asm {
// Basic SHOWERR function
// Input: X = Error Code
ldx errCode
ldx err
jsr $a437
}
}
@ -66,57 +64,50 @@ void error(char err) {
// Kernal SETNAM function
// SETNAM. Set file name parameters.
void setnam(char* filename) {
char* const filename_len = 0xfd;
char** const filename_ptr = 0xfe;
*filename_len = (char)strlen(filename);
*filename_ptr = filename;
char filename_len = (char)strlen(filename);
asm {
// Kernal SETNAM function
// SETNAM. Set file name parameters.
// Input: A = File name length; X/Y = Pointer to file name.
lda filename_len
ldx filename_ptr
ldy filename_ptr+1
ldx filename
ldy filename+1
jsr $ffbd
}
}
// SETLFS. Set file parameters.
void setlfs(char device) {
char* const deviceNum = 0xff;
*deviceNum = device;
asm {
// SETLFS. Set file parameters.
// Input: A = Logical number; X = Device number; Y = Secondary address.
ldx deviceNum
ldx device
lda #1
ldy #0
jsr $ffba
}
}
//LOAD. Load or verify file. (Must call SETLFS and SETNAM beforehands.)
// LOAD. Load or verify file. (Must call SETLFS and SETNAM beforehands.)
// - verify: 0 = Load, 1-255 = Verify
//
// Returns a status, 0xff: Success other: Kernal Error Code
char load(char* address, bool verify) {
char* loadOrVerify = 0xfd;
char** loadAddress = 0xfe;
char* status = 0xfd;
*loadOrVerify = (char)verify;
*loadAddress = address;
char load(char* address, char verify) {
char status;
asm {
//LOAD. Load or verify file. (Must call SETLFS and SETNAM beforehands.)
// Input: A: 0 = Load, 1-255 = Verify; X/Y = Load address (if secondary address = 0).
// Output: Carry: 0 = No errors, 1 = Error; A = KERNAL error code (if Carry = 1); X/Y = Address of last byte loaded/verified (if Carry = 0).
ldx loadAddress
ldy loadAddress+1
lda loadOrVerify
ldx address
ldy address+1
lda verify
jsr $ffd5
bcs error
lda #$ff
error:
sta status
}
return *status;
return status;
}

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -4,8 +4,8 @@
//
// This is a recursive solution
#include<stdio.h>
#include<tod.h>
#include <stdio.h>
#include <conio.h>
#define QUEENS 8
#define PRINT_SOLUTIONS
@ -20,9 +20,8 @@ void main() {
clrscr();
printf(" - n queens problem using backtracking -");
printf("\nnumber of queens:%u",QUEENS);
tod_init(TOD_ZERO);
queen(1);
printf("\n\nsolutions: %lu time: %s.\n",count,tod_str(tod_read()));
printf("\n\nsolutions: %lu.\n",count);
}
// Generates all valid placements of queens on a NxN board recursively

View File

@ -0,0 +1,39 @@
// Demonstrates how to code a ROM
// The rom.ld linker file declares segments for RomCode and RomData.
// It also declares a TestRom segment used for testing the ROM calls.This ensures that the compiler does not optimize them away.
#pragma target(asm6502)
#pragma link("rom.ld")
#pragma extension("bin")
#pragma start_address(0xf000)
#pragma code_seg(RomCode)
#pragma data_seg(RomData)
// A stack based ROM function that will transfer all parameters and return values through the stack.
__stackcall char call1(char param1, char param2) {
return param1+param2;
}
// A memory based ROM function that will transfer all parameters and return values through zeropage.
__ma char call2(__ma char param1, __ma char param2) {
return param1+param2;
}
// A "normal" optimized ROM function that will transfer parameters and return value through registers or zeropage.
char call3(char param1, char param2) {
return param1+param2;
}
// These calls are thrown away when assembling but needed to make sure the compiler does not optimize the ROM functions away.
// To make sure the functions are generated into the final code they must be calling them with different values for each parameter and the return value must used in some way.
#pragma code_seg(TestRom)
void main() {
char* ptr = 0xfe;
*ptr = call1(1,2);
*ptr = call1(3,4);
*ptr = call2(1,2);
*ptr = call2(3,4);
*ptr = call3(1,2);
*ptr = call3(3,4);
}

View File

@ -0,0 +1,6 @@
// ROM linking file
.file [name="%O", type="bin", segments="Rom"]
.segmentdef Rom [segments="RomCode, RomData"]
.segmentdef RomCode [start=%P]
.segmentdef RomData [startAfter="RomCode"]
.segmentdef TestRom

View File

@ -1,4 +1,4 @@
byte* SCREEN = $0400;
byte* const SCREEN = $0400;
void main() {
byte a = 'a';

View File

@ -0,0 +1,25 @@
// Demonstrates inline ASM using a variable (res)
void main() {
char * const SCREEN = 0x1009;
char x = fgetc(7);
*SCREEN = x;
}
char * const CHKIN = 0x1000;
char * const GETIN = 0x1003;
char * const CLRCHN = 0x1006;
char fgetc(byte channel)
{
char ret;
asm {
ldx channel
jsr CHKIN
jsr GETIN
sta ret
jsr CLRCHN
}
return ret;
}

View File

@ -1,5 +1,5 @@
// Tests that inline kickasm supports the clobbering directive
byte* SCREEN = $0400;
byte* const SCREEN = $0400;
void main() {
for(byte k : 0..10) {
for(byte l: 0..10) {

View File

@ -1,7 +1,7 @@
// Tests creating a long (32bit) pointer on zeropage for 45GS02 flat memory access
void main() {
unsigned long long_ptr = 0x12345678;
char long_ptr_zp = <&long_ptr;
__zp unsigned long long_ptr = 0x12345678;
const char long_ptr_zp = (char)&long_ptr;
asm {
nop
lda (long_ptr_zp),y

View File

@ -1,10 +0,0 @@
// Tests creating a long (32bit) pointer on zeropage for 45GS02 flat memory access
void main() {
unsigned long long_ptr = 0x12345678;
__zp char long_ptr_zp = (char)&long_ptr;
asm {
nop
lda (long_ptr_zp),y
sta $ff
}
}

View File

@ -0,0 +1,8 @@
// Demonstrates problem with unknown variable
char* const SCREEN = 0x0400;
char* const SPRITES_PTR = SCREEN + QWE;
void main() {
SPRITES_PTR[0] = 0;
}

View File

@ -780,7 +780,7 @@ move16Left::@return: scope:[move16Left] from move16Left
[373] return
to:@return
void rotateLeft(volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
void rotateLeft(nomodify volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
rotateLeft: scope:[rotateLeft] from leftRotate::@1 leftRotate::@10 leftRotate::@11
kickasm( uses rotateLeft::p uses rotateLeft::r) {{ ldx #r
!s:

View File

@ -13,13 +13,6 @@ Setting inferred volatile on symbol affected by address-of cputc::$4 = call conv
Setting inferred volatile on symbol affected by address-of print32::dp = (byte*)&print32::l
Setting inferred volatile on symbol affected by address-of leftRotate::p = (byte*)&leftRotate::a
Setting inferred volatile on symbol affected by address-of md5::$10 = call memcpy md5::$9 &md5::bits_len 4
Added struct type cast to parameter value list call printf_uchar print32::dp[0] (struct printf_format_number){ 2, 0, 0, 1, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar print32::dp[1] (struct printf_format_number){ 2, 0, 0, 1, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar print32::dp[2] (struct printf_format_number){ 2, 0, 0, 1, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar print32::dp[3] (struct printf_format_number){ 2, 0, 0, 1, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar md5::i (struct printf_format_number){ 2, 0, 0, 0, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar md5::g (struct printf_format_number){ 2, 0, 0, 0, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar md5::r[md5::i] (struct printf_format_number){ 2, 0, 0, 0, 0, HEXADECIMAL }
Setting inferred volatile on symbol affected by address-of: rotateLeft::p in kickasm( uses rotateLeft::p uses rotateLeft::r) {{ ldx #r
!s:
asl p+3
@ -46,6 +39,13 @@ Setting inferred volatile on symbol affected by address-of: rotateLeft::r in kic
dex
bne !s-
}}
Added struct type cast to parameter value list call printf_uchar print32::dp[0] (struct printf_format_number){ 2, 0, 0, 1, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar print32::dp[1] (struct printf_format_number){ 2, 0, 0, 1, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar print32::dp[2] (struct printf_format_number){ 2, 0, 0, 1, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar print32::dp[3] (struct printf_format_number){ 2, 0, 0, 1, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar md5::i (struct printf_format_number){ 2, 0, 0, 0, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar md5::g (struct printf_format_number){ 2, 0, 0, 0, 0, HEXADECIMAL }
Added struct type cast to parameter value list call printf_uchar md5::r[md5::i] (struct printf_format_number){ 2, 0, 0, 0, 0, HEXADECIMAL }
Inlined call cputc::$4 = call convertToScreenCode &cputc::c
Inlined call call BREAK
Inlined call call BREAK
@ -1224,7 +1224,7 @@ move16Left::@return: scope:[move16Left] from move16Left
return
to:@return
void rotateLeft(volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
void rotateLeft(nomodify volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
rotateLeft: scope:[rotateLeft] from leftRotate::@1 leftRotate::@12 leftRotate::@15
kickasm( uses rotateLeft::p uses rotateLeft::r) {{ ldx #r
!s:
@ -4370,8 +4370,8 @@ const byte* rawmap[$100] = kickasm {{ .var ht = Hashtable().put(0,64, 1,0, 2,32
.byte mask | ht.get(idx)
}
}}
void rotateLeft(volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
volatile byte* rotateLeft::p loadstore
void rotateLeft(nomodify volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
nomodify volatile byte* rotateLeft::p loadstore
volatile byte rotateLeft::r loadstore
void setcursor()
byte*~ setcursor::$0
@ -7184,7 +7184,7 @@ move16Left::@return: scope:[move16Left] from move16Left
[373] return
to:@return
void rotateLeft(volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
void rotateLeft(nomodify volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
rotateLeft: scope:[rotateLeft] from leftRotate::@1 leftRotate::@10 leftRotate::@11
kickasm( uses rotateLeft::p uses rotateLeft::r) {{ ldx #r
!s:
@ -7764,8 +7764,8 @@ byte* putchar::loc
byte* putchar::loc#0 1.000000000001E12
byte putchar::newChar
byte putchar::newChar#0 1.5000000000015E12
void rotateLeft(volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
volatile byte* rotateLeft::p loadstore 5000.5
void rotateLeft(nomodify volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
nomodify volatile byte* rotateLeft::p loadstore 5000.5
volatile byte rotateLeft::r loadstore 10001.0
void setcursor()
byte setcursor::c
@ -12487,8 +12487,8 @@ const byte* rawmap[$100] = kickasm {{ .var ht = Hashtable().put(0,64, 1,0, 2,32
.byte mask | ht.get(idx)
}
}}
void rotateLeft(volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
volatile byte* rotateLeft::p loadstore zp[2]:213 5000.5
void rotateLeft(nomodify volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
nomodify volatile byte* rotateLeft::p loadstore zp[2]:213 5000.5
volatile byte rotateLeft::r loadstore zp[1]:215 10001.0
void setcursor()
byte setcursor::c

View File

@ -327,8 +327,8 @@ const byte* rawmap[$100] = kickasm {{ .var ht = Hashtable().put(0,64, 1,0, 2,32
.byte mask | ht.get(idx)
}
}}
void rotateLeft(volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
volatile byte* rotateLeft::p loadstore zp[2]:213 5000.5
void rotateLeft(nomodify volatile byte* rotateLeft::p , volatile byte rotateLeft::r)
nomodify volatile byte* rotateLeft::p loadstore zp[2]:213 5000.5
volatile byte rotateLeft::r loadstore zp[1]:215 10001.0
void setcursor()
byte setcursor::c

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More