Advertisement
paul_nicholls

KickC c64 first steps

May 25th, 2023 (edited)
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. const word SCREEN0_ADDRESS  = $0400;
  2. const word SPR_PNTR_ADDRESS = SCREEN0_ADDRESS + (2040 - 1024);
  3.  
  4. #include <c64.h>
  5. #include "..\libraries\c64_joy.c"
  6. #include "..\libraries\c64_vic.c"
  7.  
  8. byte sprite[]  = {
  9.     0,127,0,1,255,192,3,255,224,3,231,224,
  10.     7,217,240,7,223,240,7,217,240,3,231,224,
  11.     3,255,224,3,255,224,2,255,160,1,127,64,
  12.     1,62,64,0,156,128,0,156,128,0,73,0,0,73,0,
  13.     0,62,0,0,62,0,0,62,0,0,28,0  
  14. };
  15.  
  16. __address(SPR_PNTR_ADDRESS) byte vic_spr_pntr[8];
  17.  
  18. void poke(unsigned word a,unsigned byte v) {
  19.   // write byte v to memory address a
  20.   unsigned char *MEMPTR;
  21.  
  22.   MEMPTR = (unsigned char *)a;
  23.  
  24.   *MEMPTR = v;
  25. }
  26.  
  27. byte peek(unsigned word a) {
  28.   // read byte from memory address a
  29.   unsigned char *MEMPTR;
  30.  
  31.   MEMPTR = (unsigned char *)a;
  32.   return (*MEMPTR);
  33. }
  34.  
  35. const byte SPRITE           = 2;
  36. const byte SCREEN_ORIGIN_X  = 24;
  37. const byte SCREEN_ORIGIN_Y  = 50;
  38. const byte SPRITE_SPEED     = 2;
  39.  
  40. void main() {
  41.   //ENABLE SPRITE 2
  42.   vic_spr_ena = vic_spr_ena | 4;
  43.  
  44.   //SPRITE 2 DATA FROM BLOCK 13
  45.   vic_spr_pntr[2] = 13;          
  46.  
  47.   byte i;
  48.   for (i = 0; i < 62; i++) {
  49.     poke(832+i,sprite[i]);
  50.   }
  51.  
  52.   vic_spr2_x = SCREEN_ORIGIN_X + 255/2;
  53.   vic_spr2_y = SCREEN_ORIGIN_Y + 200/2;
  54.  
  55.   vic_spr2_color = 1;
  56.    
  57.   while (true) {
  58.     vic_waitForRaster(251);
  59.  
  60.     read_joy1();
  61.     read_also_joy2();
  62.    
  63.     if      (input_dx > 0) {vic_spr2_x = vic_spr2_x + SPRITE_SPEED;}
  64.     else if (input_dx < 0) {vic_spr2_x = vic_spr2_x - SPRITE_SPEED;}
  65.      
  66.     if      (input_dy > 0) {vic_spr2_y = vic_spr2_y + SPRITE_SPEED;}
  67.     else if (input_dy < 0) {vic_spr2_y = vic_spr2_y - SPRITE_SPEED;}
  68.   }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement