Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 1662 → Rev 1661

/install/trunk/install.c
33,10 → 33,11
#include <string.h> /* memcpy() */
#include <unistd.h>
 
#include "mdr\cout.h"
#include "mdr\dos.h"
#include "svarlang.lib\svarlang.h"
 
#include "video.h"
 
/* keyboard layouts and locales */
#include "keylay.h"
#include "keyoff.h"
46,13 → 47,13
 
 
/* color scheme (color, mono) */
static unsigned char COLOR_TITLEBAR[2] = {0x70,0x70};
static unsigned char COLOR_BODY[2] = {0x07,0x17};
static unsigned char COLOR_SELECT[2] = {0x70,0x70};
static unsigned char COLOR_SELECTCUR[2] = {0x07,0x1F};
static unsigned short COLOR_TITLEBAR[2] = {0x7000,0x7000};
static unsigned short COLOR_BODY[2] = {0x1700,0x0700};
static unsigned short COLOR_SELECT[2] = {0x7000,0x7000};
static unsigned short COLOR_SELECTCUR[2] = {0x1F00,0x0700};
 
/* mono flag (0=mono 1=color) */
static unsigned char mono = 0;
/* mono flag */
static int mono = 0;
 
/* how much disk space does SvarDOS require (in MiB) */
#define SVARDOS_DISK_REQ 8
77,18 → 78,6
};
 
 
/* put a string on screen and fill it until w chars with whilte space */
static void video_putstringfix(unsigned char y, unsigned char x, unsigned char attr, const char *s, unsigned char w) {
unsigned char i;
 
/* print the string up to w characters */
i = mdr_cout_str(y, x, s, attr, w);
 
/* fill in left space (if any) with blanks */
mdr_cout_char_rep(y, x + i, ' ', attr, w - i);
}
 
 
/* reboot the computer */
static void reboot(void) {
void ((far *bootroutine)()) = (void (far *)()) 0xFFFF0000L;
99,9 → 88,10
 
 
/* outputs a string to screen with taking care of word wrapping. returns amount of lines. */
static unsigned char putstringwrap(unsigned char y, unsigned char x, unsigned char attr, const char *s) {
unsigned char linew, lincount;
linew = 80 - (x << 1);
static int putstringwrap(int y, int x, unsigned short attr, const char *s) {
int linew, lincount;
linew = 80;
if (x >= 0) linew -= (x << 1);
 
for (lincount = 1; y+lincount < 25; lincount++) {
int i, len = linew;
116,7 → 106,7
break;
}
}
mdr_cout_str(y++, x, s, attr, len);
video_putstring(y++, x, attr, s, len);
s += len;
if (*s == 0) break;
s += 1; /* skip the whitespace char */
127,7 → 117,7
 
/* an NLS wrapper around video_putstring(), also performs line wrapping when
* needed. returns the amount of lines that were output */
static unsigned char putstringnls(unsigned char y, unsigned char x, unsigned char attr, unsigned char nlsmaj, unsigned char nlsmin) {
static int putstringnls(int y, int x, unsigned short attr, int nlsmaj, int nlsmin) {
const char *s = svarlang_str(nlsmaj, nlsmin);
if (s == NULL) s = "";
return(putstringwrap(y, x, attr, s));
165,10 → 155,8
}
 
 
static int menuselect(unsigned char ypos, int xpos, unsigned char height, const char **list, int listlen) {
static int menuselect(int ypos, int xpos, int height, const char **list, int listlen) {
int i, offset = 0, res = 0, count, width = 0;
unsigned char y;
 
/* count how many positions there is, and check their width */
for (count = 0; (list[count] != NULL) && (count != listlen); count++) {
int len = strlen(list[count]);
178,33 → 166,30
/* if xpos negative, means 'center out' */
if (xpos < 0) xpos = 39 - (width >> 1);
 
mdr_cout_char(ypos, xpos+width+2, 0xBF, COLOR_SELECT[mono]); /* \ */
mdr_cout_char(ypos, xpos-1, 0xDA, COLOR_SELECT[mono]); /* / */
mdr_cout_char(ypos+height-1, xpos-1, 0xC0, COLOR_SELECT[mono]); /* \ */
mdr_cout_char(ypos+height-1, xpos+width+2, 0xD9, COLOR_SELECT[mono]);/* / */
mdr_cout_char_rep(ypos, xpos, 0xC4, COLOR_SELECT[mono], width + 2);
mdr_cout_char_rep(ypos+height-1, xpos, 0xC4, COLOR_SELECT[mono], width + 2);
video_putchar(ypos, xpos+width+2, COLOR_SELECT[mono], 0xBF); /* \ */
video_putchar(ypos, xpos-1, COLOR_SELECT[mono], 0xDA); /* / */
video_putchar(ypos+height-1, xpos-1, COLOR_SELECT[mono], 0xC0); /* \ */
video_putchar(ypos+height-1, xpos+width+2, COLOR_SELECT[mono], 0xD9);/* / */
video_putcharmulti(ypos, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
video_putcharmulti(ypos+height-1, xpos, COLOR_SELECT[mono], 0xC4, width + 2, 1);
video_putcharmulti(ypos+1, xpos-1, COLOR_SELECT[mono], 0xB3, height - 2, 80);
video_putcharmulti(ypos+1, xpos+width+2, COLOR_SELECT[mono], 0xB3, height - 2, 80);
 
for (y = ypos + 1; y < (ypos + height - 1); y++) {
mdr_cout_char(y, xpos-1, 0xB3, COLOR_SELECT[mono]);
mdr_cout_char(y, xpos+width+2, 0xB3, COLOR_SELECT[mono]);
}
 
for (;;) {
int key;
/* list of selectable items */
for (i = 0; i < height - 2; i++) {
if (i + offset == res) {
mdr_cout_char(ypos + 1 + i, xpos, 16, COLOR_SELECTCUR[mono]);
mdr_cout_char(ypos + 1 + i, xpos+width+1, 17, COLOR_SELECTCUR[mono]);
mdr_cout_locate(ypos + 1 + i, xpos);
video_putchar(ypos + 1 + i, xpos, COLOR_SELECTCUR[mono], 16);
video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECTCUR[mono], 17);
video_movecursor(ypos + 1 + i, xpos);
video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECTCUR[mono], list[i + offset], width);
} else if (i + offset < count) {
mdr_cout_char(ypos + 1 + i, xpos, ' ', COLOR_SELECT[mono]);
mdr_cout_char(ypos + 1 + i, xpos+width+1, ' ', COLOR_SELECT[mono]);
video_putchar(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ');
video_putchar(ypos + 1 + i, xpos+width+1, COLOR_SELECT[mono], ' ');
video_putstringfix(ypos + 1 + i, xpos+1, COLOR_SELECT[mono], list[i + offset], width);
} else {
mdr_cout_char_rep(ypos + 1 + i, xpos, ' ', COLOR_SELECT[mono], width+2);
video_putcharmulti(ypos + 1 + i, xpos, COLOR_SELECT[mono], ' ', width+2, 1);
}
}
key = mdr_dos_getkey();
236,12 → 221,12
}
}
 
static void newscreen(unsigned char statusbartype) {
static void newscreen(int statusbartype) {
const char *msg;
mdr_cout_cls(COLOR_BODY[mono]);
msg = svarlang_strid(0x00); /* "SVARDOS INSTALLATION" */
mdr_cout_char_rep(0, 0, ' ', COLOR_TITLEBAR[mono], 80);
mdr_cout_str(0, 40 - (strlen(msg) >> 1), msg, COLOR_TITLEBAR[mono], 80);
video_putcharmulti(0, 0, COLOR_TITLEBAR[mono], ' ', 80, 1);
video_putstring(0, 40 - (strlen(msg) >> 1), COLOR_TITLEBAR[mono], msg, -1);
video_clear(COLOR_BODY[mono], 80, -80);
switch (statusbartype) {
case 1:
msg = svarlang_strid(0x000B); /* "Up/Down = Select entry | Enter = Validate your choice | ESC = Quit to DOS" */
256,9 → 241,9
msg = svarlang_strid(0x000A); /* "Up/Down = Select entry | Enter = Validate your choice | ESC = Previous screen" */
break;
}
mdr_cout_char(24, 0, ' ', COLOR_TITLEBAR[mono]);
video_putchar(24, 0, COLOR_TITLEBAR[mono], ' ');
video_putstringfix(24, 1, COLOR_TITLEBAR[mono], msg, 79);
mdr_cout_locate(25,0);
video_movecursor(25,0);
}
 
/* fills a slocales struct accordingly to the value of its keyboff member */
296,17 → 281,9
newscreen(1);
msg = svarlang_strid(0x0100); /* "Welcome to SvarDOS" */
x = 40 - (strlen(msg) >> 1);
mdr_cout_str(4, x, msg, COLOR_BODY[mono], 80);
mdr_cout_char_rep(5, x, '=', COLOR_BODY[mono], strlen(msg));
 
/* center out the string "Please select your language..." */
msg = svarlang_str(1, 1); /* "Please select your language from the list below:" */
if (strlen(msg) > 74) {
putstringwrap(8, 1, COLOR_BODY[mono], msg);
} else {
mdr_cout_str(8, 40 - (strlen(msg) / 2), msg, COLOR_BODY[mono], 80);
}
 
video_putstring(4, x, COLOR_BODY[mono], msg, -1);
video_putcharmulti(5, x, COLOR_BODY[mono], '=', strlen(msg), 1);
putstringnls(8, -1, COLOR_BODY[mono], 1, 1); /* "Please select your language from the list below:" */
choice = menuselect(11, -1, 11, langlist, -1);
if (choice < 0) return(MENUPREV);
/* populate locales with default values */
555,8 → 532,8
system(buff);
break;
case 1:
mdr_cout_cls(0x07);
mdr_cout_locate(0, 0);
video_clear(0x0700, 0, 0);
video_movecursor(0, 0);
sprintf(buff, "FDISK %d", driveid);
system(buff);
break;
578,7 → 555,7
} else if (driveremovable > 0) {
newscreen(2);
snprintf(buff, sizeof(buff), svarlang_strid(0x0302), cselecteddrive); /* "ERROR: Drive %c: is a removable device */
mdr_cout_str(9, 1, buff, COLOR_BODY[mono], 80);
video_putstring(9, 1, COLOR_BODY[mono], buff, -1);
putstringnls(11, 2, COLOR_BODY[mono], 0, 5); /* "Press any key..." */
return(MENUQUIT);
}
587,7 → 564,7
const char *list[3];
newscreen(0);
snprintf(buff, sizeof(buff), svarlang_str(3, 3), cselecteddrive); /* "ERROR: Drive %c: seems to be unformated. Do you wish to format it?") */
mdr_cout_str(7, 1, buff, COLOR_BODY[mono], 80);
video_putstring(7, 1, COLOR_BODY[mono], buff, -1);
 
snprintf(buff, sizeof(buff), svarlang_strid(0x0007), cselecteddrive); /* "Format drive %c:" */
list[0] = buff;
597,8 → 574,8
choice = menuselect(12, -1, 4, list, -1);
if (choice < 0) return(MENUPREV);
if (choice == 1) return(MENUQUIT);
mdr_cout_cls(0x07);
mdr_cout_locate(0, 0);
video_clear(0x0700, 0, 0);
video_movecursor(0, 0);
snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
system(buff);
continue;
630,8 → 607,8
choice = menuselect(++y, -1, 4, list, -1);
if (choice < 0) return(MENUPREV);
if (choice == 1) return(MENUQUIT);
mdr_cout_cls(0x07);
mdr_cout_locate(0, 0);
video_clear(0x0700, 0, 0);
video_movecursor(0, 0);
snprintf(buff, sizeof(buff), "FORMAT %c: /Q /U /Z:seriously /V:SVARDOS", cselecteddrive);
system(buff);
continue;
642,7 → 619,7
list[1] = svarlang_strid(0x0002); /* Quit to DOS */
list[2] = NULL;
snprintf(buff, sizeof(buff), svarlang_strid(0x0306), cselecteddrive); /* "The installation of SvarDOS to %c: is about to begin." */
mdr_cout_str(7, 40 - strlen(buff), buff, COLOR_BODY[mono], 80);
video_putstring(7, -1, COLOR_BODY[mono], buff, -1);
choice = menuselect(10, -1, 4, list, -1);
if (choice < 0) return(MENUPREV);
if (choice == 1) return(MENUQUIT);
778,7 → 755,7
/* load pkg list */
fd = fopen("install.lst", "rb");
if (fd == NULL) {
mdr_cout_str(10, 30, "ERROR: INSTALL.LST NOT FOUND", COLOR_BODY[mono], 80);
video_putstring(10, 30, COLOR_BODY[mono], "ERROR: INSTALL.LST NOT FOUND", -1);
mdr_dos_getkey();
return(-1);
}
785,7 → 762,7
pkglistflen = fread(pkglist, 1, sizeof(pkglist) - 2, fd);
fclose(fd);
if (pkglistflen == sizeof(pkglist) - 2) {
mdr_cout_str(10, 30, "ERROR: INSTALL.LST TOO LARGE", COLOR_BODY[mono], 80);
video_putstring(10, 30, COLOR_BODY[mono], "ERROR: INSTALL.LST TOO LARGE", -1);
mdr_dos_getkey();
return(-1);
}
847,12 → 824,12
/* install the package */
snprintf(buff, sizeof(buff), svarlang_strid(0x0400), i+1, pkglistlen, pkgptr); /* "Installing package %d/%d: %s" */
strcat(buff, " ");
mdr_cout_str(10, 1, buff, COLOR_BODY[mono], 40);
video_putstringfix(10, 1, COLOR_BODY[mono], buff, sizeof(buff));
 
/* proceed with package copy */
sprintf(buff, "%c:\\temp\\%s.svp", targetdrv, pkgptr);
if (fcopy(buff, buff + 7, buff, sizeof(buff)) != 0) {
mdr_cout_str(10, 30, "READ ERROR", COLOR_BODY[mono], 80);
video_putstring(10, 30, COLOR_BODY[mono], "READ ERROR", -1);
mdr_dos_getkey();
fclose(fd);
return(-1);
913,7 → 890,7
static void loadcp(const struct slocales *locales) {
char buff[64];
if (locales->codepage == 437) return;
mdr_cout_locate(1, 0);
video_movecursor(1, 0);
if (locales->egafile == 1) {
snprintf(buff, sizeof(buff), "MODE CON CP PREP=((%u) EGA.CPX) > NUL", locales->codepage);
} else {
962,7 → 939,7
sourcedrv = get_cur_drive() + 'A';
 
/* init screen and detect mono status */
mono = mdr_cout_init(NULL, NULL);
mono = video_init();
 
SelectLang:
action = selectlang(&locales); /* welcome to svardos, select your language */
992,7 → 969,7
finalreboot(); /* remove the CD and reboot */
 
Quit:
mdr_cout_locate(0, 0);
mdr_cout_close();
video_clear(0x0700, 0, 0);
video_movecursor(0, 0);
return(0);
}
/install/trunk/makefile
9,8 → 9,8
 
all: install.com
 
install.com: keylay.h install.c deflang.c int24hdl.obj
wcl -0 -y -cc -wx -mt -lr -we -d0 -ox install.c deflang.c int24hdl.obj mdr\mdrs2024.lib svarlang.lib\svarlngs.lib
install.com: keylay.h install.c video.c deflang.c int24hdl.obj
wcl -0 -y -cc -wx -mt -lr -we -d0 -ox install.c video.c deflang.c int24hdl.obj mdr\mdrs2024.lib svarlang.lib\svarlngs.lib
upx --8086 -9 install.com
 
int24hdl.obj: int24hdl.asm
/install/trunk/video.c
0,0 → 1,88
/*
* Video routines used by the SvarDOS 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 */
 
/* pointer to the VGA/MDA screen */
static unsigned short far *scr = (unsigned short far *)0xB8000000L;
 
void video_clear(unsigned short attr, int offset, int offsetend) {
offsetend += 2000;
while (offset < offsetend) scr[offset++] = attr;
}
 
/* inits screen, returns 0 for color mode, 1 for mono */
int video_init(void) {
union REGS r;
int monoflag;
/* get current video mode to detect color (7 = mono, anything else is color) */
r.h.ah = 0x0F;
int86(0x10, &r, &r);
/* set the monoflag to detected value and prepare the next mode we will set */
if (r.h.al == 7) {
monoflag = 1;
r.h.al = 7; /* 80x25 2 colors (MDA / Hercules) */
scr = (unsigned short far *)0xB0000000L;
} else if (r.h.al == 2) { /* 80x25 grayscale */
monoflag = 1;
r.h.al = 2; /* 80x25 grayscale */
scr = (unsigned short far *)0xB8000000L;
} else {
monoflag = 0;
r.h.al = 3; /* 80x25 16 colors */
scr = (unsigned short far *)0xB8000000L;
}
/* (re)set video mode to be sure what we are dealing with */
r.h.ah = 0;
int86(0x10, &r, &r);
return(monoflag);
}
 
void video_putchar(int y, int x, unsigned short attr, int c) {
scr[(y << 6) + (y << 4) + x] = 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) {
scr[offset] = attr | c;
offset += step;
}
}
 
void video_putstring(int y, int x, unsigned short attr, const char *s, int maxlen) {
if (x < 0) { /* means 'center out' */
int slen;
for (slen = 0; s[slen] != 0; slen++); /* faster than strlen() */
x = 40 - (slen >> 1);
}
x += (y << 6) + (y << 4); /* I use x as an offset now */
while ((*s != 0) && (maxlen-- != 0)) {
scr[x++] = attr | *s;
s++;
}
}
 
void video_putstringfix(int y, int x, unsigned short attr, const char *s, int w) {
x += (y << 6) + (y << 4); /* I use x as an offset now */
while (w-- > 0) {
scr[x++] = attr | *s;
if (*s != 0) s++;
}
}
 
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/trunk/video.h
0,0 → 1,17
/*
* Video routines used by the SvarDOS installer
* Copyright (C) 2016 Mateusz Viste
*/
 
#ifndef VIDEO_H_SENTINEL
#define VIDEO_H_SENTINEL
 
int video_init(void);
void video_clear(unsigned short attr, int offset, int offsetend);
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, const char *str, int maxlen);
void video_putstringfix(int y, int x, unsigned short attr, const char *s, int w);
void video_movecursor(int y, int x);
 
#endif