*---------------------------------------------------------------------- * File Name: ioid.asm * * Copyright (c) 1994 Sega of America, Inc. All Rights Reserved. * * Author(s): Unni Pillai * Date: 6-06-94 * Description: Contains IO ID checking routines, executed immediately * after ICD_MARS, and start up handshake with the MASTER * and slave SH2 * * History: * *---------------------------------------------------------------------* section .text nolist include "ioid.i" ;references used by ioid.asm include "z80.h" ;Z80 hardware equates include "general.mac" ;general purpose macros list *-------------------------------------------------------------------- * _initIDCMP: does initial id checking for I/O devices attached to * port 1 and 2 on the genesis. * * void _initIDCMP( ) * in - * out .bss variables idcode1 & idcode2 * IOerrFlag1 & IOerrFlag2 (only if error) * MODS * name date comments * ---- -------- ------------------------------------- * UP 06/19/94 created *---------------------------------------------------------------------- xdef initIDCMP dc.l 0 initIDCMP: moveq #0,d1 ; port 1 jsr JSID ; what device is attached to port 1 move.b d0,idcode1 ; store device id in bss variable idcode1 cmp.b #$0f,idcode1 ; check if unknown/nothing connected beq id_ioerr bra.s id_twoplayer id_ioerr: st IOerrFlag1 ; set error flag id_twoplayer: moveq #1,d1 ; port 2 jsr JSID ; what device is attached to port 2 move.b d0,idcode2 ; store device id in bss variable idcode2 cmp.b #$0f,idcode2 ; check if unknown/nothing connected beq id_ioerr2 bra.s id_exit id_ioerr2: st IOerrFlag2 id_exit: rts *---------------------------------------------------------------------------- * _JSID: does initial id checking for I/O devices attached to * joystick id code get * this routine figures out if some kind of controller is * attached to the ports. Essentially distinguishes between * regular controllers(3 but,6but,activator,optical) and * handshaking controllers(mouse,). This identification * scheme is based on Addendum #1 in the Genesis Software Manual * port 1 and 2 on the genesis. * * void _JSID( ) * * in d1.w : port number ( 0..2 ) * * out d0.l : ID * equ $0f * ????? unknown/nothing connected * equ $0d * (MDpad,FP6B) * equ $03 * MOUSE * equ $07 * SEGA TEAM PLAYER * equ $ff * input error(incorrect port number) * * author: NG (SOJ) * MODS * name date comments * ---- -------- ------------------------------------------- * UP 06/29/1993 fixed bugs * UP 01/14/1994 (increased time between each TH transition * based on SOJ MD TECHNICAL INFO #7 01/11/94) * * copyright SEGA OF AMERICA *--------------------------------------------------------------------------- xdef JSID dc.l 0 JSID: cmp.b #3,d1 blt _JSID_10 moveq #-1,d0 rts _JSID_10: movem.l d2-d3/a0,-(sp) Z80di ;disable the Z80 off the bus move.l #$00a10003,a0 moveq #0,d0 move.b d1,d0 add.l d0,d0 adda.l d0,a0 moveq #0,d0 move.l d0,d1 move.b 6(a0),d3 ; save original status of control port swap d3 move.b (a0),d3 ; original status of I/O port move.b #%01000000,6(a0) ; I/O control : TH out move.b #%01000000,(a0) ; TH - Hi nop nop nop nop move.b (a0),d0 move.b #%00000000,(a0) ; TH - Low nop nop nop nop move.b (a0),d1 move.b #%01000000,(a0) ; TH - Hi move.w d0,d2 lsr.b #1,d0 ror.w #1,d0 lsr.b #1,d0 rol.w #1,d0 ror.w #1,d2 lsr.b #1,d2 rol.w #1,d2 or.b d2,d0 ;ID2=(PD6=1)&(PD1 OR PD0) and.w #$03,d0 lsl.b #2,d0 move.w d1,d2 lsr.b #1,d1 ror.w #1,d1 lsr.b #1,d1 rol.w #1,d1 ror.w #1,d2 lsr.b #1,d2 rol.w #1,d2 or.b d2,d1 ;ID0=(PD6=0)&(PD1 OR PD0) and.w #$03,d1 or.b d1,d0 ;return id value move.b d3,(a0) ; restore original status of I/O port swap d3 move.b d3,6(a0) ; restore original status of control port Z80ei ; Z80 bus release movem.l (sp)+,d2-d3/a0 rts *----------------------------end of file IO.ASM------------------------------;