X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=ROM2%2Fkeypad.c;h=cc6093d8f95196ce5d9612de187c622ad112b151;hb=db23b975a50ba026e1455852f4b656f18095aeb3;hp=433e78c1e4b213ac816a7cf7f3bfc1d3242a5302;hpb=5574108832c9f2ef4aef35f0f7531f8d072c68a7;p=uccvend-snackrom.git diff --git a/ROM2/keypad.c b/ROM2/keypad.c index 433e78c..cc6093d 100644 --- a/ROM2/keypad.c +++ b/ROM2/keypad.c @@ -10,12 +10,17 @@ bool new_key = 0; 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}; +#define NO_KEY 8 + +/* reads the keypad and returns the bit number that was turned on in the shift + * register (from 0..7). If no bits were turned on, it returns 8 (aka NO_KEY) + */ extern inline u8 keypad_read_row(u8 row) { u8 i, num; if (row) - _io_ports[M6811_PORTD] |= PORTD_KEYPAD_ROW; + bset((void*)&_io_ports[M6811_PORTD], PORTD_KEYPAD_ROW); else - _io_ports[M6811_PORTD] &= ~PORTD_KEYPAD_ROW; + bclr((void*)&_io_ports[M6811_PORTD], PORTD_KEYPAD_ROW); bclr_misc_output(A3800_DISPLAY_WRITE); /* disable the display clock */ @@ -23,7 +28,7 @@ extern inline u8 keypad_read_row(u8 row) { while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */ for (i = _io_ports[M6811_SPDR], num = 0; - (i&0x1) == 0; + ((i&0x1) == 0) && (num < 7); i=i>>1, num++); return num; @@ -34,11 +39,14 @@ void keypad_read() { /* FIXME: need to do debouncing of some sort? */ u8 key; key = keypad_read_row(0); - if (!key) { + if (NO_KEY == key) { key = keypad_read_row(1); + if (key <= 2) + key = keymap1[key]; + else + key = 0; + } else key = keymap0[key]; - } - key = keymap1[key]; if (key != last_key) { last_key = key; @@ -54,9 +62,3 @@ bool keypad_pressed() { new_key = 0; return 1; } - -u8 keypad_getkey() { - while (!keypad_pressed()) - keypad_read(); - return last_key; -}