undocumented opcodes added to ncpu
[fceu.git] / input / suborkb.c
1 #include <string.h>
2 #include "share.h"
3 #include "suborkb.h"
4 #define AK2(x,y)        ( (FKB_##x) | (FKB_##y <<8) )
5 #define AK(x)                 FKB_##x
6
7 static uint8 bufit[0x61];
8 static uint8 ksmode;
9 static uint8 ksindex;
10
11
12 static uint16 matrix[13][2][4]=
13 {
14 {{AK(4),AK(G),AK(F),AK(C)},
15     {AK(F2),AK(E),AK(5),AK(V)}},
16 {{AK(2),AK(D),AK(S),AK(END)},
17     {AK(F1),AK(W),AK(3),AK(X)}},
18 {{AK(INSERT),AK(BACK),AK(NEXT),AK(RIGHT)},
19         {AK(F8),AK(PRIOR),AK(DELETE),AK(HOME)}},
20 {{AK(9),AK(I),AK(L),AK(COMMA)},
21         {AK(F5),AK(O),AK(0),AK(PERIOD)}},
22 {{AK(RBRACKET),AK(RETURN),AK(UP),AK(LEFT)},
23         {AK(F7),AK(LBRACKET),AK(BACKSLASH),AK(DOWN)}},
24 {{AK(Q),AK(CAPITAL),AK(Z),AK(TAB)},
25         {AK(ESCAPE),AK(A),AK(1),AK(LCONTROL)}},
26 {{AK(7),AK(Y),AK(K),AK(M)},
27         {AK(F4),AK(U),AK(8),AK(J)}},
28 {{AK(MINUS),AK(SEMICOLON),AK(APOSTROPHE),AK(SLASH)},
29         {AK(F6),AK(P),AK(EQUALS),AK(LSHIFT)}},
30 {{AK(T),AK(H),AK(N),AK(SPACE)},
31         {AK(F3),AK(R),AK(6),AK(B)}},
32 {{0,0,0,0},
33         {0,0,0,0}},
34 {{AK(LMENU),AK(NUMPAD4),AK(NUMPAD7),AK(F11)},
35         {AK(F12),AK(NUMPAD1),AK(NUMPAD2),AK(NUMPAD8)}},
36 {{AK(SUBTRACT),AK(ADD),AK(MULTIPLY),AK(NUMPAD9)},
37         {AK(F10),AK(NUMPAD5),AK(DIVIDE),AK(NUMLOCK)}},
38 {{AK(GRAVE),AK(NUMPAD6),AK(PAUSE),AK(SPACE)},
39         {AK(F9),AK(NUMPAD3),AK(DECIMAL),AK(NUMPAD0)}},
40 };
41
42 static void FP_FASTAPASS(1) SuborKB_Write(uint8 v)
43 {
44  v>>=1;
45  if(v&2)
46  {
47   if((ksmode&1) && !(v&1))
48    ksindex=(ksindex+1)%13;
49  }
50  ksmode=v;
51 }
52
53 static uint8 FP_FASTAPASS(2) SuborKB_Read(int w, uint8 ret)
54 {
55  if(w)
56  {
57   int x;
58
59   ret&=~0x1E;
60 //  if(ksindex==9)
61 //  {
62 //     if(ksmode&1)
63 //        ret|=2;
64 //  }
65 //  else
66 //  {
67     for(x=0;x<4;x++)
68       if(bufit[matrix[ksindex][ksmode&1][x]&0xFF]||bufit[matrix[ksindex][ksmode&1][x]>>8])
69         ret|=1<<(x+1);
70 //  }
71   ret^=0x1E;
72  }
73  return(ret);
74 }
75
76 static void SuborKB_Strobe(void)
77 {
78  ksmode=0;
79  ksindex=0;
80 }
81
82 static void FP_FASTAPASS(2) SuborKB_Update(void *data, int arg)
83 {
84  memcpy(bufit+1,data,0x60);
85 }
86
87 static INPUTCFC SuborKB={SuborKB_Read,SuborKB_Write,SuborKB_Strobe,SuborKB_Update,0,0};
88
89 INPUTCFC *FCEU_InitSuborKB(void)
90 {
91  memset(bufit,0,sizeof(bufit));
92  ksmode=ksindex=0;
93  return(&SuborKB);
94 }