Files
xv6-custom-os/maze.c
iDunnoDev c23d669858 Added draw menu, vars and additional functions needed for it
Added some functionality to the procdump to show the current console and parent pids of processes for debugging
Added var to clearconsole that enables the internal lock if one wasnt prelocked before hand
Fixed issue where race conditions would stop the title from drawing by drawing it to the buffer too
Fixed issue where the maze function was spamming the conswrite and cons lock by changing it to send an entire line instead of 1 char at a time
2022-12-23 00:48:57 +00:00

87 lines
2.1 KiB
C

#include "types.h"
#include "user.h"
uint rngnumber(void)
{
// Take from http://stackoverflow.com/questions/1167253/implementation-of-rand
static unsigned int z1 = 12345, z2 = 12345, z3 = 12345, z4 = 12345;
unsigned int b;
b = ((z1 << 6) ^ z1) >> 13;
z1 = ((z1 & 4294967294U) << 18) ^ b;
b = ((z2 << 2) ^ z2) >> 27;
z2 = ((z2 & 4294967288U) << 2) ^ b;
b = ((z3 << 13) ^ z3) >> 21;
z3 = ((z3 & 4294967280U) << 7) ^ b;
b = ((z4 << 3) ^ z4) >> 12;
z4 = ((z4 & 4294967168U) << 13) ^ b;
return (z1 ^ z2 ^ z3 ^ z4) / 2;
}
int rngrange(int start, int end, int seed)
{
if (end < start)
{
int swtmp = start;
start = end;
end = swtmp;
}
int range = end - start + 1;
return (rngnumber() + seed) % (range) + start;
}
int main(int argc, char *argv[]) {
int lines = 1000;
int seed = getpid();
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-l") == 0)
{
lines = atoi(argv[i + 1]);
}
else if (strcmp(argv[i], "-s") == 0)
{
seed = atoi(argv[i + 1]);
}
}
cls();
greeting();
printf(1, "Start Maze\n");
char mazeline[80];
for (int y = 0; y < lines; y++)
{
for (int x = 0; x < 79; x++)
{
if (x == 0)
{
mazeline[x] = ' ';
continue;
}
int rndnum = rngrange(188, 197, seed);
switch (rndnum)
{
case 188:
rndnum = 32;
break;
case 189:
rndnum = 179;
break;
case 190:
rndnum = 180;
break;
}
// This is causing huge lock ups due to having to lock the console for each character
// is what im guessing so instead write it to a per line buffer then print
//printf(1, "%c", rndnum);
mazeline[x] = rndnum;
}
printf(1, "%s\n", mazeline);
sleep(10);
}
printf(1, "Maze Ended\n");
exit();
}