From 05c1a1fe281b82cdeb8642babdc968002cb92ad8 Mon Sep 17 00:00:00 2001 From: iDunnoDev Date: Fri, 9 Dec 2022 11:12:46 +0000 Subject: [PATCH] Changed the console to write directly to the console then to the current buffer --- console.c | 81 ++++++++++++++++++++++++++++++------------------------- fs.img | 3 --- xv6.img | 3 --- 3 files changed, 44 insertions(+), 43 deletions(-) delete mode 100644 fs.img delete mode 100644 xv6.img diff --git a/console.c b/console.c index 2308029..5e908bc 100644 --- a/console.c +++ b/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); diff --git a/fs.img b/fs.img deleted file mode 100644 index ab94c57..0000000 --- a/fs.img +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:5d0c3858c578bd9d627937e9b5fff66f725fb40f4a85411a7b20a6ce82417182 -size 512000 diff --git a/xv6.img b/xv6.img deleted file mode 100644 index a6a5e93..0000000 --- a/xv6.img +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:18ee787bf99126dedbb0a9500ddf41d80a5ab1004c67d14dddc0a84c460cb340 -size 5120000