Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
7b1022a
A solid attempt
Real-Septicake Sep 12, 2024
452d5ce
Fixed it
Real-Septicake Sep 12, 2024
ecc0983
Moved things
Real-Septicake Sep 13, 2024
44db8f4
Print raw disk space
Real-Septicake Sep 13, 2024
c62fafd
Add backspace functionality
Real-Septicake Sep 18, 2024
8be1f33
Removed disk files from keyboard branch
Real-Septicake Sep 19, 2024
6d46a1c
Arrow key functionality
Real-Septicake Sep 19, 2024
1efa029
Format and rename `delete` to `deletePrevChar`
Real-Septicake Sep 19, 2024
271eb5d
remove disk.o from makefile
Real-Septicake Sep 19, 2024
b083109
Added safeguards to cursor movement functions
Real-Septicake Sep 19, 2024
076ba3e
Add `delete` key functionality
Real-Septicake Sep 19, 2024
582c5f8
Background now gotten directly from deleted character
Real-Septicake Sep 19, 2024
4717d32
Start work on highlighting with cursor
Real-Septicake Sep 20, 2024
005f805
Continue working on highlighting
Real-Septicake Sep 20, 2024
861ebd0
Cursor movement after highlighting done, still need to work on deletion
Real-Septicake Sep 20, 2024
43a9b3f
Format
Real-Septicake Sep 21, 2024
cbfa9e5
Fixed moving cursor backwards while continuing to highlight
Real-Septicake Sep 25, 2024
d1b08ac
Add Key_up and Key_down functionality for highlighting
Real-Septicake Oct 9, 2024
0123424
Format
Real-Septicake Oct 9, 2024
519681a
Add support for deletion while highlighting
Real-Septicake Oct 9, 2024
8d0f74b
Delete highlighted characters when beginning to type with highlighted…
Real-Septicake Oct 9, 2024
a1c34bf
Initial code/changes for testing the keyboard/editing functionality.
Alex105178 Oct 23, 2024
7efa739
Added basic test framework for keyboard.
Alex105178 Oct 23, 2024
7962b2c
Organize functions a bit more
Real-Septicake Oct 23, 2024
a2bb9b9
Merge branch 'keyboard' of https://github.com/Real-Septicake/mOS_disk…
Real-Septicake Oct 23, 2024
ef7fb26
Add highlight deletion functions to header file
Real-Septicake Oct 24, 2024
65353b7
Add further testing
Real-Septicake Oct 24, 2024
71705df
Add information on what tests timed out, and added a space after the …
Real-Septicake Oct 24, 2024
8b1c041
Add check command for cursor position relative to beginning of vga me…
Real-Septicake Oct 24, 2024
220e308
Add more position checks to current test command sequence
Real-Septicake Oct 24, 2024
f145797
Documentation and formatting
Real-Septicake Oct 24, 2024
57f9511
Add logging for the starting and ending of tests
Real-Septicake Oct 24, 2024
c4cfbd3
remove `init_pos` from the keyboard test
Real-Septicake Oct 24, 2024
4ac7b90
Correct lack of mutex usage for getting number of active instances
Real-Septicake Oct 25, 2024
8e3b16e
Fix lack of increment in %i and %s in stdio.c
Real-Septicake Oct 30, 2024
3e2a07c
Add way to print values for debugging in ASSERT_M
Real-Septicake Oct 30, 2024
26048c5
Fix edge case of input of %i being 0
Real-Septicake Oct 30, 2024
b6618ee
test_keyboard now uses new assert macro, chkPosCMD now takes line and…
Real-Septicake Oct 30, 2024
65ffe5c
Use the already present `len` variable instead of creating `bufSize`
Real-Septicake Oct 31, 2024
eeee2af
Add utilities to prevent a change in the size of the VGA from complet…
Real-Septicake Oct 31, 2024
4b28577
Documentation
Real-Septicake Oct 31, 2024
7673409
Added macro that fails when reached, added logic to both assert and f…
Real-Septicake Oct 31, 2024
edabc13
Allow for execCMD to return a non-zero value to represent a fatal err…
Real-Septicake Oct 31, 2024
b27fc07
Formatting
Real-Septicake Oct 31, 2024
e7755fe
Add new lines to improve readability, removed unused file name parame…
Real-Septicake Oct 31, 2024
86473f4
Prevent key presses that do not produce characters from clearing the …
Real-Septicake Nov 1, 2024
5d11ede
Update how closing Qemu instances is handled
Real-Septicake Nov 1, 2024
fd31503
Formatting
Real-Septicake Nov 1, 2024
1c1296c
Remove unnecessary `undef`s
Real-Septicake Nov 1, 2024
873067d
add `test_helper.h` to include path
Real-Septicake Nov 1, 2024
4e2ea0a
Add tests to make sure that keypresses that do not produce characters…
Real-Septicake Nov 1, 2024
8a04762
Now using `sizeof(buff)` to get the size of the error text buffer
Real-Septicake Nov 2, 2024
da3fe97
Add termcolor for test output readability, color scheme is not finalized
Real-Septicake Nov 4, 2024
0e2681e
Implement several of the suggested changes, more to do but committing…
Real-Septicake Nov 4, 2024
f8fede8
Rename `cursor_struct` to `VGA_Cursor`
Real-Septicake Nov 4, 2024
238d957
Replace `extern` for usage of vga cursor with a getter
Real-Septicake Nov 4, 2024
c113f5a
Used a tab instead of spaces
Real-Septicake Nov 5, 2024
c9d465e
Correct empty line prevention in assertion macros
Real-Septicake Nov 5, 2024
d5e2414
Add expected number of characters written as a parameter, add 0 edge …
Real-Septicake Nov 5, 2024
23d6a1a
Formatting... again
Real-Septicake Nov 5, 2024
7b8de96
Consolidate both assert functions into one
Real-Septicake Nov 5, 2024
9707d95
Make `fmt` of snprintf and vsnprintf `const`
Real-Septicake Nov 5, 2024
745d6d9
Formatting once more
Real-Septicake Nov 5, 2024
6356409
make `p` const to get the compiler to shut up
Real-Septicake Nov 5, 2024
16ba516
Extracted a decent chunk of duplicate code, it is likely possible to …
Real-Septicake Nov 5, 2024
1a57af6
Update dependencies listed in README
Real-Septicake Nov 6, 2024
caeef14
`venv` not `virtualenv`
Real-Septicake Nov 12, 2024
f3f8848
Create file for handling special key cases
Real-Septicake Nov 19, 2024
4bc987e
Formatting once again
Real-Septicake Nov 19, 2024
77dbb85
Attempt at a quick fix for termcolor not respecting Windows' terminal…
Real-Septicake Dec 23, 2024
4f4125d
Use colorama instead of the inelegant selective disabling of color on…
Real-Septicake Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ OBJ_NAMES := src/os/main.o src/os/test.o os_entry.o src/lib/video/VGA_text.o \
src/lib/device/serial.o src/lib/device/ps2.o src/lib/device/keyboard.o \
src/lib/container/ring_buffer.o \
src/lib/stdlib/stdio.o src/lib/stdlib/stdlib.o src/lib/stdlib/string.o \
src/lib/pit/pit.o
src/lib/pit/pit.o src/lib/device/key_handlers.o


