1; 2; Standard PET userport joystick driver for the PET 3; 4; Marco van den Heuvel, 2010-01-23 5; 6 7 .include "zeropage.inc" 8 9 .include "joy-kernel.inc" 10 .include "joy-error.inc" 11 .include "pet.inc" 12 13 .macpack module 14 15 16; ------------------------------------------------------------------------ 17; Header. Includes jump table 18 19 module_header _pet_stdjoy_joy 20 21; Driver signature 22 23 .byte $6A, $6F, $79 ; "joy" 24 .byte JOY_API_VERSION ; Driver API version number 25 26; Library reference 27 28 .addr $0000 29 30; Jump table. 31 32 .addr INSTALL 33 .addr UNINSTALL 34 .addr COUNT 35 .addr READ 36 37; ------------------------------------------------------------------------ 38; Constants 39 40JOY_COUNT = 2 ; Number of joysticks we support 41 42 43.code 44 45; ------------------------------------------------------------------------ 46; INSTALL routine. Is called after the driver is loaded into memory. If 47; possible, check if the hardware is present and determine the amount of 48; memory available. 49; Must return an JOY_ERR_xx code in a/x. 50; 51 52INSTALL: 53 lda #<JOY_ERR_OK 54 ldx #>JOY_ERR_OK 55; rts ; Run into UNINSTALL instead 56 57; ------------------------------------------------------------------------ 58; UNINSTALL routine. Is called before the driver is removed from memory. 59; Can do cleanup or whatever. Must not return anything. 60; 61 62UNINSTALL: 63 rts 64 65 66; ------------------------------------------------------------------------ 67; COUNT: Return the total number of available joysticks in a/x. 68; 69 70COUNT: 71 lda #<JOY_COUNT 72 ldx #>JOY_COUNT 73 rts 74 75; ------------------------------------------------------------------------ 76; READ: Read a particular joystick passed in A. 77; 78 79READ: 80 tax ; Joystick number into X 81 bne joy2 82 83; Read joystick 1 84 85joy1: 86 lda #0 87 sta VIA_DDRA 88 lda VIA_PA1 89 and #$0f 90 cmp #$0c 91 bne @notc1 92 lda #$0f 93 bne @end1 94@notc1: 95 ora #$10 96@end1: 97 eor #$1f 98 rts 99 100; Read joystick 2 101 102joy2: 103 lda #0 104 sta VIA_DDRA 105 lda VIA_PA1 106 lsr 107 lsr 108 lsr 109 lsr 110 cmp #$0c 111 bne @notc2 112 lda #$0f 113 bne @end2 114@notc2: 115 ora #$10 116@end2: 117 eor #$1f 118 ldx #0 119 rts 120