Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
162 giacomo 1
/* VGAlib version 1.2 - (c) 1993 Tommy Frandsen                    */
2
/*                                                                 */
3
/* This library is free software; you can redistribute it and/or   */
4
/* modify it without any restrictions. This library is distributed */
5
/* in the hope that it will be useful, but without any warranty.   */
6
 
7
/* Multi-chipset support Copyright 1993 Harm Hanemaayer */
8
/* partially copyrighted (C) 1993 by Hartmut Schirmer */
9
/* HH: Added 4bpp support, and use bytesperpixel. */
10
 
11
#include <stdio.h>
12
#include "vga.h"
13
#include "libvga.h"
14
#include "driver.h"
15
 
16
static inline void read_write(unsigned long off)
17
{
18
    *(GM+off)=*(GM+off)+1;
19
}
20
 
21
int vga_drawpixel(int x, int y)
22
{
23
    unsigned long offset;
24
    int c;
25
 
26
    if (MODEX) {
27
             /* select plane */
28
             __svgalib_outseq(0x02,1 << (x & 3));
29
             /* write color to pixel */
30
             *(GM+y * CI.xbytes + (x >> 2))=COL;
31
        return 0;
32
    }
33
    switch (__svgalib_cur_info.bytesperpixel) {
34
    case 0:                     /* Must be 2 or 16 color mode. */
35
        /* set up video page */
36
        offset = y * CI.xbytes + (x >> 3);
37
        vga_setpage(offset >> 16);
38
        offset &= 0xffff;
39
 
40
        /* select bit */
41
        __svgalib_outgra(0x08, 0x80 >> (x & 7));
42
 
43
        /* read into latch and write dummy back */
44
        read_write(offset);
45
        break;
46
    case 1:
47
        offset = y * CI.xbytes + x;
48
 
49
        if (__svgalib_modeinfo_linearset & IS_LINEAR ) {
50
            *(LINEAR_POINTER+offset)=COL;
51
        } else {
52
            /* select segment */
53
            vga_setpage(offset >> 16);
54
 
55
            /* write color to pixel */
56
            *(GM+(offset&0xffff))=COL;
57
        }
58
        break;
59
    case 2:
60
        offset = y * CI.xbytes + x * 2;
61
        if (__svgalib_modeinfo_linearset & IS_LINEAR ) {
62
            *(uint16_t *)(LINEAR_POINTER+offset)=COL;
63
        } else {
64
            vga_setpage(offset >> 16);
65
            *(uint16_t *)(GM+(offset&0xffff))=COL;
66
        }
67
        break;
68
    case 3:
69
        c = COL;
70
        offset = y * CI.xbytes + x * 3;
71
        if (__svgalib_modeinfo_linearset & IS_LINEAR ) {
72
            /* Only on little endian */
73
            *(LINEAR_POINTER+offset)=COL&0xff;
74
            *(LINEAR_POINTER+offset+1)=(COL&0xff00)>>8;
75
            *(LINEAR_POINTER+offset+2)=(COL&0xff0000)>>16;
76
        } else {
77
            vga_setpage(offset >> 16);
78
            switch (offset & 0xffff) {
79
            case 0xfffe:
80
                *(GM+0xfffe)=COL&0xff;
81
                *(GM+0xffff)=(COL&0xff00)>>8;
82
                vga_setpage((offset >> 16) + 1);
83
                *(GM)=(COL&0xff0000)>>16;
84
                break;
85
            case 0xffff:
86
                *(GM+0xffff)=COL&0xff;
87
                vga_setpage((offset >> 16) + 1);
88
                *(GM)=(COL&0xff00)>>8;
89
                *(GM+1)=(COL&0xff0000)>>16;
90
                break;
91
            default:
92
                offset &= 0xffff;
93
                *(GM+offset)=COL&0xff;
94
                *(GM+offset+1)=(COL&0xff00)>>8;
95
                *(GM+offset+2)=(COL&0xff0000)>>16;
96
                break;
97
            }
98
        }
99
        break;
100
    case 4:
101
        offset = y * __svgalib_cur_info.xbytes + x * 4;
102
        if (__svgalib_modeinfo_linearset & IS_LINEAR ) {
103
            *(uint32_t *)(LINEAR_POINTER+offset)=COL;
104
        } else {
105
            vga_setpage(offset >> 16);
106
            *(uint32_t *)(GM+(offset&0xffff))=COL;
107
        }
108
        break;
109
    }
110
    return 0;
111
}
112
 
