Subversion Repositories SvarDOS

Rev

Rev 30 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30 Rev 33
Line 69... Line 69...
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) res--;
74
      if (res > 0) {
-
 
75
        res--;
-
 
76
        if (res < offset) offset = res;
-
 
77
      }
75
    } else if (key == 0x150) { /* down */
78
    } else if (key == 0x150) { /* down */
76
      if (res+1 < count) res++;
79
      if (res+1 < count) {
-
 
80
        res++;
-
 
81
        if (res > offset + height - 3) offset = res - (height - 3);
-
 
82
      }
-
 
83
    } else if (key == 0x147) { /* home */
-
 
84
      res = 0;
-
 
85
      offset = 0;
-
 
86
    } else if (key == 0x14F) { /* end */
-
 
87
      res = count - 1;
-
 
88
      if (res > offset + height - 3) offset = res - (height - 3);
77
    } else if (key == 0x1B) {  /* ESC */
89
    } else if (key == 0x1B) {  /* ESC */
78
      return(-1);
90
      return(-1);
-
 
91
    } else {
-
 
92
      char buf[8];
-
 
93
      sprintf(buf, "0x%02X ", key);
-
 
94
      video_putstring(1, 0, COLOR_BODY[mono], buf);
79
    }
95
    }
80
  }
96
  }
81
}
97
}
82
 
98
 
83
static void newscreen(void) {
99
static void newscreen(void) {
Line 131... Line 147...
131
  video_putstring(8, 1, COLOR_BODY[mono], "         might be unable to boot once Svarog386 is installed.");
147
  video_putstring(8, 1, COLOR_BODY[mono], "         might be unable to boot once Svarog386 is installed.");
132
  return(menuselect(14, -1, 4, choice));
148
  return(menuselect(14, -1, 4, choice));
133
}
149
}
134
 
150
 
135
 
151
 
-
 
152
/* returns 1 if drive is removable, 0 if not, -1 on error */
136
static int testdrive(int drv) {
153
static int isdriveremovable(int drv) {
137
  union REGS r;
154
  union REGS r;
138
  /* try to switch to new drive */
-
 
139
  r.h.ah = 0x0E;
155
  r.x.ax = 0x4408;
140
  r.h.dl = drv;
156
  r.h.bl = drv;
141
  int86(0x21, &r, &r);
-
 
142
  /* has it worked? if yes, then the drive is valid */
-
 
143
  r.h.ah = 0x19;
-
 
144
  int86(0x21, &r, &r);
157
  int86(0x21, &r, &r);
-
 
158
  /* CF set on error, AX set to 0 if removable, 1 if fixed */
-
 
159
  if (r.x.cflag != 0) return(-1);
145
  if (r.h.al == drv) return(0);
160
  if (r.x.ax == 0) return(1);
146
  return(-1);
161
  return(0);
147
}
162
}
148
 
163
 
149
 
164
 
150
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid
165
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid
151
 * also sets emptyflag to 1 if drive is empty, or to 0 otherwise */
166
 * also sets emptyflag to 1 if drive is empty, or to 0 otherwise */
Line 168... Line 183...
168
  return(res);
183
  return(res);
169
}
184
}
170
 
185
 
171
 
186
 
