grf_cc.c revision 1.9 1 1.8 chopps /*
2 1.9 chopps * $Id: grf_cc.c,v 1.9 1994/02/13 21:10:26 chopps Exp $
3 1.8 chopps */
4 1.8 chopps
5 1.1 mw #include "grf.h"
6 1.1 mw #if NGRF > 0
7 1.1 mw
8 1.1 mw /* Graphics routines for the AMIGA native custom chip set. */
9 1.1 mw
10 1.6 mw /* NOTE: this is now only a more or less rough interface to Chris Hopps'
11 1.6 mw view driver. Due to some design problems with RTG view can't
12 1.6 mw currently replace grf, but that's an option for the future. */
13 1.6 mw
14 1.9 chopps #include <sys/param.h>
15 1.9 chopps #include <vm/vm_param.h>
16 1.9 chopps #include <sys/errno.h>
17 1.9 chopps #include <sys/ioctl.h>
18 1.9 chopps #include <machine/cpu.h>
19 1.9 chopps
20 1.9 chopps #include <amiga/amiga/custom.h>
21 1.9 chopps #include <amiga/amiga/cia.h>
22 1.9 chopps #include <amiga/amiga/dlists.h>
23 1.9 chopps
24 1.9 chopps #include <amiga/dev/grfioctl.h>
25 1.9 chopps #include <amiga/dev/grfvar.h>
26 1.9 chopps #include <amiga/dev/grf_ccreg.h>
27 1.9 chopps #include <amiga/dev/grfabs_reg.h>
28 1.9 chopps #include <amiga/dev/viewioctl.h>
29 1.4 mw
30 1.3 mw /* Initialize hardware.
31 1.1 mw * Must point g_display at a grfinfo structure describing the hardware.
32 1.1 mw * Returns 0 if hardware not present, non-zero ow.
33 1.1 mw */
34 1.1 mw cc_init(gp, ad)
35 1.1 mw struct grf_softc *gp;
36 1.1 mw struct amiga_device *ad;
37 1.1 mw {
38 1.6 mw bmap_t bm;
39 1.1 mw struct grfinfo *gi = &gp->g_display;
40 1.6 mw int rc;
41 1.6 mw long start, off;
42 1.6 mw struct view_size vs;
43 1.6 mw
44 1.6 mw /* already initialized fail */
45 1.7 chopps if (gp->g_data == (caddr_t) 12345678)
46 1.6 mw return 0;
47 1.6 mw
48 1.6 mw rc = grfcc_probe ();
49 1.6 mw if (! rc)
50 1.1 mw return 0;
51 1.1 mw
52 1.6 mw viewprobe ();
53 1.6 mw
54 1.6 mw /* now it gets REALLY nasty.. view[0] stays open for all time
55 1.6 mw now.. */
56 1.6 mw if (viewopen (0, 0))
57 1.6 mw return 0;
58 1.6 mw
59 1.6 mw /* XXX 0 may need to change when virtual added */
60 1.6 mw XXX_grf_cc_on (0);
61 1.1 mw
62 1.1 mw return(1);
63 1.1 mw }
64 1.1 mw
65 1.1 mw cc_config(gp, di)
66 1.1 mw register struct grf_softc *gp;
67 1.1 mw struct grfdyninfo *di;
68 1.1 mw {
69 1.1 mw struct grfinfo *gi = &gp->g_display;
70 1.1 mw
71 1.1 mw /* bottom missing... */
72 1.1 mw
73 1.1 mw }
74 1.1 mw
75 1.6 mw extern struct grf_softc grf_softc[];
76 1.6 mw #define GPUNIT(ip) (((u_long)ip-(u_long)grf_softc)/sizeof(struct grf_softc))
77 1.6 mw
78 1.1 mw /*
79 1.1 mw * Change the mode of the display.
80 1.1 mw * Right now all we can do is grfon/grfoff.
81 1.1 mw * Return a UNIX error number or 0 for success.
82 1.1 mw */
83 1.1 mw cc_mode(gp, cmd, arg)
84 1.1 mw register struct grf_softc *gp;
85 1.1 mw int cmd;
86 1.1 mw void *arg;
87 1.1 mw {
88 1.1 mw switch (cmd)
89 1.1 mw {
90 1.1 mw case GM_GRFON:
91 1.6 mw XXX_grf_cc_on (GPUNIT (gp));
92 1.1 mw return 0;
93 1.1 mw
94 1.1 mw case GM_GRFOFF:
95 1.6 mw XXX_grf_cc_off (GPUNIT (gp));
96 1.1 mw return 0;
97 1.1 mw
98 1.1 mw case GM_GRFCONFIG:
99 1.1 mw return cc_config (gp, (struct grfdyninfo *) arg);
100 1.1 mw
101 1.1 mw default:
102 1.1 mw break;
103 1.1 mw }
104 1.1 mw
105 1.1 mw return EINVAL;
106 1.1 mw }
107 1.6 mw
108 1.6 mw
109 1.6 mw /* nasty nasty hack. right now grf's unit == ite's unit == view's unit. */
110 1.6 mw /* to make X work (I guess) we need to update the grf structure's HW */
111 1.6 mw /* address to the current view (as this may change without grf knowing.) */
112 1.6 mw /* Thanks to M Hitch. for finding this one. */
113 1.6 mw XXX_grf_cc_on (unit)
114 1.6 mw int unit;
115 1.6 mw {
116 1.6 mw struct grf_softc *gp = &grf_softc[unit];
117 1.6 mw struct grfinfo *gi = &gp->g_display;
118 1.6 mw bmap_t bm;
119 1.6 mw struct view_size vs;
120 1.6 mw
121 1.6 mw viewioctl (unit, VIEW_GETBITMAP, &bm, 0, -1);
122 1.6 mw
123 1.7 chopps gp->g_data = (caddr_t) 12345678; /* not particularly clean.. */
124 1.6 mw
125 1.7 chopps gi->gd_regaddr = (caddr_t) 0xdff000; /* no need to look at regs */
126 1.6 mw gi->gd_regsize = round_page(sizeof (custom)); /* I mean it X people, for CC */
127 1.6 mw /* use the view device. That way */
128 1.6 mw /* we can have both X and a console. */
129 1.6 mw /* and flip between them. People */
130 1.6 mw /* will be unhappy if this feature */
131 1.6 mw /* is so easy and yet not availble. */
132 1.6 mw /* (if you wern't using them then */
133 1.6 mw /* thanks.) */
134 1.6 mw /**** I will remove these soon.****/
135 1.6 mw gi->gd_fbaddr = bm.hardware_address;
136 1.6 mw gi->gd_fbsize = bm.depth*bm.bytes_per_row*bm.rows;
137 1.6 mw
138 1.6 mw if (viewioctl (unit, VIEW_GETSIZE, &vs, 0, -1))
139 1.6 mw {
140 1.6 mw /* fill in some default values... XXX */
141 1.6 mw vs.width = 640; vs.height = 400; vs.depth = 2;
142 1.6 mw }
143 1.6 mw
144 1.6 mw gi->gd_colors = 1 << vs.depth;
145 1.6 mw gi->gd_planes = vs.depth;
146 1.6 mw
147 1.6 mw gi->gd_fbwidth = vs.width;
148 1.6 mw gi->gd_fbheight = vs.height;
149 1.6 mw gi->gd_fbx = 0;
150 1.6 mw gi->gd_fby = 0;
151 1.6 mw gi->gd_dwidth = vs.width;
152 1.6 mw gi->gd_dheight = vs.height;
153 1.6 mw gi->gd_dx = 0;
154 1.6 mw gi->gd_dy = 0;
155 1.6 mw
156 1.6 mw gp->g_regkva = 0; /* builtin */
157 1.6 mw gp->g_fbkva = 0; /* not needed, view internal */
158 1.6 mw
159 1.6 mw viewioctl (unit, VIEW_DISPLAY, NULL, 0, -1);
160 1.6 mw
161 1.6 mw }
162 1.6 mw
163 1.6 mw XXX_grf_cc_off (unit)
164 1.6 mw int unit;
165 1.6 mw {
166 1.6 mw viewioctl (unit, VIEW_REMOVE, NULL, 0, -1);
167 1.6 mw }
168 1.6 mw
169 1.1 mw
170 1.1 mw #endif
171 1.4 mw
172