OSDN Git Service

[VM] TRY:Use namespace {VMNAME} to separate around VMs. This feature still apply...
[csp-qt/common_source_project-fm7.git] / source / src / vm / colecovision / keyboard.cpp
1 /*
2         COLECO ColecoVision Emulator 'yaCOLECOVISION'
3
4         Author : tanam
5         Date   : 2016.08.14-
6
7         [ keyboard ]
8 */
9
10 #include "keyboard.h"
11
12 namespace COLECOVISION {
13 void KEYBOARD::initialize()
14 {
15         key_stat = emu->get_key_buffer();
16         joy_stat = emu->get_joy_buffer();
17         // register event to update the key status
18 //      register_frame_event(this); // is this needed?
19 }
20
21 void KEYBOARD::event_frame()
22 {
23         if (joy_stat[0] & 0x04 || joy_stat[0] & 0x08) {
24                 d_cpu->write_signal(SIG_CPU_IRQ, 1, 1);
25         }
26 }
27
28 void KEYBOARD::write_io8(uint32_t addr, uint32_t data)
29 {
30         if ((addr & 0x000000ff)==0x80) {
31                 tenkey=true;
32         }
33         if ((addr & 0x000000ff)==0xc0) {
34                 tenkey=false;
35         }
36         return;
37 }
38
39 uint32_t KEYBOARD::read_io8(uint32_t addr)
40 {
41         // Controller 1
42         if ((addr & 0x000000ff)==0xfc) {
43                 uint32_t button=0x70;//0xf0;
44                 if (!tenkey) {
45                         uint32_t joystick=0x7f;//0xff;
46                         if (joy_stat[0] & 0x01) joystick &= 0xfe;       // U
47                         if (joy_stat[0] & 0x02) joystick &= 0xfb;       // D
48                         if (joy_stat[0] & 0x04) joystick &= 0xf7;       // L
49                         if (joy_stat[0] & 0x08) joystick &= 0xfd;       // R
50                         if (joy_stat[0] & 0x20) joystick &= 0xbf;       // F1
51                         return joystick;
52                 }
53                 if (joy_stat[0] & 0x10)
54                         button &= 0xbf;         // F2
55                 if ((key_stat[0x31] & 0x80) || (key_stat[0x61] & 0x80))
56                         return (button | 0x0d); // 1
57                 if ((key_stat[0x32] & 0x80) || (key_stat[0x62] & 0x80))
58                         return (button | 0x07); // 2
59                 if ((key_stat[0x33] & 0x80) || (key_stat[0x63] & 0x80))
60                         return (button | 0x0c); // 3
61                 if ((key_stat[0x34] & 0x80) || (key_stat[0x64] & 0x80))
62                         return (button | 0x02); // 4
63                 if ((key_stat[0x35] & 0x80) || (key_stat[0x65] & 0x80))
64                         return (button | 0x03); // 5
65                 if ((key_stat[0x36] & 0x80) || (key_stat[0x66] & 0x80))
66                         return (button | 0x0e); // 6
67                 if ((key_stat[0x37] & 0x80) || (key_stat[0x67] & 0x80))
68                         return (button | 0x05); // 7
69                 if ((key_stat[0x38] & 0x80) || (key_stat[0x68] & 0x80))
70                         return (button | 0x01); // 8
71                 if ((key_stat[0x39] & 0x80) || (key_stat[0x69] & 0x80))
72                         return (button | 0x0b); // 9
73                 if ((key_stat[0x30] & 0x80) || (key_stat[0x60] & 0x80))
74                         return (button | 0x0a); // 0
75                 if (key_stat[0xbd] & 0x80)
76                         return (button | 0x09); // * '-'
77                 if (key_stat[0xde] & 0x80)
78                         return (button | 0x06); // # '^'
79                 if (key_stat[0x43] & 0x80)
80                         return (button | 0x08); // F3 'c'
81                 if (key_stat[0x56] & 0x80)
82                         return (button | 0x04); // F4 'v'
83                 return (button | 0x0f);
84         }
85         // Controller 2
86         if ((addr & 0x000000ff)==0xff) {
87                 uint32_t button=0x70;//0xf0;
88                 if (!tenkey) {
89                         uint32_t joystick=0x7f;//0xff;
90                         if (joy_stat[1] & 0x01) joystick &= 0xfe;       // U
91                         if (joy_stat[1] & 0x02) joystick &= 0xfb;       // D
92                         if (joy_stat[1] & 0x04) joystick &= 0xf7;       // L
93                         if (joy_stat[1] & 0x08) joystick &= 0xfd;       // R
94                         if (joy_stat[1] & 0x20) joystick &= 0xbf;       // F1
95                         return joystick;
96                 }
97                 if (joy_stat[1] & 0x10)
98                         button &= 0xbf;         // F2
99                 if (key_stat[0x51] & 0x80)
100                         return (button | 0x0d); // 1 'q'
101                 if (key_stat[0x57] & 0x80)
102                         return (button | 0x07); // 2 'w'
103                 if (key_stat[0x45] & 0x80)
104                         return (button | 0x0c); // 3 'e'
105                 if (key_stat[0x52] & 0x80)
106                         return (button | 0x02); // 4 'r'
107                 if (key_stat[0x54] & 0x80)
108                         return (button | 0x03); // 5 't'
109                 if (key_stat[0x59] & 0x80)
110                         return (button | 0x0e); // 6 'y'
111                 if (key_stat[0x55] & 0x80)
112                         return (button | 0x05); // 7 'u'
113                 if (key_stat[0x49] & 0x80)
114                         return (button | 0x01); // 8 'i'
115                 if (key_stat[0x4f] & 0x80)
116                         return (button | 0x0b); // 9 'o'
117                 if (key_stat[0x50] & 0x80)
118                         return (button | 0x0a); // 0 'p'
119                 if (key_stat[0xc0] & 0x80)
120                         return (button | 0x09); // * '@'
121                 if (key_stat[0xdb] & 0x80)
122                         return (button | 0x06); // # '['
123                 if (key_stat[0xbc] & 0x80)
124                         return (button | 0x08); // F3 ','
125                 if (key_stat[0xbe] & 0x80)
126                         return (button | 0x04); // F4 '.'
127                 return (button | 0x0f);
128         }
129         return 0x0ff;
130 }
131
132 #define STATE_VERSION   2
133
134 bool KEYBOARD::process_state(FILEIO* state_fio, bool loading)
135 {
136         if(!state_fio->StateCheckUint32(STATE_VERSION)) {
137                 return false;
138         }
139         if(!state_fio->StateCheckInt32(this_device_id)) {
140                 return false;
141         }
142         state_fio->StateBool(tenkey);
143         return true;
144 }
145 }