Advertisement
paul_nicholls

Pas6502 example unit usage

Sep 6th, 2019
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.69 KB | None | 0 0
  1. program joyTest;
  2. uses
  3.   c64_vic,c64_joy;
  4.  
  5. const  
  6.   SCREEN_ADDRESS   = 1024;
  7.   SPR_PNTR_ADDRESS = SCREEN_ADDRESS + (2040 - 1024);
  8.   SCREEN_ORIGIN_X  = 24;
  9.   SCREEN_ORIGIN_Y  = 50;
  10.   SPRITE_SPEED     = 2;
  11.   VBLANK_LINE      = 251;
  12.    
  13.   sprite : array[0..62] of Byte = (
  14.     0,127,0,1,255,192,3,255,224,3,231,224,
  15.     7,217,240,7,223,240,7,217,240,3,231,224,
  16.     3,255,224,3,255,224,2,255,160,1,127,64,
  17.     1,62,64,0,156,128,0,156,128,0,73,0,0,73,0,
  18.     0,62,0,0,62,0,0,62,0,0,28,0  
  19.   );
  20.    
  21. var
  22.   i            : Byte;
  23.   ram          : Integer absolute $0000;
  24.   vic_spr_pntr : Integer absolute SPR_PNTR_ADDRESS;
  25. begin
  26.   //ENABLE SPRITE 2
  27.   vic_spr_ena := vic_spr_ena or 4;
  28.  
  29.   //SPRITE 2 DATA FROM BLOCK 13
  30.   vic_spr_pntr[2] := 13;          
  31.  
  32.   // copy sprite data into block 13
  33.   for i := 0 to Length(sprite) - 1 do begin
  34.     ram[832 + i] := sprite[i];
  35.   end;
  36.  
  37.   vic_spr2_x := SCREEN_ORIGIN_X + 255/2;
  38.   vic_spr2_y := SCREEN_ORIGIN_Y + 200/2;
  39.  
  40.   disable_irq;
  41.  
  42.   while true do begin
  43.     while vic_raster <> VBLANK_LINE do;
  44.  
  45.     read_joy2;
  46.    
  47.     if      input_dx = 1   then vic_spr2_x := vic_spr2_x + SPRITE_SPEED
  48.     else if input_dx = 255 then vic_spr2_x := vic_spr2_x - SPRITE_SPEED;
  49.      
  50.     if      input_dy = 1   then vic_spr2_y := vic_spr2_y + SPRITE_SPEED
  51.     else if input_dy = 255 then vic_spr2_y := vic_spr2_y - SPRITE_SPEED;
  52.   end;
  53. end.
  54.  
  55. //----------------------------------------------------------------------------
  56. //c64_joy
  57. //----------------------------------------------------------------------------
  58. unit c64_joy;
  59.  
  60. uses
  61.   joy,c64_cia;
  62.  
  63. procedure read_joy1;
  64. var
  65.   joy : Byte absolute cia1_prb; // port 1
  66. begin
  67.   reset_joy;
  68.  
  69.     if (joy and 1)  = 0 then input_dy  := input_dy - 1;
  70.     if (joy and 2)  = 0 then input_dy  := input_dy + 1;
  71.     if (joy and 4)  = 0 then input_dx  := input_dx - 1;
  72.     if (joy and 8)  = 0 then input_dx  := input_dx + 1;
  73.     if (joy and 16) = 0 then input_btn := input_btn + 1;
  74. end;
  75.  
  76. procedure read_joy2;
  77. var
  78.   joy : Byte absolute cia1_pra; // port 2
  79. begin
  80.   reset_joy;
  81.  
  82.     if (joy and 1)  = 0 then input_dy  := input_dy - 1;
  83.     if (joy and 2)  = 0 then input_dy  := input_dy + 1;
  84.     if (joy and 4)  = 0 then input_dx  := input_dx - 1;
  85.     if (joy and 8)  = 0 then input_dx  := input_dx + 1;
  86.     if (joy and 16) = 0 then input_btn := input_btn + 1;
  87. end;
  88.  
  89. procedure read_joy1and2;
  90. var
  91.   joy1 : Byte absolute cia1_prb; // port 1
  92.   joy2 : Byte absolute cia1_pra; // port 2
  93.   joy  : Byte;
  94. begin
  95.   reset_joy;
  96.  
  97.   joy := joy1 and joy2;
  98.  
  99.     if (joy and 1)  = 0 then input_dy  := input_dy - 1;
  100.     if (joy and 2)  = 0 then input_dy  := input_dy + 1;
  101.     if (joy and 4)  = 0 then input_dx  := input_dx - 1;
  102.     if (joy and 8)  = 0 then input_dx  := input_dx + 1;
  103.     if (joy and 16) = 0 then input_btn := input_btn + 1;
  104. end;
  105. //----------------------------------------------------------------------------
  106. //joy
  107. //----------------------------------------------------------------------------
  108. unit joy;
  109.  
  110. var
  111.   // Horizontal movement: -1 for left, 1 for right
  112.   input_dx  : Byte;
  113.   // Vertical movement: -1 for up, 1 for down
  114.   input_dy  : Byte;
  115.  
  116.   // Main button: 1 pressed, 0 not pressed
  117.   input_btn : Byte;
  118.  
  119. procedure reset_joy;
  120. begin
  121.   input_dx  := 0;
  122.   input_dy  := 0;
  123.   input_btn := 0;
  124. end;
  125. //----------------------------------------------------------------------------
  126. //c64_cia
  127. //----------------------------------------------------------------------------
  128. unit c64_cia;
  129.  
  130. //   CIA1
  131. var
  132.   cia1_pra       : byte absolute $DC00;
  133.   cia1_prb       : byte absolute $DC01;
  134.   cia1_ddra      : byte absolute $DC02;
  135.   cia1_ddrb      : byte absolute $DC03;
  136.   cia2_pra       : byte absolute $DD00;
  137.   cia2_prb       : byte absolute $DD01;
  138.   cia2_ddra      : byte absolute $DD02;
  139.   cia2_ddrb      : byte absolute $DD03;
  140.  
  141. //----------------------------------------------------------------------------
  142. //c64_vic
  143. //----------------------------------------------------------------------------
  144. unit c64_vic;
  145. //   VIC-II
  146. var
  147.   vic_spr0_x     : byte absolute $D000;
  148.   vic_spr0_y     : byte absolute $D001;
  149.   vic_spr1_x     : byte absolute $D002;
  150.   vic_spr1_y     : byte absolute $D003;
  151.   vic_spr2_x     : byte absolute $D004;
  152.   vic_spr2_y     : byte absolute $D005;
  153.   vic_spr3_x     : byte absolute $D006;
  154.   vic_spr3_y     : byte absolute $D007;
  155.   vic_spr4_x     : byte absolute $D008;
  156.   vic_spr4_y     : byte absolute $D009;
  157.   vic_spr5_x     : byte absolute $D00A;
  158.   vic_spr5_y     : byte absolute $D00B;
  159.   vic_spr6_x     : byte absolute $D00C;
  160.   vic_spr6_y     : byte absolute $D00D;
  161.   vic_spr7_x     : byte absolute $D00E;
  162.   vic_spr7_y     : byte absolute $D00F;
  163.   vic_spr_hi_x   : byte absolute $D010;
  164.   vic_cr1        : byte absolute $D011;
  165.   vic_raster     : byte absolute $D012;
  166.   vic_lp_x       : byte absolute $D013;
  167.   vic_lp_y       : byte absolute $D014;
  168.   vic_spr_ena    : byte absolute $D015;
  169.   vic_cr2        : byte absolute $D016;
  170.   vic_spr_exp_y  : byte absolute $D017;
  171.   vic_mem        : byte absolute $D018;
  172.   vic_irq        : byte absolute $D019;
  173.   vic_irq_ena    : byte absolute $D01A;
  174.   vic_spr_dp     : byte absolute $D01B;
  175.   vic_spr_mcolor : byte absolute $D01C;
  176.   vic_spr_exp_x  : byte absolute $D01D;
  177.   vic_spr_ss_col : byte absolute $D01E;
  178.   vic_spr_sd_col : byte absolute $D01F;
  179.   vic_border     : byte absolute $D020;
  180.   vic_bg_color0  : byte absolute $D021;
  181.   vic_bg_color1  : byte absolute $D022;
  182.   vic_bg_color2  : byte absolute $D023;
  183.   vic_bg_color3  : byte absolute $D024;
  184.   vic_spr_color1 : byte absolute $D025;
  185.   vic_spr_color2 : byte absolute $D026;
  186.   vic_spr0_color : byte absolute $D027;
  187.   vic_spr1_color : byte absolute $D028;
  188.   vic_spr2_color : byte absolute $D029;
  189.   vic_spr3_color : byte absolute $D02A;
  190.   vic_spr4_color : byte absolute $D02B;
  191.   vic_spr5_color : byte absolute $D02C;
  192.   vic_spr6_color : byte absolute $D02D;
  193.   vic_spr7_color : byte absolute $D02E;
  194.  
  195.   // other way of accessing sprite coord/color; array
  196.   vic_spr_coord  : byte absolute $D000; // array of 8 x (x,y)
  197.   vic_spr_color  : byte absolute $D027; // array of 8
  198.  
  199. const
  200.   black       = 0;
  201.   white       = 1;
  202.   red         = 2;
  203.   cyan        = 3;
  204.   purple      = 4;
  205.   green       = 5;
  206.   blue        = 6;
  207.   yellow      = 7;
  208.   orange      = 8;
  209.   brown       = 9;
  210.   light_red   = 10;
  211.   dark_grey   = 11;
  212.   dark_gray   = 11;
  213.   medium_grey = 12;
  214.   medium_gray = 12;
  215.   light_green = 13;
  216.   light_blue  = 14;
  217.   light_grey  = 15;
  218.   light_gray  = 15;
  219.  
  220. procedure vic_set_scroll(xscroll,yscroll : Byte); assembler;
  221. // this routine sets the hardware x and y scroll values
  222. // from xscroll & yscroll respectively
  223. asm
  224.   lda vic_cr1
  225.   and #$f8
  226.   ora yscroll
  227.   sta vic_cr1
  228.   lda vic_cr2
  229.   and #$f8
  230.   ora xscroll
  231.   sta vic_cr2
  232. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement