Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program joyTest;
- uses
- c64_vic,c64_joy;
- const
- SCREEN_ADDRESS = 1024;
- SPR_PNTR_ADDRESS = SCREEN_ADDRESS + (2040 - 1024);
- SCREEN_ORIGIN_X = 24;
- SCREEN_ORIGIN_Y = 50;
- SPRITE_SPEED = 2;
- VBLANK_LINE = 251;
- sprite : array[0..62] of Byte = (
- 0,127,0,1,255,192,3,255,224,3,231,224,
- 7,217,240,7,223,240,7,217,240,3,231,224,
- 3,255,224,3,255,224,2,255,160,1,127,64,
- 1,62,64,0,156,128,0,156,128,0,73,0,0,73,0,
- 0,62,0,0,62,0,0,62,0,0,28,0
- );
- var
- i : Byte;
- ram : Integer absolute $0000;
- vic_spr_pntr : Integer absolute SPR_PNTR_ADDRESS;
- begin
- //ENABLE SPRITE 2
- vic_spr_ena := vic_spr_ena or 4;
- //SPRITE 2 DATA FROM BLOCK 13
- vic_spr_pntr[2] := 13;
- // copy sprite data into block 13
- for i := 0 to Length(sprite) - 1 do begin
- ram[832 + i] := sprite[i];
- end;
- vic_spr2_x := SCREEN_ORIGIN_X + 255/2;
- vic_spr2_y := SCREEN_ORIGIN_Y + 200/2;
- disable_irq;
- while true do begin
- while vic_raster <> VBLANK_LINE do;
- read_joy2;
- if input_dx = 1 then vic_spr2_x := vic_spr2_x + SPRITE_SPEED
- else if input_dx = 255 then vic_spr2_x := vic_spr2_x - SPRITE_SPEED;
- if input_dy = 1 then vic_spr2_y := vic_spr2_y + SPRITE_SPEED
- else if input_dy = 255 then vic_spr2_y := vic_spr2_y - SPRITE_SPEED;
- end;
- end.
- //----------------------------------------------------------------------------
- //c64_joy
- //----------------------------------------------------------------------------
- unit c64_joy;
- uses
- joy,c64_cia;
- procedure read_joy1;
- var
- joy : Byte absolute cia1_prb; // port 1
- begin
- reset_joy;
- if (joy and 1) = 0 then input_dy := input_dy - 1;
- if (joy and 2) = 0 then input_dy := input_dy + 1;
- if (joy and 4) = 0 then input_dx := input_dx - 1;
- if (joy and 8) = 0 then input_dx := input_dx + 1;
- if (joy and 16) = 0 then input_btn := input_btn + 1;
- end;
- procedure read_joy2;
- var
- joy : Byte absolute cia1_pra; // port 2
- begin
- reset_joy;
- if (joy and 1) = 0 then input_dy := input_dy - 1;
- if (joy and 2) = 0 then input_dy := input_dy + 1;
- if (joy and 4) = 0 then input_dx := input_dx - 1;
- if (joy and 8) = 0 then input_dx := input_dx + 1;
- if (joy and 16) = 0 then input_btn := input_btn + 1;
- end;
- procedure read_joy1and2;
- var
- joy1 : Byte absolute cia1_prb; // port 1
- joy2 : Byte absolute cia1_pra; // port 2
- joy : Byte;
- begin
- reset_joy;
- joy := joy1 and joy2;
- if (joy and 1) = 0 then input_dy := input_dy - 1;
- if (joy and 2) = 0 then input_dy := input_dy + 1;
- if (joy and 4) = 0 then input_dx := input_dx - 1;
- if (joy and 8) = 0 then input_dx := input_dx + 1;
- if (joy and 16) = 0 then input_btn := input_btn + 1;
- end;
- //----------------------------------------------------------------------------
- //joy
- //----------------------------------------------------------------------------
- unit joy;
- var
- // Horizontal movement: -1 for left, 1 for right
- input_dx : Byte;
- // Vertical movement: -1 for up, 1 for down
- input_dy : Byte;
- // Main button: 1 pressed, 0 not pressed
- input_btn : Byte;
- procedure reset_joy;
- begin
- input_dx := 0;
- input_dy := 0;
- input_btn := 0;
- end;
- //----------------------------------------------------------------------------
- //c64_cia
- //----------------------------------------------------------------------------
- unit c64_cia;
- // CIA1
- var
- cia1_pra : byte absolute $DC00;
- cia1_prb : byte absolute $DC01;
- cia1_ddra : byte absolute $DC02;
- cia1_ddrb : byte absolute $DC03;
- cia2_pra : byte absolute $DD00;
- cia2_prb : byte absolute $DD01;
- cia2_ddra : byte absolute $DD02;
- cia2_ddrb : byte absolute $DD03;
- //----------------------------------------------------------------------------
- //c64_vic
- //----------------------------------------------------------------------------
- unit c64_vic;
- // VIC-II
- var
- vic_spr0_x : byte absolute $D000;
- vic_spr0_y : byte absolute $D001;
- vic_spr1_x : byte absolute $D002;
- vic_spr1_y : byte absolute $D003;
- vic_spr2_x : byte absolute $D004;
- vic_spr2_y : byte absolute $D005;
- vic_spr3_x : byte absolute $D006;
- vic_spr3_y : byte absolute $D007;
- vic_spr4_x : byte absolute $D008;
- vic_spr4_y : byte absolute $D009;
- vic_spr5_x : byte absolute $D00A;
- vic_spr5_y : byte absolute $D00B;
- vic_spr6_x : byte absolute $D00C;
- vic_spr6_y : byte absolute $D00D;
- vic_spr7_x : byte absolute $D00E;
- vic_spr7_y : byte absolute $D00F;
- vic_spr_hi_x : byte absolute $D010;
- vic_cr1 : byte absolute $D011;
- vic_raster : byte absolute $D012;
- vic_lp_x : byte absolute $D013;
- vic_lp_y : byte absolute $D014;
- vic_spr_ena : byte absolute $D015;
- vic_cr2 : byte absolute $D016;
- vic_spr_exp_y : byte absolute $D017;
- vic_mem : byte absolute $D018;
- vic_irq : byte absolute $D019;
- vic_irq_ena : byte absolute $D01A;
- vic_spr_dp : byte absolute $D01B;
- vic_spr_mcolor : byte absolute $D01C;
- vic_spr_exp_x : byte absolute $D01D;
- vic_spr_ss_col : byte absolute $D01E;
- vic_spr_sd_col : byte absolute $D01F;
- vic_border : byte absolute $D020;
- vic_bg_color0 : byte absolute $D021;
- vic_bg_color1 : byte absolute $D022;
- vic_bg_color2 : byte absolute $D023;
- vic_bg_color3 : byte absolute $D024;
- vic_spr_color1 : byte absolute $D025;
- vic_spr_color2 : byte absolute $D026;
- vic_spr0_color : byte absolute $D027;
- vic_spr1_color : byte absolute $D028;
- vic_spr2_color : byte absolute $D029;
- vic_spr3_color : byte absolute $D02A;
- vic_spr4_color : byte absolute $D02B;
- vic_spr5_color : byte absolute $D02C;
- vic_spr6_color : byte absolute $D02D;
- vic_spr7_color : byte absolute $D02E;
- // other way of accessing sprite coord/color; array
- vic_spr_coord : byte absolute $D000; // array of 8 x (x,y)
- vic_spr_color : byte absolute $D027; // array of 8
- const
- black = 0;
- white = 1;
- red = 2;
- cyan = 3;
- purple = 4;
- green = 5;
- blue = 6;
- yellow = 7;
- orange = 8;
- brown = 9;
- light_red = 10;
- dark_grey = 11;
- dark_gray = 11;
- medium_grey = 12;
- medium_gray = 12;
- light_green = 13;
- light_blue = 14;
- light_grey = 15;
- light_gray = 15;
- procedure vic_set_scroll(xscroll,yscroll : Byte); assembler;
- // this routine sets the hardware x and y scroll values
- // from xscroll & yscroll respectively
- asm
- lda vic_cr1
- and #$f8
- ora yscroll
- sta vic_cr1
- lda vic_cr2
- and #$f8
- ora xscroll
- sta vic_cr2
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement