	.code
	.bank 0
	.org $f06c
joy_analogue:
          SEI     
          RMB3    <$23
          STZ     $1000
          CLX     
          PHA     
          PLA     
          NOP     
lf076_00:
          CLY     
          LDA     #$02
          STA     $1000
lf07c_00:
          LDA     $1000
          AND     #$03
          BEQ     lf089_00
          INY     
          BNE     lf07c_00
lf086_00:
          CLI     
          SEC     
          RTS     
lf089_00:
          LDA     #$03
          STA     $1000
          PHA     
          PLA     
          NOP     
          LDA     $1000
          AND     #$0f
          TAY     
          LDA     $f14b, Y
          STA     <$96, X
          LDA     #$02
          STA     $1000
          INX     
          PHA     
          PLA     
          NOP     
          CLY     
lf0a6_00:
          INY     
          BEQ     lf086_00
          LDA     $1000
          AND     #$03
          CMP     #$01
          BNE     lf0a6_00
          LDA     #$03
          STA     $1000
          PHA     
          PLA     
          NOP     
          LDA     $1000
          AND     #$0f
          TAY     
          LDA     $f14b, Y
          STA     <$96, X
          INX     
          CPX     #$09
          BCC     lf076_00
          CLI     
          LDA     <$98
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     <$9c
          BBR6    <$37, lf0d8_00
          EOR     #$ff
lf0d8_00:
          STA     $3034
          LDA     <$99
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     <$9d
          STA     $3033
          LDA     <$9a
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     <$9e
          STA     $3035
          LDA     <$38
          STA     $302f
          LDA     <$96
          ASL     A
          ASL     A
          ASL     A
          ASL     A
          ORA     <$97
          EOR     #$ff
          STA     $3032
          TAX     
          AND     #$03
          STA     <$38
          TXA     
          ASL     A
          ROL     <$38
          ASL     A
          ROL     <$38
          LDA     #$80
          LDY     $3033
          CPY     #$4f
          BCC     lf11f_00
          LDA     #$20
          CPY     #$b0
          BCS     lf11f_00
          CLA     
lf11f_00:
          TSB     <$38
          LDA     #$10
          LDY     $3034
          CPY     #$4f
          BCC     lf131_00
          LDA     #$40
          CPY     #$b0
          BCS     lf131_00
          CLA     
lf131_00:
          TSB     <$38
          LDA     <$38
          EOR     $302f
          AND     <$38
          STA     <$39
          CMP     #$04
          BNE     lf146_00
          LDA     <$38
          CMP     #$0c
          BEQ     lf148_00
lf146_00:
          CLC     
          RTS     
lf148_00:
          JMP     lef1a_00

	.code
	.bank 0
	.org $ef49
joy_read:
          JSR     lef93_01
          JSR     lf204_01
          BBR6    <$22, lef55_01
          JSR     l8806_01
lef55_01:
          BBS0    <$21, lef5d_01
          JSR     lf15f_01
          BRA     lef6b_01
lef5d_01:
          BBS1    <$21, lef6b_01
          LDA     <$2e
          INC     A
          BEQ     lef68_01
lef65_01:
          BBR1    <$23, lef65_01
lef68_01:
          JSR     joy_analogue
lef6b_01:
          SMB7    <$23
          LDA     <$2d
lef6f_01:
          CMP     <$2d
          BEQ     lef6f_01
          RTS     

