Subversion Repositories SvarDOS

Rev

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

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