Subversion Repositories SvarDOS

Compare Revisions

Regard whitespace Rev 27 → Rev 28

/install/TODO
0,0 → 1,2
language list should be stored in a separate file (install.dat). it would contain the amount
of languages, the list of all languages, their short code, codepage, supported keyboard layouts and country.sys preferences.
/install/input.c
0,0 → 1,37
/*
* input keyboard routines used by the Svarog386 installer.
* Copyright (C) 2016 Mateusz Viste
*/
 
#ifndef input_h_sentinel
#define input_h_sentinel
 
#include <dos.h>
#include "input.h" /* include self for control */
 
/* waits for a keypress and return it. Returns 0x1xx for extended keys */
int input_getkey(void) {
union REGS regs;
int res;
regs.h.ah = 0x08;
int86(0x21, &regs, &regs);
res = regs.h.al;
if (res == 0) { /* extended key - poll again */
regs.h.ah = 0x08;
int86(0x21, &regs, &regs);
res = regs.h.al | 0x100;
}
return(res);
}
 
 
/* poll the keyboard, and return the next input key in buffer, or -1 if none */
int input_getkeyifany(void) {
union REGS regs;
regs.h.ah = 0x0B;
int86(0x21, &regs, &regs);
if (regs.h.al == 0xFF) return(input_getkey());
return(-1);
}
 
#endif
/install/input.h
0,0 → 1,11
/*
* input keyboard routines used by the Svarog386 installer.
* Copyright (C) 2016 Mateusz Viste
*/
 
/* waits for a keypress and return it. Returns 0 for extended keystroke, then
function must be called again to return scan code. */
int input_getkey(void);
 
/* poll the keyboard, and return the next input key if any, or -1 */
int input_getkeyifany(void);
/install/install.c
0,0 → 1,368
/*
* SVAROG386 INSTALL
* COPYRIGHT (C) 2016 MATEUSZ VISTE
*/
 
#include <dos.h>
#include <stdio.h> /* printf() and friends */
#include <stdlib.h> /* system() */
#include <string.h> /* memcpy() */
#include <unistd.h>
#include "input.h"
#include "video.h"
 
#define COLOR_TITLEBAR 0x7000
#define COLOR_BODY 0x1700
#define COLOR_SELECT 0x7000
#define COLOR_SELECTCUR 0x1F00
 
 
 
/* reboot the computer */
static void reboot(void) {
void ((far *bootroutine)()) = (void (far *)()) 0xFFFF0000L;
int far *rstaddr = (int far *)0x00400072L; /* BIOS boot flag is at 0040:0072 */
*rstaddr = 0x1234; /* 0x1234 = warm boot, 0 = cold boot */
(*bootroutine)(); /* jump to the BIOS reboot routine at FFFF:0000 */
}
 
static int menuselect(int ypos, int xpos, int height, char **list) {
int i, offset = 0, res = 0, count, width = 0;
/* count how many languages there is */
for (count = 0; list[count] != NULL; count++) {
int len = strlen(list[count]);
if (len > width) width = len;
}
 
/* if xpos negative, means 'center out' */
if (xpos < 0) xpos = 39 - (width >> 1);
 
video_putchar(ypos, xpos+width+2, COLOR_SELECT, 0xBF); /* \ */
video_putchar(ypos, xpos-1, COLOR_SELECT, 0xDA); /* / */
video_putchar(ypos+height-1, xpos-1, COLOR_SELECT, 0xC0); /* \ */
video_putchar(ypos+height-1, xpos+width+2, COLOR_SELECT, 0xD9);/* / */
video_putcharmulti(ypos, xpos, COLOR_SELECT, 0xC4, width + 2, 1);
video_putcharmulti(ypos+height-1, xpos, COLOR_SELECT, 0xC4, width + 2, 1);
video_putcharmulti(ypos+1, xpos-1, COLOR_SELECT, 0xB3, height - 2, 80);
video_putcharmulti(ypos+1, xpos+width+2, COLOR_SELECT, 0xB3, height - 2, 80);
 
for (;;) {
int key;
/* list of selectable items */
for (i = 0; i < height - 2; i++) {
if (i + offset == res) {
video_putchar(ypos + 1 + i, xpos, COLOR_SELECTCUR, 16);
video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECTCUR, 17);
video_movecursor(ypos + 1 + i, xpos);
video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECTCUR, list[i + offset], width);
} else if (i + offset < count) {
video_putchar(ypos + 1 + i, xpos, COLOR_SELECT, ' ');
video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECT, ' ');
video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECT, list[i + offset], width);
} else {
video_putcharmulti(ypos + 1 + i, xpos, COLOR_SELECT, ' ', width+2, 1);
}
}
key = input_getkey();
if (key == 0x0D) { /* ENTER */
return(res);
} else if (key == 0x148) { /* up */
if (res > 0) res--;
} else if (key == 0x150) { /* down */
if (res+1 < count) res++;
} else if (key == 0x1B) { /* ESC */
return(-1);
}
}
}
 
