x68kInit.c revision 9979d90a
1/* $NetBSD: x68kInit.c,v 1.9 2020/11/01 11:40:53 tsutsui Exp $ */
2/*-------------------------------------------------------------------------
3 * Copyright (c) 1996 Yasushi Yamasaki
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *-----------------------------------------------------------------------*/
26
27/*
28 *
29 * Copyright (c) 1987 by the Regents of the University of California
30 *
31 * Permission to use, copy, modify, and distribute this
32 * software and its documentation for any purpose and without
33 * fee is hereby granted, provided that the above copyright
34 * notice appear in all copies.  The University of California
35 * makes no representations about the suitability of this
36 * software for any purpose.  It is provided "as is" without
37 * express or implied warranty.
38 *
39 *
40 */
41
42/************************************************************
43Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
44
45                    All Rights Reserved
46
47Permission  to  use,  copy,  modify,  and  distribute   this
48software  and  its documentation for any purpose and without
49fee is hereby granted, provided that the above copyright no-
50tice  appear  in all copies and that both that copyright no-
51tice and this permission notice appear in  supporting  docu-
52mentation,  and  that the names of Sun or X Consortium
53not be used in advertising or publicity pertaining to
54distribution  of  the software  without specific prior
55written permission. Sun and X Consortium make no
56representations about the suitability of this software for
57any purpose. It is provided "as is" without any express or
58implied warranty.
59
60SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
61INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
62NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
63ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
64ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
65PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
66OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
67THE USE OR PERFORMANCE OF THIS SOFTWARE.
68
69*******************************************************/
70
71#include <X11/Xos.h>
72#include "x68k.h"
73#include "mi.h"
74#include "extinit.h"
75
76static int nscreens;
77
78/* default log file paths */
79#ifndef DEFAULT_LOGDIR
80#define DEFAULT_LOGDIR "/var/log"
81#endif
82#ifndef DEFAULT_LOGPREFIX
83#define DEFAULT_LOGPREFIX "X68K."
84#endif
85
86void
87OsVendorInit(void)
88{
89    static int inited;
90
91    if (!inited) {
92	const char *logfile;
93	char *lf;
94
95#define LOGSUFFIX ".log"
96#define LOGOLDSUFFIX ".old"
97	logfile = DEFAULT_LOGDIR "/" DEFAULT_LOGPREFIX;
98	if (asprintf(&lf, "%s%%s" LOGSUFFIX, logfile) == -1)
99	    FatalError("Cannot allocate space for the log file name\n");
100	LogInit(lf, LOGOLDSUFFIX);
101#undef LOGSUFFIX
102#undef LOGOLDSUFFIX
103	free(lf);
104
105	inited = 1;
106    }
107}
108
109#ifdef GLXEXT
110void
111GlxExtensionInit(void)
112{
113}
114#endif
115
116/*-------------------------------------------------------------------------
117 * function "InitOutput"                                [ called by DIX ]
118 *
119 *  purpose:  initialize outputs ( screens )
120 *  argument: (ScreenInfo *)pScreenInfo  : screen info struct
121 *            (int)argc, (char *)argv    : standard arguments
122 *  returns:  nothing
123 *-----------------------------------------------------------------------*/
124void
125InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[])
126{
127    int i;
128    X68kScreenRec *screen;
129    X68kFbProcRec *fb;
130
131    pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
132    pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
133    pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
134    pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
135
136    /* read configuration file */
137    nscreens = x68kConfig();
138
139    /* register pixmap formats */
140    x68kRegisterPixmapFormats(pScreenInfo);
141
142    /* open and initialize frame buffer for each screen */
143    for (i = 0; i < nscreens; i++) {
144        screen = x68kGetScreenRec(i);
145        fb = x68kGetFbProcRec(i);
146        if ( !(*fb->open)(screen) )
147            return;
148        if ( AddScreen(fb->init, argc, argv) < 0 )
149            FatalError("AddScreen failed\n");
150    }
151}
152
153/*-------------------------------------------------------------------------
154 * function "InitInput"                                 [ called by DIX ]
155 *
156 *  purpose:  initialize inputs ( keyboard and mouse )
157 *  argument: (int)argc, (char *)argv    : standard arguments
158 *  returns:  nothing
159 *-----------------------------------------------------------------------*/
160void
161InitInput(int argc, char *argv[])
162{
163    int rc;
164
165    rc = AllocDevicePair(serverClient, "x68k",
166			 &x68kPointerDevice, &x68kKeyboardDevice,
167			 x68kMouseProc,x68kKbdProc, FALSE);
168    if (rc != Success)
169	FatalError("Failed to init x68k default input devices.\n");
170
171    if ( !mieqInit() )
172        FatalError("mieqInit failed\n");
173
174    /* setup SIGIO handler for asynchronous event handling */
175    (void)OsSignal(SIGIO, x68kSigIOHandler);
176}
177
178void
179CloseInput(void)
180{
181    mieqFini();
182}
183
184/*-------------------------------------------------------------------------
185 * function "AbortDDX"                                 [ called by OS ]
186 *
187 *  purpose:  free signal handler and close frame buffers
188 *  argument: ExitCode
189 *  returns:  nothing
190 *-----------------------------------------------------------------------*/
191void
192AbortDDX(enum ExitCode error)
193{
194    int i;
195    X68kScreenRec *screen;
196    X68kFbProcRec *fb;
197
198    /* give up SIGIO handling */
199    (void) OsSignal(SIGIO, SIG_IGN);
200
201    /* close all frame buffers */
202    for (i = 0; i < nscreens; i++) {
203        screen = x68kGetScreenRec(i);
204        fb = x68kGetFbProcRec(i);
205        (*fb->close)(screen);
206    }
207    LogClose(error);
208}
209
210/*-------------------------------------------------------------------------
211 * function "ddxGiveUp"                                 [ called by DIX ]
212 *
213 *  purpose:  do nothing but call AbortDDX.
214 *  argument: nothing
215 *  returns:  nothing
216 *-----------------------------------------------------------------------*/
217void
218ddxGiveUp(enum ExitCode error)
219{
220    AbortDDX(error);
221}
222
223/*-------------------------------------------------------------------------
224 * function "ddxProcessArgument"                        [ called by OS ]
225 *
226 *  purpose:  process X68k dependent arguments
227 *            currently only `x68kconfig' will be recognized.
228 *  argument: (int)argc, (char **)argv: standard C arguments
229 *            (int)i                  : index of current argument
230 *  returns:  number of arguments eaten
231 *-----------------------------------------------------------------------*/
232int
233ddxProcessArgument(int argc, char *argv[], int i)
234{
235
236    if (strcmp(argv[i], "-x68kconfig") == 0) {
237        if (++i >= argc)
238            UseMsg();
239        configFilename = strdup(argv[i]);
240        return 2;
241    }
242    return 0;
243}
244
245/*-------------------------------------------------------------------------
246 * function "ddxUseMsg"                                 [ called by OS ]
247 *
248 *  purpose:  print X68k dependent usage
249 *  argument: nothing
250 *  returns:  nothing
251 *-----------------------------------------------------------------------*/
252void
253ddxUseMsg(void)
254{
255    ErrorF("\nX68k dependent options\n");
256    ErrorF("-x68kconfig filename   specify configuration file\n");
257}
258
259_X_EXPORT void
260OsVendorFatalError(const char *f, va_list args)
261{
262}
263
264/* EOF x68kInit.c */
265