tape-kernel 1.0
a modular modern independent kernel
Loading...
Searching...
No Matches
kb.c File Reference
#include "../lib/types.h"
#include "kb.h"
#include "io.h"
Include dependency graph for kb.c:

Go to the source code of this file.

Functions

uint8_t __scntasci (uint8_t inpt, uint8_t shifted)
 scntasci converts a keyboard scancode to an ascii character
uint8_t __gtchr (void)
 listens for a character outside of loops from ports
void __kbstate (uint8_t *shift, uint8_t *caps)
 kbstate exports the current keyboard modifier state
void __kbreset (void)
 kbreset resets the keyboard modifier states

Variables

static uint8_t shift_pressed = 0
static uint8_t caps_lock = 0

Function Documentation

◆ __gtchr()

uint8_t __gtchr ( void )

listens for a character outside of loops from ports

gtchr is a function that directly gets a key pressed from outside of rdln or loops

use of gtchr is done with

#include "../io/kb.h" //or just kb.h
uint8_t key = gtchr(); //also often times in a while(1) loop
if (key == 'e') { do something };
#define gtchr
Definition kb.h:6
unsigned char uint8_t
Definition types.h:28
See also
rdln()

Definition at line 109 of file kb.c.

References caps_lock, inb, scntasci, and shift_pressed.

◆ __kbreset()

void __kbreset ( void )

kbreset resets the keyboard modifier states

kbreset is a function that clears the shift and caps lock states back to their defaults (both off)

using kbreset is done with

#include "../io/kb.h" //or just kb.h
#define kbreset
Definition kb.h:8
See also
kbstate(), gtchr()

Definition at line 203 of file kb.c.

References caps_lock, and shift_pressed.

◆ __kbstate()

void __kbstate ( uint8_t * shift,
uint8_t * caps )

kbstate exports the current keyboard modifier state

kbstate is a function that writes the current shift and caps lock states into the provided pointers

Parameters
shift,apointer to store the shift state (1 = pressed)
caps,apointer to store the caps lock state (1 = enabled)

using kbstate is done with

#include "../io/kb.h" //or just kb.h
uint8_t shift, caps;
kbstate(&shift, &caps);
#define kbstate
Definition kb.h:9
See also
kbreset(), gtchr()

Definition at line 184 of file kb.c.

References caps_lock, and shift_pressed.

◆ __scntasci()

uint8_t __scntasci ( uint8_t inpt,
uint8_t shifted )

scntasci converts a keyboard scancode to an ascii character

scntasci is a function that translates ps/2 scancodes into ascii characters, applying shift and caps lock state for proper casing

Parameters
inpt,theraw scancode byte from the keyboard
shifted,whethershift is currently pressed (1) or not (0)

using scntasci is done with

#include "../io/kb.h" //or just kb.h
uint8_t scancode = inb(0x60);
uint8_t ascii = scntasci(scancode, 0); //convert without shift
#define inb
Definition io.h:6
#define scntasci
Definition kb.h:7
See also
gtchr(), kbstate()

Definition at line 26 of file kb.c.

References caps_lock.

Variable Documentation

◆ caps_lock

uint8_t caps_lock = 0
static

Definition at line 7 of file kb.c.

Referenced by __gtchr(), __kbreset(), __kbstate(), and __scntasci().

◆ shift_pressed

uint8_t shift_pressed = 0
static

Definition at line 6 of file kb.c.

Referenced by __gtchr(), __kbreset(), and __kbstate().