Skip to content

Commit 82ee1d7

Browse files
committed
v0.0.2
check out the release notes. Big updates this time!
1 parent 5a921d3 commit 82ee1d7

File tree

10 files changed

+215
-15
lines changed

10 files changed

+215
-15
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ I watched Star Wars Episode 9 opening night in theaters and Klaud was the main c
77
## Features
88

99
* double stage bootloader
10+
* BIOS boot
11+
* FAT file system (shawty got a fatty)
1012
* gdt, interrupt handler
1113
* keyboard input and printed output
1214
* kernel with commands
13-
* built in x86 assembly and C using gcc
15+
* built in x86 assembly and C with gcc as compiler
1416

1517
## How to use
1618

release_notes/v0.0.2.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Version 0.0.2
2+
3+
Added features:
4+
* Added '!' as a useable key
5+
* Added factorial in calculator
6+
* Finally added frame buffer so backspace actually works (a lot more work than you think)
7+
* Updated README and main.c in kernel

src/kernel/interrupts.c

+20-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
#include "libs/strings.h"
1111
#include "arch/i686/serial_port.h"
1212
#include "keyboard.h"
13+
#include "libs/disp.h"
1314

1415
#define INTERRUPTS_DESCRIPTOR_COUNT 256
1516
#define INTERRUPTS_KEYBOARD 33
1617
#define INTERRUPTS_TIMER 0
18+
unsigned int BUFFER_COUNT;
1719

