Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SteveOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
SteveOS
Commits
14527775
Commit
14527775
authored
6 years ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
Refactored keyboard code to prepare for applications
parent
97dc2113
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
drivers/keyboard.c
+41
-36
41 additions, 36 deletions
drivers/keyboard.c
drivers/keyboard.h
+6
-0
6 additions, 0 deletions
drivers/keyboard.h
util/terminal.c
+33
-0
33 additions, 0 deletions
util/terminal.c
util/terminal.h
+3
-0
3 additions, 0 deletions
util/terminal.h
with
83 additions
and
36 deletions
drivers/keyboard.c
+
41
−
36
View file @
14527775
...
...
@@ -7,12 +7,6 @@
#include
"../kernel/kernel.h"
#include
"../util/terminal.h"
#define BACKSPACE 0x0E
#define ENTER 0x1C
#define LSHIFT 0x2A
#define RSHIFT 0x36
static
char
key_buffer
[
256
];
static
u8
uppercase
=
0
;
#define SC_MAX 57
...
...
@@ -35,45 +29,56 @@ const char sc_shift_above[] = { '<', '>', '?', '?', '*', '?', ' '}; //0x33 to 0x
static
void
keyboard_callback
(
registers_t
regs
)
{
/* The PIC leaves us the scancode in port 0x60 */
u8
scancode
=
port_byte_in
(
0x60
);
u8
special
=
1
;
if
(
scancode
>
SC_MAX
)
{
//Key being released
scancode
-=
0x80
;
//Difference between release code and press code
if
(
scancode
==
LSHIFT
||
scancode
==
RSHIFT
)
{
uppercase
=
0
;
}
if
(
scancode
>
SC_MAX
)
{
//Key being released
scancode
-=
0x80
;
//Difference between release code and press code
if
(
scancode
==
LSHIFT
||
scancode
==
RSHIFT
)
{
uppercase
=
0
;
}
}
else
{
if
(
scancode
==
LSHIFT
||
scancode
==
RSHIFT
)
{
uppercase
=
1
;
}
else
if
(
scancode
==
BACKSPACE
)
{
if
(
strlen
(
key_buffer
)
>
0
)
{
backspace
(
key_buffer
);
delete_last
();
}
}
else
if
(
scancode
==
ENTER
)
{
newline
();
user_input
(
key_buffer
);
/* kernel-controlled function */
key_buffer
[
0
]
=
'\0'
;
}
else
{
if
(
scancode
==
LSHIFT
||
scancode
==
RSHIFT
)
{
uppercase
=
1
;
}
else
{
char
letter
=
sc_ascii
[(
int
)
scancode
];
if
(
letter
>
65
&&
letter
<
90
)
{
letter
+=
32
*
!
uppercase
;
//Remove 32 from letter(make it lower case) if uppercase is false
if
(
letter
>
65
&&
letter
<
90
)
{
letter
+=
32
*
!
uppercase
;
//Remove 32 from letter(make it lower case) if uppercase is false
special
=
0
;
}
else
if
(
uppercase
)
{
if
(
scancode
<
0x10
)
{
else
if
(
uppercase
)
{
if
(
scancode
<
0x10
)
{
special
=
0
;
letter
=
sc_shift_below
[
scancode
];
}
else
if
(
scancode
>=
0x27
&&
scancode
<=
0x2B
)
{
}
else
if
(
scancode
>=
0x27
&&
scancode
<=
0x2B
)
{
special
=
0
;
letter
=
sc_shift_middle
[
scancode
-
0x27
];
}
else
if
(
scancode
>=
0x33
&&
scancode
<=
0x39
)
{
}
else
if
(
scancode
>=
0x33
&&
scancode
<=
0x39
)
{
special
=
0
;
letter
=
sc_shift_above
[
scancode
-
0x33
];
}
}
/* Remember that kprint only accepts char[] */
char
str
[
2
]
=
{
letter
,
'\0'
};
append
(
key_buffer
,
letter
);
print
(
str
);
}
}
if
(
special
)
{
keyboard_handler_special
(
scancode
);
}
else
{
keyboard_handler
(
letter
);
}
}
}
UNUSED
(
regs
);
}
...
...
This diff is collapsed.
Click to expand it.
drivers/keyboard.h
+
6
−
0
View file @
14527775
#ifndef keyboarddriver
#define keyboarddriver
#include
"../cpu/types.h"
void
init_keyboard
();
enum
SPECIAL
{
LCTRL
=
0x1D
,
RCTRL
=
0xE0
,
LSHIFT
=
0x2A
,
RSHIFT
=
0x36
,
LALT
=
0x11
,
RALT
=
0x38
,
LSUPER
,
RSUPER
,
BACKSPACE
=
0x0E
,
ENTER
=
0x1C
};
//Will grow over time
#endif
This diff is collapsed.
Click to expand it.
util/terminal.c
+
33
−
0
View file @
14527775
...
...
@@ -2,6 +2,7 @@
#include
"font.h"
#include
"../drivers/screen.h"
#include
"../libc/string.h"
#include
"../drivers/keyboard.h"
int
offset_x
=
0
;
int
offset_y
=
8
;
//Higher numbers really means lower on screen
...
...
@@ -67,6 +68,38 @@ void set_offset(int x, int y) {
offset_y
=
y
;
}
char
key_buffer
[
512
];
void
keyboard_handler
(
char
key
)
{
//Print character
char
printstr
[]
=
{
key
,
0
};
print
(
printstr
);
append
(
key_buffer
,
key
);
}
void
keyboard_handler_special
(
enum
SPECIAL
key
)
{
if
(
key
==
BACKSPACE
)
{
if
(
strlen
(
key_buffer
)
>
0
)
{
backspace
(
key_buffer
);
delete_last
();
}
}
else
if
(
key
==
ENTER
)
{
newline
();
if
(
!
parse_command
(
key_buffer
))
{
println
(
"Command not found."
);
}
key_buffer
[
0
]
=
'\0'
;
print
(
"> "
);
}
}
char
*
commands
[
255
];
//Should be plenty, at least for now.
void
(
*
cmd_handlers
[
255
])(
char
*
);
u8
cmd_index
=
0
;
...
...
This diff is collapsed.
Click to expand it.
util/terminal.h
+
3
−
0
View file @
14527775
...
...
@@ -3,6 +3,7 @@
#define terminal
#define char_height 12
#include
"../drivers/keyboard.h"
void
print
(
char
*
c
);
void
println
(
char
*
c
);
...
...
@@ -13,5 +14,7 @@ void set_background(int r, int g, int b);
void
set_offset
();
void
register_command
(
char
*
cmd
,
void
(
*
handler
)(
char
*
));
int
parse_command
(
char
*
linein
);
void
keyboard_handler
(
char
key
);
void
keyboard_handler_special
(
enum
SPECIAL
key
);
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment