#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <conio.h>
#include "os.h"
#include "opaque.h"
#include <stdio.h>
#include "Xos.h"
#include "msdos.h"
#include "funcs.h"

#define CLIENT_TSR

extern void start_network(const char *);
extern void kbd_finit(const char *);
char *net_glue = 0;
u_char *bios = 0;

void
OsInit()
{
    static Bool been_here = FALSE;
    char *path;
    char fname[256];
    char *x11env;

#ifdef zero_debug
    s = 0L;
    *s++ = 0xEA;
    *(unsigned long *)s = (unsigned long)jmpZero;
#endif

    x11env = getenv("X11");
    if (!x11env)
	FatalError("X11 environment variable not set.\n");

    kbd_finit(x11env);

    if (!been_here) {
	srand(clock());
#ifdef notdef
	((struct overlay *)&bios)->seg = get_real_window(0, 0x1000);
	if (((struct overlay *)&bios)->seg == 0) {
	    FatalError("Can't get BIOS window\n");
	}
#else
	bios = 0;	//selector to first 0x1000 bytes of mem ?
#endif
	if (!net_glue || strchr(net_glue, '\\') == 0) {
	    if (!net_glue)
		net_glue = "NET.NET";
	    strcpy(fname, x11env);
	    path = fname + strlen(fname);
	    *path++ = '\\';
	    strcpy(path, net_glue);
	    if (!strchr(path, '.'))
		strcat(path, ".NET");
	    path = fname;
	} else
	    path = net_glue;
	start_network(path);
	been_here = TRUE;
    }

    OsInitColors();
}
