Subversion Repositories SvarDOS

Rev

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

Rev Author Line No. Line
28 mv_fox 1
/*
190 mateuszvis 2
 * SVARDOS INSTALL PROGRAM
206 mateuszvis 3
 *
190 mateuszvis 4
 * PUBLISHED UNDER THE TERMS OF THE MIT LICENSE
42 mv_fox 5
 *
1624 mateusz.vi 6
 * COPYRIGHT (C) 2016-2024 MATEUSZ VISTE, ALL RIGHTS RESERVED.
94 mv_fox 7
 *
190 mateuszvis 8
 * Permission is hereby granted, free of charge, to any person obtaining a
9
 * copy of this software and associated documentation files (the "Software"),
10
 * to deal in the Software without restriction, including without limitation
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
 * and/or sell copies of the Software, and to permit persons to whom the
13
 * Software is furnished to do so, subject to the following conditions:
94 mv_fox 14
 *
190 mateuszvis 15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
94 mv_fox 17
 *
190 mateuszvis 18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
 * DEALINGS IN THE SOFTWARE.
94 mv_fox 25
 *
868 mateusz.vi 26
 * http://svardos.org
28 mv_fox 27
 */
28
 
29
#include <dos.h>
30 mv_fox 30
#include <direct.h>  /* mkdir() */
28 mv_fox 31
#include <stdio.h>   /* printf() and friends */
32
#include <stdlib.h>  /* system() */
33
#include <string.h>  /* memcpy() */
34
#include <unistd.h>
42 mv_fox 35
 
1662 mateusz.vi 36
#include "mdr\cout.h"
1661 mateusz.vi 37
#include "mdr\dos.h"
624 mateuszvis 38
#include "svarlang.lib\svarlang.h"
42 mv_fox 39
 
67 mv_fox 40
/* keyboard layouts and locales */
41
#include "keylay.h"
42
#include "keyoff.h"
42 mv_fox 43
 
908 mateusz.vi 44
 
1664 mateusz.vi 45
/* color scheme (preset for color) */
46
static unsigned char COLOR_TITLEBAR  = 0x70;
1671 mateusz.vi 47
static unsigned char COLOR_TITLEVER  = 0x78;
1664 mateusz.vi 48
static unsigned char COLOR_BODY      = 0x17;
1673 mateusz.vi 49
static unsigned char COLOR_BODYWARN  = 0x1F;
1664 mateusz.vi 50
static unsigned char COLOR_SELECT    = 0x70;
51
static unsigned char COLOR_SELECTCUR = 0x1F;
28 mv_fox 52
 
1671 mateusz.vi 53
/* build release string, populated at startup by reading floppy's label */
54
static char BUILDSTRING[13];
28 mv_fox 55
 
190 mateuszvis 56
/* how much disk space does SvarDOS require (in MiB) */
1928 mateusz.vi 57
#define SVARDOS_DISK_REQ 4
28 mv_fox 58
 
73 mv_fox 59
/* menu screens can output only one of these: */
60
#define MENUNEXT 0
61
#define MENUPREV -1
62
#define MENUQUIT -2
63
 
67 mv_fox 64
/* a convenience 'function' used for debugging */
65
#define DBG(x) { video_putstringfix(24, 0, 0x4F00u, x, 80); }
47 mv_fox 66
 
67 mv_fox 67
struct slocales {
68
  char lang[4];
624 mateuszvis 69
  const char *keybcode;
1908 mateusz.vi 70
  unsigned short codepage;
71
  unsigned char egafile;
72
  unsigned char keybfile;
73
  short keyboff;
74
  short keyblen;
75
  unsigned short keybid;
76
  unsigned short countryid; /* 1=USA, 33=FR, 48=PL, etc */
67 mv_fox 77
};
78
 
79
 
1918 mateusz.vi 80
/* install a dummy int24h handler that always fails. this is to avoid the
81
 * annoying "abort, retry, fail... DOS messages. */
82
static void install_int24(void) {
83
  static unsigned char handler[] = { /* contains machine code instructions */
84
    0xB0, 0x03,  /* mov al, 3   ; tell DOS the action has to FAIL   */
85
    0xCF};       /* ret         ; return from the interrupt handler */
86
  /* install the handler */
87
  _asm {
88
    push dx
89
    mov ax, 0x2524          /* set INT vector 0x24 (to DS:DX)   */
90
    mov dx, offset handler  /* DS:DX points at my dummy handler */
91
    int 0x21
92
    pop dx
93
  }
94
}
95
 
96
 
97
static void exec(const char *s) {
98
  system(s);
99
  install_int24(); /* reinstall my int24 handler, apparently system() reverts
100
                      the original (DOS) one */
101
}
102
 
103
 
1908 mateusz.vi 104
/* put a string on screen and fill it until w chars with white space */
1662 mateusz.vi 105
static void video_putstringfix(unsigned char y, unsigned char x, unsigned char attr, const char *s, unsigned char w) {
106
  unsigned char i;
107
 
108
  /* print the string up to w characters */
109
  i = mdr_cout_str(y, x, s, attr, w);
110
 
111
  /* fill in left space (if any) with blanks */
112
  mdr_cout_char_rep(y, x + i, ' ', attr, w - i);
113
}
114
 
115
 
28 mv_fox 116
/* reboot the computer */
117
static void reboot(void) {
118
  void ((far *bootroutine)()) = (void (far *)()) 0xFFFF0000L;
119
  int far *rstaddr = (int far *)0x00400072L; /* BIOS boot flag is at 0040:0072 */
120
  *rstaddr = 0x1234; /* 0x1234 = warm boot, 0 = cold boot */
121
  (*bootroutine)(); /* jump to the BIOS reboot routine at FFFF:0000 */
122
}
123
 
42 mv_fox 124
 
1669 mateusz.vi 125
/* returns 1 if file exists, zero otherwise */
126
static int fileexists(const char *fname) {
127
  FILE *fd;
128
  fd = fopen(fname, "rb");
129
  if (fd == NULL) return(0);
130
  fclose(fd);
131
  return(1);
132
}
133
 
134
 
56 mv_fox 135
/* outputs a string to screen with taking care of word wrapping. returns amount of lines. */
1662 mateusz.vi 136
static unsigned char putstringwrap(unsigned char y, unsigned char x, unsigned char attr, const char *s) {
137
  unsigned char linew, lincount;
138
  linew = 80 - (x << 1);
56 mv_fox 139
 
140
  for (lincount = 1; y+lincount < 25; lincount++) {
141
    int i, len = linew;
142
    for (i = 0; i <= linew; i++) {
143
      if (s[i] == ' ') len = i;
144
      if (s[i] == '\n') {
145
        len = i;
146
        break;
147
      }
148
      if (s[i] == 0) {
149
        len = i;
150
        break;
151
      }
152
    }
1662 mateusz.vi 153
    mdr_cout_str(y++, x, s, attr, len);
56 mv_fox 154
    s += len;
155
    if (*s == 0) break;
156
    s += 1; /* skip the whitespace char */
157
  }
158
  return(lincount);
159
}
160
 
161
 
162
/* an NLS wrapper around video_putstring(), also performs line wrapping when
163
 * needed. returns the amount of lines that were output */
1662 mateusz.vi 164
static unsigned char putstringnls(unsigned char y, unsigned char x, unsigned char attr, unsigned char nlsmaj, unsigned char nlsmin) {
624 mateuszvis 165
  const char *s = svarlang_str(nlsmaj, nlsmin);
166
  if (s == NULL) s = "";
56 mv_fox 167
  return(putstringwrap(y, x, attr, s));
42 mv_fox 168
}
169
 
170
 
280 mateuszvis 171
/* copy file f1 to f2 using buff as a buffer of buffsz bytes. f2 will be overwritten if it
172
 * exists already! returns 0 on success. */
173
static int fcopy(const char *f2, const char *f1, void *buff, size_t buffsz) {
174
  FILE *fd1, *fd2;
175
  size_t sz;
176
  int res = -1; /* assume failure */
177
 
178
  /* open files */
179
  fd1 = fopen(f1, "rb");
180
  fd2 = fopen(f2, "wb");
181
  if ((fd1 == NULL) || (fd2 == NULL)) goto QUIT;
182
 
183
  /* copy data */
184
  for (;;) {
185
    sz = fread(buff, 1, buffsz, fd1);
186
    if (sz == 0) {
187
      if (feof(fd1) != 0) break;
188
      goto QUIT;
189
    }
190
    if (fwrite(buff, 1, sz, fd2) != sz) goto QUIT;
191
  }
192
 
193
  res = 0; /* success */
194
 
195
  QUIT:
196
  if (fd1 != NULL) fclose(fd1);
197
  if (fd2 != NULL) fclose(fd2);
198
  return(res);
199
}
200
 
201
 
1666 mateusz.vi 202
/* display a menu with items and return user's choice.
203
 * ypos: starting line where the menu is drawn
1948 mateusz.vi 204
 * height: max number of items to display inside the menu
1666 mateusz.vi 205
 * list: NULL-terminated list of items
206
 * maxlistlen: limit list to this many items tops */
