+ /* internal ohci */
+ usb_init(OHCI1_REG_BASE);
+
+ /* load HID keyboard driver */
+ usb_hidkb_init();
+
+ /* wait for usb keyboard plugged in */
+ if(!usb_hidkb_inuse()) {
+ print_str("plug in an usb keyboard", 23);
+ }
+ while(!usb_hidkb_inuse());
+
+#define FONT_WIDTH 13
+#define FONT_HEIGHT 15
+#define STDOUT_BORDER_LEFT 20
+#define STDOUT_BORDER_RIGHT 650
+#define STDOUT_BORDER_TOP 20
+#define STDOUT_BORDER_BOTTOM 550
+#define TABSIZE 4
+ /* you are welcome to make this nice :) */
+ char str[7];
+ u16 i, j, y=STDOUT_BORDER_TOP, x=STDOUT_BORDER_LEFT;
+ u16 old_x, old_y;
+ struct kbrep *k;
+
+ while(1) {
+ memset(str, '\0', 7);
+ j=0;
+ k = usb_hidkb_getChars();
+ old_x = x; /* save actual x and y position for printing after the loop */
+ old_y = y;
+ for(i=0; k->keys[i]>0; i++) {
+ unsigned char key = usb_hidkb_get_char_from_keycode(k->keys[i],
+ (k->mod & MOD_lshift) || (k->mod & MOD_rshift));
+ /* no key or key not relevant? next, please. */
+ if (key == 0)
+ continue;
+
+ /* RETURN pressed? */
+ if (key == '\n') {
+ x = STDOUT_BORDER_LEFT;
+ y += FONT_HEIGHT;
+ /* TAB pressed? */
+ } else if (key == '\t') {
+ x += (TABSIZE*FONT_WIDTH);
+
+ /* BACKSPACE pressed? */
+ } else if (key == '\r') {
+ /* TODO */
+
+ /* now we have only printable characters left */
+ } else {
+ x += FONT_WIDTH;
+ str[j] = key;
+ j++;
+ }
+
+ /* line full? break! */
+ if(x > (STDOUT_BORDER_RIGHT-FONT_WIDTH)) {
+ x = STDOUT_BORDER_LEFT;
+ y += FONT_HEIGHT;
+ }
+ /* screen full? start again at top */
+ if(y > (STDOUT_BORDER_BOTTOM-FONT_HEIGHT)) {
+ y = STDOUT_BORDER_TOP;
+ }
+ }
+ if(j > 0) { /* when there was any printable stuff, show it */
+ print_str_noscroll(old_x, old_y, str);
+ printf("y: %d\n", y);
+ }
+
+ }
+
+#if 0
+ printf("===============================\n");
+
+ SHA1TestCases();