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