Skip to content

Commit 5a921d3

Browse files
committed
v0.0.1
new commands + demo + README update + check the release notes if you care
1 parent 0a0e12e commit 5a921d3

File tree

10 files changed

+87
-25
lines changed

10 files changed

+87
-25
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ I watched Star Wars Episode 9 opening night in theaters and Klaud was the main c
2020
* nasm
2121
* qemu-system-x86
2222

23-
### From Release
23+
### Download From Release
2424
* download disk image and sh file from release
2525
* run run.sh
2626

27-
### From Source
27+
### Download From Source
2828
* run make toolchain
2929
* run make
3030
* run run.sh

demo.mp4

2.43 MB
Binary file not shown.

release_notes/v0.0.1.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Version 0.0.1
2+
3+
Added features:
4+
* klaud street dice game added
5+
* added echo command
6+
* better itoa function (supports negative numbers now)
7+
* better random number generator (only input is highest and lowest number)
8+
* added demo

src/kernel/arch/i686/interupt_handler.asm

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,5 @@ common_interrupt_handler: ; the common parts of the generic interr
4545
; return to the code that got interrupted
4646
iret
4747

48-
no_error_code_interrupt_handler 33 ; create handler for interrupt 1 (keyboard)
49-
no_error_code_interrupt_handler 14 ; create handler for interrupt 2 (paging)
50-
no_error_code_interrupt_handler 0 ; create handler for interrupt 3 (timer)
48+
no_error_code_interrupt_handler 33 ; for keyboard
49+
no_error_code_interrupt_handler 0 ; for timer

src/kernel/interrupts.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
#include "libs/strings.h"
1111
#include "arch/i686/serial_port.h"
1212
#include "keyboard.h"
13-
//#include "paging.h"
1413

1514
#define INTERRUPTS_DESCRIPTOR_COUNT 256
16-
#define INTERRUPTS_KEYBOARD 33
17-
#define INTERRUPTS_PAGING 14
15+
#define INTERRUPTS_KEYBOARD 33
1816
#define INTERRUPTS_TIMER 0
1917

2018
struct IDTDescriptor idt_descriptors[INTERRUPTS_DESCRIPTOR_COUNT];
@@ -43,9 +41,8 @@ void interrupts_init_descriptor(int index, unsigned int address)
4341

