mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 00:31:56 +00:00
string param passing
This commit is contained in:
parent
8a2584c7df
commit
211609c481
@ -12,21 +12,15 @@
|
||||
memory uword freadstr_arg = $22 ; argument for FREADSTR
|
||||
uword testword
|
||||
|
||||
testword = guess ; @todo fix str addrss
|
||||
testword = "sadfsafsdf" ; @todo fix str address
|
||||
secretnumber = "\n" ; @todo fix argument conversion to UBYTE
|
||||
c64utils.init_system()
|
||||
c64.VMCSB |= 2 ; activate lowercase charset
|
||||
|
||||
; greeting
|
||||
c64scr.print_string("Enter your name: ")
|
||||
Y = c64scr.input_chars(name)
|
||||
c64.CHROUT("\n") ; @todo fix argument conversion to UBYTE
|
||||
c64.CHROUT("\n") ; @todo fix argument conversion to UBYTE
|
||||
c64.CHROUT('\n')
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_string("Hello, ")
|
||||
c64scr.print_string(name)
|
||||
c64.CHROUT(".") ; @todo fix argument conversion to UBYTE
|
||||
c64.CHROUT("\n") ; @todo fix argument conversion to UBYTE
|
||||
c64.CHROUT('.')
|
||||
c64.CHROUT('\n')
|
||||
|
||||
; create a secret random number from 1-100
|
||||
c64.RNDA(0) ; fac = rnd(0)
|
||||
@ -36,10 +30,6 @@
|
||||
c64.FADDH() ; and again, so +1 total
|
||||
A, Y = c64flt.GETADRAY() ; @todo fix return value type check
|
||||
secretnumber = A
|
||||
;A=math.randbyte()
|
||||
;A+=c64.RASTER
|
||||
;A-=c64.TIME_LO
|
||||
;X,secretnumber=math.divmod_bytes(A, 99)
|
||||
|
||||
c64scr.print_string("I am thinking of a number from 1 to 100!You'll have to guess it!\n")
|
||||
|
||||
@ -51,8 +41,8 @@ ask_guess:
|
||||
|
||||
c64scr.print_string(" left.\nWhat is your next guess? ")
|
||||
Y = c64scr.input_chars(guess)
|
||||
c64.CHROUT("\n") ; @todo fix argument conversion to UBYTE
|
||||
freadstr_arg = guess ; @todo put string's adress in uword variable
|
||||
c64.CHROUT('\n')
|
||||
freadstr_arg = guess
|
||||
c64.FREADSTR(A)
|
||||
A, Y = c64flt.GETADRAY() ; @todo fix return value type check
|
||||
if(A==secretnumber) {
|
||||
@ -72,7 +62,7 @@ ask_guess:
|
||||
; game over.
|
||||
c64scr.print_string("\nToo bad! It was: ")
|
||||
c64scr.print_byte_decimal(secretnumber)
|
||||
c64.CHROUT("\n") ; @todo fix argument conversion to UBYTE
|
||||
c64.CHROUT('\n')
|
||||
|
||||
goodbye:
|
||||
c64scr.print_string("\nThanks for playing. Bye!\n")
|
||||
|
42
compiler/examples/numbergame-novm.p8
Normal file
42
compiler/examples/numbergame-novm.p8
Normal file
@ -0,0 +1,42 @@
|
||||
%import c64utils
|
||||
|
||||
~ main {
|
||||
sub start() {
|
||||
str name = " "
|
||||
str guess = "000000"
|
||||
ubyte secretnumber = rnd() % 100
|
||||
|
||||
c64scr.print_string("Let's play a number guessing game!\n")
|
||||
c64scr.print_string("Enter your name: ")
|
||||
vm_input_str(name)
|
||||
c64scr.print_string("\nHello, ")
|
||||
c64scr.print_string(name)
|
||||
c64scr.print_string(".\nI am thinking of a number from 1 to 100! You'll have to guess it!\n")
|
||||
|
||||
for ubyte attempts_left in 10 to 1 step -1 {
|
||||
c64scr.print_string("\nYou have ")
|
||||
vm_write_num(attempts_left)
|
||||
c64scr.print_string(" guess")
|
||||
if attempts_left>1 c64scr.print_string("es")
|
||||
c64scr.print_string(" left. What is your next guess? ")
|
||||
vm_input_str(guess)
|
||||
ubyte guessednumber = str2ubyte(guess)
|
||||
if guessednumber==secretnumber {
|
||||
c64scr.print_string("\nYou guessed it, impressive!\n")
|
||||
c64scr.print_string("Thanks for playing.\n")
|
||||
return
|
||||
} else {
|
||||
c64scr.print_string("That is too ")
|
||||
if guessednumber<secretnumber
|
||||
c64scr.print_string("low!\n")
|
||||
else
|
||||
c64scr.print_string("high!\n")
|
||||
}
|
||||
}
|
||||
|
||||
c64scr.print_string("\nToo bad! My number was: ")
|
||||
vm_write_num(secretnumber)
|
||||
c64scr.print_string(".\n")
|
||||
return
|
||||
}
|
||||
}
|
@ -810,7 +810,7 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
||||
translate(arg.first)
|
||||
prog.instr(Opcode.POP_REGAX_WORD)
|
||||
} else
|
||||
throw CompilerException("don't know how to pass register parameter of type $paramDt")
|
||||
TODO("pass parameter of type $paramDt in registers ${arg.second.registerOrPair}")
|
||||
}
|
||||
AY -> {
|
||||
val valueA: IExpression
|
||||
@ -829,7 +829,7 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
||||
translate(arg.first)
|
||||
prog.instr(Opcode.POP_REGAY_WORD)
|
||||
} else
|
||||
throw CompilerException("don't know how to pass register parameter of type $paramDt")
|
||||
TODO("pass parameter of type $paramDt in registers ${arg.second.registerOrPair}")
|
||||
}
|
||||
XY -> {
|
||||
// TODO: save X on stack & restore after call
|
||||
@ -849,7 +849,7 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
||||
translate(arg.first)
|
||||
prog.instr(Opcode.POP_REGXY_WORD)
|
||||
} else
|
||||
throw CompilerException("don't know how to pass register parameter of type $paramDt")
|
||||
TODO("pass parameter of type $paramDt in registers ${arg.second.registerOrPair}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user