4 * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2,
9 * or (at your option) any later version.
10 * This library / program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this library; see the file COPYING. If not, write to the
17 * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 * As a special exception, if you link this(includeed from sdcc) library
21 * with other files, some of which are compiled with SDCC,
22 * to produce an executable, this library does not by itself cause
23 * the resulting executable to be covered by the GNU General Public License.
24 * This exception does not however invalidate any other reasons why
25 * the executable file might be covered by the GNU General Public License.
33 const char charcodemap[] = {charcode_0,
54 keyin_defs keyin_old[2];
65 for(i = 0; i < 2; i++) {
66 keyin_old[0].byte[i] = 0x00;
67 keyin_old[1].byte[i] = 0x00;
68 keyin_now.byte[i] = 0x00;
70 for(i = 0; i < 16; i++) keyin_fifo[i] = 0x00;
77 * Push to keyin fifo; not used atomic-writing.
79 void push_keyinfifo(char b) __critical
81 if(keyin_counter >= 31) {
86 if((keyin_nowp > 31) || (keyin_nowp < 0))keyin_nowp = 0;
87 keyin_fifo[keyin_nowp] = b;
92 * Pop from keyin fifo; not used atomic-reading.
94 char pop_keyinfifo(void) __critical
97 if(keyin_counter <= 0) {
99 return charcode_null ;
101 if(keyin_readp > 31) keyin_readp = 0;
102 c = keyin_fifo[keyin_readp];
105 if(keyin_counter < 0) keyin_counter = 0;
109 void print_numeric(int i, unsigned char supressf)
111 if((i == 0) && (supressf != 0)){
119 unsigned char supress = 0;
120 if(supressf == 0) supress = 1;
129 _PUTCHAR((l & 0x0f)+ '0');
131 } else if(supress != 0) {
137 _PUTCHAR((l & 0x0f)+ '0');
139 _PUTCHAR((l & 0x0f)+ '0');
146 _PUTCHAR((l & 0x0f)+ '0');
148 _PUTCHAR((l & 0x0f)+ '0');
155 _PUTCHAR((l & 0x0f)+ '0');
157 _PUTCHAR((l & 0x0f)+ '0');
161 _PUTCHAR((i & 0x0f) + '0');
167 void printstr(char *s)
171 if(s == NULL) return;
173 if(s[p] == '\0') break;
179 void print_numeric_nosupress(unsigned int data, unsigned char digit)
185 if(digit == 0) return;
186 if(digit >= 5) digit = 5;
220 unsigned int subst_numeric(unsigned int start, unsigned char pos, unsigned char c)
222 unsigned int p = pos;
227 val = (start / 10) * 10 + c;
230 val = (start / 100) * 100 + start % 10 + c * 10;
233 val = (start / 1000) * 1000 + start % 100 + c * 100;
236 val = (start / 10000) * 10000 + start % 1000 + c * 1000;
239 val = start % 10000 + c * 10000;
248 unsigned int read_numeric(unsigned int initial, unsigned char digit,
249 char startx, char starty)
255 unsigned char input_flag;
262 _LOCATE(startx, starty);
263 print_numeric_nosupress(val, digit);
266 input_flag = readkey_compare();
268 } while(input_flag == 0);
272 val = subst_numeric(val, i, 0);
274 } else if((c >= charcode_1) && (c <= charcode_9)) {
275 val = subst_numeric(val, i, c - charcode_1 + 1);
276 } else if(c == charcode_f) {
279 } else if(c == charcode_d) {
282 val = (val / 10) * 10;
285 } else if(c == charcode_b) {
290 print_numeric_nosupress(val, d);
302 unsigned char readkey_compare(void)
312 for(d = 0; d < 2; d++) {
314 for(b = 0; b < 8; b++){
316 if((keyin_now.byte[d] & shift) != 0) c++;
317 if((keyin_old[0].byte[d] & shift) != 0) c++;
318 if((keyin_old[1].byte[d] & shift) != 0) c++;
321 * Clear older-inputs on .
324 keyin_old[0].byte[d] &= ~shift;
325 keyin_old[1].byte[d] &= ~shift;
326 keyin_now.byte[d] &= ~shift;
328 push_keyinfifo(charcodemap[e]);
339 unsigned char readkey(void)
342 for(i = 0; i < 8; i++) {
343 idle(0xfffe); // 1.5ms?
347 return pop_keyinfifo();
352 * Initialize sequence:
357 * In interrupt/unsleep hook(call per Nms):
361 * In application handler:
362 * c = pop_keyinfifo();