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