mirror of
https://github.com/irmen/prog8.git
synced 2024-10-17 10:24:55 +00:00
random number stuff
This commit is contained in:
parent
0c64d7ffe5
commit
80c69d83c6
@ -1,11 +1,50 @@
|
|||||||
%output raw
|
|
||||||
%launcher none
|
|
||||||
%import c64utils
|
%import c64utils
|
||||||
|
%import mathlib
|
||||||
|
%option enable_floats
|
||||||
|
|
||||||
~ main {
|
~ main {
|
||||||
memory ubyte[40*25] Screen = $0400
|
|
||||||
|
|
||||||
sub start() {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ class AstIdentifiersChecker(val heap: HeapValues) : IAstProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
null -> {}
|
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)
|
return super.process(forLoop)
|
||||||
|
@ -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"
|
" inx | lda ${ESTACK_LO.toHex()},x | ldy ${ESTACK_HI.toHex()},x | sta ${ins.callLabel} | sty ${ins.callLabel}+1"
|
||||||
}
|
}
|
||||||
Opcode.POP_VAR_FLOAT -> {
|
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 -> {
|
Opcode.INC_VAR_UB, Opcode.INC_VAR_B -> {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package prog8.stackvm
|
package prog8.stackvm
|
||||||
|
|
||||||
import prog8.ast.DataType
|
import prog8.ast.DataType
|
||||||
|
import prog8.ast.Position
|
||||||
|
import prog8.ast.unescape
|
||||||
import prog8.compiler.HeapValues
|
import prog8.compiler.HeapValues
|
||||||
import prog8.compiler.intermediate.*
|
import prog8.compiler.intermediate.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -89,7 +91,7 @@ class Program (val name: String,
|
|||||||
DataType.STR,
|
DataType.STR,
|
||||||
DataType.STR_P,
|
DataType.STR_P,
|
||||||
DataType.STR_S,
|
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_UB, DataType.ARRAY_B,
|
||||||
DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
||||||
val numbers = it.third.substring(1, it.third.length-1).split(',')
|
val numbers = it.third.substring(1, it.third.length-1).split(',')
|
||||||
|
Loading…
Reference in New Issue
Block a user