2018-01-01 22:24:39 +00:00
|
|
|
%output prg,basic
|
|
|
|
%import "c64lib"
|
2018-01-01 22:46:33 +00:00
|
|
|
%import "mathlib"
|
2017-12-28 03:20:59 +00:00
|
|
|
|
|
|
|
~ main {
|
|
|
|
var .text name = '?' * 80
|
2017-12-28 18:08:33 +00:00
|
|
|
var .text guess = '?' * 80
|
|
|
|
var secretnumber
|
|
|
|
var attempts_left = 10
|
2017-12-28 03:20:59 +00:00
|
|
|
|
2017-12-29 01:28:59 +00:00
|
|
|
|
2017-12-28 03:20:59 +00:00
|
|
|
start
|
2017-12-31 02:19:06 +00:00
|
|
|
c64.init_system()
|
2017-12-29 01:28:59 +00:00
|
|
|
|
2017-12-28 03:20:59 +00:00
|
|
|
A = c64.VMCSB
|
2017-12-28 18:08:33 +00:00
|
|
|
A |= 2 ; @todo c64.VMCSB |= 2
|
2017-12-28 03:20:59 +00:00
|
|
|
c64.VMCSB = A
|
|
|
|
|
2017-12-28 18:08:33 +00:00
|
|
|
; greeting
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("Enter your name: ")
|
|
|
|
Y = c64scr.input_chars(name)
|
2017-12-28 18:08:33 +00:00
|
|
|
c64.CHROUT('\n')
|
2017-12-28 03:20:59 +00:00
|
|
|
c64.CHROUT('\n')
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("Hello, ")
|
|
|
|
c64scr.print_string(name)
|
2017-12-28 18:08:33 +00:00
|
|
|
c64.CHROUT('.')
|
|
|
|
c64.CHROUT('\n')
|
|
|
|
|
|
|
|
; create a secret random number from 1-100
|
2018-01-01 22:46:33 +00:00
|
|
|
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-01-01 16:56:55 +00:00
|
|
|
AY = c64flt.GETADRAY()
|
2018-01-01 22:46:33 +00:00
|
|
|
secretnumber=A
|
|
|
|
;A=math.randbyte()
|
|
|
|
;A+=c64.RASTER
|
|
|
|
;A-=c64.TIME_LO
|
|
|
|
;X,secretnumber=math.divmod_bytes(A, 99)
|
2017-12-28 18:08:33 +00:00
|
|
|
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("I am thinking of a number from 1 to 100!You'll have to guess it!\n")
|
2017-12-28 03:20:59 +00:00
|
|
|
|
|
|
|
printloop
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("\nYou have ")
|
|
|
|
c64scr.print_byte_decimal(attempts_left)
|
|
|
|
c64scr.print_string(" guess")
|
2017-12-29 00:16:39 +00:00
|
|
|
|
|
|
|
; @todo comparison expression so we can do if attempts_left>0 ...
|
2017-12-28 22:03:59 +00:00
|
|
|
A = attempts_left
|
2017-12-29 01:28:59 +00:00
|
|
|
A--
|
2017-12-28 22:03:59 +00:00
|
|
|
if_zero A goto ask_guess
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("es")
|
2017-12-28 22:03:59 +00:00
|
|
|
ask_guess
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string(" left.\nWhat is your next guess? ")
|
|
|
|
Y = c64scr.input_chars(guess)
|
2017-12-28 18:08:33 +00:00
|
|
|
c64.CHROUT('\n')
|
|
|
|
[$22.word] = guess
|
|
|
|
c64.FREADSTR(A)
|
2018-01-01 16:56:55 +00:00
|
|
|
AY = c64flt.GETADRAY()
|
2017-12-29 00:16:39 +00:00
|
|
|
A -= secretnumber ; @todo condition so we can do if guess > secretnumber....
|
2017-12-28 18:08:33 +00:00
|
|
|
if_zero goto correct_guess
|
|
|
|
if_gt goto too_high
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("That is too ")
|
|
|
|
c64scr.print_string("low!\n")
|
2017-12-28 18:08:33 +00:00
|
|
|
goto continue
|
|
|
|
|
|
|
|
correct_guess
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("\nThat's my number, impressive!\n")
|
2017-12-28 22:03:59 +00:00
|
|
|
goodbye()
|
2017-12-28 18:08:33 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
too_high
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("That is too ")
|
|
|
|
c64scr.print_string("high!\n")
|
2017-12-28 18:08:33 +00:00
|
|
|
|
|
|
|
continue
|
|
|
|
attempts_left--
|
|
|
|
if_zero attempts_left goto game_over
|
|
|
|
goto printloop
|
|
|
|
|
|
|
|
game_over
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("\nToo bad! It was: ")
|
|
|
|
c64scr.print_byte_decimal(secretnumber)
|
2017-12-28 18:08:33 +00:00
|
|
|
c64.CHROUT('\n')
|
2017-12-28 22:03:59 +00:00
|
|
|
goodbye()
|
2017-12-28 18:08:33 +00:00
|
|
|
return
|
|
|
|
|
2017-12-28 22:03:59 +00:00
|
|
|
sub goodbye ()->() {
|
2017-12-28 18:08:33 +00:00
|
|
|
;var x ; @todo vars in sub
|
|
|
|
;memory y = $c000 ; @todo vars in sub
|
|
|
|
;const q = 22 ; @todo const in sub
|
|
|
|
|
2017-12-31 02:19:06 +00:00
|
|
|
c64scr.print_string("\nThanks for playing. Bye!\n")
|
2017-12-28 03:20:59 +00:00
|
|
|
return
|
2017-12-28 18:08:33 +00:00
|
|
|
}
|
2017-12-28 03:20:59 +00:00
|
|
|
|
|
|
|
}
|