1/* Nethack as a whole is licensed under a GPL license.
2   Please refer to LICENSE_GPL.txt for details.
3
4   Source files were modified to be compatible with the RefOS build system and to disable features
5   that RefOS didn't fully support. Changes occurred on October 24, 2014.
6*/
7
8#include <stdio.h>
9#include <assert.h>
10#include <refos-io/stdio.h>
11#include <refos/refos.h>
12
13#define REFOS_NETHACK_WIZARD_MODE 0
14
15int
16has_colors()
17{
18    return 1;
19}
20
21char _argv0[] = "fileserv/nethack";
22#if REFOS_NETHACK_WIZARD_MODE
23char _argv1[] = "-D";
24#endif
25
26int
27main(int argc, char **argv)
28{
29    /* Future Work 3:
30       How the selfloader bootstraps user processes needs to be modified further. Changes were
31       made to accomodate the new way that muslc expects process's stacks to be set up when
32       processes start, but the one part of this that still needs to changed is how user processes
33       find their system call table. Currently the selfloader sets up user processes so that
34       the selfloader's system call table is used by user processes by passing the address of the
35       selfloader's system call table to the user processes via the user process's environment
36       variables. Ideally, user processes would use their own system call table.
37    */
38
39    uintptr_t address = strtoll(getenv("SYSTABLE"), NULL, 16);
40    refos_init_selfload_child(address);
41    refos_stdio_translate_stdin_cr = true;
42    refos_initialise();
43    printf("RefOS nethack.\n");
44    setenv("PWD", "fileserv/", true);
45
46#if REFOS_NETHACK_WIZARD_MODE
47    char *_argv[] = {_argv0, _argv1};
48    int _argc = 2;
49#else
50    char *_argv[] = {_argv0 };
51    int _argc = 1;
52#endif
53
54    nethack_main(_argc, _argv);
55}
56