Dodaje w bicie 5 i 6 odczyt z przycisków Pot-X i Pot-Y
A zależności co wstawimy do X działa tylko dla portu 2 (jeden Joy) , lub dla obydwu portów (gra na dwa Joysticki)
Enjoy
![Smile :)](./images/smilies/icon_smile.gif)
Kod: Zaznacz cały
;*** Driver for 3-button Joysticks ***
* = $c000
;1- for Control Port 1 and 2 (two joysticks)
;0- for Control Port 2 only (one joystick)
number_joysticks = 1
;for Control Port 1 and 2, save Control Ports values to temp_cp and temp_cp+1
;for Control Port 2 only, save Control Port value to temp_cp
temp_cp = $0400
;bit-0 up
;bit-1 down
;bit-2 left
;bit-3 right
;bit-4 fire
;bit-5 fire 2 (Pot-X)
;bit-6 fire 3 (Pot-Y)
;bit-7 is unused and set to HI
;
sei
;
ldx #number_joysticks
;
lda $dc02 ;get current value of DDR A
sta temp_ddr_a ;save it away
lda #%11000000 ;
sta $dc02 ;set Port A for input
;
lda #%01000000 ;set first Paddle A / Control Port 1
cpx #$01 ;how many ports will be read?
beq main_loop ;read Control Port 1 and 2
lda #%10000000 ;set first Paddle B / Control Port 2; read Control Port 2 only
;
main_loop sta $dc00 ;%01xxxxxx = Paddles A in Control Port 1, %10xxxxxx = Paddles B in Control Port 2
;
ldy #$80 ;wait
wait nop ;
dey ;
bne wait ;
;
lda #%00000000 ;set bit-5/6 to LO, for button 2/3 as released
sta button_2+1 ;
sta button_3+1 ;
;
pot_x lda $d419 ;read Pot-X register (range $ff-00 / button 2 released or pressed)
clc ;
cmp #$80 ;
bcs pot_y ;if Pot-X is >= #$80 that means button 2 is released
;
lda #%00100000 ;set bit-5 to HI, because button 2 is pressed (Pot-X is <$80)
sta button_2+1 ;
;
pot_y lda $d41a ;read Pot-Y register (range $ff-00 / button 3 released or pressed)
clc ;
cmp #$80 ;
bcs end ;if Pot-Y is >= #$80 that means button 3 is released
;
lda #%01000000 ;set bit-6 to HI, because button 3 is pressed (Pot-Y is <$80)
sta button_3+1 ;
;
end lda $dc00,x ;read Control Port
ora #%11100000 ;set bit-5/6 to HI, button 2/3 as released; bit-7 is unused and set to HI
button_2 eor #%00100000 ;add current Pot-X state to bit-5 (if button 2 is pressed then value 1 reversed HI to LO)
button_3 eor #%01000000 ;add current Pot-Y state to bit-6 (if button 3 is pressed then value 1 reversed HI to LO)
sta temp_cp,x ;save Control Ports values to temp_cp, or to temp_cp and temp_cp+1
;
lda #%10000000 ;set Paddle B / Control Port 2
dex ;all Control Ports done?
bpl main_loop ;no
;
lda temp_ddr_a ;
sta $dc02 ;restore previous value of DDR A
;
cli
;
rts
;
temp_ddr_a byte $00
;
Kod: Zaznacz cały
* = $c000
;
;adding button 2 and 3 (Pot-X and Y) to the read value from Control Port 2
;
;$dc00 = Control Port 2 / Paddle B, $dc01 = Control Port 1 / Paddle A
;
;%01xxxxxx = Paddles A in Control Port 1, %10xxxxxx = Paddles B in Control Port 2
;
lda $dc00 ;read Control Port 2
and #%00111111 ;clear bit-6/7
ora #%10000000 ;set bis-6/7
sta $dc00 ;now selected control port is set for reading the POT registers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
lda #%00000000 ;set bit-5/6 to LO, for button 2/3 as released
sta to_eor_x+1 ;
sta to_eor_y+1 ;
;
pot_x lda $d419 ;read Pot-X register (range $ff-00 / button 2 released or pressed)
clc ;
cmp #$80 ;
bcs pot_y ;if analogue value is >= #$80 that means button 2 is released
;
lda #%00100000 ;set bit-5 to HI, because button 2 is pressed
sta to_eor_x+1 ;
;
pot_y lda $d41a ;read Pot-Y register (range $ff-00 / button 3 released or pressed)
clc ;
cmp #$80 ;
bcs end ;if analogue value is >= #$80 that means button 3 is released
;
lda #%01000000 ;set bit-6 to HI, because button 3 is pressed
sta to_eor_y+1 ;
;
end lda $dc00 ;read Control Port
ora #%11100000 ;set bit-5/6 to HI, button 2/3 as released; bit-7 is unused
to_eor_x eor #%00100000 ;add current Pot-X state to bit-5 (if button 2 is pressed then value 1 reversed HI to LO)
to_eor_y eor #%01000000 ;add current Pot-Y state to bit-6 (if button 3 is pressed then value 1 reversed HI to LO)
;
;now A register contains: bit-0/3 up,down,left,right; bit-4 fire ; bit-5 fire 2 (Pot-X); bit-6 fire 3 (Pot-Y); bit-7 unused (HI)
;
sta $0400
;
rts
;