172
static int preparedrive(void) {
187
static int preparedrive(void) {
173
  int driveexists;
188
  int driveremovable;
174
  int selecteddrive = 3; /* hardcoded to 'C:' */
189
  int selecteddrive = 3; /* hardcoded to 'C:' */
175
  int ds, emptydriveflag;
190
  int ds, emptydriveflag;
176
  for (;;) {
191
  for (;;) {
177
    newscreen();
192
    newscreen();
178
    driveexists = testdrive(selecteddrive);
193
    driveremovable = isdriveremovable(selecteddrive);
179
    if (driveexists != 0) {
194
    if (driveremovable < 0) {
180
      char *list[] = { "Run the FDISK partitionning tool", "Quit to DOS", NULL};
195
      char *list[] = { "Create an automatic partition", "Run the FDISK partitionning tool", "Quit to DOS", NULL};
181
      video_putstring(4, 2, COLOR_BODY[mono], "ERROR: Drive C: could not be found. Perhaps your hard disk needs to be");
196
      video_putstring(4, 2, COLOR_BODY[mono], "ERROR: Drive C: could not be found. Perhaps your hard disk needs to be");
182
      video_putstring(5, 2, COLOR_BODY[mono], "       partitionned first. Please create at least one partition on your");
197
      video_putstring(5, 2, COLOR_BODY[mono], "       partitionned first. Please create at least one partition on your");
183
      video_putstring(6, 2, COLOR_BODY[mono], "       hard disk, so Svarog386 can be installed on it. Note, that");
198
      video_putstring(6, 2, COLOR_BODY[mono], "       hard disk, so Svarog386 can be installed on it. Note, that");
184
      video_putstring(7, 2, COLOR_BODY[mono], "       Svarog386 requires at least 16 MiB of available disk space.");
199
      video_putstring(7, 2, COLOR_BODY[mono], "       Svarog386 requires at least 16 MiB of available disk space.");
185
      video_putstring(9, 2, COLOR_BODY[mono], "You can use the FDISK partitioning tool for creating the required partition,");
200
      video_putstring(9, 2, COLOR_BODY[mono], "You can use the FDISK partitioning tool for creating the required partition");
186
      video_putstring(10, 2, COLOR_BODY[mono], "or abort the installation and use any other partition manager of your choice.");
201
      video_putstring(10, 2, COLOR_BODY[mono], "manually, or you can let the installer partitioning your disk");
-
 
202
      video_putstring(11, 2, COLOR_BODY[mono], "automatically. You can also abort the installation to use any other");
-
 
203
      video_putstring(12, 2, COLOR_BODY[mono], "partition manager of your choice.");
187
      if (menuselect(12, -1, 4, list) != 0) return(-1);
204
      switch (menuselect(14, -1, 5, list)) {
-
 
205
        case 0:
-
 
206
          system("FDISK /AUTO");
-
 
207
          break;
-
 
208
        case 1:
188
      video_clear(0x0700, 0);
209
          video_clear(0x0700, 0);
189
      video_movecursor(0, 0);
210
          video_movecursor(0, 0);
190
      system("fdisk");
211
          system("FDISK");
-
 
212
          break;
-
 
213
        case 2:
-
 
214
          return(-1);
-
 
215
      }
191
      newscreen();
216
      newscreen();
192
      video_putstring(13, 10, COLOR_BODY[mono], "Your computer will reboot now. Press any key.");
217
      video_putstring(12, 10, COLOR_BODY[mono], "Your computer will reboot now. Press any key.");
-
 
218
      input_getkey();
193
      reboot();
219
      reboot();
194
      return(-1);
220
      return(-1);
-
 
221
    } else if (driveremovable > 0) {
-
 
222
      video_putstring(8, 2, COLOR_BODY[mono], "ERROR: Drive C: appears to be a removable device.");
-
 
223
      video_putstring(10, 2, COLOR_BODY[mono], "Installation aborted. Press any key.");
-
 
224
      return(-1);
195
    }
225
    }
196
    /* if not formatted, propose to format it right away */
226
    /* if not formatted, propose to format it right away (try to create a directory) */
197
    ds = disksize(selecteddrive, &emptydriveflag);
-
 
198
    if (ds < 0) {
227
    if (mkdir("C:\\SVWRTEST.123") != 0) {
199
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
228
      char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
200
      video_putstring(7, 2, COLOR_BODY[mono], "ERROR: Drive C: seems to be unformated.");
229
      video_putstring(7, 2, COLOR_BODY[mono], "ERROR: Drive C: seems to be unformated.");
201
      video_putstring(8, 2, COLOR_BODY[mono], "       Do you wish to format it?");
230
      video_putstring(8, 2, COLOR_BODY[mono], "       Do you wish to format it?");
202
      if (menuselect(12, -1, 4, list) != 0) return(-1);
231
      if (menuselect(12, -1, 4, list) != 0) return(-1);
203
      video_clear(0x0700, 0);
232
      video_clear(0x0700, 0);
204
      video_movecursor(0, 0);
233
      video_movecursor(0, 0);
205
      system("FORMAT /Q C:");
234
      system("FORMAT C: /Q /U /V:SVAROG");
206
      continue;
235
      continue;
207
    }
236
    }
-
 
237
    rmdir("C:\\SVWRTEST.123");
208
    /* check total space */
238
    /* check total disk space */
-
 
239
    ds = disksize(selecteddrive, &emptydriveflag);
209
    if (ds < 16) {
240
    if (ds < 16) {
-
 
241
      video_putstring(9, 2, COLOR_BODY[mono], "ERROR: Drive C: is not big enough!");
210
      video_putstring(9, 2, COLOR_BODY[mono], "ERROR: Drive C: is not big enough! Svarog386 requires a disk of at least 16 MiB.");
242
      video_putstring(10, 2, COLOR_BODY[mono], "      Svarog386 requires a disk of at least 16 MiB.");
211
      video_putstring(11, 2, COLOR_BODY[mono], "Press any key to return to DOS.");
243
      video_putstring(12, 2, COLOR_BODY[mono], "Press any key to return to DOS.");
212
      input_getkey();
244
      input_getkey();
213
      return(-1);
245
      return(-1);
214
    }
246
    }
215
    /* is the disk empty? */
247
    /* is the disk empty? */
216
    if (emptydriveflag != 0) {
248
    if (emptydriveflag != 0) {