Subversion Repositories SvarDOS

Rev

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

Rev Author Line No. Line
40 mv_fox 1
/*
190 mateuszvis 2
 * Video routines used by the SvarDOS installer
40 mv_fox 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
 
81 mv_fox 16
void video_clear(unsigned short attr, int offset, int offsetend) {
17
  offsetend += 2000;
18
  while (offset < offsetend) scr[offset++] = attr;
40 mv_fox 19
}
20
 
21
/* inits screen, returns 0 for color mode, 1 for mono */
22
int video_init(void) {
23
  union REGS r;
24
  int monoflag;
25
  /* get current video mode to detect color (7 = mono, anything else is color) */
26
  r.h.ah = 0x0F;
27
  int86(0x10, &r, &r);
28
  /* set the monoflag to detected value and prepare the next mode we will set */
29
  if (r.h.al == 7) {
30
    monoflag = 1;
31
    r.h.al = 7; /* 80x25 2 colors (MDA / Hercules) */
32
    scr = (unsigned short far *)0xB0000000L;
33
  } else if (r.h.al == 2) { /* 80x25 grayscale */
34
    monoflag = 1;
35
    r.h.al = 2; /* 80x25 grayscale */
36
    scr = (unsigned short far *)0xB8000000L;
37
  } else {
38
    monoflag = 0;
39
    r.h.al = 3; /* 80x25 16 colors */
40
    scr = (unsigned short far *)0xB8000000L;
41
  }
42
  /* (re)set video mode to be sure what we are dealing with */
43
  r.h.ah = 0;
44
  int86(0x10, &r, &r);
45
  return(monoflag);
46
}
47
 
48
void video_putchar(int y, int x, unsigned short attr, int c) {
49
  scr[(y << 6) + (y << 4) + x] = attr | c;
50
}
51
 
52
void video_putcharmulti(int y, int x, unsigned short attr, int c, int repeat, int step) {
53
  int offset = (y << 6) + (y << 4) + x;
54
  while (repeat-- > 0) {
55
    scr[offset] = attr | c;
56
    offset += step;
57
  }
58
}
59
 
191 mateuszvis 60
void video_putstring(int y, int x, unsigned short attr, const char *s, int maxlen) {
49 mv_fox 61
  if (x < 0) { /* means 'center out' */
62
    int slen;
63
    for (slen = 0; s[slen] != 0; slen++); /* faster than strlen() */
64
    x = 40 - (slen >> 1);
65
  }
40 mv_fox 66
  x += (y << 6) + (y << 4); /* I use x as an offset now */
56 mv_fox 67
  while ((*s != 0) && (maxlen-- != 0)) {
40 mv_fox 68
    scr[x++] = attr | *s;
69
    s++;
70
  }
71
}
72
 
191 mateuszvis 73
void video_putstringfix(int y, int x, unsigned short attr, const char *s, int w) {
40 mv_fox 74
  x += (y << 6) + (y << 4); /* I use x as an offset now */
75
  while (w-- > 0) {
76
    scr[x++] = attr | *s;
77
    if (*s != 0) s++;
78
  }
79
}
80
 
81
void video_movecursor(int y, int x) {
82
  union REGS r;
83
  r.h.ah = 2;
84
  r.h.bh = 0;
85
  r.h.dh = y;
86
  r.h.dl = x;
87
  int86(0x10, &r, &r);
88
}