1/* $NetBSD: x68kInit.c,v 1.5 2020/11/05 16:06:08 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
75EventList *x68kEvents = NULL;
76
77static int nscreens;
78
79/* default log file paths */
80#ifndef DEFAULT_LOGDIR
81#define DEFAULT_LOGDIR "/var/log"
82#endif
83#ifndef DEFAULT_LOGPREFIX
84#define DEFAULT_LOGPREFIX "X68K."
85#endif
86
87void
88OsVendorInit(void)
89{
90    static int inited;
91
92    if (!inited) {
93	const char *logfile;
94	char *lf;
95
96#define LOGSUFFIX ".log"
97#define LOGOLDSUFFIX ".old"
98	logfile = DEFAULT_LOGDIR "/" DEFAULT_LOGPREFIX;
99	if (asprintf(&lf, "%s%%s" LOGSUFFIX, logfile) == -1)
100	    FatalError("Cannot allocate space for the log file name\n");
101	LogInit(lf, LOGOLDSUFFIX);
102#undef LOGSUFFIX
103#undef LOGOLDSUFFIX
104	free(lf);
105
106	inited = 1;
107    }
108}
109
110/*-------------------------------------------------------------------------
111 * function "InitOutput"                                [ called by DIX ]
112 *
113 *  purpose:  initialize outputs ( screens )
114 *  argument: (ScreenInfo *)pScreenInfo  : screen info struct
115 *            (int)argc, (char *)argv    : standard arguments
116 *  returns:  nothing
117 *-----------------------------------------------------------------------*/
118void
119InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[])
120{
121    int i;
122    X68kScreenRec *screen;
123    X68kFbProcRec *fb;
124
125    pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
126    pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
127    pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
128    pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
129
130    /* read configuration file */
131    nscreens = x68kConfig();
132
133    /* register pixmap formats */
134    x68kRegisterPixmapFormats(pScreenInfo);
135
136    /* open and initialize frame buffer for each screen */
137    for (i = 0; i < nscreens; i++) {
138        screen = x68kGetScreenRec(i);
139        fb = x68kGetFbProcRec(i);
140        if ( !(*fb->open)(screen) )
141            return;
142        if ( AddScreen(fb->init, argc, argv) < 0 )
143            FatalError("AddScreen failed\n");
144    }
145}
146
147/*-------------------------------------------------------------------------
148 * function "InitInput"                                 [ called by DIX ]
149 *
150 *  purpose:  initialize inputs ( keyboard and mouse )
151 *  argument: (int)argc, (char *)argv    : standard arguments
152 *  returns:  nothing
153 *-----------------------------------------------------------------------*/
154void
155InitInput(int argc, char *argv[])
156{
157    int rc;
158
159    rc = AllocDevicePair(serverClient, "x68k",
160			 &x68kPointerDevice, &x68kKeyboardDevice,
161			 x68kMouseProc,x68kKbdProc, FALSE);
162    if (rc != Success)
163	FatalError("Failed to init x68k default input devices.\n");
164
165    GetEventList(&x68kEvents);
166
167    if ( !mieqInit() )
168        FatalError("mieqInit failed\n");
169
170    /* setup SIGIO handler for asynchronous event handling */
171    (void)OsSignal(SIGIO, x68kSigIOHandler);
172}
173
174void
175CloseInput(void)
176{
177}
178
179/*-------------------------------------------------------------------------
180 * function "AbortDDX"                                 [ called by OS ]
181 *
182 *  purpose:  free signal handler and close frame buffers
183 *  argument: nothing
184 *  returns:  nothing
185 *-----------------------------------------------------------------------*/
186void
187AbortDDX(void)
188{
189    int i;
190    X68kScreenRec *screen;
191    X68kFbProcRec *fb;
192
193    /* give up SIGIO handling */
194    (void) OsSignal(SIGIO, SIG_IGN);
195
196    /* close all frame buffers */
197    for (i = 0; i < nscreens; i++) {
198        screen = x68kGetScreenRec(i);
199        fb = x68kGetFbProcRec(i);
200        (*fb->close)(screen);
201    }
202    LogClose();
203}
204
205/*-------------------------------------------------------------------------
206 * function "ddxGiveUp"                                 [ called by DIX ]
207 *
208 *  purpose:  do nothing but call AbortDDX.
209 *  argument: nothing
210 *  returns:  nothing
211 *-----------------------------------------------------------------------*/
212void
213ddxGiveUp(void)
214{
215    AbortDDX();
216}
217
218/*-------------------------------------------------------------------------
219 * function "ddxProcessArgument"                        [ called by OS ]
220 *
221 *  purpose:  process X68k dependent arguments
222 *            currently only `x68kconfig' will be recognized.
223 *  argument: (int)argc, (char **)argv: standard C arguments
224 *            (int)i                  : index of current argument
225 *  returns:  number of arguments eaten
226 *-----------------------------------------------------------------------*/
227int
228ddxProcessArgument(int argc, char *argv[], int i)
229{
230
231    if (strcmp(argv[i], "-x68kconfig") == 0) {
232        if (++i >= argc)
233            UseMsg();
234        configFilename = strdup(argv[i]);
235        return 2;
236    }
237    return 0;
238}
239
240/*-------------------------------------------------------------------------
241 * function "ddxUseMsg"                                 [ called by OS ]
242 *
243 *  purpose:  print X68k dependent usage
244 *  argument: nothing
245 *  returns:  nothing
246 *-----------------------------------------------------------------------*/
247void
248ddxUseMsg(void)
249{
250    ErrorF("\nX68k dependent options\n");
251    ErrorF("-x68kconfig filename   specify configuration file\n");
252}
253
254void
255OsVendorFatalError(void)
256{
257}
258
259/* EOF x68kInit.c */
260