Implement EDIT statement and ON TIMER/ON KEY event trapping, update to v0.9.0
Add event-driven programming: ON TIMER(n) GOSUB with TIMER ON/OFF/STOP, ON KEY(n) GOSUB with KEY(n) ON/OFF/STOP for F1-F10. Fix F-key escape sequence parser (F9/F10 detection, push back consumed bytes on unmatched sequences). Add EDIT statement for TUI line editing. Guard key trap polling so keystrokes aren't consumed when no traps are configured.
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@
|
||||
#include "gw_math.h"
|
||||
#include "strings.h"
|
||||
|
||||
#define GW_VERSION "0.8.0"
|
||||
#define GW_VERSION "0.9.0"
|
||||
#define GW_BANNER "GW-BASIC " GW_VERSION
|
||||
|
||||
/* Tokenizer */
|
||||
|
||||
@@ -76,6 +76,10 @@ typedef struct {
|
||||
/* COMMON variable list for CHAIN */
|
||||
int common_count;
|
||||
struct { char name[2]; gw_valtype_t type; } common_vars[64];
|
||||
|
||||
/* Event trapping */
|
||||
timer_trap_t timer_trap;
|
||||
event_trap_t key_traps[10]; /* KEY(1)-KEY(10) */
|
||||
} interp_state_t;
|
||||
|
||||
extern interp_state_t gw;
|
||||
|
||||
@@ -45,6 +45,9 @@ typedef struct {
|
||||
#define TK_CTRL_C 0x03
|
||||
#define TK_CTRL_BREAK 0x200
|
||||
|
||||
/* Key buffer for event trapping (keys consumed from HAL but not yet processed) */
|
||||
#define TUI_KEYBUF_SIZE 16
|
||||
|
||||
/* TUI state */
|
||||
typedef struct {
|
||||
tui_cell_t *screen; /* dynamically allocated [rows * cols] */
|
||||
@@ -60,6 +63,9 @@ typedef struct {
|
||||
volatile bool break_flag; /* set by SIGINT handler */
|
||||
int view_top; /* top of scrollable area */
|
||||
int view_bottom; /* bottom row (rows-1 normally, rows-2 with key bar) */
|
||||
int keybuf[TUI_KEYBUF_SIZE]; /* ring buffer for pushed-back keys */
|
||||
int keybuf_head;
|
||||
int keybuf_tail;
|
||||
} tui_state_t;
|
||||
|
||||
extern tui_state_t tui;
|
||||
@@ -93,6 +99,14 @@ void tui_key_on(void);
|
||||
void tui_key_off(void);
|
||||
void tui_key_list(void);
|
||||
|
||||
/* EDIT statement */
|
||||
void tui_edit_line(const char *prefill);
|
||||
|
||||
/* Key buffer for event trapping */
|
||||
void tui_push_key(int key);
|
||||
int tui_pop_key(void);
|
||||
bool tui_keybuf_empty(void);
|
||||
|
||||
/* Ctrl+Break */
|
||||
void tui_check_break(void);
|
||||
void tui_install_break_handler(void);
|
||||
|
||||
@@ -64,11 +64,30 @@ typedef struct {
|
||||
uint16_t line_num;
|
||||
} for_entry_t;
|
||||
|
||||
/* Event trap mode */
|
||||
typedef enum { TRAP_OFF = 0, TRAP_ON = 1, TRAP_STOP = 2 } trap_mode_t;
|
||||
|
||||
/* Event trap state (shared by TIMER/KEY traps) */
|
||||
typedef struct event_trap {
|
||||
trap_mode_t mode;
|
||||
uint16_t gosub_line;
|
||||
bool pending;
|
||||
bool in_handler;
|
||||
} event_trap_t;
|
||||
|
||||
/* ON TIMER trap */
|
||||
typedef struct {
|
||||
event_trap_t trap;
|
||||
float interval; /* seconds */
|
||||
double last_fire; /* monotonic timestamp */
|
||||
} timer_trap_t;
|
||||
|
||||
/* GOSUB stack entry */
|
||||
typedef struct {
|
||||
uint8_t *ret_text;
|
||||
struct program_line *ret_line;
|
||||
uint16_t line_num;
|
||||
struct event_trap *event_source; /* non-NULL for event handler GOSUB */
|
||||
} gosub_entry_t;
|
||||
|
||||
/* WHILE stack entry */
|
||||
|
||||
Reference in New Issue
Block a user