Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lightning-speed authored Sep 9, 2021
1 parent 9efbe70 commit 0b41d6d
Show file tree
Hide file tree
Showing 47 changed files with 2,068 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/App32/Calculator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include<Util/string.h>
#include<Drivers/Screen.h>
#include<Drivers/Keyboard.h>
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: ");
}

}
}
20 changes: 20 additions & 0 deletions src/App32/ImageViewr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<Util/string.h>
#include<Drivers/Screen.h>
#include<Drivers/Keyboard.h>
#include<Graphics/Image.h>
#include<System/MemoryManager.h>
#include<Graphics/Graphics.h>
#include<FS/fs.h>
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(join("Image Viewr - ",fn));
set((int *)ftv,(int *)readFile(fn));
drawImage(40-ftv[0],12-ftv[1],ftv);
start_window_system();
}
89 changes: 89 additions & 0 deletions src/App32/Mex-Compiler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
char * process(char * in);
#include<Drivers/Screen.h>
#include<System/SystemTime.h>
#include<Util/string.h>
#include<Drivers/Keyboard.h>
#include<System/MemoryManager.h>
#include<FS/fs.h>
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<length(text);i++){
if(text[i]=='\n'){
total = join(total,process(command));
temp = 0;
command[0]=0;
}
else{
command[temp]=text[i];
command[temp+1]=0;
temp++;
}
}
total = join(total,"\r\0");
if(!doesFileExists("out.mex"))
createFile("out.mex");
writeFile("out.mex",total);
role_back(896);
}
char * process(char * in){
char * out = "\0\0\0\e\0";
if(equalS(in,"movn",4))out[0]=30;
if(equalS(in,"movr",4))out[0]=31;
if(equalS(in,"push",4))out[0]=32;
if(equalS(in,"popr",4))out[0]=33;
if(equalS(in,"cmdn",4))out[0]=34;
if(equalS(in,"addn",4))out[0]=35;
if(equalS(in,"addr",4))out[0]=36;
if(equalS(in,"subn",4))out[0]=37;
if(equalS(in,"subr",4))out[0]=38;
if(equalS(in,"jump",4))out[0]=39;
if(equalS(in,"jnzn",4))out[0]=40;
if(equalS(in,"smal",4))out[0]=41;
if(equalS(in,"bign",4))out[0]=42;
if(equalS(in,"equn",4))out[0]=43;
if(equalS(in,"inbn",4))out[0]=44;
if(equalS(in,"outb",4))out[0]=45;
int sp = 0;
for(int i = 5;i<length(in);i++)if(in[i]==' ')sp = i;
char * arg1 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
set((int *)arg1,(int *)substring(in,5,sp));
char * arg2 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
set((int *)arg2,(int *)substring(in,sp+1,length(in)));
if(arg1[0]<='9'&&arg1[0]>='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;
}
47 changes: 47 additions & 0 deletions src/Drivers/Keyboard.c
Original file line number Diff line number Diff line change
@@ -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<System/IO.h>
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)];
}
4 changes: 4 additions & 0 deletions src/Drivers/Keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
char readChar();
char * input();
char getChar();
85 changes: 85 additions & 0 deletions src/Drivers/Screen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include"Screen.h"
#include<System/IO.h>

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;i<Screen->cursorY+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);
}
18 changes: 18 additions & 0 deletions src/Drivers/Screen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#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);
22 changes: 22 additions & 0 deletions src/Drivers/idt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "idt.h"
#include<Util/types.h>
#define low_16(address) (uint16_t)((address) & 0xFFFF)
#define high_16(address) (uint16_t)(((address) >> 16) & 0xFFFF)

idt_gate_t idt[IDT_ENTRIES];
idt_register_t idt_reg;

void set_idt_gate(int n, uint32_t handler) {
idt[n].low_offset = low_16(handler);
idt[n].sel = KERNEL_CS;
idt[n].always0 = 0;
idt[n].flags = 0x8E;
idt[n].high_offset = high_16(handler);
}

void load_idt() {
idt_reg.base = (uint32_t) &idt;
idt_reg.limit = IDT_ENTRIES * sizeof(idt_gate_t) - 1;
/* Don't make the mistake of loading &idt -- always load &idt_reg */
asm volatile("lidt (%0)" : : "r" (&idt_reg));
}
34 changes: 34 additions & 0 deletions src/Drivers/idt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include<Util/types.h>


/* Segment selectors */
#define KERNEL_CS 0x08

/* How every interrupt gate (handler) is defined */
typedef struct {
uint16_t low_offset; /* Lower 16 bits of handler function address */
uint16_t sel; /* Kernel segment selector */
uint8_t always0;
/* First byte
* Bit 7: "Interrupt is present"
* Bits 6-5: Privilege level of caller (0=kernel..3=user)
* Bit 4: Set to 0 for interrupt gates
* Bits 3-0: bits 1110 = decimal 14 = "32 bit interrupt gate" */
uint8_t flags;
uint16_t high_offset; /* Higher 16 bits of handler function address */
} __attribute__((packed)) idt_gate_t;

/* A pointer to the array of interrupt handlers.
* Assembly instruction 'lidt' will read it */
typedef struct {
uint16_t limit;
uint32_t base;
} __attribute__((packed)) idt_register_t;

#define IDT_ENTRIES 256

void set_idt_gate(int n, uint32_t handler);

void load_idt();
Loading

0 comments on commit 0b41d6d

Please sign in to comment.