113
int vga_getpixel(int x, int y)
114
{
115
    unsigned long offset;
116
    unsigned char mask;
117
    int pix = 0;
118
 
119
    if (MODEX) {
120
             /* select plane */
121
             __svgalib_outseq(0x02, 1 << (x & 3) );        
122
        return gr_readb(y * CI.xbytes + (x >> 2));
123
    }
124
    switch (__svgalib_cur_info.bytesperpixel) {
125
    case 0:                     /* Must be 2 or 16 color mode. */
126
             /* set up video page */
127
             offset = y * CI.xbytes + (x >> 3);
128
             vga_setpage(offset >> 16);
129
             offset &= 0xffff;
130
 
131
             /* select bit */
132
             mask = 0x80 >> (x & 7);
133
             pix = 0;
134
             __svgalib_outgra(0x04,0);
135
             if (gr_readb(offset) & mask)
136
                pix |= 0x01;
137
             __svgalib_outgra(0x04,1);
138
             if (gr_readb(offset) & mask)
139
                pix |= 0x02;
140
             __svgalib_outgra(0x04,2);
141
             if (gr_readb(offset) & mask)
142
                pix |= 0x04;
143
             __svgalib_outgra(0x04,3);
144
             if (gr_readb(offset) & mask)
145
                pix |= 0x08;
146
        return pix;
147
    case 1:
148
        offset = y * CI.xbytes + x;
149
        if (__svgalib_modeinfo_linearset & IS_LINEAR ) {
150
            return *(LINEAR_POINTER+offset);
151
        }
152
        /* select segment */
153
        vga_setpage(offset >> 16);
154
        return gr_readb(offset & 0xffff);
155
    case 2:
156
        offset = y * CI.xbytes + x * 2;
157
        if (__svgalib_modeinfo_linearset & IS_LINEAR ) {
158
            return *(uint16_t *)(LINEAR_POINTER+offset);
159
        }
160
        vga_setpage(offset >> 16);
161
        return gr_readw(offset & 0xffff);
162
    case 3:
163
        offset = y * CI.xbytes + x * 3;
164
        if (__svgalib_modeinfo_linearset & IS_LINEAR ) {
165
            return (*(LINEAR_POINTER+offset)) + (*(LINEAR_POINTER+offset+1)<<8) +
166
                   (*(LINEAR_POINTER+offset+2)<<16);
167
        }
168
        vga_setpage(offset >> 16);
169
        switch (offset & 0xffff) {
170
        case 0xfffe:
171
            pix = gr_readw(0xfffe);
172
            vga_setpage((offset >> 16) + 1);
173
            return pix + (gr_readb(0) << 16);
174
        case 0xffff:
175
            pix = gr_readb(0xffff);
176
            vga_setpage((offset >> 16) + 1);
177
            return pix + (gr_readw(0) << 8);
178
        default:
179
            offset &= 0xffff;
180
            return gr_readw(offset) + (gr_readb(offset + 2) << 16);
181
        }
182
        break;
183
    case 4:
184
        offset = y * __svgalib_cur_info.xbytes + x * 4;
185
        if (__svgalib_modeinfo_linearset & IS_LINEAR ) {
186
            return *(uint32_t *)(LINEAR_POINTER+offset);
187
        }
188
        vga_setpage(offset >> 16);
189
        return gr_readl(offset & 0xffff);
190
    }
191
    return 0;
192
}
193