OSDN Git Service

[VM][STATE] Use namespace {VMNAME} to separate per VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz2800 / keyboard.cpp
1 /*
2         SHARP MZ-2800 Emulator 'EmuZ-2800'
3
4         Author : Takeda.Toshiya
5         Date   : 2007.08.13 -
6
7         [ keyboard ]
8 */
9
10 #include "keyboard.h"
11 #include "../i8255.h"
12 #include "../z80pio.h"
13
14 namespace MZ2800 {
15
16 static const int key_map[14][8] = {
17         {0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77},
18         {0x78, 0x79, 0x68, 0x69, 0x6c, 0x6e, 0x6b, 0x6d},
19         {0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67},
20         {0x09, 0x20, 0x0d, 0x26, 0x28, 0x25, 0x27, 0x13},
21         {0xbf, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47},
22         {0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f},
23         {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57},
24         {0x58, 0x59, 0x5a, 0xde, 0xdc, 0xe2, 0xbe, 0xbc},
25         {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37},
26         {0x38, 0x39, 0xba, 0xbb, 0xbd, 0xc0, 0xdb, 0x00},
27         {0xdd, 0x7b, 0x24, 0x2e, 0x08, 0x1b, 0x6a, 0x6f},
28         {0xa4, 0x14, 0x10, 0x15, 0xa2, 0x00, 0x00, 0x00},
29         {0x1d, 0x1c, 0x00, 0xa3, 0xa5, 0x00, 0x00, 0x00},
30         {0x19, 0x7a, 0x00, 0x7c, 0x7d, 0x7e, 0x7d, 0x00}
31 };
32
33 void KEYBOARD::initialize()
34 {
35         key_stat = emu->get_key_buffer();
36         column = 0;
37         register_frame_event(this);
38 }
39
40 void KEYBOARD::write_signal(int id, uint32_t data, uint32_t mask)
41 {
42         if(id == SIG_KEYBOARD_COLUMN) {
43                 column = data & mask;   // from z80pio port a
44                 create_keystat();
45         }
46 }
47
48 void KEYBOARD::event_frame()
49 {
50         // update key status
51         uint8_t buf[256];
52         memcpy(buf, key_stat, sizeof(buf));
53         
54         if(!buf[0x10] && buf[0x21]) {
55                 buf[0x7c] = 0x80;       // PAGE UP -> F13
56         }
57         if(!buf[0x10] && buf[0x22]) {
58                 buf[0x7d] = 0x80;       // PAGE UP -> F14
59         }
60         if(buf[0x10] && buf[0x21]) {
61                 buf[0x7e] = 0x80;       // SHIFT + PAGE UP -> F15
62         }
63         if(buf[0x10] && buf[0x22]) {
64                 buf[0x7f] = 0x80;       // SHIFT + PAGE DOWN -> F16
65         }
66         if(buf[0x2d]) {
67                 buf[0x10] = buf[0x2e] = 0x80;   // INS -> SHIFT + DEL
68         }
69         buf[0] = 0;
70         
71         keys[0xf] = 0xff;
72         for(int i = 0; i <= 0xd; i++) {
73                 uint8_t tmp = 0;
74                 for(int j = 0; j < 8; j++) {
75                         tmp |= (buf[key_map[i][j]]) ? 0 : (1 << j);
76                 }
77                 keys[i] = tmp;
78                 keys[0xf] &= tmp;
79         }
80         create_keystat();
81 }
82
83 void KEYBOARD::create_keystat()
84 {
85         uint8_t val = (!(column & 0x10)) ? keys[0xf] : ((column & 0xf) > 0xd) ? 0xff : keys[column & 0xf];
86         d_pio0->write_signal(SIG_I8255_PORT_B, val, 0x80);      // to i8255 port b
87         d_pio1->write_signal(SIG_Z80PIO_PORT_B, val, 0xff);     // to z80pio port b
88 }
89
90 #define STATE_VERSION   1
91
92 bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
93 {
94         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
95                 return false;
96         }
97         if(!state_fio->StateCheckInt32(this_device_id)) {
98                 return false;
99         }
100         state_fio->StateUint8(column);
101         return true;
102 }
103
104 }