Subversion Repositories SvarDOS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
28 mv_fox 1
/*
2
 * SVAROG386 INSTALL
3
 * COPYRIGHT (C) 2016 MATEUSZ VISTE
42 mv_fox 4
 *
5
 * http://svarog386.sf.net
28 mv_fox 6
 */
7
 
8
#include <dos.h>
30 mv_fox 9
#include <direct.h>  /* mkdir() */
28 mv_fox 10
#include <stdio.h>   /* printf() and friends */
11
#include <stdlib.h>  /* system() */
12
#include <string.h>  /* memcpy() */
13
#include <unistd.h>
42 mv_fox 14
 
15
#include "kitten\kitten.h"
16
 
53 mv_fox 17
#include "cdrom.h"
28 mv_fox 18
#include "input.h"
19
#include "video.h"
20
 
42 mv_fox 21
 
29 mv_fox 22
/* color scheme (color, mono) */
23
static unsigned short COLOR_TITLEBAR[2] = {0x7000,0x7000};
24
static unsigned short COLOR_BODY[2] = {0x1700,0x0700};
25
static unsigned short COLOR_SELECT[2] = {0x7000,0x7000};
26
static unsigned short COLOR_SELECTCUR[2] = {0x1F00,0x0700};
28 mv_fox 27
 
29 mv_fox 28
/* mono flag */
29
static int mono = 0;
28 mv_fox 30
 
47 mv_fox 31
/* how much disk space does Svarog386 require (in MiB) */
32
#define SVAROG_DISK_REQ 8
28 mv_fox 33
 
47 mv_fox 34
 
28 mv_fox 35
/* reboot the computer */
36
static void reboot(void) {
37
  void ((far *bootroutine)()) = (void (far *)()) 0xFFFF0000L;
38
  int far *rstaddr = (int far *)0x00400072L; /* BIOS boot flag is at 0040:0072 */
39
  *rstaddr = 0x1234; /* 0x1234 = warm boot, 0 = cold boot */
40
  (*bootroutine)(); /* jump to the BIOS reboot routine at FFFF:0000 */
41
}
42
 
42 mv_fox 43
 
44
/* an NLS wrapper around video_putstring() */
45
static void putstringnls(int y, int x, unsigned short attr, int nlsmaj, int nlsmin, char *s) {
46
  s = kittengets(nlsmaj, nlsmin, s);
47
  video_putstring(y, x, attr, s);
48
}
49
 
50
 
51
#define LDEC(x,y) (((unsigned short)x << 8) | (unsigned short)y)
52
/* provides codepage and country files required by lang */
53
static int getnlscp(char *lang, int *egafile) {
54
  unsigned short l;
55
  l = lang[0];
56
  l <<= 8;
57
  l |= lang[1];
58
  switch (l) {
59
    case LDEC('E','N'):
60
      *egafile = 0;
61
      return(437);
62
    case LDEC('P','L'):
63
      *egafile = 10;
64
      return(991);
65
  }
66
  *egafile = 0;
67
  return(437);
68
}
69
 
70
 
