Skip to content

Commit a86dbcc

Browse files
committed
* Semi implemented customisable prompt
* Added some settings variable * Added func.h
1 parent 68eb7ed commit a86dbcc

File tree

5 files changed

+94
-15
lines changed

5 files changed

+94
-15
lines changed

Drivers/Keyboard.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
static bool isCTRLed = false;
44
bool canNewLine = true;
55

6+
void PrintPrompt();
7+
68
bool isUSRChanged = false;
79
void printf(char *);
810
void printfchar(char st);
911
void printHex(uint8_t key);
1012
void PrintDate();
1113
char* INTTOCHARPOINT(int num);
14+
void beep();
1215
void ColourPrint(int type);
1316
bool txtcolor;
1417
bool isESPChanged = false;
@@ -60,8 +63,8 @@ CommandPort(0x64)
6063
SP[i] = "\0";
6164
}
6265

63-
char* Shell_Prompt[15] = {"r","o","o","t","@","s","e","c","o","s",":","~","#",">", " "};
64-
for (int i = 0; i < 15; i++)
66+
char *Shell_Prompt[14] = {"%", "u", "@", "%", "h", "[", "%", "d" , "}" , ";", "~", "#", ">", " "};
67+
for (int i = 0; i < 14; i++)
6568
{
6669
SP[SPIndex] = Shell_Prompt[i];
6770
SPIndex++;
@@ -523,6 +526,10 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
523526
{
524527
//power.shutdown();
525528
}
529+
else if (key_buffer[0] == "b" && key_buffer[1] == "e" && key_buffer[2] == "e" && key_buffer[3] == "p")
530+
{
531+
beep();
532+
}
526533
else
527534
{
528535
printf("Unknown Command \"");
@@ -535,13 +542,12 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
535542
if(!isTxtMode){
536543
if (canNewLine)
537544
printf("\n");
538-
for (int i = 0; SPIndex > i; i++)
539-
{
540-
printf(SP[i]);
541-
}
542545
canNewLine = true;
543546
}
544-
serialport.logToSerialPort("Command interpreter got a command :- "); serialport.logToSerialPort(COMNAME); serialport.logToSerialPort("\n");
547+
PrintPrompt();
548+
serialport.logToSerialPort("Command interpreter got a command :- ");
549+
serialport.logToSerialPort(COMNAME);
550+
serialport.logToSerialPort("\n");
545551
clear_key_buffer();
546552
}
547553
}

Include/Public_VAR.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inline char* OS_NAME = "SectorOS";
55

66
inline char* KERNEL_NAME = "SectorOS";
77
inline char* KERNEL_VERSION = "V2.3.1";
8-
inline char* KERNEL_BUILD = "Build: 2022-01-09";
8+
inline char* KERNEL_BUILD = "Build: 2022-01-25";
99
inline char* KERNEL_ARCH = "x86";
1010

1111
inline char* SHELL_NAME = "SOSH";
@@ -141,7 +141,7 @@ inline char* KeycodeToASCII(uint8_t Keycode)
141141
case 0x2D:if (!isShift) result = "x"; else result = "X"; break;
142142
case 0x2E:if (!isShift) result = "c"; else result = "C"; break;
143143
case 0x2F:if (!isShift) result = "v"; else result = "V"; break;
144-
case 0x30:if (!isShift) result = "v"; else result = "B"; break;
144+
case 0x30:if (!isShift) result = "b"; else result = "B"; break;
145145
case 0x31:if (!isShift) result = "n"; else result = "N"; break;
146146
case 0x32:if (!isShift) result = "m"; else result = "M"; break;
147147
case 0x33:if (!isShift) result = ","; else result = "<"; break;

Include/func.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef FUNC_H
2+
#define FUNC_H
3+
4+
inline char CharPOINTERToChar(char* c)
5+
{
6+
return *c;
7+
}
8+
9+
#endif

kernel/Settings.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __SETTINGS_H
2+
#define __SETTINGS_H
3+
4+
#include "../Include/types.h"
5+
6+
class Settings
7+
{
8+
public:
9+
char *UserName = "root";
10+
int UserNameLength = 4;
11+
char *UserPassword = "root";
12+
char* Hostname = "localhost";
13+
int HostnameLength = 10;
14+
15+
bool IsNetworkEnabled = false;
16+
bool IsHDDEnabled = true;
17+
};
18+
19+
#endif

