77#include "api/api.h"
88#include "api/atr.h"
99#include "api/oem.h"
10+ #include "api/pro.h"
1011#include "api/std.h"
1112#include "str/rln.h"
1213#include "sys/com.h"
2122static inline void DBG (const char * fmt , ...) { (void )fmt ; }
2223#endif
2324
24- /*
25- THIS IS A WORK IN PROGRESS
26- IT IS INCOMPLETE
27- */
28-
29- /*
30- * Attribute System - dispatches get/set to actual data sources
31- * -------------------------------------------------------------
32- * Readline attributes (0x00-0x0F) - state lives in rln.c:
33- * 0x01 ATR_SUPPRESS_END_MOVE - Suppress cursor move to end after input (bool, default 0)
34- * 0x02 ATR_SUPPRESS_NEWLINE - Suppress newline after input (bool, default 0)
35- * 0x03 ATR_ENABLE_HISTORY - Enable input history (bool, default 0)
36- * 0x04 ATR_MAX_LENGTH - Readline length limit 0-255 (uint8, default 254)
37- * 0x05 ATR_TIMEOUT - Timeout in milliseconds (uint32, 0 = disabled)
38- * 0x06 ATR_CTRL_BITS - End readline on ctrl chars (uint32)
39- * 0x07 ATR_END_CHAR - Char that ended readline (uint8, read-only)
40- * 0x08 ATR_TIMED_OUT - True if readline timed out (bool, read-only)
41- * 0x09 ATR_CURSOR_POS - Cursor position (uint8, 0xFF = end of line)
42- *
43- * System attributes (0x80-0x8F) - deprecated API functions mirrored:
44- * 0x80 ATR_PHI2_KHZ - CPU clock in kHz (uint16, read-only via attr)
45- * 0x81 ATR_CODE_PAGE - OEM code page (uint16)
46- * 0x82 ATR_LRAND - Random number (uint32, read-only)
47- * 0x83 ATR_ERRNO_OPT - Errno option (uint8, read-only via attr)
48- */
25+ // Attribute IDs
26+ #define ATR_ERRNO_OPT 0x00
27+ #define ATR_PHI2_KHZ 0x01
28+ #define ATR_CODE_PAGE 0x02
29+ #define ATR_RLN_LENGTH 0x03
30+ #define ATR_LRAND 0x04
31+ #define ATR_BEL 0x05
32+ #define ATR_LAUNCHER 0x06
4933
50- // Attribute IDs - readline (0x00-0x0F)
51- #define ATR_SUPPRESS_END_MOVE 0x01
52- #define ATR_SUPPRESS_NEWLINE 0x02
53- #define ATR_ENABLE_HISTORY 0x03
54- #define ATR_MAX_LENGTH 0x04
55- #define ATR_TIMEOUT 0x05
56- #define ATR_CTRL_BITS 0x06
57- #define ATR_END_CHAR 0x07
58- #define ATR_TIMED_OUT 0x08
59- #define ATR_CURSOR_POS 0x09
60-
61- // Attribute IDs - system (0x80-0x8F) - mirrors deprecated APIs
62- #define ATR_PHI2_KHZ 0x80
63- #define ATR_CODE_PAGE 0x81
64- #define ATR_LRAND 0x82
65- #define ATR_ERRNO_OPT 0x83
66-
67- // int ria_get_attr(uint32_t *attr, uint8_t attr_id);
34+ // long ria_get_attr(uint8_t attr_id);
6835bool atr_api_get (void )
6936{
70- uint8_t attr_id = API_A ;
71- uint32_t value = 0 ;
72-
73- switch (attr_id )
37+ switch (API_A )
7438 {
75- // Readline attributes - dispatch to rln.c
76- case ATR_SUPPRESS_END_MOVE :
77- value = rln_get_suppress_end_move () ? 1 : 0 ;
78- break ;
79- case ATR_SUPPRESS_NEWLINE :
80- value = rln_get_suppress_newline () ? 1 : 0 ;
81- break ;
82- case ATR_ENABLE_HISTORY :
83- value = rln_get_enable_history () ? 1 : 0 ;
84- break ;
85- case ATR_MAX_LENGTH :
86- value = rln_get_max_length ();
87- break ;
88- case ATR_TIMEOUT :
89- value = rln_get_timeout ();
90- break ;
91- case ATR_CTRL_BITS :
92- value = rln_get_ctrl_bits ();
93- break ;
94- case ATR_END_CHAR :
95- value = rln_get_end_char ();
96- break ;
97- case ATR_TIMED_OUT :
98- value = rln_get_timed_out () ? 1 : 0 ;
99- break ;
100- case ATR_CURSOR_POS :
101- value = rln_get_cursor_pos ();
102- break ;
103-
104- // System attributes - dispatch to respective modules
39+ case ATR_ERRNO_OPT :
40+ return api_return_axsreg (api_get_errno_opt ());
10541 case ATR_PHI2_KHZ :
106- value = cpu_get_phi2_khz ();
107- break ;
42+ return api_return_axsreg (cpu_get_phi2_khz_run ());
10843 case ATR_CODE_PAGE :
109- value = oem_get_code_page ();
110- break ;
44+ return api_return_axsreg (oem_get_code_page_run ());
45+ case ATR_RLN_LENGTH :
46+ return api_return_axsreg (rln_get_max_length ());
11147 case ATR_LRAND :
112- value = get_rand_32 () & 0x7FFFFFFF ;
113- break ;
114- case ATR_ERRNO_OPT :
115- value = api_get_errno_opt ();
116- break ;
117-
48+ return api_return_axsreg (get_rand_64 () & 0x7FFFFFFF );
49+ case ATR_BEL :
50+ return api_return_axsreg (com_get_bel ());
51+ case ATR_LAUNCHER :
52+ return api_return_axsreg (pro_get_launcher ());
11853 default :
11954 return api_return_errno (API_EINVAL );
12055 }
121-
122- // Push value to xstack for return
123- if (!api_push_uint32 (& value ))
124- return api_return_errno (API_ENOMEM );
125- return api_return_ax (0 );
12656}
12757
12858// int ria_set_attr(uint32_t attr, uint8_t attr_id);
@@ -132,134 +62,57 @@ bool atr_api_set(void)
13262 uint32_t value ;
13363 if (!api_pop_uint32_end (& value ))
13464 return api_return_errno (API_EINVAL );
135-
13665 switch (attr_id )
13766 {
138- // Readline attributes - dispatch to rln.c
139- case ATR_SUPPRESS_END_MOVE :
140- rln_set_suppress_end_move (value != 0 );
141- break ;
142- case ATR_SUPPRESS_NEWLINE :
143- rln_set_suppress_newline (value != 0 );
144- break ;
145- case ATR_ENABLE_HISTORY :
146- rln_set_enable_history (value != 0 );
147- break ;
148- case ATR_MAX_LENGTH :
149- rln_set_max_length ((uint8_t )value );
150- break ;
151- case ATR_TIMEOUT :
152- rln_set_timeout (value );
153- break ;
154- case ATR_CTRL_BITS :
155- rln_set_ctrl_bits (value );
156- break ;
157- case ATR_END_CHAR :
158- // Read-only, ignore silently
159- break ;
160- case ATR_TIMED_OUT :
161- // Read-only, ignore silently
162- break ;
163- case ATR_CURSOR_POS :
164- rln_set_cursor_pos ((uint8_t )value );
67+ case ATR_ERRNO_OPT :
68+ api_set_errno_opt ((uint8_t )value );
16569 break ;
166-
167- // System attributes
16870 case ATR_PHI2_KHZ :
169- // TODO ephemeral
170- cpu_set_phi2_khz ((uint16_t )value );
71+ cpu_set_phi2_khz_run ((uint16_t )value );
17172 break ;
17273 case ATR_CODE_PAGE :
173- oem_set_code_page_ephemeral ((uint16_t )value );
74+ oem_set_code_page_run ((uint16_t )value );
17475 break ;
175- case ATR_LRAND :
176- // Read-only, ignore silently
76+ case ATR_RLN_LENGTH :
77+ rln_set_max_length (( uint8_t ) value );
17778 break ;
178- case ATR_ERRNO_OPT :
179- api_set_errno_opt ( (uint8_t )value );
79+ case ATR_BEL :
80+ com_set_bel (( bool )!! (uint8_t )value );
18081 break ;
181-
82+ case ATR_LAUNCHER :
83+ pro_set_launcher ((bool )!!(uint8_t )value );
84+ break ;
85+ case ATR_LRAND : // Read only
18286 default :
18387 return api_return_errno (API_EINVAL );
18488 }
185-
186- return api_return_ax (0 );
187- }
188-
189- // int ria_set_readline(char *buf);
190- // Sets buffer for readline continuation. Buffer is on xstack, null-terminated.
191- bool atr_api_set_readline (void )
192- {
193- // Get buffer from xstack (null-terminated string)
194- char * buf = (char * )& xstack [xstack_ptr ];
195- size_t len = strlen (buf );
196-
197- // Clamp length to max_length
198- uint8_t max_len = rln_get_max_length ();
199- if (len > max_len )
200- len = max_len ;
201-
202- // Validate cursor position (0xFF means end of line)
203- uint8_t cursor_pos = rln_get_cursor_pos ();
204- if (cursor_pos > len )
205- cursor_pos = len ;
206- rln_set_cursor_pos (cursor_pos );
207-
208- // Output the buffer contents (with potential newline expansion based on setting)
209- for (size_t i = 0 ; i < len ; i ++ )
210- {
211- putchar (buf [i ]);
212- }
213-
214- // Move cursor back if not at end and not suppressing end move
215- if (!rln_get_suppress_end_move () && cursor_pos < len )
216- {
217- printf ("\33[%dD" , (int )(len - cursor_pos ));
218- }
219-
220- xstack_ptr = XSTACK_SIZE ;
22189 return api_return_ax (0 );
22290}
22391
22492/*
22593 * Deprecated API functions - moved here from their original modules.
226- * These are the old API op codes that are now also accessible via attributes.
94+ * These are the old API op codes that are now accessible via attributes.
22795 */
22896
229- // int phi2(unsigned khz ) - set/get CPU clock
97+ // int phi2(void ) - set/get CPU clock
23098bool atr_api_phi2 (void )
23199{
232- uint16_t khz = API_AX ;
233- if (khz )
234- cpu_set_phi2_khz (khz );
235- return api_return_ax (cpu_get_phi2_khz ());
100+ return api_return_ax (cpu_get_phi2_khz_run ());
236101}
237102
238103// int codepage(unsigned cp) - set/get OEM code page
239104bool atr_api_code_page (void )
240105{
241106 uint16_t cp = API_AX ;
242107 if (cp )
243- oem_set_code_page_ephemeral (cp );
244- return api_return_ax (oem_get_code_page ());
108+ oem_set_code_page_run (cp );
109+ return api_return_ax (oem_get_code_page_run ());
245110}
246111
247112// long lrand(void) - get random number
248113bool atr_api_lrand (void )
249114{
250- return api_return_axsreg (get_rand_32 () & 0x7FFFFFFF );
251- }
252-
253- // int stdin_opt(unsigned long ctrl_bits, unsigned char str_length)
254- bool atr_api_stdin_opt (void )
255- {
256- uint8_t str_length = API_A ;
257- uint32_t ctrl_bits ;
258- if (!api_pop_uint32_end (& ctrl_bits ))
259- return api_return_errno (API_EINVAL );
260- rln_set_max_length (str_length );
261- rln_set_ctrl_bits (ctrl_bits );
262- return api_return_ax (0 );
115+ return api_return_axsreg (get_rand_64 () & 0x7FFFFFFF );
263116}
264117
265118// int errno_opt(unsigned char opt) - set errno mapping
@@ -270,45 +123,3 @@ bool atr_api_errno_opt(void)
270123 return api_return_errno (API_EINVAL );
271124 return api_return_ax (0 );
272125}
273-
274- // stdin_opt is garbage. it's time to make better controls
275- // for the custom OS readline-like system on stdin/stdout.
276- // It should not be tcgetattr/tcsetattr. Do something best for this.
277- // Do not delete these requirements, convert into terse comment documentation that will be expanded later.
278-
279- // Need to set these, typically only once to init, get optional
280- //-----------
281- // bool to disable newline expansion. default off
282- // bool to supress moving to end of line after input. default off
283- // bool to supress newline after input. default off
284- // bool to enable input history. default off
285- // Limit readline length 0-255 (uint8), default 254
286- // Timeout in 6.2 seconds (uint8).
287- // End readline on ctrl_bits (uint32)
288-
289- // These must have get, setting would be ignored
290- // ---------
291- // ctrl_bits char that ended previous readline (uint8). always 10(\r) if ctrl_bits==0
292- // bool if previous readline timed out
293-
294- // These must have get/set, typically used with buffer sets and gets
295- // ---------
296- // Cursor position (uint8)
297-
298- // ria_set_readline is the opposite of get which is already implemented as from read_* functions.
299- // buffer (uint8[256])
300-
301- // Setting ria_set_readline tells readline to continue editing as if the text
302- // was already displayed and the term cursor placed according to "supress moving to end of line".
303- // Meaning the term cursor will be moved from the end of line to Cursor position if not supressed.
304-
305- // Invalid cursor position is moved to end of line. e.g. 0xff always means end of line
306-
307- // Do not change com.c, use putchar_raw in std_out_write to bypass newline expansion
308-
309- // These deprecated APIs are now implemented above as atr_api_*:
310- // - atr_api_phi2() was cpu_api_phi2()
311- // - atr_api_code_page() was oem_api_code_page()
312- // - atr_api_lrand() was rng_api_lrand()
313- // - atr_api_stdin_opt() was std_api_stdin_opt()
314- // - atr_api_errno_opt() was api_api_errno_opt()
0 commit comments