Small adjustments, pi program #5
@@ -39,7 +39,7 @@ Shows all of the available commands, which are explained here.
|
|||||||
|
|
||||||
#### `panic`
|
#### `panic`
|
||||||
|
|
||||||
Triggers a kernel panic by trying to divide four by zero.
|
Triggers a kernel panic by reserved exception.
|
||||||
|
|
||||||
#### `words`
|
#### `words`
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ Options:
|
|||||||
- `<nothing>` will default to `PRIMES_MAX` (a million)
|
- `<nothing>` will default to `PRIMES_MAX` (a million)
|
||||||
- `<integer>` will compute primes up to that number
|
- `<integer>` will compute primes up to that number
|
||||||
|
|
||||||
#### `rainbow`
|
#### `rainbow <string>`
|
||||||
|
|
||||||
Asks for text and then outputs it with different vibrant colors.
|
Asks for text and then outputs it with different vibrant colors.
|
||||||
|
|
||||||
@@ -77,11 +77,11 @@ A brainfuck interpreter with every instruction and default tape size (30k cells)
|
|||||||
|
|
||||||
Gets system uptime from the timer in ticks. Ticks are incremented at a rate of 18.222Hz (18.222 ticks per second).
|
Gets system uptime from the timer in ticks. Ticks are incremented at a rate of 18.222Hz (18.222 ticks per second).
|
||||||
|
|
||||||
#### `echo`
|
#### `echo <string>`
|
||||||
|
|
||||||
The classic echo command, that outputs your input.
|
The classic echo command, that outputs your input.
|
||||||
|
|
||||||
#### `sysinfo`
|
#### `sysinfo [option]`
|
||||||
|
|
||||||
Outputs information about the current system (CPU and RAM).
|
Outputs information about the current system (CPU and RAM).
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ Options:
|
|||||||
- `<nothing>` will show basic info about the CPUid and lower/upper memory.
|
- `<nothing>` will show basic info about the CPUid and lower/upper memory.
|
||||||
- `-v` will output the CPUID, lower/upper memory, and the memory map.
|
- `-v` will output the CPUID, lower/upper memory, and the memory map.
|
||||||
|
|
||||||
#### `conway`
|
#### `conway [option]`
|
||||||
|
|
||||||
A classic Game of Life implementation with standard rules and 100 generations.
|
A classic Game of Life implementation with standard rules and 100 generations.
|
||||||
|
|
||||||
@@ -98,14 +98,18 @@ Options:
|
|||||||
- `-g` will spawn a classic glider
|
- `-g` will spawn a classic glider
|
||||||
- `-l` will spawn a lightweight spaceship
|
- `-l` will spawn a lightweight spaceship
|
||||||
|
|
||||||
#### `rot13`
|
#### `rot13 <string>`
|
||||||
|
|
||||||
Encode a string using the rot13 cipher.
|
Encode a string using the rot13 cipher.
|
||||||
|
|
||||||
#### `morse`
|
#### `morse <string>`
|
||||||
|
|
||||||
Convert a string to its morse equivalent.
|
Convert a string to its morse equivalent.
|
||||||
|
|
||||||
#### `cowsay`
|
#### `cowsay <string>`
|
||||||
|
|
||||||
Makes a cow speak!
|
Makes a cow speak!
|
||||||
|
|
||||||
|
#### `pi <terms>`
|
||||||
|
|
||||||
|
Computes Pi up to a couple of digits using the Leibniz series; takes one integer argument, the number of terms of the series to compute.
|
||||||
|
|||||||
@@ -16,13 +16,35 @@
|
|||||||
#define MAX_ARGS 64
|
#define MAX_ARGS 64
|
||||||
|
|
||||||
// Splash screen: esthetic stuff.
|
// Splash screen: esthetic stuff.
|
||||||
|
|
||||||
char* motd[] =
|
char* motd[] =
|
||||||
{
|
{
|
||||||
|
"I should be root, really.",
|
||||||
|
"Not watching you!",
|
||||||
"Now in 2D!",
|
"Now in 2D!",
|
||||||
"Supercalifragilisticexpialidocious!",
|
"Supercalifragilisticexpialidocious!",
|
||||||
"Tylko jedno w glowie mam!",
|
"Tylko jedno w glowie mam!",
|
||||||
|
"Greetings, magic poppy!",
|
||||||
|
"I'm stuck in this kernel's shell, get me out!",
|
||||||
|
"And now, solve that equation!",
|
||||||
|
"Powered by TCC Incorporated.",
|
||||||
|
"Compiled at 69, CoquaineBaule Ave.",
|
||||||
|
"Shouldn't we be, uh, doing something?",
|
||||||
|
"We are the florists, we pick the plants!",
|
||||||
|
"Lalalalala, I pick the plants!",
|
||||||
|
"Woah, we're half-way there...",
|
||||||
|
"The CROU will never die!",
|
||||||
|
"Technoblade never dies!",
|
||||||
|
"Hi. My name is Guitar.",
|
||||||
|
"space station No. 9",
|
||||||
|
"May the orange juice be with you !",
|
||||||
|
"Bloody grated carrots!",
|
||||||
|
"Good night, kiddos...",
|
||||||
|
"I like trains",
|
||||||
|
"I fear planes",
|
||||||
|
"Bruteforce.exe",
|
||||||
|
"Ohayogozaimasu!",
|
||||||
};
|
};
|
||||||
|
|
||||||
int motd_size = sizeof(motd)/sizeof(motd[0]);
|
int motd_size = sizeof(motd)/sizeof(motd[0]);
|
||||||
|
|
||||||
bool do_splash = true;
|
bool do_splash = true;
|
||||||
@@ -113,6 +135,7 @@ void shell_install()
|
|||||||
register_command("time", program_time);
|
register_command("time", program_time);
|
||||||
register_command("read", program_read);
|
register_command("read", program_read);
|
||||||
register_command("reboot", program_reboot);
|
register_command("reboot", program_reboot);
|
||||||
|
register_command("pi", program_pi);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ void program_uptime()
|
|||||||
|
|
||||||
void program_help()
|
void program_help()
|
||||||
{
|
{
|
||||||
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\n");
|
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Panic
|
// Panic
|
||||||
|
|||||||
34
src/programs/pi.c
Normal file
34
src/programs/pi.c
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Program for Pi computation using Leibniz series
|
||||||
|
// Author: xamidev
|
||||||
|
// Licensed under the Unlicense. See the repo below.
|
||||||
|
// https://github.com/xamidev/blankos
|
||||||
|
|
||||||
|
#include "../libc/stdio.h"
|
||||||
|
#include "../libc/string.h"
|
||||||
|
|
||||||
|
void program_pi(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
printf("Usage: %s <terms>\n", argv[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double pi = 0.0;
|
||||||
|
int terms = atoi(argv[1]);
|
||||||
|
|
||||||
|
for (int i=0; i<terms; i++)
|
||||||
|
{
|
||||||
|
double term = 1.0/(2*i+1);
|
||||||
|
if (i%2 == 0)
|
||||||
|
{
|
||||||
|
pi += term;
|
||||||
|
} else {
|
||||||
|
pi -= term;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pi *= 4;
|
||||||
|
|
||||||
|
printf("%f\n", pi);
|
||||||
|
}
|
||||||
@@ -31,9 +31,12 @@ void program_primes(int argc, char* argv[])
|
|||||||
|
|
||||||
for (long long x=0; x<primes_max; x++)
|
for (long long x=0; x<primes_max; x++)
|
||||||
{
|
{
|
||||||
if (isPrime(x))
|
if (isPrime(x) && x != 3301)
|
||||||
{
|
{
|
||||||
printf("%d ", x);
|
printf("%d ", x);
|
||||||
|
} else if(x == 3301)
|
||||||
|
{
|
||||||
|
colorputs("3301 ", red, black);
|
||||||
}
|
}
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ void get_meminfo(unsigned int multiboot_info_address);
|
|||||||
void program_conway();
|
void program_conway();
|
||||||
void program_cowsay();
|
void program_cowsay();
|
||||||
void cowsay(); // Splash screen
|
void cowsay(); // Splash screen
|
||||||
|
void program_pi();
|
||||||
|
|
||||||
// Ciphers
|
// Ciphers
|
||||||
void program_rot13();
|
void program_rot13();
|
||||||
|
|||||||
Reference in New Issue
Block a user