Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

249 řádky
4.6KB

  1. /* vscreen.c - screen half of the vim editor for the C64 (Power C)
  2. *
  3. * Draws the text window, the status line and the cursor straight into
  4. * the screen matrix at $0400 and colour RAM at $d800. Kept in its own
  5. * file because Power C overflows its compiler when the whole editor is
  6. * one source.
  7. *
  8. * This module owns no program state: draw() receives everything it
  9. * needs from vim.c as arguments. Sharing variables between Power C
  10. * object files proved unreliable, so only functions cross the boundary.
  11. */
  12. static char stat[40]; /* status line build buffer */
  13. static int slen;
  14. /* ---------- status line text ---------- */
  15. static sclr()
  16. {
  17. slen = 0;
  18. stat[0] = 0;
  19. }
  20. static sadd(c)
  21. char c;
  22. {
  23. if (slen < 39) {
  24. stat[slen] = c;
  25. slen = slen + 1;
  26. stat[slen] = 0;
  27. }
  28. }
  29. static sstr(s)
  30. char *s;
  31. {
  32. while (*s) {
  33. sadd(*s);
  34. s = s + 1;
  35. }
  36. }
  37. static snum(n)
  38. int n;
  39. {
  40. char b[6];
  41. int i;
  42. if (n < 0) {
  43. sadd('-');
  44. n = -n;
  45. }
  46. if (n == 0) {
  47. sadd('0');
  48. return;
  49. }
  50. i = 0;
  51. while (n > 0) {
  52. b[i] = '0' + (n % 10);
  53. i = i + 1;
  54. n = n / 10;
  55. }
  56. while (i > 0) {
  57. i = i - 1;
  58. sadd(b[i]);
  59. }
  60. }
  61. /* ---------- PETSCII byte -> screen code ---------- */
  62. static sccode(c)
  63. int c;
  64. {
  65. if (c >= 193 && c <= 218) return c - 192; /* shifted letters $C1-$DA */
  66. if (c >= 96 && c <= 127) return c - 32;
  67. if (c >= 64 && c <= 95) return c - 64;
  68. /* the C-only characters have no glyph of their own in the ROM */
  69. if (c == 219) return 91; /* { -> [ */
  70. if (c == 221) return 93; /* } -> ] */
  71. if (c == 223) return 94; /* | -> up arrow */
  72. if (c == 175) return 126; /* ~ -> its graphics glyph */
  73. if (c == 164) return 95; /* _ -> left arrow */
  74. return c;
  75. }
  76. /* ---------- screen output ---------- */
  77. clrscr()
  78. {
  79. char *s;
  80. char *m;
  81. int i;
  82. s = (char *) 1024;
  83. m = (char *) 55296;
  84. for (i = 0; i < 1000; i++) {
  85. s[i] = 32;
  86. m[i] = 1;
  87. }
  88. }
  89. static putchr(x, y, ch, c)
  90. int x;
  91. int y;
  92. int ch;
  93. int c;
  94. {
  95. char *s;
  96. char *m;
  97. int o;
  98. if (x < 0) return;
  99. if (x > 39) return;
  100. if (y < 0) return;
  101. if (y > 24) return;
  102. o = y * 40 + x;
  103. s = (char *) 1024;
  104. m = (char *) 55296;
  105. s[o] = ch;
  106. m[o] = c;
  107. }
  108. static putstr(x, y, s, c)
  109. int x;
  110. int y;
  111. char *s;
  112. int c;
  113. {
  114. while (*s && x < 40) {
  115. putchr(x, y, sccode(*s), c);
  116. x = x + 1;
  117. s = s + 1;
  118. }
  119. }
  120. static revchr(o) /* reverse the character in a cell */
  121. int o;
  122. {
  123. char *s;
  124. s = (char *) 1024;
  125. if (s[o] < 128) s[o] = s[o] + 128;
  126. }
  127. /* ---------- buffer scans over the caller's text ---------- */
  128. static lstartx(tp, len, n) /* offset of the first byte of line n */
  129. char *tp;
  130. int len;
  131. int n;
  132. {
  133. int i;
  134. int c;
  135. if (n <= 0) return 0;
  136. c = 0;
  137. i = 0;
  138. while (i < len) {
  139. if (tp[i] == 13) {
  140. c = c + 1;
  141. if (c == n) return i + 1;
  142. }
  143. i = i + 1;
  144. }
  145. return len;
  146. }
  147. static lnofx(tp, cur) /* line holding the cursor */
  148. char *tp;
  149. int cur;
  150. {
  151. int i;
  152. int c;
  153. c = 0;
  154. for (i = 0; i < cur; i++)
  155. if (tp[i] == 13) c = c + 1;
  156. return c;
  157. }
  158. /* ---------- full redraw ---------- */
  159. draw(tp, len, cur, md, name, cp, cl, mc)
  160. char *tp;
  161. int len;
  162. int cur;
  163. int md;
  164. char *name;
  165. char *cp;
  166. int cl;
  167. int mc;
  168. {
  169. int ln;
  170. int top;
  171. int r;
  172. int i;
  173. int to;
  174. int c;
  175. int cs;
  176. int cr;
  177. ln = lnofx(tp, cur);
  178. top = ln - 11;
  179. if (top < 0) top = 0;
  180. clrscr();
  181. to = lstartx(tp, len, top);
  182. for (r = 0; r < 23; r++) {
  183. i = 0;
  184. while (to < len && i < 40) {
  185. c = tp[to];
  186. if (c == 13) break;
  187. putchr(i, r, sccode(c), 1);
  188. i = i + 1;
  189. to = to + 1;
  190. }
  191. while (to < len && tp[to] != 13) to = to + 1;
  192. if (to < len) to = to + 1;
  193. }
  194. for (i = 0; i < 40; i++) putchr(i, 24, 32, 11);
  195. sclr();
  196. if (md == 1) sstr("INSERT");
  197. else if (md == 2) sstr(": ");
  198. else sstr("COMMAND");
  199. sstr(" line ");
  200. snum(ln + 1);
  201. sstr(" ");
  202. sstr(name);
  203. if (mc == 1) sstr(" full");
  204. else if (mc == 2) sstr(" save err");
  205. else if (mc == 3) sstr(" saved");
  206. else if (mc == 4) sstr(" ?cmd");
  207. putstr(0, 24, stat, 11);
  208. if (md == 2) {
  209. putchr(0, 23, sccode(':'), 1);
  210. for (i = 0; i < cl; i++) putchr(i + 1, 23, sccode(cp[i]), 1);
  211. }
  212. cs = cur - lstartx(tp, len, ln);
  213. if (cs > 39) cs = 39;
  214. if (cs < 0) cs = 0;
  215. cr = ln - top;
  216. if (cr >= 0 && cr < 23) revchr(cr * 40 + cs);
  217. }

Powered by TurnKey Linux.