40 |
mv_fox |
1 |
/*
|
|
|
2 |
* Video routines used by the Svarog386 installer
|
|
|
3 |
* Copyright (C) 2016 Mateusz Viste
|
|
|
4 |
*
|
|
|
5 |
* All video routines output data directly to VRAM, and they all do that
|
|
|
6 |
* to both B8000:0000 and B0000:0000 areas simulteanously, for compatibility
|
|
|
7 |
* with all possible video adapters in all possible modes.
|
|
|
8 |
*/
|
|
|
9 |
|
|
|
10 |
#include <dos.h>
|
|
|
11 |
#include "video.h" /* include self for control */
|
|
|
12 |
|
|
|
13 |
/* pointer to the VGA/MDA screen */
|
|
|
14 |
static unsigned short far *scr = (unsigned short far *)0xB8000000L;
|
|
|
15 |
|
|
|
16 |
void video_clear(unsigned short attr, int offset) {
|
|
|
17 |
int x;
|
|
|
18 |
for (x = offset; x < 2000; x++) {
|
|
|
19 |
scr[x] = attr;
|
|
|
20 |
}
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
/* inits screen, returns 0 for color mode, 1 for mono */
|
|
|
24 |
int video_init(void) {
|
|
|
25 |
union REGS r;
|
|
|
26 |
int monoflag;
|
|
|
27 |
/* get current video mode to detect color (7 = mono, anything else is color) */
|
|
|
28 |
r.h.ah = 0x0F;
|
|
|
29 |
int86(0x10, &r, &r);
|
|
|
30 |
/* set the monoflag to detected value and prepare the next mode we will set */
|
|
|
31 |
if (r.h.al == 7) {
|
|
|
32 |
monoflag = 1;
|
|
|
33 |
r.h.al = 7; /* 80x25 2 colors (MDA / Hercules) */
|
|
|
34 |
scr = (unsigned short far *)0xB0000000L;
|
|
|
35 |
} else if (r.h.al == 2) { /* 80x25 grayscale */
|
|
|
36 |
monoflag = 1;
|
|
|
37 |
r.h.al = 2; /* 80x25 grayscale */
|
|
|
38 |
scr = (unsigned short far *)0xB8000000L;
|
|
|
39 |
} else {
|
|
|
40 |
monoflag = 0;
|
|
|
41 |
r.h.al = 3; /* 80x25 16 colors */
|
|
|
42 |
scr = (unsigned short far *)0xB8000000L;
|
|
|
43 |
}
|
|
|
44 |
/* (re)set video mode to be sure what we are dealing with */
|
|
|
45 |
r.h.ah = 0;
|
|
|
46 |
int86(0x10, &r, &r);
|
|
|
47 |
return(monoflag);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
void video_putchar(int y, int x, unsigned short attr, int c) {
|
|
|
51 |
scr[(y << 6) + (y << 4) + x] = attr | c;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
void video_putcharmulti(int y, int x, unsigned short attr, int c, int repeat, int step) {
|
|
|
55 |
int offset = (y << 6) + (y << 4) + x;
|
|
|
56 |
while (repeat-- > 0) {
|
|
|
57 |
scr[offset] = attr | c;
|
|
|
58 |
offset += step;
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
void video_putstring(int y, int x, unsigned short attr, char *s) {
|
|
|
63 |
x += (y << 6) + (y << 4); /* I use x as an offset now */
|
|
|
64 |
while (*s != 0) {
|
|
|
65 |
scr[x++] = attr | *s;
|
|
|
66 |
s++;
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
void video_putstringfix(int y, int x, unsigned short attr, char *s, int w) {
|
|
|
71 |
x += (y << 6) + (y << 4); /* I use x as an offset now */
|
|
|
72 |
while (w-- > 0) {
|
|
|
73 |
scr[x++] = attr | *s;
|
|
|
74 |
if (*s != 0) s++;
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
void video_movecursor(int y, int x) {
|
|
|
79 |
union REGS r;
|
|
|
80 |
r.h.ah = 2;
|
|
|
81 |
r.h.bh = 0;
|
|
|
82 |
r.h.dh = y;
|
|
|
83 |
r.h.dl = x;
|
|
|
84 |
int86(0x10, &r, &r);
|
|
|
85 |
}
|