28 mv_fox 71
static int menuselect(int ypos, int xpos, int height, char **list) {
72
  int i, offset = 0, res = 0, count, width = 0;
73
  /* count how many languages there is */
74
  for (count = 0; list[count] != NULL; count++) {
75
    int len = strlen(list[count]);
76
    if (len > width) width = len;
77
  }
78
 
79
  /* if xpos negative, means 'center out' */
80
  if (xpos < 0) xpos = 39 - (width >> 1);
81
 
29 mv_fox 82
  video_putchar(ypos, xpos+width+2, COLOR_SELECT[mono], 0xBF);         /*       \ */
83
  video_putchar(ypos, xpos-1, COLOR_SELECT[mono], 0xDA);               /*  /      */
84
  video_putchar(ypos+height-1, xpos-1, COLOR_SELECT[mono], 0xC0);      /*  \      */
85
  video_putchar(ypos+height-1, xpos+width+2, COLOR_SELECT[mono], 0xD9);/*      /  */
86
  video_putcharmulti(ypos, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
87
  video_putcharmulti(ypos+height-1, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
88
  video_putcharmulti(ypos+1, xpos-1, COLOR_SELECT[mono], 0xB3, height - 2, 80);
89
  video_putcharmulti(ypos+1, xpos+width+2, COLOR_SELECT[mono], 0xB3, height - 2, 80);
28 mv_fox 90
 
91
  for (;;) {
92
    int key;
93
    /* list of selectable items */
94
    for (i = 0; i < height - 2; i++) {
95
      if (i + offset == res) {
29 mv_fox 96
        video_putchar(ypos + 1 + i, xpos, COLOR_SELECTCUR[mono], 16);
97
        video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECTCUR[mono], 17);
28 mv_fox 98
        video_movecursor(ypos + 1 + i, xpos);
29 mv_fox 99
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECTCUR[mono], list[i + offset], width);
28 mv_fox 100
      } else if (i + offset < count) {
29 mv_fox 101
        video_putchar(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ');
102
        video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECT[mono], ' ');
103
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECT[mono], list[i + offset], width);
28 mv_fox 104
      } else {
29 mv_fox 105
        video_putcharmulti(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ', width+2, 1);
28 mv_fox 106
      }
107
    }
108
    key = input_getkey();
109
    if (key == 0x0D) { /* ENTER */
110
      return(res);
111
    } else if (key == 0x148) { /* up */
33 mv_fox 112
      if (res > 0) {
113
        res--;
114
        if (res < offset) offset = res;
115
      }
28 mv_fox 116
    } else if (key == 0x150) { /* down */
33 mv_fox 117
      if (res+1 < count) {
118
        res++;
119
        if (res > offset + height - 3) offset = res - (height - 3);
120
      }
121
    } else if (key == 0x147) { /* home */
122
      res = 0;
123
      offset = 0;
124
    } else if (key == 0x14F) { /* end */
125
      res = count - 1;
126
      if (res > offset + height - 3) offset = res - (height - 3);
28 mv_fox 127
    } else if (key == 0x1B) {  /* ESC */
128
      return(-1);
33 mv_fox 129
    } else {
130
      char buf[8];
131
      sprintf(buf, "0x%02X ", key);
132
      video_putstring(1, 0, COLOR_BODY[mono], buf);
28 mv_fox 133
    }
134
  }
135
}
136
 
137
static void newscreen(void) {
138
  int x;
42 mv_fox 139
  char *title;
140
  title = kittengets(0, 0, "SVAROG386 INSTALLATION");
29 mv_fox 141
  for (x = 0; x < 80; x++) video_putchar(0, x, COLOR_TITLEBAR[mono], ' ');
42 mv_fox 142
  video_putstring(0, 40 - (strlen(title) >> 1), COLOR_TITLEBAR[mono], title);
29 mv_fox 143
  video_clear(COLOR_BODY[mono], 80);
36 mv_fox 144
  video_movecursor(25,0);
28 mv_fox 145
}
146
 
147
static int selectlang(char *lang) {
148
  int choice;
42 mv_fox 149
  int x;
150
  char *msg;
28 mv_fox 151
  char *code;
152
  char *langlist[] = {
153
    "English\0EN",
154
    "French\0FR",
155
    "German\0DE",
156
    "Italian\0IT",
157
    "Polish\0PL",
158
    "Russian\0RU",
159
    "Slovenian\0SL",
160
    "Spanish\0ES",
161
    "Turkish\0TR",
162
    NULL
163
  };
164
 
165
  newscreen();
42 mv_fox 166
  msg = kittengets(1, 0, "Welcome to Svarog386");
167
  x = 40 - (strlen(msg) >> 1);
168
  video_putstring(4, x, COLOR_BODY[mono], msg);
169
  video_putcharmulti(5, x, COLOR_BODY[mono], '=', strlen(msg), 1);
49 mv_fox 170
  putstringnls(8, -1, COLOR_BODY[mono], 1, 1, "Please select your language from the list below:");
36 mv_fox 171
  choice = menuselect(10, -1, 12, langlist);
28 mv_fox 172
  if (choice < 0) return(-1);
173
  /* write short language code into lang */
174
  for (code = langlist[choice]; *code != 0; code++);
175
  memcpy(lang, code + 1, 2);
176
  lang[2] = 0;
177
  return(0);
178
}
179
 