1820
struct IDTDescriptor idt_descriptors[INTERRUPTS_DESCRIPTOR_COUNT];
1921
struct IDT idt;
@@ -68,34 +70,50 @@ void interrupt_handler(__attribute__((unused)) struct cpu_state cpu, unsigned in
6870
switch (interrupt){
6971
case INTERRUPTS_KEYBOARD:
7072
scan_code = keyboard_read_scan_code();
73+
//printf("%d",scan_code);
7174
if (scan_code == 28) {
7275
printf("\n");
76+
fb_write('\n',BUFFER_COUNT);
7377
user_input(key_buffer);
7478
memcpy(prevComm,key_buffer,strlen(key_buffer)+1);
7579
key_buffer[0] = '\0';
7680
} else if (scan_code == 1) {
7781
printf("\n> ");
7882
key_buffer[0] = '\0';
83+
scroll(1);
7984
} else if (scan_code == 72) {
8085
memcpy(key_buffer,prevComm,strlen(key_buffer)+1);
86+
move_curs(strlen(key_buffer));
8187
printf("%s",key_buffer);
8288
} else if (shift == 1) {
8389
if (scan_code==13) {scan_code = 78;}
8490
else if (scan_code==6) {scan_code = 84;}
8591
else if (scan_code==7) {scan_code = 85;}
8692
else if (scan_code==9) {scan_code = 86;}
93+
else if (scan_code==2) {scan_code = 87;}
94+
else if (scan_code==43) {scan_code = 88;}
8795
ascii = keyboard_scan_code_to_ascii(scan_code);
8896
append(key_buffer, ascii);
89-
printf("%c",ascii);
97+
fb_write(ascii,BUFFER_COUNT);
98+
//printf("%c",ascii);
9099
shift = 0;
91100
} else if (scan_code == 14) {
92101
backspace(key_buffer);
102+
BUFFER_COUNT--;
103+
fb_clear(BUFFER_COUNT);
93104
} else if (scan_code == 42) {
94105
shift = 1;
106+
} else if (scan_code == 77) {
107+
108+
} else if (scan_code == 75) {
109+
95110
} else if (scan_code <= KEYBOARD_MAX_ASCII) {
96111
ascii = keyboard_scan_code_to_ascii(scan_code);
97112
append(key_buffer, ascii);
98-
printf("%c",ascii);
113+
fb_write(ascii,BUFFER_COUNT);
114+
//putc(ascii);
115+
BUFFER_COUNT++;
116+
//printf("%c",ascii);
99117
}
100118
pic_acknowledge(interrupt);
101119

src/kernel/keyboard.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ char keyboard_scan_code_to_ascii(unsigned char scan_code)
2222
0x0, ' ', 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // 56 - 63
2323
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, '7', // 64 - 71
2424
'8', '9', '-', '4', '5', '6', '+', '1', // 72 - 79
25-
'2', '3', '0', '.', '%','^','*', // 80 - 83 plus extras
25+
'2', '3', '0', '.', '%','^','*','!' // 80 - 83 plus extras
2626
};
2727

2828
return ascii[scan_code];

src/kernel/libs/asciiArt.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "stdio.h"
2+
#include "libs/disp.h"
23

34
void klaud_ascii() {
45
puts(
@@ -16,6 +17,7 @@ void klaud_ascii() {
1617
" *,*,**#**,,**((#&&#( \r\n"
1718
" ,*,*,.....,**/#((//#( \r\n"
1819
);
20+
scroll(14);
1921
}
2022

2123
void flowers() {
@@ -29,8 +31,8 @@ void flowers() {
2931
" | |/ | / | / |/ \r\n"
3032
" |// |/// |// |/// |/// \r\n"
3133
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \r\n"
32-
3334
);
35+
scroll(8);
3436
}
3537

3638
void help() {
@@ -57,4 +59,5 @@ void help() {
5759
"Up arrow: prints the previous command into current line\r\n"
5860
"Shift: same usage as normal (uppercase not supported yet)"
5961
);
62+
scroll(20);
6063
}

src/kernel/libs/disp.c

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "disp.h"
2+
3+
static char *fb = (char *)0x000B8000;
4+
char curr_x[6];
5+
6+
void fb_move_cursor(unsigned short pos) {
7+
i686_outb(FB_COMMAND_PORT, FB_HIGH_BYTE_COMMAND);
8+
i686_outb(FB_DATA_PORT, ((pos >> 8) & 0x00FF));
9+
i686_outb(FB_COMMAND_PORT, FB_LOW_BYTE_COMMAND);
10+
i686_outb(FB_DATA_PORT, pos & 0x00FF);
11+
}
12+
13+
void reset() {
14+
memcpy(curr_x,itoa(3),strlen(itoa(100))+1);
15+
}
16+
17+
void move_curs(int x) {
18+
memcpy(curr_x,itoa(convert(curr_x)+x),strlen(itoa(curr_x+x))+1);
19+
}
20+
21+
void scroll(int x) {
22+
int c_x = convert(curr_x);
23+
c_x = (c_x + (80*x) - c_x%80)+2;
24+
//printf("%d",c_x);
25+
if (c_x >= 1842) {
26+
//printf("peen");
27+
memcpy(curr_x,itoa(1842+80),strlen(itoa(c_x))+1);
28+
} else {
29+
memcpy(curr_x,itoa(c_x),strlen(itoa(c_x))+1);
30+
}
31+
}
32+
33+
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg) {
34+
int c_x = convert(curr_x);
35+
if (c == '\n') {
36+
//c_x = c_x + 80 - c_x%80;
37+
scroll(1);
38+
//printf("%d",i);
39+
} else if (c == '$') {
40+
fb[i-2] = ' ';
41+
fb[i] = ((fg & 0x0F) << 4) | (bg & 0x0F);
42+
c_x--;
43+
memcpy(curr_x,itoa(c_x),strlen(itoa(c_x))+1);
44+
} else {
45+
fb[i] = c;
46+
fb[i + 1] = ((fg & 0x0F) << 4) | (bg & 0x0F);
47+
c_x++;
48+
memcpy(curr_x,itoa(c_x),strlen(itoa(c_x))+1);
49+
}
50+
}
51+
52+
void fb_write(char c, unsigned int i){
53+
int c_x = convert(curr_x);
54+
//printf("%d",c_x);
55+
fb_write_cell(c_x*2, c, BLACK, LIGHT_GREY);
56+
fb_move_cursor(c_x+1);
57+
}
58+
59+
void fb_clear(unsigned int i){
60+
int c_x = convert(curr_x);
61+
fb_write_cell(c_x*2+1, '$', BLACK, BLACK);
62+
}

src/kernel/libs/disp.h

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#ifndef INCLUDE_FRAMEBUFFER_H
2+
#define INCLUDE_FRAMEBUFFER_H
3+
4+
#pragma once
5+
#include "arch/i686/io.h"
6+
7+
/* The I/O ports */
8+
#define FB_COMMAND_PORT 0x3D4
9+
#define FB_DATA_PORT 0x3D5
10+
11+
/* The I/O port commands */
12+
#define FB_HIGH_BYTE_COMMAND 14
13+
#define FB_LOW_BYTE_COMMAND 15
14+
15+
/* Frame buffer supported color value */
16+
#define BLACK 0
17+
#define BLUE 1
18+
#define LIGHT_GREY 7
19+
20+
// Make a pixel(2 bytes), background is always black, a is a char, b is foreground color
21+
#define LOAD_MEMORY_ADDRESS 0xC0000000
22+
#define SCREEN ((uint16_t*)(LOAD_MEMORY_ADDRESS + 0xB8000))
23+
#define WIDTH 80
24+
#define HEIGHT 25
25+
#define DEFAULT_COLOR LIGHT_GREY
26+
#define PAINT(a,b) (((b & 0xF) << 8) | (a & 0xFF))
27+
28+
// Get pixel
29+
#define PIXEL(x, y) SCREEN[y * 80 + x]
30+
31+
/** fb_move_cursor:
32+
* Moves the cursor of the framebuffer to the given position
33+
*
34+
* @param pos The new position of the cursor
35+
*/
36+
void fb_move_cursor(unsigned short pos);
37+
38+
/** fb_write_cell:
39+
* Writes a character with the given foreground and background to position i
40+
* in the framebuffer.
41+
*
42+
* @param i The location in the framebuffer
43+
* @param c The character
44+
* @param fg The foreground color
45+
* @param bg The background color
46+
*/
47+
void fb_write_cell(unsigned int i, char c, unsigned char fg, unsigned char bg);
48+
49+
/** write:
50+
* writes the contents of the buffer buf of length len to the screen
51+
*
52+
* @param c character that needs to be written to screen
53+
* @param i number of total characters written on the framebuffer
54+
*/
55+
void fb_write(char c, unsigned int i);
56+
57+
/** clear:
58+
* clears the previous content of the buffer and move the cursor back
59+
*
60+
* @param i number of total characters written on the framebuffer
61+
*/
62+
void fb_clear(unsigned int i);
63+
64+
#endif

src/kernel/libs/math.c

+27-3
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,45 @@ int pow(int one, int two) {
1818
return ans;
1919
}
2020

21+
// function for 4 function calculator
22+
int factorial(int x) {
23+
int ans = 1;
24+
for (int i=1;i<=x;i++)
25+
ans *= i;
26+
return ans;
27+
}
28+
2129
// function for 4 function calculator
2230

2331
int calc(char * str) {
2432
char *start = str;
2533
int ans = 0;
2634
char lastOp;
27-
char opList[7] = {'+','-','/','*','%','^'};
35+
char opList[7] = {'+','-','/','*','%','^','!'};
2836
int i=0; // makes sure the first number doesn't do an operation on the number before that (0)
2937
for(;*str;str++) {
3038
// I hate continuous if/else if statements TODO fix this shit
3139
if(*str == '+') {
3240
*str = '\0';
3341
ans = ans + convert(start);
42+
if (i == 0) {ans = convert(start);}
43+
//printf("%d\n%d\n",ans,convert(start));
3444
*str = '+';
3545
start = str + 1;
3646
lastOp = *str;
47+
i++;
3748
} else if (*str == '-') {
3849
*str = '\0';
39-
ans = ans - convert(start);
50+
ans = ans-convert(start);
4051
if (i == 0) {ans = convert(start);}
4152
*str = '-';
4253
start = str + 1;
4354
lastOp = *str;
4455
i++;
4556
} else if (*str == '*') {
4657
*str = '\0';
47-
if (i == 0) {ans = 1;}
4858
ans = convert(start) * ans;
59+
if (i == 0) {ans = convert(start);}
4960
*str = '*';
5061
start = str + 1;
5162
lastOp = *str;
@@ -75,15 +86,28 @@ int calc(char * str) {
7586
start = str + 1;
7687
lastOp = *str;
7788
i++;
89+
} else if (*str == '!') {
90+
*str = '\0';
91+
ans = factorial(convert(start));
92+
*str = '!';
93+
start = str + 1;
94+
lastOp = *str;
95+
i++;
7896
}
7997
}
8098
// catches last numbers
99+
//printf("%d\n",ans);
81100
if (lastOp == '+') {ans = ans + convert(start);}
82101
else if (lastOp == '-') {ans = ans - convert(start);}
83102
else if (lastOp == '*') {ans = ans * convert(start);}
84103
else if (lastOp == '/') {ans = ans / convert(start);}
85104
else if (lastOp == '%') {ans = ans % convert(start);}
86105
else if (lastOp == '^') {ans = pow(ans,convert(start));}
106+
if (lastOp == '!') {
107+
if (i > 1) {
108+
ans = factorial(ans);
109+
}
110+
}
87111
return ans;
88112
}
89113

src/kernel/libs/stdio.c

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void clrscr()
5555
g_ScreenX = 0;
5656
g_ScreenY = 0;
5757
setcursor(g_ScreenX, g_ScreenY);
58+
reset();
5859
}
5960

6061
void changeColor(const uint8_t color) {

0 commit comments

Comments
 (0)