static void newscreen(void) {
int x;
for (x = 0; x < 80; x++) video_putchar(0, x, COLOR_TITLEBAR, ' ');
video_clear(COLOR_BODY, 80);
video_putstring(0, 29, COLOR_TITLEBAR, "SVAROG386 INSTALLATION");
}
 
 
static int selectlang(char *lang) {
int choice;
char *code;
char *langlist[] = {
"English\0EN",
"French\0FR",
"German\0DE",
"Italian\0IT",
"Polish\0PL",
"Russian\0RU",
"Slovenian\0SL",
"Spanish\0ES",
"Turkish\0TR",
NULL
};
 
newscreen();
video_putstring(3, 30, COLOR_BODY, "Welcome to Svarog386");
video_putstring(4, 30, COLOR_BODY, "====================");
video_putstring(6, 2, COLOR_BODY, "Svarog386 is an operating system based on the FreeDOS kernel. It targets");
video_putstring(7, 2, COLOR_BODY, "386+ computers and comes with a variety of third-party applications. Before");
video_putstring(8, 2, COLOR_BODY, "we get to serious business, please select your preferred language from the");
video_putstring(9, 2, COLOR_BODY, "list below, and press the ENTER key:");
choice = menuselect(11, -1, 12, langlist);
if (choice < 0) return(-1);
/* write short language code into lang */
for (code = langlist[choice]; *code != 0; code++);
memcpy(lang, code + 1, 2);
lang[2] = 0;
return(0);
}
 
 
/* returns 0 if installation must proceed, non-zero otherwise */
static int welcomescreen(void) {
char *choice[] = {"Install Svarog386 to disk", "Quit to DOS", NULL};
newscreen();
video_putstring(4, 1, COLOR_BODY, "You are about to install Svarog386, a free, MSDOS-compatible operating system");
video_putstring(5, 1, COLOR_BODY, "based on the FreeDOS kernel.");
video_putstring(7, 1, COLOR_BODY, "WARNING: If your PC has another operating system installed, this other system");
video_putstring(8, 1, COLOR_BODY, " might be unable to boot once Svarog386 is installed.");
return(menuselect(14, -1, 4, choice));
}
 
 
static int testdrive(int drv) {
union REGS r;
/* try to switch to new drive */
r.h.ah = 0x0E;
r.h.dl = drv;
int86(0x21, &r, &r);
/* has it worked? if yes, then the drive is valid */
r.h.ah = 0x19;
int86(0x21, &r, &r);
if (r.h.al == drv) return(0);
return(-1);
}
 
 
/* returns total disk space of drive drv (in MiB, max 2048), or -1 if drive invalid
* also sets emptyflag to 1 if drive is empty, or to 0 otherwise */
static int disksize(int drv, int *emptyflag) {
long res;
union REGS r;
r.h.ah = 0x36; /* DOS 2+ get free disk space */
r.h.dl = drv;
int86(0x21, &r, &r);
if (r.x.ax == 0xffffu) return(-1); /* AX set to FFFFh if drive invalid */
res = r.x.ax;
res *= r.x.bx;
res *= r.x.cx;
res >>= 20; /* bytes to MiB */
if (r.x.dx != r.x.bx) { /* DX is total number of clusters, while BX is only free clusters */
*emptyflag = 0;
} else {
*emptyflag = 1;
}
return(res);
}
 
 
static int preparedrive(void) {
int driveexists;
int selecteddrive = 3; /* hardcoded to 'C:' */
int ds, emptydriveflag;
for (;;) {
newscreen();
driveexists = testdrive(selecteddrive);
if (driveexists != 0) {
char *list[] = { "Run the FDISK partitionning tool", "Quit to DOS", NULL};
video_putstring(4, 2, COLOR_BODY, "ERROR: Drive C: could not be found. Perhaps your hard disk needs to be");
video_putstring(5, 2, COLOR_BODY, " partitionned first. Please create at least one partition on your");
video_putstring(6, 2, COLOR_BODY, " hard disk, so Svarog386 can be installed on it. Note, that");
video_putstring(7, 2, COLOR_BODY, " Svarog386 requires at least 16 MiB of available disk space.");
video_putstring(9, 2, COLOR_BODY, "You can use the FDISK partitioning tool for creating the required partition,");
video_putstring(10, 2, COLOR_BODY, "or abort the installation and use any other partition manager of your choice.");
if (menuselect(12, -1, 4, list) != 0) return(-1);
video_clear(0x0700, 0);
video_movecursor(0, 0);
system("fdisk");
newscreen();
video_putstring(13, 10, COLOR_BODY, "Your computer will reboot now. Press any key.");
reboot();
return(-1);
}
/* if not formatted, propose to format it right away */
ds = disksize(selecteddrive, &emptydriveflag);
if (ds < 0) {
char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
video_putstring(7, 2, COLOR_BODY, "ERROR: Drive C: seems to be unformated.");
video_putstring(8, 2, COLOR_BODY, " Do you wish to format it?");
if (menuselect(12, -1, 4, list) != 0) return(-1);
video_clear(0x0700, 0);
video_movecursor(0, 0);
system("FORMAT /Q C:");
continue;
}
/* check total space */
if (ds < 16) {
video_putstring(9, 2, COLOR_BODY, "ERROR: Drive C: is not big enough! Svarog386 requires a disk of at least 16 MiB.");
video_putstring(11, 2, COLOR_BODY, "Press any key to return to DOS.");
input_getkey();
return(-1);
}
/* is the disk empty? */
if (emptydriveflag != 0) {
char *list[] = { "Proceed with formatting", "Quit to DOS", NULL};
video_putstring(7, 2, COLOR_BODY, "ERROR: Drive C: is not empty. Svarog386 must be installed on an empty disk.");
video_putstring(8, 2, COLOR_BODY, " You can format the disk now, to make it empty. Note however, that");
video_putstring(9, 2, COLOR_BODY, " this will ERASE ALL CURRENT DATA on your disk.");
if (menuselect(12, -1, 4, list) != 0) return(-1);
video_clear(0x0700, 0);
video_movecursor(0, 0);
system("FORMAT /Q C:");
continue;
} else {
/* final confirmation */
char *list[] = { "Install Svarog386", "Quit to DOS", NULL};
video_putstring(8, 2, COLOR_BODY, "The installation of Svarog386 to your C: disk is about to begin.");
if (menuselect(10, -1, 4, list) != 0) return(-1);
system("SYS A: C:");
return(0);
}
}
}
 
 
static void finalreboot(void) {
newscreen();
video_putstring(10, 2, COLOR_BODY, "Svarog386 installation is over. Please remove the");
video_putstring(10, 2, COLOR_BODY, "installation diskette and/or CD from the drive.");
video_putstring(13, 2, COLOR_BODY, "Press any key to reboot...");
input_getkey();
reboot();
}
 
 
static void bootfilesgen(int targetdrv, char *lang) {
char drv = 'A' + targetdrv - 1;
char buff[128];
FILE *fd;
/*** AUTOEXEC.BAT ***/
sprintf(buff, "%c:\\AUTOEXEC.BAT", drv);
fd = fopen(buff, "wb");
if (fd == NULL) return;
fprintf(fd, "@ECHO OFF\r\n");
fprintf(fd, "SET TEMP=%c:\\TEMP\r\n", drv);
fprintf(fd, "SET DOSDIR=%c:\\SYSTEM\\SVAROG.386\r\n", drv);
fprintf(fd, "SET NLSPATH=%%DOSDIR%%\\NLS\r\n", drv);
fprintf(fd, "SET LANG=%s\r\n", lang);
fprintf(fd, "SET DIRCMD=/OGNE/P\r\n");
fprintf(fd, "SET FDNPKG.CFG=%c:\\SYSTEM\\CFG\\FDNPKG.CFG\r\n");
fprintf(fd, "SET WATTCP.CFG=%c:\\SYSTEM\\CFG\\WATTCP.CFG\r\n");
fprintf(fd, "PATH %%DOSDIR%%\\BIN;%%DOSDIR%%\\LINKS\r\n");
fprintf(fd, "PROMPT $P$G\r\n");
fprintf(fd, "\r\n\r\n");
fprintf(fd, "MODE CON CP PREPARE=((991) %c:\\SYSTEM\\SVAROG.386\\CPI\\EGA10.CPX\r\n");
fprintf(fd, "MODE CON CP SELECT=991\r\n");
fprintf(fd, "\r\n");
fprintf(fd, "SHSUCDX /d:FDCD0001\r\n");
fclose(fd);
/*** CONFIG.SYS ***/
sprintf(buff, "%c:\\CONFIG.SYS", drv);
fd = fopen(buff, "wb");
if (fd == NULL) return;
fprintf(fd, "DOS=UMB,HIGH\r\n");
fprintf(fd, "FILES=50\r\n");
fprintf(fd, "DEVICE=%c:\\SYSTEM\\SVAROG.386\\BIN\\HIMEM.EXE\r\n", drv);
fprintf(fd, "SHELLHIGH=%c:\\SYSTEM\\SVAROG.386\\BIN\\COMMAND.COM /E:512", drv);
fprintf(fd, "REM COUNTRY=001,437,%c:\\SYSTEM\\SVAROG.386\r\n", drv);
fprintf(fd, "DEVICE=%c:\\SYSTEM\\SVAROG.386\\BIN\\CDROM.SYS /D:FDCD0001\r\n", drv);
fclose(fd);
}
 
 
static void installpackages(void) {
char *pkglist[] = {
"APPEND",
"ASSIGN",
"ATTRIB",
"CHKDSK",
"CHOICE",
"COMMAND",
"COMP",
"CPIDOS",
"CTMOUSE",
"DEBUG",
"DEFRAG",
"DELTREE",
"DEVLOAD",
"DISKCOMP",
"DISKCOPY",
"DISPLAY",
"DOSFSCK",
"EDIT",
"EDLIN",
"EXE2BIN",
"FC",
"FDAPM",
"FDISK",
"FDNPKG",
"FIND",
"FORMAT",
"HELP",
"HIMEMX",
"KERNEL",
"KEYB",
"LABEL",
"LBACACHE",
"MEM",
"MIRROR",
"MODE",
"MORE",
"MOVE",
"NANSI",
"NLSFUNC",
"PRINT",
"RDISK",
"RECOVER",
"REPLACE",
"SHARE",
"SHSUCDX",
"SORT",
"SWSUBST",
"TREE",
"UNDELETE",
"XCOPY",
NULL
};
int i;
newscreen();
video_putstring(10, 2, COLOR_BODY, "Installing packages...");
for (i = 0; pkglist[i] != NULL; i++) {
char buff[32];
sprintf(buff, "FDINST %s.ZIP > NULL");
system(buff);
}
}
 
 
int main(void) {
char lang[4];
int targetdrv;
 
for (;;) { /* fake loop, it's here just to break out easily */
if (selectlang(lang) < 0) break; /* welcome to svarog, select your language */
/*selectkeyb();*/ /* if non-english, what keyb layout should we use? */
if (welcomescreen() != 0) break; /* what svarog386 is, ask whether to run live dos or install */
targetdrv = preparedrive(); /* what drive should we install to? check avail. space */
if (targetdrv < 0) break;
/*askaboutsources();*/ /* IF sources are available, ask if installing with them */
installpackages(); /* install packages */
bootfilesgen(targetdrv, lang); /* generate simple boot files */
/*localcfg();*/ /* show local params (currency, etc), and propose to change them (based on localcfg) */
/*netcfg();*/ /* basic networking config? */
finalreboot(); /* remove the CD and reboot */
break;
}
video_clear(0x0700, 0);
video_movecursor(0, 0);
return(0);
}
/install/install.txt
0,0 → 1,8
 
