From: Bernard Blackham Date: Wed, 6 Aug 2003 16:16:30 +0000 (+0000) Subject: Gratuitious use of #defines X-Git-Tag: ROMW~99 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5574108832c9f2ef4aef35f0f7531f8d072c68a7;p=uccvend-snackrom.git Gratuitious use of #defines --- diff --git a/ROM2/keypad.c b/ROM2/keypad.c index b36b326..433e78c 100644 --- a/ROM2/keypad.c +++ b/ROM2/keypad.c @@ -7,11 +7,11 @@ bool new_key = 0; /* first 8 from the first row, then 3 from the second row */ /* keys are 1-9, 0, reset */ -const u8 keymap0[8] = {8, 7, 6, 5, 4, 3, 2, 1}; -const u8 keymap1[3] = {11, 10, 9}; +const u8 keymap0[8] = {KEY_8, KEY_7, KEY_6, KEY_5, KEY_4, KEY_3, KEY_2, KEY_1}; +const u8 keymap1[3] = {KEY_RESET, KEY_0, KEY_9}; -extern inline int keypad_read_row(int row) { - int i, num; +extern inline u8 keypad_read_row(u8 row) { + u8 i, num; if (row) _io_ports[M6811_PORTD] |= PORTD_KEYPAD_ROW; else @@ -32,7 +32,7 @@ extern inline int keypad_read_row(int row) { /* returns a key 1..10 or 11 for reset */ void keypad_read() { /* FIXME: need to do debouncing of some sort? */ - int key; + u8 key; key = keypad_read_row(0); if (!key) { key = keypad_read_row(1); @@ -54,3 +54,9 @@ bool keypad_pressed() { new_key = 0; return 1; } + +u8 keypad_getkey() { + while (!keypad_pressed()) + keypad_read(); + return last_key; +} diff --git a/ROM2/keypad.h b/ROM2/keypad.h index b9cee95..1928aa8 100644 --- a/ROM2/keypad.h +++ b/ROM2/keypad.h @@ -1,10 +1,23 @@ #ifndef _KEYPAD_H_ #define _KEYPAD_H_ +#define KEY_1 1 +#define KEY_2 2 +#define KEY_3 3 +#define KEY_4 4 +#define KEY_5 5 +#define KEY_6 6 +#define KEY_7 7 +#define KEY_8 8 +#define KEY_9 9 +#define KEY_0 10 +#define KEY_RESET 11 + extern u8 last_key; /* returns true if a key has been pressed since the last call */ bool keypad_pressed(); void keypad_read(); +u8 keypad_getkey(); #endif /* _KEYPAD_H_ */