Subversion Repositories SvarDOS

Rev

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

Rev 1287 Rev 1288
Line 25... Line 25...
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
 
31
 
31
#include "mdr\cout.h"
32
#include "mdr\cout.h"
32
#include "mdr\keyb.h"
33
#include "mdr\keyb.h"
33
 
34
 
34
#include "svarlang\svarlang.h"
35
#include "svarlang\svarlang.h"
Line 42... Line 43...
42
 
43
 
43
#define SCROLL_CURSOR 0xB1
44
#define SCROLL_CURSOR 0xB1
44
 
45
 
45
 
46
 
46
struct line {
47
struct line {
47
  struct line *prev;
48
  struct line far *prev;
48
  struct line *next;
49
  struct line far *next;
49
  unsigned short len;
50
  unsigned short len;
50
  char payload[1];
51
  char payload[1];
51
};
52
};
52
 
53
 
53
struct linedb {
54
struct linedb {
54
  struct line *topscreen;
55
  struct line far *topscreen;
55
  struct line *cursor;
56
  struct line far *cursor;
56
  unsigned short xoffset;
57
  unsigned short xoffset;
57
};
58
};
58
 
59
 
59
 
60
 
60
/* returns non-zero on error */
61
/* returns non-zero on error */
61
int line_add(struct linedb *db, const char *line) {
62
int line_add(struct linedb *db, const char *line) {
62
  unsigned short slen = strlen(line);
63
  unsigned short slen = strlen(line);
63
  struct line *l;
64
  struct line far *l;
64
 
65
 
65
  /* trim out CR/LF line endings */
66
  /* trim out CR/LF line endings */
66
  if ((slen >= 2) && (line[slen - 2] == '\r')) {
67
  if ((slen >= 2) && (line[slen - 2] == '\r')) {
67
    slen -= 2;
68
    slen -= 2;
68
  } else if ((slen >= 1) && (line[slen - 1] == '\n')) {
69
  } else if ((slen >= 1) && (line[slen - 1] == '\n')) {
69
    slen--;
70
    slen--;
70
  }
71
  }
71
 
72
 
72
  l = calloc(1, sizeof(struct line) + slen + 1);
73
  l = _fcalloc(1, sizeof(struct line) + slen + 1);
73
  if (l == NULL) return(-1);
74
  if (l == NULL) return(-1);
74
 
75
 
75
  l->prev = db->cursor;
76
  l->prev = db->cursor;
76
  if (db->cursor) {
77
  if (db->cursor) {
77
    l->next = db->cursor->next;
78
    l->next = db->cursor->next;
78
    db->cursor->next = l;
79
    db->cursor->next = l;
79
    l->next->prev = l;
80
    l->next->prev = l;
80
  }
81
  }
81
  db->cursor = l;
82
  db->cursor = l;
82
  memmove(l->payload, line, slen);
83
  _fmemcpy(l->payload, line, slen);
83
  l->len = slen;
84
  l->len = slen;
84
 
85
 
85
  return(0);
86
  return(0);
86
}
87
}
87
 
88
 
Line 125... Line 126...
125
 
126
 
126
 
127
 
127
static void ui_refresh(const struct linedb *db, unsigned char screenw, unsigned char screenh, unsigned char uidirtyfrom, unsigned char uidirtyto) {
128
static void ui_refresh(const struct linedb *db, unsigned char screenw, unsigned char screenh, unsigned char uidirtyfrom, unsigned char uidirtyto) {
128
  unsigned char y = 0;
129
  unsigned char y = 0;
129
  unsigned char len;
130
  unsigned char len;
130
  struct line *l;
131
  struct line far *l;
131
 
132
 
132
  /* DEBUG TODO FIXME */
133
#ifdef DBG_REFRESH
133
  static char m = 'a';
134
  static char m = 'a';
134
  m++;
135
  m++;
135
  if (m > 'z') m = 'a';
136
  if (m > 'z') m = 'a';
-
 
137
#endif
136
 
138
 
137
  for (l = db->topscreen; l != NULL; l = l->next) {
139
  for (l = db->topscreen; l != NULL; l = l->next) {
138
 
140
 
139
    /* skip lines that do not to be refreshed */
141
    /* skip lines that do not to be refreshed */
140
    if ((y < uidirtyfrom) || (y > uidirtyto)) continue;
142
    if ((y < uidirtyfrom) || (y > uidirtyto)) continue;
141
 
143
 
142
    if (db->xoffset < l->len) {
144
    if (db->xoffset < l->len) {
143
      len = mdr_cout_str(y, 0, l->payload + db->xoffset, scheme[COL_TXT], screenw - 1);
145
      for (len = 0; l->payload[len] != 0; len++) mdr_cout_char(y, len, l->payload[len], scheme[COL_TXT]);
144
    } else {
146
    } else {
145
      len = 0;
147
      len = 0;
146
    }
148
    }
147
    while (len < screenw - 1) mdr_cout_char(y, len++, ' ', scheme[COL_TXT]);
149
    while (len < screenw - 1) mdr_cout_char(y, len++, ' ', scheme[COL_TXT]);
148
 
150
 
149
    /* FIXME DEBUG */
151
#ifdef DBG_REFRESH
150
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
152
    mdr_cout_char(y, 0, m, scheme[COL_STATUSBAR1]);
-
 
153
#endif
151
 
154
 
152
    if (y == screenh - 2) break;
155
    if (y == screenh - 2) break;
153
    y++;
156
    y++;
154
  }
157
  }
155
}
158
}