Subversion Repositories SvarDOS

Rev

Rev 1312 | Rev 1314 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1312 Rev 1313
1
/* Sved, the SvarDOS editor
1
/* Sved, the SvarDOS editor
2
 *
2
 *
3
 * Copyright (C) 2023 Mateusz Viste
3
 * Copyright (C) 2023 Mateusz Viste
4
 *
4
 *
5
 * Sved is released under the terms of the MIT license.
5
 * Sved is released under the terms of the MIT license.
6
 *
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to
8
 * of this software and associated documentation files (the "Software"), to
9
 * deal in the Software without restriction, including without limitation the
9
 * deal in the Software without restriction, including without limitation the
10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11
 * sell copies of the Software, and to permit persons to whom the Software is
11
 * sell copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
12
 * furnished to do so, subject to the following conditions:
13
 *
13
 *
14
 * The above copyright notice and this permission notice shall be included in
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
15
 * all copies or substantial portions of the Software.
16
 *
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
 * IN THE SOFTWARE.
23
 * IN THE SOFTWARE.
24
 */
24
 */
25
 
25
 
26
#include <dos.h>
26
#include <dos.h>
27
#include <fcntl.h>
27
#include <fcntl.h>
28
#include <stdlib.h>
28
#include <stdlib.h>
29
#include <string.h>
29
#include <string.h>
30
#include <malloc.h>   /* _fcalloc() */
30
#include <malloc.h>   /* _fcalloc() */
31
 
31
 
32
#include "mdr\bios.h"
32
#include "mdr\bios.h"
33
#include "mdr\cout.h"
33
#include "mdr\cout.h"
34
#include "mdr\dos.h"
34
#include "mdr\dos.h"
35
#include "mdr\keyb.h"
35
#include "mdr\keyb.h"
36
 
36
 
37
#include "svarlang\svarlang.h"
37
#include "svarlang\svarlang.h"
38
 
38
 
39
#define COL_TXT        0
39
#define COL_TXT        0
40
#define COL_STATUSBAR1 1
40
#define COL_STATUSBAR1 1
41
#define COL_STATUSBAR2 2
41
#define COL_STATUSBAR2 2
42
#define COL_SCROLLBAR  3
42
#define COL_SCROLLBAR  3
43
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
43
/* preload the mono scheme (to be overloaded at runtime if color adapter present) */
44
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0x70};
44
static unsigned char scheme[] = {0x07, 0x70, 0x70, 0x70};
45
 
45
 
46
#define SCROLL_CURSOR 0xB1
46
#define SCROLL_CURSOR 0xB1
47
 
47
 
48
 
48
 
49
struct line {
49
struct line {
50
  struct line far *prev;
50
  struct line far *prev;
51
  struct line far *next;
51
  struct line far *next;
52
  unsigned short len;
52
  unsigned short len;
53
  char payload[1];
53
  char payload[1];
54
};
54
};
55
 
55
 
56
struct linedb {
56
struct linedb {
57
  struct line far *cursor;
57
  struct line far *cursor;
58
  unsigned short xoffset;
58
  unsigned short xoffset;
-
 
59
  char lfonly; /* set if line endings are LF (CR/LF otherwise) */
59
};
60
};
60
 
61
 
61
 
62
 
62
/* returns non-zero on error */
63
/* returns non-zero on error */
63
static int line_add(struct linedb *db, const char far *line) {
64
static int line_add(struct linedb *db, const char far *line) {
64
  unsigned short slen;
65
  unsigned short slen;
65
  struct line far *l;
66
  struct line far *l;
66
 
67
 
67
  /* slen = strlen(line) (but for far pointer) */
68
  /* slen = strlen(line) (but for far pointer) */
68
  for (slen = 0; line[slen] != 0; slen++);
69
  for (slen = 0; line[slen] != 0; slen++);
69
 
70
 
70
  /* trim out CR/LF line endings */
71
  /* trim out CR/LF line endings */
71
  if ((slen >= 2) && (line[slen - 2] == '\r')) {
72
  if ((slen >= 2) && (line[slen - 2] == '\r')) {
72
    slen -= 2;
73
    slen -= 2;
73
  } else if ((slen >= 1) && (line[slen - 1] == '\n')) {
74
  } else if ((slen >= 1) && (line[slen - 1] == '\n')) {
74
    slen--;
75
    slen--;
75
  }
76
  }
76
 
77
 
77
  l = _fcalloc(1, sizeof(struct line) + slen + 1);
78
  l = _fcalloc(1, sizeof(struct line) + slen + 1);
78
  if (l == NULL) return(-1);
79
  if (l == NULL) return(-1);
79
 
80
 
80
  l->prev = db->cursor;
81
  l->prev = db->cursor;
81
  if (db->cursor) {
82
  if (db->cursor) {
82
    l->next = db->cursor->next;
83
    l->next = db->cursor->next;
83
    db->cursor->next = l;
84
    db->cursor->next = l;
84
    l->next->prev = l;
85
    l->next->prev = l;
85
  }
86
  }
86
  db->cursor = l;
87
  db->cursor = l;
87
  _fmemcpy(l->payload, line, slen);
88
  _fmemcpy(l->payload, line, slen);
88
  l->len = slen;
89
  l->len = slen;
89
 
90
 
90
  return(0);
91
  return(0);
91
}
92
}
92
 
93
 
93
 
94
 
94
static void db_rewind(struct linedb *db) {
95
static void db_rewind(struct linedb *db) {
95
  if (db->cursor == NULL) return;
96
  if (db->cursor == NULL) return;
96
  while (db->cursor->prev) db->cursor = db->cursor->prev;
97
  while (db->cursor->prev) db->cursor = db->cursor->prev;
97
}
98
}
98
 
99
 
99
 
100
 
