Subversion Repositories SvarDOS

Rev

Rev 29 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
28 mv_fox 1
/*
2
 * SVAROG386 INSTALL
3
 * COPYRIGHT (C) 2016 MATEUSZ VISTE
4
 */
5
 
6
#include <dos.h>
30 mv_fox 7
#include <direct.h>  /* mkdir() */
28 mv_fox 8
#include <stdio.h>   /* printf() and friends */
9
#include <stdlib.h>  /* system() */
10
#include <string.h>  /* memcpy() */
11
#include <unistd.h>
12
#include "input.h"
13
#include "video.h"
14
 
29 mv_fox 15
/* color scheme (color, mono) */
16
static unsigned short COLOR_TITLEBAR[2] = {0x7000,0x7000};
17
static unsigned short COLOR_BODY[2] = {0x1700,0x0700};
18
static unsigned short COLOR_SELECT[2] = {0x7000,0x7000};
19
static unsigned short COLOR_SELECTCUR[2] = {0x1F00,0x0700};
28 mv_fox 20
 
29 mv_fox 21
/* mono flag */
22
static int mono = 0;
28 mv_fox 23
 
24
 
25
/* reboot the computer */
26
static void reboot(void) {
27
  void ((far *bootroutine)()) = (void (far *)()) 0xFFFF0000L;
28
  int far *rstaddr = (int far *)0x00400072L; /* BIOS boot flag is at 0040:0072 */
29
  *rstaddr = 0x1234; /* 0x1234 = warm boot, 0 = cold boot */
30
  (*bootroutine)(); /* jump to the BIOS reboot routine at FFFF:0000 */
31
}
32
 
33
static int menuselect(int ypos, int xpos, int height, char **list) {
34
  int i, offset = 0, res = 0, count, width = 0;
35
  /* count how many languages there is */
36
  for (count = 0; list[count] != NULL; count++) {
37
    int len = strlen(list[count]);
38
    if (len > width) width = len;
39
  }
40
 
41
  /* if xpos negative, means 'center out' */
42
  if (xpos < 0) xpos = 39 - (width >> 1);
43
 
29 mv_fox 44
  video_putchar(ypos, xpos+width+2, COLOR_SELECT[mono], 0xBF);         /*       \ */
45
  video_putchar(ypos, xpos-1, COLOR_SELECT[mono], 0xDA);               /*  /      */
46
  video_putchar(ypos+height-1, xpos-1, COLOR_SELECT[mono], 0xC0);      /*  \      */
47
  video_putchar(ypos+height-1, xpos+width+2, COLOR_SELECT[mono], 0xD9);/*      /  */
48
  video_putcharmulti(ypos, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
49
  video_putcharmulti(ypos+height-1, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
50
  video_putcharmulti(ypos+1, xpos-1, COLOR_SELECT[mono], 0xB3, height - 2, 80);
51
  video_putcharmulti(ypos+1, xpos+width+2, COLOR_SELECT[mono], 0xB3, height - 2, 80);
28 mv_fox 52
 
53
  for (;;) {
54
    int key;
55
    /* list of selectable items */
56
    for (i = 0; i < height - 2; i++) {
57
      if (i + offset == res) {
29 mv_fox 58
        video_putchar(ypos + 1 + i, xpos, COLOR_SELECTCUR[mono], 16);
59
        video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECTCUR[mono], 17);
28 mv_fox 60
        video_movecursor(ypos + 1 + i, xpos);
29 mv_fox 61
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECTCUR[mono], list[i + offset], width);
28 mv_fox 62
      } else if (i + offset < count) {
29 mv_fox 63
        video_putchar(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ');
64
        video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECT[mono], ' ');
65
        video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECT[mono], list[i + offset], width);
28 mv_fox 66
      } else {
29 mv_fox 67
        video_putcharmulti(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ', width+2, 1);
28 mv_fox 68
      }
69
    }
70
    key = input_getkey();
71
    if (key == 0x0D) { /* ENTER */
72
      return(res);
73
    } else if (key == 0x148) { /* up */
74
      if (res > 0) res--;
75
    } else if (key == 0x150) { /* down */
76
      if (res+1 < count) res++;
77
    } else if (key == 0x1B) {  /* ESC */
78
      return(-1);
79
    }
80
  }
81
}
82
 
