af7bc6500fb11598d468ffddd0d78013f96e2588
[bootcensus] / src / kmain.c
1 /*
2 pcboot - bootable PC demo/game kernel
3 Copyright (C) 2018  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY, without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #include <stdio.h>
19 #include <ctype.h>
20 #include "segm.h"
21 #include "intr.h"
22 #include "keyb.h"
23 #include "timer.h"
24 #include "contty.h"
25
26 void set_mode13h(void);
27 void logohack(void);
28
29 void pcboot_main(void)
30 {
31         init_segm();
32         init_intr();
33         kb_init();
34         con_init();
35
36         /* initialize the timer */
37         init_timer();
38
39         enable_intr();
40
41         printf("PCBoot kernel initialized\n");
42
43         for(;;) {
44                 int c;
45
46                 halt_cpu();
47                 while((c = kb_getkey()) >= 0) {
48                         if(c >= KB_F1 && c <= KB_F12) {
49                                 set_mode13h();
50                                 logohack();
51                         }
52                         if(isprint(c)) {
53                                 printf("key: %d '%c'       \n", c, (char)c);
54                         } else {
55                                 printf("key: %d            \n", c);
56                         }
57                 }
58                 if((nticks % 250) == 0) {
59                         printf("ticks: %ld\r", nticks);
60                 }
61         }
62 }