100
static void load_colorscheme(void) {
101
static void load_colorscheme(void) {
101
  scheme[COL_TXT] = 0x17;
102
  scheme[COL_TXT] = 0x17;
102
  scheme[COL_STATUSBAR1] = 0x70;
103
  scheme[COL_STATUSBAR1] = 0x70;
103
  scheme[COL_STATUSBAR2] = 0x78;
104
  scheme[COL_STATUSBAR2] = 0x78;
104
  scheme[COL_SCROLLBAR] = 0x70;
105
  scheme[COL_SCROLLBAR] = 0x70;
105
}
106
}
106
 
107
 
107
 
108
 
108
static void ui_basic(unsigned char screenw, unsigned char screenh, const char *fname) {
109
static void ui_basic(unsigned char screenw, unsigned char screenh, const char *fname, const struct linedb *db) {
109
  unsigned char i;
110
  unsigned char i;
110
  const char *s = svarlang_strid(0); /* HELP */
111
  const char *s = svarlang_strid(0); /* HELP */
111
  unsigned char helpcol = screenw - (strlen(s) + 4);
112
  unsigned char helpcol = screenw - (strlen(s) + 4);
112
 
113
 
113
  /* clear screen */
114
  /* clear screen */
114
  mdr_cout_cls(scheme[COL_TXT]);
115
  mdr_cout_cls(scheme[COL_TXT]);
115
 
116
 
116
  /* status bar */
117
  /* fill status bar with background */
-
 
118
  mdr_cout_char_rep(screenh - 1, 0, ' ', scheme[COL_STATUSBAR1], screenw);
-
 
119
 
117
  for (i = 0; i < helpcol; i++) {
120
  /* filename */
118
    mdr_cout_char(screenh - 1, i, *fname, scheme[COL_STATUSBAR1]);
121
  mdr_cout_str(screenh - 1, 0, fname, scheme[COL_STATUSBAR1], screenw);
-
 
122
 
-
 
123
  /* eol type */
119
    if (*fname != 0) fname++;
124
  if (db->lfonly) {
-
 
125
    mdr_cout_str(screenh - 1, helpcol - 3, "LF", scheme[COL_STATUSBAR1], 5);
-
 
126
  } else {
-
 
127
    mdr_cout_str(screenh - 1, helpcol - 5, "CRLF", scheme[COL_STATUSBAR1], 5);
120
  }
128
  }
-
 
129
 
121
  mdr_cout_str(screenh - 1, helpcol, " F1=", scheme[COL_STATUSBAR2], 40);
130
  mdr_cout_str(screenh - 1, helpcol, " F1=", scheme[COL_STATUSBAR2], 40);
122
  mdr_cout_str(screenh - 1, helpcol + 4, s, scheme[COL_STATUSBAR2], 40);
131
  mdr_cout_str(screenh - 1, helpcol + 4, s, scheme[COL_STATUSBAR2], 40);
123
 
132
 
124
  /* scroll bar */
133
  /* scroll bar */
125
  for (i = 0; i < (screenh - 1); i++) {
134
  for (i = 0; i < (screenh - 1); i++) {
126
    mdr_cout_char(i, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
135
    mdr_cout_char(i, screenw - 1, SCROLL_CURSOR, scheme[COL_SCROLLBAR]);
127
  }
136
  }
128
}
137
}
129
 
138
 
130
 
139
 
131
static void ui_msg(const char *msg, unsigned char screenw, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
140
static void ui_msg(const char *msg, unsigned char screenw, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
132
  unsigned short x, y, msglen, i;
141
  unsigned short x, y, msglen, i;
133
  msglen = strlen(msg);
142
  msglen = strlen(msg);
134
  y = (screenh - 4) >> 1;
143
  y = (screenh - 4) >> 1;
135
  x = (screenw - msglen - 4) >> 1;
144
  x = (screenw - msglen - 4) >> 1;
136
  for (i = y+2; i >= y; i--) mdr_cout_char_rep(i, x, ' ', scheme[COL_STATUSBAR1], msglen + 2);
145
  for (i = y+2; i >= y; i--) mdr_cout_char_rep(i, x, ' ', scheme[COL_STATUSBAR1], msglen + 2);
137
  mdr_cout_str(y+1, x+1, msg, scheme[COL_STATUSBAR1], msglen);
146
  mdr_cout_str(y+1, x+1, msg, scheme[COL_STATUSBAR1], msglen);
138
 
147
 
139
  if (*uidirtyfrom > y) *uidirtyfrom = y;
148
  if (*uidirtyfrom > y) *uidirtyfrom = y;
140
  if (*uidirtyto < y+2) *uidirtyto = y+2;
149
  if (*uidirtyto < y+2) *uidirtyto = y+2;
141
}
150
}
142
 
151
 
143
 
152
 
144
static void ui_help(unsigned char screenw) {
153
static void ui_help(unsigned char screenw) {
145
#define MAXLINLEN 35
154
#define MAXLINLEN 35
146
  unsigned short i, offset;
155
  unsigned short i, offset;
147
  offset = (screenw - MAXLINLEN + 1) >> 1;
156
  offset = (screenw - MAXLINLEN + 1) >> 1;
148
  mdr_cout_cursor_hide();
157
  mdr_cout_cursor_hide();
149
  for (i = 2; i <= 12; i++) {
158
  for (i = 2; i <= 12; i++) {
150
    mdr_cout_char_rep(i, offset - 2, ' ', scheme[COL_STATUSBAR1], MAXLINLEN);
159
    mdr_cout_char_rep(i, offset - 2, ' ', scheme[COL_STATUSBAR1], MAXLINLEN);
151
  }
160
  }
152
 
161
 
153
  mdr_cout_str(3, offset, svarlang_str(0, 0), scheme[COL_STATUSBAR1], MAXLINLEN);
162
  mdr_cout_str(3, offset, svarlang_str(0, 0), scheme[COL_STATUSBAR1], MAXLINLEN);
154
  for (i = 0; i <= 2; i++) {
163
  for (i = 0; i <= 2; i++) {
155
    mdr_cout_str(5 + i, offset, svarlang_str(8, i), scheme[COL_STATUSBAR1], MAXLINLEN);
164
    mdr_cout_str(5 + i, offset, svarlang_str(8, i), scheme[COL_STATUSBAR1], MAXLINLEN);
156
  }
165
  }
157
  mdr_cout_str(9, offset, svarlang_str(8, 10), scheme[COL_STATUSBAR1], MAXLINLEN);
166
  mdr_cout_str(9, offset, svarlang_str(8, 10), scheme[COL_STATUSBAR1], MAXLINLEN);
158
  mdr_cout_str(11, offset, svarlang_str(8, 11), scheme[COL_STATUSBAR1], MAXLINLEN);
167
  mdr_cout_str(11, offset, svarlang_str(8, 11), scheme[COL_STATUSBAR1], MAXLINLEN);
159
 
168
 
160
  keyb_getkey();
169
  keyb_getkey();
161
  mdr_cout_cursor_show();
170
  mdr_cout_cursor_show();
162
#undef MAXLINLEN
171
#undef MAXLINLEN
163
}
172
}
164
 
173
 
165
 
174
 
166
static void ui_refresh(const struct linedb *db, unsigned char screenw, unsigned char screenh, unsigned char uidirtyfrom, unsigned char uidirtyto, unsigned char y) {
175
static void ui_refresh(const struct linedb *db, unsigned char screenw, unsigned char screenh, unsigned char uidirtyfrom, unsigned char uidirtyto, unsigned char y) {
167
  unsigned char len;
176
  unsigned char len;
168
  const struct line far *l;
177
  const struct line far *l;
169
 
178
 
170
#ifdef DBG_REFRESH
179
#ifdef DBG_REFRESH
171
  static char m = 'a';
180
  static char m = 'a';
172
  m++;
181
  m++;
173
  if (m > 'z') m = 'a';
182
  if (m > 'z') m = 'a';
174
#endif
183
#endif
175
 
184
 
176
  /* rewind cursor line to first line that needs redrawing */
185
  /* rewind cursor line to first line that needs redrawing */
177
  for (l = db->cursor; y > uidirtyfrom; y--) l = l->prev;
186
  for (l = db->cursor; y > uidirtyfrom; y--) l = l->prev;
178
 
187
 
179
  /* iterate over lines and redraw whatever needs to be redrawn */
188
  /* iterate over lines and redraw whatever needs to be redrawn */
180
  for (; l != NULL; l = l->next, y++) {
189
  for (; l != NULL; l = l->next, y++) {
181
 
190
 
182
    /* skip lines that do not need to be refreshed */
191
    /* skip lines that do not need to be refreshed */
183
    if (y < uidirtyfrom) continue;
192
    if (y < uidirtyfrom) continue;
184
    if (y > uidirtyto) break;
193
    if (y > uidirtyto) break;
185
 
194
 
186
    if (db->xoffset < l->len) {
195
    if (db->xoffset < l->len) {
187
      for (len = 0; l->payload[len] != 0; len++) mdr_cout_char(y, len, l->payload[len], scheme[COL_TXT]);
196
      for (len = 0; l->payload[len] != 0; len++) mdr_cout_char(y, len, l->payload[len], scheme[COL_TXT]);
188
    } else {
197
    } else {
189
      len = 0;
198
      len = 0;
190
    }
199
    }
191
    while (len < screenw - 1) mdr_cout_char(y, len++, ' ', scheme[COL_TXT]);
200
    while (len < screenw - 1) mdr_cout_char(y, len++, ' ', scheme[COL_TXT]);
192
 
201
 
193
#ifdef DBG_REFRESH
202
#ifdef DBG_REFRESH
194
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
203
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
195
#endif
204
#endif
196
 
205
 
197
    if (y == screenh - 2) break;
206
    if (y == screenh - 2) break;
198
  }
207
  }
199
 
208
 
200
}
209
}
201
 
210
 
202
 
211
 
203
static void check_cursor_not_after_eol(struct linedb *db, unsigned char *cursorpos, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
212
static void check_cursor_not_after_eol(struct linedb *db, unsigned char *cursorpos, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
204
  if (db->xoffset + *cursorpos <= db->cursor->len) return;
213
  if (db->xoffset + *cursorpos <= db->cursor->len) return;
205
 
214
 
206
  if (db->cursor->len < db->xoffset) {
215
  if (db->cursor->len < db->xoffset) {
207
    *cursorpos = 0;
216
    *cursorpos = 0;
208
    db->xoffset = db->cursor->len;
217
    db->xoffset = db->cursor->len;
209
    *uidirtyfrom = 0;
218
    *uidirtyfrom = 0;
210
    *uidirtyto = 0xff;
219
    *uidirtyto = 0xff;
211
  } else {
220
  } else {
212
    *cursorpos = db->cursor->len - db->xoffset;
221
    *cursorpos = db->cursor->len - db->xoffset;
213
  }
222
  }
214
}
223
}
215
 
224
 
216
 
225
 
217
static void cursor_up(struct linedb *db, unsigned char *cursorposy, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
226
static void cursor_up(struct linedb *db, unsigned char *cursorposy, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
218
  if (db->cursor->prev != NULL) {
227
  if (db->cursor->prev != NULL) {
219
    db->cursor = db->cursor->prev;
228
    db->cursor = db->cursor->prev;
220
    if (*cursorposy == 0) {
229
    if (*cursorposy == 0) {
221
      *uidirtyfrom = 0;
230
      *uidirtyfrom = 0;
222
      *uidirtyto = 0xff;
231
      *uidirtyto = 0xff;
223
    } else {
232
    } else {
224
      *cursorposy -= 1;
233
      *cursorposy -= 1;
225
    }
234
    }
226
  }
235
  }
227
}
236
}
228
 
237
 
229
 
238
 
230
static void cursor_eol(struct linedb *db, unsigned char *cursorposx, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
239
static void cursor_eol(struct linedb *db, unsigned char *cursorposx, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
231
  /* adjust xoffset to make sure eol is visible on screen */
240
  /* adjust xoffset to make sure eol is visible on screen */
232
  if (db->xoffset > db->cursor->len) {
241
  if (db->xoffset > db->cursor->len) {
233
    db->xoffset = db->cursor->len - 1;
242
    db->xoffset = db->cursor->len - 1;
234
    *uidirtyfrom = 0;
243
    *uidirtyfrom = 0;
235
    *uidirtyto = 0xff;
244
    *uidirtyto = 0xff;
236
  }
245
  }
237
 
246
 
238
  if (db->xoffset + screenw - 1 <= db->cursor->len) {
247
  if (db->xoffset + screenw - 1 <= db->cursor->len) {
239
    db->xoffset = db->cursor->len - screenw + 2;
248
    db->xoffset = db->cursor->len - screenw + 2;
240
    *uidirtyfrom = 0;
249
    *uidirtyfrom = 0;
241
    *uidirtyto = 0xff;
250
    *uidirtyto = 0xff;
242
  }
251
  }
243
  *cursorposx = db->cursor->len - db->xoffset;
252
  *cursorposx = db->cursor->len - db->xoffset;
244
}
253
}
245
 
254
 
246
 
255
 
247
static void cursor_down(struct linedb *db, unsigned char *cursorposy, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
256
static void cursor_down(struct linedb *db, unsigned char *cursorposy, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
248
  if (db->cursor->next != NULL) {
257
  if (db->cursor->next != NULL) {
249
    db->cursor = db->cursor->next;
258
    db->cursor = db->cursor->next;
250
    if (*cursorposy < screenh - 2) {
259
    if (*cursorposy < screenh - 2) {
251
      *cursorposy += 1;
260
      *cursorposy += 1;
252
    } else {
261
    } else {
253
      *uidirtyfrom = 0;
262
      *uidirtyfrom = 0;
254
      *uidirtyto = 0xff;
263
      *uidirtyto = 0xff;
255
    }
264
    }
256
  }
265
  }
257
}
266
}
258
 
267
 
259
 
268
 
260
static void cursor_left(struct linedb *db, unsigned char *cursorposx, unsigned char *cursorposy, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
269
static void cursor_left(struct linedb *db, unsigned char *cursorposx, unsigned char *cursorposy, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
261
  if (*cursorposx > 0) {
270
  if (*cursorposx > 0) {
262
    *cursorposx -= 1;
271
    *cursorposx -= 1;
263
  } else if (db->xoffset > 0) {
272
  } else if (db->xoffset > 0) {
264
    db->xoffset -= 1;
273
    db->xoffset -= 1;
265
    *uidirtyfrom = 0;
274
    *uidirtyfrom = 0;
266
    *uidirtyto = 0xff;
275
    *uidirtyto = 0xff;
267
  } else if (db->cursor->prev != NULL) { /* jump to end of line above */
276
  } else if (db->cursor->prev != NULL) { /* jump to end of line above */
268
    cursor_up(db, cursorposy, uidirtyfrom, uidirtyto);
277
    cursor_up(db, cursorposy, uidirtyfrom, uidirtyto);
269
    cursor_eol(db, cursorposx, screenw, uidirtyfrom, uidirtyto);
278
    cursor_eol(db, cursorposx, screenw, uidirtyfrom, uidirtyto);
270
  }
279
  }
271
}
280
}
272
 
281
 
273
 
282
 
274
static void cursor_home(struct linedb *db, unsigned char *cursorposx, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
283
static void cursor_home(struct linedb *db, unsigned char *cursorposx, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
275
  *cursorposx = 0;
284
  *cursorposx = 0;
276
  if (db->xoffset != 0) {
285
  if (db->xoffset != 0) {
277
    db->xoffset = 0;
286
    db->xoffset = 0;
278
    *uidirtyfrom = 0;
287
    *uidirtyfrom = 0;
279
    *uidirtyto = 0xff;
288
    *uidirtyto = 0xff;
280
  }
289
  }
281
}
290
}
282
 
291
 
283
 
292
 
284
static void cursor_right(struct linedb *db, unsigned char *cursorposx, unsigned char *cursorposy, unsigned char screenw, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
293
static void cursor_right(struct linedb *db, unsigned char *cursorposx, unsigned char *cursorposy, unsigned char screenw, unsigned char screenh, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
285
  if (db->cursor->len > db->xoffset + *cursorposx) {
294
  if (db->cursor->len > db->xoffset + *cursorposx) {
286
    if (*cursorposx < screenw - 2) {
295
    if (*cursorposx < screenw - 2) {
287
      *cursorposx += 1;
296
      *cursorposx += 1;
288
    } else {
297
    } else {
289
      db->xoffset += 1;
298
      db->xoffset += 1;
290
      *uidirtyfrom = 0;
299
      *uidirtyfrom = 0;
291
      *uidirtyto = 0xff;
300
      *uidirtyto = 0xff;
292
    }
301
    }
293
  } else {
302
  } else {
294
    cursor_down(db, cursorposy, screenh, uidirtyfrom, uidirtyto);
303
    cursor_down(db, cursorposy, screenh, uidirtyfrom, uidirtyto);
295
    cursor_home(db, cursorposx, uidirtyfrom, uidirtyto);
304
    cursor_home(db, cursorposx, uidirtyfrom, uidirtyto);
296
  }
305
  }
297
}
306
}
298
 
307
 
299
 
308
 
300
static void del(struct linedb *db, unsigned char cursorposx, unsigned char cursorposy, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
309
static void del(struct linedb *db, unsigned char cursorposx, unsigned char cursorposy, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
301
  if (cursorposx + db->xoffset < db->cursor->len) {
310
  if (cursorposx + db->xoffset < db->cursor->len) {
302
    _fmemmove(db->cursor->payload + cursorposx + db->xoffset, db->cursor->payload + cursorposx + db->xoffset + 1, db->cursor->len - cursorposx - db->xoffset);
311
    _fmemmove(db->cursor->payload + cursorposx + db->xoffset, db->cursor->payload + cursorposx + db->xoffset + 1, db->cursor->len - cursorposx - db->xoffset);
303
    db->cursor->len -= 1; /* do this AFTER memmove so the copy includes the nul terminator */
312
    db->cursor->len -= 1; /* do this AFTER memmove so the copy includes the nul terminator */
304
    *uidirtyfrom = cursorposy;
313
    *uidirtyfrom = cursorposy;
305
    *uidirtyto = cursorposy;
314
    *uidirtyto = cursorposy;
306
  } else if (db->cursor->next != NULL) { /* cursor is at end of line: merge current line with next one (if there is a next one) */
315
  } else if (db->cursor->next != NULL) { /* cursor is at end of line: merge current line with next one (if there is a next one) */
307
    struct line far *nextline = db->cursor->next;
316
    struct line far *nextline = db->cursor->next;
308
    if (db->cursor->next->len > 0) {
317
    if (db->cursor->next->len > 0) {
309
      void far *newptr = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + db->cursor->next->len + 1);
318
      void far *newptr = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + db->cursor->next->len + 1);
310
      if (newptr != NULL) {
319
      if (newptr != NULL) {
311
        db->cursor = newptr;
320
        db->cursor = newptr;
312
        _fmemcpy(db->cursor->payload + db->cursor->len, db->cursor->next->payload, db->cursor->next->len + 1);
321
        _fmemcpy(db->cursor->payload + db->cursor->len, db->cursor->next->payload, db->cursor->next->len + 1);
313
        db->cursor->len += db->cursor->next->len;
322
        db->cursor->len += db->cursor->next->len;
314
      }
323
      }
315
    }
324
    }
316
    db->cursor->next = db->cursor->next->next;
325
    db->cursor->next = db->cursor->next->next;
317
    db->cursor->next->prev = db->cursor;
326
    db->cursor->next->prev = db->cursor;
318
    if (db->cursor->prev != NULL) db->cursor->prev->next = db->cursor; /* in case realloc changed my pointer */
327
    if (db->cursor->prev != NULL) db->cursor->prev->next = db->cursor; /* in case realloc changed my pointer */
319
    _ffree(nextline);
328
    _ffree(nextline);
320
    *uidirtyfrom = cursorposy;
329
    *uidirtyfrom = cursorposy;
321
    *uidirtyto = 0xff;
330
    *uidirtyto = 0xff;
322
  }
331
  }
323
}
332
}
324
 
