File: testlinear.c

package info (click to toggle)
oskit 0.97.20000202-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 58,008 kB
  • ctags: 172,612
  • sloc: ansic: 832,827; asm: 7,640; sh: 3,920; yacc: 3,664; perl: 1,457; lex: 427; makefile: 337; csh: 141; awk: 78
file content (130 lines) | stat: -rw-r--r-- 3,000 bytes parent folder | download
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

/* 
   Simple test program for Cirrus linear addressing/color expansion.
   vgagl can take advantage of it (linear addressing).
 */


#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <oskit/svgalib/vga.h>
#include <time.h>
#ifdef 0
#include "../src/libvga.h"
#else
#include <oskit/x86/pio.h>
#endif
#include <oskit/clientos.h>

#define USE_LINEAR_ADDRESSING
/* #define USE_BY16_ADDRESSING */


unsigned char *vbuf;

#if 0
/* This function is Cirrus specific and has nothing to do with linear
 * addressing. */
void by8test(void)
{
    int i;
    int startclock, diffclock;

    /* Enable extended write modes and BY8/16 addressing. */
    outb(0x3ce, 0x0b);

#ifdef USE_BY16_ADDRESSING
    outb(0x3cf, inb(0x3cf) | 0x16);
#else
    outb(0x3cf, inb(0x3cf) | 0x06);
#endif
    /* Set extended write mode 4. */
    outb(0x3ce, 0x05);
    outb(0x3cf, (inb(0x3cf) & 0xf8) | 4);

    /* Set pixel mask register (coincides with VGA plane mask register). */
    outw(0x3c4, 0xff02);

    startclock = clock();
    for (i = 0; i < 248; i++) {
	outw(0x3ce, 0x01 + (i << 8));	/* Set foreground color. */
#ifdef USE_BY16_ADDRESSING
	outw(0x3ce, 0x11 + (i << 8));	/* Set high byte. */
	memset(vbuf, 0xff, 640 * 480 / 16);
#else
	memset(vbuf, 0xff, 640 * 480 / 8);
#endif
    }
    diffclock = clock() - startclock;
    printf("Color expansion framebuffer fill speed: %dK/s\n",
	   640 * 480 * 248 / diffclock / 10);
}
#endif

void main(int argc, char *argv[])
{
    int i,j;

    oskit_clientos_init();

    if (!(argc == 2 && strcmp(argv[1], "--force") == 0))
	if (!(vga_getmodeinfo(G640x480x256)->flags & CAPABLE_LINEAR)) {
	    printf("Linear addressing not supported for this chipset.\n");
	    exit(1);
	}
    vga_init();
    vga_setmode(G640x480x256);
    vga_setpage(0);
#ifdef USE_LINEAR_ADDRESSING
    if (vga_setlinearaddressing() == -1) {
	vga_setmode(TEXT);
	printf("Could not set linear addressing.\n");
	exit(-1);
    }
#endif

    /* Should not mess with bank register after this. */

    vbuf = vga_getgraphmem();
    printf("vbuf mapped at %08lx.\n", (unsigned long) vbuf);

    getchar();

#ifdef USE_LINEAR_ADDRESSING
    memset(vbuf, 0x88, 640 * 480);
    sleep(1);

    memset(vbuf, 0, 640 * 480);
    for (i = 0; i < 100000; i++)
	*(vbuf + (rand() & 0xfffff)) = rand();
#endif

#if 0
    if (vga_getcurrentchipset() == CIRRUS)
	/* Show the bandwidth of the extended write modes of the */
	/* Cirrus chip. */
	by8test();
#endif

    getchar();
    for(i = 0;i < 44;i++){
      *(vbuf + i) = 0x1c;
      *(vbuf + 640*17 + i) = 0x1c;
      *(vbuf + 640*480 - i) = 0x1c;
      *(vbuf + 640*480 - 1 - 640*17 - i) = 0x1c;
      for(j = 1;j < 17;j++){
	*(vbuf + 640*j + i) = (i == 0 || i == 43)? 0x1c:0;
	*(vbuf + 640*480 - 1 - 640*j - i) = (i == 0 || i == 43)? 0x1c:0;
      }
    }
    for(i = 3;i < 10;i++)
      for(j = 4;j < 10;j++){
	*(vbuf + i + 640*j) = 0x3f;
	*(vbuf + 640*480 -1 -640*j - i) = 0x3f;
      }
    getchar();
    vga_setmode(TEXT);
}