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

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [drivers/] [scr_bios.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
 * EGA/VGA 16 color 4 planes Screen Driver, direct hardware or bios
5
 *      If HWINIT 1 is #defined, the file vgainit.c is
6
 *      used to provide non-bios direct hw initialization of the VGA
7
 *      chipset.  Otherwise, this driver uses int10 bios to
8
 *      set/reset graphics/text modes.
9
 *
10
 *      If ROMFONT is #defined, the file romfont.c is used to
11
 *      draw all fonts, afte the bios is called to
12
 *      get the address of the ROM character font which
13
 *      is used for the character bitmaps.  Otherwise, the
14
 *      file genfont.c is used to draw linked in fonts, without
15
 *      consulting the bios.
16
 *
17
 *      All other access to the hardware is controlled through this driver.
18
 *
19
 *      Blitting enabled with #define HAVEBLIT in vgaplan4.h
20
 *
21
 *      This driver links with one of two other files, vgaplan4.c,
22
 *      the portable VGA 4 planes 16 color driver, or asmplan4.s, which
23
 *      is 8086 assembly language for speed.  This file itself
24
 *      doesn't know about any planar or packed arrangement, relying soley
25
 *      on the following external routines for all graphics drawing:
26
 *              ega_init, ega_drawpixel, ega_readpixel,
27
 *              ega_drawhorzline, ega_drawvertline
28
 *
29
 *      All text/font drawing code is based on the above routines and
30
 *      the included entry points for getting the ROM bitmap data.
31
 *
32
 *      If the environment variable EGAMODE is set, the driver implements
33
 *      the EGA 640x350 (mode 10h) resolution, otherwise 640x480 (mode 12h)
34
 *      graphics mode is set.
35
 *
36
 *      The environment variable CHARHEIGHT if set will set the assumed rom
37
 *      font character height, which defaults to 14.
38
 *
39
 */
40
#if _MINIX
41
#include <fcntl.h>
42
#include <unistd.h>
43
#include <string.h>
44
#include <ibm/int86.h>
45
#include <sys/ioctl.h>
46
#define HWINIT          0        /* =1 for non-bios direct hardware init*/
47
#define ROMFONT         0        /* =0 no bios rom fonts available*/
48
#else
49
#ifdef __rtems__
50
#define HWINIT          1       /* =1 for non-bios direct hardware init*/
51
#define ROMFONT         0        /* =0 no bios rom fonts available*/
52
#else
53
#define HWINIT          0        /* =1 for non-bios direct hardware init*/
54
#define ROMFONT         1       /* =1 uses PC rom fonts */
55
#endif
56
#endif
57
 
58
#if ELKS
59
#include <linuxmt/ntty.h>
60
#endif
61
#include <stdio.h>
62
#include <stdlib.h>
63
#include "device.h"
64
#include "vgaplan4.h"
65
#if ROMFONT
66
#include "romfont.h"
67
#else
68
#include "genfont.h"
69
#endif
70
#include "genmem.h"
71
#include "fb.h"
72
 
73
/* VGA driver entry points*/
74
static PSD  VGA_open(PSD psd);
75
static void VGA_close(PSD psd);
76
#if _MINIX
77
static void VGA_getscreeninfo(PSD psd,PMWSCREENINFO psi);
78
#else
79
static void VGA_getscreeninfo(PSD psd,PMWSCREENINFO psi);;
80
#endif
81
static void VGA_setpalette(PSD psd,int first,int count,MWPALENTRY *pal);
82
static MWBOOL VGA_mapmemgc(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,
83
                int linelen,int size,void *addr);
84
static void NULL_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w,
85
                MWCOORD h, PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op) {}
86
static PSD  NULL_allocatememgc(PSD psd) { return NULL; }
87
static MWBOOL NULL_mapmemgc(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,
88
                        int linelen,int size,void *addr) { return 0; }
89
static void NULL_freememgc(PSD mempsd) {}
90
 
91
SCREENDEVICE    scrdev = {
92
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL,
93
        VGA_open,
94
        VGA_close,
95
        VGA_getscreeninfo,
96
        VGA_setpalette,
97
        ega_drawpixel,
98
        ega_readpixel,
99
        ega_drawhorzline,
100
        ega_drawvertline,
101
        gen_fillrect,
102
#if ROMFONT
103
        pcrom_fonts,
104
#else
105
        gen_fonts,
106
#endif
107
#if HAVEBLIT
108
        ega_blit,               /* Blit*/
109
#else
110
        NULL_blit,              /* Blit*/
111
#endif
112
        NULL,                   /* PreSelect*/
113
        NULL,                   /* DrawArea*/
114
        NULL,                   /* SetIOPermissions*/
115
        gen_allocatememgc,
116
        VGA_mapmemgc,
117
        gen_freememgc
118
};
119
 
120
/* operating mode*/
121
static MWBOOL VGAMODE = TRUE;   /* ega or vga screen rows*/
122
 
123
/* int10 functions*/
124
#define FNGR640x480     0x0012  /* function for graphics mode 640x480x16*/
125
#define FNGR640x350     0x0010  /* function for graphics mode 640x350x16*/
126
#define FNTEXT          0x0003  /* function for 80x25 text mode*/
127
 
128
#if _MINIX
129
FARADDR int10(int mode, int z)
130
{
131
int fd;
132
struct mio_int86 mint86;
133
 
134
   fd = open("/dev/mem", O_RDONLY);
135
   memset(&mint86, 0, sizeof(mint86));
136
   ioctl(fd, MIOCINT86, &mint86);
137
   mint86.reg86.b.intno = 0x10;
138
   mint86.reg86.b.al = mode & 0xFF;
139
   ioctl(fd, MIOCINT86, &mint86);
140
   close(fd);
141
}
142
#endif
143
 
