Keyboard, scroll-up, escape, and stuff

This commit is contained in:
Julian Barathieu 2019-05-08 00:00:45 +02:00
parent 1eb1ff66ce
commit 56fff7b52d
6 changed files with 104 additions and 28 deletions

View File

@ -31,11 +31,9 @@
//----------------------------------------------------------------------------//
void PoShutdownQemu(void);
void PoShutdownVirtualbox(void);
void PoShutdownBochs(void);
noreturn void PoShutdownQemu(void);
noreturn void PoShutdownVirtualbox(void);
noreturn void PoShutdownBochs(void);
//----------------------------------------------------------------------------//

View File

@ -38,6 +38,8 @@ extern void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg);
// io/vga.c
extern error_t IoInitVGABuffer(void);
extern void IoScrollDown(void);
extern void IoScrollUp(void);
// io/keyb.c
extern void IoEnableKeyb(void);
@ -56,6 +58,9 @@ extern void divideByZero(void);
//
noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
{
uchar ch;
error_t rc;
KeDisableIRQs();
// Initialize the BootInfo_t structure
@ -76,24 +81,38 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
// Several inits
MmInitHeap();
//PsInitSched();
PsInitSched();
// Interrupts launching
IdtSetup();
KeEnableIRQs();
// Drivers enabling
// Start drivers
IoEnableRtc();
IoEnableKeyb();
IoGetRtcTimeChar();
IoPrintRtcTime();
// IoDoStarWars();
KernLog("Goodbye at %s\n", IoGetRtcTimeChar());
int i=0;
while(i++<50)KernLog("%d\n", i);
PoShutdownQemu();
// End this machine's suffering
// Main loop
while ((rc = bgetc(BStdIn, &ch)) == EOK) {
switch (ch) {
case 17: // DC1
IoScrollUp();
break;
case 18: // DC2
IoScrollDown();
break;
case 27: // ESC
BFlushBuf(BStdOut);
KeCrashSystem();
PoShutdownQemu();
break;
}
}
KernLog("End of input reached\n");
PoShutdownQemu();
}

View File

@ -30,8 +30,8 @@ char ScanCodes[100] = { 0 };
void KeybPrint(char code)
{
if (code) {
bputc(BStdIn, ScanCodes[(int)code]);
if (code && (isprint(ScanCodes[(int)code]) || ScanCodes[(int)code]=='\n')) {
bputc(BStdOut, ScanCodes[(int)code]);
//bprintf(BStdOut, "%x ", code);
BStdOut->flusher(BStdOut);
@ -40,6 +40,7 @@ void KeybPrint(char code)
void ScanCodesInit(void)
{
ScanCodes[0x01] = 27; // ESC
ScanCodes[0x02] = '1';
ScanCodes[0x03] = '2';
ScanCodes[0x04] = '3';
@ -94,6 +95,12 @@ void ScanCodesInit(void)
ScanCodes[0x1C] = '\n';
ScanCodes[0x39] = ' ';
// Numpad
ScanCodes[0x48] = 17; // DC1, will serve as Arrow Up
ScanCodes[0x50] = 18; // DC2, will serve as Arrow Down
ScanCodes[0x4B] = 19; // DC3, will serve as Arrow Left
ScanCodes[0x4D] = 20; // DC4, will serve as Arrow Right
}
void KeybHandler(ISRFrame_t *regs)

View File

@ -26,11 +26,6 @@
#include <kernel/boot.h>
#include <kernel/cursor.h>
//----------------------------------------------------------//
// Internal functions for VGA terminals //
// These DO NOT check input correctness //
//----------------------------------------------------------//
//
// VGA-related macros
//
@ -38,6 +33,8 @@
#define VGA_ComputeOffset(term, x, y) ((y) * (term)->width + (x))
#define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8)
static uint bscroll = 0;
//
// VGA Buffer Flusher
//
@ -49,7 +46,7 @@ error_t bvgaflusher(Buffer_t *buf)
uchar *currentLine = buf->wp - buf->lineLen - buf->lastLF;
uchar *bufStart = (uchar *)lmax((size_t)buf->buf,
(size_t)currentLine
- (buf->nLines - 2) * buf->lineLen);
- (buf->nLines - 2 + bscroll) * buf->lineLen);
uchar *ptr = bufStart;
@ -80,6 +77,23 @@ error_t bvgaflusher(Buffer_t *buf)
return EOK;
}
void IoScrollDown(void)
{
if (bscroll > 0)
bscroll--;
bvgaflusher(BStdOut);
}
void IoScrollUp(void)
{
// Keep the 8 below the 10 given to BOpenTermBufEx
if (bscroll < BtVideoInfo.framebufferHeight * 8)
bscroll++;
bvgaflusher(BStdOut);
}
//
// Initialize VGA buffer
//
@ -94,7 +108,7 @@ error_t IoInitVGABuffer(void)
bvgabufsrc, BS_WRONLY,
BtVideoInfo.framebufferWidth,
BtVideoInfo.framebufferHeight,
1, bvgaflusher);
10, bvgaflusher);
BEnableAutoScroll(BStdOut);

