-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathhw_fifo.cpp
More file actions
91 lines (77 loc) · 3.27 KB
/
hw_fifo.cpp
File metadata and controls
91 lines (77 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// *******************************************************************************************************************************
// *******************************************************************************************************************************
//
// Name: hw_fifo.c
// Purpose: Hardware Emulation (Stefany's interface)
// Created: 12th December 2022
// Author: Paul Robson ([email protected])
//
// *******************************************************************************************************************************
// *******************************************************************************************************************************
#include "sys_processor.h"
#include "hardware.h"
#include "gfx.h"
#include <stdio.h>
#include <stdlib.h>
#define FIFO_QUEUE_SIZE (8)
static int queueSize;
static int fifoQueue[FIFO_QUEUE_SIZE];
// *******************************************************************************************************************************
//
// Empty the new FIFO queue
//
// *******************************************************************************************************************************
void HWResetKeyboardHardware(void) {
queueSize = 0;
}
// *******************************************************************************************************************************
//
// Add a received key event to the queue, if space available
//
// *******************************************************************************************************************************
void HWKeyboardHardwareDequeue(int key) {
//printf("Received : %x\n",key);
if (queueSize < FIFO_QUEUE_SIZE) {
fifoQueue[queueSize++] = key;
}
}
// *******************************************************************************************************************************
//
// Simple PS/2 implementation
//
// *******************************************************************************************************************************
BYTE8 HWReadKeyboardHardware(WORD16 address) {
if (address == 0xD644) {
return (queueSize == 0) ? 1 : 0;
}
if (address == 0xD642 && queueSize > 0) {
int head = fifoQueue[0];
//printf("Popped : %x\n",head);
for (int i = 0;i < queueSize;i++) {
fifoQueue[i] = fifoQueue[i+1];
}
queueSize--;
return head;
}
return 0;
}
// *******************************************************************************************************************************
//
// Even simpler control implementation, sufficient to function
//
// *******************************************************************************************************************************
void HWWriteKeyboardHardware(WORD16 address,BYTE8 data) {
// Should clear the queue here. Not really required ?
}
// *******************************************************************************************************************************
//
// Interrupt for new key enabled ?
//
// *******************************************************************************************************************************
int HWCheckKeyboardInterruptEnabled(void) {
if ((IOReadMemory(0,0xD66C) & 0x04) == 0) { // Bit masked zero ?
IOWriteMemory(0,0xD660,4); // Set Pending Reg Bit 2
return -1;
}
return 0;
}