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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * scr_prsm.c
3
 *
4
 * Microwindows screen driver for the Isicad Prisma diskless workstation
5
 * by George Harvey.
6
 *
7
 * This is mostly 'glue' code, the real work is done by assembler routines
8
 * in asm_prsm.s.
9
 *
10
 * The Prisma has a custom graphics controller with a fixed resolution
11
 * 1280 x 1024, 256 color display. This would be great except that it
12
 * was desgined for CAD work, not graphical desktops. The only interface
13
 * to the the video display is through a set of control registers. These
14
 * support line drawing in hardware (any angle, any length, any colour)
15
 * but there is no way to access the video memory as a frame buffer.
16
 * There is a way to read and write individual pixels but it is VERY
17
 * slow so blitting is bad news.
18
 *
19
 * 26/02/00     first tests with Microwindows 0.87
20
 * 24/03/00     added blitter code
21
 *
22
 */
23
 
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include "device.h"
27
#ifdef _MINIX
28
#include <sys/types.h>
29
#endif
30
#include "genfont.h"
31
#include "genmem.h"
32
 
33
#define MY_PSD_ADDR     0x01000000      /* dummy video memory addr */
34
 
35
/* VB driver entry points*/
36
static PSD  VB_open(PSD psd);
37
static void VB_close(PSD psd);
38
static void VB_getscreeninfo(PSD psd,PMWSCREENINFO psi);;
39
static void VB_setpalette(PSD psd,int first,int count,MWPALENTRY *pal);
40
static void VB_drawpixel(PSD psd,MWCOORD x, MWCOORD y, MWPIXELVAL c);
41
static MWPIXELVAL VB_readpixel(PSD psd,MWCOORD x, MWCOORD y);
42
static void VB_drawhline(PSD psd,MWCOORD x1, MWCOORD x2, MWCOORD y,
43
         MWPIXELVAL c);
44
static void VB_drawvline(PSD psd,MWCOORD x,MWCOORD y1,MWCOORD y2,MWPIXELVAL c);
45
static void VB_fillrect(PSD psd,MWCOORD x1,MWCOORD y1,MWCOORD x2,MWCOORD y2,
46
        MWPIXELVAL c);
47
static void VB_blit(PSD destpsd,MWCOORD destx,MWCOORD desty,MWCOORD w,MWCOORD h,
48
        PSD srcpsd,MWCOORD srcx,MWCOORD srcy,long op);
49
 
50
/* low-level routines in asm_prsm.s */
51
void init_scr(void);
52
void c_pcmap(int cnt, int *map);
53
void c_ldraw4(int x1, int y1, int x2, int y2, int inten, int sel);
54
/* optimised block drawing routines */
55
void c_ldraw5y(int x1, int y1, int x2, int y2, int inten);
56
void c_ldraw5x(int x1, int y1, int x2, int y2, int inten);
57
int  r1pix3(int x, int y, int selmask);
58
void rd_rect2(int x1, int x2, int y1, int y2, unsigned char *buf);
59
void w1pix3(int x, int y, int selmask, int pixdata);
60
void wr_rect2(int x1, int x2, int y1, int y2, unsigned char *buf);
61
 
62
/* dummy routines for now */
63
static MWBOOL VB_mapmemgc(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,
64
        int linelen,int size,void *addr);
65
 
66
 
67
SCREENDEVICE    scrdev = {
68
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL,
69
        VB_open,
70
        VB_close,
71
        VB_getscreeninfo,
72
        VB_setpalette,
73
        VB_drawpixel,
74
        VB_readpixel,
75
        VB_drawhline,
76
        VB_drawvline,
77
        VB_fillrect,
78
        gen_fonts,
79
        VB_blit,
80
        NULL,                   /* preSelect */
81
        NULL,                   /* DrawArea */
82
        NULL,                   /* SetIOPermissions */
83
        gen_allocatememgc,
84
        VB_mapmemgc,
85
        gen_freememgc
86
};
87
 
88
static int *pr_cmap;            /* Prisma colour map */
89
 
