• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revision41a8147d49c4f994117724247b9ea117e872d0a1 (tree)
Time2020-03-17 00:30:37
Authorshimitei <shimitei@gmai...>
Commitershimitei

Log Message

stub term

Change Summary

Incremental Difference

--- a/src/main-cap-hardcode.c
+++ /dev/null
@@ -1,1071 +0,0 @@
1-/* File: main-cap-hardcode.c */
2-
3-/* Purpose: Support for "term.c" using "termcap" calls */
4-
5-#include "angband.h"
6-
7-#define USE_HARDCODE
8-#define USE_TPOSIX
9-
10-/*
11- * This file is a total hack, but is often very helpful. :-)
12- *
13- * This file allows use of the terminal without requiring the
14- * "curses" routines. In fact, if "USE_HARDCODE" is defined,
15- * this file will attempt to use various hard-coded "vt100"
16- * escape sequences to also avoid the use of the "termcap"
17- * routines. I do not know if this will work on System V.
18- *
19- * This file is intended for use only on those machines which are
20- * unable, for whatever reason, to compile the "main-gcu.c" file,
21- * but which seem to be able to support the "termcap" library, or
22- * which at least seem able to support "vt100" terminals.
23- *
24- * Large portions of this file were stolen from "main-gcu.c"
25- *
26- * This file incorrectly handles output to column 80, I think.
27- */
28-
29-
30-/*
31- * Require a "system"
32- */
33-#if !defined(USE_TERMCAP) && !defined(USE_HARDCODE)
34-# define USE_TERMCAP
35-#endif
36-
37-/*
38- * Hack -- try to guess which systems use what commands
39- * Hack -- allow one of the "USE_Txxxxx" flags to be pre-set.
40- * Mega-Hack -- try to guess when "POSIX" is available.
41- * If the user defines two of these, we will probably crash.
42- */
43-#if !defined(USE_TPOSIX)
44-# if !defined(USE_TERMIO) && !defined(USE_TCHARS)
45-# if defined(_POSIX_VERSION)
46-# define USE_TPOSIX
47-# else
48-# if defined(USG) || defined(linux) || defined(SOLARIS)
49-# define USE_TERMIO
50-# else
51-# define USE_TCHARS
52-# endif
53-# endif
54-# endif
55-#endif
56-
57-
58-
59-/*
60- * POSIX stuff
61- */
62-#ifdef USE_TPOSIX
63-# include <sys/ioctl.h>
64-# include <termios.h>
65-#endif
66-
67-/*
68- * One version needs these files
69- */
70-#ifdef USE_TERMIO
71-# include <sys/ioctl.h>
72-# include <termio.h>
73-#endif
74-
75-/*
76- * The other needs these files
77- */
78-#ifdef USE_TCHARS
79-# include <sys/ioctl.h>
80-# include <sys/resource.h>
81-# include <sys/param.h>
82-# include <sys/file.h>
83-# include <sys/types.h>
84-#endif
85-
86-
87-/*
88- * XXX XXX Hack -- POSIX uses "O_NONBLOCK" instead of "O_NDELAY"
89- *
90- * They should both work due to the "(i != 1)" test in the code
91- * which checks for the result of the "read()" command.
92- */
93-#ifndef O_NDELAY
94-# define O_NDELAY O_NONBLOCK
95-#endif
96-
97-
98-
99-
100-#ifdef USE_TERMCAP
101-
102-/*
103- * Termcap string information
104- */
105-
106-static char blob[1024]; /* The "termcap" entry */
107-static char area[1024]; /* The string extraction buffer */
108-static char *next = area; /* The current "index" into "area" */
109-static char *desc; /* The terminal name */
110-
111-#endif
112-
113-
114-/*
115- * Pointers into the "area"
116- */
117-
118-static char *cm; /* Move cursor */
119-static char *ch; /* Move cursor to horizontal location */
120-static char *cv; /* Move cursor to vertical location */
121-static char *ho; /* Move cursor to top left */
122-static char *ll; /* Move cursor to bottom left */
123-static char *cs; /* Set scroll area */
124-static char *cl; /* Clear screen */
125-static char *cd; /* Clear to end of display */
126-static char *ce; /* Clear to end of line */
127-static char *cr; /* Move to start of line */
128-static char *so; /* Turn on standout */
129-static char *se; /* Turn off standout */
130-static char *md; /* Turn on bold */
131-static char *me; /* Turn off bold */
132-static char *vi; /* Cursor - invisible */
133-static char *ve; /* Cursor - normal */
134-static char *vs; /* Cursor - bright */
135-
136-
137-/*
138- * State variables
139- */
140-
141-static int rows; /* Screen size (Y) */
142-static int cols; /* Screen size (X) */
143-static int curx; /* Cursor location (X) */
144-static int cury; /* Cursor location (Y) */
145-static int curv; /* Cursor visibility */
146-
147-
148-/*
149- * Extern functions
150- */
151-extern char *getenv();
152-extern char *tgoto();
153-extern char *tgetstr();
154-
155-
156-/*
157- * Write some chars to the terminal
158- */
159-static void ewrite(char *str)
160-{
161- int numtowrite, numwritten;
162-
163- /* See how much work we have */
164- numtowrite = strlen(str);
165-
166- /* Write until done */
167- while (numtowrite > 0)
168- {
169- /* Try to write the chars */
170- numwritten = write(1, str, numtowrite);
171-
172- /* Handle FIFOs and EINTR */
173- if (numwritten < 0) numwritten = 0;
174-
175- /* See what we completed */
176- numtowrite -= numwritten;
177- str += numwritten;
178-
179- /* Hack -- sleep if not done */
180- if (numtowrite > 0) sleep(1);
181- }
182-}
183-
184-
185-
186-#ifdef USE_TERMCAP
187-
188-static char write_buffer[128];
189-static char *write_buffer_ptr;
190-
191-static void output_one(char c)
192-{
193- *write_buffer_ptr++ = c;
194-}
195-
196-static void tp(char *s)
197-{
198- /* Dump the string into us */
199- write_buffer_ptr = write_buffer;
200-
201- /* Write the string with padding */
202- tputs (s, 1, output_one);
203-
204- /* Finish the string */
205- *write_buffer_ptr = '\0';
206-
207- /* Dump the recorded buffer */
208- ewrite (write_buffer);
209-}
210-
211-#endif
212-
213-#ifdef USE_HARDCODE
214-
215-static void tp(char *s)
216-{
217- ewrite(s);
218-}
219-
220-#endif
221-
222-
223-
224-
225-
226-
227-
228-/*
229- * Clear the screen
230- */
231-static void do_cl(void)
232-{
233- if (cl) tp (cl);
234-}
235-
236-/*
237- * Clear to the end of the line
238- */
239-static void do_ce(void)
240-{
241- if (ce) tp(ce);
242-}
243-
244-
245-/*
246- * Set the cursor visibility (0 = invis, 1 = normal, 2 = bright)
247- */
248-static void curs_set(int vis)
249-{
250- char *v = NULL;
251-
252- if (!vis)
253- {
254- v = vi;
255- }
256- else if (vis > 1)
257- {
258- v = vs ? vs : ve;
259- }
260- else
261- {
262- v = ve ? ve : vs;
263- }
264-
265- if (v) tp(v);
266-}
267-
268-
269-
270-/*
271- * Restrict scrolling to within these rows
272- */
273-static void do_cs(int y1, int y2)
274-{
275-
276-#ifdef USE_TERMCAP
277- if (cs) tp(tgoto(cs, y2, y1));
278-#endif
279-
280-#ifdef USE_HARDCODE
281- char temp[64];
282- sprintf(temp, cs, y1, y2);
283- tp (temp);
284-#endif
285-
286-}
287-
288-
289-
290-/*
291- * Go to the given screen location directly
292- */
293-static void do_cm(int x, int y)
294-{
295-
296-#ifdef USE_TERMCAP
297- if (cm) tp(tgoto(cm, x, y));
298-#endif
299-
300-#ifdef USE_HARDCODE
301- char temp[64];
302- sprintf(temp, cm, y+1, x+1);
303- tp(temp);
304-#endif
305-
306-}
307-
308-
309-/*
310- * Go to the given screen location in a "clever" manner
311- *
312- * XXX XXX XXX This function could use some work!
313- */
314-static void do_move(int x1, int y1, int x2, int y2)
315-{
316- /* Hack -- unknown start location */
317- if ((x1 == x2) && (y1 == y2)) do_cm(x2, y2);
318-
319- /* Left edge */
320- else if (x2 == 0)
321- {
322- if ((y2 <= 0) && ho) tp(ho);
323- else if ((y2 >= rows-1) && ll) tp(ll);
324- else if ((y2 == y1) && cr) tp(cr);
325-#if 0
326- else if ((y2 == y1+1) && cr && dn)
327- { tp(cr); tp(dn); }
328- else if ((y2 == y1-1) && cr && up)
329- { tp(cr); tp(up); }
330-#endif
331- else do_cm(x2, y2);
332- }
333-
334-#if 0
335- /* Up/Down one line */
336- else if ((x2 == x1) && (y2 == y1+1) && dn) tp(dn);
337- else if ((x2 == x1) && (y2 == y1-1) && up) tp(up);
338-#endif
339-
340- /* Default -- go directly there */
341- else do_cm(x2, y2);
342-}
343-
344-
345-
346-
347-/*
348- * Help initialize this file (see below)
349- */
350-errr init_cap_aux(void)
351-{
352-
353-#ifdef USE_TERMCAP
354-
355- /* Get the terminal name (if possible) */
356- desc = getenv("TERM");
357- if (!desc) return (1);
358-
359- /* Get the terminal info */
360- if (tgetent(blob, desc) != 1) return (2);
361-
362- /* Get the (initial) columns and rows, or default */
363- if ((cols = tgetnum("co")) == -1) cols = 80;
364- if ((rows = tgetnum("li")) == -1) rows = 24;
365-
366- /* Find out how to move the cursor to a given location */
367- cm = tgetstr("cm", &next);
368- if (!cm) return (10);
369-
370- /* Find out how to move the cursor to a given position */
371- ch = tgetstr("ch", &next);
372- cv = tgetstr("cv", &next);
373-
374- /* Find out how to "home" the screen */
375- ho = tgetstr("ho", &next);
376-
377- /* Find out how to "last-line" the screen */
378- ll = tgetstr("ll", &next);
379-
380- /* Find out how to do a "carriage return" */
381- cr = tgetstr("cr", &next);
382- if (!cr) cr = "\r";
383-
384- /* Find out how to clear the screen */
385- cl = tgetstr("cl", &next);
386- if (!cl) return (11);
387-
388- /* Find out how to clear to the end of display */
389- cd = tgetstr("cd", &next);
390-
391- /* Find out how to clear to the end of the line */
392- ce = tgetstr("ce", &next);
393-
394- /* Find out how to scroll (set the scroll region) */
395- cs = tgetstr("cs", &next);
396-
397- /* Find out how to hilite */
398- so = tgetstr("so", &next);
399- se = tgetstr("se", &next);
400- if (!so || !se) so = se = NULL;
401-
402- /* Find out how to bold */
403- md = tgetstr("md", &next);
404- me = tgetstr("me", &next);
405- if (!md || !me) md = me = NULL;
406-
407- /* Check the cursor visibility stuff */
408- vi = tgetstr("vi", &next);
409- vs = tgetstr("vs", &next);
410- ve = tgetstr("ve", &next);
411-
412-#endif
413-
414-#ifdef USE_HARDCODE
415-
416- /* Assume some defualt information */
417- rows = 24;
418- cols = 80;
419-
420- /* Clear screen */
421- cl = "\033[2J\033[H"; /* --]--]-- */
422-
423- /* Clear to end of line */
424- ce = "\033[K"; /* --]-- */
425-
426- /* Hilite on/off */
427- so = "\033[7m"; /* --]-- */
428- se = "\033[m"; /* --]-- */
429-
430- /* Scroll region */
431- cs = "\033[%d;%dr"; /* --]-- */
432-
433- /* Move cursor */
434- cm = "\033[%d;%dH"; /* --]-- */
435-
436-#endif
437-
438- /* Success */
439- return (0);
440-}
441-
442-
443-
444-
445-
446-
447-
448-/*
449- * Save the "normal" and "angband" terminal settings
450- */
451-
452-#ifdef USE_TPOSIX
453-
454-static struct termios norm_termios;
455-
456-static struct termios game_termios;
457-
458-#endif
459-
460-#ifdef USE_TERMIO
461-
462-static struct termio norm_termio;
463-
464-static struct termio game_termio;
465-
466-#endif
467-
468-#ifdef USE_TCHARS
469-
470-static struct sgttyb norm_ttyb;
471-static struct tchars norm_tchars;
472-static struct ltchars norm_ltchars;
473-static int norm_local_chars;
474-
475-static struct sgttyb game_ttyb;
476-static struct tchars game_tchars;
477-static struct ltchars game_ltchars;
478-static int game_local_chars;
479-
480-#endif
481-
482-
483-
484-/*
485- * Are we active? Not really needed.
486- */
487-static int active = FALSE;
488-
489-
490-/*
491- * The main screen (no sub-screens)
492- */
493-static term term_screen_body;
494-
495-
496-
497-/*
498- * Place the "keymap" into its "normal" state
499- */
500-static void keymap_norm(void)
501-{
502-
503-#ifdef USE_TPOSIX
504-
505- /* restore the saved values of the special chars */
506- (void)tcsetattr(0, TCSAFLUSH, &norm_termios);
507-
508-#endif
509-
510-#ifdef USE_TERMIO
511-
512- /* restore the saved values of the special chars */
513- (void)ioctl(0, TCSETA, (char *)&norm_termio);
514-
515-#endif
516-
517-#ifdef USE_TCHARS
518-
519- /* restore the saved values of the special chars */
520- (void)ioctl(0, TIOCSETP, (char *)&norm_ttyb);
521- (void)ioctl(0, TIOCSETC, (char *)&norm_tchars);
522- (void)ioctl(0, TIOCSLTC, (char *)&norm_ltchars);
523- (void)ioctl(0, TIOCLSET, (char *)&norm_local_chars);
524-
525-#endif
526-
527-}
528-
529-
530-/*
531- * Place the "keymap" into the "game" state
532- */
533-static void keymap_game(void)
534-{
535-
536-#ifdef USE_TPOSIX
537-
538- /* restore the saved values of the special chars */
539- (void)tcsetattr(0, TCSAFLUSH, &game_termios);
540-
541-#endif
542-
543-#ifdef USE_TERMIO
544-
545- /* restore the saved values of the special chars */
546- (void)ioctl(0, TCSETA, (char *)&game_termio);
547-
548-#endif
549-
550-#ifdef USE_TCHARS
551-
552- /* restore the saved values of the special chars */
553- (void)ioctl(0, TIOCSETP, (char *)&game_ttyb);
554- (void)ioctl(0, TIOCSETC, (char *)&game_tchars);
555- (void)ioctl(0, TIOCSLTC, (char *)&game_ltchars);
556- (void)ioctl(0, TIOCLSET, (char *)&game_local_chars);
557-
558-#endif
559-
560-}
561-
562-
563-/*
564- * Save the normal keymap
565- */
566-static void keymap_norm_prepare(void)
567-{
568-
569-#ifdef USE_TPOSIX
570-
571- /* Get the normal keymap */
572- tcgetattr(0, &norm_termios);
573-
574-#endif
575-
576-#ifdef USE_TERMIO
577-
578- /* Get the normal keymap */
579- (void)ioctl(0, TCGETA, (char *)&norm_termio);
580-
581-#endif
582-
583-#ifdef USE_TCHARS
584-
585- /* Get the normal keymap */
586- (void)ioctl(0, TIOCGETP, (char *)&norm_ttyb);
587- (void)ioctl(0, TIOCGETC, (char *)&norm_tchars);
588- (void)ioctl(0, TIOCGLTC, (char *)&norm_ltchars);
589- (void)ioctl(0, TIOCLGET, (char *)&norm_local_chars);
590-
591-#endif
592-
593-}
594-
595-
596-/*
597- * Save the keymaps (normal and game)
598- */
599-static void keymap_game_prepare(void)
600-{
601-
602-#ifdef USE_TPOSIX
603-
604- /* Acquire the current mapping */
605- tcgetattr(0, &game_termios);
606-
607- /* Force "Ctrl-C" to interupt */
608- game_termios.c_cc[VINTR] = (char)3;
609-
610- /* Force "Ctrl-Z" to suspend */
611- game_termios.c_cc[VSUSP] = (char)26;
612-
613- /* Hack -- Leave "VSTART/VSTOP" alone */
614-
615- /* Disable the standard control characters */
616- game_termios.c_cc[VQUIT] = (char)-1;
617- game_termios.c_cc[VERASE] = (char)-1;
618- game_termios.c_cc[VKILL] = (char)-1;
619- game_termios.c_cc[VEOF] = (char)-1;
620- game_termios.c_cc[VEOL] = (char)-1;
621-
622- /* Normally, block until a character is read */
623- game_termios.c_cc[VMIN] = 1;
624- game_termios.c_cc[VTIME] = 0;
625-
626- /* Hack -- Turn off "echo" and "canonical" mode */
627- game_termios.c_lflag &= ~(ECHO | ICANON);
628-
629- /* Turn off flow control */
630- game_termios.c_iflag &= ~IXON;
631-
632-#endif
633-
634-#ifdef USE_TERMIO
635-
636- /* Acquire the current mapping */
637- (void)ioctl(0, TCGETA, (char *)&game_termio);
638-
639- /* Force "Ctrl-C" to interupt */
640- game_termio.c_cc[VINTR] = (char)3;
641-
642- /* Force "Ctrl-Z" to suspend */
643- game_termio.c_cc[VSUSP] = (char)26;
644-
645- /* Hack -- Leave "VSTART/VSTOP" alone */
646-
647- /* Disable the standard control characters */
648- game_termio.c_cc[VQUIT] = (char)-1;
649- game_termio.c_cc[VERASE] = (char)-1;
650- game_termio.c_cc[VKILL] = (char)-1;
651- game_termio.c_cc[VEOF] = (char)-1;
652- game_termio.c_cc[VEOL] = (char)-1;
653-
654-#if 0
655- /* Disable the non-posix control characters */
656- game_termio.c_cc[VEOL2] = (char)-1;
657- game_termio.c_cc[VSWTCH] = (char)-1;
658- game_termio.c_cc[VDSUSP] = (char)-1;
659- game_termio.c_cc[VREPRINT] = (char)-1;
660- game_termio.c_cc[VDISCARD] = (char)-1;
661- game_termio.c_cc[VWERASE] = (char)-1;
662- game_termio.c_cc[VLNEXT] = (char)-1;
663- game_termio.c_cc[VSTATUS] = (char)-1;
664-#endif
665-
666- /* Normally, block until a character is read */
667- game_termio.c_cc[VMIN] = 1;
668- game_termio.c_cc[VTIME] = 0;
669-
670- /* Hack -- Turn off "echo" and "canonical" mode */
671- game_termio.c_lflag &= ~(ECHO | ICANON);
672-
673- /* Turn off flow control */
674- game_termio.c_iflag &= ~IXON;
675-
676-#endif
677-
678-#ifdef USE_TCHARS
679-
680- /* Get the default game characters */
681- (void)ioctl(0, TIOCGETP, (char *)&game_ttyb);
682- (void)ioctl(0, TIOCGETC, (char *)&game_tchars);
683- (void)ioctl(0, TIOCGLTC, (char *)&game_ltchars);
684- (void)ioctl(0, TIOCLGET, (char *)&game_local_chars);
685-
686- /* Force interupt (^C) */
687- game_tchars.t_intrc = (char)3;
688-
689- /* Force start/stop (^Q, ^S) */
690- game_tchars.t_startc = (char)17;
691- game_tchars.t_stopc = (char)19;
692-
693- /* Cancel some things */
694- game_tchars.t_quitc = (char)-1;
695- game_tchars.t_eofc = (char)-1;
696- game_tchars.t_brkc = (char)-1;
697-
698- /* Force suspend (^Z) */
699- game_ltchars.t_suspc = (char)26;
700-
701- /* Cancel some things */
702- game_ltchars.t_dsuspc = (char)-1;
703- game_ltchars.t_rprntc = (char)-1;
704- game_ltchars.t_flushc = (char)-1;
705- game_ltchars.t_werasc = (char)-1;
706- game_ltchars.t_lnextc = (char)-1;
707-
708- /* XXX XXX XXX XXX Verify this before use */
709- /* Hack -- Turn off "echo" and "canonical" mode */
710- /* game_termios.c_lflag &= ~(ECHO | ICANON); */
711- game_ttyb.flag &= ~(ECHO | ICANON);
712-
713- /* XXX XXX XXX Should maybe turn off flow control too. How? */
714-
715-#endif
716-
717-}
718-
719-
720-
721-
722-
723-
724-
725-
726-/*
727- * Suspend/Resume
728- */
729-static errr Term_xtra_cap_alive(int v)
730-{
731- /* Suspend */
732- if (!v)
733- {
734- if (!active) return (1);
735-
736- /* Hack -- make sure the cursor is visible */
737- curs_set(1);
738-
739- /* Move to bottom right */
740- do_move(0, rows - 1, 0, rows - 1);
741-
742- /* Go to normal keymap mode */
743- keymap_norm();
744-
745- /* No longer active */
746- active = FALSE;
747- }
748-
749- /* Resume */
750- else
751- {
752- if (active) return (1);
753-
754- /* Hack -- restore the cursor location */
755- do_move(curx, cury, curx, cury);
756-
757- /* Hack -- restore the cursor visibility */
758- curs_set(curv);
759-
760- /* Go to angband keymap mode */
761- keymap_game();
762-
763- /* Now we are active */
764- active = TRUE;
765- }
766-
767- /* Success */
768- return (0);
769-}
770-
771-
772-
773-/*
774- * Process an event
775- */
776-static errr Term_xtra_cap_event(int v)
777-{
778- int i, arg;
779- char buf[2];
780-
781- /* Wait */
782- if (v)
783- {
784- /* Wait for one byte */
785- i = read(0, buf, 1);
786-
787- /* Hack -- Handle "errors" */
788- if ((i <= 0) && (errno != EINTR)) exit_game_panic();
789- }
790-
791- /* Do not wait */
792- else
793- {
794- /* Get the current flags for stdin */
795- if ((arg = fcntl(0, F_GETFL, 0)) < 1) return (1);
796-
797- /* Tell stdin not to block */
798- if (fcntl(0, F_SETFL, arg | O_NDELAY) < 0) return (1);
799-
800- /* Read one byte, if possible */
801- i = read(0, buf, 1);
802-
803- /* Replace the flags for stdin */
804- if (fcntl(0, F_SETFL, arg)) return (1);
805- }
806-
807- /* No keys ready */
808- if ((i != 1) || (!buf[0])) return (1);
809-
810- /* Enqueue the keypress */
811- Term_keypress(buf[0]);
812-
813- /* Success */
814- return (0);
815-}
816-
817-
818-
819-
820-/*
821- * Actually move the hardware cursor
822- */
823-static errr Term_curs_cap(int x, int y)
824-{
825- /* Literally move the cursor */
826- do_move(curx, cury, x, y);
827-
828- /* Save the cursor location */
829- curx = x;
830- cury = y;
831-
832- /* Success */
833- return (0);
834-}
835-
836-
837-/*
838- * Erase a grid of space
839- *
840- * XXX XXX XXX Note that we will never be asked to clear the
841- * bottom line all the way to the bottom right edge, since we
842- * have set the "avoid the bottom right corner" flag.
843- */
844-static errr Term_wipe_cap(int x, int y, int n)
845-{
846- int dx;
847-
848- /* Place the cursor */
849- Term_curs_cap(x, y);
850-
851- /* Wipe to end of line */
852- if (x + n >= 80)
853- {
854- do_ce();
855- }
856-
857- /* Wipe region */
858- else
859- {
860- for (dx = 0; dx < n; ++dx)
861- {
862- putc(' ', stdout);
863- curx++;
864- }
865- }
866-
867- /* Success */
868- return (0);
869-}
870-
871-
872-/*
873- * Place some text on the screen using an attribute
874- */
875-static errr Term_text_cap(int x, int y, int n, byte a, concptr s)
876-{
877- int i;
878-
879- /* Move the cursor */
880- Term_curs_cap(x, y);
881-
882- /* Dump the text, advance the cursor */
883- for (i = 0; s[i]; i++)
884- {
885- /* Dump the char */
886- putc(s[i], stdout);
887-
888- /* Advance cursor 'X', and wrap */
889- if (++curx >= cols)
890- {
891- /* Reset cursor 'X' */
892- curx = 0;
893-
894- /* Hack -- Advance cursor 'Y', and wrap */
895- if (++cury == rows) cury = 0;
896- }
897- }
898-
899- /* Success */
900- return (0);
901-}
902-
903-
904-/*
905- * Handle a "special request"
906- */
907-static errr Term_xtra_cap(int n, int v)
908-{
909- /* Analyze the request */
910- switch (n)
911- {
912- /* Clear the screen */
913- case TERM_XTRA_CLEAR:
914- do_cl();
915- do_move(0, 0, 0, 0);
916- return (0);
917-
918- /* Make a noise */
919- case TERM_XTRA_NOISE:
920- (void)write(1, "\007", 1);
921- return (0);
922-
923- /* Change the cursor visibility */
924- case TERM_XTRA_SHAPE:
925- curv = v;
926- curs_set(v);
927- return (0);
928-
929- /* Suspend/Resume */
930- case TERM_XTRA_ALIVE:
931- return (Term_xtra_cap_alive(v));
932-
933- /* Process events */
934- case TERM_XTRA_EVENT:
935- return (Term_xtra_cap_event(v));
936-
937- /* Flush events */
938- case TERM_XTRA_FLUSH:
939- while (!Term_xtra_cap_event(FALSE));
940- return (0);
941-
942- /* Delay */
943- case TERM_XTRA_DELAY:
944- usleep(1000 * v);
945- return (0);
946- }
947-
948- /* Not parsed */
949- return (1);
950-}
951-
952-
953-
954-
955-/*
956- * Init a "term" for this file
957- */
958-static void Term_init_cap(term *t)
959-{
960- if (active) return;
961-
962- /* Assume cursor at top left */
963- curx = 0;
964- cury = 0;
965-
966- /* Assume visible cursor */
967- curv = 1;
968-
969- /* Clear the screen */
970- do_cl();
971-
972- /* Hack -- visible cursor */
973- curs_set(1);
974-
975- /* Assume active */
976- active = TRUE;
977-}
978-
979-
980-/*
981- * Nuke a "term" for this file
982- */
983-static void Term_nuke_cap(term *t)
984-{
985- if (!active) return;
986-
987- /* Hack -- make sure the cursor is visible */
988- curs_set(1);
989-
990- /* Move to bottom right */
991- do_move(0, rows - 1, 0, rows - 1);
992-
993- /* Normal keymap */
994- keymap_norm();
995-
996- /* No longer active */
997- active = FALSE;
998-}
999-
1000-
1001-
1002-
1003-
1004-
1005-
1006-
1007-
1008-
1009-/*
1010- * Prepare this file for Angband usage
1011- */
1012-errr init_cap(void)
1013-{
1014- term *t = &term_screen_body;
1015-
1016-
1017- /*** Initialize ***/
1018-
1019- /* Initialize the screen */
1020- if (init_cap_aux()) return (-1);
1021-
1022- /* Hack -- Require large screen, or Quit with message */
1023- if ((rows < 24) || (cols < 80)) quit("Screen too small!");
1024-
1025-
1026- /*** Prepare to play ***/
1027-
1028- /* Extract the normal keymap */
1029- keymap_norm_prepare();
1030-
1031- /* Extract the game keymap */
1032- keymap_game_prepare();
1033-
1034- /* Hack -- activate the game keymap */
1035- keymap_game();
1036-
1037- /* Hack -- Do NOT buffer stdout */
1038- setbuf(stdout, NULL);
1039-
1040-
1041- /*** Now prepare the term ***/
1042-
1043- /* Initialize the term */
1044- term_init(t, 80, 24, 256);
1045-
1046- /* Avoid the bottom right corner */
1047- t->icky_corner = TRUE;
1048-
1049- /* Erase with "white space" */
1050- t->attr_blank = TERM_WHITE;
1051- t->char_blank = ' ';
1052-
1053- /* Set some hooks */
1054- t->init_hook = Term_init_cap;
1055- t->nuke_hook = Term_nuke_cap;
1056-
1057- /* Set some more hooks */
1058- t->text_hook = Term_text_cap;
1059- t->wipe_hook = Term_wipe_cap;
1060- t->curs_hook = Term_curs_cap;
1061- t->xtra_hook = Term_xtra_cap;
1062-
1063- /* Save the term */
1064- term_screen = t;
1065-
1066- /* Activate it */
1067- Term_activate(term_screen);
1068-
1069- /* Success */
1070- return (0);
1071-}
--- /dev/null
+++ b/src/main-wasm-term.c
@@ -0,0 +1,169 @@
1+/* File: main-wasm-term.c */
2+
3+#include "angband.h"
4+
5+/*
6+ * The main screen (no sub-screens)
7+ */
8+static term term_screen_body;
9+
10+/*
11+ * Are we active? Not really needed.
12+ */
13+static int active = FALSE;
14+
15+/*
16+ * State variables
17+ */
18+
19+static int rows; /* Screen size (Y) */
20+static int cols; /* Screen size (X) */
21+static int curx; /* Cursor location (X) */
22+static int cury; /* Cursor location (Y) */
23+static int curv; /* Cursor visibility */
24+
25+/*
26+ * Help initialize this file (see below)
27+ */
28+errr init_wasm_aux(void)
29+{
30+ /* Assume some defualt information */
31+ rows = 24;
32+ cols = 80;
33+
34+ /* Success */
35+ return (0);
36+}
37+
38+/*
39+ * Init a "term" for this file
40+ */
41+static void Term_init_wasm(term* t)
42+{
43+ if (active) return;
44+
45+ /* Assume cursor at top left */
46+ curx = 0;
47+ cury = 0;
48+
49+ /* Assume visible cursor */
50+ curv = 1;
51+
52+ /* Assume active */
53+ active = TRUE;
54+}
55+
56+/*
57+ * Nuke a "term" for this file
58+ */
59+static void Term_nuke_wasm(term* t)
60+{
61+ if (!active) return;
62+
63+ /* No longer active */
64+ active = FALSE;
65+}
66+
67+/*
68+ * Place some text on the screen using an attribute
69+ */
70+static errr Term_text_wasm(int x, int y, int n, byte a, concptr s)
71+{
72+ printf("%s", s);
73+
74+ /* Success */
75+ return (0);
76+}
77+
78+/*
79+ * Erase a grid of space
80+ *
81+ * XXX XXX XXX Note that we will never be asked to clear the
82+ * bottom line all the way to the bottom right edge, since we
83+ * have set the "avoid the bottom right corner" flag.
84+ */
85+static errr Term_wipe_wasm(int x, int y, int n)
86+{
87+ /* Success */
88+ return (0);
89+}
90+
91+/*
92+ * Actually move the hardware cursor
93+ */
94+static errr Term_curs_wasm(int x, int y)
95+{
96+ /* Save the cursor location */
97+ curx = x;
98+ cury = y;
99+
100+ /* Success */
101+ return (0);
102+}
103+
104+/*
105+ * Process an event
106+ */
107+static errr Term_xtra_wasm_event(int v)
108+{
109+ /* Success */
110+ return (0);
111+}
112+
113+/*
114+ * Handle a "special request"
115+ */
116+static errr Term_xtra_wasm(int n, int v)
117+{
118+ /* Not parsed */
119+ return (1);
120+}
121+
122+/*
123+ * Prepare this file for Angband usage
124+ */
125+errr init_wasm(void)
126+{
127+ term *t = &term_screen_body;
128+
129+
130+ /*** Initialize ***/
131+
132+ /* Initialize the screen */
133+ if (init_wasm_aux()) return (-1);
134+
135+ /* Hack -- Require large screen, or Quit with message */
136+ if ((rows < 24) || (cols < 80)) quit("Screen too small!");
137+
138+
139+ /*** Now prepare the term ***/
140+
141+ /* Initialize the term */
142+ term_init(t, 80, 24, 256);
143+
144+ /* Avoid the bottom right corner */
145+ t->icky_corner = TRUE;
146+
147+ /* Erase with "white space" */
148+ t->attr_blank = TERM_WHITE;
149+ t->char_blank = ' ';
150+
151+ /* Set some hooks */
152+ t->init_hook = Term_init_wasm;
153+ t->nuke_hook = Term_nuke_wasm;
154+
155+ /* Set some more hooks */
156+ t->text_hook = Term_text_wasm;
157+ t->wipe_hook = Term_wipe_wasm;
158+ t->curs_hook = Term_curs_wasm;
159+ t->xtra_hook = Term_xtra_wasm;
160+
161+ /* Save the term */
162+ term_screen = t;
163+
164+ /* Activate it */
165+ Term_activate(term_screen);
166+
167+ /* Success */
168+ return (0);
169+}
--- a/src/makefile.em
+++ b/src/makefile.em
@@ -4,11 +4,12 @@ CC = emcc
44 LD = emcc
55 CFLAGS = -c
66 LDFLAGS = -v -s EXIT_RUNTIME=1
7+DEFINES = -DHAVE_USLEEP
78
89 TARGET_FILE = hengband.html
910
1011 CFILES = \
11- main-wasm.c main-cap-hardcode.c \
12+ main-wasm.c main-wasm-term.c \
1213 artifact.c autopick.c avatar.c \
1314 birth.c bldg.c \
1415 chest.c chuukei.c cmd2.c cmd4.c cmd-activate.c cmd-eat.c \
@@ -54,7 +55,7 @@ install : all
5455 cp hengband.* ..
5556
5657 $(TARGET_FILE):
57- $(LD) $(LDFLAGS) $(CFILES) --preload-file lib -o $(TARGET_FILE)
58+ $(LD) $(LDFLAGS) $(DEFINES) $(CFILES) --preload-file lib -o $(TARGET_FILE)
5859
5960 .PHONY: clean
6061 clean: