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 loadscreenbuffer(ushort *bufferin);
|
||||
void savescreenbuffer(ushort *bufferin);
|
||||
void clearscreen(void);
|
||||
|
||||
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
|
||||
if (myproc() != 0x0)
|
||||
{
|
||||
consoleindex = myproc()->consoleIndex;
|
||||
consoleindex = currentconsoleindex; //myproc()->consoleIndex;
|
||||
}
|
||||
ushort* currentbuffer = consoles[consoleindex].screenbuffer;
|
||||
|
||||
if (consoleindex == currentconsoleindex)
|
||||
{
|
||||
// Cursor position: col + 80*row.
|
||||
outb(CRTPORT, 14);
|
||||
pos = inb(CRTPORT + 1) << 8;
|
||||
outb(CRTPORT, 15);
|
||||
pos |= inb(CRTPORT + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = consoles[consoleindex].pos;
|
||||
}
|
||||
|
||||
//ushort* currentbuffer = consoles[consoleindex].screenbuffer;
|
||||
|
||||
// Cursor position: col + 80*row.
|
||||
outb(CRTPORT, 14);
|
||||
pos = inb(CRTPORT + 1) << 8;
|
||||
outb(CRTPORT, 15);
|
||||
pos |= inb(CRTPORT + 1);
|
||||
|
||||
if (c == '\n') {
|
||||
pos += SCRWIDTH - pos % SCRWIDTH;
|
||||
}
|
||||
else if (c == BACKSPACE) {
|
||||
if (pos > (TITLEOFF)) {
|
||||
currentbuffer[pos] = 0; // Clear the character from the buffer
|
||||
//currentbuffer[pos] = 0; // Clear the character from the buffer
|
||||
--pos;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
@ -205,22 +200,17 @@ static void cgaputc(int c) {
|
||||
}
|
||||
|
||||
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;
|
||||
memset(currentbuffer + 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;
|
||||
memset(crt + pos, 0, sizeof(crt[0]) * (SCRHEIGHT * SCRWIDTH - pos));
|
||||
}
|
||||
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) {
|
||||
@ -411,6 +401,12 @@ void loadscreenbuffer(ushort *bufferin)
|
||||
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)
|
||||
{
|
||||
//cprintf("process id: %d", myproc()->consoleIndex);
|
||||
@ -424,7 +420,7 @@ void clearscreen(void)
|
||||
|
||||
//testfillbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||
clearconsole(consoles[currentconsoleindex].screenbuffer);
|
||||
loadscreenbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||
//loadscreenbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||
|
||||
consoles[currentconsoleindex].pos = pos;
|
||||
|
||||
@ -470,13 +466,24 @@ int newconsole(void)
|
||||
|
||||
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;
|
||||
input = &consoles[currentconsoleindex].keybuffer;
|
||||
//ioapicenable(IRQ_KBD, 0);
|
||||
release(&cons.lock);
|
||||
//release(&cons.lock);
|
||||
|
||||
loadscreenbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||
loadscreenbuffer(consoles[consoleindex].screenbuffer);
|
||||
|
||||
if (!consoles[currentconsoleindex].active)
|
||||
{
|
||||
@ -486,7 +493,7 @@ int switchtoconsole(int consoleindex)
|
||||
}
|
||||
else
|
||||
{
|
||||
int pos = consoles[currentconsoleindex].pos;
|
||||
pos = consoles[consoleindex].pos;
|
||||
|
||||
outb(CRTPORT, 14);
|
||||
outb(CRTPORT + 1, pos >> 8);
|
||||
|
Reference in New Issue
Block a user