1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
#include <atari.h>
#include <conio.h>
#include <string.h>
#include "addrs.h"
#include "screen.h"
#include "edbox.h"
#include "complete.h"
#include "keytab.h"
extern void __fastcall__ bell(void);
char *old_edbox[EDBOX_SIZE];
static u16 old_len;
static int typeover;
int edbox_visible = 0;
static u16 edbox_pos; /* range 0 to EDBOX_SIZE - 1 */
u16 edbox_len; /* idem */
void (*edbox_callback)(void);
static void hide_cursor(void) {
edit_box[edbox_pos] &= 0x7f;
}
static void show_cursor(void) {
edit_box[edbox_pos] |= 0x80;
}
void edbox_clear(void) {
memset(edit_box, 0, EDBOX_SIZE);
edbox_pos = edbox_len = 0;
show_cursor(); // not needed? seems it is..
}
void edbox_show(void) {
u16 addr;
if(edbox_pos < 80)
addr = (u16)edit_box;
else
addr = (u16)edit_box + edbox_pos - 79;
scr_waitvcount(116);
*dlist_status_lms = addr;
*dlist_last_line = 0x02; /* ANTIC GR.0 */
edbox_visible = 1;
show_cursor();
}
void edbox_hide(void) {
scr_end_scrollback(); /* exit Start+E mode */
edbox_visible = 0;
scr_refresh();
}
/* note: c will never be an EOL.
idea: when the edbox is completely full (240 chars), go
ahead and pretend the user pressed Return (call edbox_callback,
etc). not sure if this is more or less annoying than just
refusing to accept more input until Return is pressed. */
void edbox_putc(char c) {
if(!c)
return; /* no inserting nulls */
if(!typeover)
memmove(edit_box + edbox_pos + 1, edit_box + edbox_pos, EDBOX_SIZE - edbox_pos - 1);
edit_box[edbox_pos] = c;
if(edbox_pos < EDBOX_SIZE - 1) {
edbox_pos++;
edbox_len++;
} else {
bell();
}
}
static void copy_to_old(void) {
if(!edbox_len) return;
memcpy(old_edbox, edit_box, edbox_len);
memset(old_edbox + edbox_len, 0, (EDBOX_SIZE - 1) - edbox_len);
old_len = edbox_len;
}
static void restore_old(void) {
edbox_clear();
hide_cursor();
memcpy(edit_box, old_edbox, old_len);
edbox_pos = edbox_len = old_len;
}
static void del_char(void) {
if(!edbox_len) return;
memmove(edit_box + edbox_pos, edit_box + edbox_pos + 1, EDBOX_SIZE - edbox_pos - 1);
edbox_len--;
}
static void del_to_end(void) {
while(edbox_len > edbox_pos)
del_char();
}
static void backspace(void) {
if(!edbox_pos) return;
edbox_pos--;
del_char();
}
static void up(void) {
if(!edbox_len) {
restore_old();
} else {
if(edbox_pos > 39)
edbox_pos -= 40;
else
edbox_pos = 0;
}
}
static void down(void) {
if(edbox_pos > 199) return;
edbox_pos += 40;
if(edbox_pos > edbox_len)
edbox_pos = edbox_len;
}
static void word_left(char del) {
if(!edbox_pos) return;
if(!del) edbox_pos--;
while(edbox_pos && edit_box[edbox_pos] == ' ') {
if(del) del_char();
edbox_pos--;
}
while(edbox_pos && edit_box[edbox_pos] != ' ') {
if(del) del_char();
edbox_pos--;
}
// XXX: what's this good for?
if(del && !edbox_pos) edit_box[edbox_pos] = /* ' ' */ 0;
}
static void del_word(void) {
word_left(1);
}
static void back_word(void) {
word_left(0);
}
static void forward_word(void) {
while(edbox_pos < edbox_len && edit_box[edbox_pos] == ' ')
edbox_pos++;
while(edbox_pos < edbox_len && edit_box[edbox_pos] != ' ')
edbox_pos++;
}
static void del_to_start(void) {
while(edbox_pos) backspace();
}
void left(void) {
if(edbox_pos) edbox_pos--;
}
void right(void) {
if(edbox_pos < edbox_len) edbox_pos++;
}
void edbox_keystroke(char c) {
extern char start_latch;
extern void start_keystroke(char);
if(c == CH_ESC) {
start_latch = 1;
return;
}
if(c != XCH_TAB)
comp_complete_done();
if(c >= XCH_SCR1 && c <= XCH_SCR7) {
start_keystroke(c & 0x7f);
return;
} else if(c == XCH_ACTIVE) {
start_keystroke('a');
return;
}
edbox_show();
hide_cursor();
switch(c) {
case CH_EOL:
copy_to_old();
edbox_hide();
if(edbox_callback)
(*edbox_callback)();
edbox_clear();
break;
case XCH_TAB:
comp_complete();
break;
case XCH_UP:
up();
break;
case XCH_DOWN:
down();
break;
case XCH_LEFT:
left();
break;
case XCH_RIGHT:
right();
break;
case XCH_LWORD:
back_word();
break;
case XCH_RWORD:
forward_word();
break;
case XCH_CLS:
edbox_clear();
edbox_hide();
return;
case CH_DELCHR:
case 0x18: /* ^X */
del_char();
break;
case CH_DELLINE:
edbox_clear();
break;
case XCH_INSCHR:
typeover = !typeover;
break;
case 0x15: /* ^U */
del_to_start();
break;
case 0x0b: /* ^K */
del_to_end();
break;
case XCH_BS:
if(!edbox_len)
edbox_hide();
else
backspace();
break;
case 0x17: /* ^W */
del_word();
break;
case 0x01: /* ^A */
edbox_pos = 0;
break;
case 0x05: /* ^E */
edbox_pos = edbox_len;
break;
default:
edbox_putc(c);
break;
}
show_cursor();
if(edbox_visible) edbox_show();
}
void edbox_addchr(char c) {
edit_box[edbox_len++] = c;
edbox_pos = edbox_len;
}
void edbox_space(void) {
edbox_addchr(' ');
}
void edbox_set(char *contents) {
edbox_clear();
while(*contents) {
edit_box[edbox_len++] = *contents++;
}
edbox_pos = edbox_len;
}
|