blob: 7acccfbed3ebc5767cb54856858db8151d82e22a (
plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/*
RCC-Project
Copyright (C) 2026 Richard Qin
This file is part of RCC-Project.
RCC-Project is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.
RCC-Project is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
*/
#include "bios.h"
#include "regs.h"
#define BIOS_ZF 0x0040u
#define BDA_KBD_HEAD 0x041Au
#define BDA_KBD_TAIL 0x041Cu
#define BDA_KBD_BUFFER 0x041Eu
#define BDA_KBD_BUFFER_END 0x043Eu
static u8
scancode_to_ascii (u8 scancode)
{
switch (scancode)
{
case 0x1Eu:
return 'a';
case 0x30u:
return 'b';
case 0x2Eu:
return 'c';
case 0x20u:
return 'd';
case 0x12u:
return 'e';
case 0x21u:
return 'f';
case 0x22u:
return 'g';
case 0x23u:
return 'h';
case 0x17u:
return 'i';
case 0x24u:
return 'j';
case 0x25u:
return 'k';
case 0x26u:
return 'l';
case 0x32u:
return 'm';
case 0x31u:
return 'n';
case 0x18u:
return 'o';
case 0x19u:
return 'p';
case 0x10u:
return 'q';
case 0x13u:
return 'r';
case 0x1Fu:
return 's';
case 0x14u:
return 't';
case 0x16u:
return 'u';
case 0x2Fu:
return 'v';
case 0x11u:
return 'w';
case 0x2Du:
return 'x';
case 0x15u:
return 'y';
case 0x2Cu:
return 'z';
case 0x39u:
return ' ';
case 0x1Cu:
return '\r';
default:
return 0;
}
}
void
int16_service (struct bios_regs *regs)
{
volatile u16 *head;
volatile u16 *tail;
volatile u16 *buffer;
u8 function;
u16 position;
u16 value;
u8 scancode;
u8 ascii;
function = (u8)(regs->eax >> 8);
if (function != 0x00u && function != 0x01u)
{
regs->eax = 0;
regs->flags |= BIOS_ZF;
return;
}
head = (volatile u16 *)BDA_KBD_HEAD;
tail = (volatile u16 *)BDA_KBD_TAIL;
buffer = (volatile u16 *)BDA_KBD_BUFFER;
if (*head == *tail)
{
regs->eax = 0;
regs->flags |= BIOS_ZF;
return;
}
position = *head;
value = buffer[(position - BDA_KBD_BUFFER) >> 1];
scancode = (u8)(value >> 8);
ascii = scancode_to_ascii (scancode);
regs->eax = ((u32)scancode << 8) | ascii;
regs->flags &= (u16)~BIOS_ZF;
if (function == 0x00u)
{
position += 2;
if (position >= BDA_KBD_BUFFER_END)
position = BDA_KBD_BUFFER;
*head = position;
}
}
|