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
|
|
|
|
2018-12-10 23:09:37 +00:00
|
|
|
|
|
|
|
; The classic number guessing game.
|
|
|
|
; This version uses more low-level subroutines (calls directly into the C64's ROM routines)
|
|
|
|
; and instead of a loop (with the added behind the scenes processing), uses absolute jumps.
|
|
|
|
; It's less readable I think, but produces a smaller program.
|
|
|
|
|
|
|
|
|
2018-09-29 15:33:59 +00:00
|
|
|
~ main {
|
2018-10-21 21:03:15 +00:00
|
|
|
sub start() {
|
|
|
|
str name = "????????????????????????????????????????"
|
2018-12-10 23:09:37 +00:00
|
|
|
str input = "??????????"
|
2018-12-07 23:27:12 +00:00
|
|
|
ubyte guess
|
2018-10-21 21:03:15 +00:00
|
|
|
ubyte secretnumber = 0
|
|
|
|
ubyte attempts_left = 10
|
2018-12-10 23:09:37 +00:00
|
|
|
memory uword freadstr_arg = $22 ; argument for FREADSTR ($22/$23)
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
; greeting
|
2018-12-07 23:27:12 +00:00
|
|
|
c64.VMCSB |= 2 ; switch lowercase chars
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("Please introduce yourself: ")
|
2018-12-07 23:27:12 +00:00
|
|
|
c64scr.input_chars(name)
|
2018-11-28 00:12:23 +00:00
|
|
|
c64.CHROUT('\n')
|
|
|
|
c64.CHROUT('\n')
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("Hello, ")
|
|
|
|
c64.STROUT(name)
|
|
|
|
c64.STROUT(".\nLet's play a number guessing game.\nI am thinking of a number from 1 to 100!You'll have to guess it!\n")
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
; create a secret random number from 1-100
|
2018-12-10 23:09:37 +00:00
|
|
|
c64.RND() ; fac = random number between 0 and 1
|
2018-09-29 15:33:59 +00:00
|
|
|
c64.MUL10() ; fac *= 10
|
|
|
|
c64.MUL10() ; .. and now *100
|
|
|
|
c64.FADDH() ; add 0.5..
|
|
|
|
c64.FADDH() ; and again, so +1 total
|
2018-12-04 21:30:35 +00:00
|
|
|
A, Y = c64flt.GETADRAY()
|
2018-12-07 23:27:12 +00:00
|
|
|
secretnumber = A ; secret number = rnd()*100+1
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
ask_guess:
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("\nYou have ")
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print_ub(attempts_left)
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT(" guess")
|
2018-12-10 23:09:37 +00:00
|
|
|
if(attempts_left>1)
|
|
|
|
c64.STROUT("es")
|
2018-09-29 15:33:59 +00:00
|
|
|
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT(" left.\nWhat is your next guess? ")
|
2018-12-10 23:09:37 +00:00
|
|
|
Y=c64scr.input_chars(input)
|
2018-11-28 00:12:23 +00:00
|
|
|
c64.CHROUT('\n')
|
2018-12-10 23:09:37 +00:00
|
|
|
freadstr_arg = input
|
2018-12-07 23:27:12 +00:00
|
|
|
c64.FREADSTR(Y)
|
2018-12-04 21:30:35 +00:00
|
|
|
A, Y = c64flt.GETADRAY()
|
2018-12-07 23:27:12 +00:00
|
|
|
guess=A
|
2018-12-10 08:25:38 +00:00
|
|
|
if(guess==secretnumber) {
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("\nThat's my number, impressive!\n")
|
2018-09-29 15:33:59 +00:00
|
|
|
goto goodbye
|
|
|
|
}
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("\nThat is too ")
|
2018-12-10 23:09:37 +00:00
|
|
|
if(guess < secretnumber)
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("low!\n")
|
2018-09-29 15:33:59 +00:00
|
|
|
else
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("high!\n")
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
attempts_left--
|
2018-12-10 23:09:37 +00:00
|
|
|
if_nz goto ask_guess
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
; game over.
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("\nToo bad! It was: ")
|
2018-12-21 00:06:01 +00:00
|
|
|
c64scr.print_ub(secretnumber)
|
2018-11-28 00:12:23 +00:00
|
|
|
c64.CHROUT('\n')
|
2018-09-29 15:33:59 +00:00
|
|
|
|
|
|
|
goodbye:
|
2018-12-06 23:08:22 +00:00
|
|
|
c64.STROUT("\nThanks for playing, ")
|
|
|
|
c64.STROUT(name)
|
|
|
|
c64.STROUT(".\n")
|
2018-09-29 15:33:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|