1665 mateusz.vi 207
static int menuselect(unsigned char ypos, unsigned char height, const char **list, int maxlistlen) {
208
  int i, offset = 0, res = 0, count;
209
  unsigned char y, xpos, width = 0;
1662 mateusz.vi 210
 
1666 mateusz.vi 211
  /* count how many positions there are, and check their width */
1665 mateusz.vi 212
  for (count = 0; (list[count] != NULL) && (count != maxlistlen); count++) {
28 mv_fox 213
    int len = strlen(list[count]);
214
    if (len > width) width = len;
215
  }
1666 mateusz.vi 216
  width++; /* it's nice to have a small margin to the right of the widest item */
28 mv_fox 217
 
1948 mateusz.vi 218
  /* adjust height if there is less items than max height */
219
  if (count < height) height = count;
220
 
28 mv_fox 221
  /* if xpos negative, means 'center out' */
1665 mateusz.vi 222
  xpos = 39 - (width >> 1);
28 mv_fox 223
 
1666 mateusz.vi 224
  mdr_cout_char_rep(ypos, xpos, 0xC4, COLOR_SELECT, width + 2);  /* top line */
1664 mateusz.vi 225
  mdr_cout_char(ypos, xpos+width+2, 0xBF, COLOR_SELECT);         /*       \ */
226
  mdr_cout_char(ypos, xpos-1, 0xDA, COLOR_SELECT);               /*  /      */
1666 mateusz.vi 227
  ypos++; /* from now on ypos relates to the position of the content */
228
  mdr_cout_char(ypos+height, xpos-1, 0xC0, COLOR_SELECT);      /*  \      */
229
  mdr_cout_char(ypos+height, xpos+width+2, 0xD9, COLOR_SELECT);/*      /  */
230
  mdr_cout_char_rep(ypos+height, xpos, 0xC4, COLOR_SELECT, width + 2);
28 mv_fox 231
 
232
  for (;;) {
233
    int key;
1666 mateusz.vi 234
 
235
    /* draw side borders of the menu + the cursor */
236
    if (count <= height) { /* no need for a cursor, all fits on one page */
237
      i = 255;
238
    } else {
239
      i = offset * (height - 1) / (count - height);
240
    }
241
 
242
    for (y = ypos; y < (ypos + height); y++) {
243
      mdr_cout_char(y, xpos-1, 0xB3, COLOR_SELECT); /* left side */
244
      if (y - ypos == i) {
1667 mateusz.vi 245
        mdr_cout_char(y, xpos+width+2, '=', COLOR_SELECT); /* cursor */
1666 mateusz.vi 246
      } else {
247
        mdr_cout_char(y, xpos+width+2, 0xB3, COLOR_SELECT); /* right side */
248
      }
249
    }
250
 
28 mv_fox 251
    /* list of selectable items */
1666 mateusz.vi 252
    for (i = 0; i < height; i++) {
28 mv_fox 253
      if (i + offset == res) {
1666 mateusz.vi 254
        mdr_cout_char(ypos + i, xpos, 16, COLOR_SELECTCUR);
255
        mdr_cout_char(ypos + i, xpos+width+1, 17, COLOR_SELECTCUR);
256
        mdr_cout_locate(ypos + i, xpos);
257
        video_putstringfix(ypos + i, xpos+1, COLOR_SELECTCUR, list[i + offset], width);
28 mv_fox 258
      } else if (i + offset < count) {
1666 mateusz.vi 259
        mdr_cout_char(ypos + i, xpos, ' ', COLOR_SELECT);
260
        mdr_cout_char(ypos + i, xpos+width+1, ' ', COLOR_SELECT);
261
        video_putstringfix(ypos + i, xpos+1, COLOR_SELECT, list[i + offset], width);
28 mv_fox 262
      } else {
1666 mateusz.vi 263
        mdr_cout_char_rep(ypos + i, xpos, ' ', COLOR_SELECT, width+2);
28 mv_fox 264
      }
265
    }
1661 mateusz.vi 266
    key = mdr_dos_getkey();
28 mv_fox 267
    if (key == 0x0D) { /* ENTER */
268
      return(res);
269
    } else if (key == 0x148) { /* up */
1948 mateusz.vi 270
      UP_AGAIN:
33 mv_fox 271
      if (res > 0) {
272
        res--;
273
        if (res < offset) offset = res;
1948 mateusz.vi 274
        if (list[res][0] == 0) goto UP_AGAIN;
33 mv_fox 275
      }
28 mv_fox 276
    } else if (key == 0x150) { /* down */
1948 mateusz.vi 277
      DOWN_AGAIN:
33 mv_fox 278
      if (res+1 < count) {
279
        res++;
1666 mateusz.vi 280
        if (res > offset + height - 1) offset = res - (height - 1);
1948 mateusz.vi 281
        if (list[res][0] == 0) goto DOWN_AGAIN;
33 mv_fox 282
      }
283
    } else if (key == 0x147) { /* home */
284
      res = 0;
285
      offset = 0;
286
    } else if (key == 0x14F) { /* end */
287
      res = count - 1;
1666 mateusz.vi 288
      if (res > offset + height - 1) offset = res - (height - 1);
28 mv_fox 289
    } else if (key == 0x1B) {  /* ESC */
290
      return(-1);
78 mv_fox 291
    }/* else {
33 mv_fox 292
      char buf[8];
55 mv_fox 293
      snprintf(buf, sizeof(buf), "0x%02X ", key);
1664 mateusz.vi 294
      video_putstring(1, 0, COLOR_BODY, buf, -1);
78 mv_fox 295
    }*/
28 mv_fox 296
  }
297
}
298
 
1946 mateusz.vi 299
 
1662 mateusz.vi 300
static void newscreen(unsigned char statusbartype) {
624 mateuszvis 301
  const char *msg;
1664 mateusz.vi 302
  mdr_cout_cls(COLOR_BODY);
624 mateuszvis 303
  msg = svarlang_strid(0x00); /* "SVARDOS INSTALLATION" */
1664 mateusz.vi 304
  mdr_cout_char_rep(0, 0, ' ', COLOR_TITLEBAR, 80);
305
  mdr_cout_str(0, 40 - (strlen(msg) >> 1), msg, COLOR_TITLEBAR, 80);
1671 mateusz.vi 306
  mdr_cout_str(0, 80 - strlen(BUILDSTRING), BUILDSTRING, COLOR_TITLEVER, 12);
307
 
79 mv_fox 308
  switch (statusbartype) {
309
    case 1:
624 mateuszvis 310
      msg = svarlang_strid(0x000B); /* "Up/Down = Select entry | Enter = Validate your choice | ESC = Quit to DOS" */
79 mv_fox 311
      break;
312
    case 2:
624 mateuszvis 313
      msg = svarlang_strid(0x0005); /* "Press any key..." */
79 mv_fox 314
      break;
315
    case 3:
316
      msg = "";
317
      break;
318
    default:
624 mateuszvis 319
      msg = svarlang_strid(0x000A); /* "Up/Down = Select entry | Enter = Validate your choice | ESC = Previous screen" */
79 mv_fox 320
      break;
321
  }
1664 mateusz.vi 322
  mdr_cout_char(24, 0, ' ', COLOR_TITLEBAR);
323
  video_putstringfix(24, 1, COLOR_TITLEBAR, msg, 79);
1662 mateusz.vi 324
  mdr_cout_locate(25,0);
28 mv_fox 325
}
326
 
1908 mateusz.vi 327
 
96 mv_fox 328
/* fills a slocales struct accordingly to the value of its keyboff member */
329
static void kblay2slocal(struct slocales *locales) {
624 mateuszvis 330
  const char *m;
96 mv_fox 331
  for (m = kblayouts[locales->keyboff]; *m != 0; m++); /* skip layout name */
332
  m++;
333
  /* skip keyb code and copy it to locales.keybcode */
334
  locales->keybcode = m;
335
  for (; *m != 0; m++);
336
  /* */
337
  locales->codepage = ((unsigned short)m[1] << 8) | m[2];
338
  locales->egafile = m[3];
339
  locales->keybfile = m[4];
340
  locales->keybid = ((unsigned short)m[5] << 8) | m[6];
1908 mateusz.vi 341
  locales->countryid = ((unsigned short)m[7] << 8) | m[8];
96 mv_fox 342
}
343
 
1908 mateusz.vi 344
 
