Debian Codegraph @

common/shell.h

raw
1 /*****************************************************************************
2 * Free42 -- an HP-42S calculator simulator
3 * Copyright (C) 2004-2026 Thomas Okken
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,
7 * as 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, see http://www.gnu.org/licenses/.
16 *****************************************************************************/
17
18 #ifndef SHELL_H
19 #define SHELL_H 1
20
21 #include "free42.h"
22
23 /* shell_platform()
24 *
25 * The shell should return a null-terminated string here that identifies the
26 * app's version number, and the platform it is built for. So, something like
27 * "2.5.3 Windows". N.B. It is not necessary to identify the version of the OS
28 * we're running on; what matters is the version of the app itself, and
29 * "Windows" conveys that information, while "Windows 2000 sp4" or "Windows 10"
30 * would add nothing useful.
31 * The returned string will not be freed by the caller, so it can be passed in
32 * a static buffer, or it may even be a constant.
33 */
34 const char *shell_platform();
35
36 /* shell_blitter()
37 *
38 * Callback invoked by the emulator core to cause the display, or some portion
39 * of it, to be repainted.
40 *
41 * 'bits' is a pointer to a 1 bpp (monochrome) bitmap. The bits within a byte
42 * are laid out with left corresponding to least significant, right
43 * corresponding to most significant; this corresponds to the convention for
44 * X11 images, but it is the reverse of the convention for MacOS and Windows.
45 * The bytes are laid out sequentially, that is, bits[0] is at the top
46 * left corner, bits[1] is to the right of bits[0], bits[2] is to the right of
47 * bits[1], and so on; this corresponds to X11, MacOS, and Windows usage.
48 * 'bytesperline' is the number of bytes per line of the bitmap; this means
49 * that the bits just below bits[0] are at bits[bytesperline].
50 * 'x', 'y', 'width', and 'height' define the part of the bitmap that needs to
51 * be repainted. 'x' and 'y' are 0-based coordinates, with (0, 0) being the top
52 * left corner of the bitmap, and x coordinates increasing to the right, and y
53 * coordinates increasing downwards. 'width' and 'height' are the width and
54 * height of the area to be repainted.
55 */
56 void shell_blitter(const char *bits, int bytesperline, int x, int y,
57 int width, int height);
58
59 /* shell_beeper()
60 *
61 * Callback invoked by the emulator core to play a sound.
62 * The parameter is the tone number, from 0 to 9, or 10 for the error beep.
63 * Sound playback should be synchronous (the beeper function should
64 * not return until the sound has finished), if possible.
65 */
66 void shell_beeper(int tone);
67
68 /* shell_annunciators()
69 *
70 * Callback invoked by the emulator core to change the state of the display
71 * annunciators (up/down, shift, print, run, battery, (g)rad).
72 * Every parameter can have values 0 (turn off), 1 (turn on), or -1 (leave
73 * unchanged).
74 * The battery annunciator is missing from the list; this is the only one of
75 * the lot that the emulator core does not actually have any control over, and
76 * so the shell is expected to handle that one by itself.
77 */
78 void shell_annunciators(int updn, int shf, int prt, int run, int g, int rad);
79
80 /* shell_wants_cpu()
81 *
82 * Callback used by the emulator core to check for pending events.
83 * It calls this periodically during long operations, such as running a
84 * user program, or the solver, etc. The shell should not handle any events
85 * in this call! If there are pending events, it should return 1; the currently
86 * active invocation of core_keydown() or core_keyup() will then return
87 * immediately (with a return value of 1, to indicate that it would like to get
88 * the CPU back as soon as possible).
89 */
90 bool shell_wants_cpu();
91
92 /* shell_delay()
93 *
94 * Callback to suspend execution for the given number of milliseconds. No event
95 * processing will take place during the wait, so the core can call this
96 * without having to worry about core_keydown() etc. being re-entered.
97 */
98 void shell_delay(int duration);
99
100 /* shell_request_timeout3()
101 *
102 * Callback to ask the shell to call core_timeout3() after the given number of
103 * milliseconds. If there are keystroke events during that time, the timeout is
104 * cancelled. (Pressing 'shift' does not cancel the timeout.)
105 * This function supports the delay after SHOW, MEM, and shift-VARMENU.
106 */
107 void shell_request_timeout3(int delay);
108
109 /* shell_get_mem()
110 *
111 * Callback to get the amount of free memory in bytes.
112 */
113 uint8 shell_get_mem();
114
115 /* shell_low_battery()
116 *
117 * Callback to find out if the battery is low. Used to emulate flag 49 and the
118 * battery annunciator.
119 */
120 bool shell_low_battery();
121
122 /* shell_powerdown()
123 *
124 * Callback to tell the shell that the emulator wants to power down.
125 * Only called in response to OFF (shift-EXIT or the OFF command); automatic
126 * power-off is left to the OS and/or shell.
127 */
128 void shell_powerdown();
129
130 /* shell_random_seed()
131 *
132 * When SEED is invoked with X = 0, the random number generator should be
133 * seeded to a random value; the emulator core calls this function to obtain
134 * it. The core uses the least significant 14 decimal digits of the provided
135 * value, so using a millisecond-resolution time stamp means SEED won't
136 * repeat itself for more than 3000 years.
137 */
138 int8 shell_random_seed();
139
140 /* shell_milliseconds()
141 *
142 * Returns an elapsed-time value in milliseconds. The caller should make no
143 * assumptions as to what this value is relative to; it is only intended to
144 * allow the emulator core make short-term elapsed-time measurements.
145 */
146 uint4 shell_milliseconds();
147
148 /* shell_number_format()
149 *
150 * Returns a UTF-8 encoded four-character string, describing the number
151 * formatting parameters for the current locale. The four characters are:
152 * 0: decimal (must be one of '.' or ',')
153 * 1: grouping character (must be one of '.', ',', '\'', or space)
154 * 2: primary grouping size
155 * 3: secondary grouping size
156 * The grouping sizes are encoded as ASCII digits. If there is no grouping,
157 * only the decimal character will be present, so the string will be only 1
158 * character long.
159 * The caller should not modify or free the string.
160 *
161 * The number formatting information is used for Copy and Paste of scalars and
162 * matrices, and to determine the initial setting of flag 28 on cold start.
163 */
164 const char *shell_number_format();
165
166 /* shell_date_format()
167 *
168 * Returns 0 if the host's locale uses MDY date format;
169 * returns 1 if it uses DMY;
170 * returns 2 if it uses YMD.
171 * If the host's date format doesn't match any of these three component
172 * orders, returns 0.
173 * Used to initialize flags 31 and 67 on hard reset.
174 */
175 int shell_date_format();
176
177 /* shell_clk24()
178 *
179 * Returns 0 if the host's locale uses a 12-hour clock
180 * returns 1 if it uses a 24-hour clock
181 * Used to initialize CLK12/CLK24 mode on hard reset.
182 */
183 bool shell_clk24();
184
185 /* shell_print()
186 *
187 * Printer emulation. The first 2 parameters are the plain text version of the
188 * data to be printed; the remaining 6 parameters are the bitmap version. The
189 * former is used for text-mode copying and for spooling to text files; the
190 * latter is used for graphics-mode copying, spooling to image files, and
191 * on-screen display.
192 */
193 void shell_print(const char *text, int length,
194 const char *bits, int bytesperline,
195 int x, int y, int width, int height);
196
197 #if defined(ANDROID) || defined(IPHONE)
198
199 /* shell_show_alpha_keyboard()
200 *
201 * Requests the pop-up ALPHA keyboard to be shown or hidden.
202 */
203 void shell_show_alpha_keyboard(bool show);
204
205 /* shell_get_acceleration()
206 * shell_get_location()
207 * shell_get_heading()
208 *
209 * These functions were added to support the iPhone's accelerometer, GPS, and
210 * compass. Shells on platforms that do not provide this functionality should
211 * return 0; a return value of 1 indicates success (though not necessarily
212 * accuracy!).
213 *
214 * The units used here match those on the iPhone; implementations on other
215 * platforms should transform their units to match iPhone conventions. This
216 * probably won't be an issue in practice, since the iPhone's units match
217 * established international standards, the one exception being acceleration,
218 * which it expresses in units of Earth gravities rather than the standard
219 * m/s^2. TODO: what is the exact conversion factor used by the iPhone?
220 *
221 * shell_get_acceleration: x, y, z in g's (see above). Looking at the device
222 * in portrait orientation, positive x points to the right, positive y points
223 * up, and positive z points toward the user.
224 * shell_get_location: lat and lon are in decimal degrees, with N and E
225 * positive; lat_lon_acc, elev, and elev_acc are in meters. TODO: what is
226 * elev relative to?
227 * shell_get_heading: mag_heading and true_heading are in decimal degrees,
228 * along the y axis (using the same coordinate system as described above),
229 * with 0 being N, 90 being E, etc., acc is in decimal degrees, and x, y, and z
230 * are magnetic deviation (again using the same coordinate system as above),
231 * in microteslas, but normalized to the range -128..128. TODO: What's this
232 * "normalization"? I hope they mean "clipped", because otherwise you wouldn't
233 * have a unit, yet they claim the unit is microteslas.
234 */
235 bool shell_get_acceleration(double *x, double *y, double *z);
236 bool shell_get_location(double *lat, double *lon, double *lat_lon_acc,
237 double *elev, double *elev_acc);
238 bool shell_get_heading(double *mag_heading, double *true_heading, double *acc,
239 double *x, double *y, double *z);
240
241 #endif
242
243 /* shell_always_on()
244 *
245 * Sets and queries the "always on" state (flag 44). Pass 0 to clear, 1 to set,
246 * or -1 to leave unchanged; returns the previous state.
247 */
248 bool shell_always_on(int always_on);
249
250 /* shell_get_time_date()
251 *
252 * Get the current time and date. The date should be provided formatted as
253 * YYYYMMDD, and the time should be provided formatted as HHMMSSss (24-hour).
254 * The weekday is a number from 0 to 6, with 0 being Sunday.
255 */
256 void shell_get_time_date(uint4 *time, uint4 *date, int *weekday);
257
258 /* shell_message()
259 *
260 * Displays a modal pop-up message box.
261 */
262 void shell_message(const char *message);
263
264 /* shell_log()
265 *
266 * Writes text to some place where log output should go, typically Standard
267 * Output on systems where this is easy to access, and the system's usual
268 * logging facility otherwise.
269 * Note: non-debug versions of Free42 should never use this.
270 */
271 void shell_log(const char *message);
272
273 #endif