mirror of
https://github.com/irmen/prog8.git
synced 2024-07-10 23:29:02 +00:00
flipped the order of the parameters of mkword() so it's now mkword(msb, lsb) for easier readability
This commit is contained in:
parent
f41192a52a
commit
bd9ebf4603
@ -193,7 +193,7 @@ private fun writeAssembly(programAst: Program, errors: ErrorReporter, outputDir:
|
|||||||
programAst.processAstBeforeAsmGeneration(errors)
|
programAst.processAstBeforeAsmGeneration(errors)
|
||||||
errors.handle()
|
errors.handle()
|
||||||
|
|
||||||
// printAst(programAst)
|
printAst(programAst)
|
||||||
|
|
||||||
val assembly = CompilationTarget.asmGenerator(
|
val assembly = CompilationTarget.asmGenerator(
|
||||||
programAst,
|
programAst,
|
||||||
|
@ -448,7 +448,9 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun funcMkword(fcall: IFunctionCall, func: FSignature) {
|
private fun funcMkword(fcall: IFunctionCall, func: FSignature) {
|
||||||
translateFunctionArguments(fcall.args, func)
|
// trick: push the args in reverse order (msb first, lsb second) this saves some instructions
|
||||||
|
asmgen.translateExpression(fcall.args[1])
|
||||||
|
asmgen.translateExpression(fcall.args[0])
|
||||||
asmgen.out(" inx | lda $ESTACK_LO_HEX,x | sta $ESTACK_HI_PLUS1_HEX,x")
|
asmgen.out(" inx | lda $ESTACK_LO_HEX,x | sta $ESTACK_HI_PLUS1_HEX,x")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ val BuiltinFunctions = mapOf(
|
|||||||
"all" to FSignature(true, listOf(FParam("values", ArrayDatatypes)), DataType.UBYTE) { a, p, prg -> collectionArg(a, p, prg, ::builtinAll) },
|
"all" to FSignature(true, listOf(FParam("values", ArrayDatatypes)), DataType.UBYTE) { a, p, prg -> collectionArg(a, p, prg, ::builtinAll) },
|
||||||
"lsb" to FSignature(true, listOf(FParam("value", setOf(DataType.UWORD, DataType.WORD))), DataType.UBYTE) { a, p, prg -> oneIntArgOutputInt(a, p, prg) { x: Int -> x and 255 }},
|
"lsb" to FSignature(true, listOf(FParam("value", setOf(DataType.UWORD, DataType.WORD))), DataType.UBYTE) { a, p, prg -> oneIntArgOutputInt(a, p, prg) { x: Int -> x and 255 }},
|
||||||
"msb" to FSignature(true, listOf(FParam("value", setOf(DataType.UWORD, DataType.WORD))), DataType.UBYTE) { a, p, prg -> oneIntArgOutputInt(a, p, prg) { x: Int -> x ushr 8 and 255}},
|
"msb" to FSignature(true, listOf(FParam("value", setOf(DataType.UWORD, DataType.WORD))), DataType.UBYTE) { a, p, prg -> oneIntArgOutputInt(a, p, prg) { x: Int -> x ushr 8 and 255}},
|
||||||
"mkword" to FSignature(true, listOf(FParam("lsb", setOf(DataType.UBYTE)), FParam("msb", setOf(DataType.UBYTE))), DataType.UWORD, ::builtinMkword),
|
"mkword" to FSignature(true, listOf(FParam("msb", setOf(DataType.UBYTE)), FParam("lsb", setOf(DataType.UBYTE))), DataType.UWORD, ::builtinMkword),
|
||||||
"rnd" to FSignature(true, emptyList(), DataType.UBYTE),
|
"rnd" to FSignature(true, emptyList(), DataType.UBYTE),
|
||||||
"rndw" to FSignature(true, emptyList(), DataType.UWORD),
|
"rndw" to FSignature(true, emptyList(), DataType.UWORD),
|
||||||
"rndf" to FSignature(true, emptyList(), DataType.FLOAT),
|
"rndf" to FSignature(true, emptyList(), DataType.FLOAT),
|
||||||
@ -323,9 +323,9 @@ private fun builtinLen(args: List<Expression>, position: Position, program: Prog
|
|||||||
|
|
||||||
private fun builtinMkword(args: List<Expression>, position: Position, program: Program): NumericLiteralValue {
|
private fun builtinMkword(args: List<Expression>, position: Position, program: Program): NumericLiteralValue {
|
||||||
if (args.size != 2)
|
if (args.size != 2)
|
||||||
throw SyntaxError("mkword requires lsb and msb arguments", position)
|
throw SyntaxError("mkword requires msb and lsb arguments", position)
|
||||||
val constLsb = args[0].constValue(program) ?: throw NotConstArgumentException()
|
val constMsb = args[0].constValue(program) ?: throw NotConstArgumentException()
|
||||||
val constMsb = args[1].constValue(program) ?: throw NotConstArgumentException()
|
val constLsb = args[1].constValue(program) ?: throw NotConstArgumentException()
|
||||||
val result = (constMsb.number.toInt() shl 8) or constLsb.number.toInt()
|
val result = (constMsb.number.toInt() shl 8) or constLsb.number.toInt()
|
||||||
return NumericLiteralValue(DataType.UWORD, result, position)
|
return NumericLiteralValue(DataType.UWORD, result, position)
|
||||||
}
|
}
|
||||||
|
@ -586,10 +586,10 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
|
|||||||
} else if (amount >= 8) {
|
} else if (amount >= 8) {
|
||||||
val lsb = TypecastExpression(expr.left, DataType.UBYTE, true, expr.position)
|
val lsb = TypecastExpression(expr.left, DataType.UBYTE, true, expr.position)
|
||||||
if (amount == 8) {
|
if (amount == 8) {
|
||||||
return FunctionCall(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(NumericLiteralValue.optimalInteger(0, expr.position), lsb), expr.position)
|
return FunctionCall(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(lsb, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position)
|
||||||
}
|
}
|
||||||
val shifted = BinaryExpression(lsb, "<<", NumericLiteralValue.optimalInteger(amount - 8, expr.position), expr.position)
|
val shifted = BinaryExpression(lsb, "<<", NumericLiteralValue.optimalInteger(amount - 8, expr.position), expr.position)
|
||||||
return FunctionCall(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(NumericLiteralValue.optimalInteger(0, expr.position), shifted), expr.position)
|
return FunctionCall(IdentifierReference(listOf("mkword"), expr.position), mutableListOf(shifted, NumericLiteralValue.optimalInteger(0, expr.position)), expr.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
@ -748,8 +748,9 @@ msb(x)
|
|||||||
sgn(x)
|
sgn(x)
|
||||||
Get the sign of the value. Result is -1, 0 or 1 (negative, zero, positive).
|
Get the sign of the value. Result is -1, 0 or 1 (negative, zero, positive).
|
||||||
|
|
||||||
mkword(lsb, msb)
|
mkword(msb, lsb)
|
||||||
Efficiently create a word value from two bytes (the lsb and the msb). Avoids multiplication and shifting.
|
Efficiently create a word value from two bytes (the msb and the lsb). Avoids multiplication and shifting.
|
||||||
|
So mkword($80, $22) results in $8022.
|
||||||
|
|
||||||
any(x)
|
any(x)
|
||||||
1 ('true') if any of the values in the array value x is 'true' (not zero), else 0 ('false')
|
1 ('true') if any of the values in the array value x is 'true' (not zero), else 0 ('false')
|
||||||
|
@ -159,7 +159,7 @@ main {
|
|||||||
ubyte sx = rotatedx[i] / persp + width/2 as ubyte + 20
|
ubyte sx = rotatedx[i] / persp + width/2 as ubyte + 20
|
||||||
ubyte sy = rotatedy[i] / persp + height/2 as ubyte + 40
|
ubyte sy = rotatedy[i] / persp + height/2 as ubyte + 40
|
||||||
|
|
||||||
c64.SPXYW[i] = mkword(sx, sy)
|
c64.SPXYW[i] = mkword(sy, sx)
|
||||||
|
|
||||||
if(zc < 30*128)
|
if(zc < 30*128)
|
||||||
c64.SPRPTR[i] = $2000/64 +1 ; large ball
|
c64.SPRPTR[i] = $2000/64 +1 ; large ball
|
||||||
|
@ -27,7 +27,7 @@ main {
|
|||||||
c64.CHROUT(bye[char])
|
c64.CHROUT(bye[char])
|
||||||
|
|
||||||
|
|
||||||
float clock_seconds = ((mkword(c64.TIME_LO, c64.TIME_MID) as float) + (c64.TIME_HI as float)*65536.0) / 60
|
float clock_seconds = ((mkword(c64.TIME_MID, c64.TIME_LO) as float) + (c64.TIME_HI as float)*65536.0) / 60
|
||||||
float hours = floor(clock_seconds / 3600)
|
float hours = floor(clock_seconds / 3600)
|
||||||
clock_seconds -= hours*3600
|
clock_seconds -= hours*3600
|
||||||
float minutes = floor(clock_seconds / 60)
|
float minutes = floor(clock_seconds / 60)
|
||||||
|
@ -8,19 +8,14 @@ main {
|
|||||||
sub start() {
|
sub start() {
|
||||||
|
|
||||||
ubyte ub
|
ubyte ub
|
||||||
uword uw
|
uword uw = $ee44
|
||||||
word w
|
ubyte vlsb = $11
|
||||||
byte b
|
ubyte vmsb = $ff
|
||||||
float f
|
|
||||||
|
|
||||||
|
uw = mkword(vmsb, vlsb) ; todo flip the order of the operands , MSB first
|
||||||
ub = 4 | ub | 2
|
c64scr.print_uwhex(uw, 1)
|
||||||
ub = ub | 2 | 7
|
uw = mkword($ee, $22) ; todo flip the order of the operands , MSB first
|
||||||
ub = 4 | 2 | ub
|
c64scr.print_uwhex(uw, 1)
|
||||||
|
|
||||||
ub = 4 + ub + 2
|
|
||||||
ub = ub + 2 + 7
|
|
||||||
ub = 4 + 2 + ub
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,18 +47,17 @@ irq {
|
|||||||
ubyte angle
|
ubyte angle
|
||||||
|
|
||||||
sub irq() {
|
sub irq() {
|
||||||
c64.EXTCOL--
|
|
||||||
angle++
|
angle++
|
||||||
c64.MSIGX=0
|
c64.MSIGX=0
|
||||||
ubyte @zp spri
|
ubyte @zp spri
|
||||||
for spri in 7 downto 0 {
|
for spri in 7 downto 0 {
|
||||||
|
c64.EXTCOL++
|
||||||
uword @zp x = sin8u(angle*2-spri*16) as uword + 50
|
uword @zp x = sin8u(angle*2-spri*16) as uword + 50
|
||||||
ubyte @zp y = cos8u(angle*3-spri*16) / 2 + 70
|
ubyte @zp y = cos8u(angle*3-spri*16) / 2 + 70
|
||||||
c64.SPXYW[spri] = mkword(lsb(x), y)
|
c64.SPXYW[spri] = mkword(y, lsb(x))
|
||||||
c64.MSIGX <<= 1
|
c64.MSIGX <<= 1
|
||||||
if msb(x) c64.MSIGX++
|
if msb(x) c64.MSIGX++
|
||||||
c64.EXTCOL++
|
|
||||||
}
|
}
|
||||||
c64.EXTCOL-=7
|
c64.EXTCOL-=8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user