Add: program: words version 1
This commit is contained in:
Binary file not shown.
@@ -36,7 +36,7 @@ int kmain(int retvalue)
|
|||||||
|
|
||||||
// TODO: Grub modules to load programs
|
// TODO: Grub modules to load programs
|
||||||
|
|
||||||
//timer_install();
|
timer_install();
|
||||||
keyboard_install();
|
keyboard_install();
|
||||||
|
|
||||||
shell_install();
|
shell_install();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
#include "../libc/string.h"
|
#include "../libc/string.h"
|
||||||
|
#include "../programs/programs.h"
|
||||||
|
|
||||||
#define BUFFER_SIZE 256
|
#define BUFFER_SIZE 256
|
||||||
|
|
||||||
@@ -26,6 +27,10 @@ void shell_install()
|
|||||||
{
|
{
|
||||||
printf("%d", 4/0);
|
printf("%d", 4/0);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(input_buffer, "words") == 0)
|
||||||
|
{
|
||||||
|
program_words();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
printf("Unknown command %s\n", input_buffer);
|
printf("Unknown command %s\n", input_buffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,8 @@ void delay(int ticks);
|
|||||||
void keyboard_install();
|
void keyboard_install();
|
||||||
char keyboard_getchar();
|
char keyboard_getchar();
|
||||||
void shell_install();
|
void shell_install();
|
||||||
|
|
||||||
|
extern volatile unsigned long global_ticks;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "../libc/stdio.h"
|
#include "../libc/stdio.h"
|
||||||
|
|
||||||
int timer_ticks = 0;
|
volatile unsigned long global_ticks = 0;
|
||||||
|
|
||||||
void timer_handler()
|
void timer_handler()
|
||||||
{
|
{
|
||||||
timer_ticks++;
|
global_ticks++;
|
||||||
|
|
||||||
if(timer_ticks % 18 == 0)
|
|
||||||
{
|
|
||||||
puts("One second has passed\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_install()
|
void timer_install()
|
||||||
@@ -21,6 +16,6 @@ void timer_install()
|
|||||||
void delay(int ticks)
|
void delay(int ticks)
|
||||||
{
|
{
|
||||||
unsigned long eticks;
|
unsigned long eticks;
|
||||||
eticks = timer_ticks + ticks;
|
eticks = global_ticks + ticks;
|
||||||
while ((unsigned long)timer_ticks < eticks);
|
while (global_ticks < eticks);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#include "crypto.h"
|
||||||
|
|
||||||
|
int lcg(int seed)
|
||||||
|
{
|
||||||
|
int x = seed;
|
||||||
|
|
||||||
|
// Constants (ZX81 LCG)
|
||||||
|
int a = 75;
|
||||||
|
int c = 74;
|
||||||
|
long m = 65537;
|
||||||
|
|
||||||
|
for (int i=0; i<10; i++)
|
||||||
|
{
|
||||||
|
x = (a*x + c) % m;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int randint(int seed)
|
||||||
|
{
|
||||||
|
int x = lcg(seed);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|||||||
9
src/libc/crypto.h
Normal file
9
src/libc/crypto.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef CRYPTO_H
|
||||||
|
#define CRYPTO_H
|
||||||
|
|
||||||
|
#define RAND_MAX 1024
|
||||||
|
|
||||||
|
int lcg(int seed);
|
||||||
|
int randint(int seed);
|
||||||
|
|
||||||
|
#endif
|
||||||
6
src/programs/programs.h
Normal file
6
src/programs/programs.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef PROGRAMS_H
|
||||||
|
#define PROGRAMS_H
|
||||||
|
|
||||||
|
void program_words();
|
||||||
|
|
||||||
|
#endif
|
||||||
52
src/programs/words.c
Normal file
52
src/programs/words.c
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
#include "../libc/stdio.h"
|
||||||
|
#include "../libc/crypto.h"
|
||||||
|
#include "../kernel/system.h"
|
||||||
|
|
||||||
|
char* words[] =
|
||||||
|
{
|
||||||
|
"I", "us", "they", "my",
|
||||||
|
"a", "an", "is", "are", "for", "while", "not", "none", "yes", "no",
|
||||||
|
"absolutely", "addition", "additive", "afternoon", "architect", "ask",
|
||||||
|
"be", "blindfold", "brilliant", "boy", "brilliant", "bring", "buddy",
|
||||||
|
"career", "caterpillar", "change", "cheeky", "chop",
|
||||||
|
"decide", "demonstrate", "draw", "druggist",
|
||||||
|
"eagle", "ear", "effort", "evening",
|
||||||
|
"fabric", "famous", "fuse",
|
||||||
|
"generation", "generous", "girl", "gypsy", "grip",
|
||||||
|
"habit", "handsome", "helmet", "help", "horror",
|
||||||
|
"insist", "inventor", "itself", "ivory",
|
||||||
|
"jog", "joint", "joke", "judge",
|
||||||
|
"karate", "kebab", "kitchen",
|
||||||
|
"lamb", "lawnmower", "left", "lock",
|
||||||
|
"math", "medicine", "most",
|
||||||
|
"noodles", "nowadays", "nowhere",
|
||||||
|
"ocean", "older", "ounce",
|
||||||
|
"part", "pathetic", "pastime",
|
||||||
|
"quite", "quits", "quotation",
|
||||||
|
"race", "raise", "reality",
|
||||||
|
"safe", "scare", "screen",
|
||||||
|
"taught", "temple", "that", "this",
|
||||||
|
"unable", "unkind", "usual",
|
||||||
|
"velvet", "vivid", "vote",
|
||||||
|
"we", "warm", "watch",
|
||||||
|
"xylophone",
|
||||||
|
"yolk", "young", "your",
|
||||||
|
"zebra", "zodiac", "zucchini",
|
||||||
|
};
|
||||||
|
|
||||||
|
int words_size = sizeof(words)/sizeof(words[0]);
|
||||||
|
|
||||||
|
// Generates 5 random words
|
||||||
|
void program_words()
|
||||||
|
{
|
||||||
|
for (int i=0; i<10; i++)
|
||||||
|
{
|
||||||
|
int random = randint(global_ticks);
|
||||||
|
char* word = words[random%words_size];
|
||||||
|
//printf("Global ticks: %d\nRandom integer: %d\nWord: %s\n", global_ticks, random, word);
|
||||||
|
printf("%s ", word);
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
puts("\n");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user