333
 
325
 
334
 
326
static void bkspc(struct linedb *db, unsigned char *cursorposx, unsigned char *cursorposy, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
335
static void bkspc(struct linedb *db, unsigned char *cursorposx, unsigned char *cursorposy, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
327
 
336
 
328
  /* backspace is basically "left + del", not applicable only if cursor is on 1st byte of the file */
337
  /* backspace is basically "left + del", not applicable only if cursor is on 1st byte of the file */
329
  if ((*cursorposx == 0) && (db->xoffset == 0) && (db->cursor->prev == NULL)) return;
338
  if ((*cursorposx == 0) && (db->xoffset == 0) && (db->cursor->prev == NULL)) return;
330
 
339
 
331
  cursor_left(db, cursorposx, cursorposy, screenw, uidirtyfrom, uidirtyto);
340
  cursor_left(db, cursorposx, cursorposy, screenw, uidirtyfrom, uidirtyto);
332
  del(db, *cursorposx, *cursorposy, uidirtyfrom, uidirtyto);
341
  del(db, *cursorposx, *cursorposy, uidirtyfrom, uidirtyto);
333
}
342
}
334
 
343
 
335
 
344
 
336
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
345
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
337
 * of argc and argv, saves some 330 bytes of binary size */
346
 * of argc and argv, saves some 330 bytes of binary size */
