-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.c
More file actions
95 lines (86 loc) · 1.37 KB
/
kernel.c
File metadata and controls
95 lines (86 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stddef.h>
#include <stdint.h>
#include "uart.h"
void kernel_main(uint32_t r0, uint32_t r1, uint32_t atags)
{
uint8_t mem[256];
uint8_t j = 0;
uart_init();
uart_puts("DiOS version 0.0.1 (pre-alpha)\n");
while (1) {
char buffer[256];
uart_putc('$');
uart_ngets(255, buffer);
uint8_t i = 0;
while (buffer[i] != 0) {
switch (buffer[i]) {
case '+':
mem[j]++;
i++;
break;
case '-':
mem[j]--;
i++;
break;
case '>':
j++;
i++;
break;
case '<':
j--;
i++;
break;
case '.':
uart_putc(mem[j]);
i++;
break;
case ',':
mem[j] = uart_getc();
i++;
break;
case '|':
for (uint8_t k = 0; k < 255; k++)
mem[k] = 0;
i++;
break;
case 'p':
/* thank me later */
uart_printnum(mem[j]);
uart_putc('\n');
i++;
break;
case 'd':
for (uint8_t k = 0; k < 0xff; k++) {
uart_printnum(mem[k]);
if (((k+1) & 0x0f) == 0x00) {
uart_putc('\n');
} else {
uart_putc(' ');
}
}
uart_printnum(mem[0xff]);
uart_putc('\n');
i++;
break;
case ']':
if (mem[j] == 0) {
i++;
break;
}
i--;
uint8_t br = 1;
while (1) {
if (buffer[i] == '[') {
if (--br == 0) break;
} else if (buffer[i] == ']') {
br++;
}
i--;
}
break;
default:
i++;
}
}
}
}