OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [drivers/] [memplan4.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com>
3
 *
4
 * 4 planes EGA/VGA Memory (blitting) Video Driver for Microwindows
5
 * Included with #define HAVEBLIT in vgaplan4.h
6
 *
7
 * 4bpp colors are stored in linear 4pp format in memory dc's
8
 *
9
 *      In this driver, psd->linelen is line byte length, not line pixel length
10
 */
11
/*#define NDEBUG*/
12
#include <assert.h>
13
#include <stdio.h>
14
#include <string.h>
15
#include "device.h"
16
#include "vgaplan4.h"
17
#include "fb.h"
18
 
19
#if HAVEBLIT
20
 
21
#if MSDOS | ELKS | __rtems__
22
/* assumptions for speed: NOTE: psd is ignored in these routines*/
23
#define SCREENBASE(psd)         EGA_BASE
24
#define BYTESPERLINE(psd)       80
25
#else
26
/* run on top of framebuffer*/
27
#define SCREENBASE(psd)         ((char *)((psd)->addr))
28
#define BYTESPERLINE(psd)       ((psd)->linelen)
29
#endif
30
 
31
/* extern data*/
32
extern int gr_mode;     /* temp kluge*/
33
 
34
static unsigned char notmask[2] = { 0x0f, 0xf0};
35
 
36
/* Calc linelen and mmap size, return 0 on fail*/
37
static int
38
mempl4_init(PSD psd)
39
{
40
        if (!psd->size)
41
                psd->size = psd->yres * psd->linelen;
42
        /* linelen in bytes for bpp 1, 2, 4, 8 so no change*/
43
        return 1;
44
}
45
 
46
/* Set pixel at x, y, to pixelval c*/
47
static void
48
mempl4_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
49
{
50
        ADDR8   addr = psd->addr;
51
 
52
        assert (addr != 0);
53
        assert (x >= 0 && x < psd->xres);
54
        assert (y >= 0 && y < psd->yres);
55
        assert (c < psd->ncolors);
56
 
57
        addr += (x>>1) + y * psd->linelen;
58
        if(gr_mode == MWMODE_XOR)
59
                *addr ^= c << ((1-(x&1))<<2);
60
        else
61
                *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
62
}
63
 
64
/* Read pixel at x, y*/
65
static MWPIXELVAL
66
mempl4_readpixel(PSD psd, MWCOORD x, MWCOORD y)
67
{
68
        ADDR8   addr = psd->addr;
69
 
70
        assert (addr != 0);
71
        assert (x >= 0 && x < psd->xres);
72
        assert (y >= 0 && y < psd->yres);
73
 
74
        return (addr[(x>>1) + y * psd->linelen] >> ((1-(x&1))<<2) ) & 0x0f;
75
}
76
 
77
/* Draw horizontal line from x1,y to x2,y including final point*/
78
static void
79
mempl4_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
80
{
81
        ADDR8   addr = psd->addr;
82
 
83
        assert (addr != 0);
84
        assert (x1 >= 0 && x1 < psd->xres);
85
        assert (x2 >= 0 && x2 < psd->xres);
86
        assert (x2 >= x1);
87
        assert (y >= 0 && y < psd->yres);
88
        assert (c < psd->ncolors);
89
 
90
        addr += (x1>>1) + y * psd->linelen;
91
        if(gr_mode == MWMODE_XOR) {
92
                while(x1 <= x2) {
93
                        *addr ^= c << ((1-(x1&1))<<2);
94
                        if((++x1 & 1) == 0)
95
                                ++addr;
96
                }
97
        } else {
98
                while(x1 <= x2) {
99
                        *addr = (*addr & notmask[x1&1]) | (c << ((1-(x1&1))<<2));
100
                        if((++x1 & 1) == 0)
101
                                ++addr;
102
                }
103
        }
104
}
105
 
106
/* Draw a vertical line from x,y1 to x,y2 including final point*/
107
static void
108
mempl4_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
109
{
110
        ADDR8   addr = psd->addr;
111
        int     linelen = psd->linelen;
112
 
113
        assert (addr != 0);
114
        assert (x >= 0 && x < psd->xres);
115
        assert (y1 >= 0 && y1 < psd->yres);
116
        assert (y2 >= 0 && y2 < psd->yres);
117
        assert (y2 >= y1);
118
        assert (c < psd->ncolors);
119
 
120
        addr += (x>>1) + y1 * linelen;
121
        if(gr_mode == MWMODE_XOR)
122
                while(y1++ <= y2) {
123
                        *addr ^= c << ((1-(x&1))<<2);
124
                        addr += linelen;
125
                }
126
        else
127
                while(y1++ <= y2) {
128
                        *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
129
                        addr += linelen;
130
                }
131
}
132
 
133
/* srccopy bitblt, opcode is currently ignored*/
134
/* copy from memdc to memdc*/
135
static void
136
mempl4_to_mempl4_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
137
        PSD srcpsd, MWCOORD srcx, MWCOORD srcy, int op)