83
static void newscreen(void) {
84
  int x;
29 mv_fox 85
  for (x = 0; x < 80; x++) video_putchar(0, x, COLOR_TITLEBAR[mono], ' ');
86
  video_clear(COLOR_BODY[mono], 80);
87
  video_putstring(0, 29, COLOR_TITLEBAR[mono], "SVAROG386 INSTALLATION");
28 mv_fox 88
}
89
 
90
 
91
static int selectlang(char *lang) {
92
  int choice;
93
  char *code;
94
  char *langlist[] = {
95
    "English\0EN",
96
    "French\0FR",
97
    "German\0DE",
98
    "Italian\0IT",
99
    "Polish\0PL",
100
    "Russian\0RU",
101
    "Slovenian\0SL",
102
    "Spanish\0ES",
103
    "Turkish\0TR",
104
    NULL
105
  };
106
 
107
  newscreen();
29 mv_fox 108
  video_putstring(3, 30, COLOR_BODY[mono], "Welcome to Svarog386");
109
  video_putstring(4, 30, COLOR_BODY[mono], "====================");
110
  video_putstring(6, 2, COLOR_BODY[mono], "Svarog386 is an operating system based on the FreeDOS kernel. It targets");
111
  video_putstring(7, 2, COLOR_BODY[mono], "386+ computers and comes with a variety of third-party applications. Before");
112
  video_putstring(8, 2, COLOR_BODY[mono], "we get to serious business, please select your preferred language from the");
113
  video_putstring(9, 2, COLOR_BODY[mono], "list below, and press the ENTER key:");
28 mv_fox 114
  choice = menuselect(11, -1, 12, langlist);
115
  if (choice < 0) return(-1);
116
  /* write short language code into lang */
117
  for (code = langlist[choice]; *code != 0; code++);
118
  memcpy(lang, code + 1, 2);
119
  lang[2] = 0;
120
  return(0);
121
}
122
 
123
 
124
/* returns 0 if installation must proceed, non-zero otherwise */
125
static int welcomescreen(void) {
126
  char *choice[] = {"Install Svarog386 to disk", "Quit to DOS", NULL};
127
  newscreen();
29 mv_fox 128
  video_putstring(4, 1, COLOR_BODY[mono], "You are about to install Svarog386, a free, MSDOS-compatible operating system");
129
  video_putstring(5, 1, COLOR_BODY[mono], "based on the FreeDOS kernel.");
130
  video_putstring(7, 1, COLOR_BODY[mono], "WARNING: If your PC has another operating system installed, this other system");
131
  video_putstring(8, 1, COLOR_BODY[mono], "         might be unable to boot once Svarog386 is installed.");
28 mv_fox 132
  return(menuselect(14, -1, 4, choice));
133
}
134
 
135
 
136
static int testdrive(int drv) {
137
  union REGS r;
138
  /* try to switch to new drive */
139
  r.h.ah = 0x0E;
140
  r.h.dl = drv;
141
  int86(0x21, &r, &r);
142
  /* has it worked? if yes, then the drive is valid */
143
  r.h.ah = 0x19;
144
  int86(0x21, &r, &r);
145
  if (r.h.al == drv) return(0);
146
  return(-1);
147
}
148
 
149
 
150
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid
151
 * also sets emptyflag to 1 if drive is empty, or to 0 otherwise */