90
static PSD
91
VB_open(PSD psd)
92
{
93
        /* allocate space for the colour map */
94
        if ((pr_cmap = (int *)malloc((size_t)(256 * sizeof(int)))) == NULL) {
95
                perror("malloc cmap");
96
                return(0);
97
        }
98
        memset(pr_cmap, 0, (256 * sizeof(int))); /* clear colour map */
99
 
100
        /* init driver variables */
101
        psd->xres = psd->xvirtres = 1280;
102
        psd->yres = psd->yvirtres = 1024;
103
        psd->planes = 1;
104
        psd->bpp = 8;
105
        psd->ncolors = 256;
106
        psd->pixtype = MWPF_PALETTE;
107
#if HAVEBLIT
108
        psd->flags = PSF_SCREEN | PSF_HAVEBLIT;
109
#else
110
        psd->flags = PSF_SCREEN;
111
#endif
112
        psd->addr = (void *)MY_PSD_ADDR;        /* dummy addr. */
113
        psd->linelen = 1280;
114
        init_scr();                             /* init VB and clear screen */
115
        printf("VB_open: finished open\n");     /* DEBUG */
116
        return psd;
117
}
118
 
119
static void
120
VB_close(PSD psd)
121
{
122
        /* should probably restore the default palette here */
123
        /* empty for now */
124
}
125
 
126
static void
127
VB_getscreeninfo(PSD psd,PMWSCREENINFO psi)
128
{
129
        psi->rows = psd->yvirtres;
130
        psi->cols = psd->xvirtres;
131
        psi->planes = psd->planes;
132
        psi->bpp = psd->bpp;
133
        psi->ncolors = psd->ncolors;
134
        psi->pixtype = psd->pixtype;
135
        psi->fonts = 1;
136
 
137
        /* 1280 x 1024 on a 16in monitor */
138
        psi->xdpcm = 40;        /* assumes screen width of 32 cm*/
139
        psi->ydpcm = 43;        /* assumes screen height of 24 cm*/
140
}
141
 
142
static void
143
VB_setpalette(PSD psd,int first,int count,MWPALENTRY *pal)
144
{
145
        int i, ind;
146
        MWPALENTRY *p;
147
 
148
        ind = first;
149
        for (i = 0; i < count; i++) {
150
                p = &pal[i];
151
                if (ind > 255) {
152
                        fprintf(stderr, "VB_setpalette: index out of range: %d\n", ind);
153
                        return;
154
                }
155
                *(pr_cmap + ind) = (ind << 24) | (p->r << 16) | (p->g << 8) |
156
                        (p->b);
157
                ind++;
158
        }
159
        /* to try and debug palette code in VNC... */
160
/*      if (count == 1) {
161
                printf("VB_setpalette: setting %d to %08x\n", first, \
162
                        *(pr_cmap + first));
163
        }
164
 */
165
        /* write a maximum of 16 entries at a time, any more doesn't work
166
         * reliably (no idea why not)
167
         */
168
        ind = first;
169
        while (count) {
170
                if (count >= 16) {
171
                        c_pcmap(16, (pr_cmap + ind));
172
                        count -= 16;
173
                        ind += 16;
174
                } else {
175
                        c_pcmap(count, (pr_cmap + ind));
176
                        count = 0;
177
                }
178
        }
179
 
180
}
181
 
182
static void
183
VB_drawpixel(PSD psd,MWCOORD x, MWCOORD y, MWPIXELVAL c)
184
{
185
        w1pix3(x, y, 255, (int)c);
186
}
187
 
188
static MWPIXELVAL
189
VB_readpixel(PSD psd,MWCOORD x, MWCOORD y)
190
{
191
        return((MWPIXELVAL)r1pix3(x, y, 255));
192
}
193
 
