Changed console to write to both the buffer and the screen if currently active
This commit is contained in:
4
Makefile
4
Makefile
@ -223,8 +223,8 @@ QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
|
||||
then echo "-gdb tcp::$(GDBPORT)"; \
|
||||
else echo "-s -p $(GDBPORT)"; fi)
|
||||
ifndef CPUS
|
||||
#CPUS := 2
|
||||
CPUS := 1
|
||||
CPUS := 2
|
||||
#CPUS := 1
|
||||
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)
|
||||
|
||||
|
134
console.c
134
console.c
@ -29,6 +29,8 @@ struct kbdbuffer inputBuffer;
|
||||
struct kbdbuffer * input = 0;
|
||||
|
||||
struct vconsole {
|
||||
struct spinlock lock;
|
||||
struct proc* processowner;
|
||||
ushort screenbuffer[SCRWIDTH * SCRHEIGHT];
|
||||
struct kbdbuffer keybuffer;
|
||||
int pos;
|
||||
@ -36,6 +38,7 @@ struct vconsole {
|
||||
};
|
||||
|
||||
struct vconsole consoles[MAXVCONSOLES];
|
||||
struct vconsole* currentconsole = 0;
|
||||
static uint currentconsoleindex = 0;
|
||||
|
||||
#define C(x) ((x) - '@') // Control-x
|
||||
@ -171,28 +174,40 @@ static void cgaputc(int c) {
|
||||
// Check if a process has actually been created otherwise use the base console
|
||||
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.
|
||||
outb(CRTPORT, 14);
|
||||
pos = inb(CRTPORT + 1) << 8;
|
||||
outb(CRTPORT, 15);
|
||||
pos |= inb(CRTPORT + 1);
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
crt[pos++] = (c & 0xff) | 0x0700; // black on white
|
||||
//int posp = pos;
|
||||
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) {
|
||||
@ -200,17 +215,25 @@ static void cgaputc(int c) {
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
outb(CRTPORT, 14);
|
||||
outb(CRTPORT + 1, pos >> 8);
|
||||
outb(CRTPORT, 15);
|
||||
outb(CRTPORT + 1, pos);
|
||||
crt[pos] = ' ' | 0x0700;
|
||||
if (consoleindex == currentconsoleindex)
|
||||
{
|
||||
outb(CRTPORT, 14);
|
||||
outb(CRTPORT + 1, pos >> 8);
|
||||
outb(CRTPORT, 15);
|
||||
outb(CRTPORT + 1, pos);
|
||||
crt[pos] = ' ' | 0x0700;
|
||||
}
|
||||
}
|
||||
|
||||
void consputc(int c) {
|
||||
@ -260,7 +283,7 @@ void consoleintr(int (*getc)(void)) {
|
||||
break;
|
||||
case C('U'): // Kill line.
|
||||
while (input->e != input->w &&
|
||||
input->buf[(input->e - 1) % INPUT_BUF] != '\n') {
|
||||
input->buf[(input->e - 1) % INPUT_BUF] != '\n') {
|
||||
input->e--;
|
||||
consputc(BACKSPACE);
|
||||
}
|
||||
@ -292,6 +315,7 @@ void consoleintr(int (*getc)(void)) {
|
||||
}
|
||||
}
|
||||
release(&cons.lock);
|
||||
|
||||
if (doprocdump) {
|
||||
procdump(); // now call procdump() wo. cons.lock held
|
||||
}
|
||||
@ -392,7 +416,7 @@ void testfillbuffer(ushort *bufferin)
|
||||
void clearconsole(ushort *bufferin)
|
||||
{
|
||||
// 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)
|
||||
@ -411,32 +435,46 @@ void clearscreen(void)
|
||||
{
|
||||
//cprintf("process id: %d", myproc()->consoleIndex);
|
||||
//return;
|
||||
|
||||
//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));
|
||||
|
||||
//return;
|
||||
int pos = TITLEOFF;
|
||||
int consoleindex = 0;
|
||||
// Check if a process has actually been created otherwise use the base console
|
||||
if (myproc() != 0x0)
|
||||
{
|
||||
consoleindex = myproc()->consoleIndex;
|
||||
}
|
||||
if (consoleindex == currentconsoleindex)
|
||||
{
|
||||
acquire(&cons.lock);
|
||||
int pos = TITLEOFF;
|
||||
|
||||
//testfillbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||
clearconsole(consoles[currentconsoleindex].screenbuffer);
|
||||
//loadscreenbuffer(consoles[currentconsoleindex].screenbuffer);
|
||||
//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 + 1, pos >> 8);
|
||||
outb(CRTPORT, 15);
|
||||
outb(CRTPORT + 1, pos);
|
||||
outb(CRTPORT, 14);
|
||||
outb(CRTPORT + 1, pos >> 8);
|
||||
outb(CRTPORT, 15);
|
||||
outb(CRTPORT + 1, pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void consoleinit(void) {
|
||||
initlock(&cons.lock, "console");
|
||||
|
||||
consoles[currentconsoleindex].active = 1;
|
||||
|
||||
// Initialise pointer to point to our console input buffer
|
||||
input = &consoles[currentconsoleindex].keybuffer;
|
||||
currentconsole = &consoles[currentconsoleindex];
|
||||
currentconsole->active = 1;
|
||||
initlock(¤tconsole->lock, "vconsole0");
|
||||
input = ¤tconsole->keybuffer;
|
||||
|
||||
devsw[CONSOLE].write = consolewrite;
|
||||
devsw[CONSOLE].read = consoleread;
|
||||
@ -468,32 +506,35 @@ int switchtoconsole(int consoleindex)
|
||||
{
|
||||
int pos;
|
||||
|
||||
outb(CRTPORT, 14);
|
||||
/*outb(CRTPORT, 14);
|
||||
pos = inb(CRTPORT + 1) << 8;
|
||||
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(¤tconsole->lock);
|
||||
//sleep(&(currentconsole), ¤tconsole->lock);
|
||||
acquire(&cons.lock);
|
||||
currentconsoleindex = consoleindex;
|
||||
input = &consoles[currentconsoleindex].keybuffer;
|
||||
currentconsole = &consoles[currentconsoleindex];
|
||||
input = ¤tconsole->keybuffer;
|
||||
//ioapicenable(IRQ_KBD, 0);
|
||||
//release(&cons.lock);
|
||||
|
||||
loadscreenbuffer(consoles[consoleindex].screenbuffer);
|
||||
loadscreenbuffer(currentconsole->screenbuffer);
|
||||
release(&cons.lock);
|
||||
|
||||
if (!consoles[currentconsoleindex].active)
|
||||
if (!currentconsole->active)
|
||||
{
|
||||
clearscreen();
|
||||
cprintf("Welcome to Console: %d\n", currentconsoleindex);
|
||||
consoles[currentconsoleindex].active = 1;
|
||||
currentconsole->active = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = consoles[consoleindex].pos;
|
||||
pos = currentconsole->pos;
|
||||
|
||||
outb(CRTPORT, 14);
|
||||
outb(CRTPORT + 1, pos >> 8);
|
||||
@ -501,13 +542,14 @@ int switchtoconsole(int consoleindex)
|
||||
outb(CRTPORT + 1, pos);
|
||||
}
|
||||
|
||||
//wakeup(myproc()->chan);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int closeconsole(int consoleindex)
|
||||
{
|
||||
clearconsole(consoles[currentconsoleindex].screenbuffer);
|
||||
consoles[currentconsoleindex].active = 0;
|
||||
clearconsole(currentconsole->screenbuffer);
|
||||
currentconsole->active = 0;
|
||||
switchtoconsole(0);
|
||||
return 0;
|
||||
}
|
||||
|
1
param.h
1
param.h
@ -11,6 +11,7 @@
|
||||
#define LOGSIZE (MAXOPBLOCKS*3) // max data blocks in on-disk log
|
||||
#define NBUF (MAXOPBLOCKS*3) // size of disk block cache
|
||||
#define FSSIZE 1000 // size of file system in blocks
|
||||
|
||||
#define MAXVCONSOLES 10 // Max number of consoles that can be open
|
||||
#define SCRWIDTH 80 // Numbers of characters across the screen
|
||||
#define SCRHEIGHT 25 // Number of lines down the screen
|
||||
|
Reference in New Issue
Block a user