338
static char *parseargv(void) {
347
static char *parseargv(void) {
339
  char *tail = (void *)0x81; /* THIS WORKS ONLY IN SMALL MEMORY MODEL */
348
  char *tail = (void *)0x81; /* THIS WORKS ONLY IN SMALL MEMORY MODEL */
340
  unsigned char count = 0;
349
  unsigned char count = 0;
341
  char *argv[4];
350
  char *argv[4];
342
 
351
 
343
  while (count < 4) {
352
  while (count < 4) {
344
    /* jump to nearest arg */
353
    /* jump to nearest arg */
345
    while (*tail == ' ') {
354
    while (*tail == ' ') {
346
      *tail = 0;
355
      *tail = 0;
347
      tail++;
356
      tail++;
348
    }
357
    }
349
 
358
 
350
    if (*tail == '\r') {
359
    if (*tail == '\r') {
351
      *tail = 0;
360
      *tail = 0;
352
      break;
361
      break;
353
    }
362
    }
354
 
363
 
355
    argv[count++] = tail;
364
    argv[count++] = tail;
356
 
365
 
357
    /* jump to next delimiter */
366
    /* jump to next delimiter */
358
    while ((*tail != ' ') && (*tail != '\r')) tail++;
367
    while ((*tail != ' ') && (*tail != '\r')) tail++;
359
  }
368
  }
360
 
369
 
361
  /* check args now */
370
  /* check args now */
362
  if (count != 1) return(NULL);
371
  if (count != 1) return(NULL);
363
 
372
 
364
  return(argv[0]);
373
  return(argv[0]);
365
}
374
}
366
 