152
static int disksize(int drv, int *emptyflag) {
153
  long res;
154
  union REGS r;
155
  r.h.ah = 0x36; /* DOS 2+ get free disk space */
156
  r.h.dl = drv;
157
  int86(0x21, &r, &r);
158
  if (r.x.ax == 0xffffu) return(-1); /* AX set to FFFFh if drive invalid */
159
  res = r.x.ax;
160
  res *= r.x.bx;
161
  res *= r.x.cx;
162
  res >>= 20; /* bytes to MiB */
163
  if (r.x.dx != r.x.bx) { /* DX is total number of clusters, while BX is only free clusters */
164
    *emptyflag = 0;
165
  } else {
166
    *emptyflag = 1;
167
  }
168
  return(res);
169
}
170
 
171
 
172
static int preparedrive(void) {
173
  int driveexists;
174
  int selecteddrive = 3; /* hardcoded to 'C:' */
175
  int ds, emptydriveflag;
176
  for (;;) {
177
    newscreen();
178
    driveexists = testdrive(selecteddrive);
179
    if (driveexists != 0) {
180
      char *list[] = { "Run the FDISK partitionning tool", "Quit to DOS", NULL};
29 mv_fox 181
      video_putstring(4, 2, COLOR_BODY[mono], "ERROR: Drive C: could not be found. Perhaps your hard disk needs to be");
182
      video_putstring(5, 2, COLOR_BODY[mono], "       partitionned first. Please create at least one partition on your");
183
      video_putstring(6, 2, COLOR_BODY[mono], "       hard disk, so Svarog386 can be installed on it. Note, that");
184
      video_putstring(7, 2, COLOR_BODY[mono], "       Svarog386 requires at least 16 MiB of available disk space.");
185
      video_putstring(9, 2, COLOR_BODY[mono], "You can use the FDISK partitioning tool for creating the required partition,");
186
      video_putstring(10, 2, COLOR_BODY[mono], "or abort the installation and use any other partition manager of your choice.");
28 mv_fox 187
      if (menuselect(12, -1, 4, list) != 0) return(-1);
188
      video_clear(0x0700, 0);
189
      video_movecursor(0, 0);
190
      system("fdisk");
191
      newscreen();
29 mv_fox 192
      video_putstring(13, 10, COLOR_BODY[mono], "Your computer will reboot now. Press any key.");
28 mv_fox 193
      reboot();
194
      return(-1);
195
    }
196
    /* if not formatted, propose to format it right away */
197
    ds = disksize(selecteddrive, &emptydriveflag);
198
    if (ds < 0) {
199
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
29 mv_fox 200
      video_putstring(7, 2, COLOR_BODY[mono], "ERROR: Drive C: seems to be unformated.");
201
      video_putstring(8, 2, COLOR_BODY[mono], "       Do you wish to format it?");
28 mv_fox 202
      if (menuselect(12, -1, 4, list) != 0) return(-1);
203
      video_clear(0x0700, 0);
204
      video_movecursor(0, 0);
205
      system("FORMAT /Q C:");
206
      continue;
207
    }
208
    /* check total space */
209
    if (ds < 16) {
29 mv_fox 210
      video_putstring(9, 2, COLOR_BODY[mono], "ERROR: Drive C: is not big enough! Svarog386 requires a disk of at least 16 MiB.");
211
      video_putstring(11, 2, COLOR_BODY[mono], "Press any key to return to DOS.");
28 mv_fox 212
      input_getkey();
213
      return(-1);
214
    }
215
    /* is the disk empty? */
216
    if (emptydriveflag != 0) {
217
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
29 mv_fox 218
      video_putstring(7, 2, COLOR_BODY[mono], "ERROR: Drive C: is not empty. Svarog386 must be installed on an empty disk.");
219
      video_putstring(8, 2, COLOR_BODY[mono], "       You can format the disk now, to make it empty. Note however, that");
220
      video_putstring(9, 2, COLOR_BODY[mono], "       this will ERASE ALL CURRENT DATA on your disk.");
28 mv_fox 221
      if (menuselect(12, -1, 4, list) != 0) return(-1);
222
      video_clear(0x0700, 0);
223
      video_movecursor(0, 0);
224
      system("FORMAT /Q C:");
225
      continue;
226
    } else {
227
      /* final confirmation */
228
      char *list[] = { "Install Svarog386", "Quit to DOS", NULL};
29 mv_fox 229
      video_putstring(8, 2, COLOR_BODY[mono], "The installation of Svarog386 to your C: disk is about to begin.");
28 mv_fox 230
      if (menuselect(10, -1, 4, list) != 0) return(-1);
231
      system("SYS A: C:");
30 mv_fox 232
      mkdir("C:\\TEMP");
28 mv_fox 233
      return(0);
234
    }
235
  }
236
}
237
 