180
 
181
/* returns 0 if installation must proceed, non-zero otherwise */
182
static int welcomescreen(void) {
183
  char *choice[] = {"Install Svarog386 to disk", "Quit to DOS", NULL};
42 mv_fox 184
  choice[0] = kittengets(0, 1, choice[0]);
185
  choice[1] = kittengets(0, 2, choice[1]);
28 mv_fox 186
  newscreen();
42 mv_fox 187
  putstringnls(4, 1, COLOR_BODY[mono], 2, 0, "You are about to install Svarog386: a free, MSDOS-compatible operating system");
188
  putstringnls(5, 1, COLOR_BODY[mono], 2, 1, "based on the FreeDOS kernel. Svarog386 targets 386+ computers and comes with a");
189
  putstringnls(6, 1, COLOR_BODY[mono], 2, 2, "variety of third-party applications.");
190
  putstringnls(8, 1, COLOR_BODY[mono], 2, 3, "WARNING: If your PC has another operating system installed, this other system");
191
  putstringnls(9, 1, COLOR_BODY[mono], 2, 4, "         might be unable to boot once Svarog386 is installed.");
192
  return(menuselect(13, -1, 4, choice));
28 mv_fox 193
}
194
 
195
 
33 mv_fox 196
/* returns 1 if drive is removable, 0 if not, -1 on error */
197
static int isdriveremovable(int drv) {
28 mv_fox 198
  union REGS r;
33 mv_fox 199
  r.x.ax = 0x4408;
200
  r.h.bl = drv;
28 mv_fox 201
  int86(0x21, &r, &r);
33 mv_fox 202
  /* CF set on error, AX set to 0 if removable, 1 if fixed */
203
  if (r.x.cflag != 0) return(-1);
204
  if (r.x.ax == 0) return(1);
205
  return(0);
28 mv_fox 206
}
207
 
208
 
35 mv_fox 209
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid */
210
static int disksize(int drv) {
28 mv_fox 211
  long res;
212
  union REGS r;
213
  r.h.ah = 0x36; /* DOS 2+ get free disk space */
214
  r.h.dl = drv;
215
  int86(0x21, &r, &r);
216
  if (r.x.ax == 0xffffu) return(-1); /* AX set to FFFFh if drive invalid */
49 mv_fox 217
  res = r.x.ax;  /* sectors per cluster */
218
  res *= r.x.dx; /* dx contains total clusters, bx contains free clusters */
219
  res *= r.x.cx; /* bytes per sector */
220
  res >>= 20;    /* convert bytes to MiB */
221
  return(res);
35 mv_fox 222
}
223
 
224
 
225
/* returns 0 if disk is empty, non-zero otherwise */
226
static int diskempty(int drv) {
227
  unsigned int rc;
228
  int res;
229
  char buff[8];
230
  struct find_t fileinfo;
231
  sprintf(buff, "%c:\\*.*", 'A' + drv - 1);
232
  rc = _dos_findfirst(buff, _A_NORMAL | _A_SUBDIR | _A_HIDDEN | _A_SYSTEM, &fileinfo);
233
  if (rc == 0) {
234
    res = 1; /* call successfull means disk is not empty */
28 mv_fox 235
  } else {
35 mv_fox 236
    res = 0;
28 mv_fox 237
  }
35 mv_fox 238
  /* _dos_findclose(&fileinfo); */ /* apparently required only on OS/2 */
28 mv_fox 239
  return(res);
240
}
241
 
242
 
