Subversion Repositories SvarDOS

Rev

Rev 55 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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