.PHONY: clean qemu test
Expand Down
116 changes: 116 additions & 0 deletions src/lib/device/key_handlers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "key_handlers.h"

#include "video/VGA_text.h"

void specialHandler(KeyPress out) {
if (!(out.modifiers & KEY_MOD_SHIFT)) {
switch (out.code) {
case Key_backspace:
if (getCursor()->highlight_offset) {
highlightDeletePrev(getCursor()->highlight_offset);
getCursor()->highlight_offset = 0;
} else
deletePrevChar();
break;
case Key_delete:
if (getCursor()->highlight_offset) {
highlightDeleteCurrent(getCursor()->highlight_offset);
getCursor()->highlight_offset = 0;
} else
deleteCurrentChar();
break;
case Key_left:
if (getCursor()->highlight_offset) {
cursorHighlightLeft(getCursor()->highlight_offset);
getCursor()->highlight_offset = 0;
} else
cursorLeft();
break;
case Key_down:
if (getCursor()->highlight_offset) {
cursorHighlightDown(getCursor()->highlight_offset);
getCursor()->highlight_offset = 0;
} else
cursorDown();
break;
case Key_up:
if (getCursor()->highlight_offset) {
cursorHighlightUp(getCursor()->highlight_offset);
getCursor()->highlight_offset = 0;
} else
cursorUp();
break;
case Key_right:
if (getCursor()->highlight_offset) {
cursorHighlightRight(getCursor()->highlight_offset);
getCursor()->highlight_offset = 0;
} else
cursorRight();
break;
default:
break;
}
} else {
if (((out.code == Key_up || out.code == Key_left) &&
cursorIsAtStart()) ||
((out.code == Key_down || out.code == Key_right) &&
cursorIsAtEnd()))
return;
if ((out.code == Key_up || out.code == Key_left ||
out.code == Key_down || out.code == Key_right) &&
!getCursor()->highlight_offset)
highlightCurrentChar();
switch (out.code) {
case Key_up:
for (int i = 0; i < VGA_WIDTH && !cursorIsAtStart(); i++) {
if (getCursor()->highlight_offset > 0) {
highlightCurrentChar();
cursorLeft();
} else {
cursorLeft();
highlightCurrentChar();
}
getCursor()->highlight_offset--;
}
break;
case Key_down:
for (int i = 0; i < VGA_WIDTH && !cursorIsAtEnd(); i++) {
if (getCursor()->highlight_offset < 0) {
highlightCurrentChar();
cursorRight();
} else {
cursorRight();
highlightCurrentChar();
}
getCursor()->highlight_offset++;
}
break;
case Key_left:
if (getCursor()->highlight_offset > 0) {
highlightCurrentChar();
cursorLeft();
} else {
cursorLeft();
highlightCurrentChar();
}
getCursor()->highlight_offset--;
break;
case Key_right:
if (getCursor()->highlight_offset < 0) {
highlightCurrentChar();
cursorRight();
} else {
cursorRight();
highlightCurrentChar();
}
getCursor()->highlight_offset++;
break;
default:
break;
}
if ((out.code == Key_up || out.code == Key_left ||
out.code == Key_down || out.code == Key_right) &&
!getCursor()->highlight_offset)
highlightCurrentChar();
}
}
8 changes: 8 additions & 0 deletions src/lib/device/key_handlers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef KEY_HANDLERS_H
#define KEY_HANDLERS_H

