summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/omron/omronInit.c
blob: df92273294e780a44c37820f5651d5b182200033 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
 * $XConsortium: omronInit.c,v 1.2 93/09/26 12:29:39 rws Exp $
 *
 * Copyright 1991 by OMRON Corporation
 * 
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of OMRON not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  OMRON makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 *
 * OMRON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL OMRON
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "omron.h"
#include "omronFb.h"
#include "omronKbd.h"
#include "omronMouse.h"

OmronFbInfo	omron_fb_info;	

int omronScreenIndex;
static unsigned long omronGeneration;

static Bool omronScreenInit();
static Bool omronGetFbInfo();
static void omronSetConsoleMode();
static void omronResetConsoleMode();

#ifndef luna88k
# ifdef uniosu
#  ifndef luna2
static OmronFbProc omron_fb_proc_2 = {
	omronFsBmCreate,  omronFsBmInit,  omronFsBmGiveUp
};
#  endif
# endif /* uniosu */
static OmronFbProc omron_fb_proc_1 = {
	omronDtBmCreate,  omronDtBmInit,  omronDtBmGiveUp
};
#else /* luna88k */
static OmronFbProc omron_fb_proc_1 = {
	omron88kBmCreate, omron88kBmInit, omron88kBmGiveUp
};
#endif /* luna88k */


void
InitOutput(pScreenInfo, argc, argv)
ScreenInfo 	  *pScreenInfo;
int     	  argc;
char    	  **argv;
{
static PixmapFormatRec  MonoFormats = {
	    1, 1, BITMAP_SCANLINE_PAD,  /* 1-bit deep */
	};
static Bool omronFbInfo 	= FALSE;
static Bool omronDevsCreate = FALSE;
	
	if (!omronFbInfo) {
		if (omronGetFbInfo(&omron_fb_info) != TRUE) 
			FatalError("Can't get framebuffer information.\n");
		omronFbInfo = TRUE;
	}

	pScreenInfo->imageByteOrder     = IMAGE_BYTE_ORDER;
	pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
	pScreenInfo->bitmapScanlinePad  = BITMAP_SCANLINE_PAD;
	pScreenInfo->bitmapBitOrder     = BITMAP_BIT_ORDER;

	pScreenInfo->numPixmapFormats = 1;
	pScreenInfo->formats[0]       = MonoFormats;
	
	if (!omronDevsCreate) {
		omronSetConsoleMode();

		if (!(* omron_fb_info.func->CreateProc)(&omron_fb_info)) {
			FatalError("Can't create framebuffer.\n");
		}
		omronDevsCreate = TRUE;
	}

	if(AddScreen(omronScreenInit, argc, argv) < 0) {
		FatalError("Can't add screen\n");
	}
}


static Bool
omronScreenInit(screenIndex, pScreen, argc, argv)
int		screenIndex;
ScreenPtr	pScreen;
int		argc;
char 		**argv;
{
	if (omronGeneration != serverGeneration) {
		if((omronScreenIndex = AllocateScreenPrivateIndex()) <0) {
			ErrorF("AllocateScreenPrivateIndex error.\n");
			return FALSE;
		}
		omronGeneration = serverGeneration;
	}
	pScreen->devPrivates[omronScreenIndex].ptr = (pointer)&omron_fb_info;

	return((* omron_fb_info.func->InitProc)(screenIndex, pScreen, argc, argv));
}


void
InitInput(argc, argv)
    int    argc;
    char   **argv;
{
    DevicePtr p, k;

#ifndef UNUSE_DRV_TIME
	omronInitEventPrvRec();
#endif
    
    p = AddInputDevice(omronMouseProc, TRUE);
    k = AddInputDevice(omronKbdProc, TRUE);

    RegisterPointerDevice(p);
    RegisterKeyboardDevice(k);

    miRegisterPointerDevice(screenInfo.screens[0], p);

    if (mieqInit (k, p) != TRUE) {
		FatalError("Enqueue init error.\n");
	}

	omronSetIoHandler(omronEnqueueEvents);

#ifndef UNUSE_SIGIO_SIGNAL
	(void) OsSignal(SIGIO, omronSigIOHandler);
#else
    if(RegisterBlockAndWakeupHandlers(NoopDDA, omronWakeupProc, (pointer)0) != TRUE) {
		FatalError("Can't register WakeupHandler\n");
	 }
#endif
}


