update PrintInt and change PutString to PutInt
This commit is contained in:
@@ -173,10 +173,12 @@ ConsoleOutput::PutChar(char ch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ConsoleOutput::PutString(char *str)
|
ConsoleOutput::PutInt(int value)
|
||||||
{
|
{
|
||||||
ASSERT(putBusy == FALSE);
|
ASSERT(putBusy == FALSE);
|
||||||
WriteFile(writeFileNo, str, strlen(str));
|
char *printStr = (char*)malloc(sizeof(char)*15);
|
||||||
|
sprintf(printStr, "%d\n", value);
|
||||||
|
WriteFile(writeFileNo, printStr, strlen(printStr)*sizeof(char));
|
||||||
putBusy = TRUE;
|
putBusy = TRUE;
|
||||||
kernel->interrupt->Schedule(this, ConsoleTime, ConsoleWriteInt);
|
kernel->interrupt->Schedule(this, ConsoleTime, ConsoleWriteInt);
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ class ConsoleOutput : public CallBackObj {
|
|||||||
void PutChar(char ch); // Write "ch" to the console display,
|
void PutChar(char ch); // Write "ch" to the console display,
|
||||||
// and return immediately. "callWhenDone"
|
// and return immediately. "callWhenDone"
|
||||||
// will called when the I/O completes.
|
// will called when the I/O completes.
|
||||||
void PutString(char *str);
|
void PutInt(int n);
|
||||||
void CallBack(); // Invoked when next character can be put
|
void CallBack(); // Invoked when next character can be put
|
||||||
// out to the display.
|
// out to the display.
|
||||||
|
|
||||||
|
|||||||
@@ -359,3 +359,8 @@ Interrupt::DumpState()
|
|||||||
cout << "\nEnd of pending interrupts\n";
|
cout << "\nEnd of pending interrupts\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Interrupt::PrintInt(int value)
|
||||||
|
{
|
||||||
|
return kernel->PrintInt(value);
|
||||||
|
}
|
||||||
@@ -308,4 +308,7 @@ int Kernel::CreateFile(char *filename)
|
|||||||
return fileSystem->Create(filename);
|
return fileSystem->Create(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Kernel::PrintInt(int value)
|
||||||
|
{
|
||||||
|
return synchConsoleOut->PutInt(value);
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ class Kernel {
|
|||||||
void NetworkTest(); // interactive 2-machine network test
|
void NetworkTest(); // interactive 2-machine network test
|
||||||
Thread* getThread(int threadID){return t[threadID];}
|
Thread* getThread(int threadID){return t[threadID];}
|
||||||
|
|
||||||
|
void PrintInt(int n);
|
||||||
|
|
||||||
int CreateFile(char* filename); // fileSystem call
|
int CreateFile(char* filename); // fileSystem call
|
||||||
|
|
||||||
// These are public for notational convenience; really,
|
// These are public for notational convenience; really,
|
||||||
|
|||||||
@@ -37,33 +37,7 @@ int SysCreate(char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SysPrintInt(int value) {
|
void SysPrintInt(int value) {
|
||||||
static char zero[2] = "0";
|
kernel->interrupt->PrintInt(value);
|
||||||
|
|
||||||
if (value == 0) {
|
|
||||||
kernel->synchConsoleOut->PutString(zero);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char outputBuf[INT_BUF_LENGTH];
|
|
||||||
bool isNeg = false;
|
|
||||||
int curPos = INT_BUF_LENGTH;
|
|
||||||
outputBuf[--curPos] = '\0';
|
|
||||||
outputBuf[--curPos] = '\n';
|
|
||||||
|
|
||||||
if (value < 0) {
|
|
||||||
isNeg = true;
|
|
||||||
value = -value;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (value > 0) {
|
|
||||||
outputBuf[--curPos] = '0' + (value % 10);
|
|
||||||
value /= 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNeg)
|
|
||||||
outputBuf[--curPos] = '-';
|
|
||||||
|
|
||||||
kernel->synchConsoleOut->PutString(&outputBuf[curPos]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenFileId SysOpen(char *name) {
|
OpenFileId SysOpen(char *name) {
|
||||||
|
|||||||
@@ -107,10 +107,10 @@ SynchConsoleOutput::PutChar(char ch)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SynchConsoleOutput::PutString(char *str)
|
SynchConsoleOutput::PutInt(int value)
|
||||||
{
|
{
|
||||||
lock->Acquire();
|
lock->Acquire();
|
||||||
consoleOutput->PutString(str);
|
consoleOutput->PutInt(value);
|
||||||
waitFor->P();
|
waitFor->P();
|
||||||
lock->Release();
|
lock->Release();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class SynchConsoleOutput : public CallBackObj {
|
|||||||
~SynchConsoleOutput();
|
~SynchConsoleOutput();
|
||||||
|
|
||||||
void PutChar(char ch); // Write a character, waiting if necessary
|
void PutChar(char ch); // Write a character, waiting if necessary
|
||||||
void PutString(char *ch);
|
void PutInt(int value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConsoleOutput *consoleOutput;// the hardware display
|
ConsoleOutput *consoleOutput;// the hardware display
|
||||||
|
|||||||
Reference in New Issue
Block a user