Advertisement
rilo

Commander X16/KickC circle.

Nov 20th, 2019
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. // Circle.kc
  2. import "vera"
  3.  
  4. char j = 16;
  5.  
  6. void main() {
  7.  
  8. vpoke(15,VERA_DC_VIDEO,1);
  9. vpoke(15,VERA_DC_HSCALE,64);
  10. vpoke(15,VERA_DC_VSCALE,64);
  11.  
  12. vpoke(15,VERA_LAYER1,0);
  13. vpoke(15,VERA_LAYER0,(7 << 5) | 1);
  14.  
  15. vpoke(15,VERA_L0_CTRL1,%00000000);
  16.  
  17. vpoke(15,VERA_L0_TILE_BASE_L,0);
  18. vpoke(15,VERA_L0_TILE_BASE_H,0);
  19.  
  20. vaddr(0x10,0x0000);
  21.  
  22. for (dword i = 0; i < (320*239); i++) {
  23. *VERA_ADDR_DATA0 = 0;
  24. }
  25.  
  26. for (int i = 5; i < 200; i += 1) {
  27. circle(160,100,i);
  28. j++;
  29. }
  30.  
  31.  
  32. do {} while (1);
  33. }
  34.  
  35. void circle(int xc, int yc, int r) {
  36. int x = 0;
  37. int y = r;
  38. int p = 3-(r << 1);
  39.  
  40. for(int x = 0; x <= y; x ++) {
  41. if(p < 0) {
  42. p = p + (x << 2) + 6;
  43. } else {
  44. y=y-1;
  45. p = p + ((x-y) << 2) + 10;
  46. }
  47.  
  48. plot(xc+x,yc-y);
  49. plot(xc-x,yc-y);
  50. plot(xc+x,yc+y);
  51. plot(xc-x,yc+y);
  52. plot(xc+y,yc-x);
  53. plot(xc-y,yc-x);
  54. plot(xc+y,yc+x);
  55. plot(xc-y,yc+x);
  56. }
  57. }
  58.  
  59. void plot(int x, int y) {
  60. if (x < 0 || x >= 320 || y < 0 || y >= 200) {
  61. return; // bounds check
  62. }
  63. word z = (word) y * 320;
  64. vpoke(0,(word) x+z, j);
  65. }
  66.  
  67. -----8<--- split here ---8<-----
  68.  
  69. // Vera.kc
  70. const char* VERA_ADDR_LO = 0x9f20;
  71. const char* VERA_ADDR_MID = 0x9f21;
  72. const char* VERA_ADDR_HI = 0x9f22;
  73. const char* VERA_ADDR_INC = 0x9f22;
  74. const char* VERA_ADDR_DATA0 = 0x9f23;
  75. const char* VERA_ADDR_DATA1 = 0x9f24;
  76. const char* VERA_CTRL = 0x9f25;
  77.  
  78. const word VERA_DC_VIDEO = 0x0000;
  79. const word VERA_DC_HSCALE = 0x0001;
  80. const word VERA_DC_VSCALE = 0x0002;
  81. const word VERA_DC_BORDER_COLOR = 0x0003;
  82. const word VERA_DC_HSTART_L = 0x0004;
  83. const word VERA_DC_HSTOP_L = 0x0005;
  84. const word VERA_DC_VSTART_L = 0x0006;
  85. const word VERA_DC_VSTOP_L = 0x0007;
  86. const word VERA_DC_STARTSTOP_H = 0x0008;
  87. const word VERA_DC_IRQ_LINE_L = 0x0009;
  88. const word VERA_DC_IRQ_LINE_H = 0x000a;
  89.  
  90. const word VERA_LAYER0 = 0x2000;
  91. const word VERA_L0_CTRL1 = 0x2001;
  92. const word VERA_L0_TILE_BASE_L = 0x2004;
  93. const word VERA_L0_TILE_BASE_H = 0x2005;
  94. const word VERA_LAYER1 = 0x3000;
  95. const word VERA_L1_CTRL1 = 0x3001;
  96. const word VERA_L1_TILE_BASE_L = 0x3004;
  97. const word VERA_L1_TILE_BASE_H = 0x3005;
  98.  
  99. void vaddr(char bank, word offset) {
  100. *VERA_ADDR_LO = (char) offset;
  101. *VERA_ADDR_MID = (char) (offset >> 8);
  102. *VERA_ADDR_HI = bank;
  103. }
  104.  
  105. void vpoke(char bank, word offset, char value) {
  106. *VERA_ADDR_LO = (char) offset;
  107. *VERA_ADDR_MID = (char) (offset >> 8);
  108. *VERA_ADDR_HI = bank;
  109. *VERA_ADDR_DATA0 = value;
  110. }
  111.  
  112. char vpeek(char bank, word offset) {
  113. *VERA_ADDR_LO = (char) offset;
  114. *VERA_ADDR_MID = (char) (offset >> 8);
  115. *VERA_ADDR_HI = bank;
  116. return *VERA_ADDR_DATA0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement