Example Joystick Quicky

QUERY_JOYSTICK macro                     
;           joystick pot readings are also switched by the (de)muliplexer (analog section)  
;           with    joystick pots the switching is not done in regard of the output (in opposite to "input" switching of integrator logic)  
;           but     with regard to input  
;           thus,   the SEL part of the mux now selects which joystick pot is selected and send to the compare logic.  
;           mux     sel:                 
;           xxxx    x00x: port 0 horizontal  
;           xxxx    x01x: port 0 vertical  
;           xxxx    x10x: port 1 horizontal  
;           xxxx    x11x: port 1 vertical  
;                                        
;           the     result of  pot reading is compared to  
;           value   present in the dac and according to the comparisson the compare flag of VIA (bit 5 of port b) is set.  
;           (compare bit is set if contents of dac was "smaller" (signed) than the "pot" read)  
DIGITAL_JOYTICK_LOOP_MIN EQU $08         
            lda     #$03                ; mux disabled, mux sel = 01 (vertical pot port 0) 
            sta     <VIA_port_b         ; 
            clr     <VIA_port_a         ; dac = 0 
            dec     <VIA_port_b         ; mux enabled, mux sel = 01 
            ldb     #DIGITAL_JOYTICK_LOOP_MIN ; a wait loop 32 times a loop (waiting for the pots to "read" values, and feed to compare logic) 
waitLoopV?:                              
            decb                        ; ... 
            bne     waitLoopV?          ; wait... 
            inc     <VIA_port_b         ; disable mux 
            ldb     #$20                ; load b with comparator bit (0010 0000) 
            lda     #$40                ; load a with test value (positive y) 
            sta     <VIA_port_a         ; test value to DAC 
            lda     #$01                ; default result value y was pushed UP 
            bitb    <VIA_port_b         ; test comparator 
            bne     yReadDone?          ; if comparator cleared - joystick was moved up 
            neg     <VIA_port_a         ; "load" with ative value 
            nega                        ; also switch the possible result in A 
            bitb    <VIA_port_b         ; test comparator again 
            beq     yReadDone?          ; if cleared the joystick was moved down 
            clra                        ; if still not cleared, we clear a as the final vertical test result (no move at all) 
yReadDone?:                              
            sta     >Vec_Joy_1_Y        ; remember the result in "our" joystick data 
;                                        
;           now     the same for horizontal  
            lda     #$01                ; mux disabled, mux sel = 00 (horizontal pot port 0) 
            sta     <VIA_port_b         ; 
            clr     <VIA_port_a         ; dac = 0 
            dec     <VIA_port_b         ; mux enabled, mux sel = 01 
            ldb     #DIGITAL_JOYTICK_LOOP_MIN ; a wait loop 32 times a loop (waiting for the pots to "read" values, and feed to compare logic) 
waitLoopH?:                              
            decb                        ; ... 
            bne     waitLoopH?          ; wait... 
            inc     <VIA_port_b         ; disable mux 
            ldb     #$20                ; load b with comparator bit (0010 0000) 
            lda     #$40                ; load a with test value (positive x) 
            sta     <VIA_port_a         ; test value to DAC 
            lda     #$01                ; default result value x was pushed right 
            bitb    <VIA_port_b         ; test comparator 
            bne     xReadDone?          ; if comparator cleared - joystick was moved right 
            neg     <VIA_port_a         ; "load" with ative value 
            nega                        ; also switch the possible result in A 
            bitb    <VIA_port_b         ; test comparator again 
            beq     xReadDone?          ; if cleared the joystick was moved left 
            clra                        ; if still not cleared, we clear a as the final vertical test result (no move at all) 
xReadDone?:                              
            sta     >Vec_Joy_1_X        ; remember the result in "our" joystick data 
            endm