Subversion Repositories SvarDOS

Rev

Rev 1292 | Rev 1307 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1292 Rev 1302
Line 105... Line 105...
105
}
105
}
106
 
106
 
107
 
107
 
108
static void ui_basic(unsigned char screenw, unsigned char screenh, const char *fname) {
108
static void ui_basic(unsigned char screenw, unsigned char screenh, const char *fname) {
109
  unsigned char i;
109
  unsigned char i;
110
  const char *s = "HELP";
110
  const char *s = svarlang_strid(0); /* HELP */
111
  unsigned char helpcol = screenw - (strlen(s) + 4);
111
  unsigned char helpcol = screenw - (strlen(s) + 4);
112
 
112
 
113
  /* clear screen */
113
  /* clear screen */
114
  mdr_cout_cls(scheme[COL_TXT]);
114
  mdr_cout_cls(scheme[COL_TXT]);
115
 
115
 
Line 218... Line 218...
218
    }
218
    }
219
  }
219
  }
220
}
220
}
221
 
221
 
222
 
222
 
-
 
223
static void cursor_left(struct linedb *db, unsigned char *cursorposx, unsigned char *cursorposy, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
-
 
224
  if (*cursorposx > 0) {
-
 
225
    *cursorposx -= 1;
-
 
226
  } else if (db->xoffset > 0) {
-
 
227
    db->xoffset -= 1;
-
 
228
    *uidirtyfrom = 0;
-
 
229
    *uidirtyto = 0xff;
-
 
230
  } else if (db->cursor->prev != NULL) { /* jump to end of line above */
-
 
231
    cursor_up(db, cursorposy, uidirtyfrom, uidirtyto);
-
 
232
    cursor_eol(db, cursorposx, screenw, uidirtyfrom, uidirtyto);
-
 
233
  }
-
 
234
}
-
 
235
 
-
 
236
 
223
static void cursor_home(struct linedb *db, unsigned char *cursorposx, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
237
static void cursor_home(struct linedb *db, unsigned char *cursorposx, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
224
  *cursorposx = 0;
238
  *cursorposx = 0;
225
  if (db->xoffset != 0) {
239
  if (db->xoffset != 0) {
226
    db->xoffset = 0;
240
    db->xoffset = 0;
227
    *uidirtyfrom = 0;
241
    *uidirtyfrom = 0;
Line 256... Line 270...
256
    *uidirtyto = 0xff;
270
    *uidirtyto = 0xff;
257
  }
271
  }
258
}
272
}
259
 
273
 
260
 
274
 
-
 
275
static void bkspc(struct linedb *db, unsigned char *cursorposx, unsigned char *cursorposy, unsigned char screenw, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
-
 
276
 
-
 
277
  /* backspace is basically "left + del", not applicable only if cursor is on 1st byte of the file */
-
 
278
  if ((*cursorposx == 0) && (db->xoffset == 0) && (db->cursor->prev == NULL)) return;
-
 
279
 
-
 
280
  cursor_left(db, cursorposx, cursorposy, screenw, uidirtyfrom, uidirtyto);
-
 
281
  del(db, *cursorposx, *cursorposy, uidirtyfrom, uidirtyto);
-
 
282
}
-
 
283
 
-
 
284
 
261
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
285
/* a custom argv-parsing routine that looks directly inside the PSP, avoids the need
262
 * of argc and argv, saves some 330 bytes of binary size */
286
 * of argc and argv, saves some 330 bytes of binary size */
263
static char *parseargv(void) {
287
static char *parseargv(void) {
264
  char *tail = (void *)0x81; /* THIS WORKS ONLY IN SMALL MEMORY MODEL */
288
  char *tail = (void *)0x81; /* THIS WORKS ONLY IN SMALL MEMORY MODEL */
265
  unsigned char count = 0;
289
  unsigned char count = 0;
Line 344... Line 368...
344
  svarlang_autoload_nlspath("sved");
368
  svarlang_autoload_nlspath("sved");
345
 
369
 
346
  fname = parseargv();
370
  fname = parseargv();
347
 
371
 
348
  if (fname == NULL) {
372
  if (fname == NULL) {
349
    mdr_coutraw_puts("usage: sved file.txt");
373
    mdr_coutraw_puts(svarlang_str(1,0)); /* usage: sved file.txt */
350
    return(0);
374
    return(0);
351
  }
375
  }
352
 
376
 
353
  /* load file */
377
  /* load file */
354
  if (loadfile(&db, fname) != 0) return(1);
378
  if (loadfile(&db, fname) != 0) return(1);
Line 393... Line 417...
393
        cursor_down(&db, &cursorposy, screenh, &uidirtyfrom, &uidirtyto);
417
        cursor_down(&db, &cursorposy, screenh, &uidirtyfrom, &uidirtyto);
394
        cursor_home(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
418
        cursor_home(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
395
      }
419
      }
396
 
420
 
397
    } else if (k == 0x14B) { /* left */
421
    } else if (k == 0x14B) { /* left */
398
      if (cursorposx > 0) {
-
 
399
        cursorposx--;
-
 
400
      } else if (db.xoffset > 0) {
-
 
401
        db.xoffset--;
-
 
402
        uidirtyfrom = 0;
-
 
403
        uidirtyto = 0xff;
-
 
404
      } else if (db.cursor->prev != NULL) { /* jump to end of line above */
-
 
405
        cursor_up(&db, &cursorposy, &uidirtyfrom, &uidirtyto);
-
 
406
        cursor_eol(&db, &cursorposx, screenw, &uidirtyfrom, &uidirtyto);
422
      cursor_left(&db, &cursorposx, &cursorposy, screenw, &uidirtyfrom, &uidirtyto);
407
      }
-
 
408
 
423
 
409
    } else if (k == 0x149) { /* pgup */
424
    } else if (k == 0x149) { /* pgup */
410
      // TODO
425
      // TODO
411
 
426
 
412
    } else if (k == 0x151) { /* pgdown */
427
    } else if (k == 0x151) { /* pgdown */
Line 442... Line 457...
442
      }
457
      }
443
 
458
 
444
    } else if (k == 0x153) {  /* DEL */
459
    } else if (k == 0x153) {  /* DEL */
445
      del(&db, cursorposx, cursorposy, &uidirtyfrom, &uidirtyto);
460
      del(&db, cursorposx, cursorposy, &uidirtyfrom, &uidirtyto);
446
 
461
 
-
 
462
    } else if (k == 0x008) { /* BKSPC */
-
 
463
      bkspc(&db, &cursorposx, &cursorposy, screenw, &uidirtyfrom, &uidirtyto);
-
 
464
 
447
    } else { /* UNHANDLED KEY - TODO IGNORE THIS IN PRODUCTION RELEASE */
465
    } else { /* UNHANDLED KEY - TODO IGNORE THIS IN PRODUCTION RELEASE */
448
      char buff[4];
466
      char buff[4];
449
      const char *HEX = "0123456789ABCDEF";
467
      const char *HEX = "0123456789ABCDEF";
450
      buff[0] = HEX[(k >> 8) & 15];
468
      buff[0] = HEX[(k >> 8) & 15];
451
      buff[1] = HEX[(k >> 4) & 15];
469
      buff[1] = HEX[(k >> 4) & 15];