138
{
139
        ADDR8   dst;
140
        ADDR8   src;
141
        int     i;
142
        int     dlinelen = dstpsd->linelen;
143
        int     slinelen = srcpsd->linelen;
144
 
145
        assert (dstpsd->addr != 0);
146
        assert (dstx >= 0 && dstx < dstpsd->xres);
147
        assert (dsty >= 0 && dsty < dstpsd->yres);
148
        assert (w > 0);
149
        assert (h > 0);
150
        assert (srcpsd->addr != 0);
151
        assert (srcx >= 0 && srcx < srcpsd->xres);
152
        assert (srcy >= 0 && srcy < srcpsd->yres);
153
        assert (dstx+w <= dstpsd->xres);
154
        assert (dsty+h <= dstpsd->yres);
155
        assert (srcx+w <= srcpsd->xres);
156
        assert (srcy+h <= srcpsd->yres);
157
 
158
        dst = (char *)dstpsd->addr + (dstx>>1) + dsty * dlinelen;
159
        src = (char *)srcpsd->addr + (srcx>>1) + srcy * slinelen;
160
        while(--h >= 0) {
161
                ADDR8   d = dst;
162
                ADDR8   s = src;
163
                MWCOORD dx = dstx;
164
                MWCOORD sx = srcx;
165
                for(i=0; i<w; ++i) {
166
                        *d = (*d & notmask[dx&1]) |
167
                           ((*s >> ((1-(sx&1))<<2) & 0x0f) << ((1-(dx&1))<<2));
168
                        if((++dx & 1) == 0)
169
                                ++d;
170
                        if((++sx & 1) == 0)
171
                                ++s;
172
                }
173
                dst += dlinelen;
174
                src += slinelen;
175
        }
176
}
177
 
178
/* srccopy bitblt, opcode is currently ignored*/
179
/* copy from vga memory to vga memory, psd's ignored for speed*/
180
static void
181
vga_to_vga_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
182
        PSD srcpsd, MWCOORD srcx, MWCOORD srcy, int op)
183
{
184
        FARADDR dst;
185
        FARADDR src;
186
        int     i, plane;
187
        int     x1, x2;
188
 
189
        assert (dstx >= 0 && dstx < dstpsd->xres);
190
        assert (dsty >= 0 && dsty < dstpsd->yres);
191
        assert (w > 0);
192
        assert (h > 0);
193
        assert (srcx >= 0 && srcx < srcpsd->xres);
194
        assert (srcy >= 0 && srcy < srcpsd->yres);
195
        assert (dstx+w <= dstpsd->xres);
196
        assert (dsty+h <= dstpsd->yres);
197
        assert (srcx+w <= srcpsd->xres);
198
        assert (srcy+h <= srcpsd->yres);
199
 
200
        DRAWON;
201
        set_enable_sr(0);
202
        dst = SCREENBASE(dstpsd) + (dstx>>3) + dsty * BYTESPERLINE(dstpsd);
203
        src = SCREENBASE(srcpsd) + (srcx>>3) + srcy * BYTESPERLINE(srcpsd);
204
        x1 = dstx>>3;
205
        x2 = (dstx + w - 1) >> 3;
206
        while(--h >= 0) {
207
                for(plane=0; plane<4; ++plane) {
208
                        FARADDR d = dst;
209
                        FARADDR s = src;
210
 
211
                        set_read_plane(plane);
212
                        set_write_planes(1 << plane);
213
 
214
                        /* FIXME: only works if srcx and dstx are same modulo*/
215
                        if(x1 == x2) {
216
                                select_and_set_mask((0xff >> (x1 & 7)) & (0xff << (7 - (x2 & 7))));
217
                                PUTBYTE_FP(d, GETBYTE_FP(s));
218
                        } else {
219
                                select_and_set_mask(0xff >> (x1 & 7));
220
                                PUTBYTE_FP(d++, GETBYTE_FP(s++));
221
 
222
                                set_mask(0xff);
223
                                for(i=x1+1; i<x2; ++i)
224
                                        PUTBYTE_FP(d++, GETBYTE_FP(s++));
225
 
226
                                set_mask(0xff << (7 - (x2 & 7)));
227
                                PUTBYTE_FP(d, GETBYTE_FP(s));
228
                        }
229
                }
230
                dst += BYTESPERLINE(dstpsd);
231
                src += BYTESPERLINE(srcpsd);
232
        }
233
        set_write_planes(0x0f);
234
        set_enable_sr(0x0f);
235
        DRAWOFF;
236
}
237
 
