OSDN Git Service

[VM][State] Apply new state framework to some VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / ex80 / keyboard.cpp
1 /*
2         TOSHIBA EX-80 Emulator 'eEX-80'
3
4         Author : Takeda.Toshiya
5         Date   : 2015.12.10-
6
7         [ keyboard ]
8 */
9
10 #include "keyboard.h"
11 #include "../i8255.h"
12
13 void KEYBOARD::initialize()
14 {
15         column = 0xff;
16         register_frame_event(this);
17 }
18
19 void KEYBOARD::write_signal(int id, uint32_t data, uint32_t mask)
20 {
21         column = data & mask;
22         event_frame();
23 }
24
25 void KEYBOARD::event_frame()
26 {
27         const uint8_t* key_stat = emu->get_key_buffer();
28         uint32_t val = 0xff;
29         
30         if(!(column & 0x10)) {
31                 if(key_stat[0x80] || key_stat[0x30] || key_stat[0x60]) val &= ~0x01;    // 0
32                 if(key_stat[0x81] || key_stat[0x31] || key_stat[0x61]) val &= ~0x02;    // 1
33                 if(key_stat[0x82] || key_stat[0x32] || key_stat[0x62]) val &= ~0x04;    // 2
34                 if(key_stat[0x83] || key_stat[0x33] || key_stat[0x63]) val &= ~0x08;    // 3
35                 if(key_stat[0x84] || key_stat[0x34] || key_stat[0x64]) val &= ~0x10;    // 4
36                 if(key_stat[0x85] || key_stat[0x35] || key_stat[0x65]) val &= ~0x20;    // 5
37                 if(key_stat[0x86] || key_stat[0x36] || key_stat[0x66]) val &= ~0x40;    // 6
38                 if(key_stat[0x87] || key_stat[0x37] || key_stat[0x67]) val &= ~0x80;    // 7
39         }
40         if(!(column & 0x20)) {
41                 if(key_stat[0x88] || key_stat[0x38] || key_stat[0x68]) val &= ~0x01;    // 8
42                 if(key_stat[0x89] || key_stat[0x39] || key_stat[0x69]) val &= ~0x02;    // 9
43                 if(key_stat[0x8a] || key_stat[0x41]                  ) val &= ~0x04;    // A
44                 if(key_stat[0x8b] || key_stat[0x42]                  ) val &= ~0x08;    // B
45                 if(key_stat[0x8c] || key_stat[0x43]                  ) val &= ~0x10;    // C
46                 if(key_stat[0x8d] || key_stat[0x44]                  ) val &= ~0x20;    // D
47                 if(key_stat[0x8e] || key_stat[0x45]                  ) val &= ~0x40;    // E
48                 if(key_stat[0x8f] || key_stat[0x46]                  ) val &= ~0x80;    // F
49         }
50         if(!(column & 0x40)) {
51                 if(key_stat[0x98] || key_stat[0x70]                  ) val &= ~0x02;    // RET ... F1
52                 if(key_stat[0x99] || key_stat[0x71]                  ) val &= ~0x01;    // RUN ... F2
53                 if(key_stat[0x9a] || key_stat[0x72]                  ) val &= ~0x40;    // SDA ... F3
54                 if(key_stat[0x9b] || key_stat[0x73]                  ) val &= ~0x80;    // LDA ... F4
55                 if(key_stat[0x9c] || key_stat[0x74]                  ) val &= ~0x04;    // ADR ... F5
56                 if(key_stat[0x9d] || key_stat[0x75] || key_stat[0x21]) val &= ~0x10;    // RIC ... F6 or PgUp
57                 if(key_stat[0x9e] || key_stat[0x76] || key_stat[0x22]) val &= ~0x08;    // RDC ... F7 or PgDn
58                 if(key_stat[0x9f] || key_stat[0x77] || key_stat[0x0d]) val &= ~0x20;    // WIC ... F8 or Enter
59         }
60         d_pio->write_signal(SIG_I8255_PORT_A, val, 0xff);
61 }
62
63 #define STATE_VERSION   1
64
65 bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
66 {
67         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
68                 return false;
69         }
70         if(!state_fio->StateCheckInt32(this_device_id)) {
71                 return false;
72         }
73         state_fio->StateUint32(column);
74         return true;
75 }