SVAROG386 INSTALLER
Copyright (C) 2016 Mateusz Viste
 
This is a simple installer for Svarog386. It installs packages from the CD
(relying on fdinst), SYS the boot disk and pre-configures default boot files
(autoexec.bat and config.sys).
 
/install/makefile
0,0 → 1,18
#
# This is a makefile to build the Svarog386 install program
#
# You can use following targets:
#
# make - compiles the program
# make clean - cleans up all non-source files
#
 
all: install.com
 
install.com: install.c input.c video.c
wcl -0 -y -cc -wx -mt -lr -we -d0 -ox install.c input.c video.c
upx --8086 -9 install.com
 
clean: .SYMBOLIC
del install.com
del *.obj
/install/video.c
0,0 → 1,70
/*
* Video routines used by the Svarog386 installer
* Copyright (C) 2016 Mateusz Viste
*
* All video routines output data directly to VRAM, and they all do that
* to both B8000:0000 and B0000:0000 areas simulteanously, for compatibility
* with all possible video adapters in all possible modes.
*/
 
#include <dos.h>
#include "video.h" /* include self for control */
 
/* pointers to VGA/MDA screens */
static unsigned short far *vga = (unsigned short far *)0xB8000000L;
static unsigned short far *mda = (unsigned short far *)0xB0000000L;
 