67 mv_fox 345
static int selectlang(struct slocales *locales) {
346
  int choice, x;
624 mateuszvis 347
  const char *msg;
348
  const char *langlist[] = {
67 mv_fox 349
    "English",
1177 mateusz.vi 350
    "Brazilian",
67 mv_fox 351
    "French",
133 mv_fox 352
    "German",
119 mv_fox 353
    "Italian",
67 mv_fox 354
    "Polish",
116 mv_fox 355
    "Russian",
123 mv_fox 356
    "Slovene",
128 mv_fox 357
    "Swedish",
67 mv_fox 358
    "Turkish",
28 mv_fox 359
    NULL
360
  };
361
 
79 mv_fox 362
  newscreen(1);
624 mateuszvis 363
  msg = svarlang_strid(0x0100); /* "Welcome to SvarDOS" */
42 mv_fox 364
  x = 40 - (strlen(msg) >> 1);
1664 mateusz.vi 365
  mdr_cout_str(4, x, msg, COLOR_BODY, 80);
366
  mdr_cout_char_rep(5, x, '=', COLOR_BODY, strlen(msg));
1662 mateusz.vi 367
 
368
  /* center out the string "Please select your language..." */
369
  msg = svarlang_str(1, 1); /* "Please select your language from the list below:" */
370
  if (strlen(msg) > 74) {
1664 mateusz.vi 371
    putstringwrap(8, 1, COLOR_BODY, msg);
1662 mateusz.vi 372
  } else {
1664 mateusz.vi 373
    mdr_cout_str(8, 40 - (strlen(msg) / 2), msg, COLOR_BODY, 80);
1662 mateusz.vi 374
  }
375
 
1666 mateusz.vi 376
  choice = menuselect(11, 9, langlist, -1);
73 mv_fox 377
  if (choice < 0) return(MENUPREV);
1669 mateusz.vi 378
 
67 mv_fox 379
  /* populate locales with default values */
380
  memset(locales, 0, sizeof(struct slocales));
381
  switch (choice) {
382
    case 1:
1179 mateusz.vi 383
      strcpy(locales->lang, "BR");
384
      locales->keyboff = OFFLOC_BR;
385
      locales->keyblen = OFFLEN_BR;
386
      break;
387
    case 2:
67 mv_fox 388
      strcpy(locales->lang, "FR");
389
      locales->keyboff = OFFLOC_FR;
390
      locales->keyblen = OFFLEN_FR;
391
      break;
1177 mateusz.vi 392
    case 3:
133 mv_fox 393
      strcpy(locales->lang, "DE");
394
      locales->keyboff = OFFLOC_DE;
395
      locales->keyblen = OFFLEN_DE;
396
      break;
1177 mateusz.vi 397
    case 4:
119 mv_fox 398
      strcpy(locales->lang, "IT");
399
      locales->keyboff = OFFLOC_IT;
400
      locales->keyblen = OFFLEN_IT;
401
      break;
1177 mateusz.vi 402
    case 5:
67 mv_fox 403
      strcpy(locales->lang, "PL");
404
      locales->keyboff = OFFLOC_PL;
405
      locales->keyblen = OFFLEN_PL;
406
      break;
1177 mateusz.vi 407
    case 6:
116 mv_fox 408
      strcpy(locales->lang, "RU");
409
      locales->keyboff = OFFLOC_RU;
410
      locales->keyblen = OFFLEN_RU;
411
      break;
1177 mateusz.vi 412
    case 7:
123 mv_fox 413
      strcpy(locales->lang, "SI");
414
      locales->keyboff = OFFLOC_SI;
415
      locales->keyblen = OFFLEN_SI;
416
      break;
1177 mateusz.vi 417
    case 8:
128 mv_fox 418
      strcpy(locales->lang, "SV");
419
      locales->keyboff = OFFLOC_SV;
420
      locales->keyblen = OFFLEN_SV;
421
      break;
1177 mateusz.vi 422
    case 9:
67 mv_fox 423
      strcpy(locales->lang, "TR");
424
      locales->keyboff = OFFLOC_TR;
425
      locales->keyblen = OFFLEN_TR;
426
      break;
427
    default:
428
      strcpy(locales->lang, "EN");
429
      locales->keyboff = 0;
430
      locales->keyblen = OFFCOUNT;
431
      break;
432
  }
96 mv_fox 433
  /* populate the slocales struct accordingly to the keyboff member */
434
  kblay2slocal(locales);
67 mv_fox 435
  /* */
73 mv_fox 436
  return(MENUNEXT);
28 mv_fox 437
}
438
 
439
 
67 mv_fox 440
static int selectkeyb(struct slocales *locales) {
96 mv_fox 441
  int menuheight, choice;
442
  if (locales->keyblen == 1) return(MENUNEXT); /* do not ask for keyboard layout if only one is available for given language */
79 mv_fox 443
  newscreen(0);
1664 mateusz.vi 444
  putstringnls(5, 1, COLOR_BODY, 1, 5); /* "SvarDOS supports different keyboard layouts */
1666 mateusz.vi 445
  menuheight = locales->keyblen;
446
  if (menuheight > 11) menuheight = 11;
1665 mateusz.vi 447
  choice = menuselect(10, menuheight, &(kblayouts[locales->keyboff]), locales->keyblen);
96 mv_fox 448
  if (choice < 0) return(MENUPREV);
449
  /* (re)load the keyboard layout & codepage setup */
450
  locales->keyboff += choice;
451
  kblay2slocal(locales);
73 mv_fox 452
  return(MENUNEXT);
67 mv_fox 453
}
454
 
455
 
28 mv_fox 456
/* returns 0 if installation must proceed, non-zero otherwise */
457
static int welcomescreen(void) {
73 mv_fox 458
  int c;
624 mateuszvis 459
  const char *choice[3];
460
  choice[0] = svarlang_strid(0x0001);
461
  choice[1] = svarlang_strid(0x0002);
462
  choice[2] = NULL;
79 mv_fox 463
  newscreen(0);
1664 mateusz.vi 464
  putstringnls(4, 1, COLOR_BODY, 2, 0); /* "You are about to install SvarDOS */
1666 mateusz.vi 465
  c = menuselect(13, 2, choice, -1);
73 mv_fox 466
  if (c < 0) return(MENUPREV);
467
  if (c == 0) return(MENUNEXT);
468
  return(MENUQUIT);
28 mv_fox 469
}
470
 
471
 
1908 mateusz.vi 472
/* returns total disk space of drive drv (in MiB, max 2048, A=1 B=2 etc), or -1 if drive invalid */
1911 mateusz.vi 473
static int disksize(unsigned char drv) {
2157 mateusz.vi 474
  struct diskfree_t df;
1911 mateusz.vi 475
  long res;
35 mv_fox 476
 
2157 mateusz.vi 477
  if (_dos_getdiskfree(drv, &df) != 0) return(-1);
35 mv_fox 478
 
2157 mateusz.vi 479
  res = df.sectors_per_cluster;
480
  res *= df.total_clusters;
481
  res *= df.bytes_per_sector;
1911 mateusz.vi 482
  res >>= 20;
483
  return((int)res);
484
}
485
 
486
 
35 mv_fox 487
/* returns 0 if disk is empty, non-zero otherwise */
1942 mateusz.vi 488
static int diskempty(char drv) {
35 mv_fox 489
  unsigned int rc;
490
  int res;
491
  char buff[8];
492
  struct find_t fileinfo;
1942 mateusz.vi 493
  snprintf(buff, sizeof(buff), "%c:\\*.*", drv);
35 mv_fox 494
  rc = _dos_findfirst(buff, _A_NORMAL | _A_SUBDIR | _A_HIDDEN | _A_SYSTEM, &fileinfo);
495
  if (rc == 0) {
496
    res = 1; /* call successfull means disk is not empty */
28 mv_fox 497
  } else {
35 mv_fox 498
    res = 0;
28 mv_fox 499
  }
35 mv_fox 500
  /* _dos_findclose(&fileinfo); */ /* apparently required only on OS/2 */
28 mv_fox 501
  return(res);
502
}
503
 
200 mateuszvis 504
 
1930 mateusz.vi 505
/* replace all occurences of char a by char b in s */
506
static void strtr(char *s, char a, char b) {
507
  for (;*s != 0; s++) {
508
    if (*s == a) *s = b;
509
  }
510
}
511
 
512
 
898 mateusz.vi 513
/* tries to write an empty file to drive.
514
 * asks DOS to inhibit the int 24h handler for this job, so erros are
515
 * gracefully reported - unfortunately this does not work under FreeDOS because
516
 * the DOS-C kernel does not implement the required flag.
517
 * returns 0 on success (ie. "disk exists and is writeable"). */
1908 mateusz.vi 518
static unsigned short test_drive_write(char drive) {
898 mateusz.vi 519
  unsigned short result = 0;
1908 mateusz.vi 520
  char *buff = "@:\\SVWRTEST.123";
521
  buff[0] = drive;
898 mateusz.vi 522
  _asm {
523
    push ax
524
    push bx
525
    push cx
526
    push dx
527
 
528
    mov ah, 0x6c   /* extended open/create file */
529
    mov bx, 0x2001 /* open for write + inhibit int 24h handler */
530
    xor cx, cx     /* file attributes on the created file */
531
    mov dx, 0x0010 /* create file if does not exist, fail if it exists */
532
    mov si, buff   /* filename to create */
533
    int 0x21
534
    jc FAILURE
535
    /* close the file (handle in AX) */
536
    mov bx, ax
537
    mov ah, 0x3e /* close file */
538
    int 0x21
539
    jc FAILURE
540
    /* delete the file */
541
    mov ah, 0x41 /* delete file pointed out by DS:DX */
542
    mov dx, buff
543
    int 0x21
544
    jnc DONE
545
 
546
    FAILURE:
547
    mov result, ax
548
    DONE:
549
 
550
    pop dx
551
    pop cx
552
    pop bx
553
    pop ax
554
  }
555
  return(result);
556
}
557
 
558
 
1944 mateusz.vi 559
#define MBR_WRITE 3
560
#define MBR_READ 2
561
/* read (action=2) or write (action=3) MBR of driveid (0x80, 0x81..) into buff */
562
static int READ_OR_WRITE_MBR(unsigned char action, char *buff, unsigned char driveid);
563
#pragma aux READ_OR_WRITE_MBR = \
1939 mateusz.vi 564
"push es" \
1944 mateusz.vi 565
"mov al, 1"       /* read 1 sector into memory */ \
1940 mateusz.vi 566
"mov cx, 0x0001"  /* cylinder 0, sector 1 */ \
567
"xor dh, dh"      /* head 0 */ \
1939 mateusz.vi 568
"push ds" \
569
"pop es" \
570
"int 0x13" \
571
"mov ax, 0" /* do not do "xor ax, ax", CF needs to be preserved */ \
572
"jnc DONE" \
573
"inc ax" \
574
"DONE:" \
575
"pop es" \
1944 mateusz.vi 576
parm [ah] [bx] [dl] \
1940 mateusz.vi 577
modify [cx dx] \
1939 mateusz.vi 578
value [ax]
579
 
580
 
1944 mateusz.vi 581
 
1939 mateusz.vi 582
/*
583
 * MBR structure:
584
 *
585
 * Boot signature (word 0xAA55) is at 0x01FE
586
 *
587
 * partition entry 1 is at 0x01BE
588
 *                 2    at 0x01CE
589
 *                 3    at 0x01DE
590
 *                 4    at 0x01EE
591
 *
592
 * a partition entry is:
593
 * 0x00  status byte (active is bit 0x80 set)
594
 * 0x01  CHS addr of first sector (here: HEAD)
595
 * 0x02  CHS addr of first sector (CCSSSSSS) sector in 6 low bits, cylinder high bits in CC
596
 * 0x03  CHS addr of furst sector (here: low 8 bits of cylinder)
597
 * 0x04  Partition type:
598
        0x06/0x08 for CHS FAT16/32
599
        0x0E/0x0C for LBA FAT16/32
600
 * 0x05  CHS addr of last sector (same format as for 1st sector)
601
 * 0x06  CHS addr of last sector (same format as for 1st sector)
602
 * 0x07  CHS addr of last sector (same format as for 1st sector)
603
 * 0x08  LBA addr of first sector (4 bytes) - used sometimes instead of CHS
604
 * 0x0C  number of sectors in partition (4 bytes)
605
 */
606
 
607
struct drivelist {
1940 mateusz.vi 608
  unsigned long start_lba;
1943 mateusz.vi 609
  unsigned long tot_sect;  /* size (of partition), in sectors */
1940 mateusz.vi 610
  unsigned short tot_size; /* size in MiB */
1943 mateusz.vi 611
  unsigned char partid;    /* position of the partition in the MBR (0,1,2,3) */
1944 mateusz.vi 612
  unsigned char hd;        /* 0-3 */
613
  unsigned char dosid;     /* DOS drive id (A=0, B=1...)*/
1939 mateusz.vi 614
};
615
 
1940 mateusz.vi 616
 
617
/* a (very partial) struct mimicking what EDR-DOS uses in int 2Fh,AX=0803h */
618
#pragma pack (push)
619
#pragma pack (0) /* disable the automatic alignment of struct members */
620
struct dos_udsc {
1944 mateusz.vi 621
  unsigned short next_off; /* offset FFFFh if last */
1940 mateusz.vi 622
  unsigned short next_seg;
1944 mateusz.vi 623
  unsigned char hd;        /* physical unit (as in int 13h) */
624
  unsigned char letter;    /* DOS letter drive (A=0, B=1, C=2, ...) */
1940 mateusz.vi 625
  unsigned short sectsize; /* bytes per sector */
626
  unsigned char unknown[15];
627
  unsigned long start_lba; /* LBA address of the partition (only for primary partitions) */
628
};
629
#pragma pack (pop)
630
 
631
 
632
/* get the DOS drive data table list */
2158 mateusz.vi 633
static struct dos_udsc far *get_dos_udsc(void);
634
#pragma aux get_dos_udsc = \
635
"push ds" \
636
"mov ax, 0x0803" \
637
"int 0x2f" /* drive data table list is in DS:DI, error if DI is 0xffff */ \
638
"push ds" \
639
"pop es" \
640
"pop ds" \
641
"cmp di, 0xffff" \
642
"jne DONE" \
643
"xor di, di" \
644
"mov es, di" \
645
"DONE:" \
646
modify [ax] \
647
value [es di]
1940 mateusz.vi 648
 
649
 
1994 mateusz.vi 650
/* returns 0 if fsid is a valid (recognized) filesystem for SvarDOS install  */
1996 mateusz.vi 651
static int is_fstype_valid(unsigned char fsid) {
1994 mateusz.vi 652
  switch (fsid) {
653
    case 0x01: /* FAT-12 in first 32M of disk                                */
654
    case 0x04: /* FAT-16 partition that resides within first 32M of disk     */
655
    case 0x06: /* FAT-16B with 64K+ sectors, must be within first 8G of disk */
656
    case 0x0B: /* FAT-32 with CHS addressing                                 */
657
    case 0x0C: /* FAT-32 with LBA addressing                                 */
658
    case 0x0E: /* FAT-16B with LBA addressing                                */
659
      return(0);
660
    default:
661
      return(-1);
662
  }
663
}
664
 
665
 
1940 mateusz.vi 666
/* reads the MBR and matches its entries to DOS drives
1943 mateusz.vi 667
 * fills the drives array with up to 16 drives (4 partitions * 4 disks)
1940 mateusz.vi 668
 * see https://github.com/SvarDOS/bugz/issues/89 */
1943 mateusz.vi 669
static int get_drives_list(char *buff, struct drivelist *drives) {
1939 mateusz.vi 670
  int i;
1943 mateusz.vi 671
  int listlen = 0;
672
  int drv;
1940 mateusz.vi 673
  struct dos_udsc far *udsc_root = get_dos_udsc();
674
  struct dos_udsc far *udsc_node;
1939 mateusz.vi 675
 
1943 mateusz.vi 676
  for (drv = 0x80; drv < 0x84; drv++) {
1940 mateusz.vi 677
 
1944 mateusz.vi 678
    if (READ_OR_WRITE_MBR(MBR_READ, buff, drv) != 0) continue;
1939 mateusz.vi 679
 
1943 mateusz.vi 680
    /* check boot signature at 0x01fe */
681
    if (*(unsigned short *)(buff + 0x01fe) != 0xAA55) continue;
1939 mateusz.vi 682
 
1943 mateusz.vi 683
    /* iterate over the 4 partitions in the MBR */
684
    for (i = 0; i < 4; i++) {
685
      unsigned char *entry;
1939 mateusz.vi 686
 
1943 mateusz.vi 687
      entry = buff + 0x01BE + (i * 16);
1939 mateusz.vi 688
 
1943 mateusz.vi 689
      /* ignore partition if fs is unknown (non-FAT) */
1994 mateusz.vi 690
      if (is_fstype_valid(entry[4]) != 0) continue;
691
 
1943 mateusz.vi 692
      bzero(&(drives[listlen]), sizeof(struct drivelist));
1944 mateusz.vi 693
      drives[listlen].hd = drv & 3;
1943 mateusz.vi 694
      drives[listlen].partid = i;
695
      drives[listlen].start_lba = ((unsigned long *)entry)[2];
696
      drives[listlen].tot_sect = ((unsigned long *)entry)[3];
1939 mateusz.vi 697
 
2158 mateusz.vi 698
      /* now iterate over DOS drives and try to match one to this MBR entry */
1943 mateusz.vi 699
      udsc_node = udsc_root;
700
      while (udsc_node != NULL) {
701
        if (udsc_node->hd != drv) goto NEXT;
702
        if (udsc_node->start_lba != drives[listlen].start_lba) goto NEXT;
1939 mateusz.vi 703
 
1943 mateusz.vi 704
        /* FOUND! */
1944 mateusz.vi 705
        drives[listlen].dosid = udsc_node->letter;
1943 mateusz.vi 706
        {
707
          unsigned long sz = (drives[listlen].tot_sect * udsc_node->sectsize) >> 20;
708
          drives[listlen].tot_size = (unsigned short)sz;
709
        }
710
        listlen++;
711
        break;
712
 
713
        NEXT:
714
        if (udsc_node->next_off == 0xffff) break;
715
        udsc_node = MK_FP(udsc_node->next_seg, udsc_node->next_off);
716
      } /* iterate over UDSC nodes */
717
    } /* iterate over partition entries of the MBR */
718
  } /* iterate over BIOS disks (0x80, 0x81, ...) */
719
 
720
  return(listlen);
1939 mateusz.vi 721
}
722
 
723
 
1942 mateusz.vi 724
/* displays a list of drives and asks user to choose one for installation
1944 mateusz.vi 725
 * returns a word with bits HHPPLLLLLLLL where:
726
 * HH = hard drive id (0..3)
727
 * PP = position of the partition in MBR (0..3)
728
 * LL... = drive's DOS id (A=0, B=1, C=2, ...) */
1942 mateusz.vi 729
static int selectdrive(void) {
1935 mateusz.vi 730
  char buff[512];
1943 mateusz.vi 731
  struct drivelist drives[16];
732
  char drvlist[16][32]; /* up to 16 drives (4 partitions on 4 disks) */
733
  int i, drvlistlen;
1942 mateusz.vi 734
  const char *menulist[16];
735
  unsigned char driveid = 1; /* fdisk runs on first drive (unless USB boot) */
1935 mateusz.vi 736
 
1940 mateusz.vi 737
  /* read MBR of first HDD */
1943 mateusz.vi 738
  drvlistlen = get_drives_list(buff, drives);
1939 mateusz.vi 739
 
1942 mateusz.vi 740
  /* if no drive found - disk not partitioned? */
741
  if (drvlistlen == 0) {
742
    const char *list[4];
743
    newscreen(0);
744
    list[0] = svarlang_str(0, 3); /* Create a partition automatically */
745
    list[1] = svarlang_str(0, 4); /* Run the FDISK tool */
746
    list[2] = svarlang_str(0, 2); /* Quit to DOS */
747
    list[3] = NULL;
748
    snprintf(buff, sizeof(buff), svarlang_strid(0x0300), SVARDOS_DISK_REQ); /* "ERROR: No drive could be found. Note, that SvarDOS requires at least %d MiB of available disk space */
749
    switch (menuselect(6 + putstringwrap(4, 1, COLOR_BODY, buff), 3, list, -1)) {
750
      case 0:
751
        sprintf(buff, "FDISK /PRI:MAX %u", driveid);
752
        exec(buff);
753
        break;
754
      case 1:
755
        mdr_cout_cls(0x07);
756
        mdr_cout_locate(0, 0);
757
        sprintf(buff, "FDISK %u", driveid);
758
        exec(buff);
759
        break;
760
      case 2:
761
        return(MENUQUIT);
762
      default:
763
        return(-1);
1908 mateusz.vi 764
    }
1942 mateusz.vi 765
    /* write a temporary MBR which only skips the drive (in case BIOS would
766
     * try to boot off the not-yet-ready C: disk) */
767
    sprintf(buff, "FDISK /LOADIPL %u", driveid);
768
    exec(buff); /* writes BOOT.MBR into actual MBR */
769
    newscreen(2);
770
    putstringnls(10, 10, COLOR_BODY, 3, 1); /* "Your computer will reboot now." */
771
    putstringnls(12, 10, COLOR_BODY, 0, 5); /* "Press any key..." */
772
    mdr_dos_getkey();
773
    reboot();
774
    return(MENUQUIT);
775
  }
1908 mateusz.vi 776
 
1943 mateusz.vi 777
  /* build a menu with all drives */
778
  for (i = 0; i < drvlistlen; i++) {
1944 mateusz.vi 779
    snprintf(drvlist[i], sizeof(drvlist[0]), "%c: [%u MiB, hd%c%u]", 'A' + drives[i].dosid, drives[i].tot_size, 'a' + drives[i].hd, drives[i].partid);
1943 mateusz.vi 780
    menulist[i] = drvlist[i];
781
  }
1948 mateusz.vi 782
  menulist[i++] = "";
1942 mateusz.vi 783
  menulist[i++] = svarlang_str(0, 2); /* Quit to DOS */
784
  menulist[i] = NULL;
1943 mateusz.vi 785
 
1942 mateusz.vi 786
  newscreen(0);
1948 mateusz.vi 787
 
1949 mateusz.vi 788
  snprintf(buff, sizeof(buff), "%s", svarlang_strid(0x0307));
1948 mateusz.vi 789
  i = menuselect(7 + putstringwrap(4, 1, COLOR_BODY, buff) /*ypos*/, 10 /*max-height*/, menulist, -1);
1942 mateusz.vi 790
  if (i < 0) {
791
    return(MENUPREV);
792
  } else if (i < drvlistlen) {
1944 mateusz.vi 793
    /* return a bitfield HHPPLLLLLLLL
794
     * HH = hard drive id (0..3)
795
     * PP = position of the partition in MBR (0..3)
796
     * LL... = drive's DOS id (A=0, B=1, C=2, ...) */
797
    return((drives[i].partid << 8) | (drives[i].hd << 10) | drives[i].dosid);
1942 mateusz.vi 798
  }
1935 mateusz.vi 799
 
1942 mateusz.vi 800
  return(MENUQUIT);
801
}
1935 mateusz.vi 802
 
1944 mateusz.vi 803
/* hd_drv is a bitfield HHPPLLLLLLLL
804
 * HH = hard drive id (0..3)
805
 * PP = position of the partition in MBR (0..3)
806
 * LL... = drive's DOS id (A=0, B=1, C=2, ...) */
1942 mateusz.vi 807
static int preparedrive(int hd_drv) {
808
  unsigned char selecteddrive;
1944 mateusz.vi 809
  unsigned char driveid, partid;
1942 mateusz.vi 810
  char cselecteddrive;
811
  int choice;
812
  char buff[512];
556 mateuszvis 813
 
1942 mateusz.vi 814
  /* decode hd and drive id from hd_drv */
1944 mateusz.vi 815
  selecteddrive = hd_drv & 0xff; /* DOS drive letter (A=0. B=1, C=2 etc) */
816
  partid = (hd_drv >> 8) & 3;    /* position of partition in MBR (0..3) */
817
  driveid = (hd_drv >> 10);      /* HDD identifier (0..3) */
556 mateuszvis 818
 
1944 mateusz.vi 819
  cselecteddrive = 'A' + selecteddrive;
1935 mateusz.vi 820
 
1942 mateusz.vi 821
  TRY_AGAIN:
1935 mateusz.vi 822
 
1942 mateusz.vi 823
  /* if not formatted, propose to format it right away (try to create a directory) */
824
  if (test_drive_write(cselecteddrive) != 0) {
825
    const char *list[3];
79 mv_fox 826
    newscreen(0);
1942 mateusz.vi 827
    snprintf(buff, sizeof(buff), svarlang_str(3, 3), cselecteddrive); /* "ERROR: Drive %c: seems to be unformated. Do you wish to format it?") */
828
    mdr_cout_str(7, 1, buff, COLOR_BODY, 80);
556 mateuszvis 829
 
1942 mateusz.vi 830
    snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
831
    list[0] = buff;
832
    list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
833
    list[2] = NULL;
556 mateuszvis 834
 
1942 mateusz.vi 835
    choice = menuselect(12, 2, list, -1);
836
    if (choice < 0) return(MENUPREV);
837
    if (choice == 1) return(MENUQUIT);
838
    mdr_cout_cls(0x07);
839
    mdr_cout_locate(0, 0);
840
    snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
841
    exec(buff);
842
    goto TRY_AGAIN;
28 mv_fox 843
  }
1942 mateusz.vi 844
 
845
  /* check total disk space */
1944 mateusz.vi 846
  if (disksize(selecteddrive+1) < SVARDOS_DISK_REQ) {
1942 mateusz.vi 847
    int y = 9;
848
    newscreen(2);
849
    snprintf(buff, sizeof(buff), svarlang_strid(0x0304), cselecteddrive, SVARDOS_DISK_REQ); /* "ERROR: Drive %c: is not big enough! SvarDOS requires a disk of at least %d MiB." */
850
    y += putstringwrap(y, 1, COLOR_BODY, buff);
851
    putstringnls(++y, 1, COLOR_BODY, 0, 5); /* "Press any key..." */
852
    mdr_dos_getkey();
853
    return(MENUPREV);
854
  }
855
 
856
  /* is the disk empty? */
857
  newscreen(0);
858
  if (diskempty(cselecteddrive) != 0) {
859
    const char *list[3];
860
    int y = 6;
861
    snprintf(buff, sizeof(buff), svarlang_strid(0x0305), cselecteddrive); /* "ERROR: Drive %c: not empty" */
862
    y += putstringwrap(y, 1, COLOR_BODY, buff);
863
 
864
    snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
865
    list[0] = buff;
866
    list[1] = svarlang_strid(0x0002); /* "Quit to DOS" */
867
    list[2] = NULL;
868
 
869
    choice = menuselect(++y, 2, list, -1);
870
    if (choice < 0) return(MENUPREV);
871
    if (choice == 1) return(MENUQUIT);
872
    mdr_cout_cls(0x07);
873
    mdr_cout_locate(0, 0);
874
    snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
875
    exec(buff);
876
    goto TRY_AGAIN;
877
  } else {
878
    /* final confirmation */
879
    const char *list[3];
880
    list[0] = svarlang_strid(0x0001); /* Install SvarDOS */
881
    list[1] = svarlang_strid(0x0002); /* Quit to DOS */
882
    list[2] = NULL;
883
    snprintf(buff, sizeof(buff), svarlang_strid(0x0306), cselecteddrive); /* "The installation of SvarDOS to %c: is about to begin." */
884
    mdr_cout_str(7, 40 - (strlen(buff) / 2), buff, COLOR_BODY, 80);
885
    choice = menuselect(10, 2, list, -1);
886
    if (choice < 0) return(MENUPREV);
887
    if (choice == 1) return(MENUQUIT);
1944 mateusz.vi 888
 
889
    /* update the disk's MBR, transfer the boot system, make sure the partition
890
     * is ACTIVE and create a TEMP directory to copy SVP files over */
1942 mateusz.vi 891
    snprintf(buff, sizeof(buff), "SYS %c: > NUL", cselecteddrive);
892
    exec(buff);
1944 mateusz.vi 893
    sprintf(buff, "FDISK /MBR %u", driveid + 1);
1942 mateusz.vi 894
    exec(buff);
1944 mateusz.vi 895
 
896
    if (READ_OR_WRITE_MBR(MBR_READ, buff, driveid | 0x80) == 0) {
897
      /* active flags for part 0,1,2,3 are at offsets 0x01BE, 0x01CE, 0x01DE, 0x01EE */
898
      unsigned char i, flag_before, changed = 0;
899
      unsigned short memoffset = 0x01BE; /* first partition flag is here */
900
      for (i = 0; i < 4; i++) {
901
        flag_before = buff[memoffset];
902
        buff[memoffset] &= 127;
903
        if (i == partid) buff[memoffset] |= 0x80;
904
        if (flag_before != buff[memoffset]) changed++;
905
        memoffset += 16; /* jump to next partition entry */
906
      }
907
      /* do I need to update the MBR? */
908
      if (changed != 0) READ_OR_WRITE_MBR(MBR_WRITE, buff, driveid | 0x80);
909
    }
910
 
911
    snprintf(buff, sizeof(buff), "%c:\\TEMP", cselecteddrive);
1942 mateusz.vi 912
    mkdir(buff);
913
    return(0);
914
  }
28 mv_fox 915
}
916
 
917
 
280 mateuszvis 918
/* generates locales-related configurations and writes them to file (this
919
 * is used to compute autoexec.bat content) */
920
static void genlocalesconf(FILE *fd, const struct slocales *locales) {
921
 
922
  fprintf(fd, "SET LANG=%s\r\n", locales->lang);
923
 
924
  if (locales->egafile > 0) {
925
    fprintf(fd, "DISPLAY CON=(EGA,,1)\r\n");
926
    if (locales->egafile == 1) {
927
      fprintf(fd, "MODE CON CP PREPARE=((%u) %%DOSDIR%%\\CPI\\EGA.CPX)\r\n", locales->codepage);
928
    } else {
1908 mateusz.vi 929
      fprintf(fd, "MODE CON CP PREPARE=((%u) %%DOSDIR%%\\CPI\\EGA%u.CPX)\r\n", locales->codepage, locales->egafile);
280 mateuszvis 930
    }
931
    fprintf(fd, "MODE CON CP SELECT=%u\r\n", locales->codepage);
932
  }
933
 
934
  if (locales->keybfile > 0) {
1659 bttr 935
    fprintf(fd, "KEYB %s,%d,%%DOSDIR%%\\", locales->keybcode, locales->codepage);
280 mateuszvis 936
    if (locales->keybfile == 1) {
937
      fprintf(fd, "KEYBOARD.SYS");
938
    } else {
1908 mateusz.vi 939
      fprintf(fd, "KEYBRD%u.SYS", locales->keybfile);
280 mateuszvis 940
    }
941
    if (locales->keybid != 0) fprintf(fd, " /ID:%d", locales->keybid);
942
    fprintf(fd, "\r\n");
943
  }
944
}
945
 
946
 
1946 mateusz.vi 947
/* get the DOS "current drive" (0=A:, 1=B:, etc) */
948
static unsigned char get_cur_drive(void);
949
#pragma aux get_cur_drive = \
950
"mov ah, 0x19" /* DOS 1+ GET CURRENT DEFAULT DRIVE */ \
951
"int 0x21" \
952
modify [ah] \
953
value [al]
954
 
955
 
956
/* generates configuration files on the dest drive, this is run once system
957
 * booted successfully on the dst drive (postinst stage) */
1950 mateusz.vi 958
static void bootfilesgen(void) {
28 mv_fox 959
  char buff[128];
960
  FILE *fd;
1946 mateusz.vi 961
  unsigned char bootdrv = get_cur_drive() + 'A';
1950 mateusz.vi 962
  struct slocales locales;
1930 mateusz.vi 963
 
1950 mateusz.vi 964
  /* load locales from ZLOCALES.DAT */
965
  fd = fopen("ZLOCALES.DAT", "rb");
966
  if (fd == NULL) return;
967
  fread(&locales, sizeof(struct slocales), 1, fd);
968
  fclose(fd);
969
 
970
  svarlang_load("INSTALL.LNG", locales.lang);
971
 
1930 mateusz.vi 972
  /****************
973
   * CONFIG.SYS ***
974
   ****************/
1946 mateusz.vi 975
  snprintf(buff, sizeof(buff), "%c:\\CONFIG.SYS", bootdrv);
53 mv_fox 976
  fd = fopen(buff, "wb");
977
  if (fd == NULL) return;
1751 mateusz.vi 978
  fprintf(fd, "; SvarDOS kernel configuration\r\n"
979
              "\r\n"
980
              "; highest allowed drive letter\r\n"
981
              "LASTDRIVE=Z\r\n"
982
              "\r\n"
983
              "; max. number of files that programs are allowed to open simultaneously\r\n"
984
              "FILES=25\r\n");
985
  fprintf(fd, "\r\n"
986
              "; XMS memory driver\r\n"
1930 mateusz.vi 987
              "DEVICE=%c:\\SVARDOS\\HIMEMX.EXE\r\n", bootdrv);
1751 mateusz.vi 988
  fprintf(fd, "\r\n"
989
              "; try moving DOS to upper memory, then to high memory\r\n"
990
              "DOS=UMB,HIGH\r\n");
991
  fprintf(fd, "\r\n"
1930 mateusz.vi 992
              "; command interpreter (shell) location and environment size\r\n"
993
              "SHELL=%c:\\COMMAND.COM /E:512 /P\r\n", bootdrv);
1751 mateusz.vi 994
  fprintf(fd, "\r\n"
1908 mateusz.vi 995
              "; NLS configuration\r\n");
1950 mateusz.vi 996
  fprintf(fd, "COUNTRY=%03u,%u,%c:\\SVARDOS\\COUNTRY.SYS\r\n", locales.countryid, locales.codepage, bootdrv);
1751 mateusz.vi 997
  fprintf(fd, "\r\n"
998
              "; CD-ROM driver initialization\r\n"
1930 mateusz.vi 999
              ";DEVICE=%c:\\DRIVERS\\VIDECDD\\VIDE-CDD.SYS /D:SVCD0001\r\n", bootdrv);
53 mv_fox 1000
  fclose(fd);
1930 mateusz.vi 1001
 
1002
  /****************
1003
   * AUTOEXEC.BAT *
1004
   ****************/
1005
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\AUTOEXEC.BAT", bootdrv);
28 mv_fox 1006
  fd = fopen(buff, "wb");
1930 mateusz.vi 1007
  if (fd == NULL) {
1008
    return;
1009
  } else {
1010
    char *autoexec_bat1 =
1011
      "@ECHO OFF\r\n"
1935 mateusz.vi 1012
      "SET TEMP=#:\\TEMP\r\n"
1013
      "SET DOSDIR=#:\\SVARDOS\r\n"
1930 mateusz.vi 1014
      "SET NLSPATH=%DOSDIR%\\NLS\r\n"
1015
      "SET DIRCMD=/O/P\r\n"
1946 mateusz.vi 1016
      "SET WATTCP.CFG=%DOSDIR%\r\n"
1930 mateusz.vi 1017
      "PATH %DOSDIR%\r\n"
1018
      "PROMPT $P$G\r\n"
1019
      "\r\n"
1020
      "REM enable CPU power saving\r\n"
1021
      "FDAPM ADV:REG\r\n"
1022
      "\r\n";
1023
    char *autoexec_bat2 =
1024
      "REM Uncomment the line below for CDROM support\r\n"
1025
      "REM SHSUCDX /d:SVCD0001\r\n"
1026
      "\r\n"
1027
      "ECHO.\r\n";
1028
 
1935 mateusz.vi 1029
    /* replace all '#' occurences by bootdrive */
1030
    strtr(autoexec_bat1, '#', bootdrv);
1930 mateusz.vi 1031
 
1032
    /* write all to file */
1033
    fputs(autoexec_bat1, fd);
2169 mateusz.vi 1034
    /* insert provox initialization if to be installed */
1035
    if (fileexists("PROVOX.SVP")) {
1036
      fprintf(fd, "%c:\\DRIVERS\\PROVOX\\PROVOX.EXE\r\n", bootdrv);
1037
      fprintf(fd, "%c:\\DRIVERS\\PROVOX\\PV.EXE BNS\r\n", bootdrv);
1038
    }
1950 mateusz.vi 1039
    genlocalesconf(fd, &locales);
1930 mateusz.vi 1040
    fputs(autoexec_bat2, fd);
1041
 
1042
    fprintf(fd, "ECHO %s\r\n", svarlang_strid(0x0600)); /* "Welcome to SvarDOS!" */
1043
    fclose(fd);
1044
  }
1045
 
200 mateuszvis 1046
  /*** CREATE DIRECTORY FOR CONFIGURATION FILES ***/
1930 mateusz.vi 1047
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS", bootdrv);
200 mateuszvis 1048
  mkdir(buff);
1930 mateusz.vi 1049
 
1050
  /****************
1051
   * PKG.CFG      *
1052
   ****************/
1935 mateusz.vi 1053
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\PKG.CFG", bootdrv);
277 mateuszvis 1054
  fd = fopen(buff, "wb");
1930 mateusz.vi 1055
  if (fd == NULL) {
1056
    return;
1057
  } else {
1058
    char *pkg_cfg =
1059
      "# pkg config file - specifies locations where packages should be installed\r\n"
1060
      "\r\n"
1061
      "# System boot drive\r\n"
1935 mateusz.vi 1062
      "BOOTDRIVE @\r\n"
1930 mateusz.vi 1063
      "\r\n"
1064
      "# DOS core binaries\r\n"
1065
      "DIR BIN @:\\SVARDOS\r\n"
1066
      "\r\n"
1067
      "# Programs\r\n"
1068
      "DIR PROGS @:\\\r\n"
1069
      "\r\n"
1070
      "# Games \r\n"
1071
      "DIR GAMES @:\\\r\n"
1072
      "\r\n"
1073
      "# Drivers\r\n"
1074
      "DIR DRIVERS @:\\DRIVERS\r\n"
1075
      "\r\n"
1076
      "# Development tools\r\n"
1077
      "DIR DEVEL @:\\DEVEL\r\n";
1078
 
1079
    /* replace all @ by the actual boot drive */
1080
    strtr(pkg_cfg, '@', bootdrv);
1081
 
1082
    /* write to file */
1083
    fputs(pkg_cfg, fd);
1084
    fclose(fd);
1085
  }
1086
 
1946 mateusz.vi 1087
  /****************
1088
   * PICOTCP      *
1089
   ****************/
1930 mateusz.vi 1090
  /* TODO (or not? maybe not that useful) */
1091
 
1946 mateusz.vi 1092
  /****************
1093
   * WATTCP.CFG   *
1094
   ****************/
1095
  snprintf(buff, sizeof(buff), "%c:\\SVARDOS\\WATTCP.CFG", bootdrv);
303 mateuszvis 1096
  fd = fopen(buff, "wb");
1097
  if (fd == NULL) return;
1098
  fprintf(fd, "my_ip = dhcp\r\n"
1099
              "#my_ip = 192.168.0.7\r\n"
1100
              "#netmask = 255.255.255.0\r\n"
1101
              "#nameserver = 192.168.0.1\r\n"
1102
              "#nameserver = 192.168.0.2\r\n"
554 mateuszvis 1103
              "#gateway = 192.168.0.1\r\n");
303 mateuszvis 1104
  fclose(fd);
1946 mateusz.vi 1105
 
1106
  /****************
1107
   * POSTINST.BAT *
1108
   ****************/
1109
  /* create the postinst.bat file for actual installation of packages */
1950 mateusz.vi 1110
  fd = fopen("POSTINST.BAT", "wb");
1111
  if (fd == NULL) return;
1946 mateusz.vi 1112
  fprintf(fd,
1113
    "@ECHO OFF\r\n"
1114
    "SET DOSDIR=%c:\\SVARDOS\r\n"
1115
    "PATH %%DOSDIR%%\r\n"
1116
    "ECHO INSTALLING PACKAGES\r\n"
1117
    "COPY \\COMMAND.COM \\CMD.COM\r\n" /* move COMMAND.COM so it does not clashes with the installation of the SVARCOM package */
1118
    "SET COMSPEC=%c:\\CMD.COM\r\n"
1119
    "DEL \\AUTOEXEC.BAT\r\n"
1120
    "COPY AUTOEXEC.BAT \\\r\n"
1950 mateusz.vi 1121
    "DEL AUTOEXEC.BAT\r\n"
1122
    "DEL ZLOCALES.DAT\r\n"
1946 mateusz.vi 1123
    "DEL \\COMMAND.COM\r\n"
1124
    "DEL \\KERNEL.SYS\r\n" /* KERNEL.SYS will be installed from the package in a moment */
1982 mateusz.vi 1125
    "FOR %%%%P IN (*.SVP) DO PKG INOWARN %%%%P\r\n" /* install packages (with warnings muted) */
1946 mateusz.vi 1126
    "DEL *.SVP\r\n", bootdrv, bootdrv);
1127
 
1128
  /* restore COMSPEC and do some cleanup */
1129
  fprintf(fd, "DEL pkg.exe\r\n"
1130
              "DEL install.com\r\n"
1131
              "DEL install.lng\r\n"
1132
              "SET COMSPEC=\\COMMAND.COM\r\n"
1133
              "DEL \\CMD.COM\r\n");
1134
  /* print out the "installation over" message (load codepage first, now that MODE is installed) */
1950 mateusz.vi 1135
  genlocalesconf(fd, &locales);
1946 mateusz.vi 1136
  fprintf(fd, "ECHO.\r\n"
1137
              "ECHO ");
1138
  fprintf(fd, svarlang_strid(0x0502)); /* "SvarDOS installation is over. Please restart your computer now" */
1139
  fprintf(fd, "\r\n"
1140
              "ECHO.\r\n");
1141
  fclose(fd);
1142
 
28 mv_fox 1143
}
1144
 
1145
 
1942 mateusz.vi 1146
static int copypackages(char drvletter, const struct slocales *locales) {
192 mateuszvis 1147
  char pkglist[512];
30 mv_fox 1148
  int i, pkglistlen;
192 mateuszvis 1149
  size_t pkglistflen;
280 mateuszvis 1150
  char buff[1024]; /* must be *at least* 1 sector big for efficient file copying */
1151
  FILE *fd = NULL;
192 mateuszvis 1152
  char *pkgptr;
1942 mateusz.vi 1153
 
79 mv_fox 1154
  newscreen(3);
1942 mateusz.vi 1155
 
192 mateuszvis 1156
  /* load pkg list */
1157
  fd = fopen("install.lst", "rb");
1158
  if (fd == NULL) {
1664 mateusz.vi 1159
    mdr_cout_str(10, 30, "ERROR: INSTALL.LST NOT FOUND", COLOR_BODY, 80);
1661 mateusz.vi 1160
    mdr_dos_getkey();
192 mateuszvis 1161
    return(-1);
1162
  }
1125 mateusz.vi 1163
  pkglistflen = fread(pkglist, 1, sizeof(pkglist) - 2, fd);
192 mateuszvis 1164
  fclose(fd);
1125 mateusz.vi 1165
  if (pkglistflen == sizeof(pkglist) - 2) {
1664 mateusz.vi 1166
    mdr_cout_str(10, 30, "ERROR: INSTALL.LST TOO LARGE", COLOR_BODY, 80);
1661 mateusz.vi 1167
    mdr_dos_getkey();
192 mateuszvis 1168
    return(-1);
1169
  }
1125 mateusz.vi 1170
  /* mark the end of list */
1171
  pkglist[pkglistflen] = 0;
1172
  pkglist[pkglistflen + 1] = 0xff;
192 mateuszvis 1173
  /* replace all \r and \n chars by 0 bytes, and count the number of packages */
1174
  pkglistlen = 0;
1175
  for (i = 0; i < pkglistflen; i++) {
1176
    switch (pkglist[i]) {
1177
      case '\n':
1178
        pkglistlen++;
1179
        /* FALLTHRU */
1180
      case '\r':
1181
        pkglist[i] = 0;
1182
        break;
1183
    }
1184
  }
280 mateuszvis 1185
 
1930 mateusz.vi 1186
  /* copy pkg.exe, install.com and install.lng to the new drive, along with all packages */
1942 mateusz.vi 1187
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\PKG.EXE", drvletter);
1930 mateusz.vi 1188
  fcopy(buff, buff + 8, buff, sizeof(buff));
1942 mateusz.vi 1189
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\INSTALL.COM", drvletter);
1930 mateusz.vi 1190
  fcopy(buff, buff + 8, buff, sizeof(buff));
1942 mateusz.vi 1191
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\INSTALL.LNG", drvletter);
1930 mateusz.vi 1192
  fcopy(buff, buff + 8, buff, sizeof(buff));
1193
 
2169 mateusz.vi 1194
  /* copy the PROVOX driver, if present */
1195
  if (fileexists("provox.exe")) {
1196
    snprintf(buff, sizeof(buff), "%c:\\TEMP\\PROVOX.EXE", drvletter);
1197
    fcopy(buff, buff + 8, buff, sizeof(buff));
1198
    snprintf(buff, sizeof(buff), "%c:\\TEMP\\PV.EXE", drvletter);
1199
    fcopy(buff, buff + 8, buff, sizeof(buff));
1200
  }
1201
 
280 mateuszvis 1202
  /* copy packages */
192 mateuszvis 1203
  for (i = 0;; i++) {
1125 mateusz.vi 1204
    RETRY_ENTIRE_LIST:
1205
 
192 mateuszvis 1206
    /* move forward to nearest entry or end of list */
1125 mateusz.vi 1207
    for (pkgptr = pkglist; *pkgptr == 0; pkgptr++);
1208
    if (*pkgptr == 0xff) break; /* end of list: means all packages have been processed */
1209
 
1210
    /* is this package present on the floppy disk? */
1211
    TRY_NEXTPKG:
1212
    sprintf(buff, "%s.svp", pkgptr);
1669 mateusz.vi 1213
    if (!fileexists(buff)) {
1125 mateusz.vi 1214
      while (*pkgptr != 0) pkgptr++;
1215
      while (*pkgptr == 0) pkgptr++;
1216
      /* end of list? ask for next floppy, there's nothing interesting left on this one */
1217
      if (*pkgptr == 0xff) {
1664 mateusz.vi 1218
        putstringnls(12, 1, COLOR_BODY, 4, 1); /* "INSERT THE DISK THAT CONTAINS THE REQUIRED FILE AND PRESS ANY KEY" */
1661 mateusz.vi 1219
        mdr_dos_getkey();
1664 mateusz.vi 1220
        video_putstringfix(12, 1, COLOR_BODY, "", 80); /* erase the 'insert disk' message */
1125 mateusz.vi 1221
        goto RETRY_ENTIRE_LIST;
1222
      }
1223
      goto TRY_NEXTPKG;
1224
    }
1225
 
1953 mateusz.vi 1226
    /* copy the package */
1227
    snprintf(buff, sizeof(buff), svarlang_strid(0x0400), i+1, pkglistlen, pkgptr); /* "Copying package %d/%d: %s" */
36 mv_fox 1228
    strcat(buff, "       ");
1664 mateusz.vi 1229
    mdr_cout_str(10, 1, buff, COLOR_BODY, 40);
1125 mateusz.vi 1230
 
1231
    /* proceed with package copy */
1942 mateusz.vi 1232
    sprintf(buff, "%c:\\TEMP\\%s.svp", drvletter, pkgptr);
1930 mateusz.vi 1233
    if (fcopy(buff, buff + 8, buff, sizeof(buff)) != 0) {
1664 mateusz.vi 1234
      mdr_cout_str(10, 30, "READ ERROR", COLOR_BODY, 80);
1661 mateusz.vi 1235
      mdr_dos_getkey();
192 mateuszvis 1236
      return(-1);
55 mv_fox 1237
    }
1125 mateusz.vi 1238
    /* jump to next entry or end of list and zero out the pkg name in the process */
1239
    while ((*pkgptr != 0) && (*pkgptr != 0xff)) {
1240
      *pkgptr = 0;
1241
      pkgptr++;
1242
    }
28 mv_fox 1243
  }
1934 mateusz.vi 1244
 
1950 mateusz.vi 1245
  /* dump locales into ZLOCALES.DAT so the 2nd stage install can get them back */
1246
  snprintf(buff, sizeof(buff), "%c:\\TEMP\\ZLOCALES.DAT", drvletter);
1934 mateusz.vi 1247
  fd = fopen(buff, "wb");
1248
  if (fd == NULL) return(-1);
1950 mateusz.vi 1249
  fwrite(locales, sizeof(struct slocales), 1, fd);
280 mateuszvis 1250
  fclose(fd);
1251
 
1946 mateusz.vi 1252
  /* prepare a dummy autoexec.bat that will exec install and call temp\postinst.bat */
1942 mateusz.vi 1253
  snprintf(buff, sizeof(buff), "%c:\\autoexec.bat", drvletter);
280 mateuszvis 1254
  fd = fopen(buff, "wb");
1255
  if (fd == NULL) return(-1);
1256
  fprintf(fd, "@ECHO OFF\r\n"
1950 mateusz.vi 1257
              "CD TEMP\r\n"
2169 mateusz.vi 1258
              "IF EXIST PROVOX.EXE PROVOX.EXE\r\n"
1259
              "IF EXIST PV.EXE PV BNS\r\n"
1946 mateusz.vi 1260
              "install\r\n"   /* installer will run in 2nd stage (generating autoexec.bat, pkg.cfg and stuff) */
280 mateuszvis 1261
              "postinst.bat\r\n");
1262
  fclose(fd);
1263
 
192 mateuszvis 1264
  return(0);
28 mv_fox 1265
}
1266
 
1267
 
42 mv_fox 1268
static void finalreboot(void) {
56 mv_fox 1269
  int y = 9;
79 mv_fox 1270
  newscreen(2);
1673 mateusz.vi 1271
  y += putstringnls(y, 1, COLOR_BODY, 5, 0); /* "Your computer will reboot now." */
1272
  y += putstringnls(y, 1, COLOR_BODYWARN, 5, 1); /* Please remove the installation disk from your drive" */
1664 mateusz.vi 1273
  putstringnls(++y, 1, COLOR_BODY, 0, 5); /* "Press any key..." */
1661 mateusz.vi 1274
  mdr_dos_getkey();
42 mv_fox 1275
  reboot();
1276
}
1277
 
1278
 
2158 mateusz.vi 1279
static void reinit_ega(void);
1280
#pragma aux reinit_ega = \
1281
"mov ah, 0x0f" /* get current video mode */ \
1282
"int 0x10"     /* al contains the current video mode now */ \
1283
"or al, 128"   /* set AL's high bit so BIOS does not flush VRAM (EGA+) */ \
1284
"xor ah, ah"   /* re-set video mode (to whatever is set in AL) */ \
1285
"int 0x10" \
1286
modify [ax bx]
1287
 
1288
 
192 mateuszvis 1289
static void loadcp(const struct slocales *locales) {
42 mv_fox 1290
  char buff[64];
67 mv_fox 1291
  if (locales->codepage == 437) return;
1662 mateusz.vi 1292
  mdr_cout_locate(1, 0);
67 mv_fox 1293
  if (locales->egafile == 1) {
310 mateuszvis 1294
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA.CPX) > NUL", locales->codepage);
42 mv_fox 1295
  } else {
310 mateuszvis 1296
    snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA%d.CPX) > NUL", locales->codepage, locales->egafile);
42 mv_fox 1297
  }
1918 mateusz.vi 1298
  exec(buff);
67 mv_fox 1299
  snprintf(buff, sizeof(buff), "MODE CON CP SEL=%u > NUL", locales->codepage);
1918 mateusz.vi 1300
  exec(buff);
42 mv_fox 1301
  /* below I re-init the video controller - apparently this is required if
65 mv_fox 1302
   * I want the new glyph symbols to be actually applied, at least some
1303
   * (broken?) BIOSes, like VBox, apply glyphs only at next video mode change */
2158 mateusz.vi 1304
  reinit_ega();
42 mv_fox 1305
}
1306
 
200 mateuszvis 1307
 
1671 mateusz.vi 1308
int main(void) {
1950 mateusz.vi 1309
  struct slocales locales;
28 mv_fox 1310
  int targetdrv;
73 mv_fox 1311
  int action;
28 mv_fox 1312
 
1911 mateusz.vi 1313
  /* setup an internal int 24h handler ("always fail") so DOS does not output
1314
   * the ugly "abort, retry, fail" messages */
1918 mateusz.vi 1315
  install_int24();
908 mateusz.vi 1316
 
1930 mateusz.vi 1317
  /* init screen and detect mono adapters */
1318
  if (mdr_cout_init(NULL, NULL) == 0) {
1319
    /* overload color scheme with mono settings */
1320
    COLOR_TITLEBAR = 0x70;
1321
    COLOR_TITLEVER = 0x70;
1322
    COLOR_BODY = 0x07;
1323
    COLOR_BODYWARN = 0x07;
1324
    COLOR_SELECT = 0x70;
1325
    COLOR_SELECTCUR = 0x07;
1326
  }
1327
 
1328
  /* is it stage 2 of the installation? */
1950 mateusz.vi 1329
  if (fileexists("ZLOCALES.DAT")) goto GENCONF;
1930 mateusz.vi 1330
 
1671 mateusz.vi 1331
  /* read the svardos build revision (from floppy label) */
1332
  {
1333
    const char *fspec = "*.*";
1334
    const char *res = (void*)0x9E; /* default DTA is at PSP:80h, field 1Eh of DTA is the ASCIZ file name */
868 mateusz.vi 1335
 
1671 mateusz.vi 1336
    _asm {
1337
      push cx
1338
      push dx
1339
 
1340
      mov ax, 0x4e00  /* findfirst */
1341
      mov cx, 0x08    /* file attr mask, 0x08 = volume label */
1342
      mov dx, fspec
1343
      int 0x21
1344
      jnc good
1672 mateusz.vi 1345
      mov bx, res
1346
      mov [bx], byte ptr 0
1671 mateusz.vi 1347
      good:
1348
 
1349
      pop dx
1350
      pop cx
1351
    }
1352
 
1353
    memcpy(BUILDSTRING, res, 12);
1354
  }
1355
 
73 mv_fox 1356
 SelectLang:
1950 mateusz.vi 1357
  action = selectlang(&locales); /* welcome to svardos, select your language */
1930 mateusz.vi 1358
  if (action != MENUNEXT) goto QUIT;
1950 mateusz.vi 1359
  loadcp(&locales);
1360
  svarlang_load("INSTALL.LNG", locales.lang); /* NLS support */
865 mateusz.vi 1361
 
1950 mateusz.vi 1362
  action = selectkeyb(&locales);  /* what keyb layout should we use? */
1930 mateusz.vi 1363
  if (action == MENUQUIT) goto QUIT;
1908 mateusz.vi 1364
  if (action == MENUPREV) goto SelectLang;
73 mv_fox 1365
 
1366
 WelcomeScreen:
190 mateuszvis 1367
  action = welcomescreen(); /* what svardos is, ask whether to run live dos or install */
1930 mateusz.vi 1368
  if (action == MENUQUIT) goto QUIT;
1950 mateusz.vi 1369
  if (action == MENUPREV) goto SelectLang;
1669 mateusz.vi 1370
 
1942 mateusz.vi 1371
 SelDriveScreen:
1372
  targetdrv = selectdrive();
1930 mateusz.vi 1373
  if (targetdrv == MENUQUIT) goto QUIT;
73 mv_fox 1374
  if (targetdrv == MENUPREV) goto WelcomeScreen;
1942 mateusz.vi 1375
 
1376
  action = preparedrive(targetdrv); /* what drive should we install to? check avail. space */
1377
  if (action == MENUQUIT) goto QUIT;
1378
  if (action == MENUPREV) goto SelDriveScreen;
1944 mateusz.vi 1379
  targetdrv = (targetdrv & 0xff) + 'A'; /* convert the part+hd+drv value to a DOS letter */
1942 mateusz.vi 1380
 
1381
  /* copy packages to dst drive */
1950 mateusz.vi 1382
  if (copypackages(targetdrv, &locales) != 0) goto QUIT;
1930 mateusz.vi 1383
  finalreboot(); /* remove the install medium and reboot */
73 mv_fox 1384
 
1930 mateusz.vi 1385
  goto QUIT;
1386
 
1387
 GENCONF: /* second stage of the installation (run from the destination disk) */
1950 mateusz.vi 1388
  bootfilesgen(); /* generate boot files and other configurations */
1930 mateusz.vi 1389
 
1390
 QUIT:
1662 mateusz.vi 1391
  mdr_cout_locate(0, 0);
1392
  mdr_cout_close();
28 mv_fox 1393
  return(0);
1394
}