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

Subversion Repositories thor

[/] [thor/] [trunk/] [software/] [emuThor/] [source/] [clsKeyboard.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 robfinch
#pragma once
2 32 robfinch
#include "clsDevice.h"
3 35 robfinch
// Keyboard Device Emulation
4
//
5
// The keyboard controller code loops around until there are no more scan
6
// codes available from the keyboard. In real life an interrupt signal is
7
// generated by each scan code sent by the keyboard. There is no hardware
8
// buffering of scan-codes. In the emulation only a single emulation 
9
// interrupt is generated for a keypress(button) event and multiple scan
10
// codes are buffered. Rather than emulate the keyboard interface more
11
// closely the emulation is simplified and the driver software recognizes
12
// the way the emulation works. Otherwise it might be necessary to
13
// implement the keyboard interface in it's own thread with calls to
14
// Sleep() between each scan-code transmission.
15
// It should work because the interrupt routine checks for additional
16
// scan codes during it's processing. This is a case where the software
17
// for the system is designed around supporting the emulator.
18
// In real life there should never be two scan-codes sent by the keyboard
19
// close enough together for the loop in the keyboard code to be 
20
// effective. The loop is harmless enough as the scan-code status
21
// needs to be tested anyway. Whether its a while() or an if() is
22
// irrelevant.
23 32 robfinch
 
24
class clsKeyboard : public clsDevice
25 30 robfinch
{
26
        unsigned __int8 buffer[32];
27
        int head;
28
        int tail;
29
public:
30
        volatile unsigned __int8 scancode;
31
        volatile unsigned __int8 status;
32
        clsKeyboard(void);
33
        ~clsKeyboard(void);
34
        bool IsSelected(unsigned int ad) { return ((ad & 0xFFFFFFF0)==0xFFDC0000); };
35
        void Put(unsigned __int8 sc) {
36
                scancode = sc;
37
                buffer[head] = sc;
38
                head++;
39
                head &= 31;
40
        };
41
        unsigned __int8 Get() {
42
                unsigned __int8 sc;
43
 
44
                sc = 0;
45
                if (head != tail) {
46
                        sc = buffer[tail];
47
                        tail++;
48
                        tail &= 31;
49
                }
50
                return sc;
51
        };
52
        unsigned __int8 Peek(int amt) {
53
                unsigned __int8 sc;
54
                int ndx;
55
 
56
                ndx = tail + amt;
57
                ndx &= 31;
58
                sc = buffer[ndx];
59
                return sc;
60
        };
61
        unsigned __int8 GetStatus() {
62
                if (head != tail)
63
                        return 0x80;
64
                else
65
                        return 0x00;
66
        };
67
};
68
 

powered by: WebSVN 2.1.0

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