OSDN Git Service

[VM][FMTOWNS][MEMORY] Fix setup around memory banks by I/O 0404h and 0480h.
[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 namespace MZ700 {
16         
17 static const int key_map[10][8] = {
18 #if defined(_MZ800)
19         {0x0d, 0xba, 0xbb, 0x14, 0x09, 0x78, 0x21, 0x22},
20 #else
21         {0x0d, 0xba, 0xbb, 0x00, 0x09, 0x78, 0x21, 0x22},
22 #endif
23         {0x00, 0x00, 0x00, 0xdd, 0xdb, 0xc0, 0x5a, 0x59},
24         {0x58, 0x57, 0x56, 0x55, 0x54, 0x53, 0x52, 0x51},
25         {0x50, 0x4f, 0x4e, 0x4d, 0x4c, 0x4b, 0x4a, 0x49},
26         {0x48, 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41},
27         {0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31},
28         {0xbe, 0xbc, 0x39, 0x30, 0x20, 0xbd, 0xde, 0xdc},
29         {0xbf, 0xe2, 0x25, 0x27, 0x28, 0x26, 0x2e, 0x2d},
30         {0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x08},
31         {0x00, 0x00, 0x00, 0x74, 0x73, 0x72, 0x71, 0x70}
32 };
33
34 void KEYBOARD::initialize()
35 {
36         key_stat = emu->get_key_buffer();
37         column = 0;
38         
39         // register event
40         register_frame_event(this);
41 }
42
43 void KEYBOARD::write_signal(int id, uint32_t data, uint32_t mask)
44 {
45         column = data & 0x0f;
46         update_key();
47 }
48
49 void KEYBOARD::event_frame()
50 {
51         update_key();
52 }
53
54 void KEYBOARD::update_key()
55 {
56         uint8_t stat = 0xff;
57         
58         if(column < 10) {
59                 for(int i = 0; i < 8; i++) {
60                         if(key_stat[key_map[column][i]]) {
61                                 stat &= ~(1 << i);
62                         }
63                 }
64         }
65         d_pio->write_signal(SIG_I8255_PORT_B, stat, 0xff);
66 }
67
68 #define STATE_VERSION   1
69
70 bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
71 {
72         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
73                 return false;
74         }
75         if(!state_fio->StateCheckInt32(this_device_id)) {
76                 return false;
77         }
78         state_fio->StateValue(column);
79         return true;
80 }
81
82 }