Subversion Repositories SvarDOS

Rev

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

Rev 1309 Rev 1310
Line 51... Line 51...
51
  unsigned short len;
51
  unsigned short len;
52
  char payload[1];
52
  char payload[1];
53
};
53
};
54
 
54
 
55
struct linedb {
55
struct linedb {
56
  struct line far *topscreen;
-
 
57
  struct line far *cursor;
56
  struct line far *cursor;
58
  unsigned short xoffset;
57
  unsigned short xoffset;
59
};
58
};
60
 
59
 
61
 
60
 
Line 92... Line 91...
92
 
91
 
93
 
92
 
94
static void db_rewind(struct linedb *db) {
93
static void db_rewind(struct linedb *db) {
95
  if (db->cursor == NULL) return;
94
  if (db->cursor == NULL) return;
96
  while (db->cursor->prev) db->cursor = db->cursor->prev;
95
  while (db->cursor->prev) db->cursor = db->cursor->prev;
97
  db->topscreen = db->cursor;
-
 
98
}
96
}
99
 
97
 
100
 
98
 
101
static void load_colorscheme(void) {
99
static void load_colorscheme(void) {
102
  scheme[COL_TXT] = 0x17;
100
  scheme[COL_TXT] = 0x17;
Line 149... Line 147...
149
  mdr_cout_cursor_show();
147
  mdr_cout_cursor_show();
150
#undef MAXLINLEN
148
#undef MAXLINLEN
151
}
149
}
152
 
150
 
153
 
151
 
