File: lineart.c

package info (click to toggle)
svgalib 1%3A1.4.3-24
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,768 kB
  • ctags: 9,153
  • sloc: ansic: 59,341; makefile: 1,141; asm: 630; sh: 61; perl: 54; pascal: 49
file content (133 lines) | stat: -rw-r--r-- 3,149 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*  A program to test any mode for linear.  Default mode is G640x480x256 = 10
**  or parameters may be used giving modes as integers.
** linp [mode mode ...]
**                          Don Secrest Oct. 1998
*/

#include <vga.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

static void screen(int mode)
{
  int bpp,bott,endp,linlen,i,j,bii,col,p;
  vga_modeinfo *minf;
  unsigned char *vbuf;
  int mem;
  
  if(mode == 0)
    {
      printf("Usage:linp [mode mode ...]\n
              where mode is an integer.\n");
      return;
    }
  if(! vga_hasmode(mode)) {
    printf("Invalid mode %d\n",mode);
    return;
  }
  vga_setmode(mode);
  minf = vga_getmodeinfo(mode);
  if(! (minf->flags & CAPABLE_LINEAR)){
    vga_setmode(TEXT);
    printf("The mode %d is not capable of linear\n",mode);
    return;
  }
  vga_setpage(0);
  if(vga_setlinearaddressing() == -1) {
    vga_setmode(TEXT);
    printf("Could not set linear addressing for mode %d\n",mode);
    return;
  }
  bpp = minf->bytesperpixel;
  linlen = minf->width*bpp;
  bott = linlen*17;            /* pointer 17 pixels wide. */
  endp = linlen*minf->height;
  mem = minf->linewidth*minf->height;

  /* Do random pixels */
  vbuf = vga_getgraphmem();
  printf("Memory mapped to %08x. Mode = %d.\n",(int) vbuf,mode);
  memset(vbuf,0,mem);    /* Clear out 2 megabytes of memory, */
  for(i = 0;i < 100000;i++)
    {
      p = rand() % mem-2;
      *(vbuf + p) = rand() & 0xff;
      if(bpp > 1)
	*(vbuf + p + 1) = rand() & 0xff;
      if(bpp == 3) 
	*(vbuf + p + 2) = rand() & 0xff;
    }

  /* Place marker at top left and bottem right. */
  for(i = 0;i < 44;i += bpp) {
    *(vbuf + i) = 0x60;
    *(vbuf + bott + i) = 0x60;
    *(vbuf + endp - i) = 0x60;
    bii = endp -1 -bott;
    *(vbuf + bii -i) = 0x60;
    if(bpp > 1) {
      *(vbuf + i + 1) = 0x60;
      *(vbuf + i + 1 + bott) = 0x60;
      *(vbuf - i - 1 + endp) = 0x60;
      *(vbuf - i - 1 + bii) = 0x60;
    }
    if(bpp == 3) {
            *(vbuf + i + 2) = 0x60;
	    *(vbuf + i + 2 + bott) = 0x60;
	    *(vbuf - i - 2 + endp) = 0x60;
	    *(vbuf - i - 2 + bii) = 0x60;
    }
    col = (i == 0 || i >= 42)? 0x60:0;
    for(j = 1;j < 17;j++) {
      *(vbuf + i + linlen*j) = col;
      *(vbuf - i + endp -1 - linlen*j) = col;
      if(bpp > 1) {
	*(vbuf + i + 1 + linlen*j) = col;
	*(vbuf - i - 2 + endp - linlen*j) = col;
      }
      if(bpp == 3) {
	*(vbuf + i + 2 + linlen*j) = col;
	*(vbuf - i - 3 + endp - linlen*j) = col;
      }
    }
  }
  for(i = 5;i < 12;i += bpp)
    for(j = 4;j < 12;j++) {
            *(vbuf + i + linlen*j) = 0x3f;
	    *(vbuf + endp - i - bpp - linlen*j) = 0x3f;
    }
  getchar();   /* Wait for a key punch */
}

int
main(int argc,char *argv[])
{
  int mode,c;

  vga_init();
  c=1;
  if(argc == 1)
    screen(10);     /* G640x480x256 */
  else
    c = 0;
  while(argc > 1)
    {
      argc--;
      c++;
      if(isdigit(*argv[c]))
	mode = atoi(argv[c]);
      else if(*argv[c] == 'G')
	mode = vga_getmodenumber(argv[c]);
      else
	{
	  printf("Unknown mode %s\n",argv[c]);
	  continue;
	}
      screen(mode);
    }
  vga_setmode(TEXT);
  return 0;
}