Changed console to write to both the buffer and the screen if currently active

This commit is contained in:
iDunnoDev
2022-12-12 16:40:38 +00:00
committed by iDunnoDev
parent 05c1a1fe28
commit 5b21654261
4 changed files with 107 additions and 65 deletions

View File

@ -223,8 +223,8 @@ QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \ then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi) else echo "-s -p $(GDBPORT)"; fi)
ifndef CPUS ifndef CPUS
#CPUS := 2 CPUS := 2
CPUS := 1 #CPUS := 1
endif endif
QEMUOPTS = -drive file=fs.img,index=1,media=disk,format=raw -drive file=xv6.img,index=0,media=disk,format=raw -smp $(CPUS) -m 512 $(QEMUEXTRA) QEMUOPTS = -drive file=fs.img,index=1,media=disk,format=raw -drive file=xv6.img,index=0,media=disk,format=raw -smp $(CPUS) -m 512 $(QEMUEXTRA)

160
console.c
View File

@ -29,6 +29,8 @@ struct kbdbuffer inputBuffer;
struct kbdbuffer * input = 0; struct kbdbuffer * input = 0;
struct vconsole { struct vconsole {
struct spinlock lock;
struct proc* processowner;
ushort screenbuffer[SCRWIDTH * SCRHEIGHT]; ushort screenbuffer[SCRWIDTH * SCRHEIGHT];
struct kbdbuffer keybuffer; struct kbdbuffer keybuffer;
int pos; int pos;
@ -36,6 +38,7 @@ struct vconsole {
}; };
struct vconsole consoles[MAXVCONSOLES]; struct vconsole consoles[MAXVCONSOLES];
struct vconsole* currentconsole = 0;
static uint currentconsoleindex = 0; static uint currentconsoleindex = 0;
#define C(x) ((x) - '@') // Control-x #define C(x) ((x) - '@') // Control-x
@ -171,46 +174,66 @@ 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 = currentconsoleindex; //myproc()->consoleIndex; consoleindex = myproc()->consoleIndex;
} }
//ushort* currentbuffer = consoles[consoleindex].screenbuffer; ushort* currentbuffer = consoles[consoleindex].screenbuffer;
// Cursor position: col + 80*row. if (consoleindex == currentconsoleindex)
outb(CRTPORT, 14); {
pos = inb(CRTPORT + 1) << 8; // Cursor position: col + 80*row.
outb(CRTPORT, 15); outb(CRTPORT, 14);
pos |= inb(CRTPORT + 1); pos = inb(CRTPORT + 1) << 8;
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 //int posp = pos;
crt[pos++] = (c & 0xff) | 0x0700; // black on white if (consoleindex == currentconsoleindex)
{
crt[pos] = (c & 0xff) | 0x0700; // black on white
}
currentbuffer[pos] = (c & 0xff) | 0x0700; // black on white
pos++;
} }
if (pos < TITLEOFF || pos > SCRHEIGHT * SCRWIDTH) { if (pos < TITLEOFF || pos > SCRHEIGHT * SCRWIDTH) {
panic("pos under/overflow"); panic("pos under/overflow");
} }
if ((pos / 80) >= 24) { // Scroll up. if ((pos / 80) >= 24) { // Scroll up.
memmove(crt + TITLEOFF, crt + (SCRWIDTH + TITLEOFF), sizeof(crt[0]) * (SCRHEIGHT - 1) * SCRWIDTH); memmove(currentbuffer + TITLEOFF, currentbuffer + (SCRWIDTH + TITLEOFF), sizeof(crt[0]) * (SCRHEIGHT - 1) * SCRWIDTH);
pos -= 80; pos -= 80;
memset(crt + pos, 0, sizeof(crt[0]) * (SCRHEIGHT * SCRWIDTH - pos)); memset(currentbuffer + pos, 0, sizeof(crt[0]) * (SCRHEIGHT * SCRWIDTH - pos));
if (consoleindex == currentconsoleindex)
{
memmove(crt + TITLEOFF, crt + (SCRWIDTH + TITLEOFF), sizeof(crt[0]) * (SCRHEIGHT - 1) * SCRWIDTH);
memset(crt + pos, 0, sizeof(crt[0]) * (SCRHEIGHT * SCRWIDTH - pos));
}
}
consoles[consoleindex].pos = pos;
if (consoleindex == currentconsoleindex)
{
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) {
@ -250,8 +273,8 @@ int consoleget(void) {
void consoleintr(int (*getc)(void)) { void consoleintr(int (*getc)(void)) {
int c, doprocdump = 0, doconsoleswitch = 0, doconsolehome = 0; int c, doprocdump = 0, doconsoleswitch = 0, doconsolehome = 0;
acquire(&cons.lock); acquire(&cons.lock);
while ((c = getc()) >= 0) { while ((c = getc()) >= 0) {
switch (c) { switch (c) {
case C('P'): // Process listing. case C('P'): // Process listing.
@ -260,7 +283,7 @@ void consoleintr(int (*getc)(void)) {
break; break;
case C('U'): // Kill line. case C('U'): // Kill line.
while (input->e != input->w && while (input->e != input->w &&
input->buf[(input->e - 1) % INPUT_BUF] != '\n') { input->buf[(input->e - 1) % INPUT_BUF] != '\n') {
input->e--; input->e--;
consputc(BACKSPACE); consputc(BACKSPACE);
} }
@ -292,6 +315,7 @@ void consoleintr(int (*getc)(void)) {
} }
} }
release(&cons.lock); release(&cons.lock);
if (doprocdump) { if (doprocdump) {
procdump(); // now call procdump() wo. cons.lock held procdump(); // now call procdump() wo. cons.lock held
} }
@ -324,7 +348,7 @@ int consoleread(struct inode *ip, char *dst, int n) {
int c; int c;
iunlock(ip); iunlock(ip);
target = n; target = n;
acquire(&cons.lock); acquire(&cons.lock);
while (n > 0) { while (n > 0) {
while (input->r == input->w) { while (input->r == input->w) {
@ -392,7 +416,7 @@ void testfillbuffer(ushort *bufferin)
void clearconsole(ushort *bufferin) void clearconsole(ushort *bufferin)
{ {
// Flood the screen buffer with blank spaces // Flood the screen buffer with blank spaces
memset(bufferin, 0x0700, sizeof(bufferin[0]) * SCRHEIGHT * SCRWIDTH); memset(bufferin, 0, sizeof(bufferin[0]) * SCRHEIGHT * SCRWIDTH);
} }
void loadscreenbuffer(ushort *bufferin) void loadscreenbuffer(ushort *bufferin)
@ -411,32 +435,46 @@ void clearscreen(void)
{ {
//cprintf("process id: %d", myproc()->consoleIndex); //cprintf("process id: %d", myproc()->consoleIndex);
//return; //return;
//cprintf("size of buffer item: %d\n", sizeof(consoles[currentconsoleindex].screenbuffer[0]) * (SCRHEIGHT * SCRWIDTH)); //cprintf("size of buffer item: %d\n", sizeof(consoles[currentconsoleindex].screenbuffer[0]) * (SCRHEIGHT * SCRWIDTH));
//cprintf("size of crt item: %d\n", sizeof(crt[0]) * (SCRHEIGHT * SCRWIDTH)); //cprintf("size of crt item: %d\n", sizeof(crt[0]) * (SCRHEIGHT * SCRWIDTH));
//return; //return;
int pos = TITLEOFF; int consoleindex = 0;
// Check if a process has actually been created otherwise use the base console
//testfillbuffer(consoles[currentconsoleindex].screenbuffer); if (myproc() != 0x0)
clearconsole(consoles[currentconsoleindex].screenbuffer); {
//loadscreenbuffer(consoles[currentconsoleindex].screenbuffer); consoleindex = myproc()->consoleIndex;
}
if (consoleindex == currentconsoleindex)
{
acquire(&cons.lock);
int pos = TITLEOFF;
//testfillbuffer(consoles[currentconsoleindex].screenbuffer);
clearconsole(crt);
//loadscreenbuffer(consoles[currentconsoleindex].screenbuffer);
release(&cons.lock);
consoles[currentconsoleindex].pos = pos; currentconsole->pos = pos;
outb(CRTPORT, 14); outb(CRTPORT, 14);
outb(CRTPORT + 1, pos >> 8); outb(CRTPORT + 1, pos >> 8);
outb(CRTPORT, 15); outb(CRTPORT, 15);
outb(CRTPORT + 1, pos); outb(CRTPORT + 1, pos);
}
else
{
}
} }
void consoleinit(void) { void consoleinit(void) {
initlock(&cons.lock, "console"); initlock(&cons.lock, "console");
consoles[currentconsoleindex].active = 1; // Initialise pointer to point to our console input buffer
currentconsole = &consoles[currentconsoleindex];
// Initialise pointer to point to our console input buffer currentconsole->active = 1;
input = &consoles[currentconsoleindex].keybuffer; initlock(&currentconsole->lock, "vconsole0");
input = &currentconsole->keybuffer;
devsw[CONSOLE].write = consolewrite; devsw[CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread; devsw[CONSOLE].read = consoleread;
@ -468,32 +506,35 @@ int switchtoconsole(int consoleindex)
{ {
int pos; int pos;
outb(CRTPORT, 14); /*outb(CRTPORT, 14);
pos = inb(CRTPORT + 1) << 8; pos = inb(CRTPORT + 1) << 8;
outb(CRTPORT, 15); outb(CRTPORT, 15);
pos |= inb(CRTPORT + 1); pos |= inb(CRTPORT + 1);*/
consoles[currentconsoleindex].pos = pos; //consoles[currentconsoleindex].pos = pos;
savescreenbuffer(consoles[currentconsoleindex].screenbuffer); //savescreenbuffer(consoles[currentconsoleindex].screenbuffer);
//acquire(&cons.lock); //acquire(&currentconsole->lock);
//sleep(&(currentconsole), &currentconsole->lock);
acquire(&cons.lock);
currentconsoleindex = consoleindex; currentconsoleindex = consoleindex;
input = &consoles[currentconsoleindex].keybuffer; currentconsole = &consoles[currentconsoleindex];
input = &currentconsole->keybuffer;
//ioapicenable(IRQ_KBD, 0); //ioapicenable(IRQ_KBD, 0);
//release(&cons.lock);
loadscreenbuffer(currentconsole->screenbuffer);
release(&cons.lock);
loadscreenbuffer(consoles[consoleindex].screenbuffer); if (!currentconsole->active)
if (!consoles[currentconsoleindex].active)
{ {
clearscreen(); clearscreen();
cprintf("Welcome to Console: %d\n", currentconsoleindex); cprintf("Welcome to Console: %d\n", currentconsoleindex);
consoles[currentconsoleindex].active = 1; currentconsole->active = 1;
} }
else else
{ {
pos = consoles[consoleindex].pos; pos = currentconsole->pos;
outb(CRTPORT, 14); outb(CRTPORT, 14);
outb(CRTPORT + 1, pos >> 8); outb(CRTPORT + 1, pos >> 8);
@ -501,13 +542,14 @@ int switchtoconsole(int consoleindex)
outb(CRTPORT + 1, pos); outb(CRTPORT + 1, pos);
} }
//wakeup(myproc()->chan);
return 0; return 0;
} }
int closeconsole(int consoleindex) int closeconsole(int consoleindex)
{ {
clearconsole(consoles[currentconsoleindex].screenbuffer); clearconsole(currentconsole->screenbuffer);
consoles[currentconsoleindex].active = 0; currentconsole->active = 0;
switchtoconsole(0); switchtoconsole(0);
return 0; return 0;
} }

View File

@ -11,6 +11,7 @@
#define LOGSIZE (MAXOPBLOCKS*3) // max data blocks in on-disk log #define LOGSIZE (MAXOPBLOCKS*3) // max data blocks in on-disk log
#define NBUF (MAXOPBLOCKS*3) // size of disk block cache #define NBUF (MAXOPBLOCKS*3) // size of disk block cache
#define FSSIZE 1000 // size of file system in blocks #define FSSIZE 1000 // size of file system in blocks
#define MAXVCONSOLES 10 // Max number of consoles that can be open #define MAXVCONSOLES 10 // Max number of consoles that can be open
#define SCRWIDTH 80 // Numbers of characters across the screen #define SCRWIDTH 80 // Numbers of characters across the screen
#define SCRHEIGHT 25 // Number of lines down the screen #define SCRHEIGHT 25 // Number of lines down the screen

View File

@ -131,10 +131,9 @@ int sys_screen(void)
int result = 0; int result = 0;
int consoleindex = -1; int consoleindex = -1;
if ((consoleindex = newconsole()) != 0) if ((consoleindex = newconsole()) != 0)
{ {
curproc->consoleIndex = consoleindex; curproc->consoleIndex = consoleindex;
switchtoconsole(consoleindex); switchtoconsole(consoleindex);
wakeup(myproc()->chan);
result = 1; result = 1;
} }
return result; return result;