Xyris  0.5
Apps Namespace Reference

Functions

void testAnimation ()
 
void find_primes (void)
 
void show_primes (void)
 
void spinner (void)
 

Function Documentation

◆ find_primes()

void Apps::find_primes ( void  )

Starts a task to find prime numbers.

Definition at line 27 of file primes.cpp.

28 {
29  for (prime_current = 2; prime_current < PRIME_MAX_SQRT; prime_current++) {
30  if (!map.Test(prime_current)) continue;
31  for (size_t j = prime_current * prime_current; j < PRIME_MAX; j += prime_current) {
32  map.Reset(j);
33  }
34  }
35 }

◆ show_primes()

void Apps::show_primes ( void  )

Starts a task to display number of primes found by find_primes.

Definition at line 37 of file primes.cpp.

38 {
39  do {
40  tasks_nano_sleep(1000ULL * 1000 * 1000);
41  size_t pct = (prime_current * 100) / PRIME_MAX_SQRT;
42  Console::printf("\e[s\e[23;0fComputing primes: %%%zu\e[u", pct);
43  } while (prime_current < PRIME_MAX_SQRT);
44 
45  size_t count = 0;
46  for (size_t i = 2; i < PRIME_MAX; i++) {
47  count += map.Test(i);
48  }
49  Console::printf("\e[s\e[23;0fFound %zu primes between 2 and %u.\e[u", count, PRIME_MAX);
50 }
+ Here is the call graph for this function:

◆ spinner()

void Apps::spinner ( void  )

Starts a spinner in an infinite loop.

Definition at line 16 of file spinner.cpp.

16  {
17  Console::printf("\n");
18  int i = 0;
19  const char spinnay[] = { '|', '/', '-', '\\' };
20  while (true) {
21  // Display a spinner to know that we're still running.
22  Console::printf("\e[s\e[24;0f%c\e[u", spinnay[i]);
23  i = (i + 1) % sizeof(spinnay);
24  asm volatile("hlt");
25  }
26 }
+ Here is the call graph for this function:

◆ testAnimation()

void Apps::testAnimation ( )

Run a simple animation.

Definition at line 16 of file animation.cpp.

17 {
18  int x = 10;
19  while (1) {
20  if (x > 250)
21  x = 10;
22 
24  //background
25  Graphics::putrect(0,0,280,280,0x00FFFF);
26  x+=10;
27  //snake
28  Graphics::putrect(x,10,10,10,0xFF0000);
29  //apple
30  Graphics::putrect(50,30,10,10,0xFFFF00);
32  }
33 }
+ Here is the call graph for this function:
PRIME_MAX_SQRT
#define PRIME_MAX_SQRT
Definition: primes.cpp:20
Graphics::swap
void swap()
Swap the data on backbuffer to memory video buffer and show in the screen.
Definition: graphics.cpp:93
tasks_nano_sleep
void tasks_nano_sleep(uint64_t time)
Sleep for a given period of time (in nanoseconds).
Definition: tasks.cpp:506
Graphics::resetDoubleBuffer
void resetDoubleBuffer()
Fill the backbuffer with '0'.
Definition: graphics.cpp:86
PRIME_MAX
#define PRIME_MAX
Definition: primes.cpp:21
Console::printf
int printf(const char *fmt,...)
Definition: console.cpp:273
Graphics::putrect
void putrect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color)
Draws and fills a rectangle of a given width and height, and color at the provided coordinates.
Definition: graphics.cpp:71