OSDN Git Service

[General][Qt] Merge upstream 2015-03-15.
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz700 / keyboard.cpp
1 /*
2         SHARP MZ-700 Emulator 'EmuZ-700'
3         SHARP MZ-800 Emulator 'EmuZ-800'
4         SHARP MZ-1500 Emulator 'EmuZ-1500'
5
6         Author : Takeda.Toshiya
7         Date   : 2008.06.05 -
8
9         [ keyboard ]
10 */
11
12 #include "keyboard.h"
13 #include "../i8255.h"
14
15 static const int key_map[10][8] = {
16 #if defined(_MZ800)
17         {0x0d, 0xba, 0xbb, 0x14, 0x09, 0x78, 0x21, 0x22},
18 #else
19         {0x0d, 0xba, 0xbb, 0x00, 0x09, 0x78, 0x21, 0x22},
20 #endif
21         {0x00, 0x00, 0x00, 0xdd, 0xdb, 0xc0, 0x5a, 0x59},
22         {0x58, 0x57, 0x56, 0x55, 0x54, 0x53, 0x52, 0x51},
23         {0x50, 0x4f, 0x4e, 0x4d, 0x4c, 0x4b, 0x4a, 0x49},
24         {0x48, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41},
25         {0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31},
26         {0xbe, 0xbc, 0x39, 0x30, 0x20, 0xbd, 0xde, 0xdc},
27         {0xbf, 0xe2, 0x25, 0x27, 0x28, 0x26, 0x2e, 0x2d},
28         {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x08},
29         {0x00, 0x00, 0x00, 0x74, 0x73, 0x72, 0x71, 0x70}
30 };
31
32 void KEYBOARD::initialize()
33 {
34         key_stat = emu->key_buffer();
35         column = 0;
36         
37         // register event
38         register_frame_event(this);
39 }
40
41 void KEYBOARD::write_signal(int id, uint32 data, uint32 mask)
42 {
43         column = data & 0x0f;
44         update_key();
45 }
46
47 void KEYBOARD::event_frame()
48 {
49         update_key();
50 }
51
52 void KEYBOARD::update_key()
53 {
54         uint8 stat = 0xff;
55         
56         if(column < 10) {
57                 for(int i = 0; i < 8; i++) {
58                         if(key_stat[key_map[column][i]]) {
59                                 stat &= ~(1 << i);
60                         }
61                 }
62         }
63         d_pio->write_signal(SIG_I8255_PORT_B, stat, 0xff);
64 }
65
66 #define STATE_VERSION   1
67
68 void KEYBOARD::save_state(FILEIO* state_fio)
69 {
70         state_fio->FputUint32(STATE_VERSION);
71         state_fio->FputInt32(this_device_id);
72         
73         state_fio->FputUint8(column);
74 }
75
76 bool KEYBOARD::load_state(FILEIO* state_fio)
77 {
78         if(state_fio->FgetUint32() != STATE_VERSION) {
79                 return false;
80         }
81         if(state_fio->FgetInt32() != this_device_id) {
82                 return false;
83         }
84         column = state_fio->FgetUint8();
85         return true;
86 }
87