1 /* SCCS Id: @(#)amilib.c 3.2 96/02/04 */
2 /* Copyright (c) Gregg Wonderly, Naperville, Illinois, 1991,1992,1993,1996. */
3 /* NetHack may be freely redistributed. See license for details. */
4
5 #include "hack.h"
6 #include "wintype.h"
7 #include "winami.h"
8 #include "func_tab.h"
9
10 #ifdef AMIGA_INTUITION
11
12 #include <exec/types.h>
13 #include <graphics/gfxbase.h>
14 #include <intuition/intuition.h>
15 #include <intuition/intuitionbase.h>
16 #include <libraries/dosextens.h>
17 #include <ctype.h>
18 #undef strcmpi
19 #include <string.h>
20 #include <errno.h>
21
22 #ifdef IDCMP_CLOSEWINDOW
23 # define INTUI_NEW_LOOK
24 #endif
25
26 #ifdef AZTEC_C
27 # include <functions.h>
28 #else
29 # ifndef _DCC
30 # include <dos.h>
31 # endif
32 # ifdef _DCC
33 # include <clib/exec_protos.h>
34 # else
35 # include <proto/exec.h>
36 # endif
37 #endif
38
39 #include "NH:sys/amiga/lib/amilib.h"
40 #include "winproto.h"
41
42 WinamiBASE *WinamiBase = 0;
43
44 extern char *roles[];
45 extern char orgdir[];
46
47 struct Library *ConsoleDevice = 0;
48 int bigscreen = 0;
49 char Initialized = 0;
50 struct amii_DisplayDesc *amiIDisplay = 0;
51 struct Screen *HackScreen = 0;
52 winid WIN_BASE = WIN_ERR;
53 #ifdef VIEWWINDOW
54 winid WIN_OVER = WIN_ERR;
55 #endif
56 winid amii_rawprwin = WIN_ERR;
57 extern const char *configfile;
58
59 void amii_outrip( winid, int );
60 void setup_librefs( WinamiBASE * );
61
62 /* The current color map */
63 unsigned short amii_initmap[ MAXCOLORS ] = {
64 #define C_BLACK 0
65 #define C_WHITE 1
66 #define C_BROWN 2
67 #define C_CYAN 3
68 #define C_GREEN 4
69 #define C_MAGENTA 5
70 #define C_BLUE 6
71 #define C_RED 7
72
73 0x0000, /* color #0 */
74 0x0FFF, /* color #1 */
75 0x0830, /* color #2 */
76 0x07ac, /* color #3 */
77 0x0181, /* color #4 */
78 0x0C06, /* color #5 */
79 0x023E, /* color #6 */
80 0x0c00 /* color #7 */
81 #ifdef VIEWWINDOW
82 0x0AAA, /* Various shades of grey */
83 0x0fff,
84 0x0444,
85 0x0666,
86 0x0888,
87 0x0bbb,
88 0x0ddd,
89 0x0222,
90 #endif
91 };
92
93 /* Interface definition, for use by windows.c and winprocs.h to provide
94 * the simple intuition interface for the amiga...
95 */
96 struct window_procs amii_procs =
97 {
98 "amii",
99 amii_init_nhwindows,
100 amii_player_selection,
101 amii_askname,
102 amii_get_nh_event,
103 amii_exit_nhwindows,
104 amii_suspend_nhwindows,
105 amii_resume_nhwindows,
106 amii_create_nhwindow,
107 amii_clear_nhwindow,
108 amii_display_nhwindow,
109 amii_destroy_nhwindow,
110 amii_curs,
111 amii_putstr,
112 amii_display_file,
113 amii_start_menu,
114 amii_add_menu,
115 amii_end_menu,
116 amii_select_menu,
117 genl_message_menu,
118 amii_update_inventory,
119 amii_mark_synch,
120 amii_wait_synch,
121 #ifdef CLIPPING
122 amii_cliparound,
123 #endif
124 #ifdef POSITIONBAR
125 donull,
126 #endif
127 amii_print_glyph,
128 amii_raw_print,
129 amii_raw_print_bold,
130 amii_nhgetch,
131 amii_nh_poskey,
132 amii_bell,
133 amii_doprev_message,
134 amii_yn_function,
135 amii_getlin,
136 amii_get_ext_cmd,
137 amii_number_pad,
138 amii_delay_output,
139 /* other defs that really should go away (they're tty specific) */
140 #ifdef CHANGE_COLOR
141 amii_change_color,
142 amii_get_color_string,
143 #endif
144 (void *)amii_delay_output,
145 (void *)amii_delay_output,
146
147 amii_outrip,
148 };
149
150
151 /* Interface definition, for use by windows.c and winprocs.h to provide
152 * the view window interface to nethack...
153 */
154 struct window_procs amiv_procs =
155 {
156 "amiv",
157 amii_init_nhwindows,
158 amii_player_selection,
159 amii_askname,
160 amii_get_nh_event,
161 amii_exit_nhwindows,
162 amii_suspend_nhwindows,
163 amii_resume_nhwindows,
164 amii_create_nhwindow,
165 amii_clear_nhwindow,
166 amii_display_nhwindow,
167 amii_destroy_nhwindow,
168 amii_curs,
169 amii_putstr,
170 amii_display_file,
171 amii_start_menu,
172 amii_add_menu,
173 amii_end_menu,
174 amii_select_menu,
175 genl_message_menu,
176 amii_update_inventory,
177 amii_mark_synch,
178 amii_wait_synch,
179 #ifdef CLIPPING
180 amii_cliparound,
181 #endif
182 #ifdef POSITIONBAR
183 donull,
184 #endif
185 amii_print_glyph,
186 amii_raw_print,
187 amii_raw_print_bold,
188 amii_nhgetch,
189 amii_nh_poskey,
190 amii_bell,
191 amii_doprev_message,
192 amii_yn_function,
193 amii_getlin,
194 amii_get_ext_cmd,
195 amii_number_pad,
196 (void *)amii_delay_output,
197 /* other defs that really should go away (they're tty specific) */
198 #ifdef CHANGE_COLOR
199 amii_change_color,
200 amii_get_color_string,
201 #endif
202 (void *)amii_delay_output,
203 (void *)amii_delay_output,
204
205 amii_outrip,
206 };
207
208 void
amii_loadlib(void)209 amii_loadlib( void )
210 {
211 /* Close the library if opened it already (switching display types) */
212 if( WinamiBase )
213 CloseLibrary( (struct Library *)WinamiBase );
214
215 if( ( WinamiBase = ( WinamiBASE *)OpenLibrary( "winami.library", 0 ) ) == NULL )
216 {
217 panic( "can't find winami.library" );
218 }
219 setup_librefs( WinamiBase );
220 }
221
222 void
amiv_loadlib(void)223 amiv_loadlib( void )
224 {
225 /* Close the library if opened it already (switching display types) */
226 if( WinamiBase )
227 CloseLibrary( (struct Library *)WinamiBase );
228
229 if( ( WinamiBase = ( WinamiBASE *)OpenLibrary( "winamiv.library", 0 ) ) == NULL )
230 {
231 panic( "can't find winami.library" );
232 }
233 setup_librefs( WinamiBase );
234 }
235
236 void
CleanUp()237 CleanUp()
238 {
239 if( WinamiBase )
240 {
241 CloseLibrary( (struct Library *)WinamiBase );
242 WinamiBase = NULL;
243 }
244 }
245
246 /* The library has references to the following code and data items in the main
247 * game, so fill in the access pointers for it to user...uggghhh...
248 */
249 void
setup_librefs(base)250 setup_librefs( base )
251 WinamiBASE *base;
252 {
253 base->G_pline = pline;
254 base->G_display_inventory = display_inventory;
255 base->G_terminate = terminate;
256 base->G_rnd = rnd;
257 base->G_rn2 = rn2;
258 base->G_panic = panic;
259 base->G_clearlocks = clearlocks;
260 base->G_on_level = on_level;
261 base->G_exit = exit;
262 base->G_lowc = lowc;
263 base->G_alloc = alloc;
264 base->G_Abort = Abort;
265 base->G_error = error;
266 base->G_fopenp = fopenp;
267 base->G_doredraw = doredraw;
268 base->G_fopen = fopen;
269 base->G_fclose = fclose;
270 base->G_fputs = fputs;
271 base->G_fprintf = fprintf;
272 base->G_fgets = fgets;
273 base->G_fflush = fflush;
274
275 base->G_yn_number = &yn_number;
276 base->G_zapcolors = zapcolors;
277 base->G_plname = plname;
278 base->G_objects = objects;
279 base->G_monsyms = monsyms;
280 base->G_extcmdlist = extcmdlist;
281 base->G_flags = &flags;
282 base->G_oc_syms = oc_syms;
283 base->G_showsyms = showsyms;
284 base->G_quitchars = quitchars;
285 base->G_pl_character = pl_character;
286 base->G_WIN_MESSAGE = &WIN_MESSAGE;
287 base->G_WIN_MAP = &WIN_MAP;
288 base->G_tc_gbl_data = &tc_gbl_data;
289 base->G_defsyms = defsyms;
290 base->G_WIN_STATUS = &WIN_STATUS;
291 base->G_u = &u;
292 base->G_roles = roles;
293 base->G_dungeon_topology = &dungeon_topology;
294 base->G_toplines = toplines;
295 base->G_WIN_INVEN = &WIN_INVEN;
296 base->G_windowprocs = &windowprocs;
297 base->G_orgdir = orgdir;
298 base->G_mons = mons;
299 base->G_amiIDisplay = &amiIDisplay;
300 base->G_HackScreen = &HackScreen;
301 base->G_pl_classes = pl_classes;
302 base->G_bigscreen = &bigscreen;
303 base->G_WINBASE = &WIN_BASE;
304 base->G_amii_rawprwin = &amii_rawprwin;
305 base->G_amii_initmap = amii_initmap;
306 base->G_Initialized = &Initialized;
307 base->G_ConsoleDevice = &ConsoleDevice;
308 base->G_configfile = configfile;
309 base->G_amii_procs = &amii_procs;
310 base->G_amii_set_text_font = amii_set_text_font;
311 }
312
313 /*
314 * We don't compile the NetHack sources with amilib.h, so we define the function
315 * here to call the shared library version
316 */
317 void
amii_set_text_font(name,size)318 amii_set_text_font( name, size )
319 char *name;
320 int size;
321 {
322 /*(*WinamiBase->G_amii_set_text_font)( name, size );*/
323 }
324 #endif
325
Abort(rc)326 void Abort(rc)
327 long rc;
328 {
329 #ifdef CHDIR
330 chdir(orgdir);
331 #endif
332 if (Initialized && ConsoleDevice) {
333 printf("\n\nAbort with alert code %08lx...\n", rc);
334 amii_getret();
335 } else
336 Alert(rc);
337 #ifdef __SASC
338 {
339 /* __emit(0x4afc); /* illegal instruction */
340 __emit(0x40fc); /* divide by */
341 __emit(0x0000); /* #0 */
342 /* NOTE: don't move CleanUp() above here - */
343 /* it is too likely to kill the system */
344 /* before it can get the SnapShot out, if */
345 /* there is something really wrong. */
346 }
347 #endif
348 CleanUp();
349 #undef exit
350 #ifdef AZTEC_C
351 _abort();
352 #endif
353 exit((int) rc);
354 }
355
356 /* fatal error */
357 /*VARARGS1*/
358 void error VA_DECL(const char *, s)
359 VA_START(s);
360 VA_INIT(s, char *);
361
362 putchar('\n');
363 vprintf(s, VA_ARGS);
364 putchar('\n');
365
366 VA_END();
367 Abort(0L);
368 }
369
370