375
 
367
 
376
 
368
static int loadfile(struct linedb *db, const char *fname) {
377
static int loadfile(struct linedb *db, const char *fname) {
369
  char buff[1024];
378
  char buff[1024];
370
  unsigned int prevlen = 0, len, llen;
379
  unsigned int prevlen = 0, len, llen;
371
  int fd;
380
  int fd;
372
  int r = 0;
381
  int r = 0;
373
 
382
 
374
  if (_dos_open(fname, O_RDONLY, &fd) != 0) {
383
  if (_dos_open(fname, O_RDONLY, &fd) != 0) {
375
    mdr_coutraw_puts("Failed to open file:");
384
    mdr_coutraw_puts("Failed to open file:");
376
    mdr_coutraw_puts(fname);
385
    mdr_coutraw_puts(fname);
377
    return(-1);
386
    return(-1);
378
  }
387
  }
379
 
388
 
-
 
389
  db->lfonly = 1;
-
 
390
 
380
  do {
391
  do {
381
    if (_dos_read(fd, buff + prevlen, sizeof(buff) - prevlen, &len) == 0) {
392
    if (_dos_read(fd, buff + prevlen, sizeof(buff) - prevlen, &len) == 0) {
382
      len += prevlen;
393
      len += prevlen;
383
    } else {
394
    } else {
384
      len = prevlen;
395
      len = prevlen;
385
    }
396
    }
386
 
397
 
387
    /* look for nearest \n and replace with 0*/
398
    /* look for nearest \n and replace with 0*/
388
    for (llen = 0; buff[llen] != '\n'; llen++) {
399
    for (llen = 0; buff[llen] != '\n'; llen++) {
389
      if (llen == sizeof(buff)) break;
400
      if (llen == sizeof(buff)) break;
390
    }
401
    }
391
    buff[llen] = 0;
402
    buff[llen] = 0;
-
 
403
    if ((llen > 0) && (buff[llen - 1] == '\r')) {
392
    if ((llen > 0) && (buff[llen - 1])) buff[llen - 1] = 0; /* trim \r if line ending is cr/lf */
404
      buff[llen - 1] = 0; /* trim \r if line ending is cr/lf */
-
 
405
      db->lfonly = 0;
-
 
406
    }
393
    if (line_add(db, buff) != 0) {
407
    if (line_add(db, buff) != 0) {
394
      mdr_coutraw_puts("out of memory");
408
      mdr_coutraw_puts("out of memory");
395
      r = -1;
409
      r = -1;
396
      break;
410
      break;
397
    }
411
    }
398
 
412
 
399
    len -= llen + 1;
413
    len -= llen + 1;
400
    memmove(buff, buff + llen + 1, len);
414
    memmove(buff, buff + llen + 1, len);
401
    prevlen = len;
415
    prevlen = len;
402
  } while (len > 0);
416
  } while (len > 0);
403
 
417
 
404
  _dos_close(fd);
418
  _dos_close(fd);
405
 
419
 
406
  return(r);
420
  return(r);
407
}
421
}
408
 
