Subversion Repositories SvarDOS

Rev

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

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