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 25, 2021
1 parent a5cab66 commit 4492075
Show file tree
Hide file tree
Showing 45 changed files with 1,566 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("Image Viewr");
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);
roll_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();
93 changes: 93 additions & 0 deletions src/Drivers/Screen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#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);
}
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;
}
}
20 changes: 20 additions & 0 deletions src/Drivers/Screen.h
Original file line number Diff line number Diff line change
@@ -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();
9 changes: 9 additions & 0 deletions src/FS/default_files.h
Original file line number Diff line number Diff line change
@@ -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");
}
Loading

0 comments on commit 4492075

Please sign in to comment.