144
static PSD
145
VGA_open(PSD psd)
146
{
147
#if _MINIX
148
int s;
149
struct mio_ldt86 mldt86;
150
struct segdesc_s {              /* segment descriptor for protected mode */
151
        u16_t limit_low;
152
        u16_t base_low;
153
        u8_t base_middle;
154
        u8_t access;                  /* |P|DL|1|X|E|R|A| */
155
        u8_t granularity;             /* |G|X|0|A|LIMT| */
156
        u8_t base_high;
157
} *dp;
158
int fd;
159
unsigned long vidmem = 0xA0000;
160
 
161
        fd = open("/dev/mem", O_RDONLY);
162
        dp = (struct segdesc_s *) mldt86.entry;
163
        mldt86.idx = 1;
164
        s = ioctl(fd, MIOCGLDT86, &mldt86);
165
        dp->limit_low    = 0xFFFF;
166
        dp->base_low     = (vidmem >>  0) & 0xFFFF;
167
        dp->base_middle  = (vidmem >> 16) & 0xFF;
168
        dp->base_high    = (vidmem >> 24) & 0xFF;
169
        dp->granularity |= 0x80;
170
        mldt86.idx = 2;
171
        s = ioctl(fd, MIOCSLDT86, &mldt86);
172
        close(fd);
173
#endif
174
        /* setup operating mode from environment variable*/
175
        if(getenv("EGAMODE"))
176
                VGAMODE = FALSE;
177
        else VGAMODE = TRUE;
178
 
179
#if ELKS
180
        /* disallow console switching while in graphics mode*/
181
        if(ioctl(0, DCGET_GRAPH) != 0)
182
                return NULL;
183
#endif
184
 
185
#if HWINIT
186
        /* enter graphics mode*/
187
        ega_hwinit();
188
#else
189
        /* init bios graphics mode*/
190
        int10(VGAMODE? FNGR640x480: FNGR640x350, 0);
191
#endif
192
 
193
        /* init driver variables depending on ega/vga mode*/
194
        psd->xres = psd->xvirtres = 640;
195
        psd->yres = psd->yvirtres = VGAMODE? 480: 350;
196
        psd->planes = 4;
197
        psd->bpp = 4;
198
        psd->ncolors = 16;
199
        psd->pixtype = MWPF_PALETTE;
200
#if HAVEBLIT
201
        psd->flags = PSF_SCREEN | PSF_HAVEBLIT;
202
#else
203
        psd->flags = PSF_SCREEN;
204
#endif
205
 
206
        /* init planes driver (sets psd->addr and psd->linelen)*/
207
        ega_init(psd);
208
 
209
#if ROMFONT
210
        /* init pc rom font routines*/
211
        pcrom_init(psd);
212
#endif
213
#if 0
214
        ROM_CHAR_HEIGHT = VGAMODE? 16: 14;
215
#endif
216
        /* FIXME: add palette code*/
217
        return psd;
218
}
219
 
220
static void
221
VGA_close(PSD psd)
222
{
223
#if ELKS
224
        /* allow console switching again*/
225
        ioctl(0, DCREL_GRAPH);
226
#endif
227
#if HWINIT
228
        ega_hwterm();
229
#else
230
        /* init bios 80x25 text mode*/
231
        int10(FNTEXT, 0);
232
#endif
233
}
234
 
235
static void
236
VGA_getscreeninfo(PSD psd,PMWSCREENINFO psi)
237
{
238
        psi->rows = psd->yvirtres;
239
        psi->cols = psd->xvirtres;
240
        psi->planes = psd->planes;
241
        psi->bpp = psd->bpp;
242
        psi->ncolors = psd->ncolors;
243
        psi->pixtype = psd->pixtype;
244
        psi->fonts = NUMBER_FONTS;
245
 
246
        if(VGAMODE) {
247
                /* VGA 640x480*/
248
                psi->xdpcm = 27;        /* assumes screen width of 24 cm*/
249
                psi->ydpcm = 27;        /* assumes screen height of 18 cm*/
250
        } else {
251
                /* EGA 640x350*/
252
                psi->xdpcm = 27;        /* assumes screen width of 24 cm*/
253
                psi->ydpcm = 19;        /* assumes screen height of 18 cm*/
254
        }
255
 
256
#if ETA4000
257
        /* SVGA 800x600*/
258
        psi->xdpcm = 33;                /* assumes screen width of 24 cm*/
259
        psi->ydpcm = 33;                /* assumes screen height of 18 cm*/
260
#endif
261
}
262
 
263
static void
264
VGA_setpalette(PSD psd,int first,int count,MWPALENTRY *pal)
265
{
266
        /* not yet implemented, std 16 color palette assumed*/
267
}
268
 
269
#if HAVEBLIT
270
/* initialize memory device with passed parms, and select suitable fb driver*/
271
static MWBOOL
272
VGA_mapmemgc(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,int linelen,
273
        int size,void *addr)
274
{
275
        extern SUBDRIVER memplan4;
276
 
277
        /* initialize mem screen driver*/
278
        initmemgc(mempsd, w, h, planes, bpp, linelen, size, addr);
279
 
280
        /* set and initialize subdriver into mem screen driver*/
281
        if (!set_subdriver(mempsd, &memplan4, TRUE))
282
                return 0;
283
 
284
        return 1;
285
}
286
#endif

powered by: WebSVN 2.1.0

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