1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Standard C array syntax implemented char x[8]. The KickC syntax char[8] x is still supported, but will be removed. Closes #162

This commit is contained in:
jespergravgaard 2020-03-26 09:13:48 +01:00
parent 1160a14359
commit f9560de10d
37 changed files with 2053 additions and 1796 deletions

File diff suppressed because it is too large Load Diff

View File

@ -66,8 +66,13 @@ declVariableList
;
declVariableInit
: NAME ('=' expr)? #declVariableInitExpr
| NAME '=' declKasm #declVariableInitKasm
: declVariable ('=' expr)? #declVariableInitExpr
| declVariable '=' declKasm #declVariableInitKasm
;
declVariable
: NAME #declVariableName
| declVariable BRACKET_BEGIN (expr)? BRACKET_END #declVariableArray
;
declFunction

File diff suppressed because it is too large Load Diff

View File

@ -52,95 +52,95 @@ EXPORT=51
ALIGN=52
INLINE=53
VOLATILE=54
INTERRUPT=55
REGISTER=56
ADDRESS=57
ADDRESS_ZEROPAGE=58
ADDRESS_MAINMEM=59
FORM_SSA=60
FORM_MA=61
CALLING=62
CALLINGCONVENTION=63
VARMODEL=64
IF=65
ELSE=66
WHILE=67
DO=68
FOR=69
SWITCH=70
RETURN=71
BREAK=72
CONTINUE=73
ASM=74
DEFAULT=75
CASE=76
STRUCT=77
ENUM=78
SIZEOF=79
TYPEID=80
KICKASM=81
RESOURCE=82
USES=83
CLOBBERS=84
BYTES=85
CYCLES=86
LOGIC_NOT=87
SIGNEDNESS=88
SIMPLETYPE=89
BOOLEAN=90
KICKASM_BODY=91
STRING=92
CHAR=93
NUMBER=94
NUMFLOAT=95
BINFLOAT=96
DECFLOAT=97
HEXFLOAT=98
NUMINT=99
BININTEGER=100
DECINTEGER=101
HEXINTEGER=102
NAME=103
WS=104
COMMENT_LINE=105
COMMENT_BLOCK=106
ASM_BYTE=107
ASM_MNEMONIC=108
ASM_IMM=109
ASM_COLON=110
ASM_COMMA=111
ASM_PAR_BEGIN=112
ASM_PAR_END=113
ASM_BRACKET_BEGIN=114
ASM_BRACKET_END=115
ASM_DOT=116
ASM_SHIFT_LEFT=117
ASM_SHIFT_RIGHT=118
ASM_PLUS=119
ASM_MINUS=120
ASM_LESS_THAN=121
ASM_GREATER_THAN=122
ASM_MULTIPLY=123
ASM_DIVIDE=124
ASM_CURLY_BEGIN=125
ASM_CURLY_END=126
ASM_NUMBER=127
ASM_NUMFLOAT=128
ASM_BINFLOAT=129
ASM_DECFLOAT=130
ASM_HEXFLOAT=131
ASM_NUMINT=132
ASM_BININTEGER=133
ASM_DECINTEGER=134
ASM_HEXINTEGER=135
ASM_CHAR=136
ASM_MULTI_REL=137
ASM_MULTI_NAME=138
ASM_NAME=139
ASM_WS=140
ASM_COMMENT_LINE=141
ASM_COMMENT_BLOCK=142
STATIC=143
STATIC=55
INTERRUPT=56
REGISTER=57
ADDRESS=58
ADDRESS_ZEROPAGE=59
ADDRESS_MAINMEM=60
FORM_SSA=61
FORM_MA=62
CALLING=63
CALLINGCONVENTION=64
VARMODEL=65
IF=66
ELSE=67
WHILE=68
DO=69
FOR=70
SWITCH=71
RETURN=72
BREAK=73
CONTINUE=74
ASM=75
DEFAULT=76
CASE=77
STRUCT=78
ENUM=79
SIZEOF=80
TYPEID=81
KICKASM=82
RESOURCE=83
USES=84
CLOBBERS=85
BYTES=86
CYCLES=87
LOGIC_NOT=88
SIGNEDNESS=89
SIMPLETYPE=90
BOOLEAN=91
KICKASM_BODY=92
STRING=93
CHAR=94
NUMBER=95
NUMFLOAT=96
BINFLOAT=97
DECFLOAT=98
HEXFLOAT=99
NUMINT=100
BININTEGER=101
DECINTEGER=102
HEXINTEGER=103
NAME=104
WS=105
COMMENT_LINE=106
COMMENT_BLOCK=107
ASM_BYTE=108
ASM_MNEMONIC=109
ASM_IMM=110
ASM_COLON=111
ASM_COMMA=112
ASM_PAR_BEGIN=113
ASM_PAR_END=114
ASM_BRACKET_BEGIN=115
ASM_BRACKET_END=116
ASM_DOT=117
ASM_SHIFT_LEFT=118
ASM_SHIFT_RIGHT=119
ASM_PLUS=120
ASM_MINUS=121
ASM_LESS_THAN=122
ASM_GREATER_THAN=123
ASM_MULTIPLY=124
ASM_DIVIDE=125
ASM_CURLY_BEGIN=126
ASM_CURLY_END=127
ASM_NUMBER=128
ASM_NUMFLOAT=129
ASM_BINFLOAT=130
ASM_DECFLOAT=131
ASM_HEXFLOAT=132
ASM_NUMINT=133
ASM_BININTEGER=134
ASM_DECINTEGER=135
ASM_HEXINTEGER=136
ASM_CHAR=137
ASM_MULTI_REL=138
ASM_MULTI_NAME=139
ASM_NAME=140
ASM_WS=141
ASM_COMMENT_LINE=142
ASM_COMMENT_BLOCK=143
';'=8
'..'=11
'?'=12
@ -176,37 +176,38 @@ STATIC=143
'align'=52
'inline'=53
'volatile'=54
'interrupt'=55
'register'=56
'__address'=57
'__zp'=58
'__mem'=59
'__ssa'=60
'__ma'=61
'calling'=62
'var_model'=64
'if'=65
'else'=66
'while'=67
'do'=68
'for'=69
'switch'=70
'return'=71
'break'=72
'continue'=73
'asm'=74
'default'=75
'case'=76
'struct'=77
'enum'=78
'sizeof'=79
'typeid'=80
'kickasm'=81
'resource'=82
'uses'=83
'clobbers'=84
'bytes'=85
'cycles'=86
'!'=87
'.byte'=107
'#'=109
'static'=55
'interrupt'=56
'register'=57
'__address'=58
'__zp'=59
'__mem'=60
'__ssa'=61
'__ma'=62
'calling'=63
'var_model'=65
'if'=66
'else'=67
'while'=68
'do'=69
'for'=70
'switch'=71
'return'=72
'break'=73
'continue'=74
'asm'=75
'default'=76
'case'=77
'struct'=78
'enum'=79
'sizeof'=80
'typeid'=81
'kickasm'=82
'resource'=83
'uses'=84
'clobbers'=85
'bytes'=86
'cycles'=87
'!'=88
'.byte'=108
'#'=110

