one thing I forgot, the source code
Code: Select all
DetectAnalog1: ; Detects the presence of analog controller
JSR WaitOneFrame ; Wait a little (poll may have been in progress)
MOVE.B ($A10003), D0
AND.B #3, D0 ; First step: axe bits must be unset
BEQ NextAnalogStep1
CLR.L D0
RTS
NextAnalogStep1:
MOVE.B #$40, ($A10003) ; Next step: pulse TH so timers start and axe
NOP #4 ; bits are set
MOVE.B #$00, ($A10003)
MOVE.W #31, D0
AnalogInitLoop1:
DBRA D0, AnalogInitLoop1
MOVE.B ($A10003), D0
AND.B #3, D0 ; Bits must be set now
BNE WeHaveAnalog1
CLR.L D0
RTS
WeHaveAnalog1:
MOVEQ #1, D0
RTS
DetectAnalog2: ; Detects the presence of analog controller
JSR WaitOneFrame ; Wait a little (poll may have been in progress)
MOVE.B ($A10005), D0
AND.B #3, D0 ; First step: axe bits must be unset
BEQ NextAnalogStep2
CLR.L D0
RTS
NextAnalogStep2:
MOVE.B #$40, ($A10005) ; Next step: pulse TH so timers start and axe
NOP #4 ; bits are set
MOVE.B #$00, ($A10005)
MOVE.W #31, D0
AnalogInitLoop2:
DBRA D0, AnalogInitLoop2
MOVE.B ($A10005), D0
AND.B #3, D0 ; Bits must be set now
BNE WeHaveAnalog2
CLR.L D0
RTS
WeHaveAnalog2:
MOVEQ #1, D0
RTS
ReadAnalog1: ; Reads analog gamepad button and axe status
CLR.W D1 ; X counter
CLR.W D2 ; Y counter
MOVE.B #$40, ($A10003)
NOP #4
MOVE.B #$00, ($A10003)
MOVE.B ($A10003), D0
NOT.B D0
MOVE.W D0, (P1CTRL)
PollJoy1:
MOVE.B ($A10003), D0
AND.B #3, D0 ; Check if poll is done
BEQ PollDone1
BTST #0, D0 ; Check X
BEQ DummyAxe11
ADDQ.W #1, D1
BRA NextAxe1
DummyAxe11:
ADDQ.W #1, D3
BRA NextAxe1
NextAxe1:
BTST #1, D0 ; Check Y
BEQ DummyAxe21
ADDQ.W #1, D2
BRA PollJoy1
DummyAxe21:
ADDQ.W #1, D3
BRA PollJoy1
PollDone1:
MOVE.W D1, (JOYX1)
MOVE.W D2, (JOYY1)
RTS
ReadAnalog2: ; Reads analog gamepad button and axe status
CLR.W D1 ; D1=X counter
CLR.W D2 ; D2=Y counter
MOVE.B #$40, ($A10005) ; D3=Dummy counter
NOP #4
MOVE.B #$00, ($A10005)
MOVE.B ($A10005), D0
NOT.B D0
MOVE.W D0, (P2CTRL)
PollJoy2:
MOVE.B ($A10005), D0
AND.B #3, D0 ; Check if poll is done
BEQ PollDone2
BTST #0, D0 ; Check X
BEQ DummyAxe12
ADDQ.W #1, D1
BRA NextAxe2
DummyAxe12:
ADDQ.W #1, D3
BRA NextAxe2
NextAxe2:
BTST #1, D0 ; Check Y
BEQ DummyAxe22
ADDQ.W #1, D2
BRA PollJoy2
DummyAxe22:
ADDQ.W #1, D3
BRA PollJoy2
PollDone2:
MOVE.W D1, (JOYX2)
MOVE.W D2, (JOYY2)
RTS