From 3ea5f9e0efb4dd933405eb73715f9611976c65e6 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Tue, 13 Mar 2018 13:06:26 +0000 Subject: [PATCH] startrek: add an input routine for x.yz fixed point co-ords --- Applications/games/startrek.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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) { -- 2.34.1