194
/* Draw horizontal line from x1,y to x2,y including final point*/
195
static void
196
VB_drawhline(PSD psd,MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
197
{
198
/*      ++x2;           /* draw final point*/
199
        y = 1023 - y;   /* flip y axis */
200
        c_ldraw4(x1, y, x2, y, (int)c, 255);
201
}
202
 
203
/* Draw a vertical line from x,y1 to x,y2 including final point*/
204
static void
205
VB_drawvline(PSD psd,MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
206
{
207
/*      ++y2;           /* draw final point*/
208
        y1 = 1023 - y1;
209
        y2 = 1023 - y2;
210
        c_ldraw4(x, y1, x, y2, (int)c, 255);
211
}
212
 
213
static void
214
VB_fillrect(PSD psd, MWCOORD x1, MWCOORD y1, MWCOORD x2, MWCOORD y2, MWPIXELVAL c)
215
{
216
        register int w, h;
217
 
218
        w = ((x2 - x1) >= 0) ? (x2 - x1) : (x1 - x2);    /* abs width */
219
        h = ((y2 - y1) >= 0) ? (y2 - y1) : (y1 - y2);    /* abs height */
220
        /* sanity check */
221
        if ((w > 1279) || (h > 1023))
222
                return;
223
        y1 = 1023 - y1;                 /* flip origin to top corner */
224
        y2 = 1023 - y2;
225
        if (w >= h) {
226
                /* width is greater, draw horizontal lines */
227
#if 0
228
                while(y2 <= y1) {
229
                        c_ldraw4(x1, y2, x2, y2, (int)c, 255);
230
                        y2++;
231
                }
232
#endif
233
                c_ldraw5y(x1, y2, x2, y1, (int)c);
234
        } else {
235
                /* height is greater, draw vertical lines */
236
#if 0
237
                while(x1 <= x2) {
238
                        c_ldraw4(x1, y2, x1, y1, (int)c, 255);
239
                        x1++;
240
                }
241
#endif
242
                c_ldraw5x(x1, y2, x2, y1, (int)c);
243
        }
244
}
245
 
246
/*
247
 * Blitting is going to be very slow on the Prisma!
248
 */
249
static void
250
VB_blit(PSD destpsd,MWCOORD destx,MWCOORD desty,MWCOORD w,MWCOORD h,
251
        PSD srcpsd,MWCOORD srcx,MWCOORD srcy,long op)
252
{
253
        int x1s, x1e, x2s, x2e, y1s, y1e, y2s, y2e;
254
        unsigned char *rect;
255
 
256
/*      printf("VB_blit\n");                    /* DEBUG */
257
        if ((rect = (unsigned char *)malloc((size_t)(w * h * sizeof(char))))
258
                        == NULL) {
259
                perror("malloc rect");
260
                return;
261
        }
262
        /* always copy in +ve direction */
263
        x1s = (w >= 0) ? srcx : (srcx + w);
264
        x2s = (w >= 0) ? destx : (destx + w);
265
        x1e = (w >= 0) ? (srcx + w) : srcx;
266
        x2e = (w >= 0) ? (destx + w) : destx;
267
        y1s = (h >= 0) ? srcy : (srcy + h);
268
        y2s = (h >= 0) ? desty : (desty + h);
269
        y1e = (h >= 0) ? (srcy + h) : srcy;
270
        y2e = (h >= 0) ? (desty + h) : desty;
271
 
272
        /* determine which PSD is the screen */
273
        if ((srcpsd->addr == MY_PSD_ADDR) && (destpsd->addr == MY_PSD_ADDR)) {
274
                /* screen to screen copy */
275
                /* copy rectangle into buffer */
276
                rd_rect2(x1s, y1s, x1e, y1e, rect);
277
                /* copy rectangle out of buffer */
278
                wr_rect2(x2s, y2s, x2e, y2e, rect);
279
        } else if (srcpsd->addr == MY_PSD_ADDR) {
280
                /* screen to off-screen */
281
        } else if (destpsd->addr == MY_PSD_ADDR) {
282
                /* off-screen to screen */
283
        } else {
284
                /* error ! */
285
                printf("VB_blit with no screen!\n");
286
        }
287
        free(rect);
288
}
289
 
290
static MWBOOL
291
VB_mapmemgc(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,int linelen,
292
        int size,void *addr)
293
{
294
        return 0;
295
}
296
 

powered by: WebSVN 2.1.0

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