	.code
	.bank 4
	.org $7298
joy_analogue:
          LDA     #$00
          STA     $1000
          PHA     
          PLA     
          NOP     
          LDA     #$02
          STA     $1000
          LDA     #$06
          STA     $2a33
          CLY     
          CLX     
l72ac_00:
          INX     
          BNE     l72b2_00
          JMP     l7351_00
l72b2_00:
          LDA     $1000
          AND     #$03
          BNE     l72ac_00
          LDA     #$03
          STA     $1000
          PHA     
          PLA     
          NOP     
          LDA     $1000
          AND     #$0f
          TAX     
          LDA     $7353, X
          STA     $2a20, Y
          INY     
          LDA     #$02
          STA     $1000
          PHA     
          PLA     
          NOP     
          CLX     
l72d7_00:
          INX     
          BEQ     l7351_00
          LDA     $1000
          AND     #$03
          CMP     #$01
          BNE     l72d7_00
          LDA     #$03
          STA     $1000
          PHA     
          PLA     
          NOP     
          LDA     $1000
          AND     #$0f
          TAX     
          LDA     $7353, X
          STA     $2a20, Y
          INY     
          LDA     #$02
          STA     $1000
          PHA     
          PLA     
          NOP     
          DEC     $2a33
          BEQ     l7308_00
          JMP     l72ac_00
l7308_00:
          LDA     $2a20
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     $2a21
          STA     $2a30
          LDA     $2a22
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     $2a26
          TAY     
          LDA     [$50], Y
          STA     $2a31
          LDA     $2a23
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     $2a27
          TAY     
          LDA     [$52], Y
          STA     $2a32
          LDA     $2a24
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     $2a28
          STA     $2a33
          LDA     $2a25
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     $2a29
          STA     $2a34
          CLC     
          RTS     

	.data
	.bank 4
	.org $7353
joy_tab:
    .db $00,$01,$08,$09,$02,$03,$0a,$0b
    .db $04,$05,$0c,$0d,$06,$07,$0e,$0f

	.code
	.bank 0
	.org $f6cd
joy_update:
          JSR     joy_analogue
          LDA     $2540
          STA     $2545
          LDA     $2a30
          AND     #$03
          ASL     A
          ASL     A
          STA     <$1d
          LDA     $2a30
          AND     #$c0
          CLC     
          ROL     A
          ROL     A
          STA     <$1e
          ROL     A
          ROL     A
          AND     #$02
          ORA     <$1e
          ORA     <$1d
          EOR     #$ff
          AND     #$0f
          STA     $2540
          EOR     $2545
          AND     $2540
          STA     $254a
          LDA     <$47
          AND     $f77c
          BEQ     lf77b_02
          LDA     $254a
          CMP     #$04
          BNE     lf77b_02
          LDA     $2540
          CMP     #$0c
          BNE     lf77b_02
          JMP     le000_02
          CLY     
          LDA     #$01
          STA     $1000
          LDA     #$03
          STA     $1000
lf724_02:
          LDA     #$01
          STA     $1000
          PHA     
          PLA     
          NOP     
          LDA     $2540, Y
          STA     $2545, Y
          LDA     $1000
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          STA     $2540, Y
          STZ     $1000
          PHA     
          PLA     
          NOP     
          LDA     $1000
          AND     #$0f
          ORA     $2540, Y
          EOR     #$ff
          STA     $2540, Y
          EOR     $2545, Y
          AND     $2540, Y
          STA     $254a, Y
          INY     
          CPY     #$05
          BCC     lf724_02
          CLY     
lf75e_02:
          LDA     <$47
          AND     $f77c, Y
          BEQ     lf776_02
          LDA     $254a, Y
          CMP     #$04
          BNE     lf776_02
          LDA     $2540, Y
          CMP     #$0c
          BNE     lf776_02
          JMP     le000_02
lf776_02:
          INY     
          CPY     #$05
          BCC     lf75e_02
lf77b_02:
          RTS     

