Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

135 linhas
2.7KB

  1. /* vmlwrap.c - the C side of the machine code helpers. build-ml.ps1 appends
  2. * this to the generated byte array to make vml.c; edit it here.
  3. *
  4. * Parameters go through a block at $c400 (not $cf00: the C stack lives just below $d000), then sys() jumps to the entry.
  5. * On the c64 sys() takes no bank argument: sys(addr, &a, &x, &y).
  6. */
  7. extern char *bfr;
  8. extern unsigned blen;
  9. extern unsigned lptr[];
  10. extern int nlines, top, leftcol;
  11. /* move the code to $c000 and keep power c's heap and stack below it.
  12. must run before malloc() */
  13. mlinit()
  14. {
  15. char *d;
  16. int i;
  17. highmem(0xc000);
  18. d = (char *) 0xc000;
  19. for (i = 0; i < MLSIZE; i++) d[i] = mlcode[i];
  20. return 0;
  21. }
  22. /* call an entry, return what it left in A */
  23. mlgo(addr)
  24. unsigned addr;
  25. {
  26. char a, x, y;
  27. a = 0;
  28. x = 0;
  29. y = 0;
  30. sys(addr, &a, &x, &y);
  31. return a & 255;
  32. }
  33. /* The wrappers fill the parameter block through one pointer instead of
  34. calling a helper per field: every power c function call costs a lot, and
  35. mlscr runs on every key. Words are stored low byte first. */
  36. /* paint one row at screen address dst: len bytes from src, cursor at column
  37. cur (255 = none), rev = 128 for an all reverse row */
  38. mlrow(src, len, dst, cur, rev)
  39. unsigned src, dst;
  40. int len, cur, rev;
  41. {
  42. char *p;
  43. p = (char *) 0xc400;
  44. p[0] = src;
  45. p[1] = src >> 8;
  46. p[2] = len;
  47. p[3] = dst;
  48. p[4] = dst >> 8;
  49. p[5] = cur;
  50. p[6] = rev;
  51. mlgo(MLROW);
  52. return 0;
  53. }
  54. /* paint screen rows r0..r1 from the buffer; the cursor sits at screen row
  55. crow (255 = none), column ccol */
  56. mlscr(r0, r1, crow, ccol)
  57. int r0, r1, crow, ccol;
  58. {
  59. char *p;
  60. unsigned v;
  61. p = (char *) 0xc400;
  62. v = (unsigned) bfr;
  63. p[0] = v;
  64. p[1] = v >> 8;
  65. v = (unsigned) lptr;
  66. p[2] = v;
  67. p[3] = v >> 8;
  68. p[4] = nlines;
  69. p[5] = nlines >> 8;
  70. p[6] = top;
  71. p[7] = top >> 8;
  72. p[8] = blen;
  73. p[9] = blen >> 8;
  74. p[10] = leftcol;
  75. p[11] = leftcol >> 8;
  76. p[12] = crow;
  77. p[13] = ccol;
  78. p[14] = r0;
  79. p[15] = r1;
  80. mlgo(MLSCRN);
  81. return 0;
  82. }
  83. /* memmove: n bytes from 'from' to 'to', overlap safe */
  84. mlmove(from, to, n)
  85. unsigned from, to, n;
  86. {
  87. char *p;
  88. if (n == 0) return 0;
  89. p = (char *) 0xc400;
  90. p[0] = from;
  91. p[1] = from >> 8;
  92. p[2] = to;
  93. p[3] = to >> 8;
  94. p[4] = n;
  95. p[5] = n >> 8;
  96. mlgo(MLBMOVE);
  97. return 0;
  98. }
  99. /* add d to n words starting at address a (line index fix-ups) */
  100. mladj(a, n, d)
  101. unsigned a, n, d;
  102. {
  103. char *p;
  104. if (n == 0) return 0;
  105. p = (char *) 0xc400;
  106. p[0] = a;
  107. p[1] = a >> 8;
  108. p[2] = n;
  109. p[3] = n >> 8;
  110. p[4] = d;
  111. p[5] = d >> 8;
  112. mlgo(MLLADJ);
  113. return 0;
  114. }
  115. /* next key from the kernal buffer, or 0 */
  116. mlkey()
  117. {
  118. return mlgo(MLKPOP);
  119. }

Powered by TurnKey Linux.