kernel/kernel.cpp

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "../Drivers/Keyboard.h"
66
#include "../Shell/Shell.h"
77
#include "../Include/multiboot.h"
8+
#include "../Include/func.h"
9+
#include "Settings.h"
810
#include "../Hardcom/SerialPort.h"
911
#include "../CPU/syscall.h"
1012
#include "../Drivers/Mouse.h"
@@ -25,11 +27,16 @@ static uint8_t cursorx;
2527
static bool useMouse = true;
2628
bool isused;
2729

30+
bool isPrefix;
31+
bool lkl;
32+
int index = 0;
33+
int spind = 0;
34+
2835
static uint8_t x = 0, y = 0;
2936

3037
bool isTxtMode;
31-
KeyboardDriver* kbrd;
32-
DriverManager* drvMngr;
38+
KeyboardDriver *kbrd;
39+
DriverManager *drvMngr;
3340
InterruptManager* intMngr;
3441
SyscallHandler* shand;
3542
extern const void *mb;
@@ -45,6 +52,7 @@ port8BIT port61(0x61);
4552
int delay;
4653
volatile int done;
4754
static uint16_t *VideoMemory = (uint16_t *)0xb8000;
55+
Settings set;
4856

4957
static void play_sound(uint32_t nFrequence)
5058
{
@@ -724,7 +732,6 @@ void printf(char *str)
724732
for (int i = 0; i != 80; i++)
725733
VideoMemory[80 * 1 + i] = (VideoMemory[80 * 1 + i] & 0xFF00) | foo[i];
726734
printf("\n");
727-
play_sound(440);
728735
}
729736
}
730737

@@ -743,6 +750,42 @@ void PrintDate()
743750
printf(INTTOCHARPOINT(rtclock.year));
744751
}
745752

753+
void PrintPrompt()
754+
{
755+
for (int i = 0; SPIndex > i; i++)
756+
{
757+
if (SP[i][0] == '%')
758+
{
759+
switch (SP[i + 1][0])
760+
{
761+
case 'd':
762+
{
763+
PrintDate();
764+
index = 2;
765+
break;
766+
}
767+
case 'u':
768+
{
769+
printf(set.UserName);
770+
index = 2;
771+
break;
772+
}
773+
case 'h':
774+
{
775+
printf(set.Hostname);
776+
index = 2;
777+
break;
778+
}
779+
}
780+
}
781+
else if (index <= 0)
782+
{
783+
printf(SP[i]);
784+
}
785+
index--;
786+
}
787+
}
788+
746789
void printTime()
747790
{
748791
if (!done && delay)
@@ -1162,7 +1205,8 @@ extern "C" void kernelMain(const void *multiboot_structure, uint32_t multiboot_m
11621205

11631206
printf("Allocating Memory....\n");
11641207
PrintMEM(multiboot_structure);
1165-
//PrintPartitions();
1208+
1209+
// PrintPartitions();
11661210
sp.logToSerialPort("\nHardware initialising stage 3 finished");
11671211
detect_cpu();
11681212

@@ -1186,9 +1230,10 @@ extern "C" void kernelMain(const void *multiboot_structure, uint32_t multiboot_m
11861230
printf("Welcome to SectorOS Shell\nRun help to get the list of commands which is implemented \n \n");
11871231
sp.logToSerialPort("\nKernel initialization surcessful.\nGiving execution access to the kernel.\nAwaiting user input...");
11881232

1189-
SPIndex = 15;
1233+
SPIndex = set.UserNameLength + set.HostnameLength + 5 + 11;
11901234

1191-
asm("int $0x80" :: "a"(1), "b"("root@secos:~#> ")); // Used syscall to print this prompt
1235+
//asm("int $0x80" :: "a"(1), "b"("root@secos:~#> ")); // Used syscall to print this prompt
1236+
PrintPrompt();
11921237
SPOMEMLOC(sp);
11931238

11941239
while (1);

0 commit comments

Comments
 (0)