154
static void ui_refresh(const struct linedb *db, unsigned char screenw, unsigned char screenh, unsigned char uidirtyfrom, unsigned char uidirtyto) {
152
static void ui_refresh(const struct linedb *db, unsigned char screenw, unsigned char screenh, unsigned char uidirtyfrom, unsigned char uidirtyto, unsigned char y) {
155
  unsigned char y = 0;
-
 
156
  unsigned char len;
153
  unsigned char len;
157
  struct line far *l;
154
  const struct line far *l;
158
 
155
 
159
#ifdef DBG_REFRESH
156
#ifdef DBG_REFRESH
160
  static char m = 'a';
157
  static char m = 'a';
161
  m++;
158
  m++;
162
  if (m > 'z') m = 'a';
159
  if (m > 'z') m = 'a';
163
#endif
160
#endif
164
 
161
 
-
 
162
  /* rewind cursor line to first line that needs redrawing */
-
 
163
  for (l = db->cursor; y > uidirtyfrom; y--) l = l->prev;
-
 
164
 
-
 
165
  /* iterate over lines and redraw whatever needs to be redrawn */
165
  for (l = db->topscreen; l != NULL; l = l->next, y++) {
166
  for (; l != NULL; l = l->next, y++) {
166
 
167
 
167
    /* skip lines that do not to be refreshed */
168
    /* skip lines that do not need to be refreshed */
168
    if (y < uidirtyfrom) continue;
169
    if (y < uidirtyfrom) continue;
169
    if (y > uidirtyto) break;
170
    if (y > uidirtyto) break;
170
 
171
 
171
    if (db->xoffset < l->len) {
172
    if (db->xoffset < l->len) {
172
      for (len = 0; l->payload[len] != 0; len++) mdr_cout_char(y, len, l->payload[len], scheme[COL_TXT]);
173
      for (len = 0; l->payload[len] != 0; len++) mdr_cout_char(y, len, l->payload[len], scheme[COL_TXT]);
Line 179... Line 180...
179
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
180
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
180
#endif
181
#endif
181
 
182
 
182
    if (y == screenh - 2) break;
183
    if (y == screenh - 2) break;
183
  }
184
  }
-
 
185
 
184
}
186
}
185
 
187
 
186
 
188
 
187
static void check_cursor_not_after_eol(struct linedb *db, unsigned char *cursorpos, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
189
static void check_cursor_not_after_eol(struct linedb *db, unsigned char *cursorpos, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
188
  if (db->xoffset + *cursorpos <= db->cursor->len) return;
190
  if (db->xoffset + *cursorpos <= db->cursor->len) return;
Line 200... Line 202...
200
 
202
 
201
static void cursor_up(struct linedb *db, unsigned char *cursorposy, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
203
static void cursor_up(struct linedb *db, unsigned char *cursorposy, unsigned char *uidirtyfrom, unsigned char *uidirtyto) {
202
  if (db->cursor->prev != NULL) {
204
  if (db->cursor->prev != NULL) {
203
    db->cursor = db->cursor->prev;
205
    db->cursor = db->cursor->prev;
204
    if (*cursorposy == 0) {
206
    if (*cursorposy == 0) {
205
      db->topscreen = db->cursor;
-
 
206
      *uidirtyfrom = 0;
207
      *uidirtyfrom = 0;
207
      *uidirtyto = 0xff;
208
      *uidirtyto = 0xff;
208
    } else {
209
    } else {
209
      *cursorposy -= 1;
210
      *cursorposy -= 1;
210
    }
211
    }
Line 233... Line 234...
233
  if (db->cursor->next != NULL) {
234
  if (db->cursor->next != NULL) {
234
    db->cursor = db->cursor->next;
235
    db->cursor = db->cursor->next;
235
    if (*cursorposy < screenh - 2) {
236
    if (*cursorposy < screenh - 2) {
236
      *cursorposy += 1;
237
      *cursorposy += 1;
237
    } else {
238
    } else {
238
      db->topscreen = db->topscreen->next;
-
 
239
      *uidirtyfrom = 0;
239
      *uidirtyfrom = 0;
240
      *uidirtyto = 0xff;
240
      *uidirtyto = 0xff;
241
    }
241
    }
242
  }
242
  }
243
}
243
}
Line 295... Line 295...
295
      void far *newptr = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + db->cursor->next->len + 1);
295
      void far *newptr = _frealloc(db->cursor, sizeof(struct line) + db->cursor->len + db->cursor->next->len + 1);
296
      if (newptr != NULL) {
296
      if (newptr != NULL) {
297
        db->cursor = newptr;
297
        db->cursor = newptr;
298
        _fmemcpy(db->cursor->payload + db->cursor->len, db->cursor->next->payload, db->cursor->next->len + 1);
298
        _fmemcpy(db->cursor->payload + db->cursor->len, db->cursor->next->payload, db->cursor->next->len + 1);
299
        db->cursor->len += db->cursor->next->len;
299
        db->cursor->len += db->cursor->next->len;
300
        /* update db->topscreen if needed */
-
 
301
        if (cursorposy == 0) db->topscreen = db->cursor;
-
 
302
      }
300
      }
303
    }
301
    }
304
    db->cursor->next = db->cursor->next->next;
302
    db->cursor->next = db->cursor->next->next;
305
    db->cursor->next->prev = db->cursor;
303
    db->cursor->next->prev = db->cursor;
306
    if (db->cursor->prev != NULL) db->cursor->prev->next = db->cursor; /* in case realloc changed my pointer */
304
    if (db->cursor->prev != NULL) db->cursor->prev->next = db->cursor; /* in case realloc changed my pointer */
Line 432... Line 430...
432
 
430
 
433
    check_cursor_not_after_eol(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
431
    check_cursor_not_after_eol(&db, &cursorposx, &uidirtyfrom, &uidirtyto);
434
    mdr_cout_locate(cursorposy, cursorposx);
432
    mdr_cout_locate(cursorposy, cursorposx);
435
 
433
 
436
    if (uidirtyfrom != 0xff) {
434
    if (uidirtyfrom != 0xff) {
437
      ui_refresh(&db, screenw, screenh, uidirtyfrom, uidirtyto);
435
      ui_refresh(&db, screenw, screenh, uidirtyfrom, uidirtyto, cursorposy);
438
      uidirtyfrom = 0xff;
436
      uidirtyfrom = 0xff;
439
    }
437
    }
440
 
438
 
441
    k = keyb_getkey();
439
    k = keyb_getkey();
442
 
440
 
Line 477... Line 475...
477
        cursorposx = 0;
475
        cursorposx = 0;
478
        if (cursorposy < screenh - 2) {
476
        if (cursorposy < screenh - 2) {
479
          uidirtyfrom = cursorposy;
477
          uidirtyfrom = cursorposy;
480
          cursorposy++;
478
          cursorposy++;
481
        } else {
479
        } else {
482
          db.topscreen = db.topscreen->next;
-
 
483
          uidirtyfrom = 0;
480
          uidirtyfrom = 0;
484
        }
481
        }
485
        uidirtyto = 0xff;
482
        uidirtyto = 0xff;
486
      } else {
483
      } else {
487
        /* ERROR: OUT OF MEMORY */
484
        /* ERROR: OUT OF MEMORY */
Line 498... Line 495...
498
      n = _frealloc(db.cursor, sizeof(struct line) + db.cursor->len);
495
      n = _frealloc(db.cursor, sizeof(struct line) + db.cursor->len);
499
      if (n != NULL) {
496
      if (n != NULL) {
500
        unsigned short off = db.xoffset + cursorposx;
497
        unsigned short off = db.xoffset + cursorposx;
501
        if (n->prev) n->prev->next = n;
498
        if (n->prev) n->prev->next = n;
502
        if (n->next) n->next->prev = n;
499
        if (n->next) n->next->prev = n;
503
        if (db.topscreen == db.cursor) db.topscreen = n;
-
 
504
        db.cursor = n;
500
        db.cursor = n;
505
        _fmemmove(db.cursor->payload + off + 1, db.cursor->payload + off, db.cursor->len - off + 1);
501
        _fmemmove(db.cursor->payload + off + 1, db.cursor->payload + off, db.cursor->len - off + 1);
506
        db.cursor->len += 1;
502
        db.cursor->len += 1;
507
        uidirtyfrom = cursorposy;
503
        uidirtyfrom = cursorposy;
508
        uidirtyto = cursorposy;
504
        uidirtyto = cursorposy;