243
static int preparedrive(void) {
33 mv_fox 244
  int driveremovable;
36 mv_fox 245
  int selecteddrive = 3; /* hardcoded to 'C:' for now */
246
  int cselecteddrive;
35 mv_fox 247
  int ds;
36 mv_fox 248
  char buff[128];
249
  cselecteddrive = 'A' + selecteddrive - 1;
28 mv_fox 250
  for (;;) {
251
    newscreen();
33 mv_fox 252
    driveremovable = isdriveremovable(selecteddrive);
253
    if (driveremovable < 0) {
49 mv_fox 254
      char *list[] = { "Create a partition automatically", "Run the FDISK partitioning tool", "Quit to DOS", NULL};
42 mv_fox 255
      list[0] = kittengets(0, 3, list[0]);
256
      list[1] = kittengets(0, 4, list[1]);
257
      list[2] = kittengets(0, 2, list[2]);
258
      sprintf(buff, kittengets(3, 0, "ERROR: Drive %c: could not be found. Perhaps your hard disk needs to be"), cselecteddrive);
259
      video_putstring(4, 2, COLOR_BODY[mono], buff);
260
      putstringnls(5, 2, COLOR_BODY[mono], 3, 1, "       partitioned first. Please create at least one partition on your");
261
      putstringnls(6, 2, COLOR_BODY[mono], 3, 2, "       hard disk, so Svarog386 can be installed on it. Note, that");
47 mv_fox 262
      sprintf(buff, kittengets(3, 3, "       Svarog386 requires at least %d MiB of available disk space."), SVAROG_DISK_REQ);
42 mv_fox 263
      video_putstring(7, 2, COLOR_BODY[mono], buff);
264
      putstringnls(9, 2, COLOR_BODY[mono], 3, 4, "You can use the FDISK partitioning tool for creating the required partition");
265
      putstringnls(10, 2, COLOR_BODY[mono], 3, 5, "manually, or you can let the installer partitioning your disk");
266
      putstringnls(11, 2, COLOR_BODY[mono], 3, 6, "automatically. You can also abort the installation to use any other");
267
      putstringnls(12, 2, COLOR_BODY[mono], 3, 7, "partition manager of your choice.");
33 mv_fox 268
      switch (menuselect(14, -1, 5, list)) {
269
        case 0:
270
          system("FDISK /AUTO");
271
          break;
272
        case 1:
273
          video_clear(0x0700, 0);
274
          video_movecursor(0, 0);
275
          system("FDISK");
276
          break;
277
        case 2:
278
          return(-1);
279
      }
28 mv_fox 280
      newscreen();
42 mv_fox 281
      putstringnls(11, 10, COLOR_BODY[mono], 3, 8, "Your computer will reboot now.");
282
      putstringnls(12, 10, COLOR_BODY[mono], 0, 5, "Press any key...");
33 mv_fox 283
      input_getkey();
28 mv_fox 284
      reboot();
285
      return(-1);
33 mv_fox 286
    } else if (driveremovable > 0) {
42 mv_fox 287
      sprintf(buff, kittengets(3, 9, "ERROR: Drive %c: is a removable device. Installation aborted."), cselecteddrive);
36 mv_fox 288
      video_putstring(9, 2, COLOR_BODY[mono], buff);
42 mv_fox 289
      putstringnls(11, 2, COLOR_BODY[mono], 0, 5, "Press any key...");
33 mv_fox 290
      return(-1);
28 mv_fox 291
    }
33 mv_fox 292
    /* if not formatted, propose to format it right away (try to create a directory) */
36 mv_fox 293
    sprintf(buff, "%c:\\SVWRTEST.123", cselecteddrive);
53 mv_fox 294
    if (mkdir(buff) == 0) {
295
      rmdir(buff);
296
    } else {
28 mv_fox 297
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
42 mv_fox 298
      list[0] = kittengets(0, 6, list[0]);
299
      list[1] = kittengets(0, 2, list[1]);
300
      sprintf(buff, kittengets(3, 10, "ERROR: Drive %c: seems to be unformated."), cselecteddrive);
36 mv_fox 301
      video_putstring(7, 2, COLOR_BODY[mono], buff);
42 mv_fox 302
      putstringnls(8, 2, COLOR_BODY[mono], 3, 11, "       Do you wish to format it?");
28 mv_fox 303
      if (menuselect(12, -1, 4, list) != 0) return(-1);
304
      video_clear(0x0700, 0);
305
      video_movecursor(0, 0);
42 mv_fox 306
      sprintf(buff, "FORMAT %c: /Q /U /Z:seriously /V:SVAROG386", cselecteddrive);
36 mv_fox 307
      system(buff);
28 mv_fox 308
      continue;
309
    }
33 mv_fox 310
    /* check total disk space */
35 mv_fox 311
    ds = disksize(selecteddrive);
47 mv_fox 312
    if (ds < SVAROG_DISK_REQ) {
42 mv_fox 313
      sprintf(buff, kittengets(3, 12, "ERROR: Drive %c: is not big enough!"), cselecteddrive);
314
      video_putstring(9, 2, COLOR_BODY[mono], buff);
47 mv_fox 315
      sprintf(buff, kittengets(3, 13, "      Svarog386 requires a disk of at least %d MiB."), SVAROG_DISK_REQ);
42 mv_fox 316
      video_putstring(10, 2, COLOR_BODY[mono], buff);
317
      putstringnls(12, 2, COLOR_BODY[mono], 0, 5, "Press any key...");
28 mv_fox 318
      input_getkey();
319
      return(-1);
320
    }
321
    /* is the disk empty? */
35 mv_fox 322
    if (diskempty(selecteddrive) != 0) {
28 mv_fox 323
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
42 mv_fox 324
      list[0] = kittengets(0, 6, list[0]);
325
      list[1] = kittengets(0, 2, list[1]);
326
      sprintf(buff, kittengets(3, 14, "ERROR: Drive %c: is not empty. Svarog386 must be installed on an empty disk."), cselecteddrive);
327
      video_putstring(7, 2, COLOR_BODY[mono], buff);
328
      putstringnls(8, 2, COLOR_BODY[mono], 3, 15, "       You can format the disk now, to make it empty. Note however, that");
329
      putstringnls(9, 2, COLOR_BODY[mono], 3, 16, "       this will ERASE ALL CURRENT DATA on your disk.");
28 mv_fox 330
      if (menuselect(12, -1, 4, list) != 0) return(-1);
331
      video_clear(0x0700, 0);
332
      video_movecursor(0, 0);
42 mv_fox 333
      sprintf(buff, "FORMAT %c: /Q /U /Z:seriously /V:SVAROG386", cselecteddrive);
334
      system(buff);
28 mv_fox 335
      continue;
336
    } else {
337
      /* final confirmation */
338
      char *list[] = { "Install Svarog386", "Quit to DOS", NULL};
42 mv_fox 339
      list[0] = kittengets(0, 1, list[0]);
340
      list[1] = kittengets(0, 2, list[1]);
341
      sprintf(buff, kittengets(3, 17, "The installation of Svarog386 to %c: is about to begin."), cselecteddrive);
49 mv_fox 342
      video_putstring(7, -1, COLOR_BODY[mono], buff);
28 mv_fox 343
      if (menuselect(10, -1, 4, list) != 0) return(-1);
36 mv_fox 344
      sprintf(buff, "SYS A: %c:", cselecteddrive);
345
      system(buff);
346
      sprintf(buff, "%c:\\TEMP", cselecteddrive);
347
      mkdir(buff);
348
      return(cselecteddrive);
28 mv_fox 349
    }
350
  }
351
}
352
 
