Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

171 Zeilen
3.8KB

  1. /* vscreen.c - screen and keyboard for the c64 vim clone.
  2. *
  3. * The editor writes straight into the screen matrix at $0400 and colour ram at
  4. * $d800 rather than going through the kernal, and it selects the lower/upper
  5. * case character set at $1800 so that petscii $41-$5a draws as real lowercase.
  6. *
  7. * Everything here returns int, so the other compilation unit can call these
  8. * without declaring them (power c is K&R C).
  9. */
  10. char *scr; /* screen matrix, $0400 */
  11. char *colr; /* colour ram, $d800 */
  12. /* petscii byte -> screen code */
  13. s2v(p)
  14. int p;
  15. {
  16. if (p >= 0xc0) return p - 0x80;
  17. if (p >= 0xa0) return p - 0x40;
  18. if (p >= 0x60) return p - 0x20;
  19. if (p >= 0x40) return p - 0x40;
  20. return p;
  21. }
  22. /* raw screen code at row r, column c */
  23. sraw(r, c, v)
  24. int r, c, v;
  25. {
  26. int i;
  27. if (r < 0) return 0;
  28. if (r > 24) return 0;
  29. if (c < 0) return 0;
  30. if (c > 39) return 0;
  31. i = r * 40 + c;
  32. scr[i] = v;
  33. colr[i] = 1;
  34. return 0;
  35. }
  36. /* one petscii character */
  37. spc(r, c, p)
  38. int r, c, p;
  39. {
  40. sraw(r, c, s2v(p));
  41. return 0;
  42. }
  43. /* one petscii character, inverted: the cursor and the status row */
  44. srpc(r, c, p)
  45. int r, c, p;
  46. {
  47. sraw(r, c, s2v(p) + 128);
  48. return 0;
  49. }
  50. /* a reversed space, for the cursor sitting past the end of a line */
  51. sblk(r, c)
  52. int r, c;
  53. {
  54. sraw(r, c, 160);
  55. return 0;
  56. }
  57. /* a zero terminated petscii string */
  58. sps(r, c, s)
  59. int r, c;
  60. char *s;
  61. {
  62. while (*s) spc(r, c++, *s++);
  63. return 0;
  64. }
  65. /* n blanks from (r,c) */
  66. sclr(r, c, n)
  67. int r, c, n;
  68. {
  69. while (n-- > 0) sraw(r, c++, 32);
  70. return 0;
  71. }
  72. /* take over the machine: black on blue, lower case, no blinking cursor */
  73. sinit()
  74. {
  75. int i;
  76. char *p;
  77. scr = (char *) 0x0400;
  78. colr = (char *) 0xd800;
  79. p = (char *) 0xd018;
  80. *p = 0x17;
  81. p = (char *) 0xd020;
  82. *p = 0;
  83. p = (char *) 0xd021;
  84. *p = 6;
  85. p = (char *) 0x00cc;
  86. *p = 0;
  87. p = (char *) 0x0091; /* run/stop flag: drop whatever boot left */
  88. *p = 0;
  89. for (i = 0; i < 1000; i++) {
  90. scr[i] = 32;
  91. colr[i] = 1;
  92. }
  93. return 0;
  94. }
  95. /* give the machine back the way basic expects it */
  96. sdone()
  97. {
  98. char *p;
  99. char a, x, y;
  100. p = (char *) 0xd018;
  101. *p = 0x15;
  102. p = (char *) 0xd020;
  103. *p = 14;
  104. p = (char *) 0xd021;
  105. *p = 6;
  106. /* do not return to basic: power c owns zero page 43-74, which is where
  107. basic keeps its program and variable pointers, so basic carries on with
  108. garbage and prints a mangled error instead of READY. restart the
  109. machine through the kernal reset instead - banner and READY, like
  110. switching on. the file has been saved (or abandoned with :q!) by now. */
  111. a = 0;
  112. x = 0;
  113. y = 0;
  114. sys(0xfce2, &a, &x, &y); /* never comes back */
  115. return 0;
  116. }
  117. /* ---------------------------------------------------------------- keyboard
  118. *
  119. * Keys come straight out of the kernal's keyboard buffer: $c6 says how many
  120. * are waiting and they queue from $0277. The kernal's own irq handler scans
  121. * the keyboard matrix and fills that buffer, so this gets each press as it
  122. * happens - and it also catches anything typed before the program started.
  123. *
  124. * (GETIN through sys() once "crashed" - but that was sys() called with the
  125. * c128 bank argument; on the c64 it is sys(addr, &a, &x, &y).) And the library's getchar() is line buffered - it
  126. * echoes through the screen editor and only hands characters over after RETURN.
  127. */
  128. /* next key, or 0 if none is waiting */
  129. skeyp()
  130. {
  131. int n, k, i;
  132. char *cnt, *buf;
  133. cnt = (char *) 0x00c6;
  134. n = *cnt;
  135. n = n & 255;
  136. if (n == 0) return 0;
  137. buf = (char *) 0x0277;
  138. k = buf[0];
  139. k = k & 255;
  140. for (i = 1; i < n; i++) buf[i - 1] = buf[i];
  141. *cnt = (char) (n - 1);
  142. return k;
  143. }
  144. /* wait for a key */
  145. skey()
  146. {
  147. int k;
  148. for (;;) {
  149. k = skeyp();
  150. if (k != 0) return k;
  151. }
  152. }

Powered by TurnKey Linux.