1; 2; Standard joystick driver for the CX16. 3; May be installed multiple times when statically linked to an application. 4; 5; 2019-12-24, Greg King 6; 7 8 .include "joy-kernel.inc" 9 .include "joy-error.inc" 10 11 .include "cbm_kernal.inc" 12 .include "cx16.inc" 13 14 .macpack generic 15 .macpack module 16 17 .importzp tmp1 18 19 20; ------------------------------------------------------------------------ 21; Header. Includes jump table 22 23 module_header _cx16_std_joy 24 25; Driver signature 26 27 .byte $6A, $6F, $79 ; ASCII "joy" 28 .byte JOY_API_VERSION ; Driver API version number 29 30; Library reference 31 32 .addr $0000 33 34; Jump table. 35 36 .addr INSTALL 37 .addr UNINSTALL 38 .addr COUNT 39 .addr READ 40 41; ------------------------------------------------------------------------ 42; Constant 43 44JOY_COUNT = 2 ; Number of joysticks we support 45 46; ------------------------------------------------------------------------ 47; Data. 48 49 50.code 51 52; ------------------------------------------------------------------------ 53; INSTALL routine -- is called after the driver is loaded into memory. 54; If possible, check if the hardware is present, and determine the amount 55; of memory available. 56; Must return a JOY_ERR_xx code in .XA . 57 58INSTALL: 59 lda #<JOY_ERR_OK 60 ldx #>JOY_ERR_OK 61; rts ; Run into UNINSTALL instead 62 63; ------------------------------------------------------------------------ 64; UNINSTALL routine -- is called before the driver is removed from memory. 65; Can do clean-up or whatever. Shouldn't return anything. 66 67UNINSTALL: 68 rts 69 70; ------------------------------------------------------------------------ 71; COUNT: Return the total number of possible joysticks, in .XA . 72 73COUNT: lda #<JOY_COUNT 74 ldx #>JOY_COUNT 75 rts 76 77; ------------------------------------------------------------------------ 78; READ: Read a particular joystick passed in .A . 79 80READ: and #%00000001 81 jsr JOYSTICK_GET 82 sta tmp1 83 txa 84 bit #%00001110 ; Is it NES or SNES controller? 85 bze nes 86 87 asl tmp1 ; Get SNES's B button 88 ror a ; Put it next to the A button 89 asl tmp1 ; Drop SNES's Y button 90 asl a ; Get back the B button 91 ror tmp1 92 asl a ; Get SNES's A button 93 ror tmp1 ; Make byte look like NES pad 94 95nes: lda tmp1 ; The controllers give zeroes for "pressed" 96 eor #%11111111 ; We want ones for "pressed" 97 rts 98