From 4492075836a2e1236f5c154950d2475f6f6d5d25 Mon Sep 17 00:00:00 2001 From: sheispeko <82322282+lightning-speed@users.noreply.github.com> Date: Sat, 25 Sep 2021 16:11:23 +0530 Subject: [PATCH] Add files via upload --- src/App32/Calculator.c | 54 +++++ src/App32/ImageViewr.c | 20 ++ src/App32/Mex-Compiler.c | 89 +++++++ src/Drivers/Keyboard.c | 47 ++++ src/Drivers/Keyboard.h | 4 + src/Drivers/Screen.c | 93 ++++++++ src/Drivers/Screen.h | 20 ++ src/FS/default_files.h | 9 + src/FS/fs.c | 162 +++++++++++++ src/FS/fs.h | 16 ++ src/Graphics/Graphics.c | 25 ++ src/Graphics/Graphics.h | 8 + src/Graphics/Image.c | 18 ++ src/Graphics/Image.h | 2 + src/Graphics/Window.c | 59 +++++ src/Mego-Runtime/Command.c | 23 ++ src/Mego-Runtime/Memory.c | 76 ++++++ src/Mego-Runtime/Processor.c | 85 +++++++ src/Mego-Runtime/Runtime.c | 43 ++++ src/Mego-Runtime/Runtime.h | 14 ++ src/Shell/shell.c | 49 ++++ src/Shell/shell.h | 3 + src/System/IO.c | 16 ++ src/System/IO.h | 15 ++ src/System/Logo.c | 19 ++ src/System/MemoryManager.c | 31 +++ src/System/MemoryManager.h | 4 + src/System/Random.c | 5 + src/System/Random.h | 2 + src/System/System.c | 12 + src/System/System.h | 3 + src/System/SystemTime.c | 52 ++++ src/System/SystemTime.h | 7 + src/System/Time.asm | 1 + src/Terminal-Runtime/Terminal-Runtime.c | 303 ++++++++++++++++++++++++ src/Terminal-Runtime/Terminal-Runtime.h | 3 + src/Timer/Timer.c | 8 + src/Timer/Timer.h | 2 + src/Util/string.c | 92 +++++++ src/Util/string.h | 14 ++ src/Util/types.h | 7 + src/desktop.ini | 4 + src/kernel.c | 24 ++ src/kernel_loader.asm | 11 + src/kernel_loader2.asm | 12 + 45 files changed, 1566 insertions(+) create mode 100644 src/App32/Calculator.c create mode 100644 src/App32/ImageViewr.c create mode 100644 src/App32/Mex-Compiler.c create mode 100644 src/Drivers/Keyboard.c create mode 100644 src/Drivers/Keyboard.h create mode 100644 src/Drivers/Screen.c create mode 100644 src/Drivers/Screen.h create mode 100644 src/FS/default_files.h create mode 100644 src/FS/fs.c create mode 100644 src/FS/fs.h create mode 100644 src/Graphics/Graphics.c create mode 100644 src/Graphics/Graphics.h create mode 100644 src/Graphics/Image.c create mode 100644 src/Graphics/Image.h create mode 100644 src/Graphics/Window.c create mode 100644 src/Mego-Runtime/Command.c create mode 100644 src/Mego-Runtime/Memory.c create mode 100644 src/Mego-Runtime/Processor.c create mode 100644 src/Mego-Runtime/Runtime.c create mode 100644 src/Mego-Runtime/Runtime.h create mode 100644 src/Shell/shell.c create mode 100644 src/Shell/shell.h create mode 100644 src/System/IO.c create mode 100644 src/System/IO.h create mode 100644 src/System/Logo.c create mode 100644 src/System/MemoryManager.c create mode 100644 src/System/MemoryManager.h create mode 100644 src/System/Random.c create mode 100644 src/System/Random.h create mode 100644 src/System/System.c create mode 100644 src/System/System.h create mode 100644 src/System/SystemTime.c create mode 100644 src/System/SystemTime.h create mode 100644 src/System/Time.asm create mode 100644 src/Terminal-Runtime/Terminal-Runtime.c create mode 100644 src/Terminal-Runtime/Terminal-Runtime.h create mode 100644 src/Timer/Timer.c create mode 100644 src/Timer/Timer.h create mode 100644 src/Util/string.c create mode 100644 src/Util/string.h create mode 100644 src/Util/types.h create mode 100644 src/desktop.ini create mode 100644 src/kernel.c create mode 100644 src/kernel_loader.asm create mode 100644 src/kernel_loader2.asm diff --git a/src/App32/Calculator.c b/src/App32/Calculator.c new file mode 100644 index 00000000..69e7260b --- /dev/null +++ b/src/App32/Calculator.c @@ -0,0 +1,54 @@ +#include +#include +#include +void calc_init(){ + printW("\nEnter First Number: "); + int fn = parseInt(input()); + printW("\nEnter Second Number: "); + int sn = parseInt(input()); + printW("\nEnter the valid operator: "); + char ae; + int runningC = 1; + while(runningC){ + ae = readChar(); + if(ae=='+'){ + printC(ae); + printW("\nOutput: "); + printW(toString(fn+sn)); + runningC = 0; + } + else if(ae=='-'){ + printC(ae); + printW("\nOutput: "); + printW(toString(fn-sn)); + runningC = 0; + } + else if(ae=='/'){ + printC(ae); + + printW("\nOutput: "); + printW(toString(fn/sn)); + runningC = 0; + } + else if(ae=='*'){ + printC(ae); + + printW("\nOutput: "); + printW(toString((fn*sn))); + runningC = 0; + } + else if(ae=='%'){ + printC(ae); + + printW("\nOutput: "); + printW(toString((fn%sn))); + runningC = 0; + + } + else{ + printC(ae); + printW("\nEnter the valid operator: "); + } + + } +} \ No newline at end of file diff --git a/src/App32/ImageViewr.c b/src/App32/ImageViewr.c new file mode 100644 index 00000000..11b81f32 --- /dev/null +++ b/src/App32/ImageViewr.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include +#include +#include +char * ftv; +void ImageViewr_pre(){ + ftv = new_str(109); +} +void ImageViewr_init(char * fn){ + for(int i = 0;i<108;i++){ + ftv[i]=0; + } + makeWindow("Image Viewr"); + set((int *)ftv,(int *)readFile(fn)); + drawImage(40-ftv[0],12-ftv[1],ftv); + start_window_system(); +} \ No newline at end of file diff --git a/src/App32/Mex-Compiler.c b/src/App32/Mex-Compiler.c new file mode 100644 index 00000000..2b36b7a6 --- /dev/null +++ b/src/App32/Mex-Compiler.c @@ -0,0 +1,89 @@ +char * process(char * in); +#include +#include +#include +#include +#include +#include +void compile(char * text){ + char * command = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + char * total = new_str(896); + int temp = 0; + for(int i = 0;i<896;i++)total[i]=0; + for(int i = 0;i='0')out[1]=(char)parseInt(arg1); + else if(arg1[0]=="'"[0])out[1]=arg1[1]; + else{ + if(equalS(arg1,"aa",2))out[1]=1; + else if(equalS(arg1,"ab",2))out[1]=2; + else if(equalS(arg1,"ac",2))out[1]=3; + else if(equalS(arg1,"ad",2))out[1]=4; + else if(equalS(arg1,"ae",2))out[1]=5; + else if(equalS(arg1,"af",2))out[1]=6; + else if(equalS(arg1,"ag",2))out[1]=7; + else if(equalS(arg1,"ah",2))out[1]=8; + else if(equalS(arg1,"ai",2))out[1]=9; + else if(equalS(arg1,"aj",2))out[1]=10; + else if(equalS(arg1,"ak",2))out[1]=11; + else if(equalS(arg1,"al",2))out[1]=12; + } + if(arg2[0]<='9'&&arg2[0]>='0')out[2]=(char)parseInt(arg2); + else if(arg2[0]=="'"[0])out[2]=arg2[1]; + else{ + if(equalS(arg2,"aa",2))out[2]=1; + else if(equalS(arg2,"ab",2))out[2]=2; + else if(equalS(arg2,"ac",2))out[2]=3; + else if(equalS(arg2,"ad",2))out[2]=4; + else if(equalS(arg2,"ae",2))out[2]=5; + else if(equalS(arg2,"af",2))out[2]=6; + else if(equalS(arg2,"ag",2))out[2]=7; + else if(equalS(arg2,"ah",2))out[2]=8; + else if(equalS(arg2,"ai",2))out[2]=9; + else if(equalS(arg2,"aj",2))out[2]=10; + else if(equalS(arg2,"ak",2))out[2]=11; + else if(equalS(arg2,"al",2))out[2]=12; + } + out[3]='\e'; + return out; +} \ No newline at end of file diff --git a/src/Drivers/Keyboard.c b/src/Drivers/Keyboard.c new file mode 100644 index 00000000..f8caf94a --- /dev/null +++ b/src/Drivers/Keyboard.c @@ -0,0 +1,47 @@ +#include"Screen.h" +char * keycode = "\e 1234567890-=\b\tqwertyuiop[]\n\0asdfghjkl;'`\0\\zxcvbnm,./\0\0\0 "; +char * keycode2 = "\e !@#$%^&*()_+\b\tQWERTYUIOP{}\n\0ASDFGHJKL:'~\0|ZXCVBNM<>?\0\0\0 "; +int isShift= 0; +#include +char readChar(){ + int run = 1; + char out = 0; + while(run){ + if(inportb(0x64) & 0x1){ + if(inportb(0x60)==0x2A&&!isShift)isShift=1; + else if(inportb(0x60)==0xAA&&isShift)isShift=0; + if(!isShift) + out = keycode[inportb(0x60)]; + else if(isShift) + out = keycode2[inportb(0x60)]; + if(out!=0&&inportb(0x60)<60)run=0; + + } + } + return out; +} + char * input(){ + char tp=0; + char * out=""; + int index = 0; + while((tp=readChar())!='\n'){ + out[index]=tp; + out[index+1]=0; + if(out[index]=='\b'){ + if(index>0){ + out[index]=0; + out[index-1]=0; + backspace(); + index-=1; + } + } + else{ + printChar(tp,Screen->defaultColor); + index++; + } + } + return out; +} +char getChar(){ + if(inportb(0x60)<60&&inportb(0x60)>0&&keycode[inportb(0x60)]>0&&keycode[inportb(0x60)]<254)return keycode[inportb(0x60)]; +} \ No newline at end of file diff --git a/src/Drivers/Keyboard.h b/src/Drivers/Keyboard.h new file mode 100644 index 00000000..475408a9 --- /dev/null +++ b/src/Drivers/Keyboard.h @@ -0,0 +1,4 @@ +#pragma once +char readChar(); +char * input(); +char getChar(); \ No newline at end of file diff --git a/src/Drivers/Screen.c b/src/Drivers/Screen.c new file mode 100644 index 00000000..d1b54a24 --- /dev/null +++ b/src/Drivers/Screen.c @@ -0,0 +1,93 @@ +#include"Screen.h" +#include + +void scroll(); +void printChar(char ch,int color){ + if(ch=='\b'){backspace();return;} + if(Screen->cursorY>=24){scroll();} + if(ch=='\n'||Screen->cursorX==160){ + Screen->cursorY++; + Screen->cursorX = 0; + } + if(ch!='\n'){ + Screen->vga[(Screen->cursorY*160)+Screen->cursorX]=ch; + Screen->vga[(Screen->cursorY*160)+Screen->cursorX+1]=color; + Screen->cursorX+=2; + } + setCursorPosition(Screen->cursorX,Screen->cursorY); +} +void setCursorPosition(int xe,int ye){ + unsigned temp; + temp = ye * 80 + (xe/2); + outportb(0x3D4, 14); + outportb(0x3D5, temp >> 8); + outportb(0x3D4, 15); + outportb(0x3D5, temp); +} +void printC(char a){ + printChar(a,Screen->defaultColor); +} +void print(const char * str,int color){ + for(int i = 0;str[i]!=0;i++){ + printChar(str[i],color); + } + setCursorPosition(Screen->cursorX,Screen->cursorY); +} +void printW(const char * str){ + print(str,Screen->defaultColor); + setCursorPosition(Screen->cursorX,Screen->cursorY); +} +void clearScreen(){ + Screen->cursorX = 0; + Screen->cursorY = 0; + for(int i = 0;i<160*25;i+=2){ + Screen->vga[i]=0; + } +} + +void screen_init(){ + Screen->vga = (char *) 0xB8000; + Screen->cursorX = 0; + Screen->cursorY = 0; + Screen->defaultColor = 0x07; +} +void setDefaultColor(int color){ + Screen->defaultColor = color; +} +void clearLine(int line){ + for(int i = 0;i<160;i++){ + Screen->vga[(160*line)+i]=0; + } +} +void setScreenColor(int color){ + setDefaultColor(color); + char * vga = (char *) 0xB8000; + for(int i = 1;i<160*26;i+=2){ + vga[i] = (color-(color%16))+(vga[i]%16); + } +} +void scroll(){ + char * * lines; + for(int i = 1;icursorY+1;i++){ + for(int j = 0;j<160;j++){ + Screen->vga[(160*(i-1))+j] = Screen->vga[(160*i)+j]; + } + } + clearLine(Screen->cursorY); + Screen->cursorY--; + setScreenColor(Screen->defaultColor); +} +void backspace(){ + if(Screen->cursorX!=0)Screen->cursorX-=2; + else{Screen->cursorX=160;Screen->cursorY--;} + Screen->vga[(Screen->cursorY*160)+Screen->cursorX]=0; + setCursorPosition(Screen->cursorX,Screen->cursorY); +} +void clearFullScreen(){ + Screen->cursorX = 0; + Screen->cursorY = 0; + for (int i = 0; i < 25*160; i+=2){ + Screen->vga[i] = 0; + Screen->vga[i+1] = Screen->defaultColor; + } +} \ No newline at end of file diff --git a/src/Drivers/Screen.h b/src/Drivers/Screen.h new file mode 100644 index 00000000..62921bce --- /dev/null +++ b/src/Drivers/Screen.h @@ -0,0 +1,20 @@ +#pragma once +struct sc +{ + int cursorX; + int cursorY; + int defaultColor; + char *vga; +}; +static struct sc *Screen; +void screen_init(); +void clearScreen(); +void printChar(char ch, int color); +void print(const char *str, int color); +void printW(const char *str); +void setScreenColor(int color); +void setDefaultColor(int color); +void setCursorPosition(int xe, int ye); +void backspace(); +void printC(char a); +void clearFullScreen(); \ No newline at end of file diff --git a/src/FS/default_files.h b/src/FS/default_files.h new file mode 100644 index 00000000..782a0518 --- /dev/null +++ b/src/FS/default_files.h @@ -0,0 +1,9 @@ +void createNativeFiles() +{ + createFile("hello"); + writeFile("hello", "movn af 6\ncmdn 4 1\nmovn ac 'H\ncmdn 1 1\nmovn ac 'e\ncmdn 1 1\nmovn ac 'l\ncmdn 1 1\nmovn ac 'l\ncmdn 1 1\nmovn ac 'o\ncmdn 1 1\nmovn ac ',\ncmdn 1 1\nmovn ac 'M\ncmdn 1 1\nmovn ac 'e\ncmdn 1 1\nmovn ac 'x\ncmdn 1 1\n"); + createFile("build.sh"); + writeFile("build.sh", "echo building...\nmex hello\nrename out.mex hello.mex\nmex ascii\nrename out.mex ascii.mex\necho done\n"); + createFile("ascii"); + writeFile("ascii", "movn ac 127\naddn ac 127\ncmdn 1 1\nsubn ac 1\nbign ac 1\njnzn 8 1\n"); +} \ No newline at end of file diff --git a/src/FS/fs.c b/src/FS/fs.c new file mode 100644 index 00000000..1ed52877 --- /dev/null +++ b/src/FS/fs.c @@ -0,0 +1,162 @@ +#include "fs.h" +#include "default_files.h" +#include +#include +char *fs; +int fs_index = 0; +int file_index = 0; +void createNativeFiles(); +void fs_init() +{ + fs = (char *)new_str(56000); + createNativeFiles(); +} +void createFile(char *fn) +{ + for (int i = fs_index; i <= fs_index + 2048; i++) + { + fs[i] = 0; + } + for (int i = 0; i < length(fn); i++) + { + fs[fs_index + i] = fn[i]; + } + fs_index += 2048; + file_index++; +} +void writeFileAt(int indexF, char *content) +{ + int loc = indexF * 2048; + for (int i = loc + 32; i < loc + 32 + length(content); i++) + { + fs[i] = content[i - (loc + 32)]; + } +} +char *getFileNameAt(int indexF) +{ + char *out = new_str(34); //32-bit name + int loc = indexF * 2048; + for (int i = 0; i < 32; i++) + { + out[i] = fs[loc + i]; + } + return out; +} +char *getFileContentAt(int indexF) +{ + char *out = new_str(2050); + int loc = indexF * 2048; + for (int i = 0; i < 2000; i++) + { + out[i] = fs[loc + i + 32]; + } + return out; +} +char *readFile(char *name) +{ + for (int i = 0; i < file_index; i++) + { + if (equal(name, getFileNameAt(i))) + { + return getFileContentAt(i); + } + } +} +void writeFile(char *name, char *text) +{ + for (int i = 0; i < file_index; i++) + { + if (equal(name, getFileNameAt(i))) + { + writeFileAt(i, text); + } + } +} +int doesFileExists(char *name) +{ + for (int i = 0; i < file_index; i++) + { + if (equal(name, getFileNameAt(i))) + { + return 1; + } + } + return 0; +} +int file_size_of(char *name) +{ + return length(readFile(name)); +} +char *getFS() +{ + return fs; +} +int total_files() +{ + return file_index; +} + +void copyFile(char *in, char *des) +{ + createFile(des); + writeFile(des, readFile(in)); +} +void clearFile(char *name) +{ + for (int i = 0; i < file_index; i++) + { + if (equal(name, getFileNameAt(i))) + { + for (int j = 0; j < 2000; j++) + { + fs[(i * 2048) + j + 32] = 0; + } + } + } +} +void deleteFileAt(int ie) +{ + int loc = ie * 2048; + int inr = 0; + for (int i = loc; i < loc + 2048; i++) + { + fs[i] = 0; + } + for (int i = loc + 2048; i <= fs_index; i++) + { + fs[loc + inr] = fs[i]; + inr++; + } + fs_index -= 2048; + file_index--; +} +void deleteFile(char *name) +{ + for (int i = 0; i < file_index; i++) + { + if (equal(name, getFileNameAt(i))) + { + deleteFileAt(i); + return; + } + } +} +void rename(char *fileName, char *to) +{ + for (int i = 0; i < file_index; i++) + { + if (equal(fileName, getFileNameAt(i))) + { + int ind = 2048 * i; + for (int i = 0; i < 32; i++) + { + fs[ind + i] = 0; + } + for (int i = 0; i < length(to); i++) + { + fs[ind + i] = to[i]; + } + break; + } + } +} \ No newline at end of file diff --git a/src/FS/fs.h b/src/FS/fs.h new file mode 100644 index 00000000..fa6a4866 --- /dev/null +++ b/src/FS/fs.h @@ -0,0 +1,16 @@ +#pragma once +void createFile(char *fn); +void fs_init(); +char *getFS(); +void writeFileAt(int indexF, char *content); +char *getFileNameAt(int indexF); +char *getFileContentAt(int indexF); +int total_files(); +int file_size_of(char *name); +char *readFile(char *name); +int doesFileExists(char *name); +void writeFile(char *name, char *text); +void copyFile(char *in, char *des); +void clearFile(char *name); +void deleteFile(char *name); +void rename(char *fileName, char *to); \ No newline at end of file diff --git a/src/Graphics/Graphics.c b/src/Graphics/Graphics.c new file mode 100644 index 00000000..cea7a9f6 --- /dev/null +++ b/src/Graphics/Graphics.c @@ -0,0 +1,25 @@ +#include + +int length(char * in); +void setDefaultScreenColor(int color); +void setCharAt(int xex,int ye,char ae,int color){ + int xe = xex*2; + char * vga = (char *) 0xB8000; + vga[(ye*160)+xe]=ae; + vga[(ye*160)+xe+1]=color; +} +void printAt(int xe,int ye,char * tex,int color){ + for(int i = 0;ivga[(y*160)+(x*4)]=219; + Screen->vga[(y*160)+(x*4)+1]=color; + Screen->vga[(y*160)+(x*4)+2]=219; + Screen->vga[(y*160)+(x*4)+3]=color; + +} \ No newline at end of file diff --git a/src/Graphics/Graphics.h b/src/Graphics/Graphics.h new file mode 100644 index 00000000..177f5aac --- /dev/null +++ b/src/Graphics/Graphics.h @@ -0,0 +1,8 @@ +#pragma once +void setCharAt(int xe,int ye,char ae,int color); +void printAt(int xe,int ye,char * tex,int color); +void printCenter(int ye,char * text,int color); +void setBlockAt(int x,int y,int color); +void makeWindow(char * window_name); +void printStringInWindow(char * text); +void start_window_system(); \ No newline at end of file diff --git a/src/Graphics/Image.c b/src/Graphics/Image.c new file mode 100644 index 00000000..03ce1729 --- /dev/null +++ b/src/Graphics/Image.c @@ -0,0 +1,18 @@ +#include +typedef int * Image; +int he,we; +void drawImage(int xe,int ye,char * img){ + we = img[0]; + he = img[1]; + int temp = 2; + xe*=2; + for(int i = 0;ivga[(160*(i+ye))+j+xe]=219; + Screen->vga[(160*(i+ye))+j+1+xe]=img[temp]; + Screen->vga[(160*(i+ye))+j+2+xe]=219; + Screen->vga[(160*(i+ye))+j+3+xe]=img[temp]; + temp++; + } + } +} \ No newline at end of file diff --git a/src/Graphics/Image.h b/src/Graphics/Image.h new file mode 100644 index 00000000..db3a8b06 --- /dev/null +++ b/src/Graphics/Image.h @@ -0,0 +1,2 @@ +#pragma once +void drawImage(int xe,int ye,char * img); \ No newline at end of file diff --git a/src/Graphics/Window.c b/src/Graphics/Window.c new file mode 100644 index 00000000..3edc0e70 --- /dev/null +++ b/src/Graphics/Window.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include +char *screen = (char *)0xFFFFFFF; +void makeWindow(char *window_name) +{ + for (int i = 0; i < 160 * 25; i++) + { + screen[i] = Screen->vga[i]; + } + clearScreen(); + for (int i = 0; i < 80; i++) + { + printChar(' ', 0x1f); + setCharAt(i, 24, ' ', 0x1f); + } + for (int i = 0; i < 25; i++) + { + setCharAt(0, i, ' ', 0x1f); + setCharAt(79, i, ' ', 0x1f); + } + printCenter(0, window_name, 0x1f); + Screen->cursorX = 2; + Screen->cursorY = 1; + printAt(0, 24, " Press ESC to exit", 0x1f); +} +void printStringInWindow(char *text) +{ + for (int i = 0; i < length(text); i++) + { + if (Screen->cursorX % 160 == 0) + { + Screen->cursorX += 2; + } + if (Screen->cursorX % 158 == 0) + { + Screen->cursorX += 4; + } + printC(text[i]); + } +} +void start_window_system() +{ + int running = 1; + while (running) + if (inportb(0x60) == 0x01) + running = 0; + clearFullScreen(); +} +void clearWindow() +{ + for (int i = 160; i < 1840; i += 2) + { + Screen->vga[i] = 0; + } + Screen->cursorX = 2; + Screen->cursorY = 1; +} \ No newline at end of file diff --git a/src/Mego-Runtime/Command.c b/src/Mego-Runtime/Command.c new file mode 100644 index 00000000..aea63c2b --- /dev/null +++ b/src/Mego-Runtime/Command.c @@ -0,0 +1,23 @@ +#include"Runtime.h" +#include +#include +#include +#include +void execute_command(int command){ + if(command==1){ + printC(getRegValueOf(3)); + } + else if(command==2){ + setRegValueOf(4,readChar()); + } + else if(command==3){ + clearScreen(); + } + else if(command==4){ + if(getRegValueOf(6)!=1) + setDefaultColor(0x10+getRegValueOf(6)); + } + else if(command==5){ + Sleep(getRegValueOf(3)); + } +} \ No newline at end of file diff --git a/src/Mego-Runtime/Memory.c b/src/Mego-Runtime/Memory.c new file mode 100644 index 00000000..87ee34d5 --- /dev/null +++ b/src/Mego-Runtime/Memory.c @@ -0,0 +1,76 @@ +#include +int AA = 0; +int AB = 0; +int AC = 0; +int AD = 0; +int AE = 0; +int AF = 0; +int AG = 0; +int AH = 0; +int AI = 0; +int AJ = 0; +int AK = 0; +int AL = 0; +int * virtual_memory = (int *)0xFF; +int stack_pointer = 0; + +void mem_init(){ + AA = 0; + AB = 0; + AC = 0; + AD = 0; + AE = 0; + AF = 0; + AH = 0; + AI = 0; + AJ = 0; + AK = 0; + AL = 0; +} +void setRegValueOf(int in,int value){ + if(in==1)AA = value; + if(in==2)AB = value; + if(in==3)AC = value; + if(in==4)AD = value; + if(in==5)AE = value; + if(in==6)AF = value; + if(in==7)AG = value; + if(in==8)AH = value; + if(in==9)AI = value; + if(in==10)AJ = value; + if(in==11)AK = value; + if(in==12)AL = value; +} +int getRegValueOf(int in){ + if(in==1)return AA; + if(in==2)return AB; + if(in==3)return AC; + if(in==4)return AD; + if(in==5)return AE; + if(in==6)return AF; + if(in==7)return AG; + if(in==8)return AH; + if(in==9)return AI; + if(in==10)return AJ; + if(in==11)return AK; + if(in==12)return AL; + else return 0; +} +void push(int in){ + virtual_memory[stack_pointer] = in; + stack_pointer++; +} +int pop(){ + int out = virtual_memory[0]; + for(int i = 0;iarg2){ + condition = 1; + } + else condition = 0; + } + if(command==43){ + //EQU + if(getRegValueOf(arg1)==arg2){ + condition = 1; + } + else condition = 0; + } + if(command==44){ + //OUTB + setMemoryAt(getRegValueOf(arg1),getRegValueOf(arg2)); + } + if(command==45){ + //INB + setRegValueOf(arg1,getMemoryAt(getRegValueOf(arg2))); + } +} \ No newline at end of file diff --git a/src/Mego-Runtime/Runtime.c b/src/Mego-Runtime/Runtime.c new file mode 100644 index 00000000..1150ffd6 --- /dev/null +++ b/src/Mego-Runtime/Runtime.c @@ -0,0 +1,43 @@ +#include"Runtime.h" +int cpu_pointer = 0; +void run_block(int * block){ + int * instruction = (int *)"\0\0\0\0"; + int temp = 0; + for(cpu_pointer = 0;block[cpu_pointer]!=0;cpu_pointer++){ + if(block[cpu_pointer]!='\e'&&temp<3){ + instruction[temp]=block[cpu_pointer]; + temp++; + } + else{ + run_instruction(instruction); + temp = 0; + instruction = (int *)"\0\0\0\0"; + } + } +} +void setMemory(int * mem){ + for(int i = 0;mem[i]!=0;i++) + setMemoryAt(i+50,mem[i]); +} +void setCpuPointer(int in){ + cpu_pointer = in-1; +} +void execute_program(int * program){ + mem_init(); + int * program_block=(int *)0xFFFF; + int * mem=(int *)0xAAAA; + for(int i = 0;i<1000;i++){ + mem[i]=0; + program_block[i]=0; + } + int tempy = 0; + for(int i = 0;program[i]!='\r'&&program[i]!=0;i++){ + program_block[i] = program[i]; + tempy = i+2; + } + for(int i = tempy;program[i]!=0;i++){ + mem[i-tempy]=program[i]; + } + setMemory(mem); + run_block(program_block); +} \ No newline at end of file diff --git a/src/Mego-Runtime/Runtime.h b/src/Mego-Runtime/Runtime.h new file mode 100644 index 00000000..9a8ecb81 --- /dev/null +++ b/src/Mego-Runtime/Runtime.h @@ -0,0 +1,14 @@ +#pragma once +void push(int in); +int getRegValueOf(int in); +void setRegValueOf(int in,int value); +int pop(); +void exec_instruction(int command,int arg1,int arg2); +void run_instruction(int * instruction); +void mem_init(); +void execute_command(int command); +void setCpuPointer(int in); +void run_block(int * block); +void setMemoryAt(int in,int mem); +int getMemoryAt(int in); +void execute_program(int * program); \ No newline at end of file diff --git a/src/Shell/shell.c b/src/Shell/shell.c new file mode 100644 index 00000000..bbaf0800 --- /dev/null +++ b/src/Shell/shell.c @@ -0,0 +1,49 @@ +#include "shell.h" +#include +#include +#include +#include +#include +#include +#include +void ImageViewr_pre(); +void memory_init(); + +void shell_main(){ + for(int i = 0;i<2000;i++) + Screen->vga[i]=0; + for(int i = 1;i<2000;i+=2){ + Screen->vga[i]=0x1f; + } + setScreenColor(0x1f); + printW("Radical OS [Version 2.0.0]\n"); + printW("Copyright (c) 2021 Radical Foundation. All rights reserved.\n\n"); + printW("Welcome to Radical OS. Hope you have fun :)\n\n"); + printW("Setting up Memory Manager... "); + memory_init(); + print("[ done ]\n\n",0x1a); + printW("Setting up VFS... "); + fs_init(); + print("[ done ]\n\n",0x1a); + printW("Time from boot: "); + printW(toString(getTimeFromBoot())); + printC('\n'); + start_shell(); +} +void start_shell(){ + ImageViewr_pre(); + char * temp = 0x0; + for(int i =0;i<1000000;i++){ + if(temp[i]=='w'&&temp[i+1]=='e'&&temp[i+2]=='0'){ + printC(temp[i+3]); + break; + } + } + printW("\nBuilding Some Mex Binaries..."); + runSh("build.sh"); + printC('\n'); + while(1){ + print("\nRADICAL>> ",0x1c); + system(input()); + } +} \ No newline at end of file diff --git a/src/Shell/shell.h b/src/Shell/shell.h new file mode 100644 index 00000000..2d10f232 --- /dev/null +++ b/src/Shell/shell.h @@ -0,0 +1,3 @@ +#pragma once +void shell_main(); +void start_shell(); \ No newline at end of file diff --git a/src/System/IO.c b/src/System/IO.c new file mode 100644 index 00000000..0372416e --- /dev/null +++ b/src/System/IO.c @@ -0,0 +1,16 @@ +#include + +uint8 inportb (uint16 _port) +{ + uint8 rv; + __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port)); + return rv; +} + +void outportb (uint16 _port, uint8 _data) +{ +__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data)); +} +void cli(){ + __asm__("cli"); +} \ No newline at end of file diff --git a/src/System/IO.h b/src/System/IO.h new file mode 100644 index 00000000..5b9a8d1f --- /dev/null +++ b/src/System/IO.h @@ -0,0 +1,15 @@ +#pragma once +typedef signed char int8; +typedef unsigned char uint8; + +typedef signed short int16; +typedef unsigned short uint16; + +typedef signed int int32; +typedef unsigned int uint32; + +typedef signed long long int64; +typedef unsigned long long uint64; +uint8 inportb (uint16 _port); +void outportb (uint16 _port, uint8 _data); +void cli(); \ No newline at end of file diff --git a/src/System/Logo.c b/src/System/Logo.c new file mode 100644 index 00000000..af415aa4 --- /dev/null +++ b/src/System/Logo.c @@ -0,0 +1,19 @@ +#include +int length(char * in); +char * logo[7]; +void printLogo(){ +logo[0] = " OOOOOO OO OOOOO OOOOOOO OOOOO OO O\n"; +logo[1] = " O O O O O O O O O O O\n"; +logo[2] = " O O O O O O O O O O O\n"; +logo[3] = " OOOOOO OOOOOO O O O O OOOOOO O\n"; +logo[4] = " O O O O O O O O O O O\n"; +logo[5] = " O O O O O O O O O O O\n"; +logo[6] = " O O O O OOOOO OOOOOOO OOOOO O O OOOOOOO\n"; +for(int i = 0;i<7;i++) + for(int j = 0;j +int random(){ + return (getSeconds()*getTimeFromBoot()*getSeconds()*getMinutes())*getSeconds(); +} \ No newline at end of file diff --git a/src/System/Random.h b/src/System/Random.h new file mode 100644 index 00000000..214f42d0 --- /dev/null +++ b/src/System/Random.h @@ -0,0 +1,2 @@ +#pragma once +int random(); \ No newline at end of file diff --git a/src/System/System.c b/src/System/System.c new file mode 100644 index 00000000..77ee6af6 --- /dev/null +++ b/src/System/System.c @@ -0,0 +1,12 @@ +#include "System.h" +#include +#include +void restart(){ + uint8 good = 0x02; + while (good & 0x02) + good = inportb(0x64); + outportb(0x64, 0xFE); +} +void shutdown(){ + __asm__ __volatile__("int $0x10"); +} diff --git a/src/System/System.h b/src/System/System.h new file mode 100644 index 00000000..7f0a1421 --- /dev/null +++ b/src/System/System.h @@ -0,0 +1,3 @@ +#pragma once +void restart(); +void shutdown(); \ No newline at end of file diff --git a/src/System/SystemTime.c b/src/System/SystemTime.c new file mode 100644 index 00000000..e879a83a --- /dev/null +++ b/src/System/SystemTime.c @@ -0,0 +1,52 @@ +#include"SystemTime.h" +#include"IO.h" + +long long TimeAtBoot = 0; +int readPit(void) { + unsigned count = 0; + cli(); + outportb(0x43,0b0000000); + count = inportb(0x40); + count |= inportb(0x40)<<8; + return count; +} +void setPit(unsigned count) { + cli(); + outportb(0x40,count&0xFF); // Low byte + outportb(0x40,(count&0xFF00)>>8); // High byte + return; +} + +int getSeconds(){ + int cmos_address = 0x70; + int cmos_data = 0x71; + outportb(cmos_address, 0x0); + int second = inportb(cmos_data); + second = (second & 0x0F) + ((second / 16) * 10); + return second; +} +int getMinutes(){ + int cmos_address = 0x70; + int cmos_data = 0x71; + outportb(cmos_address, 0x02); + int minute = inportb(cmos_data); + minute = (minute & 0x0F) + ((minute / 16) * 10); + return minute; +} +int getHours(){ + int cmos_address = 0x70; + int cmos_data = 0x71; + outportb(cmos_address, 0x04); + int hour = inportb(cmos_data); + hour = (hour & 0x0F) + ((hour / 16) * 10); + return hour; +} +void time_init(){ + TimeAtBoot = (getSeconds()+(getMinutes()*60)+(getHours()*3600)); +} +long long currentTime(){ + return (getSeconds()+(getMinutes()*60)+(getHours()*3600)); +} +long long getTimeFromBoot(){ + return (getSeconds()+(getMinutes()*60)+(getHours()*3600))-TimeAtBoot; +} \ No newline at end of file diff --git a/src/System/SystemTime.h b/src/System/SystemTime.h new file mode 100644 index 00000000..99af4ff6 --- /dev/null +++ b/src/System/SystemTime.h @@ -0,0 +1,7 @@ +#pragma once +void time_init(); +int getSeconds(); +int getMinutes(); +int getHours(); +long long getTimeFromBoot(); +long long currentTime(); \ No newline at end of file diff --git a/src/System/Time.asm b/src/System/Time.asm new file mode 100644 index 00000000..9a387d30 --- /dev/null +++ b/src/System/Time.asm @@ -0,0 +1 @@ +;Time.asm \ No newline at end of file diff --git a/src/Terminal-Runtime/Terminal-Runtime.c b/src/Terminal-Runtime/Terminal-Runtime.c new file mode 100644 index 00000000..e60351dc --- /dev/null +++ b/src/Terminal-Runtime/Terminal-Runtime.c @@ -0,0 +1,303 @@ +#include "Terminal-Runtime.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +void calc_init(); +void ImageViewr_init(char *fn); +int runSh(char *fn) +{ + if (fn[length(fn) - 1] == 'h' && fn[length(fn) - 2] == 's') + { + char *ft = (char *)new_str(length(readFile(fn))); + for (int i = 0; i < length(readFile(fn)); i++) + ft[i] = readFile(fn)[i]; + char *command = new_str(50); + int tempy = 0; + for (int i = 0; ft[i] != 0; i++) + { + if (ft[i] == '\n') + { + system(command); + command[0] = 0; + tempy = 0; + } + else + { + command[tempy] = ft[i]; + command[tempy + 1] = 0; + tempy++; + } + } + roll_back(50 + length(readFile(fn))); + return 1; + } + return 0; +} +int runFile(char *in) +{ + if (readFile(in)[0] != 0) + { + printC('\n'); + int *pro = (int *)new_str(length(readFile(in))); + for (int i = 0; i < length(readFile(in)); i++) + { + pro[i] = readFile(in)[i]; + } + execute_program((int *)pro); + roll_back(length(readFile(in))); + return 1; + } + return 0; +} +void compile(); +void system(char *command) +{ + setDefaultColor(0x1b); + if (0) + { + } + else if (equalS(command, "rename", 6)) + { + int dif = 0; + for (int i = 7; i < 40; i++) + { + if (command[i] == ' ') + { + dif = i - 1; + break; + } + } + char *to_name = new_str(32); + char *fn = new_str(32); + set((int *)fn, (int *)substring(command, 7, dif + 1)); + set((int *)to_name, (int *)substring(command, dif + 2, length(command))); + rename(fn, to_name); + } + else if (equalS(command, "cls", 3) || equalS(command, "clear", 4)) + { + clearScreen(); + setScreenColor(0x1f); + } + else if (equalS(command, "mex", 3)) + { + if (doesFileExists(substring(command, 4, length(command)))) + { + char *in = new_str(896); + set((int *)in, (int *)readFile(substring(command, 4, length(command)))); + compile(in); + roll_back(896); + } + else + printW("\nInput File doesn't exists"); + } + else if (equalS("edit", command, 4)) + { + printW("\nPress tab to exit\nType the text you want to write in file:\n"); + char *inputText = (char *)new_str(2048); + char tempC = 0; + for (int i = 0; (tempC = readChar()) != '\t'; i++) + { + if (tempC != '\b') + { + inputText[i] = tempC; + } + else if (i > 0) + { + inputText[i - 1] = 0; + i -= 2; + } + printC(tempC); + } + clearFile(substring(command, 5, length(command))); + writeFile(substring(command, 5, length(command)), inputText); + roll_back(2048); + } + else if (equalS(command, "echo", 4)) + { + printC('\n'); + for (int i = 5; command[i] != 0; i++) + { + printC(command[i]); + } + } + else if (equalS(command, "mk", 2)) + { + if (command[3] == 0) + { + printW("\ncannot make a file with empty file name"); + } + else if (!doesFileExists(substring(command, 3, 38))) + { + createFile(substring(command, 3, 38)); + writeFile(substring(command, 3, 38), "\0\0\0\0\0"); + } + else + { + printW("\nFile already exists"); + } + } + else if (equalS(command, "readf", 5)) + { + if (doesFileExists(substring(command, 6, 38))) + { + makeWindow(substring(command, 6, 38)); + printStringInWindow(readFile(substring(command, 6, 38))); + start_window_system(); + } + else + { + printW("\nFile does not exists"); + } + } + else if (equalS(command, "mem", 3)) + { + printC('\n'); + printW(toString(getMemPointer())); + } + else if (equalS(command, "del", 3)) + { + if (doesFileExists(substring(command, 4, 36))) + { + deleteFile(substring(command, 4, 36)); + } + else + { + printW("\nFile does not exists"); + } + } + else if ((doesFileExists(command) && runSh(command))) + { + } + else if (command[0] != 0 && doesFileExists(command) && command[length(command) - 1] == 'x' && command[length(command) - 2] == 'e') + { + runFile(command); + } + else if (equal(command, "ls")) + { + for (int i = 0; i < total_files(); i++) + { + printC('\n'); + printW(getFileNameAt(i)); + for (int j = 0; j < 20 - length(getFileNameAt(i)); j++) + { + printC(' '); + } + printW(toString(length(getFileContentAt(i)))); + printW(" Bytes"); + } + } + else if (equalS(command, "ascii", 5)) + { + printC('\n'); + for (int i = 0; i < 255; i++) + { + printW(toString(i)); + printW(" "); + printC(i); + printW(" "); + } + } + else if (equalS(command, "colors", 6)) + { + printC('\n'); + for (int i = 0; i < 16; i++) + { + printChar(219, i); + } + } + else if (equalS(command, "copy", 4)) + { + char *in = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + char *des = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + int f = 5; + int sec = 0; + for (int i = 5; command[i] != ' ' && command[i] != 0; i++) + f++; + set((int *)in, (int *)substring(command, 5, f)); + sec = f + 1; + set((int *)des, (int *)substring(command, sec, length(command))); + if (!doesFileExists(in)) + { + printW("\nInput file doesn't exists"); + return; + } + if (doesFileExists(des)) + { + printW("\nOutput file already exists"); + return; + } + copyFile(in, des); + } + else if (equalS(command, "restart", 7)) + { + restart(); + } + else if (equalS(command, "shutdown", 8)) + { + shutdown(); + } + else if (equalS(command, "read", 4)) + { + printW("\nPress Any key to continue..."); + readChar(); + } + else if (equalS(command, "help", 4)) + { + printW("\nRadical Kernel Version 2.0.0"); + printW("\nKernel Build: 1721"); + printW("\nCommands are:-\n"); + printW("cls\n"); + printW("echo\n"); + printW("mk\n"); + printW("del\n"); + printW("copy\n"); + printW("ls\n"); + printW("rename\n"); + printW("readf\n"); + printW("restart\n"); + printW("shutdown\n"); + printW("colors\n"); + printW("ascii\n"); + printW("time\n"); + printW("calc\n"); + printW("view\n"); + printW("mex\n"); + } + else if (equalS(command, "calc", 4)) + { + calc_init(); + } + else if (equalS(command, "view", 4)) + { + if (doesFileExists(substring(command, 5, length(command)))) + ImageViewr_init(substring(command, 5, length(command))); + else + printW("\nFile dosen't exists"); + } + else if (equalS("time", command, 4)) + { + printW("\nCurrent BIOS time is: "); + printW(toString(getHours())); + printC(':'); + printW(toString(getMinutes())); + printC(':'); + printW(toString(getSeconds())); + } + + else if (command[0] != 0) + { + printW("\n'"); + printW(command); + printW("'"); + printW(" is not recognized as an internal or external command,\noperable program or batch file."); + } + for (int i = 0; i < 100; i++) + command[i] = 0; + setDefaultColor(0x1f); +} \ No newline at end of file diff --git a/src/Terminal-Runtime/Terminal-Runtime.h b/src/Terminal-Runtime/Terminal-Runtime.h new file mode 100644 index 00000000..861e7581 --- /dev/null +++ b/src/Terminal-Runtime/Terminal-Runtime.h @@ -0,0 +1,3 @@ +#pragma once +void system(char * command); +int runSh(char * fn); \ No newline at end of file diff --git a/src/Timer/Timer.c b/src/Timer/Timer.c new file mode 100644 index 00000000..14e6698e --- /dev/null +++ b/src/Timer/Timer.c @@ -0,0 +1,8 @@ +#include"Timer.h" +#include +void Sleep(int seconds){ + for(int i = 0;i +int length(string abc){ + for(int i = 0;;i++) + if(abc[i]=='\0')return i; +} +string reverse(string in){ + string out = (char *)"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + int temp = 0; + for(int i = length(in)-1;i>-1;i--){ + out[temp] = in[i]; + temp++; + } + return out; +} +string toString(int val){ + if(val==0)return (string)"0"; + string out = (string)"\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + int base = 10; + char * buf = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + int i = 30; + for(; val && i ; --i, val /= base) + buf[i] = "0123456789abcdef"[val % base]; + out = &buf[i+1]; + return out; +} +int parseInt(string a){ + int n = length(a); + int out = 0; + int ae = 1; + for(int i = n-1;i>-1;i--){ + out+=(a[i]-'0')*ae; + ae*=10; + } + return out; +} +int max(int a,int b){ + if(a>b)return a; + else return b; +} +int equal(string a,string b){ + for(int i = 0;i +#include +#include +#include +#include +#include +void printLogo(); +extern int kmain(){ + screen_init(); + clearScreen(); + time_init(); + printCenter(2,"Welcome to",0x0b); + Screen->cursorY = 5; + printLogo(); + setCursorPosition(-1,-1); + printCenter(15,"Operating System",0x0c); + printCenter(17,"Press Any Key to start",0x09); + printCenter(24,"(C) Krish",0x0f); + readChar(); + clearScreen(); + shell_main(); + for(;;){} + return 0; +} \ No newline at end of file diff --git a/src/kernel_loader.asm b/src/kernel_loader.asm new file mode 100644 index 00000000..d1befc4c --- /dev/null +++ b/src/kernel_loader.asm @@ -0,0 +1,11 @@ +bits 32 + dd 0x1BADB002 + dd 0x0 + dd - 0x1BADB002 + +extern _kmain + cli + call _kmain + jmp $ + + diff --git a/src/kernel_loader2.asm b/src/kernel_loader2.asm new file mode 100644 index 00000000..5dc0cefd --- /dev/null +++ b/src/kernel_loader2.asm @@ -0,0 +1,12 @@ + +bits 32 + dd 0x1BADB002 + dd 0x0 + dd - 0x1BADB002 + +extern kmain + cli + call kmain + jmp $ + +