+ bclr((void*)&_io_ports[M6811_PORTD], PORTD_KEYPAD_ROW);
+
+ spi_enable();
+
+ bset_misc_output(A3800_KEYPAD_STROBE);
+ bclr_misc_output(A3800_KEYPAD_STROBE);
+
+ bclr_misc_output(A3800_DISPLAY_WRITE); /* disable the display clock */
+
+ /* _io_ports[M6811_SPDR] = 0; */
+ asm volatile (
+ "ldab #0\n"
+ "stab %0\n"
+ : "=m" (_io_ports[M6811_SPDR])
+ :
+ : "b"
+ );
+ while(!(_io_ports[M6811_SPSR]&M6811_SPIF)); /* wait for completion */
+
+ /* SPDR read to clear SPIF flag is performed below: */
+ i = _io_ports[M6811_SPDR];
+
+ /* print out the row & read in key in binary */
+ char msg_buf[11] = "XKXXXXXXXX";
+ msg_buf[0] = row?'1':'0';
+ for (j = 1, num = 0; num < 8; j = j << 1, num++) {
+ msg_buf[num+2] = (i & j)?'1':'0';
+ }
+ set_msg(msg_buf);
+
+ num = 0;
+ while (((i & 0x01) == 0) && (num < 8)) {
+ i = i >> 1;
+ num++;
+ }
+
+ spi_disable();
+
+ return num;