void video_clear(unsigned short attr, int offset) {
int x;
for (x = offset; x < 2000; x++) {
vga[x] = attr;
mda[x] = attr;
}
}
 
void video_putchar(int y, int x, unsigned short attr, int c) {
int offset = (y << 6) + (y << 4) + x;
vga[offset] = attr | c;
mda[offset] = attr | c;
}
 
void video_putcharmulti(int y, int x, unsigned short attr, int c, int repeat, int step) {
int offset = (y << 6) + (y << 4) + x;
while (repeat-- > 0) {
vga[offset] = attr | c;
mda[offset] = attr | c;
offset += step;
}
}
 
void video_putstring(int y, int x, unsigned short attr, char *s) {
x += (y << 6) + (y << 4); /* I use x as an offset now */
while (*s != 0) {
unsigned short b = attr | *s;
vga[x] = b;
mda[x] = b;
x++;
s++;
}
}
 
void video_putstringfix(int y, int x, unsigned short attr, char *s, int w) {
x += (y << 6) + (y << 4); /* I use x as an offset now */
while (w-- > 0) {
unsigned short b;
b = attr | *s;
if (*s != 0) s++;
vga[x] = b;
mda[x] = b;
x++;
}
}
 
void video_movecursor(int y, int x) {
union REGS r;
r.h.ah = 2;
r.h.bh = 0;
r.h.dh = y;
r.h.dl = x;
int86(0x10, &r, &r);
}
/install/video.h
0,0 → 1,16
/*
* Video routines used by the Svarog386 installer
* Copyright (C) 2016 Mateusz Viste
*/
 
#ifndef VIDEO_H_SENTINEL
#define VIDEO_H_SENTINEL
 
void video_clear(unsigned short attr, int offset);
void video_putchar(int y, int x, unsigned short attr, int c);
void video_putcharmulti(int y, int x, unsigned short attr, int c, int repeat, int step);
void video_putstring(int y, int x, unsigned short attr, char *str);
void video_putstringfix(int y, int x, unsigned short attr, char *s, int w);
void video_movecursor(int y, int x);
 
#endif