	dc.l $00000000,	EntryPoint,	ErrorTrap,	ErrorTrap	;00
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;10
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;20
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;30
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;40
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;50
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;60
	dc.l HInt,	ErrorTrap,	VInt,		ErrorTrap	;70
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;80
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;90
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;A0
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;B0
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;C0
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;D0
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;E0
	dc.l ErrorTrap,	ErrorTrap,	ErrorTrap,	ErrorTrap	;F0

check_sum equ	$0000
;------------------------------------------------------------------------
	dc.b	'SEGA GENESIS    '	;100
	dc.b	'(C)T-xx 2008.06 '	;110 release year.month
	dc.b	'YM2612 Detune Bu'	;120 Japan title
	dc.b	'g               '	;130
	dc.b	'                '	;140
	dc.b	'YM2612 Detune Bu'	;150 US title
	dc.b	'g               '	;160
	dc.b	'                '	;170
	dc.b	'GM T-XXXXXX XX'  	;180 product #, version
	dc.w	check_sum         	;18E check sum
	dc.b	'J               '	;190 controller
	dc.l	$00000000,$0007ffff,$00ff0000,$00ffffff		;1A0
	dc.b	'                '	;1B0
	dc.b	'                '	;1C0
	dc.b	'                '	;1D0
	dc.b	'                '	;1E0
	dc.b	'JUE             '	;1F0


ErrorTrap:
	jmp	ErrorTrap

HInt:
VInt:
	rte

EntryPoint:
	move.w #$FFFF,D0
Loop1:
	dbf D0,Loop1

Loop2:
	move.b #1,$A11100	;BUSREQ
	move.b #1,$A11200	;RESET
	btst.b #0,$A11100
	bne	Loop2

	;Set channel 3 global settings
	move.b #$B2,D0
	move.b #$07,D1	;Set algorithm to 7 (4 channel parallel)
	bsr WriteYm2612
	move.b #$B6,D0
	move.b #$C0,D1	;Set L/R,AMS/PMS
	bsr WriteYm2612

	;Initialize channel 3 op 4 with an instant on/instant off envelope
	move.b #$4E,D0
	move.b #$00,D1	;Set TL
	bsr WriteYm2612
	move.b #$5E,D0
	move.b #$1F,D1	;Set KS/AR
	bsr WriteYm2612
	move.b #$6E,D0
	move.b #$00,D1	;Set AM/DR
	bsr WriteYm2612
	move.b #$7E,D0
	move.b #$00,D1	;Set SR
	bsr WriteYm2612
	move.b #$8E,D0
	move.b #$0F,D1	;Set SL/RR
	bsr WriteYm2612
	move.b #$9E,D0
	move.b #$00,D1	;Set SSG-EG
	bsr WriteYm2612

	;Set DT/MULTI with the maximum negative detune value
	move.b #$3E,D0
	move.b #$70,D1
	bsr WriteYm2612

	;Set channel 3 frequency
	move.b #$A2,D0
	move.b #$00,D1
	bsr WriteYm2612
	move.b #$A6,D0
	move.b #$00,D1
	bsr WriteYm2612

	;Send a key on event to channel 3
	move.b #$28,D0
	move.b #$F2,D1
	bsr WriteYm2612

	jmp	ErrorTrap


WriteYM2612:
	btst #7,$A04000
	bne WriteYM2612
	move.b D0,$A04000
WriteYM2612Data:
	btst #7,$A04000
	bne WriteYM2612Data
	move.b D1,$A04001
	rts
