Subversion Repositories SvarDOS

Rev

Rev 49 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
56 mv_fox 62
void video_putstring(int y, int x, unsigned short attr, char *s, int maxlen) {
49 mv_fox 63
  if (x < 0) { /* means 'center out' */
64
    int slen;
65
    for (slen = 0; s[slen] != 0; slen++); /* faster than strlen() */
66
    x = 40 - (slen >> 1);
67
  }
40 mv_fox 68
  x += (y << 6) + (y << 4); /* I use x as an offset now */
56 mv_fox 69
  while ((*s != 0) && (maxlen-- != 0)) {
40 mv_fox 70
    scr[x++] = attr | *s;
71
    s++;
72
  }
73
}
74
 
75
void video_putstringfix(int y, int x, unsigned short attr, char *s, int w) {
76
  x += (y << 6) + (y << 4); /* I use x as an offset now */
77
  while (w-- > 0) {
78
    scr[x++] = attr | *s;
79
    if (*s != 0) s++;
80
  }
81
}
82
 
83
void video_movecursor(int y, int x) {
84
  union REGS r;
85
  r.h.ah = 2;
86
  r.h.bh = 0;
87
  r.h.dh = y;
88
  r.h.dl = x;
89
  int86(0x10, &r, &r);
90
}