Operating System
stone.c
Go to the documentation of this file.
1 __asm__("jmpl $0, $stone\n");
2 
3 #include "../../include/utilities.h"
4 #include "stone.h"
5 #include "../../include/stdio.h"
6 #define DELAY (5 * 1e5)
7 int getKbHit();
8 void checkBound();
9 
10 int x;
11 int y;
12 int deltax;
13 int deltay;
14 int stone() {
15  // return 0;
16  x = _X;
17  y = _Y;
18  deltax = 1;
19  deltay = 1;
20  uint8_t style = 0;
21 
22  clear_screen();
23  while(1) {
24  int key = getKbHit();
25  if (key == 'q') return key;
26 
27  int delay = DELAY;
28  while ((--delay) >= 0) continue;
29 
30  draw_str(" ", y, x);
31  x += deltax;
32  y += deltay;
33 
34  checkBound();
35  draw_str_style("A", y, x, style & 15);
36  style++;
37  }
38 }
39 
40 int getKbHit() {
41  int try = kbhit();
42  if (try) {
43  int key = readkb();
44  return key;
45  }
46  return 0;
47 }
48 void checkBound() {
49  if (x <= LEFT_B) deltax = 1;
50  if (x >= RIGHT_B) deltax = -1;
51  if (y <= UP_B) deltay = 1;
52  if (y >= DOWN_B) deltay = -1;
53 }
void clear_screen()
uint8_t style
Definition: timeout.c:16
static int16_t draw_str(char const *str, int row, int col)
Definition: stdio.h:104
int stone()
Definition: stone.c:14
int x
Definition: stone.c:10
int deltay
Definition: stone.c:13
int y
Definition: stone.c:11
int kbhit()
#define DELAY
Definition: stone.c:6
void checkBound()
Definition: stone.c:48
int deltax
Definition: stone.c:12
static int16_t draw_str_style(char const *str, int row, int col, uint8_t style)
Definition: stdio.h:120
__asm__("jmpl $0, $stone\)
int readkb()
int getKbHit()
Definition: stone.c:40