238
/* srccopy bitblt, opcode is currently ignored*/
239
/* copy from memdc to vga memory*/
240
static void
241
mempl4_to_vga_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
242
        PSD srcpsd, MWCOORD srcx, MWCOORD srcy, int op)
243
{
244
        FARADDR dst;
245
        ADDR8   src;
246
        int     i;
247
        int     slinelen = srcpsd->linelen;
248
        int     color, lastcolor = -1;
249
        static unsigned char mask[8] = {
250
                0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
251
        };
252
 
253
        assert (dstx >= 0 && dstx < dstpsd->xres);
254
        assert (dsty >= 0 && dsty < dstpsd->yres);
255
        assert (w > 0);
256
        assert (h > 0);
257
        assert (srcpsd->addr != 0);
258
        assert (srcx >= 0 && srcx < srcpsd->xres);
259
        assert (srcy >= 0 && srcy < srcpsd->yres);
260
        assert (dstx+w <= dstpsd->xres);
261
        assert (dsty+h <= dstpsd->yres);
262
        assert (srcx+w <= srcpsd->xres);
263
        assert (srcy+h <= srcpsd->yres);
264
 
265
        DRAWON;
266
        set_op(0);               /* modetable[MWMODE_COPY]*/
267
        dst = SCREENBASE(dstpsd) + (dstx>>3) + dsty * BYTESPERLINE(dstpsd);
268
        src = (char *)srcpsd->addr + (srcx>>1) + srcy * slinelen;
269
        while(--h >= 0) {
270
                FARADDR d = dst;
271
                ADDR8   s = src;
272
                MWCOORD dx = dstx;
273
                MWCOORD sx = srcx;
274
                for(i=0; i<w; ++i) {
275
                        color = *s >> ((1-(sx&1))<<2) & 0x0f;
276
                        if(color != lastcolor)
277
                                set_color(lastcolor = color);
278
                        select_and_set_mask (mask[dx&7]);
279
                        RMW_FP(d);
280
 
281
                        if((++dx & 7) == 0)
282
                                ++d;
283
                        if((++sx & 1) == 0)
284
                                ++s;
285
                }
286
                dst += BYTESPERLINE(dstpsd);
287
                src += slinelen;
288
        }
289
        DRAWOFF;
290
}
291
 
292
/* srccopy bitblt, opcode is currently ignored*/
293
/* copy from vga memory to memdc*/
294
static void
295
vga_to_mempl4_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
296
        PSD srcpsd, MWCOORD srcx, MWCOORD srcy, int op)
297
{
298
        printf("vga_to_mempl4 called, not implemented\n");
299
        /* FIXME*/
300
}
301
 
302
void
303
ega_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
304
        PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
305
{
306
        MWBOOL  srcvga, dstvga;
307
 
308
        /* decide which blit algorithm to use*/
309
        srcvga = srcpsd->flags & PSF_SCREEN;
310
        dstvga = dstpsd->flags & PSF_SCREEN;
311
 
312
        if(srcvga) {
313
                if(dstvga)
314
                        vga_to_vga_blit(dstpsd, dstx, dsty, w, h,
315
                                srcpsd, srcx, srcy, op);
316
                else
317
                        vga_to_mempl4_blit(dstpsd, dstx, dsty, w, h,
318
                                srcpsd, srcx, srcy, op);
319
        } else {
320
                if(dstvga)
321
                        mempl4_to_vga_blit(dstpsd, dstx, dsty, w, h,
322
                                srcpsd, srcx, srcy, op);
323
                else
324
                        mempl4_to_mempl4_blit(dstpsd, dstx, dsty, w, h,
325
                                srcpsd, srcx, srcy, op);
326
        }
327
}
328
 
329
SUBDRIVER memplan4 = {
330
        mempl4_init,
331
        mempl4_drawpixel,
332
        mempl4_readpixel,
333
        mempl4_drawhorzline,
334
        mempl4_drawvertline,
335
        gen_fillrect,
336
        ega_blit
337
};
338
 
339
#endif /* HAVEBLIT*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.