2018-09-29 15:33:59 +00:00
|
|
|
%output prg
|
|
|
|
%import c64lib
|
2018-10-21 21:03:15 +00:00
|
|
|
%import c64utils
|
2018-09-29 15:33:59 +00:00
|
|
|
%import mathlib
|
|
|
|
|
|
|
|
~ main {
|
2018-10-21 21:03:15 +00:00
|
|
|
sub start() {
|
|
|
|
str name = "????????????????????????????????????????"
|
|
|
|
str guess = "??????????"
|
|
|
|
ubyte secretnumber = 0
|
|
|
|
ubyte attempts_left = 10
|
|
|
|
memory uword freadstr_arg = $22 ; argument for FREADSTR
|
2018-11-21 23:01:41 +00:00
|
|
|
uword testword
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
; greeting
|
|
|
|
c64scr.print_string("Enter your name: ")
|
2018-11-21 23:01:41 +00:00
|
|
|
Y = c64scr.input_chars(name)
|
2018-11-28 00:12:23 +00:00
|
|
|
c64.CHROUT('\n')
|
|
|
|
c64.CHROUT('\n')
|
2018-09-29 15:33:59 +00:00
|
|
|
c64scr.print_string("Hello, ")
|
|
|
|
c64scr.print_string(name)
|
2018-11-28 00:12:23 +00:00
|
|
|
c64.CHROUT('.')
|
|
|
|
c64.CHROUT('\n')
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
; create a secret random number from 1-100
|
|
|
|
c64.RNDA(0) ; fac = rnd(0)
|
|
|
|
c64.MUL10() ; fac *= 10
|
|
|
|
c64.MUL10() ; .. and now *100
|
|
|
|
c64.FADDH() ; add 0.5..
|
|
|
|
c64.FADDH() ; and again, so +1 total
|
2018-12-03 23:19:13 +00:00
|
|
|
A, Y = c64flt.GETADRAY() ; @todo fix return value type check "cannot assign word to byte, use msb() or lsb()"
|
2018-09-29 15:33:59 +00:00
|
|
|
secretnumber = A
|
|
|
|
|
|
|
|
c64scr.print_string("I am thinking of a number from 1 to 100!You'll have to guess it!\n")
|
|
|
|
|
|
|
|
ask_guess:
|
|
|
|
c64scr.print_string("\nYou have ")
|
|
|
|
c64scr.print_byte_decimal(attempts_left)
|
|
|
|
c64scr.print_string(" guess")
|
|
|
|
if(attempts_left>0) c64scr.print_string("es")
|
|
|
|
|
|
|
|
c64scr.print_string(" left.\nWhat is your next guess? ")
|
|
|
|
Y = c64scr.input_chars(guess)
|
2018-11-28 00:12:23 +00:00
|
|
|
c64.CHROUT('\n')
|
|
|
|
freadstr_arg = guess
|
2018-09-29 15:33:59 +00:00
|
|
|
c64.FREADSTR(A)
|
2018-12-03 23:19:13 +00:00
|
|
|
A, Y = c64flt.GETADRAY() ; @todo fix return value type check "cannot assign word to byte, use msb() or lsb()"
|
2018-09-29 15:33:59 +00:00
|
|
|
if(A==secretnumber) {
|
|
|
|
c64scr.print_string("\nThat's my number, impressive!\n")
|
|
|
|
goto goodbye
|
|
|
|
}
|
|
|
|
c64scr.print_string("That is too ")
|
|
|
|
if(A > secretnumber)
|
|
|
|
c64scr.print_string("low!\n")
|
|
|
|
else
|
|
|
|
c64scr.print_string("high!\n")
|
|
|
|
|
|
|
|
attempts_left--
|
|
|
|
if(attempts_left>0) goto ask_guess
|
|
|
|
; more efficient: if_nz goto ask_guess
|
|
|
|
|
|
|
|
; game over.
|
|
|
|
c64scr.print_string("\nToo bad! It was: ")
|
|
|
|
c64scr.print_byte_decimal(secretnumber)
|
2018-11-28 00:12:23 +00:00
|
|
|
c64.CHROUT('\n')
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
goodbye:
|
|
|
|
c64scr.print_string("\nThanks for playing. Bye!\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|