Difference between revisions of "YM2151 Detection"

From 8BitDev.org - Atari 7800 Development Wiki
Jump to: navigation, search
(Created page with "<pre> YM2151ADDR EQU $460 YM2151DATA EQU $461 XMCNTRL EQU $470 LDA #$70 STA CTRL ;TURN OFF MARIA LDA #$84 ;enable YM STA XMCNTRL LDA #$00 TAX YMLP1: JSR WRITEYMAD...")
 
(No difference)

Latest revision as of 17:26, 10 April 2021

YM2151ADDR	EQU	$460
YM2151DATA	EQU	$461
XMCNTRL		EQU	$470

	LDA #$70
	STA CTRL		;TURN OFF MARIA

	LDA #$84		;enable YM
	STA XMCNTRL

	LDA #$00
	TAX
YMLP1:  JSR WRITEYMADDR
	STA YM2151DATA
	INX
	BNE YMLP1		

	LDX #$14		;disable counter
	LDA #00
	JSR WRITEYMADDR

	LDX #$12		;set counter
	LDA #252		
	JSR WRITEYMADDR

	LDX #$14		;enable counter
	LDA #$2A
	JSR WRITEYMADDR

;TIMER IS NOW ACTIVE SO LETS COUNT WHILE WAITING FOR THE CLOCK TO OVERFLOW
	LDY #$02
REPEAT: LDX #$00
POLLFLAG: INX
	BEQ YMNOTFOUND		;timeout if no ym present	
	LDA YM2151DATA		;read counter flag
	AND #$02
	BNE CHECKCOUNT
	JMP POLLFLAG

WRITEYMADDR
	BIT YM2151DATA
	BMI WRITEYMADDR
	STX YM2151ADDR
WRITEYMDATA
	BIT YM2151DATA
	BMI WRITEYMDATA
	STA YM2151DATA
	RTS

CHECKCOUNT:
	DEY
	BEQ CHKCNT
	LDX #$14		;RESET COUNTER FLAG
	LDA #$2A
	JSR WRITEYMADDR
	JMP REPEAT
CHKCNT: 			
	CPX #$80		;COUNT SHOULD BE $88, CHECK IT'S BETWEEN $80-$90
	BCC YMNOTFOUND		;COUNT < $80
	CPX #$90
	BCS YMNOTFOUND		;COUND >=$90

YMFOUND:
        LDA #$40
        STA CTRL
        LDA #$D4        ;MAKE BACKGROUND GREEN
        STA $20

YMFOUNDLP: JMP YMFOUNDLP

YMNOTFOUND:
        LDA #$40
        STA CTRL
        LDA #$46        ;MAKE BACKGROUND RED
        STA $20
YMNOTFOUNDLP: JMP YMNOTFOUNDLP