238
 
239
static void finalreboot(void) {
240
  newscreen();
29 mv_fox 241
  video_putstring(10, 2, COLOR_BODY[mono], "Svarog386 installation is over. Please remove the");
242
  video_putstring(10, 2, COLOR_BODY[mono], "installation diskette and/or CD from the drive.");
243
  video_putstring(13, 2, COLOR_BODY[mono], "Press any key to reboot...");
28 mv_fox 244
  input_getkey();
245
  reboot();
246
}
247
 
248
 
249
static void bootfilesgen(int targetdrv, char *lang) {
250
  char drv = 'A' + targetdrv - 1;
251
  char buff[128];
252
  FILE *fd;
253
  /*** AUTOEXEC.BAT ***/
254
  sprintf(buff, "%c:\\AUTOEXEC.BAT", drv);
255
  fd = fopen(buff, "wb");
256
  if (fd == NULL) return;
257
  fprintf(fd, "@ECHO OFF\r\n");
258
  fprintf(fd, "SET TEMP=%c:\\TEMP\r\n", drv);
259
  fprintf(fd, "SET DOSDIR=%c:\\SYSTEM\\SVAROG.386\r\n", drv);
260
  fprintf(fd, "SET NLSPATH=%%DOSDIR%%\\NLS\r\n", drv);
261
  fprintf(fd, "SET LANG=%s\r\n", lang);
262
  fprintf(fd, "SET DIRCMD=/OGNE/P\r\n");
263
  fprintf(fd, "SET FDNPKG.CFG=%c:\\SYSTEM\\CFG\\FDNPKG.CFG\r\n");
264
  fprintf(fd, "SET WATTCP.CFG=%c:\\SYSTEM\\CFG\\WATTCP.CFG\r\n");
265
  fprintf(fd, "PATH %%DOSDIR%%\\BIN;%%DOSDIR%%\\LINKS\r\n");
266
  fprintf(fd, "PROMPT $P$G\r\n");
30 mv_fox 267
  fprintf(fd, "ALIAS REBOOT=FDAPM COLDBOOT\r\n");
268
  fprintf(fd, "ALIAS HALT=FDAPM POWEROFF\r\n");
28 mv_fox 269
  fprintf(fd, "\r\n\r\n");
270
  fprintf(fd, "MODE CON CP PREPARE=((991) %c:\\SYSTEM\\SVAROG.386\\CPI\\EGA10.CPX\r\n");
271
  fprintf(fd, "MODE CON CP SELECT=991\r\n");
272
  fprintf(fd, "\r\n");
273
  fprintf(fd, "SHSUCDX /d:FDCD0001\r\n");
274
  fclose(fd);
275
  /*** CONFIG.SYS ***/
276
  sprintf(buff, "%c:\\CONFIG.SYS", drv);
277
  fd = fopen(buff, "wb");
278
  if (fd == NULL) return;
279
  fprintf(fd, "DOS=UMB,HIGH\r\n");
280
  fprintf(fd, "FILES=50\r\n");
281
  fprintf(fd, "DEVICE=%c:\\SYSTEM\\SVAROG.386\\BIN\\HIMEM.EXE\r\n", drv);
282
  fprintf(fd, "SHELLHIGH=%c:\\SYSTEM\\SVAROG.386\\BIN\\COMMAND.COM /E:512", drv);
283
  fprintf(fd, "REM COUNTRY=001,437,%c:\\SYSTEM\\SVAROG.386\r\n", drv);
284
  fprintf(fd, "DEVICE=%c:\\SYSTEM\\SVAROG.386\\BIN\\CDROM.SYS /D:FDCD0001\r\n", drv);
285
  fclose(fd);
286
}
287
 