353
 
53 mv_fox 354
/* copy file src into dst, substituting all characters c1 by c2 */
355
static void fcopysub(char *dst, char *src, char c1, char c2) {
356
  FILE *fdd, *fds;
357
  int buff;
358
  fds = fopen(src, "rb");
359
  if (fds == NULL) return;
360
  fdd = fopen(dst, "wb");
361
  if (fdd == NULL) {
362
    fclose(fds);
363
    return;
364
  }
365
  /* */
366
  for (;;) {
367
    buff = fgetc(fds);
368
    if (buff == EOF) break;
369
    if (buff == c1) buff = c2;
370
    fprintf(fdd, "%c", buff);
371
  }
372
  /* close files and return */
373
  fclose(fdd);
374
  fclose(fds);
375
}
376
 
377
 
378
static void bootfilesgen(int targetdrv, char *lang, int cdromdrv) {
28 mv_fox 379
  char buff[128];
49 mv_fox 380
  int cp, egafile;
28 mv_fox 381
  FILE *fd;
49 mv_fox 382
  cp = getnlscp(lang, &egafile);
53 mv_fox 383
  /*** CONFIG.SYS ***/
384
  sprintf(buff, "%c:\\CONFIG.SYS", targetdrv);
385
  fd = fopen(buff, "wb");
386
  if (fd == NULL) return;
387
  fprintf(fd, "DOS=UMB,HIGH\r\n");
388
  fprintf(fd, "FILES=50\r\n");
389
  fprintf(fd, "DEVICE=%c:\\SYSTEM\\SVAROG.386\\BIN\\HIMEMX.EXE\r\n", targetdrv);
390
  fprintf(fd, "SHELLHIGH=%c:\\SYSTEM\\SVAROG.386\\BIN\\COMMAND.COM /E:512 /P\r\n", targetdrv);
391
  if (egafile > 0) fprintf(fd, "DEVICE=%c:\\SYSTEM\\SVAROG.386\\BIN\\DISPLAY.SYS\r\n", targetdrv);
392
  fprintf(fd, "REM COUNTRY=001,437,%c:\\SYSTEM\\CONF\\COUNTRY.SYS\r\n", targetdrv);
393
  fprintf(fd, "DEVICE=%c:\\SYSTEM\\DRIVERS\\UDVD2\\UDVD2.SYS /D:SVCD0001 /H\r\n", targetdrv);
394
  fclose(fd);
28 mv_fox 395
  /*** AUTOEXEC.BAT ***/
36 mv_fox 396
  sprintf(buff, "%c:\\AUTOEXEC.BAT", targetdrv);
28 mv_fox 397
  fd = fopen(buff, "wb");
398
  if (fd == NULL) return;
399
  fprintf(fd, "@ECHO OFF\r\n");
36 mv_fox 400
  fprintf(fd, "SET TEMP=%c:\\TEMP\r\n", targetdrv);
401
  fprintf(fd, "SET DOSDIR=%c:\\SYSTEM\\SVAROG.386\r\n", targetdrv);
49 mv_fox 402
  fprintf(fd, "SET NLSPATH=%%DOSDIR%%\\NLS\r\n");
28 mv_fox 403
  fprintf(fd, "SET LANG=%s\r\n", lang);
53 mv_fox 404
  fprintf(fd, "SET DIRCMD=/OGNE/P/4\r\n");
405
  fprintf(fd, "SET FDNPKG.CFG=%c:\\SYSTEM\\CFG\\FDNPKG.CFG\r\n", targetdrv);
406
  fprintf(fd, "SET WATTCP.CFG=%c:\\SYSTEM\\CFG\\WATTCP.CFG\r\n", targetdrv);
407
  fprintf(fd, "PATH %%DOSDIR%%\\BIN;%c:\\SYSTEM\\LINKS\r\n", targetdrv);
28 mv_fox 408
  fprintf(fd, "PROMPT $P$G\r\n");
30 mv_fox 409
  fprintf(fd, "ALIAS REBOOT=FDAPM COLDBOOT\r\n");
410
  fprintf(fd, "ALIAS HALT=FDAPM POWEROFF\r\n");
28 mv_fox 411
  fprintf(fd, "\r\n");
49 mv_fox 412
  if (egafile > 0) {
413
    if (egafile == 1) {
414
      fprintf(fd, "MODE CON CP PREPARE=((%d) %c:\\SYSTEM\\SVAROG.386\\CPI\\EGA.CPX)\r\n", cp, targetdrv);
415
    } else {
416
      fprintf(fd, "MODE CON CP PREPARE=((%d) %c:\\SYSTEM\\SVAROG.386\\CPI\\EGA%d.CPX)\r\n", cp, targetdrv, egafile);
417
    }
418
    fprintf(fd, "MODE CON CP SELECT=%d\r\n", cp);
419
    fprintf(fd, "\r\n");
420
  }
421
  fprintf(fd, "SHSUCDX /d:SVCD0001\r\n");
422
  fprintf(fd, "\r\n");
423
  fprintf(fd, "REM Uncomment the line below for automatic mouse support\r\n");
424
  fprintf(fd, "REM CTMOUSE\r\n");
425
  fprintf(fd, "\r\n");
53 mv_fox 426
  fprintf(fd, "ECHO.\r\n");
427
  fprintf(fd, "ECHO Welcome to Svarog386! Type 'HELP' if your need help.\r\n");
28 mv_fox 428
  fclose(fd);
53 mv_fox 429
  /*** CREATE DIRECTORY FOR OTHER CONFIGURATION FILES ***/
430
  snprintf(buff, sizeof(buff), "%c:\\SYSTEM\\CFG", targetdrv);
431
  mkdir(buff);
432
  /*** FDNPKG.CFG ***/
433
  snprintf(buff, sizeof(buff), "%c:\\SYSTEM\\CFG\\FDNPKG.CFG", targetdrv);
434
  fcopysub(buff, "A:\\DAT\\FDNPKG.CFG", '$', cdromdrv);
435
  /*** COUNTRY.SYS ***/
436
  /*** PICOTCP ***/
437
  /*** WATTCP ***/
28 mv_fox 438
}
439
 
