Simple Operating System
test.c
Go to the documentation of this file.
1 
5 #include <io.h>
6 #include <file.h>
7 #include <conio.h>
8 #include <mouse.h>
9 #include <graphics.h>
10 #include <string.h>
11 #include <stdlib.h>
12 
13 __start int main() {
14  char a[] = "Greetings from C disk! Parameters:";
15  Byte parameters = 0x80;
16  printf("%s\"%s\"\n", a, parameters);
17  Byte disk[701];
18 
19  //read and print file data.txt
20  FILE *file = NULL;
21  file = open("data.txt", "");
22  if(file == NULL) {
23  puts("ERROR file cannot be opened\n");
24  return 404;
25  }
26  printf("Size: %i; ID: %i\n", file->size, file->id);
27  size_t size = read(disk, 12, file);
28  printf("Readed: %iB: ", size);
29  for(size_t i = 0; i < size; i++)
30  putc(disk[i]);
31  printf("\nSize: %i; ID: %i\n", size, file->id);
32 
33  size = read(disk, 700, file);
34  if(size != 700) {
35  puts("ERROR file cannot be readed\n");
36  return 403;
37  }
38  for(size_t i = 0; i < size; i++)
39  putc(disk[i]);
40  puts("END");
41  putc('\n');
42 
43  write("Hello!!! data.txt, I've overwritten it!", 40, file);
44  create("HELLO.txt", 2);
45 
46  getc();
47  // test colors
48  for(int i = 0; i < 16; i++) {
49  for(int j = 0; j < 16; j++)
50  cputc('X', j + i * 16, 2);
51  putc('\n');
52  }
53  //test interrupts
54  asm("int 0x20"
55  ::"a"(0xff00));
56  asm("int 0x21"
57  ::"a"(0xff00));
58 
59  //test string operations
60  char L0[8] = "123456";
61  char L1[] = "Napis1\n";
62  puts(L1);
63  printf("Napis2\npis456=%s\n", strncpy(L0, strchr(L1, 'p'), 3));
64 
65  char test2[] = "cdYou shouldn't see this";
66  char test1[] = "ab";
67  strcpy(test2, test1);
68  printf("ab=%s", test2);
69 
70  //test graphics
71  getc();
72  setVideoMode(0x10);
73  Position pos = {0, 0};
74 
75  for(int i = 0; i < 10000; i++) {
76  pos.x += i;
77  pos.y = i % 250;
78  pos.x %= 250;
79  writePixel(pos, Green);
80  }
81 
82  for(size_t i = 0; i < SIZE_X; i++) {
83  pos.x = i;
84  pos.y = SIZE_Y - i;
85  writePixel(pos, Cyan);
86  }
87  getc();
88  int ret = mouseInitialize();
89  if(ret < 0)return ret;
90  setVideoMode(ColorMode);
91  Key key;
92  Color color = Red;
93  do {
94  printf("%i %i %i %i", mouse.x, mouse.y, mouse.status, (Color)color);
95  Position pos = {mouse.x, mouse.y};
96  if(mouse.status == LeftPress) {
97  color--;
98  udelay(100000);
99  }
100  if(mouse.status == RightPress) {
101  color++;
102  udelay(100000);
103  }
104  writePixel(pos, color);
105 
106  key = getKeyBuff();
107  if(key.available == 1) {
108  key = getc();
109  putc(key.character);
110  }
111  else
112  putc('x');
113  printf(" \r");
114  udelay(10000);
115  } while(key.character != 'a');
116  setVideoMode(0x2);
117  setColorPalette(DarkGrey);
118 
119  return -1234;
120 }
121 char b[] = "DISK 1234567890";
Console input output control.
void cputc(char c, Color color, Byte times)
Color put character.
Definition: conio.h:102
void setVideoMode(Mode mode)
Set the video mode of screen.
Definition: conio.h:41
File IO.
int create(const int filename, size_t size)
Create file.
Definition: file.h:77
int write(int buf, size_t size, FILE *stream)
Write to file.
Definition: file.h:66
FILE * open(int filename, int mode)
Open file.
Definition: file.h:33
int read(int buf, size_t size, FILE *stream)
Read from file.
Definition: file.h:53
Draw pixels in graphics mode.
void writePixel(Position pos, Color color)
Draw single pixel.
Definition: graphics.h:30
Standard input output library.
Key getKeyBuff(void)
Get key from buffer.
Definition: io.h:96
Key getc(void)
Wait for key in buffer, get it and clear buffer.
Definition: io.h:83
void printf(const int str,...)
C-like printf function.
Definition: io.h:72
void puts(const int string)
Put string.
Definition: io.h:42
void putc(Byte character)
Put character.
Definition: io.h:31
__start void main()
Definition: kernel.c:131
Get mouse position and status, to use mouse call mouseInitialize()
int mouseInitialize()
Initialize mouse, by default mouse in enabled.
Definition: mouse.h:80
Standard libary.
void udelay(unsigned long usecs)
Delay usecs microseconds.
Definition: stdlib.h:29
Simple string handling.
int strncpy(int destination, int source, size_t num)
Copy num Bytes from source to destination until \0 appears.
Definition: string.h:131
char * strcpy(char *destination, const char *source)
Copy from source to destination until \0 appears.
Definition: string.h:113
const char * strchr(const char *str, int character)
Find first appearance of character.
Definition: string.h:64
Information about file.
Definition: file.h:20
Byte id
Definition: file.h:21
Word size
Definition: file.h:22
Position on screen.
Definition: graphics.h:16
#define NULL
pointer to NULL
Definition: types.h:22
#define __start
Must be before main function of program to put this function as first in binary file.
Definition: types.h:35
Key information, got from buffer.
Definition: io.h:14