422
 
409
 
423
 
410
static int savefile(const struct linedb *db, const char *fname) {
424
static int savefile(const struct linedb *db, const char *fname) {
411
  int fd;
425
  int fd;
412
  const struct line far *l;
426
  const struct line far *l;
413
  unsigned bytes;
427
  unsigned bytes;
-
 
428
  unsigned char eollen;
-
 
429
  unsigned char eolbuf[2];
-
 
430
 
414
  if (_dos_open(fname, O_WRONLY, &fd) != 0) {
431
  if (_dos_open(fname, O_WRONLY, &fd) != 0) {
415
    return(-1);
432
    return(-1);
416
  }
433
  }
417
 
434
 
418
  l = db->cursor;
435
  l = db->cursor;
419
  while (l->prev) l = l->prev;
436
  while (l->prev) l = l->prev;
420
 
437
 
-
 
438
  /* preset line terminators */
-
 
439
  if (db->lfonly) {
-
 
440
    eolbuf[0] = '\n';
-
 
441
    eollen = 1;
-
 
442
  } else {
-
 
443
    eolbuf[0] = '\r';
-
 
444
    eolbuf[1] = '\n';
-
 
445
    eollen = 2;
-
 
446
  }
-
 
447
 
421
  while (l) {
448
  while (l) {
422
    _dos_write(fd, l->payload, l->len, &bytes);
449
    _dos_write(fd, l->payload, l->len, &bytes);
423
    _dos_write(fd, "\r\n", 2, &bytes);
450
    _dos_write(fd, eolbuf, eollen, &bytes);
424
    l = l->next;
451
    l = l->next;
425
  }
452
  }
426
 
453
 
427
  _dos_close(fd);
454
  _dos_close(fd);
428
  return(0);
455
  return(0);
429
}
456
}
430
 
457
 
431
 
458
 
