File: bg_test.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 (129 lines) | stat: -rw-r--r-- 2,378 bytes parent folder | download | duplicates (9)
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
/*                             bg_test.c


	Copyright (c) 1997  Michael Friman. All rights reserved.


*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <vga.h>
#include <vgagl.h>

/*
  If you really want to see background runin, add after 
  vga_setmode vga_runinbackground(1) in fun.
  Remember to compile the svgalib with background.
*/

int go = 0;
int linear = 0;

void drawline(int x1, int y1, int x2, int y2)

{
 if (linear)
     {
      gl_line(x1,y1,x2,y2,vga_white());
     }
 else
     {
      vga_drawline(x1,y1,x2,y2);
     }
}

void set_go(void)

{
 go=1;
 return;
}

int main(int argc, char *argv[])

{
 int x[2];
 int y[2];
 int counter;
 int mode;

 if ((argc > 2) || ((argc == 2) && (strcmp(argv[1], "linear") != 0)))
     {
      fputs("Usage: bg_test [linear]\n", stderr);
      exit(2);
     }
 vga_init();
 printf("This is small test for background runin.\n");
 if (vga_runinbackground_version()==1)
     {
      printf("Background runin enabled. mode 1\n");
     }
   else
     {
      printf("Svgalib is not mode 1 background capable.\n");
      printf("Test ended.\n");
      return(0);
     }
 printf("Switch to another console when the box appears.\n");
 printf("Press enter to continue or CTRL-c to stop.\n");
 getchar();
 
 mode = vga_getdefaultmode();
 if (mode < 0)
     mode = G320x200x256;
 if (argc == 2)
     {
      if (vga_getmodeinfo(mode)->flags & CAPABLE_LINEAR)
       {
	vga_setlinearaddressing();
	fputs("Linear mode set.\n", stderr);
        linear = 1;
       }
      else
       {
	fputs("Linear mode unavailable.\n", stderr);
       }
     }
 vga_setmode(mode);
 if (linear)
     gl_setcontextvga(mode);
 vga_runinbackground(VGA_GOTOBACK,set_go); 
 vga_runinbackground(1); 
 x[0]=0;
 y[0]=0;
 x[1]=vga_getxdim()-1;
 y[1]=vga_getydim()-1;

 if (!linear)
     vga_setcolor(vga_white()); 
 counter=(y[1]/11)*5+1;
 while(counter<=(y[1]/11)*6)
   {
    drawline((x[1]/11)*5,counter,(x[1]/11)*6,counter);
    counter++;
   }
   
 /* Program won't go further without console switching. */
 
 while(!go) usleep(1000);
  
 drawline(x[0],y[0],x[1],y[0]);
 drawline(x[1],y[0],x[1],y[1]);
 drawline(x[1],y[1],x[0],y[1]);
 drawline(x[0],y[1],x[0],y[0]);

 drawline(x[0],y[0],x[1],y[1]);
 drawline(x[1],y[0],x[0],y[1]);


 while(!vga_getkey());
 
 vga_setmode(TEXT);
 
 printf("Ok.\n");
 return(0);
}