***************************************************************************** *six.asm - MEGADRIVE I/O device id routines and data routines * *ver: 4.0 (released with Universal Driver VER 4.0) * *author: Unni Pillai * *MODS: * *UP Jan 14th 1994 (increased time between each TH transition to 4usecs * based on SOJ MD TECHNICAL INFO #7 01/11/94) *Copyright (c) SEGA OF AMERICA INC. * All Rights Reserved ***************************************************************************** section .text include "z80.h" *********************************************************************************** *JOYGET6 joystick data get ( six button and three button ) * 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. * Essentially this routine is designed for games that are just going * to use just the six button and three button controllers only. * 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,TB,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 * *ver: 0.2 *author: Unni Pillai (Peripherals Dept SOA) * *mods: added Z80 disable/enable code 6/30/93 *NOTE: this code adds 88 cycles (11usecs) to driver execution time. * most games polling the I/O port at the begining of the V_INT * can save this overhead by removing the Z80 disable/enable code. * * UP Jan 14th 1994 (increased time between each TH transition to 4usecs * based on SOJ MD TECHNICAL INFO #7 01/11/94) * added 3 nops after each moveq instruction * * copyright June 1993 SEGA OF AMERICA ************************************************************************************** xdef JOYGET6 dc.l 0 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 nop nop nop 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 nop nop nop 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 nop nop nop 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 nop nop nop 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 #$80000000,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 *-------------------end of file six.asm---------------------------------------------------------