2 MITSUBISHI Electric MULTI8 Emulator 'EmuLTI8'
4 Author : Takeda.Toshiya
16 static const uint8_t matrix_normal[256] = {
17 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x08,0x09,0x00,0x00, 0x00,0x0d,0x00,0x00, // 00
18 0x00,0x00,0x00,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1b, 0x00,0x00,0x00,0x00, // 10
19 0x20,0x00,0x00,0x00, 0x0b,0x1d,0x1e,0x1c, 0x1f,0x00,0x00,0x00, 0x00,0x12,0x7f,0x00, // 20
20 0x30,0x31,0x32,0x33, 0x34,0x35,0x36,0x37, 0x38,0x39,0x00,0x00, 0x00,0x00,0x00,0x00, // 30
21 0x00,0x41,0x42,0x43, 0x44,0x45,0x46,0x47, 0x48,0x49,0x4a,0x4b, 0x4c,0x4d,0x4e,0x4f, // 40
22 0x50,0x51,0x52,0x53, 0x54,0x55,0x56,0x57, 0x58,0x59,0x5a,0x00, 0x00,0x00,0x00,0x00, // 50
23 0x30,0x31,0x32,0x33, 0x34,0x35,0x36,0x37, 0x38,0x39,0x00,0x2b, 0x00,0x00,0x2e,0x00, // 60
24 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x10,0x03,0x15,0x00, 0x00,0x00,0x00,0x00, // 70
25 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 80
26 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 90
27 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // a0
28 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x3a,0x3b, 0x2c,0x2d,0x2e,0x2f, // b0
29 0x40,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // c0
30 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x5b, 0x5c,0x5d,0x5e,0x00, // d0
31 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // e0
32 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 // f0
34 static const uint8_t matrix_shift[256] = {
35 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x08,0x09,0x00,0x00, 0x00,0x0d,0x00,0x00, // 00
36 0x00,0x00,0x00,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1b, 0x00,0x00,0x00,0x00, // 10
37 0x20,0x00,0x00,0x00, 0x0b,0x1d,0x1e,0x1c, 0x1f,0x00,0x00,0x00, 0x00,0x12,0x7f,0x00, // 20
38 0x00,0x21,0x22,0x23, 0x24,0x25,0x26,0x27, 0x28,0x29,0x00,0x00, 0x00,0x00,0x00,0x00, // 30
39 0x00,0x61,0x62,0x63, 0x64,0x65,0x66,0x67, 0x68,0x69,0x6a,0x6b, 0x6c,0x6d,0x6e,0x6f, // 40
40 0x70,0x71,0x72,0x73, 0x74,0x75,0x76,0x77, 0x78,0x79,0x7a,0x00, 0x00,0x00,0x00,0x00, // 50
41 0x30,0x31,0x32,0x33, 0x34,0x35,0x36,0x37, 0x38,0x39,0x00,0x2b, 0x00,0x00,0x2e,0x00, // 60
42 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x10,0x03,0x15,0x00, 0x00,0x00,0x00,0x00, // 70
43 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 80
44 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 90
45 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // a0
46 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x2a,0x2b, 0x3c,0x3d,0x3e,0x3f, // b0
47 0x60,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // c0
48 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x7b, 0x7c,0x7d,0x7e,0x00, // d0
49 0x00,0x00,0x5f,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // e0
50 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 // f0
52 static const uint8_t matrix_ctrl[256] = {
53 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 00
54 0x00,0x00,0x00,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 10
55 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 20
56 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 30
57 0x00,0x01,0x02,0x03, 0x04,0x05,0x06,0x07, 0x08,0x09,0x0a,0x0b, 0x0c,0x0d,0x0e,0x0f, // 40
58 0x10,0x11,0x12,0x13, 0x14,0x15,0x16,0x17, 0x18,0x19,0x1a,0x00, 0x00,0x00,0x00,0x00, // 50
59 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 60
60 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x10,0x03,0x15,0x00, 0x00,0x00,0x00,0x00, // 70
61 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 80
62 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 90
63 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // a0
64 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // b0
65 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // c0
66 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // d0
67 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // e0
68 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 // f0
70 static const uint8_t matrix_graph[256] = {
71 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x00, 0x00,0x0d,0x00,0x00, // 00
72 0x00,0x00,0x00,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1b, 0x00,0x00,0x00,0x00, // 10
73 0x20,0x00,0x00,0x00, 0x0b,0x1d,0x1e,0x1c, 0x1f,0x00,0x00,0x00, 0x00,0x12,0x7f,0x00, // 20
74 0xf7,0xf8,0xf9,0xfa, 0xfb,0xf2,0xf3,0xf4, 0xf5,0xf6,0x00,0x00, 0x00,0x00,0x00,0x00, // 30
75 0x00,0xec,0x84,0x82, 0x9f,0x9d,0xe6,0xe7, 0xf0,0xe8,0xea,0xeb, 0x8e,0x86,0x85,0xe9, // 40
76 0x8d,0xed,0xe4,0x9e, 0xe5,0xef,0x83,0x9c, 0x81,0xee,0x80,0x00, 0x00,0x00,0x00,0x00, // 50
77 0x30,0x31,0x32,0x33, 0x34,0x35,0x36,0x37, 0x38,0x39,0x00,0x2b, 0x00,0x00,0x2e,0x00, // 60
78 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x10,0x03,0x15,0x00, 0x00,0x00,0x00,0x00, // 70
79 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 80
80 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 90
81 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // a0
82 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x94,0x89, 0x87,0x8c,0x88,0x97, // b0
83 0x8a,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // c0
84 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xe1, 0xf1,0xe2,0x8b,0x00, // d0
85 0x00,0x00,0xe3,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // e0
86 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 // f0
88 static const uint8_t matrix_kana[256] = {
89 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x08,0x09,0x00,0x00, 0x00,0x0d,0x00,0x00, // 00
90 0x00,0x00,0x00,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1b, 0x00,0x00,0x00,0x00, // 10
91 0x20,0x00,0x00,0x00, 0x0b,0x1d,0x1e,0x1c, 0x1f,0x00,0x00,0x00, 0x00,0x12,0x7f,0x00, // 20
92 0xdc,0xc7,0xcc,0xb1, 0xb3,0xb4,0xb5,0xd4, 0xd5,0xd6,0x00,0x00, 0x00,0x00,0x00,0x00, // 30
93 0x00,0xc1,0xba,0xbf, 0xbc,0xb2,0xca,0xb7, 0xb8,0xc6,0xcf,0xc9, 0xd8,0xd3,0xd0,0xd7, // 40
94 0xbe,0xc0,0xbd,0xc4, 0xb6,0xc5,0xcb,0xc3, 0xbb,0xdd,0xc2,0x00, 0x00,0x00,0x00,0x00, // 50
95 0x30,0x31,0x32,0x33, 0x34,0x35,0x36,0x37, 0x38,0x39,0x00,0x2b, 0x00,0x00,0x2e,0x00, // 60
96 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x10,0x03,0x15,0x00, 0x00,0x00,0x00,0x00, // 70
97 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 80
98 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 90
99 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // a0
100 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0xb9,0xda, 0xc8,0xce,0xd9,0xd2, // b0
101 0xde,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // c0
102 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xdf, 0xb0,0xd1,0xcd,0x00, // d0
103 0x00,0x00,0xdb,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // e0
104 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 // f0
106 static const uint8_t matrix_shiftkana[256] = {
107 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 00
108 0x00,0x00,0x00,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 10
109 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 20
110 0xa6,0x00,0x00,0xa7, 0xa9,0xaa,0xab,0xac, 0xad,0xae,0x00,0x00, 0x00,0x00,0x00,0x00, // 30
111 0x00,0x00,0x00,0x00, 0x00,0xa8,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 40
112 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0xaf,0x00, 0x00,0x00,0x00,0x00, // 50
113 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 60
114 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x10,0x03,0x15,0x00, 0x00,0x00,0x00,0x00, // 70
115 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 80
116 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // 90
117 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // a0
118 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0xa4,0x00,0xa1,0xa5, // b0
119 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // c0
120 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xa2, 0x00,0xa3,0x00,0x00, // d0
121 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, // e0
122 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 // f0
125 void KEYBOARD::initialize()
127 key_stat = emu->get_key_buffer();
128 register_frame_event(this);
131 void KEYBOARD::reset()
133 caps = caps_prev = false;
134 graph = graph_prev = false;
135 kana = kana_prev = false;
137 code = code_prev = 0;
141 void KEYBOARD::write_io8(uint32_t addr, uint32_t data)
143 switch(addr & 0xff) {
151 uint32_t KEYBOARD::read_io8(uint32_t addr)
153 switch(addr & 0xff) {
167 } else if(init == 2) {
170 } else if(init == 3) {
179 void KEYBOARD::event_frame()
181 bool shift = (key_stat[0x10] != 0);
182 bool ctrl = (key_stat[0x11] != 0);
183 caps = (key_stat[0x14] && !caps_prev) ? !caps : caps;
184 graph = (key_stat[0x12] && !graph_prev) ? !graph : graph;
185 kana = (key_stat[0x15] && !kana_prev) ? !kana : kana;
186 bool function = false;
188 caps_prev = (key_stat[0x14] != 0);
189 graph_prev = (key_stat[0x12] != 0);
190 kana_prev = (key_stat[0x15] != 0);
192 uint8_t next_stat, next_code = 0;
197 } else if(key_stat[0x71]) {
200 } else if(key_stat[0x72]) {
203 } else if(key_stat[0x73]) {
207 const uint8_t* matrix = matrix_normal;
209 matrix = matrix_ctrl;
211 matrix = matrix_graph;
212 } else if(kana && shift) {
213 matrix = matrix_shiftkana;
214 } else if(kana && !shift) {
215 matrix = matrix_kana;
217 matrix = matrix_shift;
219 for(int i = 0; i < 256; i++) {
221 next_code = matrix[i];
228 if('a' <= next_code && next_code <= 'z') {
230 } else if('A' <= next_code && next_code <= 'Z') {
235 bool press = (next_code || function);
236 next_stat = (shift ? 0x80 : 0) | (function ? 0x40 : 0) | (press ? 0 : 0x08);
238 if(next_code != code && press) {
245 #define STATE_VERSION 1
247 bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
249 if(!state_fio->StateCheckUint32(STATE_VERSION)) {
252 if(!state_fio->StateCheckInt32(this_device_id)) {
255 state_fio->StateInt32(init);
256 state_fio->StateUint8(code);
257 state_fio->StateUint8(code_prev);
258 state_fio->StateUint8(stat);
259 state_fio->StateBool(caps);
260 state_fio->StateBool(caps_prev);
261 state_fio->StateBool(graph);
262 state_fio->StateBool(graph_prev);
263 state_fio->StateBool(kana);
264 state_fio->StateBool(kana_prev);