440
 
53 mv_fox 441
static void installpackages(int targetdrv, int cdromdrv) {
28 mv_fox 442
  char *pkglist[] = {
443
    "APPEND",
444
    "ASSIGN",
445
    "ATTRIB",
446
    "CHKDSK",
447
    "CHOICE",
448
    "COMMAND",
449
    "COMP",
450
    "CPIDOS",
451
    "CTMOUSE",
452
    "DEBUG",
453
    "DEFRAG",
454
    "DELTREE",
455
    "DEVLOAD",
456
    "DISKCOMP",
457
    "DISKCOPY",
458
    "DISPLAY",
459
    "DOSFSCK",
460
    "EDIT",
461
    "EDLIN",
462
    "EXE2BIN",
463
    "FC",
464
    "FDAPM",
465
    "FDISK",
466
    "FDNPKG",
467
    "FIND",
468
    "FORMAT",
469
    "HELP",
470
    "HIMEMX",
471
    "KERNEL",
472
    "KEYB",
473
    "LABEL",
474
    "LBACACHE",
475
    "MEM",
476
    "MIRROR",
477
    "MODE",
478
    "MORE",
479
    "MOVE",
480
    "NANSI",
481
    "NLSFUNC",
482
    "PRINT",
483
    "RDISK",
484
    "RECOVER",
485
    "REPLACE",
486
    "SHARE",
487
    "SHSUCDX",
488
    "SORT",
489
    "SWSUBST",
490
    "TREE",
491
    "UNDELETE",
492
    "XCOPY",
493
    NULL
494
  };
30 mv_fox 495
  int i, pkglistlen;
46 mv_fox 496
  char buff[64];
28 mv_fox 497
  newscreen();
30 mv_fox 498
  /* count how long the pkg list is */
499
  for (pkglistlen = 0; pkglist[pkglistlen] != NULL; pkglistlen++);
46 mv_fox 500
  /* set DOSDIR and friends */
501
  snprintf(buff, sizeof(buff), "%c:\\SYSTEM\\SVAROG.386", targetdrv);
502
  setenv("DOSDIR", buff, 1);
503
  snprintf(buff, sizeof(buff), "%c:\\TEMP", targetdrv);
504
  setenv("TEMP", buff, 1);
30 mv_fox 505
  /* install packages */
28 mv_fox 506
  for (i = 0; pkglist[i] != NULL; i++) {
36 mv_fox 507
    char buff[128];
42 mv_fox 508
    snprintf(buff, sizeof(buff), kittengets(4, 0, "Installing package %d/%d: %s"), i+1, pkglistlen, pkglist[i]);
36 mv_fox 509
    strcat(buff, "       ");
30 mv_fox 510
    video_putstring(10, 2, COLOR_BODY[mono], buff);
53 mv_fox 511
    sprintf(buff, "FDINST INSTALL %c:\\CORE\\%s.ZIP > NUL", cdromdrv, pkglist[i]);
28 mv_fox 512
    system(buff);
513
  }
514
}
515
 
