Subversion Repositories SvarDOS

Rev

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

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