Changed the console to write directly to the console then to the current buffer
This commit is contained in:
81
console.c
81
console.c
@ -42,6 +42,7 @@ static uint currentconsoleindex = 0;
|
|||||||
|
|
||||||
void clearconsole(ushort *bufferin);
|
void clearconsole(ushort *bufferin);
|
||||||
void loadscreenbuffer(ushort *bufferin);
|
void loadscreenbuffer(ushort *bufferin);
|
||||||
|
void savescreenbuffer(ushort *bufferin);
|
||||||
void clearscreen(void);
|
void clearscreen(void);
|
||||||
|
|
||||||
static void consputc(int);
|
static void consputc(int);
|
||||||
@ -170,34 +171,28 @@ static void cgaputc(int c) {
|
|||||||
// Check if a process has actually been created otherwise use the base console
|
// Check if a process has actually been created otherwise use the base console
|
||||||
if (myproc() != 0x0)
|
if (myproc() != 0x0)
|
||||||
{
|
{
|
||||||
consoleindex = myproc()->consoleIndex;
|
consoleindex = currentconsoleindex; //myproc()->consoleIndex;
|
||||||
}
|
}
|
||||||
ushort* currentbuffer = consoles[consoleindex].screenbuffer;
|
//ushort* currentbuffer = consoles[consoleindex].screenbuffer;
|
||||||
|
|
||||||
if (consoleindex == currentconsoleindex)
|
// Cursor position: col + 80*row.
|
||||||
{
|
outb(CRTPORT, 14);
|
||||||
// Cursor position: col + 80*row.
|
pos = inb(CRTPORT + 1) << 8;
|
||||||
outb(CRTPORT, 14);
|
outb(CRTPORT, 15);
|
||||||
pos = inb(CRTPORT + 1) << 8;
|
pos |= inb(CRTPORT + 1);
|
||||||
outb(CRTPORT, 15);
|
|
||||||
pos |= inb(CRTPORT + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pos = consoles[consoleindex].pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
pos += SCRWIDTH - pos % SCRWIDTH;
|
pos += SCRWIDTH - pos % SCRWIDTH;
|
||||||
}
|
}
|
||||||
else if (c == BACKSPACE) {
|
else if (c == BACKSPACE) {
|
||||||
if (pos > (TITLEOFF)) {
|
if (pos > (TITLEOFF)) {
|
||||||
currentbuffer[pos] = 0; // Clear the character from the buffer
|
//currentbuffer[pos] = 0; // Clear the character from the buffer
|
||||||
--pos;
|
--pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
currentbuffer[pos++] = (c & 0xff) | 0x0700; // black on white
|
//currentbuffer[pos++] = (c & 0xff) | 0x0700; // black on white
|
||||||
|
crt[pos++] = (c & 0xff) | 0x0700; // black on white
|
||||||
|
|
||||||
}
|
}
|
||||||
if (pos < TITLEOFF || pos > SCRHEIGHT * SCRWIDTH) {
|
if (pos < TITLEOFF || pos > SCRHEIGHT * SCRWIDTH) {
|
||||||
@ -205,22 +200,17 @@ static void cgaputc(int c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((pos / 80) >= 24) { // Scroll up.
|
if ((pos / 80) >= 24) { // Scroll up.
|
||||||
memmove(currentbuffer + TITLEOFF, currentbuffer + (SCRWIDTH + TITLEOFF), sizeof(crt[0]) * (SCRHEIGHT - 1) * SCRWIDTH);
|
memmove(crt + TITLEOFF, crt + (SCRWIDTH + TITLEOFF), sizeof(crt[0]) * (SCRHEIGHT - 1) * SCRWIDTH);
|
||||||
pos -= 80;
|
pos -= 80;
|
||||||
memset(currentbuffer + pos, 0, sizeof(crt[0]) * (SCRHEIGHT * SCRWIDTH - pos));
|
memset(crt + pos, 0, sizeof(crt[0]) * (SCRHEIGHT * SCRWIDTH - pos));
|
||||||
}
|
|
||||||
consoles[consoleindex].pos = pos;
|
|
||||||
|
|
||||||
if (consoleindex == currentconsoleindex)
|
|
||||||
{
|
|
||||||
loadscreenbuffer(currentbuffer);
|
|
||||||
|
|
||||||
outb(CRTPORT, 14);
|
|
||||||
outb(CRTPORT + 1, pos >> 8);
|
|
||||||
outb(CRTPORT, 15);
|
|
||||||
outb(CRTPORT + 1, pos);
|
|
||||||
crt[pos] = ' ' | 0x0700;
|
|
||||||
}
|
}
|
||||||
|
consoles[consoleindex].pos = pos;
|
||||||
|
|
||||||
|
outb(CRTPORT, 14);
|
||||||
|
outb(CRTPORT + 1, pos >> 8);
|
||||||
|
outb(CRTPORT, 15);
|
||||||
|
outb(CRTPORT + 1, pos);
|
||||||
|
crt[pos] = ' ' | 0x0700;
|
||||||
}
|
}
|
||||||
|
|
||||||
void consputc(int c) {
|
void consputc(int c) {
|
||||||
@ -411,6 +401,12 @@ void loadscreenbuffer(ushort *bufferin)
|
|||||||
memmove(crt, bufferin, sizeof(bufferin[0]) * SCRHEIGHT * SCRWIDTH);
|
memmove(crt, bufferin, sizeof(bufferin[0]) * SCRHEIGHT * SCRWIDTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void savescreenbuffer(ushort *bufferin)
|
||||||
|
{
|
||||||
|
// Copy the memory from the console buffer to the crt buffer
|
||||||
|
memmove(bufferin, crt, sizeof(crt[0]) * SCRHEIGHT * SCRWIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
void clearscreen(void)
|
void clearscreen(void)
|
||||||
{
|
{
|
||||||
//cprintf("process id: %d", myproc()->consoleIndex);
|
//cprintf("process id: %d", myproc()->consoleIndex);
|
||||||
@ -424,7 +420,7 @@ void clearscreen(void)
|
|||||||
|
|
||||||
//testfillbuffer(consoles[currentconsoleindex].screenbuffer);
|
//testfillbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||||
clearconsole(consoles[currentconsoleindex].screenbuffer);
|
clearconsole(consoles[currentconsoleindex].screenbuffer);
|
||||||
loadscreenbuffer(consoles[currentconsoleindex].screenbuffer);
|
//loadscreenbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||||
|
|
||||||
consoles[currentconsoleindex].pos = pos;
|
consoles[currentconsoleindex].pos = pos;
|
||||||
|
|
||||||
@ -470,13 +466,24 @@ int newconsole(void)
|
|||||||
|
|
||||||
int switchtoconsole(int consoleindex)
|
int switchtoconsole(int consoleindex)
|
||||||
{
|
{
|
||||||
acquire(&cons.lock);
|
int pos;
|
||||||
|
|
||||||
|
outb(CRTPORT, 14);
|
||||||
|
pos = inb(CRTPORT + 1) << 8;
|
||||||
|
outb(CRTPORT, 15);
|
||||||
|
pos |= inb(CRTPORT + 1);
|
||||||
|
|
||||||
|
consoles[currentconsoleindex].pos = pos;
|
||||||
|
|
||||||
|
savescreenbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||||
|
|
||||||
|
//acquire(&cons.lock);
|
||||||
currentconsoleindex = consoleindex;
|
currentconsoleindex = consoleindex;
|
||||||
input = &consoles[currentconsoleindex].keybuffer;
|
input = &consoles[currentconsoleindex].keybuffer;
|
||||||
//ioapicenable(IRQ_KBD, 0);
|
//ioapicenable(IRQ_KBD, 0);
|
||||||
release(&cons.lock);
|
//release(&cons.lock);
|
||||||
|
|
||||||
loadscreenbuffer(consoles[currentconsoleindex].screenbuffer);
|
loadscreenbuffer(consoles[consoleindex].screenbuffer);
|
||||||
|
|
||||||
if (!consoles[currentconsoleindex].active)
|
if (!consoles[currentconsoleindex].active)
|
||||||
{
|
{
|
||||||
@ -486,7 +493,7 @@ int switchtoconsole(int consoleindex)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int pos = consoles[currentconsoleindex].pos;
|
pos = consoles[consoleindex].pos;
|
||||||
|
|
||||||
outb(CRTPORT, 14);
|
outb(CRTPORT, 14);
|
||||||
outb(CRTPORT + 1, pos >> 8);
|
outb(CRTPORT + 1, pos >> 8);
|
||||||
|
Reference in New Issue
Block a user