OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [sim/] [Keyboard.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#pragma once
19
 
20
#include <stdint.h>
21
#include "Simulator.h"
22
 
23
#include <SDL_events.h>
24
 
25
#include <boost/serialization/list.hpp>
26
#include <boost/serialization/deque.hpp>
27
#include <boost/serialization/string.hpp>
28
#include <boost/serialization/version.hpp>
29
 
30
#include <map>
31
#include <deque>
32
 
33
#include "SoftwareCPU.h"
34
#include "PIC.h"
35
#include "../bios/bda.h"
36
 
37
static std::map<int, std::vector<unsigned char>> sdl_to_keyboard = {
38
    {SDLK_a, {0x1c}},
39
    {SDLK_b, {0x32}},
40
    {SDLK_c, {0x21}},
41
    {SDLK_d, {0x23}},
42
    {SDLK_e, {0x24}},
43
    {SDLK_f, {0x2b}},
44
    {SDLK_g, {0x34}},
45
    {SDLK_h, {0x33}},
46
    {SDLK_i, {0x43}},
47
    {SDLK_j, {0x3b}},
48
    {SDLK_k, {0x42}},
49
    {SDLK_l, {0x4b}},
50
    {SDLK_m, {0x3a}},
51
    {SDLK_n, {0x31}},
52
    {SDLK_o, {0x44}},
53
    {SDLK_p, {0x4d}},
54
    {SDLK_q, {0x15}},
55
    {SDLK_r, {0x2d}},
56
    {SDLK_s, {0x1b}},
57
    {SDLK_t, {0x2c}},
58
    {SDLK_u, {0x3c}},
59
    {SDLK_v, {0x2a}},
60
    {SDLK_w, {0x1d}},
61
    {SDLK_x, {0x22}},
62
    {SDLK_y, {0x35}},
63
    {SDLK_z, {0x1a}},
64
    {SDLK_1, {0x16}},
65
    {SDLK_2, {0x1e}},
66
    {SDLK_3, {0x26}},
67
    {SDLK_4, {0x25}},
68
    {SDLK_5, {0x2e}},
69
    {SDLK_6, {0x36}},
70
    {SDLK_7, {0x3d}},
71
    {SDLK_8, {0x3e}},
72
    {SDLK_9, {0x46}},
73
    {SDLK_0, {0x45}},
74
    {SDLK_MINUS, {0x4e}},
75
    {SDLK_EQUALS, {0x55}},
76
    {SDLK_LEFTBRACKET, {0x54}},
77
    {SDLK_RIGHTBRACKET, {0x5b}},
78
    {SDLK_SEMICOLON, {0x4c}},
79
    {SDLK_QUOTE, {0x52}},
80
    {SDLK_BACKQUOTE, {0x0e}},
81
    {SDLK_BACKSLASH, {0x5d}},
82
    {SDLK_COMMA, {0x41}},
83
    {SDLK_PERIOD, {0x49}},
84
    {SDLK_SLASH, {0x4a}},
85
    {SDLK_F1, {0x05}},
86
    {SDLK_F2, {0x06}},
87
    {SDLK_F3, {0x04}},
88
    {SDLK_F4, {0x0c}},
89
    {SDLK_F5, {0x03}},
90
    {SDLK_F6, {0x0b}},
91
    {SDLK_F7, {0x83}},
92
    {SDLK_F8, {0x0a}},
93
    {SDLK_F9, {0x01}},
94
    {SDLK_F10, {0x09}},
95
    {SDLK_F11, {0x78}},
96
    {SDLK_F12, {0x07}},
97
    {SDLK_BACKSPACE, {0x66}},
98
    {SDLK_DELETE, {0xe0, 0x71}},
99
    {SDLK_DOWN, {0xe0, 0x72}},
100
    {SDLK_END, {0xe0, 0x69}},
101
    {SDLK_RETURN, {0x5a}},
102
    {SDLK_ESCAPE, {0x76}},
103
    {SDLK_HOME, {0xe0, 0x6c}},
104
    {SDLK_INSERT, {0xe0, 0x70}},
105
    {SDLK_LEFT, {0xe0, 0x6b}},
106
    {SDLK_PAGEDOWN, {0xe0, 0x7a}},
107
    {SDLK_PAGEUP, {0xe0, 0x7d}},
108
    {SDLK_PRINTSCREEN, {0xe0, 0x12, 0xe0, 0x7c}},
109
    {SDLK_RIGHT, {0xe0, 0x74}},
110
    {SDLK_SPACE, {0x29}},
111
    {SDLK_TAB, {0x0d}},
112
    {SDLK_UP, {0xe0, 0x75}},
113
    {SDLK_LCTRL, {0x14}},
114
    {SDLK_LALT, {0x11}},
115
    {SDLK_LSHIFT, {0x12}},
116
};
117
 
118
static const uint8_t ps2_ctrl_rx_valid = 1 << 0;
119
 
120
class Keyboard : public IOPorts
121
{
122
public:
123
    Keyboard(PIC *pic) : IOPorts(0x0060, 1), pic(pic)
124
    {
125
    }
126
 
127
    void write8(uint16_t __unused port_num,
128
                unsigned __unused offs,
129
                uint8_t __unused v)
130
    {
131
        if (offs == 1 && (v & ps2_ctrl_rx_valid)) {
132
            if (pending.size())
133
                pending.pop_front();
134
        }
135
    }
136
 
137
    uint8_t read8(uint16_t __unused port_num, unsigned __unused offs)
138
    {
139
        if (offs)
140
            return 0;
141
 
142
        return pending.size() ? pending.front() : 0;
143
    }
144
 
145
    void set_scancode(uint8_t v)
146
    {
147
        pic->raise_irq(1);
148
 
149
        pending.push_back(v);
150
    }
151
 
152
    void process_event(SDL_Event e)
153
    {
154
        if (sdl_to_keyboard.count(e.key.keysym.sym) == 0)
155
            return;
156
 
157
        for (auto b : sdl_to_keyboard[e.key.keysym.sym]) {
158
            if (e.type == SDL_KEYUP)
159
                set_scancode(0xf0);
160
            set_scancode(b);
161
        }
162
    }
163
 
164
private:
165
    PIC *pic;
166
    std::deque<uint8_t> pending;
167
 
168
    friend class boost::serialization::access;
169
    template <class Archive>
170
    void serialize(Archive &ar, const unsigned int __unused version)
171
    {
172
        // clang-format off
173
        ar & pending;
174
        // clang-format on
175
    }
176
};

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.