View File

@ -26,29 +26,35 @@
#include <kernel/iomisc.h>
#include <kernel/time.h>
void PoShutdownQemu(void)
noreturn void PoShutdownQemu(void)
{
KernLog("Shutdown QEMU at %s...\n", IoGetRtcTimeChar());
IoRtcWait(1000);
IoWriteWordOnPort(0x604, 0x2000);
__builtin_unreachable();
};
void PoShutdownVirtualbox(void)
noreturn void PoShutdownVirtualbox(void)
{
KernLog("Shutdown VirtualBox at %s...\n", IoGetRtcTimeChar());
IoRtcWait(1000);
IoWriteWordOnPort(0x4004, 0x3400);
__builtin_unreachable();
};
void PoShutdownBochs(void)
noreturn void PoShutdownBochs(void)
{
KernLog("Shutdown Bochs at %s...\n", IoGetRtcTimeChar());
IoRtcWait(1000);
IoWriteWordOnPort(0xB004, 0x2000);
__builtin_unreachable();
};

View File

@ -25,13 +25,18 @@
#include <extras/buf.h>
#include <extras/locks.h>
#ifdef _KALEID_KERNEL
#include <kernel/time.h>
#endif
error_t BGetFromBuf(Buffer_t *buf, uchar *ch)
{
error_t rc;
assert(buf && buf->initDone == INITOK);
if (!buf) return EINVAL;
if (buf->flags & BUF_TERM || buf->state != BS_RDWR && buf->state != BS_RDONLY) {
if (buf->flags & BF_TERM) return EBADF;
if (buf->state != BS_RDWR && buf->state != BS_RDONLY) {
return EBADF;
}
@ -41,13 +46,40 @@ error_t BGetFromBuf(Buffer_t *buf, uchar *ch)
return rc;
}
// XXX for now, at most 4096 characters can be inputed in BStdIn
error_t bgetc(Buffer_t *buf, uchar *ch)
{
error_t rc = EOK;
if (buf->flags & (BF_EOF|BF_ERR)) return EENDF;
if (
assert(!(buf->rp > buf->wp)); // Shouldn't be possible right now
if (buf->rp == buf->buf + buf->size) {
buf->flags |= BF_EOF;
return EENDF;
}
// Are there things to read at all?
if (buf->rp < buf->wp) {
*ch = *buf->rp++;
return EOK;
}
// We need to fill the buffer
else {
// We need a BFiller_t
// For now we wait until something is in there
// (so that BStdIn works; don't make anything else)
while (buf->rp >= buf->wp) {
#ifdef _KALEID_KERNEL
IoRtcWait(1);
#endif
}
*ch = *buf->rp++;
}
if (rc != EOK) {
// buf->flags |= BF_ERR;