Drugi przycisk joysticka

Tutaj możemy porozmawiać o sprzęcie i modyfikacjach C64.
Wiadomość
Autor
radius75
Posty: 126
Rejestracja: 26 sie 2020, 15:56

Re: Drugi przycisk joysticka

#21 Post autor: radius75 »

To ja na zakończenie wątku wrzucę Driver do odczytu Pot jako dodatkowych przycisków Joysticków.
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 :)

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
;
A to uproszczona wersja bez zapisywania do DDRA i działa tylko dla portu 2

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
;

hobocti77x_
Posty: 229
Rejestracja: 15 gru 2020, 10:41

Re: Drugi przycisk joysticka

#22 Post autor: hobocti77x_ »

Jaki cel ma wstawinie za kazdym razem rozkazu CLC przed rozkazem CMP ?
clc ;
cmp #$80 ;
bcs end
Czy to jakas forma podpisu elektronicznego ? :wink:

radius75
Posty: 126
Rejestracja: 26 sie 2020, 15:56

Re: Drugi przycisk joysticka

#23 Post autor: radius75 »

Hehe, brakowało mi chyba jednego bajta do zaplanowanej wielkości programu :wink:

hobocti77x_
Posty: 229
Rejestracja: 15 gru 2020, 10:41

Re: Drugi przycisk joysticka

#24 Post autor: hobocti77x_ »

ObrazekOj, to wygląda, że tych bajtów jest znacznie więcej ;)
Po 3 przestałem liczyć ;)

A tak przy okazji to znalazłem bardzo fajne pomiary rezystancji do różnych wersji SiD-ów i wychodzi, że te 470k to tak trochę z palca sobie wzięli ;)
Okazuje się, że dla pierwszych 6581 (R2) to tak ok. 250k byłoby w sam raz, 6581 R3 ok. 270k, a dla wszystkich innych nie więcej jak 370k.
Pod koniec zakresu roznica ok. 100ohm (grubo) w zaleznosci od wersji SID-a
Więc te 470k wychodzi ze 1/4 zakresu jest bezuzyteczna ;)
A i z tą liniowością to też legenda ;)
paddles.gif
paddles.gif (26.38 KiB) Przejrzano 499 razy

majster
Posty: 8
Rejestracja: 10 gru 2024, 12:34

Re: Drugi przycisk joysticka

#25 Post autor: majster »

A propos pomiarów, dorzucę jeszcze to wideo gdzie Jeff Birt właśnie opisuje sposób pomiaru i pokazuje wartości w Excelu. Wykresy też są. ;) Tak od 6:12 jak ktoś się spieszy.

ODPOWIEDZ