From: Alan Cox Date: Tue, 13 Mar 2018 13:06:26 +0000 (+0000) Subject: startrek: add an input routine for x.yz fixed point co-ords X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=3ea5f9e0efb4dd933405eb73715f9611976c65e6;p=FUZIX.git startrek: add an input routine for x.yz fixed point co-ords --- diff --git a/Applications/games/startrek.c b/Applications/games/startrek.c index b2aca079..25026232 100644 --- a/Applications/games/startrek.c +++ b/Applications/games/startrek.c @@ -256,6 +256,34 @@ static double input_dec(void) return atof(x); } +/* Input a value between 0.00 and 9.99 */ +static int16_t input_f00(void) +{ + int16_t v; + char buf[8]; + char *x; + input(buf, 8); + x = buf; + if (!isdigit(*x)) + return -1; + v = 100 * (*x++ - '0'); + if (*x == 0) + return v; + if (*x++ != '.') + return -1; + if (!*x) + return v; + if (!isdigit(*x)) + return -1; + v += 10 * (*x++ - '0'); + if (!*x) + return v; + if (!isdigit(*x)) + return -1; + v += *x++ - '0'; + return v; +} + /* Integer: unsigned, or returns -1 for blank/error */ static int input_int(void) {