Import backup from 2005-06-02

This commit is contained in:
josh committed 2017-07-25 22:23:50 -04:00
1 parent b0132c866e
commit 692cf2fc08
22 files changed
+512 -244

No files matched your search

+5 -52
View File
@@ -1,28 +1,21 @@
// keyboard.c
// Author: Josh Holtrop
// Created: 04/17/03
// Modified: 08/16/04
// Modified: 05/19/05
#include "hos_defines.h"
#include "char/keyboard.h"
#include "sys/io.h" // inportb, outportb
#include "functions.h"
#include "lang/conv.h" // asciiSwitchCase()
#include "display/kout.h"
#include "display/kout.h" // kprintf()
#include "display/display.h" // display_activate()
#define KBD_BUFFER_LENGTH 64
u8_t kbdFlags = 0; // holds current keyboard flags - caps/num/scroll/shift/ctrl/alt
u8_t lastWasE0 = 0; // was the last byte 0x0E ?
u32_t kbdBuffer[KBD_BUFFER_LENGTH]; // a buffer for all keypresses
int kbdBufferStart = 0; // position of next key in buffer
int kbdBufferLen = 0; // number of keys left in the buffer
u8_t rawIgnore = 0; // how many signals to blatantly ignore
u8_t ackReason = 0; // used to record the reason why we would get an acknowledge byte (0xFA)
//these arrays convert a keyboard scan code to an ASCII character value
const u8_t SCAN2ASCII[129] = // for normal keys
"\000\0331234567890-=\010\011" // null,esc,1234567890-=,bksp,tab
@@ -83,7 +76,6 @@ void isr_keyboard()
return;
}
switch (kbdScan) // handle control keys
{
case KBD_SCAN_LSHIFT:
@@ -111,6 +103,7 @@ void isr_keyboard()
case KBD_SCAN_ALT + KBD_SCAN_RELEASED:
kbdFlags &= (KBDF_ALT ^ 0xFF);
break;
case KBD_SCAN_CAPS+KBD_SCAN_RELEASED:
kbdFlags ^= KBDF_CAPS;
kbd_resetLEDs(); // update LEDs
@@ -142,48 +135,9 @@ void isr_keyboard()
}
if (kbdScan & KBD_SCAN_RELEASED)
kbdAscii = 0;
if (kbdBufferLen < KBD_BUFFER_LENGTH) //no key slots available
kbdBuffer[(kbdBufferStart+kbdBufferLen++)%KBD_BUFFER_LENGTH] = (u32_t) ((kbdFlags << 16) | (kbdScan << 8) | kbdAscii);
if (kbdAscii)
kprintf("%c", kbdAscii);
// if (kbdFlags & KBDF_ALT)
// {
if (kbdScan >= 0x3B && kbdScan <= 0x44)
display_activate(kbdScan - 0x3B);
if (kbdScan >= 0x57 && kbdScan <= 0x58)
display_activate(kbdScan - 0x4D);
// }
}
//Gets a key from the buffer, returns 0 if no keys available, returns immediately
u32_t kbdGetKey()
{
if (kbdBufferLen == 0) // buffer empty
return 0;
u32_t retVal = kbdBuffer[kbdBufferStart];
kbdBufferStart++;
kbdBufferLen--;
if (kbdBufferStart >= KBD_BUFFER_LENGTH)
kbdBufferStart = 0;
return retVal;
}
//Gets a key from the buffer, if no keys available, waits for one to be entered
u32_t kbdWaitKey()
{
for (;;)
{
if (kbdBufferLen != 0) // buffer empty
break;
}
u32_t retVal = kbdBuffer[kbdBufferStart];
kbdBufferStart++;
kbdBufferLen--;
if (kbdBufferStart >= KBD_BUFFER_LENGTH)
kbdBufferStart = 0;
return retVal;
// send a key event to the display subsystem
display_key_event((kbdFlags << 16) | (kbdScan << 8) | kbdAscii);
}
//Resets the keyboard LEDs to reflect the current state of the num lock, caps lock, and scroll lock bits
@@ -195,4 +149,3 @@ void kbd_resetLEDs()
+18 -17
View File
@@ -1,35 +1,36 @@
// keyboard.h
// Author: Josh Holtrop
// Created: 04/17/03
// Modified: 08/20/04
// Modified: 05/19/05
#include "hos_defines.h"
#ifndef __HOS_KEYBOARD__
#define __HOS_KEYBOARD__ __HOS_KEYBOARD__
#define KBDF_SCROLL 0x01
#define KBDF_NUM 0x02
#define KBDF_CAPS 0x04
#define KBDF_SHIFT 0x10
#define KBDF_CTRL 0x20
#define KBDF_ALT 0x40
#define KBDF_SCROLL 0x01
#define KBDF_NUM 0x02
#define KBDF_CAPS 0x04
#define KBDF_SHIFT 0x10
#define KBDF_CTRL 0x20
#define KBDF_ALT 0x40
#define KBD_SCAN_RELEASED 0x80
#define KBD_SCAN_RELEASED 0x80
#define KBD_SCAN_CTRL 29
#define KBD_SCAN_LSHIFT 42
#define KBD_SCAN_RSHIFT 54
#define KBD_SCAN_ALT 56
#define KBD_SCAN_SCROLL 70
#define KBD_SCAN_CAPS 58
#define KBD_SCAN_NUM 69
#define KBD_SCAN_CTRL 29
#define KBD_SCAN_LSHIFT 42
#define KBD_SCAN_RSHIFT 54
#define KBD_SCAN_ALT 56
#define KBD_SCAN_SCROLL 70
#define KBD_SCAN_CAPS 58
#define KBD_SCAN_NUM 69
#define KBD_ASCII(x) ((x) & 0xFF)
#define KBD_SCAN(x) (((x) >> 8) & 0xFF)
#define KBD_FLAGS(x) (((x) >> 16) &0xFF)
void isr_keyboard();
void kbd_resetLEDs();
u32_t kbdGetKey();
u32_t kbdWaitKey();
#endif
+30 -12
View File
@@ -18,7 +18,6 @@ extern "C"
#include "char/vconsole.h"
VConsole *vconsoles[VCONSOLE_MAX]; // pointer to virtual console structs
extern int display_activeConsole; // display subsystem active virtual console number
char ansi2vgaAttr[8] = {0, 4, 2, 6, 1, 5, 3, 7};
void vconsole_setup(int width, int height)
@@ -27,6 +26,22 @@ void vconsole_setup(int width, int height)
vconsoles[i] = new VConsole(width, height);
}
int vconsole_activate(u32_t id)
{
if (id >= VCONSOLE_MAX)
return -1;
vconsoles[id]->activate();
return 0;
}
int vconsole_deactivate(u32_t id)
{
if (id >= VCONSOLE_MAX)
return -1;
vconsoles[id]->deactivate();
return 0;
}
VConsoleDriver::~VConsoleDriver()
{
for (int i = 0; i < VCONSOLE_MAX; i++)
@@ -46,6 +61,7 @@ int VConsoleDriver::char_write(minor_t minor, int c)
VConsole::VConsole(int width, int height)
{
myBuffer = new u16_t[width * height];
myBuffer2 = NULL;
myWidth = width;
myHeight = height;
myAttribute = myForeground = 0x07;
@@ -63,12 +79,23 @@ VConsole::~VConsole()
void VConsole::activate()
{
if (myActive) // don't activate if already active
return;
myActive = 1;
myBuffer2 = myBuffer;
myBuffer = (u16_t *)CONSOLE_MEMORY;
memcpyd(myBuffer, myBuffer2, (myWidth * myHeight) >> 1);
writeCursorPosition(myCursorPosition);
}
void VConsole::deactivate()
{
if (!myActive) // don't deactivate non-active console
return;
myActive = 0;
myBuffer = myBuffer2;
myBuffer2 = NULL;
memcpyd(myBuffer, (u16_t *)CONSOLE_MEMORY, (myWidth * myHeight) >> 1);
}
int VConsole::char_write(int c)
@@ -110,12 +137,10 @@ int VConsole::char_write(int c)
break;
case 'J': // clear screen, home cursor
memsetw(myBuffer, 0x0720, myWidth * myHeight);
// vconsole_draw(id);
update_cursor_coord(0, 0);
break;
case 'K': // erase line from cursor position (including char. under cursor) to end of line
memsetw(myBuffer + myCursorPosition, 0x0720, myWidth - cursorX);
// vconsole_draw(id);
break;
case 's': // push cursor position on an internal stack
if (myCursorStackPosition < 16)
@@ -202,8 +227,6 @@ void VConsole::put_char(int c)
break;
default:
myBuffer[myCursorPosition] = c | (myAttribute << 8);
// if (myActive)
// display_console_put_char(c | (myAttribute << 8), myCursorPosition);
update_cursor(myCursorPosition + 1);
}
}
@@ -237,14 +260,9 @@ void VConsole::update_cursor(u16_t position)
myCursorPosition -= myWidth;
memcpyw(myBuffer, myBuffer + myWidth, myWidth * (myHeight - 1));
memsetw(myBuffer + (myWidth * (myHeight - 1)), 0x0720, myWidth);
// if (myActive)
// {
// vconsole_draw(id);
// return;
// }
}
// if (myActive)
// display_console_update_cursor(id, position);
if (myActive)
writeCursorPosition(position);
}
void VConsole::update_attribute()
+5 -1
View File
@@ -6,7 +6,7 @@
#ifndef __HOS_VCONSOLE__
#define __HOS_VCONSOLE__ __HOS_VCONSOLE__
#define VCONSOLE_MAX 7
#define VCONSOLE_MAX 12
#ifdef _HOS_CPP_
extern "C" {
@@ -15,6 +15,9 @@ extern "C" {
#include "hos_defines.h"
void vconsole_setup(int width, int height);
int vconsole_activate(u32_t id);
int vconsole_deactivate(u32_t id);
#ifdef _HOS_CPP_
}
@@ -32,6 +35,7 @@ class VConsole
{
protected:
u16_t *myBuffer;
u16_t *myBuffer2;
u16_t myWidth;
u16_t myHeight;
u16_t myCursorPosition;