#IFNDEF __lib_joysticktests #DEFINE __lib_joysticktests 1 #INCLUDE "joystick.c65" #INCLUDE "mouse.c65" #INCLUDE "pointer.c65" GOTO __skip_lib_joysticktests // ============================================================================ // FUNC test_joystick_read // Test basic joystick reading using card suit symbols // Displays suits in 4 directions, lights up when joystick pressed // Runs forever - reset to exit // ============================================================================ //FUNC test_joystick_read // WORD screen_ptr @ $fb // BYTE raster @ $d012 // // // Initialize joystick // joy_init() // // // Draw suit symbols in cross pattern (center of screen) // // Hearts (red) = UP, Diamonds (red) = DOWN, Spades (black) = LEFT, Clubs (black) = RIGHT // // // UP position - Hearts suit symbol // POINTER screen_ptr -> 9*40+$0400+18 // POKE screen_ptr[0] , $50 // // // DOWN position - Diamonds suit symbol // POINTER screen_ptr -> 11*40+$0400+18 // POKE screen_ptr[0] , $51 // // // LEFT position - Spades suit symbol // POINTER screen_ptr -> 10*40+$0400+16 // POKE screen_ptr[0] , $0e // // // RIGHT position - Clubs suit symbol // POINTER screen_ptr -> 10*40+$0400+20 // POKE screen_ptr[0] , $0f // // // CENTER - Fire indicator (Ace symbol) // POINTER screen_ptr -> 10*40+$0400+18 // POKE screen_ptr[0] , 0 // // // Main test loop - runs forever // WHILE 1 // joy_read_port2() // // // Wait for raster // WHILE raster != 250 // WEND // // // Update suit displays based on joystick // // // UP - Hearts (normal or highlighted) // POINTER screen_ptr -> 9*40+$0400+18 // IF joy_up // POKE screen_ptr[0] , $50+64 // Red/highlighted // ELSE // POKE screen_ptr[0] , $50 // Normal // ENDIF // // // DOWN - Diamonds // POINTER screen_ptr -> 11*40+$0400+18 // IF joy_down // POKE screen_ptr[0] , $51+64 // Red/highlighted // ELSE // POKE screen_ptr[0] , $51 // Normal // ENDIF // // // LEFT - Spades // POINTER screen_ptr -> 10*40+$0400+16 // IF joy_left // POKE screen_ptr[0] , $0e+64 // Red/highlighted // ELSE // POKE screen_ptr[0] , $0e // Normal // ENDIF // // // RIGHT - Clubs // POINTER screen_ptr -> 10*40+$0400+20 // IF joy_right // POKE screen_ptr[0] , $0f+64 // Red/highlighted // ELSE // POKE screen_ptr[0] , $0f // Normal // ENDIF // // // FIRE - Center Ace // POINTER screen_ptr -> 10*40+$0400+18 // IF joy_fire // POKE screen_ptr[0] , 13+64 // Ace highlighted // ELSE // POKE screen_ptr[0] , 0 // Blank // ENDIF // WEND //FEND // ============================================================================ // FUNC test_pointer_sprite // Test sprite pointer movement with joystick // Initializes sprite, copies sprite data, and moves pointer with joystick // Run for ~200 frames then returns // ============================================================================ FUNC test_pointer_sprite // Copy sprite data to $2200 (sprite block 136) // $2000-$21FF reserved for charset WORD src_ptr @ $fa WORD src_end_ptr WORD dst_ptr @ $fc WORD frame_count BYTE raster @ $d012 POINTER src_ptr -> pointer_sprite_data POINTER src_end_ptr -> pointer_sprite_data_end POINTER dst_ptr -> $2200 mem_copy(src_ptr, src_end_ptr, dst_ptr) // Initialize pointer pointer_init(160, 100, color_red, 136) // Sprite block 136 = $2200, red color pointer_set_speed(2) // Enable sprite pointer_enable(1) // Movement loop - runs forever WHILE 1 // Wait for raster WHILE raster != 250 WEND DEC $d020 // Read joystick and update pointer joy_read_port2() pointer_update_joystick(joy_state) INC $d020 WEND FEND // ============================================================================ // FUNC test_pointer_manual // Test pointer with manual position setting // Moves pointer in a square pattern without joystick // ============================================================================ //FUNC test_pointer_manual // WORD x // BYTE y // BYTE delay // WORD x_down // BYTE y_down // // // Copy sprite data to $2200 (sprite block 136) // WORD src_ptr @ $fa // WORD src_end_ptr // WORD dst_ptr @ $fc // POINTER src_ptr -> pointer_sprite_data // POINTER src_end_ptr -> pointer_sprite_data_end // POINTER dst_ptr -> $2200 // mem_copy(src_ptr, src_end_ptr, dst_ptr) // // // Initialize pointer // pointer_init(50, 50, color_cyan, 136) // pointer_set_speed(3) // // // Move in square pattern // // Right // FOR x = 50 TO 200 // pointer_set_x(x) // pointer_set_y(50) // // Small delay // FOR delay = 0 TO 10 // NEXT // NEXT // // // Down // FOR y = 50 TO 150 // pointer_set_x(200) // pointer_set_y(y) // FOR delay = 0 TO 10 // NEXT // NEXT // // // Left // x_down = 200 // WHILE x_down > 50 // pointer_set_x(x_down) // pointer_set_y(150) // x_down-- // FOR delay = 0 TO 10 // NEXT // WEND // // // Up // y_down = 150 // WHILE y_down > 50 // pointer_set_x(50) // pointer_set_y(y_down) // y_down-- // FOR delay = 0 TO 10 // NEXT // WEND // // // Disable sprite // pointer_enable(0) //FEND // ============================================================================ // FUNC test_pointer_mouse // Test sprite pointer movement with 1351 mouse // Initializes sprite, copies sprite data, and moves pointer with mouse // Run forever - press RUN/STOP+RESTORE to exit // ============================================================================ FUNC test_pointer_mouse // Copy sprite data to $2200 (sprite block 136) // $2000-$21FF reserved for charset WORD src_ptr @ $fa WORD src_end_ptr WORD dst_ptr @ $fc BYTE raster @ $d012 POINTER src_ptr -> pointer_sprite_data POINTER src_end_ptr -> pointer_sprite_data_end POINTER dst_ptr -> $2200 mem_copy(src_ptr, src_end_ptr, dst_ptr) // Initialize mouse and pointer mouse_init() pointer_init(160, 100, color_red, 136) // Sprite block 136 = $2200, white color // Enable sprite pointer_enable(1) // Movement loop - runs forever WHILE 1 // Wait for raster WHILE raster != 250 WEND DEC $d020 // Read mouse and update pointer mouse_read() pointer_update_mouse(mouse_delta_x, mouse_delta_y) // Test buttons (active-low: 0=pressed) BYTE left_btn BYTE right_btn // Left button = bit 4 left_btn = mouse_buttons & %00010000 IF left_btn == 0 INC $0400 // Pressed ENDIF // Right button = bit 0 right_btn = mouse_buttons & %00000001 IF right_btn == 0 INC $0401 // Pressed ENDIF INC $d020 WEND FEND LABEL __skip_lib_joysticktests #IFEND