Subversion Repositories SvarDOS

Rev

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