print "Joy: $", pc ;=======================================; ; Joypad Read Routine ;=======================================; ; Scratch RAM: ; $18-$19: controller 1 data ; $1a-$1b: controller 2 data ; $1c-$1d: controller 3 data ; $1e-$1f: controller 4 data ;=======================================; joypad: ; Class Joypad .return rts ; Return label. .read lda $e6 ;\ If joypad read flag isn't set beq .return ;/ return. ; rep #$20 ; 16-bit A lda $4218 ;\ Read controller 1 from Auto Joypad, sta $18 ;/ lda $421a ;\ ...controller 2, sta $1a ;/ lda $421e ;\ ...and controller 3. sta $1c ;/ stz $1e ; Isn't possible to read controller 4 from Auto Joypad. sep #$20 ; 8-bit A ; stz $4201 ; I/O port 1->0 lda #$01 ;\ Latch MP5 (controller 4) sta $4016 ;/ nop #2 ;\ I'm not sure if this waste time is required. stz $4016 ;/ ; ldx #$10 ; Loop size. - lda $4017 ;\ Read controller 4 button rep #$20 ;| and roll to $1E. lsr ;| rol $1e ;| sep #$20 ;/ dex ;\ Loop. bne - ;/ ; lda #$80 ;\ I/O port 0->1 sta $4201 ;/ ; rep #$20 ; 16-bit A ;lda $e7 ;\ If controller 3 and 4 isn't allowed to work, ;bne + ;| clear all buttons. ;stz $1c ;| ;stz $1e ;/ + lda $3040 ;\ Set all readed buttons eor #$ffff ;| to all RAMs. sta $00 ;| And, setup all "pressed once" RAMs. lda $18 ;| and $00 ;| sta $3048 ;| lda $3042 ;| eor #$ffff ;| sta $00 ;| lda $1a ;| and $00 ;| sta $304a ;| lda $3044 ;| eor #$ffff ;| sta $00 ;| lda $1c ;| and $00 ;| sta $304c ;| lda $3046 ;| eor #$ffff ;| sta $00 ;| lda $1e ;| and $00 ;| sta $304e ;| lda $18 ;| sta $3040 ;| lda $1a ;| sta $3042 ;| lda $1c ;| sta $3044 ;| lda $1e ;| sta $3046 ;/ sep #$20 ; 8-bit A rts ; Return.