Revert "Update package dependency from libwxgtk3.0-dev to libwxgtk3.0-gtk3-dev for...
[ctsim.git] / libctsupport / consoleio.cpp
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (c) 1983-2009 Kevin Rosenberg
4 **
5 **  This program is free software; you can redistribute it and/or modify
6 **  it under the terms of the GNU General Public License (version 2) as
7 **  published by the Free Software Foundation.
8 **
9 **  This program is distributed in the hope that it will be useful,
10 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 **  GNU General Public License for more details.
13 **
14 **  You should have received a copy of the GNU General Public License
15 **  along with this program; if not, write to the Free Software
16 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 ******************************************************************************/
18
19 #include <stdio.h>
20 #include <string.h>
21 #include "ctsupport.h"
22
23
24 /* NAME
25  *   cio_put_c                          Put a character on screen
26  *
27  * SYNOPSIS
28  *   cio_put_c (c)
29  *   char c                             Character to write
30  *
31  * NOTES
32  *   Color of character is determined by the global variable, crtv.text_attr.
33  *
34  * SIDE EFFECTS
35  *   Cursor is advanced by one.  If necessary, the cursor will wrap around
36  *   and maybe the screen will scroll
37  */
38
39 void
40 cio_put_c (int c)
41 {
42     fputc(c, stdout);
43 }
44
45
46
47 /* NAME
48  *    cio_put_cc                        Put a char on screen count times
49  *
50  * SYNOPSIS
51  *    cio_put_cc (c, count)
52  *    char c                            Character to write
53  *    int count                         Number of characters to write
54  */
55
56 void
57 cio_put_cc (int c, int count)
58 {
59     for (int i = 0; i < count; i++)
60         cio_put_c (c);
61 }
62
63
64 void
65 cio_put_str (const char *str)
66 {
67     fputs (str, stdout);
68 }
69
70
71
72 /* NAME
73  *   kb_getc                    Get a character from the keyboard
74  *
75  * SYNOPSIS
76  *   key = kb_getc()
77  *
78  * DESCRIPTION
79  *      1. This routine returns an EXTENTED ASCII code,
80  *         the extended codes have a low byte of 0 and a distinctive
81  *         high byte, such as 0x2D00 and 0x3200
82  *      2. This routine waits until a key has been typed
83  *      2. The keystroke will not be echoed.
84  */
85
86 unsigned int cio_kb_getc(void)
87 {
88     return fgetc(stdin);
89 }
90
91 void
92 cio_kb_ungetc (unsigned int c)
93 {
94     ungetc(c, stdin);
95 }
96
97 /* NAME
98  *    kb_gets                           Get a string from the keyboard
99  *
100  * SYNOPSIS
101  *    str = kb_gets (str, maxlen)
102  *    char *str                         Space to store input string
103  *    int maxlen                        Maximum number of characters to read
104  *                                      (Not including EOS)
105  * NOTES
106  *    Backspace - erases character to the right
107  *    Escape    - erases to beginning of line
108  *    Return    - ends string (no not cause a linefeed)
109  */
110
111 char *
112 cio_kb_gets (char *str, int maxlen)
113 {
114     return fgets(str, maxlen, stdin);
115 }
116
117 /* NAME
118  *   kb_waitc                   Wait for a character from the keyboard
119  *
120  * SYNOPSIS
121  *   key = kb_waitc (astr, estr, beep)
122  *   int key                    Keystroke entered
123  *   char *astr                 String of valid ascii characters
124  *   bool beep                  If TRUE, beep when user hits invalid key
125  *
126  */
127
128
129 unsigned int
130 cio_kb_waitc (const char *astr, int beep_on_error)
131 {
132   unsigned int c;
133   do {
134     c = cio_kb_getc ();
135     if (strchr (astr, c) != NULL)
136         break;
137     if (beep_on_error)
138       cio_beep();
139   } while (1);
140
141   return (c);
142 }
143
144
145 /* NAME
146  *    beep                              sound a beep to user
147  *
148  * SYNOPSIS
149  *    beep()
150  */
151
152 void cio_beep (void)
153 {
154         cio_tone (2000.0, 0.3);
155 }
156
157 /* NAME
158  *    tone              play a frequency sound for some duration
159  *
160  * SYNOPSIS
161  *    tone (freq, length)
162  *    double freq       frequency to play in Hertz
163  *    double length     duration to play note in seconds
164  */
165
166 void
167 cio_tone (double freq, double length)
168 {
169 #if 1
170   fprintf(stdout, "\007");
171 #else
172   cio_spkr_freq (freq);         /* Set frequency of tone */
173   cio_spkr_on ();                       /* Turn on speaker */
174   pause (length);                       /* Pause for length seconds */
175   cio_spkr_off ();                      /* Turn off speaker */
176 #endif
177 }