|
|
| version 1.1, 2005/02/07 16:56:32 | version 1.2, 2005/02/26 03:59:50 |
|---|---|
| Line 3 | Line 3 |
| #include "xmil.h" | #include "xmil.h" |
| #include "joymng.h" | #include "joymng.h" |
| #include "palmkbd.h" | #include "palmkbd.h" |
| #include "palm5way.h" | #include "PalmNavigator.h" |
| typedef struct { | typedef struct { |
| UINT32 tick; | UINT32 input; |
| BOOL input; | |
| REG8 flag; | REG8 flag; |
| } JOYSTICK; | } JOYSTICK; |
| Line 16 static JOYSTICK joy; | Line 15 static JOYSTICK joy; |
| void joymng_initialize(void) { | void joymng_initialize(void) { |
| joy.input = FALSE; | |
| joy.flag = JOY_PADALL | JOY_BTNALL; | joy.flag = JOY_PADALL | JOY_BTNALL; |
| } | } |
| void joymng_sync(REG8 key) { | void joymng_sync(REG8 key) { |
| joy.flag |= JOY_PADALL; | joy.flag &= JOY_BTNALL; |
| joy.flag &= ~key; | joy.flag |= ~key; |
| } | } |
| void joymng_btnsync(REG8 key) { | REG8 joymng_getstat(void) { |
| joy.flag |= JOY_BTNALL; | return(joy.flag); |
| joy.flag &= ~key; | |
| joy.tick = GETTICK(); | |
| joy.input = TRUE; | |
| } | } |
| REG8 joymng_getstat(void) { | static const UINT hardkey[] = {0, 0,0x20,0x0d,0x1b,0x8a,0x8b,0x91,0x92,0x93,0x94,0x95}; |
| static const REG8 joybit[] = {JOY_BTN1_BIT, JOY_BTN2_BIT}; | |
| return(joy.flag); | static void setjoybutton (UINT32 keystate, REG8 keycode, UINT keybit) { |
| if (keystate & keybit) { | |
| joy.flag &= ~joybit[keycode]; | |
| } else { | |
| joy.flag |= joybit[keycode]; | |
| } | |
| } | } |
| void joymng_callback(void) { | static void setkeybutton (UINT32 keystate, REG8 keycode, UINT keybit) { |
| if (joy.input) { | if (keystate & keybit) { |
| if ((GETTICK() - joy.tick) > 100) { | palmkbd_keydown(hardkey[keycode], TRUE); |
| joy.flag |= JOY_BTNALL; | } else { |
| joy.input = FALSE; | palmkbd_keyup(hardkey[keycode]); |
| } | |
| } | } |
| } | } |
| static void setbutton (UINT32 state, REG8 keycode, UINT keybit) { | |
| switch (keycode) { | |
| case 0: | |
| case 1: | |
| setjoybutton(state, keycode, keybit); | |
| break; | |
| default: | |
| setkeybutton(state, keycode, keybit); | |
| break; | |
| } | |
| } | |
| void joymng_hardkey(UINT32 state) { | |
| setbutton(state, xmiloscfg.HARDKEY1, keyBitHard1); | |
| setbutton(state, xmiloscfg.HARDKEY2, keyBitHard2); | |
| setbutton(state, xmiloscfg.HARDKEY3, keyBitHard3); | |
| setbutton(state, xmiloscfg.HARDKEY4, keyBitHard4); | |
| } | |
| static const UINT navbits[] = { JOY_UP_BIT, JOY_DOWN_BIT, JOY_LEFT_BIT, JOY_RIGHT_BIT, | |
| chrUpArrow, chrDownArrow, chrLeftArrow, chrRightArrow}; | |
| static int setdirection(UINT data, int base) { | static int setdirection(UINT data, int base) { |
| if (data & navBitRight) { | if (data & JOY_RIGHT_BIT) { |
| return(base+1); | return(base+1); |
| } | } |
| else if (data & navBitLeft) { | else if (data & JOY_LEFT_BIT) { |
| return(base-1); | return(base-1); |
| } | } |
| else { | else { |
| Line 63 static int setdirection(UINT data, int b | Line 87 static int setdirection(UINT data, int b |
| BRESULT joymng_5way(UINT code) { | BRESULT joymng_5way(UINT code) { |
| int key; | int key, i; |
| BRESULT ret = FALSE; | BRESULT ret = FALSE; |
| if (xmiloscfg.FIVEWAY == 0) { | if (xmiloscfg.FIVEWAY == 0) { |
| Line 71 BRESULT joymng_5way(UINT code) { | Line 95 BRESULT joymng_5way(UINT code) { |
| ret = TRUE; | ret = TRUE; |
| } | } |
| else if (xmiloscfg.FIVEWAY == 1) { | else if (xmiloscfg.FIVEWAY == 1) { |
| if (code & navChangeUp) { | for (i=0;i<4;i++) { |
| if (code & navBitUp) { | if (code & navbits[i]) { |
| palmkbd_keydown(chrUpArrow, FALSE); | palmkbd_keydown(navbits[i+4], TRUE); |
| } | |
| else { | |
| palmkbd_keyup(chrUpArrow); | |
| } | |
| ret = TRUE; | |
| } else if (code & navChangeDown) { | |
| if (code & navBitDown) { | |
| palmkbd_keydown(chrDownArrow, FALSE); | |
| } | |
| else { | |
| palmkbd_keyup(chrDownArrow); | |
| } | |
| ret = TRUE; | |
| } | |
| if (code & navChangeLeft) { | |
| if (code & navBitLeft) { | |
| palmkbd_keydown(chrLeftArrow, FALSE); | |
| } | |
| else { | |
| palmkbd_keyup(chrLeftArrow); | |
| } | |
| ret = TRUE; | |
| } else if (code & navChangeRight) { | |
| if (code & navBitRight) { | |
| palmkbd_keydown(chrRightArrow, FALSE); | |
| } | } |
| else { | |
| palmkbd_keyup(chrRightArrow); | |
| } | |
| ret = TRUE; | |
| } | |
| if (code & navChangeSelect) { | |
| ret = TRUE; | |
| } | } |
| ret = TRUE; | |
| } | } |
| else if (xmiloscfg.FIVEWAY == 2) { | else if (xmiloscfg.FIVEWAY == 2) { |
| if (code & navBitUp) { | if (code & JOY_UP_BIT) { |
| key = setdirection(code, 0x88); | key = setdirection(code, 0x88); |
| } | } |
| else if (code & navBitDown) { | else if (code & JOY_DOWN_BIT) { |
| key = setdirection(code, 0x82); | key = setdirection(code, 0x82); |
| } | } |
| else { | else { |
| key = setdirection(code, 0x85); | key = setdirection(code, 0x85); |
| if ((key == 0x85) && !(code & navBitSelect)) { | if ((key == 0x85) && !(code & navBitSelect)) { |
| return(FALSE); | return(ret); |
| } | } |
| } | } |
| palmkbd_keydown(key, TRUE); | palmkbd_keydown(key, TRUE); |