516
 
42 mv_fox 517
static void finalreboot(void) {
518
  newscreen();
49 mv_fox 519
  putstringnls(9, 2, COLOR_BODY[mono], 5, 0, "Svarog386 installation is over. Your computer will reboot now.");
520
  putstringnls(10, 2, COLOR_BODY[mono], 5, 1, "Please remove the installation disk from your drive.");
521
  putstringnls(12, 2, COLOR_BODY[mono], 0, 5, "Press any key...");
42 mv_fox 522
  input_getkey();
523
  reboot();
524
}
525
 
526
 
527
static void loadcp(char *lang) {
528
  int cp, egafile;
529
  char buff[64];
530
  cp = getnlscp(lang, &egafile);
531
  if (cp == 437) return;
532
  video_movecursor(1, 0);
533
  if (egafile == 1) {
534
    sprintf(buff, "MODE CON CP PREP=((%d) A:\\EGA.CPX)", cp);
535
  } else {
536
    sprintf(buff, "MODE CON CP PREP=((%d) A:\\EGA%d.CPX)", cp, egafile);
537
  }
538
  system(buff);
539
  sprintf(buff, "MODE CON CP SEL=%d", cp);
540
  system(buff);
541
  /* below I re-init the video controller - apparently this is required if
542
   * I want the new glyph symbols to be actually applied */
543
  {
544
  union REGS r;
545
  r.h.ah = 0x0F; /* get current video mode */
546
  int86(0x10, &r, &r); /* r.h.al contains the current video mode now */
547
  r.h.ah = 0; /* set video mode (to whatever is set in AL) */
548
  int86(0x10, &r, &r);
549
  }
550
}
551
 
