random number stuff

This commit is contained in:
Irmen de Jong 2018-12-06 01:25:06 +01:00
parent 0c64d7ffe5
commit 80c69d83c6
4 changed files with 48 additions and 7 deletions

View File

@ -1,11 +1,50 @@
%output raw
%launcher none
%import c64utils
%import mathlib
%option enable_floats
~ main {
memory ubyte[40*25] Screen = $0400
sub start() {
A, Y = c64flt.GETADRAY()
;math.randseed($5566) ; if you want the exact same number sequence every restart of the program
;math.randseedr()
c64flt.print_float_ln(rndf())
c64flt.print_float_ln(rndf())
c64flt.print_float_ln(rndf())
return
ubyte loop
c64scr.print_string("random bytes:\n")
for loop in 1 to 5 {
rsave() ; @todo automatic based on clobbers declaration
c64scr.print_byte_decimal(loop)
c64.CHROUT(':')
c64.CHROUT(' ')
ubyte ubr = rnd()
c64scr.print_byte_decimal(ubr)
rrestore()
c64.CHROUT('\n')
}
c64scr.print_string("\nrandom words:\n")
for loop in 1 to 5 {
rsave() ; @todo automatic based on clobbers declaration
c64scr.print_byte_decimal(loop)
c64.CHROUT(':')
c64.CHROUT(' ')
uword uwr = rndw()
c64scr.print_word_decimal(uwr)
rrestore()
c64.CHROUT('\n')
}
c64scr.print_string("\nrandom floats:\n")
for loop in 1 to 5 {
c64scr.print_byte_decimal(loop)
c64.CHROUT(':')
c64.CHROUT(' ')
float f = rndf()
c64flt.print_float_ln(f)
}
}
}

View File

@ -161,7 +161,7 @@ class AstIdentifiersChecker(val heap: HeapValues) : IAstProcessor {
}
}
null -> {}
else -> checkResult.add(SyntaxError("loop variables can only be a byte or word", forLoop.position))
else -> checkResult.add(SyntaxError("loop variables can only be an unsigned byte or unsigned word", forLoop.position)) // TODO loops over signed values
}
}
return super.process(forLoop)

View File

@ -561,7 +561,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
" inx | lda ${ESTACK_LO.toHex()},x | ldy ${ESTACK_HI.toHex()},x | sta ${ins.callLabel} | sty ${ins.callLabel}+1"
}
Opcode.POP_VAR_FLOAT -> {
" lda #<${ins.callLabel} | ldy #>${ins.callLabel} | jsr prog8_lib.pop_var_float"
" lda #<${ins.callLabel} | ldy #>${ins.callLabel} | jsr prog8_lib.pop_float"
}
Opcode.INC_VAR_UB, Opcode.INC_VAR_B -> {

View File

@ -1,6 +1,8 @@
package prog8.stackvm
import prog8.ast.DataType
import prog8.ast.Position
import prog8.ast.unescape
import prog8.compiler.HeapValues
import prog8.compiler.intermediate.*
import java.io.File
@ -89,7 +91,7 @@ class Program (val name: String,
DataType.STR,
DataType.STR_P,
DataType.STR_S,
DataType.STR_PS -> heap.add(it.second, it.third.substring(1, it.third.length-1))
DataType.STR_PS -> heap.add(it.second, unescape(it.third.substring(1, it.third.length-1), Position("<stackvmsource>", 0, 0, 0)))
DataType.ARRAY_UB, DataType.ARRAY_B,
DataType.ARRAY_UW, DataType.ARRAY_W -> {
val numbers = it.third.substring(1, it.third.length-1).split(',')