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