432
int main(void) {
459
int main(void) {
433
  const char *fname;
460
  const char *fname;
434
  struct linedb db;
461
  struct linedb db;
435
  unsigned char screenw = 0, screenh = 0;
462
  unsigned char screenw = 0, screenh = 0;
436
  unsigned char cursorposx = 0, cursorposy = 0;
463
  unsigned char cursorposx = 0, cursorposy = 0;
437
  unsigned char uidirtyfrom = 0, uidirtyto = 0xff; /* make sure to redraw entire UI at first run */
464
  unsigned char uidirtyfrom = 0, uidirtyto = 0xff; /* make sure to redraw entire UI at first run */
438
 
465
 
439
  bzero(&db, sizeof(db));
466
  bzero(&db, sizeof(db));
440
 
467
 
441
  {
468
  {
442
    char nlspath[128], lang[8];
469
    char nlspath[128], lang[8];
443
    svarlang_autoload_pathlist("sved", mdr_dos_getenv(nlspath, "NLSPATH", sizeof(nlspath)), mdr_dos_getenv(lang, "LANG", sizeof(lang)));
470
    svarlang_autoload_pathlist("sved", mdr_dos_getenv(nlspath, "NLSPATH", sizeof(nlspath)), mdr_dos_getenv(lang, "LANG", sizeof(lang)));
444
  }
471
  }
445
 
472
 
446
  fname = parseargv();
473
  fname = parseargv();
447
 
474
 
448
  if (fname == NULL) {
475
  if (fname == NULL) {
449
    mdr_coutraw_puts(svarlang_str(1,0)); /* usage: sved file.txt */
476
    mdr_coutraw_puts(svarlang_str(1,0)); /* usage: sved file.txt */
450
    return(0);
477
    return(0);
451
  }
478
  }
452
 
479
 
453
  /* load file */
480
  /* load file */
454
  if (loadfile(&db, fname) != 0) return(1);
481
  if (loadfile(&db, fname) != 0) return(1);
455
 
482
 
456
  /* add an empty line at end if not present already */
483
  /* add an empty line at end if not present already */
457
  if (db.cursor->len != 0) line_add(&db, "");
484
  if (db.cursor->len != 0) line_add(&db, "");
458
 
485
 
459
  if (mdr_cout_init(&screenw, &screenh)) load_colorscheme();
486
  if (mdr_cout_init(&screenw, &screenh)) load_colorscheme();
460
  ui_basic(screenw, screenh, fname);
487
  ui_basic(screenw, screenh, fname, &db);
461
 
488
 
462
  db_rewind(&db);
489
  db_rewind(&db);
463
 
490
 
464
  for (;;) {
491
  for (;;) {
465
    int k;
492
    int k;
466
 
493
 
467
    check_cursor_not_after_eol(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
494
    check_cursor_not_after_eol(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
468
    mdr_cout_locate(cursorposy, cursorposx);
495
    mdr_cout_locate(cursorposy, cursorposx);
469
 
496
 
470
    if (uidirtyfrom != 0xff) {
497
    if (uidirtyfrom != 0xff) {
471
      ui_refresh(&db, screenw, screenh, uidirtyfrom, uidirtyto, cursorposy);
498
      ui_refresh(&db, screenw, screenh, uidirtyfrom, uidirtyto, cursorposy);
472
      uidirtyfrom = 0xff;
499
      uidirtyfrom = 0xff;
473
    }
500
    }
474
 
501
 
475
    k = keyb_getkey();
502
    k = keyb_getkey();
476
 
503
 
477
    if (k == 0x150) { /* down */
504
    if (k == 0x150) { /* down */
478
      cursor_down(&db, &cursorposy, screenh, &uidirtyfrom, &uidirtyto);
505
      cursor_down(&db, &cursorposy, screenh, &uidirtyfrom, &uidirtyto);
479
 
506
 
480
    } else if (k == 0x148) { /* up */
507
    } else if (k == 0x148) { /* up */
481
      cursor_up(&db, &cursorposy, &uidirtyfrom, &uidirtyto);
508
      cursor_up(&db, &cursorposy, &uidirtyfrom, &uidirtyto);
482
 
509
 
483
    } else if (k == 0x14D) { /* right */
510
    } else if (k == 0x14D) { /* right */
484
      cursor_right(&db, &cursorposx, &cursorposy, screenw, screenh, &uidirtyfrom, &uidirtyto);
511
      cursor_right(&db, &cursorposx, &cursorposy, screenw, screenh, &uidirtyfrom, &uidirtyto);
485
 
512
 
486
    } else if (k == 0x14B) { /* left */
513
    } else if (k == 0x14B) { /* left */
487
      cursor_left(&db, &cursorposx, &cursorposy, screenw, &uidirtyfrom, &uidirtyto);
514
      cursor_left(&db, &cursorposx, &cursorposy, screenw, &uidirtyfrom, &uidirtyto);
488
 
515
 
489
    } else if (k == 0x149) { /* pgup */
516
    } else if (k == 0x149) { /* pgup */
490
      // TODO
517
      // TODO
491
 
518
 
492
    } else if (k == 0x151) { /* pgdown */
519
    } else if (k == 0x151) { /* pgdown */
493
      // TODO
520
      // TODO
494
 
521
 
495
    } else if (k == 0x147) { /* home */
522
    } else if (k == 0x147) { /* home */
496
       cursor_home(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
523
       cursor_home(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
497
 
524
 
498
    } else if (k == 0x14F) { /* end */
525
    } else if (k == 0x14F) { /* end */
499
       cursor_eol(&db, &cursorposx, screenw, &uidirtyfrom, &uidirtyto);
526
       cursor_eol(&db, &cursorposx, screenw, &uidirtyfrom, &uidirtyto);
500
 
527
 
501
    } else if (k == 0x1B) { /* ESC */
528
    } else if (k == 0x1B) { /* ESC */
502
      break;
529
      break;
503
 
530
 
504
    } else if (k == 0x0D) { /* ENTER */
531
    } else if (k == 0x0D) { /* ENTER */
505
      /* add a new line */
532
      /* add a new line */
506
      if (line_add(&db, db.cursor->payload + db.xoffset + cursorposx) == 0) {
533
      if (line_add(&db, db.cursor->payload + db.xoffset + cursorposx) == 0) {
507
        /* trim the line above */
534
        /* trim the line above */
508
        db.cursor->prev->len = db.xoffset + cursorposx;
535
        db.cursor->prev->len = db.xoffset + cursorposx;
509
        db.cursor->prev->payload[db.cursor->prev->len] = 0;
536
        db.cursor->prev->payload[db.cursor->prev->len] = 0;
510
        /* move cursor to the (new) line below */
537
        /* move cursor to the (new) line below */
511
        cursorposx = 0;
538
        cursorposx = 0;
512
        if (cursorposy < screenh - 2) {
539
        if (cursorposy < screenh - 2) {
513
          uidirtyfrom = cursorposy;
540
          uidirtyfrom = cursorposy;
514
          cursorposy++;
541
          cursorposy++;
515
        } else {
542
        } else {
516
          uidirtyfrom = 0;
543
          uidirtyfrom = 0;
517
        }
544
        }
518
        uidirtyto = 0xff;
545
        uidirtyto = 0xff;
519
      } else {
546
      } else {
520
        /* ERROR: OUT OF MEMORY */
547
        /* ERROR: OUT OF MEMORY */
521
      }
548
      }
522
 
549
 
523
    } else if (k == 0x153) {  /* DEL */
550
    } else if (k == 0x153) {  /* DEL */
524
      del(&db, cursorposx, cursorposy, &uidirtyfrom, &uidirtyto);
551
      del(&db, cursorposx, cursorposy, &uidirtyfrom, &uidirtyto);
525
 
552
 
526
    } else if (k == 0x008) { /* BKSPC */
553
    } else if (k == 0x008) { /* BKSPC */
527
      bkspc(&db, &cursorposx, &cursorposy, screenw, &uidirtyfrom, &uidirtyto);
554
      bkspc(&db, &cursorposx, &cursorposy, screenw, &uidirtyfrom, &uidirtyto);
528
 
555
 
529
    } else if ((k >= 0x20) && (k <= 0xff)) { /* "normal" character */
556
    } else if ((k >= 0x20) && (k <= 0xff)) { /* "normal" character */
530
      struct line far *n;
557
      struct line far *n;
531
      n = _frealloc(db.cursor, sizeof(struct line) + db.cursor->len);
558
      n = _frealloc(db.cursor, sizeof(struct line) + db.cursor->len);
532
      if (n != NULL) {
559
      if (n != NULL) {
533
        unsigned short off = db.xoffset + cursorposx;
560
        unsigned short off = db.xoffset + cursorposx;
534
        if (n->prev) n->prev->next = n;
561
        if (n->prev) n->prev->next = n;
535
        if (n->next) n->next->prev = n;
562
        if (n->next) n->next->prev = n;
536
        db.cursor = n;
563
        db.cursor = n;
537
        _fmemmove(db.cursor->payload + off + 1, db.cursor->payload + off, db.cursor->len - off + 1);
564
        _fmemmove(db.cursor->payload + off + 1, db.cursor->payload + off, db.cursor->len - off + 1);
538
        db.cursor->len += 1;
565
        db.cursor->len += 1;
539
        uidirtyfrom = cursorposy;
566
        uidirtyfrom = cursorposy;
540
        uidirtyto = cursorposy;
567
        uidirtyto = cursorposy;
541
        db.cursor->payload[off] = k;
568
        db.cursor->payload[off] = k;
542
        cursor_right(&db, &cursorposx, &cursorposy, screenw, screenh, &uidirtyfrom, &uidirtyto);
569
        cursor_right(&db, &cursorposx, &cursorposy, screenw, screenh, &uidirtyfrom, &uidirtyto);
543
      }
570
      }
544
 
571
 
545
    } else if (k == 0x13b) { /* F1 */
572
    } else if (k == 0x13b) { /* F1 */
546
      ui_help(screenw);
573
      ui_help(screenw);
547
      uidirtyfrom = 0;
574
      uidirtyfrom = 0;
548
      uidirtyto = 0xff;
575
      uidirtyto = 0xff;
549
 
576
 
550
    } else if (k == 0x13f) { /* F5 */
577
    } else if (k == 0x13f) { /* F5 */
551
      const char *m[] = {"SAVED", "SAVING FILE FAILED"};
578
      const char *m[] = {"SAVED", "SAVING FILE FAILED"};
552
      int i;
579
      int i;
553
      i = !!savefile(&db, fname);
580
      i = !!savefile(&db, fname);
554
      ui_msg(m[i], screenw, screenh, &uidirtyfrom, &uidirtyto);
581
      ui_msg(m[i], screenw, screenh, &uidirtyfrom, &uidirtyto);
555
      mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
582
      mdr_bios_tickswait(11); /* 11 ticks is about 600 ms */
556
 
583
 
557
    } else { /* UNHANDLED KEY - TODO IGNORE THIS IN PRODUCTION RELEASE */
584
    } else { /* UNHANDLED KEY - TODO IGNORE THIS IN PRODUCTION RELEASE */
558
      char buff[4];
585
      char buff[4];
559
      const char *HEX = "0123456789ABCDEF";
586
      const char *HEX = "0123456789ABCDEF";
560
      buff[0] = HEX[(k >> 8) & 15];
587
      buff[0] = HEX[(k >> 8) & 15];
561
      buff[1] = HEX[(k >> 4) & 15];
588
      buff[1] = HEX[(k >> 4) & 15];
562
      buff[2] = HEX[k & 15];
589
      buff[2] = HEX[k & 15];
563
      mdr_cout_str(screenh - 1, 0, "UNHANDLED KEY: 0x", scheme[COL_STATUSBAR1], 17);
590
      mdr_cout_str(screenh - 1, 0, "UNHANDLED KEY: 0x", scheme[COL_STATUSBAR1], 17);
564
      mdr_cout_str(screenh - 1, 17, buff, scheme[COL_STATUSBAR1], 3);
591
      mdr_cout_str(screenh - 1, 17, buff, scheme[COL_STATUSBAR1], 3);
565
      keyb_getkey();
592
      keyb_getkey();
566
      break;
593
      break;
567
    }
594
    }
568
  }
595
  }
569
 
596
 
570
  mdr_cout_close();
597
  mdr_cout_close();
571
 
598
 
572
  /* TODO free memory */
599
  /* TODO free memory */
573
 
600
 
574
  return(0);
601
  return(0);
575
}
602
}
576
 
603