4442
void interrupts_install_idt()
4543
{
46-
interrupts_init_descriptor(INTERRUPTS_KEYBOARD, (unsigned int) interrupt_handler_33);
47-
interrupts_init_descriptor(INTERRUPTS_PAGING, (unsigned int) interrupt_handler_14);
4844
interrupts_init_descriptor(INTERRUPTS_TIMER,(unsigned int) interrupt_handler_0);
45+
interrupts_init_descriptor(INTERRUPTS_KEYBOARD, (unsigned int) interrupt_handler_33);
4946

5047
idt.address = (int) &idt_descriptors;
5148
idt.size = sizeof(struct IDTDescriptor) * INTERRUPTS_DESCRIPTOR_COUNT;
@@ -103,10 +100,9 @@ void interrupt_handler(__attribute__((unused)) struct cpu_state cpu, unsigned in
103100
pic_acknowledge(interrupt);
104101

105102
break;
106-
107-
case INTERRUPTS_PAGING:
108-
break;
109103
case INTERRUPTS_TIMER:
104+
printf("penis");
105+
pic_acknowledge(interrupt);
110106
break;
111107
default:
112108
break;

src/kernel/libs/asciiArt.c

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void help() {
3838
"Commands:\r\n"
3939
"klaud: Everything starts with Klaud.\r\n"
4040
"klaud ascii: prints ascii picture of Klaud.\r\n"
41+
"klaud echo <phrase>: returns whatever you say back\r\n"
42+
"klaud dice <bet value (int)>: gamble all your money away by playing dice with klaud\r\n"
4143
"klaud live-slug-reaction: ascii art of the 'live slug reaction' meme\r\n"
4244
"klaud shrine: Klaud shrine in ascii art for your Klaud worshiping needs\r\n"
4345
"klaud rizz: rizz up Klaud and see what he says\r\n"

src/kernel/libs/haikuu.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void makeLine(int numSyl,int * struc) {
1717
int syl = numSyl;
1818
int i;
1919
for (i=0;syl!=0;i++) {
20-
int newWord = rand(33)%(((syl)+1)-1) + 1;
20+
int newWord = randint(syl,1);
2121
if (newWord != 0) {
2222
syl = syl-newWord;
2323
struc[i] = abs(newWord);
@@ -48,7 +48,7 @@ void makeLine(int numSyl,int * struc) {
4848
}
4949
}
5050
//printf("\n");
51-
int randNum = abs(rand(32)%((2+1)-0) + 0);
51+
int randNum = abs(randint(2,0));
5252
//printf("%d",randNum);
5353
if (j%2==0) {printf("%s ",noun[ops[randNum]]);}
5454
else {printf("%s ",verb[ops[randNum]]);}
@@ -63,7 +63,7 @@ void makeLine(int numSyl,int * struc) {
6363
l++;
6464
}
6565
}
66-
int randNum = abs(rand(32)%((2+1)-0) + 0);
66+
int randNum = abs(randint(2,0));
6767
//printf("%d",randNum);
6868
printf("%s ",noun[ops[randNum]]);
6969
}

src/kernel/libs/stdio.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ void append(char s[], char n) {
350350
s[len+1] = '\0';
351351
}
352352

353-
// random number from 1 to 10
353+
// random number
354354

355355
int rand(uint32_t *state) {
356356
// Precomputed parameters for Schrage's method
@@ -370,6 +370,10 @@ int rand(uint32_t *state) {
370370
return *state = result;
371371
}
372372

373+
int randint(int hi, int lo) {
374+
return rand(32)%((hi+1)-lo) + lo;
375+
}
376+
373377
char * slice_str(const char * str, char * buffer, int start, int end)
374378
{
375379
int j = 0;

src/kernel/libs/strings.c

+22-6
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,26 @@ int convert(char s[])
6161
return num;
6262
}
6363

64-
char * itoa (int val, int base) {
65-
static char buf[32] = {0};
66-
int i = 30;
67-
for(; val && i ; --i, val /= base)
68-
buf[i] = "0123456789abcdef"[val % base];
69-
return &buf[i+1];
64+
char *itoa(int nbr, int base)
65+
{
66+
static char rep[] = "0123456789";
67+
static char buff[65];
68+
char *ptr;
69+
int neg;
70+
71+
ptr = &buff[64];
72+
*ptr = '\0';
73+
neg = nbr;
74+
if (nbr < 0)
75+
nbr *= -1;
76+
if (nbr == 0)
77+
*--ptr = rep[nbr % 10];
78+
while (nbr != 0)
79+
{
80+
*--ptr = rep[nbr % 10];
81+
nbr /= 10;
82+
}
83+
if (neg < 0)
84+
*--ptr = '-';
85+
return (ptr);
7086
}

src/kernel/main.c

+39-2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,16 @@ void __attribute__((section(".entry"))) start(uint16_t bootDrive)
6969
for (;;);
7070
}
7171

72-
// look at all these if statements. very disgusting
72+
// user input function. This could rank in my top 10 ugliest pieces of code to date. I'm
73+
// sure as hell not fixing it lmao
7374

7475
void user_input(char *input) {
7576
int len = strlen(input);
7677
char buffer[len + 1];
7778
static char rizz[6];
7879
static char dice[6];
80+
static char umoney[6];
81+
static char kmoney[6];
7982
if (strcmp(rizz,"True") == 0) {
8083
int score = rizzScore(input);
8184
printf("\n");
@@ -89,6 +92,29 @@ void user_input(char *input) {
8992
printf(" he said in his native language\n");
9093
memcpy(rizz,"False",strlen("False")+1);
9194
printf("> ");
95+
} else if (strcmp(dice,"True") == 0) {
96+
if (strcmp(input,"exit") != 0) {
97+
int score = convert(umoney);
98+
int bscore = convert(kmoney);
99+
int mroll = randint(6,1) + randint(6,1);
100+
int kroll = randint(6,1) + randint(6,1);
101+
if (mroll >= kroll) {
102+
score = score + convert(input);
103+
bscore = bscore - convert(input);
104+
} else {
105+
score = score - convert(input);
106+
bscore = bscore + convert(input);
107+
}
108+
memcpy(umoney,itoa(score,10),6);
109+
memcpy(kmoney,itoa(bscore,10),6);
110+
printf("your roll: %d, klaud roll: %d\n",mroll,kroll);
111+
printf("your money: %s, klaud money: %s\n",umoney,kmoney);
112+
printf("Type 'exit' to leave the game\nPlace bet>");
113+
} else {
114+
memcpy(dice,"False",strlen("False")+1);
115+
clrscr();
116+
printf("> ");
117+
}
92118
} else if (strlen(input) <= 4) {
93119
printf("Every command starts with klaud, try again");
94120
printf("\n> ");
@@ -168,12 +194,23 @@ void user_input(char *input) {
168194
"Chewbacca was the person who convinced Klaud to join the Resistance"
169195
};
170196
int arrMax = *(&factList + 1) - factList;
171-
int randNum = rand(32)%((arrMax+1)-0) + 0;
197+
int randNum = randint(arrMax,0);
172198
if (randNum == 12) {randNum = 11;} // im not sure why this works but oh well
173199
printf("%s\n> ",factList[randNum]);
174200
} else if (strcmp(slice_str(input,buffer,0,9),"klaud plot")==0) {
175201
graph(slice_str(input,buffer,11,len),22);
176202
printf("> ");
203+
} else if (strcmp(slice_str(input,buffer,0,9),"klaud echo")==0) {
204+
printf("'%s' Klaud said in his native language",slice_str(input,buffer,11,len));
205+
printf("\n> ");
206+
} else if (strcmp(slice_str(input,buffer,0,9),"klaud dice")==0) {
207+
memcpy(dice,"True",strlen("True")+1);
208+
memcpy(umoney,"500",strlen("500")+1);
209+
memcpy(kmoney,"500",strlen("500")+1);
210+
clrscr();
211+
klaud_ascii();
212+
printf("your money:%s, klaud money: %s",umoney,kmoney);
213+
printf("\nPlace bet>");
177214
} else {
178215
printf("You said: %s, which is not a certified Klaud command. Use the klaud --help command.",input);
179216
printf("\n> ");

0 commit comments

Comments
 (0)