View File

@ -157,6 +157,30 @@ public class KickCParserBaseListener implements KickCParserListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDeclVariableInitKasm(KickCParser.DeclVariableInitKasmContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDeclVariableArray(KickCParser.DeclVariableArrayContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDeclVariableArray(KickCParser.DeclVariableArrayContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDeclVariableName(KickCParser.DeclVariableNameContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDeclVariableName(KickCParser.DeclVariableNameContext ctx) { }
/**
* {@inheritDoc}
*

View File

@ -97,6 +97,20 @@ public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDeclVariableInitKasm(KickCParser.DeclVariableInitKasmContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDeclVariableArray(KickCParser.DeclVariableArrayContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDeclVariableName(KickCParser.DeclVariableNameContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*

View File

@ -133,6 +133,30 @@ public interface KickCParserListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitDeclVariableInitKasm(KickCParser.DeclVariableInitKasmContext ctx);
/**
* Enter a parse tree produced by the {@code declVariableArray}
* labeled alternative in {@link KickCParser#declVariable}.
* @param ctx the parse tree
*/
void enterDeclVariableArray(KickCParser.DeclVariableArrayContext ctx);
/**
* Exit a parse tree produced by the {@code declVariableArray}
* labeled alternative in {@link KickCParser#declVariable}.
* @param ctx the parse tree
*/
void exitDeclVariableArray(KickCParser.DeclVariableArrayContext ctx);
/**
* Enter a parse tree produced by the {@code declVariableName}
* labeled alternative in {@link KickCParser#declVariable}.
* @param ctx the parse tree
*/
void enterDeclVariableName(KickCParser.DeclVariableNameContext ctx);
/**
* Exit a parse tree produced by the {@code declVariableName}
* labeled alternative in {@link KickCParser#declVariable}.
* @param ctx the parse tree
*/
void exitDeclVariableName(KickCParser.DeclVariableNameContext ctx);
/**
* Enter a parse tree produced by {@link KickCParser#declFunction}.
* @param ctx the parse tree

View File

@ -86,6 +86,20 @@ public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitDeclVariableInitKasm(KickCParser.DeclVariableInitKasmContext ctx);
/**
* Visit a parse tree produced by the {@code declVariableArray}
* labeled alternative in {@link KickCParser#declVariable}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDeclVariableArray(KickCParser.DeclVariableArrayContext ctx);
/**
* Visit a parse tree produced by the {@code declVariableName}
* labeled alternative in {@link KickCParser#declVariable}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDeclVariableName(KickCParser.DeclVariableNameContext ctx);
/**
* Visit a parse tree produced by {@link KickCParser#declFunction}.
* @param ctx the parse tree

View File

@ -567,11 +567,11 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Object visitDeclVariableInitExpr(KickCParser.DeclVariableInitExprContext ctx) {
String varName = (String) this.visit(ctx.declVariable());
KickCParser.ExprContext initializer = ctx.expr();
StatementSource statementSource = new StatementSource(ctx);
StatementSource declSource = new StatementSource((ParserRuleContext) ctx.parent.parent);
try {
String varName = ctx.NAME().getText();
KickCParser.ExprContext initializer = ctx.expr();
if(declVarStructMember && (initializer != null))
throw new CompileError("Initializer not supported inside structs " + declVarType.getTypeName(), statementSource);
if(initializer != null)
@ -593,14 +593,38 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
}
if(initializer != null)
PrePostModifierHandler.addPostModifiers(this, initializer, statementSource);
return null;
} catch(CompileError e) {
throw new CompileError(e.getMessage(), declSource);
}
return null;
}
@Override
public String visitDeclVariableName(KickCParser.DeclVariableNameContext ctx) {
return ctx.NAME().getText();
}
@Override
public String visitDeclVariableArray(KickCParser.DeclVariableArrayContext ctx) {
// Handle array type declaration by updating the declared type and the array spec
// TODO This fails for a comma-separated list with some array in the middle! Eg. char x, y[5], x;
SymbolType elementType = declVarType;
if(ctx.expr() != null) {
RValue sizeVal = (RValue) visit(ctx.expr());
declArraySpec = new ArraySpec((ConstantValue) sizeVal);
declVarType = new SymbolTypePointer(elementType);
} else {
declArraySpec = new ArraySpec();
declVarType = new SymbolTypePointer(elementType);
}
// Find the variable name
return (String) this.visit(ctx.declVariable());
}
/**
* Ensure that tha initializer value is a constant. Fail if it is not
* Ensure that the initializer value is a constant. Fail if it is not
*
* @param initValue The initializer value (result from {@link Initializers#constantify(RValue, Initializers.ValueTypeSpec, Program, StatementSource)}
* @param initializer The initializer
@ -621,7 +645,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
@Override
public Object visitDeclVariableInitKasm(KickCParser.DeclVariableInitKasmContext ctx) {
String varName = ctx.NAME().getText();
String varName = (String) this.visit(ctx.declVariable());
StatementSource statementSource = new StatementSource(ctx);
if(!(this.declVarType instanceof SymbolTypePointer) || declArraySpec == null) {
throw new CompileError("KickAsm initializers only supported for arrays " + declVarType.getTypeName(), statementSource);

View File

@ -1,7 +1,7 @@
byte[3] b;
byte[] c = {'c', 'm', 'l'};
byte[] d = "cml"z;
byte b[3];
byte c[] = {'c', 'm', 'l'};
byte d[] = "cml"z;
byte* SCREEN = $400;

View File

@ -16,8 +16,8 @@ signed char* xp = $f4;
signed char* yp = $f5;
// Pointers used to multiply perspective (d/z0-z) onto x- & y-coordinates. Points into mulf_sqr1 / mulf_sqr2
word* psp1 = $f6;
word* psp2 = $f8;
unsigned int* psp1 = $f6;
unsigned int* psp2 = $f8;
char* SCREEN = $400;
@ -25,8 +25,8 @@ void main() {
asm { sei }
sprites_init();
//mulf_init();
*psp1 = (word)mulf_sqr1;
*psp2 = (word)mulf_sqr2;
*psp1 = (unsigned int)mulf_sqr1;
*psp2 = (unsigned int)mulf_sqr2;
debug_print_init();
@ -36,18 +36,18 @@ void main() {
}
// Positions to rotate
signed char[8] xs = { -52, -52, -52, 0, 0, 52, 52, 52};
signed char[8] ys = { -52, 0, 52, -52, 52, -52, 0, 52};
signed char[8] zs = { 52, 52, 52, 52, 52, 52, 52, 52};
signed char xs[8] = { -52, -52, -52, 0, 0, 52, 52, 52};
signed char ys[8] = { -52, 0, 52, -52, 52, -52, 0, 52};
signed char zs[8] = { 52, 52, 52, 52, 52, 52, 52, 52};
// Rotated positions
signed char[8] xrs;
signed char[8] yrs;
signed char[8] zrs;
// Persepctive factors (from zrs)
signed char[8] pps;
// Rotated positions with persepctive
signed char[8] xps;
signed char[8] yps;
signed char xrs[8];
signed char yrs[8];
signed char zrs[8];
// Perspective factors (from zrs)
signed char pps[8];
// Rotated positions with perspective
signed char xps[8];
signed char yps[8];
signed char sx = 0;
signed char sy = 0;
@ -166,7 +166,7 @@ void sprites_init() {
}
// The rotation matrix
signed char[9] rotation_matrix;
signed char rotation_matrix[9];
// Prepare the 3x3 rotation matrix into rotation_matrix[]
// Angles sx, sy, sz are based on 2*PI=$100
@ -199,13 +199,13 @@ void calculate_matrix(signed char sx, signed char sy, signed char sz) {
void calculate_matrix_16(signed char sx, signed char sy, signed char sz) {
signed char t1 = sy-sz;
signed char t2 = sy+sz;
signed word cosh_t1 = (signed word){ COSH_HI[t1], COSH_LO[t1] };
signed word cosh_t2 = (signed word){ COSH_HI[t2], COSH_LO[t2] };
signed int cosh_t1 = (signed int){ COSH_HI[t1], COSH_LO[t1] };
signed int cosh_t2 = (signed int){ COSH_HI[t2], COSH_LO[t2] };
rotation_matrix[0] = round_hi(cosh_t1 + cosh_t2);
signed word sinh_t1 = (signed word){ SINH_HI[t1], SINH_LO[t1] };
signed word sinh_t2 = (signed word){ SINH_HI[t2], SINH_LO[t2] };
signed int sinh_t1 = (signed int){ SINH_HI[t1], SINH_LO[t1] };
signed int sinh_t2 = (signed int){ SINH_HI[t2], SINH_LO[t2] };
rotation_matrix[1] = round_hi(sinh_t1 - sinh_t2);
signed word sinh_sy = (signed word){ SINH_HI[sy], SINH_LO[sy] };
signed int sinh_sy = (signed int){ SINH_HI[sy], SINH_LO[sy] };
rotation_matrix[2] = round_hi(sinh_sy+sinh_sy);
signed char t3 = sx+sz;
signed char t4 = sx-sz;
@ -213,35 +213,35 @@ void calculate_matrix_16(signed char sx, signed char sy, signed char sz) {
signed char t6 = sx-t1; // = sx-sy+sz
signed char t7 = sx+t1; // = sx+sy-sz
signed char t8 = t2-sx; // = sy+sz-sx
signed word sinh_t3 = (signed word){ SINH_HI[t3], SINH_LO[t3] };
signed word sinh_t4 = (signed word){ SINH_HI[t4], SINH_LO[t4] };
signed word cosq_t5 = (signed word){ COSQ_HI[t5], COSH_LO[t5] };
signed word cosq_t6 = (signed word){ COSQ_HI[t6], COSH_LO[t6] };
signed word cosq_t7 = (signed word){ COSQ_HI[t7], COSH_LO[t7] };
signed word cosq_t8 = (signed word){ COSQ_HI[t8], COSH_LO[t8] };
signed int sinh_t3 = (signed int){ SINH_HI[t3], SINH_LO[t3] };
signed int sinh_t4 = (signed int){ SINH_HI[t4], SINH_LO[t4] };
signed int cosq_t5 = (signed int){ COSQ_HI[t5], COSH_LO[t5] };
signed int cosq_t6 = (signed int){ COSQ_HI[t6], COSH_LO[t6] };
signed int cosq_t7 = (signed int){ COSQ_HI[t7], COSH_LO[t7] };
signed int cosq_t8 = (signed int){ COSQ_HI[t8], COSH_LO[t8] };
rotation_matrix[3] = round_hi(sinh_t3 - sinh_t4 + cosq_t6 - cosq_t5 + cosq_t8 - cosq_t7);
rotation_matrix[7] = round_hi(sinh_t3 + sinh_t4 + cosq_t6 - cosq_t5 + cosq_t7 - cosq_t8);
signed word cosh_t3 = (signed word){ COSH_HI[t3], COSH_LO[t3] };
signed word cosh_t4 = (signed word){ COSH_HI[t4], COSH_LO[t4] };
signed word sinq_t5 = (signed word){ SINQ_HI[t5], SINH_LO[t5] };
signed word sinq_t6 = (signed word){ SINQ_HI[t6], SINH_LO[t6] };
signed word sinq_t7 = (signed word){ SINQ_HI[t7], SINH_LO[t7] };
signed word sinq_t8 = (signed word){ SINQ_HI[t8], SINH_LO[t8] };
signed int cosh_t3 = (signed int){ COSH_HI[t3], COSH_LO[t3] };
signed int cosh_t4 = (signed int){ COSH_HI[t4], COSH_LO[t4] };
signed int sinq_t5 = (signed int){ SINQ_HI[t5], SINH_LO[t5] };
signed int sinq_t6 = (signed int){ SINQ_HI[t6], SINH_LO[t6] };
signed int sinq_t7 = (signed int){ SINQ_HI[t7], SINH_LO[t7] };
signed int sinq_t8 = (signed int){ SINQ_HI[t8], SINH_LO[t8] };
rotation_matrix[4] = round_hi( cosh_t3 + cosh_t4 + sinq_t5 - sinq_t6 - sinq_t7 - sinq_t8);
rotation_matrix[6] = round_hi( cosh_t4 - cosh_t3 + sinq_t6 - sinq_t5 - sinq_t7 - sinq_t8);
signed char t9 = sy-sx;
signed char t10 = sy+sx;
signed word sinh_t9 = (signed word){ SINH_HI[t9], SINH_LO[t9] };
signed word sinh_t10 = (signed word){ SINH_HI[t10], SINH_LO[t10] };
signed int sinh_t9 = (signed int){ SINH_HI[t9], SINH_LO[t9] };
signed int sinh_t10 = (signed int){ SINH_HI[t10], SINH_LO[t10] };
rotation_matrix[5] = round_hi( sinh_t9 - sinh_t10);
signed word cosh_t9 = (signed word){ COSH_HI[t9], COSH_LO[t9] };
signed word cosh_t10 = (signed word){ COSH_HI[t10], COSH_LO[t10] };
signed int cosh_t9 = (signed int){ COSH_HI[t9], COSH_LO[t9] };
signed int cosh_t10 = (signed int){ COSH_HI[t10], COSH_LO[t10] };
rotation_matrix[8] = round_hi( cosh_t9 + cosh_t10 );
}
// Returns the rounded high char of the passed signed word.
// Returns the rounded high char of the passed signed int.
// Examines the lower char to determine whether to round up or down
signed char round_hi(signed word val) {
signed char round_hi(signed int val) {
return (signed char)>(val+$80);
}
@ -385,7 +385,7 @@ void rotate_matrix(signed char x, signed char y, signed char z) {
// mulf_sqr tables will contain f(x)=int(x*x) and g(x) = f(1-x).
// f(x) = >(( x * x ))
char[0x200] align(0x100) mulf_sqr1 = kickasm {{
char align(0x100) mulf_sqr1[0x200] = kickasm {{
.for(var i=0;i<$200;i++) {
.if(i<=159) { .byte round((i*i)/256) }
.if(i>159 && i<=351 ) { .byte round(((i-256)*(i-256))/256) }
@ -394,7 +394,7 @@ char[0x200] align(0x100) mulf_sqr1 = kickasm {{
}};
// g(x) = >((( 1 - x ) * ( 1 - x )))
char[0x200] align(0x100) mulf_sqr2 = kickasm {{
char align(0x100) mulf_sqr2[0x200] = kickasm {{
.for(var i=0;i<$200;i++) {
.if(i<=159) { .byte round((-i-1)*(-i-1)/256) }
.if(i>159 && i<=351 ) { .byte round(((255-i)*(255-i))/256) }
@ -419,8 +419,8 @@ byte[512] align($100) mulf_sqr2;
// Initialize the mulf_sqr multiplication tables with f(x)=int(x*x) and g(x) = f(1-x)
void mulf_init() {
signed word sqr = 0;
signed word add = 1;
signed int sqr = 0;
signed int add = 1;
for( byte i:0..128) {
byte val = >sqr;
mulf_sqr1[i] = val;
@ -447,7 +447,7 @@ kickasm(pc SPRITE, resource "balloon.png") {{
}}
// Perspective multiplication table containing (d/(z0-z)[z] for each z-value
signed char[0x100] align(0x100) PERSP_Z = kickasm {{
signed char align(0x100) PERSP_Z[0x100] = kickasm {{
{
.var d = 256.0
.var z0 = 6.0
@ -465,7 +465,7 @@ signed char[0x100] align(0x100) PERSP_Z = kickasm {{
// Sine and Cosine Tables
// Angles: $00=0, $80=PI,$100=2*PI
// Half Sine/Cosine: signed fixed [-$20;20]
signed char[0x140] align(0x40) SINH = kickasm {{
signed char align(0x40) SINH[0x140] = kickasm {{
{
.var min = -$2000
.var max = $2000
@ -479,7 +479,7 @@ signed char[0x140] align(0x40) SINH = kickasm {{
signed char* COSH = SINH+$40; // sin(x) = cos(x+PI/2)
// Quarter Sine/Cosine: signed fixed [-$10,$10]
signed char[0x140] align(0x40) SINQ = kickasm {{
signed char align(0x40) SINQ[0x140] = kickasm {{
{
.var min = -$1000
.var max = $1000
@ -495,7 +495,7 @@ signed char* COSQ = SINQ+$40; // sin(x) = cos(x+PI/2)
// 16 bit Sine and Cosine Tables
// Angles: $00=0, $80=PI,$100=2*PI
// Half Sine/Cosine: signed fixed [-$1f,$1f]
char[0x140] align(0x40) SINH_LO = kickasm {{
char align(0x40) SINH_LO[0x140] = kickasm {{
{
.var min = -$2000
.var max = $2000
@ -508,7 +508,7 @@ char[0x140] align(0x40) SINH_LO = kickasm {{
}};
char* COSH_LO = SINH_LO+$40; // sin(x) = cos(x+PI/2)
char[0x140] align(0x40) SINH_HI = kickasm {{
char align(0x40) SINH_HI[0x140] = kickasm {{
{
.var min = -$2000
.var max = $2000
@ -522,7 +522,7 @@ char[0x140] align(0x40) SINH_HI = kickasm {{
char* COSH_HI = SINH_HI+$40; // sin(x) = cos(x+PI/2)
// Quarter Sine/Cosine: signed fixed [-$0f,$0f]
char[0x140] align(0x40) SINQ_LO = kickasm {{
char align(0x40) SINQ_LO[0x140] = kickasm {{
{
.var min = -$1000
.var max = $1000
@ -535,7 +535,7 @@ char[0x140] align(0x40) SINQ_LO = kickasm {{
}};
char* COSQ_LO = SINQ_LO+$40; // sin(x) = cos(x+PI/2)
char[0x140] align(0x40) SINQ_HI = kickasm {{
char align(0x40) SINQ_HI[0x140] = kickasm {{
{
.var min = -$1000
.var max = $1000

View File

@ -11,14 +11,14 @@ signed char* yr = $f1;
signed char* zr = $f2;
// Pointers used to multiply perspective (d/z0-z) onto x- & y-coordinates. Points into mulf_sqr1 / mulf_sqr2.
word* psp1 = $f3;
word* psp2 = $f5;
unsigned int* psp1 = $f3;
unsigned int* psp2 = $f5;
void main() {
asm { sei }
mulf_init();
*psp1 = (word)mulf_sqr1;
*psp2 = (word)mulf_sqr2;
*psp1 = (unsigned int)mulf_sqr1;
*psp2 = (unsigned int)mulf_sqr2;
print_cls();
do_perspective($39, -$47, $36);
/*
@ -97,14 +97,14 @@ void perspective(signed char x, signed char y, signed char z) {
// - http://codebase64.org/doku.php?id=magazines:chacking16
// mulf_sqr tables will contain f(x)=int(x*x) and g(x) = f(1-x).
// f(x) = >(( x * x ))
char[512] align($100) mulf_sqr1;
char align($100) mulf_sqr1[512];
// g(x) = >((( 1 - x ) * ( 1 - x )))
char[512] align($100) mulf_sqr2;
char align($100) mulf_sqr2[512];
// Initialize the mulf_sqr multiplication tables with f(x)=int(x*x) and g(x) = f(1-x)
void mulf_init() {
signed word sqr = 0;
signed word add = 1;
signed int sqr = 0;
signed int add = 1;
for( char i:0..128) {
char val = >sqr;
mulf_sqr1[i] = val;
@ -121,7 +121,7 @@ void mulf_init() {
}
// Perspective multiplication table containing (d/(z0-z)[z] for each z-value
signed char[0x100] align(0x100) PERSP_Z = kickasm {{
signed char align(0x100) PERSP_Z[0x100] = kickasm {{
{
.var d = 256.0
.var z0 = 5.0

View File

@ -4,8 +4,8 @@ import "bitmap-draw.kc"
const char* SCREEN = $400;
const char* BITMAP = $2000;
char[] lines_x = { 60, 80, 110, 80, 60, 40, 10, 40, 60 };
char[] lines_y = { 10, 40, 60, 80, 110, 80, 60, 40, 10 };
char lines_x[] = { 60, 80, 110, 80, 60, 40, 10, 40, 60 };
char lines_y[] = { 10, 40, 60, 80, 110, 80, 60, 40, 10 };
char lines_cnt = 8;
void main() {

View File

@ -68,7 +68,7 @@ void print_str_at(char* str, char* at) {
// Render 8x8 char (ch) as pixels on char canvas #pos
void plot_chargen(char pos, char ch, char shift) {
asm { sei }
char* chargen = CHARGEN+(word)ch*8;
char* chargen = CHARGEN+(unsigned int)ch*8;
if(shift!=0) {
chargen = chargen + $0800;
}

View File

@ -8,7 +8,7 @@
import "print.kc"
signed char[] vals = {-95, -64, -32, -16, 0, 16, 32, 64, 95};
signed char vals[] = {-95, -64, -32, -16, 0, 16, 32, 64, 95};
void main() {
init_screen();
@ -71,7 +71,7 @@ signed char fmul8(signed char a, signed char b) {
// mulf_sqr tables will contain f(x)=int(x*x) and g(x) = f(1-x).
// f(x) = >(( x * x ))
char[0x200] align(0x100) mulf_sqr1 = kickasm {{
char align(0x100) mulf_sqr1[0x200] = kickasm {{
.for(var i=0;i<$200;i++) {
.if(i<=159) { .byte round((i*i)/256) }
.if(i>159 && i<=351 ) { .byte round(((i-256)*(i-256))/256) }
@ -81,7 +81,7 @@ char[0x200] align(0x100) mulf_sqr1 = kickasm {{
// g(x) = >((( 1 - x ) * ( 1 - x )))
char[0x200] align(0x100) mulf_sqr2 = kickasm {{
char align(0x100) mulf_sqr2[0x200] = kickasm {{
.for(var i=0;i<$200;i++) {
.if(i<=159) { .byte round((-i-1)*(-i-1)/256) }
.if(i>159 && i<=351 ) { .byte round(((255-i)*(255-i))/256) }

View File

@ -56,7 +56,7 @@ void fire(unsigned char* screenbase) {
// Make a fire-friendly charset in chars $00-$3f of the passed charset
void makecharset(char* charset) {
const unsigned char[8] bittab = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
const unsigned char bittab[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
for (unsigned char *font = charset; font != (charset+(1*8)); ++font)
*font = 0x00;
for (unsigned char *font = (charset+(64*8)); font != (charset+(256*8)); ++font)
@ -78,7 +78,7 @@ void makecharset(char* charset) {
// Fill a screen (1000 chars) with a specific char
void fillscreen(unsigned char* screen, unsigned char fill) {
for( unsigned word i : 0..999) {
for( unsigned int i : 0..999) {
*screen++ = fill;
}
}

View File

@ -1,5 +1,5 @@
// SID registers for random number generation
const word* SID_VOICE3_FREQ = $d40e;
const unsigned int* SID_VOICE3_FREQ = $d40e;
const char* SID_VOICE3_FREQ_LOW = $d40e;
const char* SID_VOICE3_FREQ_HIGH = $d40f;
const char* SID_VOICE3_CONTROL = $d412;

View File

@ -6,7 +6,7 @@ import "string"
const char* SCREEN = 0x0400;
const char* FONT_ORIGINAL = 0x2000;
const char* FONT_COMPRESSED = 0x2800;
char[0x100] align(0x100) FONT_COMPRESSED_MAP;
char align(0x100) FONT_COMPRESSED_MAP[0x100];
void main() {
// Create 2x2 font from CHARGEN

View File

@ -8,7 +8,7 @@ import "c64"
// Sprite file
#pragma data_seg(Sprite)
export char[] SPRITE = kickasm(resource "sprite.png") {{
export char SPRITE[] = kickasm(resource "sprite.png") {{
.var pic = LoadPicture("sprite.png", List().add($000000, $ffffff))
.for (var y=0; y<21; y++)
.for (var x=0;x<3; x++)

View File

@ -29,5 +29,5 @@ void fillscreen(char c) {
*screen = c+base[i++];
}
char[256] base;
char base[256];

View File

@ -5,7 +5,7 @@ import "multiplexer"
// Location of screen & sprites
char* SCREEN = $400;
char[0x100] align(0x100) YSIN = kickasm {{
char align(0x100) YSIN[0x100] = kickasm {{
.var min = 50
.var max = 250-21
.var ampl = max-min;

View File

@ -5,7 +5,7 @@
import "c64"
const unsigned int SAMPLE_SIZE = 0x6100;
char[SAMPLE_SIZE] SAMPLE = kickasm(resource "moments_sample.bin") {{ .import binary "moments_sample.bin" }};
char SAMPLE[SAMPLE_SIZE] = kickasm(resource "moments_sample.bin") {{ .import binary "moments_sample.bin" }};
volatile char* sample = SAMPLE;

View File

@ -13,7 +13,7 @@ import "sid"
const unsigned char* SCREEN1 = $2800;
const unsigned char* CHARSET = $2000;
const unsigned char[0x100] align(0x100) SINTABLE = kickasm {{
const unsigned char align(0x100) SINTABLE[0x100] = kickasm {{
.for(var i=0;i<$100;i++)
.byte round(127.5+127.5*sin(toRadians(360*i/256)))
}};
@ -40,8 +40,8 @@ unsigned char c2B = 0;
// Render plasma to the passed screen
void doplasma(unsigned char* screen) {
unsigned char[40] xbuf;
unsigned char[25] ybuf;
unsigned char xbuf[40];
unsigned char ybuf[25];
unsigned char c1a = c1A;
unsigned char c1b = c1B;
@ -79,7 +79,7 @@ void doplasma(unsigned char* screen) {
// Make a plasma-friendly charset where the chars are randomly filled
void makecharset(unsigned char* charset) {
const unsigned char[8] bittab = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
const unsigned char bittab[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
sid_rnd_init();
print_cls();
for (unsigned int c = 0; c < 0x100; ++c) {

View File

@ -12,7 +12,7 @@ const char* SCREEN1 = 0x2800;
const char* SCREEN2 = 0x2c00;
const char* CHARSET = 0x2000;
const char[0x100] align(0x100) SINTABLE = kickasm {{
const char align(0x100) SINTABLE[0x100] = kickasm {{
.for(var i=0;i<$100;i++)
.byte round(127.5+127.5*sin(2*PI*i/256))
}};
@ -41,8 +41,8 @@ char c2B = 0;
// Render plasma to the passed screen
void doplasma (char* screen) {
char[40] xbuf;
char[25] ybuf;
char xbuf[40];
char ybuf[25];
char c1a = c1A;
char c1b = c1B;
@ -72,7 +72,7 @@ void doplasma (char* screen) {
// Make a plasma-friendly charset where the chars are randomly filled
void makecharset(char* charset) {
const char[8] bittab = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
const char bittab[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
sid_rnd_init();
print_cls();
for (unsigned int c = 0; c < 0x100; ++c) {

View File

@ -11,7 +11,7 @@ void main() {
} while (true);
}
char[] rastercols = { $b, $0, $b, $b, $c, $b, $c, $c, $f, $c, $f, $f, $1, $f, $1, $1, $f, $1, $f, $f, $c, $f, $c, $c, $b, $c, $b, $b, $0, $b, $0, $ff };
char rastercols[] = { $b, $0, $b, $b, $c, $b, $c, $c, $f, $c, $f, $f, $1, $f, $1, $1, $f, $1, $f, $f, $c, $f, $c, $c, $b, $c, $b, $b, $0, $b, $0, $ff };
void raster() {

View File

@ -10,7 +10,7 @@ char* SCREEN = $0400;
// Sine and Cosine tables
// Angles: $00=0, $80=PI,$100=2*PI
// Sine/Cosine: signed fixed [-$7f,$7f]
char[0x140] align(0x40) SIN = kickasm {{
char align(0x40) SIN[0x140] = kickasm {{
.for(var i=0;i<$140;i++)
.byte >round($7fff*sin(i*2*PI/256))
}};
@ -34,8 +34,8 @@ void init() {
}
// Positions to rotate
signed char[8] xs = { -70, -70, -70, 0, 0, 70, 70, 70};
signed char[8] ys = { -70, 0, 70, -70, 70, -70, 0, 70};
signed char xs[8] = { -70, -70, -70, 0, 0, 70, 70, 70};
signed char ys[8] = { -70, 0, 70, -70, 70, -70, 0, 70};
void anim() {
char angle = 0;
@ -50,12 +50,12 @@ void anim() {
signed char x = xs[i]; // signed fixed[7.0]
signed char y = ys[i]; // signed fixed[7.0]
mulf8s_prepare(cos_a);
signed word xr = mulf8s_prepared(x)*2; // signed fixed[8.8]
signed word yr = mulf8s_prepared(y)*2; // signed fixed[8.8]
signed int xr = mulf8s_prepared(x)*2; // signed fixed[8.8]
signed int yr = mulf8s_prepared(y)*2; // signed fixed[8.8]
mulf8s_prepare(sin_a);
xr -= mulf8s_prepared(y)*2; // signed fixed[8.8]
yr += mulf8s_prepared(x)*2; // signed fixed[8.8]
signed word xpos = ((signed char) >xr) + 24 /*border*/ + 149 /*center*/;
signed int xpos = ((signed char) >xr) + 24 /*border*/ + 149 /*center*/;
sprite_msb = sprite_msb/2;
if(>xpos!=0) {
sprite_msb |= $80;
@ -68,7 +68,7 @@ void anim() {
*SPRITES_XMSB = sprite_msb;
angle++;
// Calculate the cycle count - 0x12 is the base usage of start/read
dword cyclecount = clock()-CLOCKS_PER_INIT;
unsigned long cyclecount = clock()-CLOCKS_PER_INIT;
// Print cycle count
print_dword_at(cyclecount, SCREEN);
*BORDERCOL = LIGHT_BLUE;

View File

@ -2,7 +2,7 @@ const char* SCREEN = $0400;
const char* RASTER = $d012;
const char* BGCOL = $d020;
const char* SCROLL = $d016;
const char[] TEXT = "-= this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. =- ";
const char TEXT[] = "-= this is rex of camelot testing a scroller created in kickc. kickc is an optimizing c-compiler for 6502 assembler. =- ";
void main() {
fillscreen(SCREEN, $20);

View File

@ -3,9 +3,9 @@ import "basic-floats"
import "print"
const char sinlen_x = 221;
const char[221] sintab_x;
const char sintab_x[221];
const char sinlen_y = 197;
const char[197] sintab_y;
const char sintab_y[197];
const char* sprites = $2000;
const char* SCREEN = $400;
@ -53,7 +53,7 @@ void progress_init(char* line) {
// Done by increasing the character until the idx is 8 and then moving to the next char
void progress_inc() {
// Progress characters
const char[] progress_chars = { $20, $65, $74, $75, $61, $f6, $e7, $ea, $e0};
const char progress_chars[] = { $20, $65, $74, $75, $61, $f6, $e7, $ea, $e0};
if(++progress_idx==8) {
*progress_cursor = progress_chars[8];
progress_cursor++;
@ -121,7 +121,7 @@ void place_sprites() {
}
void gen_sprites() {
char[] cml = "camelot"z;
char cml[] = "camelot"z;
char* spr = sprites;
for( char i : 0..6 ) {
gen_chargen_sprite(cml[i], spr);
@ -181,9 +181,9 @@ void gen_chargen_sprite(char ch, char* sprite) {
// - min is the minimum value of the generated sinus
// - max is the maximum value of the generated sinus
void gen_sintab(char* sintab, char length, char min, char max) {
char[] f_i = {0, 0, 0, 0, 0}; // i * 2 * PI
char[] f_min = {0, 0, 0, 0, 0}; // amplitude/2 + min
char[] f_amp = {0, 0, 0, 0, 0}; // amplitude/2
char f_i[] = {0, 0, 0, 0, 0}; // i * 2 * PI
char f_min[] = {0, 0, 0, 0, 0}; // amplitude/2 + min
char f_amp[] = {0, 0, 0, 0, 0}; // amplitude/2
char* f_2pi = $e2e5; // 2 * PI
setFAC((unsigned int)max); // fac = max
setARGtoFAC(); // arg = max

View File

@ -32,7 +32,7 @@ void loop() {
}
// Array containing the zeropage code to be transferred to zeropage before execution
char[] zpCodeData = kickasm {{
char zpCodeData[] = kickasm {{
.segmentout [segments="ZpCode"]
}};

View File

@ -40,13 +40,13 @@ main: {
sei
// sprites_init()
jsr sprites_init
// *psp1 = (word)mulf_sqr1
// *psp1 = (unsigned int)mulf_sqr1
//mulf_init();
lda #<mulf_sqr1
sta psp1
lda #>mulf_sqr1
sta psp1+1
// *psp2 = (word)mulf_sqr2
// *psp2 = (unsigned int)mulf_sqr2
lda #<mulf_sqr2
sta psp2
lda #>mulf_sqr2
@ -1226,9 +1226,9 @@ sprites_init: {
xrs: .fill 8, 0
yrs: .fill 8, 0
zrs: .fill 8, 0
// Persepctive factors (from zrs)
// Perspective factors (from zrs)
pps: .fill 8, 0
// Rotated positions with persepctive
// Rotated positions with perspective
xps: .fill 8, 0
yps: .fill 8, 0
// The rotation matrix

View File

@ -6287,9 +6287,9 @@ sprites_init: {
xrs: .fill 8, 0
yrs: .fill 8, 0
zrs: .fill 8, 0
// Persepctive factors (from zrs)
// Perspective factors (from zrs)
pps: .fill 8, 0
// Rotated positions with persepctive
// Rotated positions with perspective
xps: .fill 8, 0
yps: .fill 8, 0
// The rotation matrix
@ -8771,9 +8771,9 @@ sprites_init: {
xrs: .fill 8, 0
yrs: .fill 8, 0
zrs: .fill 8, 0
// Persepctive factors (from zrs)
// Perspective factors (from zrs)
pps: .fill 8, 0
// Rotated positions with persepctive
// Rotated positions with perspective
xps: .fill 8, 0
yps: .fill 8, 0
// The rotation matrix
@ -9685,14 +9685,14 @@ main: {
// [5] call sprites_init
jsr sprites_init
// main::@1
// *psp1 = (word)mulf_sqr1
// *psp1 = (unsigned int)mulf_sqr1
// [6] *((const word*) psp1) ← (word)(const byte*) mulf_sqr1 -- _deref_pwuc1=vwuc2
//mulf_init();
lda #<mulf_sqr1
sta psp1
lda #>mulf_sqr1
sta psp1+1
// *psp2 = (word)mulf_sqr2
// *psp2 = (unsigned int)mulf_sqr2
// [7] *((const word*) psp2) ← (word)(const byte*) mulf_sqr2 -- _deref_pwuc1=vwuc2
lda #<mulf_sqr2
sta psp2
@ -11363,9 +11363,9 @@ sprites_init: {
xrs: .fill 8, 0
yrs: .fill 8, 0
zrs: .fill 8, 0
// Persepctive factors (from zrs)
// Perspective factors (from zrs)
pps: .fill 8, 0
// Rotated positions with persepctive
// Rotated positions with perspective
xps: .fill 8, 0
yps: .fill 8, 0
// The rotation matrix

View File

@ -19,12 +19,12 @@ main: {
sei
// mulf_init()
jsr mulf_init
// *psp1 = (word)mulf_sqr1
// *psp1 = (unsigned int)mulf_sqr1
lda #<mulf_sqr1
sta psp1
lda #>mulf_sqr1
sta psp1+1
// *psp2 = (word)mulf_sqr2
// *psp2 = (unsigned int)mulf_sqr2
lda #<mulf_sqr2
sta psp2
lda #>mulf_sqr2

View File

@ -3511,13 +3511,13 @@ main: {
// [88] phi from main to mulf_init [phi:main->mulf_init]
jsr mulf_init
// main::@1
// *psp1 = (word)mulf_sqr1
// *psp1 = (unsigned int)mulf_sqr1
// [6] *((const word*) psp1) ← (word)(const byte*) mulf_sqr1 -- _deref_pwuc1=vwuc2
lda #<mulf_sqr1
sta psp1
lda #>mulf_sqr1
sta psp1+1
// *psp2 = (word)mulf_sqr2
// *psp2 = (unsigned int)mulf_sqr2
// [7] *((const word*) psp2) ← (word)(const byte*) mulf_sqr2 -- _deref_pwuc1=vwuc2
lda #<mulf_sqr2
sta psp2

View File

@ -270,18 +270,18 @@ plot_chargen: {
.label y = 8
// asm
sei
// (word)ch
// (unsigned int)ch
sta.z __0
lda #0
sta.z __0+1
// (word)ch*8
// (unsigned int)ch*8
asl.z __1
rol.z __1+1
asl.z __1
rol.z __1+1
asl.z __1
rol.z __1+1
// chargen = CHARGEN+(word)ch*8
// chargen = CHARGEN+(unsigned int)ch*8
clc
lda.z chargen
adc #<CHARGEN

View File

@ -4587,12 +4587,12 @@ plot_chargen: {
// asm
// asm { sei }
sei
// (word)ch
// (unsigned int)ch
// [73] (word~) plot_chargen::$0 ← (word)(byte) plot_chargen::ch#2 -- vwuz1=_word_vbuaa
sta.z __0
lda #0
sta.z __0+1
// (word)ch*8
// (unsigned int)ch*8
// [74] (word~) plot_chargen::$1 ← (word~) plot_chargen::$0 << (byte) 3 -- vwuz1=vwuz1_rol_3
asl.z __1
rol.z __1+1
@ -4600,7 +4600,7 @@ plot_chargen: {
rol.z __1+1
asl.z __1
rol.z __1+1
// chargen = CHARGEN+(word)ch*8
// chargen = CHARGEN+(unsigned int)ch*8
// [75] (byte*) plot_chargen::chargen#0 ← (const byte*) CHARGEN + (word~) plot_chargen::$1 -- pbuz1=pbuc1_plus_vwuz1
clc
lda.z chargen

View File

@ -401,7 +401,7 @@ fillscreen: {
bne !+
inc.z screen+1
!:
// for( unsigned word i : 0..999)
// for( unsigned int i : 0..999)
inc.z i
bne !+
inc.z i+1

View File

@ -4013,7 +4013,7 @@ fillscreen: {
bne !+
inc.z screen+1
!:
// for( unsigned word i : 0..999)
// for( unsigned int i : 0..999)
// [95] (word) fillscreen::i#1 ← ++ (word) fillscreen::i#2 -- vwuz1=_inc_vwuz1
inc.z i
bne !+