288
 
289
static void installpackages(void) {
290
  char *pkglist[] = {
291
    "APPEND",
292
    "ASSIGN",
293
    "ATTRIB",
294
    "CHKDSK",
295
    "CHOICE",
296
    "COMMAND",
297
    "COMP",
298
    "CPIDOS",
299
    "CTMOUSE",
300
    "DEBUG",
301
    "DEFRAG",
302
    "DELTREE",
303
    "DEVLOAD",
304
    "DISKCOMP",
305
    "DISKCOPY",
306
    "DISPLAY",
307
    "DOSFSCK",
308
    "EDIT",
309
    "EDLIN",
310
    "EXE2BIN",
311
    "FC",
312
    "FDAPM",
313
    "FDISK",
314
    "FDNPKG",
315
    "FIND",
316
    "FORMAT",
317
    "HELP",
318
    "HIMEMX",
319
    "KERNEL",
320
    "KEYB",
321
    "LABEL",
322
    "LBACACHE",
323
    "MEM",
324
    "MIRROR",
325
    "MODE",
326
    "MORE",
327
    "MOVE",
328
    "NANSI",
329
    "NLSFUNC",
330
    "PRINT",
331
    "RDISK",
332
    "RECOVER",
333
    "REPLACE",
334
    "SHARE",
335
    "SHSUCDX",
336
    "SORT",
337
    "SWSUBST",
338
    "TREE",
339
    "UNDELETE",
340
    "XCOPY",
341
    NULL
342
  };
30 mv_fox 343
  int i, pkglistlen;
28 mv_fox 344
  newscreen();
30 mv_fox 345
  /* count how long the pkg list is */
346
  for (pkglistlen = 0; pkglist[pkglistlen] != NULL; pkglistlen++);
347
  /* install packages */
28 mv_fox 348
  for (i = 0; pkglist[i] != NULL; i++) {
30 mv_fox 349
    char buff[16];
350
    sprintf(buff, "Installing package %d/%d: %s", i, pkglistlen, pkglist[i]);
351
    video_putstring(10, 2, COLOR_BODY[mono], buff);
352
    sprintf(buff, "FDNPKG INSTALL %s > NULL");
28 mv_fox 353
    system(buff);
354
  }
355
}
356
 
357
 
358
int main(void) {
359
  char lang[4];
360
  int targetdrv;
361
 
29 mv_fox 362
  /* init screen and detect mono status */
363
  mono = video_init();
364
 
28 mv_fox 365
  for (;;) { /* fake loop, it's here just to break out easily */
366
    if (selectlang(lang) < 0) break; /* welcome to svarog, select your language */
30 mv_fox 367
    /*selectkeyb();*/ /* what keyb layout should we use? */
28 mv_fox 368
    if (welcomescreen() != 0) break; /* what svarog386 is, ask whether to run live dos or install */
369
    targetdrv = preparedrive(); /* what drive should we install to? check avail. space */
370
    if (targetdrv < 0) break;
371
    /*askaboutsources();*/ /* IF sources are available, ask if installing with them */
372
    installpackages();   /* install packages */
373
    bootfilesgen(targetdrv, lang); /* generate simple boot files */
374
    /*localcfg();*/ /* show local params (currency, etc), and propose to change them (based on localcfg) */
375
    /*netcfg();*/ /* basic networking config? */
376
    finalreboot(); /* remove the CD and reboot */
377
    break;
378
  }
379
  video_clear(0x0700, 0);
380
  video_movecursor(0, 0);
381
  return(0);
382
}