static Bool
omronGetFbInfo(omron_fb_info)
OmronFbInfoPtr omron_fb_info;
{
	int machine_type;

	if ( fb_type )
	{
		if (strcmp(fb_type, "DT_BM") == 0) {
			omron_fb_info->fb_type = DT_BM;
			omron_fb_info->func  = &omron_fb_proc_1;
		} else if (strcmp(fb_type, "DT_BM8") == 0) {
			omron_fb_info->fb_type = DT_BM8;
			omron_fb_info->func  = &omron_fb_proc_1;
		} else if (strcmp(fb_type, "DT_PLASMA") == 0) {
			omron_fb_info->fb_type = DT_PLASMA;
			omron_fb_info->func  = &omron_fb_proc_1;
		} else if (strcmp(fb_type, "FS_BM") == 0) {	
			omron_fb_info->fb_type = FS_BM;
#if (defined(uniosu) && (! defined(luna2)))
			omron_fb_info->func  = &omron_fb_proc_2;
#endif
		} else if (strcmp(fb_type, "DS_BM") == 0) {
			omron_fb_info->fb_type = DS_BM; 
		} else {
			ErrorF("Unknown framebuffer type.\n");
			return (FALSE);
		}

		if (omron_fb_info->fb_type != DT_PLASMA) {
			omron_fb_info->scr_width = SCREEN_WIDTH;  
			omron_fb_info->scr_height = SCREEN_HEIGHT;  
		} else {
			omron_fb_info->scr_width = PLASMA_SCREEN_WIDTH;  
			omron_fb_info->scr_height = PLASMA_SCREEN_HEIGHT;  
		}

		omron_fb_info->fb_width = FB_WIDTH;  
		omron_fb_info->fb_height = FB_HEIGHT;  
		omron_fb_info->fb_depth = 1;
		return (TRUE);
	}

#ifdef	uniosu
	if (sys9100(S91MACHTYPE,&machine_type) < 0) {
		Error("sys9100 error.");
		return (FALSE);
	}
#else
	if (sysomron(S91MACHTYPE,&machine_type) < 0) {
		Error("sysomron error.");
		return (FALSE);
	}
#endif

	switch(machine_type & (MACH_MACH | MACH_GRAPHIC_BOARD)) {
	case MACH_DT | MACH_BM : /* we call LUNA */ 
		omron_fb_info->fb_type = DT_BM;
		omron_fb_info->func  = &omron_fb_proc_1;
		break;

	case MACH_DT | MACH_PLASMA  : /* LUNA support plasma display */  
		omron_fb_info->fb_type = DT_PLASMA;
		omron_fb_info->func  = &omron_fb_proc_1;
		break;

	case MACH_DS | MACH_BM : /* we call Mr. */
		omron_fb_info->fb_type = DS_BM;
		break;

	case MACH_FS | MACH_BM : /* we call M90 */
		omron_fb_info->fb_type = FS_BM;
#if (defined(uniosu) && (! defined(luna2)))
		omron_fb_info->func  = &omron_fb_proc_2;
#endif
		break;
	default : 
		ErrorF("Can't support machine type. (0x%x)\n",machine_type);
		return (FALSE);
	}

	switch(machine_type & MACH_PLANE){
	case MACH_1_PLANE :
		omron_fb_info->fb_depth = 1;
		break;

	case MACH_4_PLANE :
		omron_fb_info->fb_depth = 4;
		break;

	case MACH_8_PLANE :
		omron_fb_info->fb_depth = 8;
		if(omron_fb_info->fb_type == DT_BM) {
			omron_fb_info->fb_type = DT_BM8;
		}
		break;

	default :
		ErrorF("Can't support plane number. (0x%x)\n", machine_type); 
		return (FALSE);
	}

	if (omron_fb_info->fb_type != DT_PLASMA) {
		omron_fb_info->scr_width  = SCREEN_WIDTH;  
		omron_fb_info->scr_height = SCREEN_HEIGHT;  
	} else {
		omron_fb_info->scr_width  = PLASMA_SCREEN_WIDTH;  
		omron_fb_info->scr_height = PLASMA_SCREEN_HEIGHT;  
	}

	if( scrw )
		omron_fb_info->scr_width  = scrw;
	if( scrh )
		omron_fb_info->scr_height = scrh;

	omron_fb_info->fb_width = FB_WIDTH;  
	omron_fb_info->fb_height = FB_HEIGHT;  

	return(TRUE);
}


static int  NonConsole;

static void
omronSetConsoleMode()
{
	extern	char *ttyname();
	char *p = ttyname(2);
	register int i; 

	if (p && strcmp(p,"/dev/console")!=0) {
		NonConsole = TRUE;
		return;
	} 

	i = fcntl(2, F_GETFL, 0); 
	if(i >=0)
		i = fcntl(2, F_SETFL, i | FNDELAY);
	if (i < 0) {
		FatalError("InitOutput:on console can't put stderr in non-block mode.\n");
	}
}

static void
omronResetConsoleMode()
{
	register int i;

	if ( NonConsole ) {
		return;
	}
	i = fcntl(2, F_GETFL, 0);
	if (i >= 0)
		(void)fcntl(2, F_SETFL, i & ~FNDELAY);
}


void
AbortDDX()
{
	omronResetConsoleMode();
}


void
ddxGiveUp()
{
	omronKbdGiveUp();
	omronMouseGiveUp();
	if (omron_fb_info.func->GiveUpProc != NULL)
		(*omron_fb_info.func->GiveUpProc)(&omron_fb_info);
	omronResetConsoleMode();
}