OSDN Git Service

[General] Convert sourcecode's CRLF format: DOS(WINDOWS) to Unix, to apply patches...
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz2500 / keyboard.cpp
1 /*
2         SHARP MZ-80B Emulator 'EmuZ-80B'
3         SHARP MZ-2200 Emulator 'EmuZ-2200'
4         SHARP MZ-2500 Emulator 'EmuZ-2500'
5
6         Author : Takeda.Toshiya
7         Date   : 2006.12.01 -
8
9         [ keyboard ]
10 */
11
12 #include "keyboard.h"
13 #include "../i8255.h"
14 #include "../z80pio.h"
15 #include "../../fileio.h"
16
17 #ifdef _MZ2500
18 #define MAX_COLUMN 14
19 #else
20 #define MAX_COLUMN 12
21 #endif
22
23 static const int key_map[14][8] = {
24         {0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77},
25         {0x78, 0x79, 0x68, 0x69, 0x6c, 0x6e, 0x6b, 0x6d},
26         {0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67},
27         {0x09, 0x20, 0x0d, 0x26, 0x28, 0x25, 0x27, 0x13},
28         {0xbf, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47},
29         {0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f},
30         {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57},
31         {0x58, 0x59, 0x5a, 0xde, 0xdc, 0xe2, 0xbe, 0xbc},
32         {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37},
33         {0x38, 0x39, 0xba, 0xbb, 0xbd, 0xc0, 0xdb, 0x00},
34         {0xdd, 0x7b, 0x24, 0x2e, 0x08, 0x1b, 0x6a, 0x6f},
35         {0x12, 0x14, 0x10, 0x15, 0x11, 0x00, 0x00, 0x00},
36         {0x1d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
37         {0x19, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
38 };
39
40 void KEYBOARD::initialize()
41 {
42         key_stat = emu->key_buffer();
43         column = 0;
44         register_frame_event(this);
45 }
46
47 void KEYBOARD::write_signal(int id, uint32 data, uint32 mask)
48 {
49         if(id == SIG_KEYBOARD_COLUMN) {
50                 column = data & mask;   // from z80pio port a
51                 create_keystat();
52         }
53 }
54
55 void KEYBOARD::event_frame()
56 {
57         // update key status
58         memset(keys, 0xff, sizeof(keys));
59         key_stat[0] = 0;
60         for(int i = 0; i < MAX_COLUMN; i++) {
61                 uint8 tmp = 0;
62                 for(int j = 0; j < 8; j++) {
63                         tmp |= (key_stat[key_map[i][j]]) ? 0 : (1 << j);
64                 }
65                 keys[i] = tmp;
66                 keys[0x0f] &= tmp;
67         }
68         create_keystat();
69 }
70
71 void KEYBOARD::create_keystat()
72 {
73         uint8 val = keys[(column & 0x10) ? (column & 0x0f) : 0x0f];
74         d_pio_i->write_signal(SIG_I8255_PORT_B, val, 0x80);     // to i8255 port b
75         d_pio->write_signal(SIG_Z80PIO_PORT_B, val, 0xff);      // to z80pio port b
76 }
77
78 #define STATE_VERSION   1
79
80 void KEYBOARD::save_state(FILEIO* state_fio)
81 {
82         state_fio->FputUint32(STATE_VERSION);
83         state_fio->FputInt32(this_device_id);
84         
85         state_fio->FputUint8(column);
86 }
87
88 bool KEYBOARD::load_state(FILEIO* state_fio)
89 {
90         if(state_fio->FgetUint32() != STATE_VERSION) {
91                 return false;
92         }
93         if(state_fio->FgetInt32() != this_device_id) {
94                 return false;
95         }
96         column = state_fio->FgetUint8();
97         return true;
98 }
99