==========================================
************************************************** ***************************
*
* Utility routines for genesis
*
*
************************************************** ***************************
Z80BusReq equ $A11100 * bit 8 (high=BusReq)
Z80Reset equ $A11200 * bit 8 (low=Reset)
************************************************** *********************************
* _JOYGET6 joystick data get ( six button and three button )
* THIS DRIVER READS BOTH THE SIX AND THREE BUTTON PADS
* ID checking and distinguishing between the three button and the
* six button controllers is done while driver actually gets data
* from the controllers. The above feature will allow the user to
* interchange controllers.
* If any device that uses a handshaking scheme( eg MOUSE) is plugged
* in, the routine returns value 0 in register d0.l Also if nothing is
* connected, the driver returns value 0 in register d0.l
* In case of three and six button controllers the driver
* cannot return value zero in register d0.l
*
* Access this routine from within the V_INT.
* SOJ recomends that the six button driver must be called from
* within V_INT.
* The Z80 Enable/Disable code is provided as a safety check, to
* prevent unfavorable bus access. Also refer to note under mods
*
* in d1.w : port number ( 0..2 )
*
* out d0.l : for case of six pad
* d0.l= 1xxx|xxxx|xxxx|xxxx|MD,TX,TY,TZ,1,1,1,1,St,TA,TC,T B,R,L,D,U
* for case of three pad
* d0.l= 0xxx|xxxx|xxxx|xxxx|xxxx|xxxx|St,TA,TC,TB,R,L,D,U
* x denotes don't care bits
* flag bit is bit 31 in d0.l
* bit 31 = 0 i.e three button controller
* bit 31 = 1 i.e six button controller
* error (unknown controller/ nothing connected) is reported by
* d0.l = 0
*
* REGISTERS:
* registers d0 to d5 are used by this routine.
* register d1 is exclusively used for input to the routine.
* register d0 is used for output
*
* EXECUTION TIME:
* six button controller, takes 722 cycles approx 90.25usecs
* three button controller, takes 688 cycles approx 86usecs
*
************************************************** ************************************
_JOYGET6:
movem.l d1/d2/d3/d4/d5/a0,-(sp)
move.w #$100,Z80BusReq * Z80 bus request
move.w #$100,Z80Reset * Z80 reset line high (NORMAL RUN STATE)
btst.b #0,Z80BusReq * Z80 bus grant acknowledge?
bne.s *-8 * wait until bus granted
moveq #0,d0
cmp.w #$0002,d1
bhi JOYGET6_ERR
add.w d1,d1
move.l #$00a10003,a0 *joystick data port address
move.b #$40,6(a0,d1.w) *set TH = output
nop
nop
move.b #$40,(a0,d1.w) * select [ ? 1 TRG-C TRG-B R L D U ]
moveq #0,d2
move.b $00(a0,d1.w),d2 * d2 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U
cmp.b #$70,d2 * checking for mouse or other handshaking device
beq JOYGET6_ERR
move.b #$00,(a0,d1.w) * select [ ? 0 START TRG-A 0 0 D U ]
lsl.w #8,d2 * d2 = ? 1 TRG-C TRG-B R L D U|0 0 0 0 0 0 0 0
move.b $00(a0,d1.w),d2 * d2 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 D U
cmp.b #$3f,d2 * checking for nothing connected
beq JOYGET6_ERR
move.b #$40,(a0,d1.w) * select [ ? 1 TRG-C TRG-B R L D U ]
moveq #0,d3
move.b $00(a0,d1.w),d3 * d3 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U
move.b #$00,(a0,d1.w) * select [ ? 0 START TRG-A 0 0 D U ]
lsl.w #8,d3
move.b $00(a0,d1.w),d3 *d3 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 D U
move.b #$40,(a0,d1.w) * select [ ? 1 TRG-C TRG-B R L D U ]
moveq #0,d4
move.b $00(a0,d1.w),d4 * d4 = xxxx|xxxx|? 1 TRG-C TRG-B R L D U
move.b #$00,(a0,d1.w) * select [ ? 0 START TRG-A 0 0 0 0 ]
lsl.w #8,d4
move.b $00(a0,d1.w),d4 * d4 = ? 1 TRG-C TRG-B R L D U|? 0 St TRG-A 0 0 0 0
move.b #$40,(a0,d1.w) * select [ ? 1 0 0 MD TX TY TZ ]
moveq #0,d5
move.b $00(a0,d1.w),d5 * d5 = 0000|0000|? 1 0 0 MD TX TY TZ
move.b #$00,(a0,d1.w) * select [ ? 0 0 0 1 1 1 1 ]
lsl.w #8,d5
move.b $00(a0,d1.w),d5 * d5 = ? 1 0 0 MD TX TY TZ| ? 0 0 0 1 1 1 1
move.b #$40,(a0,d1.w)
cmp.w d2,d3
bne JOYGET6_ERR * nothing connected or unknown device
cmp.w d3,d4
beq JOYGET3_PAD * regular 3 button controller
and.w #$000f,d4
bne JOYGET6_ERR
move.b d2,d0
lsl.w #4,d0 * d0.w = 0000|? 0 St TA 0 0 D U 0 0 0 0
lsr.w #8,d2 * d2.w = 0000|0000|? 1 TC TB R L D U
move.b d2,d0 * d0.w = 0000|? 0 St TA ? 1 TC TB R L D U
lsl.b #2,d0 * d0.w = 0000|? 0 St TA TC TB R L D U 0 0
lsr.w #2,d0 * d0.w = 0000|0 0 ? 0|St TA TC TB R L D U
and.l #$000000ff,d0
lsl.b #4,d5 * d5.w = ? 1 0 0 MD TX TY TZ|1 1 1 1 0 0 0 0
lsl.w #4,d5 * d5.w = MD TX TY TZ 1 1 1 1 0 0 0 0 0 0 0 0
or.w d5,d0 * d0.w = MD TX TY TZ 1 1 1 1 St TA TC TB R L D U
or.l #$10000000,d0 * d0.l = 1xxx|xxxx|xxxx|xxxx|MD,TX,TY,TZ,St,TA,TC,TB,R,L,D, U
bra JOYGET6_ERR
JOYGET3_PAD:
move.b d2,d0
lsl.w #4,d0 * d0.w = 0000|? 0 St TA 0 0 D U 0 0 0 0
lsr.w #8,d2 * d2.w = 0000|0000|? 1 TC TB R L D U
move.b d2,d0 * d0.w = 0000|? 0 St TA ? 1 TC TB R L D U
lsl.b #2,d0 * d0.w = 0000|? 0 St TA TC TB R L D U 0 0
lsr.w #2,d0 * d0.w = 0000|0 0 ? 0|St TA TC TB R L D U
and.l #$000000ff,d0 * d0.l = 0xxx|xxxx|xxxx|xxxx|xxxx|xxxx|St,TA,TC,TB,R,L,D,U
JOYGET6_ERR:
move.w #0,Z80BusReq * Z80 bus release
movem.l (sp)+,d1/d2/d3/d4/d5/a0
rts
==========================================
Bookmarks