552
 
28 mv_fox 553
int main(void) {
554
  char lang[4];
555
  int targetdrv;
53 mv_fox 556
  int cdromdrv;
28 mv_fox 557
 
53 mv_fox 558
  /* find where the cdrom drive is */
559
  cdromdrv = cdrom_findfirst();
560
  if (cdromdrv < 0) {
561
    printf("ERROR: CD-ROM DRIVE NOT FOUND\r\n");
562
    return(1);
563
  }
564
  cdromdrv += 'A'; /* convert the cdrom 'id' (A=0) to an actual drive letter */
565
 
29 mv_fox 566
  /* init screen and detect mono status */
567
  mono = video_init();
568
 
28 mv_fox 569
  for (;;) { /* fake loop, it's here just to break out easily */
570
    if (selectlang(lang) < 0) break; /* welcome to svarog, select your language */
42 mv_fox 571
    setenv("LANG", lang, 1);
572
    loadcp(lang);
573
    kittenopen("INSTALL"); /* NLS support */
30 mv_fox 574
    /*selectkeyb();*/ /* what keyb layout should we use? */
28 mv_fox 575
    if (welcomescreen() != 0) break; /* what svarog386 is, ask whether to run live dos or install */
576
    targetdrv = preparedrive(); /* what drive should we install to? check avail. space */
577
    if (targetdrv < 0) break;
578
    /*askaboutsources();*/ /* IF sources are available, ask if installing with them */
53 mv_fox 579
    installpackages(targetdrv, cdromdrv);    /* install packages */
580
    bootfilesgen(targetdrv, lang, cdromdrv); /* generate boot files and other configurations */
28 mv_fox 581
    /*localcfg();*/ /* show local params (currency, etc), and propose to change them (based on localcfg) */
42 mv_fox 582
    /*netcfg();*/ /* basic networking config */
28 mv_fox 583
    finalreboot(); /* remove the CD and reboot */
584
    break;
585
  }
42 mv_fox 586
  kittenclose(); /* close NLS support */
28 mv_fox 587
  video_clear(0x0700, 0);
588
  video_movecursor(0, 0);
589
  return(0);
590
}