#include "keyboard.h"

void specialHandler(KeyPress out);

#endif
28 changes: 25 additions & 3 deletions src/lib/device/ps2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../../os/hard/idt.h"
#include "../../os/hard/port_io.h"
#include "container/ring_buffer.h"
#include "key_handlers.h"

#define PS2_BUF_SIZE 64
#define PS2_TIMEOUT 100000
Expand Down Expand Up @@ -72,6 +73,29 @@ const struct PS2Device *getPortType(int portnum) {
// temporary include for #7
#include "video/VGA_text.h"

void vgaEditor(struct PS2Buf_t out) {
switch (out.keyEvent.code) {
case Key_backspace:
case Key_delete:
case Key_left:
case Key_down:
case Key_up:
case Key_right:
specialHandler(out.keyEvent);
break;
default:
char buf[2] = " ";
buf[0] = keyPressToASCII(out.keyEvent);
if (buf[0] != 0) {
if (getCursor()->highlight_offset) {
highlightDeletePrev(getCursor()->highlight_offset);
getCursor()->highlight_offset = 0;
}
print(buf, white);
}
}
}

void ps2HandlerPort1(isr_registers_t *regs) {
uint8_t b = inb(PS2_DATA);

Expand All @@ -86,9 +110,7 @@ void ps2HandlerPort1(isr_registers_t *regs) {

// temporary to satisfy exactly what issue #7 says
if (out.keyEvent.code != Key_none && out.keyEvent.event == KeyPressed) {
char buf[2] = " ";
buf[0] = keyPressToASCII(out.keyEvent);
print(buf, white);
vgaEditor(out);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/device/ps2.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ struct PS2Buf_t {
int ps2Init();
const struct PS2Device *getPortType(int portnum);

void vgaEditor(struct PS2Buf_t out);

bool ps2Present(void);
bool ps2Port1Present(void);
bool ps2Port2Present(void);
Expand All @@ -84,4 +86,4 @@ struct PS2Buf_t popDev1(void);
struct PS2Buf_t peekDev2(void);
struct PS2Buf_t popDev2(void);

#endif
#endif
26 changes: 16 additions & 10 deletions src/lib/stdlib/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

#define MAX_SNPRINTF_STRING 100

int snprintf(char *restrict buffer, size_t bufsz, char *format, ...);
int vsnprintf(char *restrict buffer, size_t bufsz, char *format, va_list ap);
int snprintf(char *restrict buffer, size_t bufsz, const char *format, ...);
int vsnprintf(char *restrict buffer, size_t bufsz, const char *format,
va_list ap);

// Inspired by chapter 7.3 of The C Programming Language
int snprintf(char *restrict buffer, size_t bufsz, char *format, ...) {
int snprintf(char *restrict buffer, size_t bufsz, const char *format, ...) {
va_list ap;
int retval;
va_start(ap, format);
Expand All @@ -19,8 +20,9 @@ int snprintf(char *restrict buffer, size_t bufsz, char *format, ...) {
return retval;
}

int vsnprintf(char *restrict buffer, size_t bufsz, char *format, va_list ap) {
char *p;
int vsnprintf(char *restrict buffer, size_t bufsz, const char *format,
va_list ap) {
const char *p;

// valid types
unsigned char c; // printf("%c\n", 'c');
Expand Down Expand Up @@ -54,6 +56,7 @@ int vsnprintf(char *restrict buffer, size_t bufsz, char *format, va_list ap) {
if (len + n + 1 < bufsz) {
memcpy(buffer, s, len);
buffer += len;
n += len - 1;
} else {
return n;
}
Expand All @@ -75,19 +78,22 @@ int vsnprintf(char *restrict buffer, size_t bufsz, char *format, va_list ap) {
case 'i':
i = va_arg(ap, int);
int temp = i;
int bufSize = 0;
len = 0;
if (i < 0) {
bufSize++;
len++;
temp *= -1;
}
for (; temp >= 1; temp = temp / 10, bufSize++)
for (; temp >= 1; temp = temp / 10, len++)
;
if (i == 0)
len++;

// checks if there is space for the entire string
// plus the null-terminating byte
if (bufSize + n + 1 < bufsz) {
if (len + n + 1 < bufsz) {
itoa_s(i, buffer, MAX_SNPRINTF_STRING - n);
buffer += bufSize;
buffer += len;
n += len - 1;
} else {
return n;
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/stdlib/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdarg.h>
#include <stddef.h>

int snprintf(char *restrict buffer, size_t bufsz, char *format, ...);
int snprintf(char *restrict buffer, size_t bufsz, const char *format, ...);

int vsnprintf(char *restrict buffer, size_t bufsz, char *format, va_list ap);
int vsnprintf(char *restrict buffer, size_t bufsz, const char *format,
va_list ap);
Loading