gloaduc.s 2.43 KB
/*
 * File:		gloaduc.s
 * Creator:		yasu@rd3.nintendo.co.jp
 */

#ifdef	SWITCH_UCODE
 #------------------------------------------------------------------
 #  マイクロコードの SWITCH 処理	12 insts.	計 27insts.
 #					SMARTINP で          +2 insts.
 #					DMA2BUF/DMANOWAIT で +3 insts.
 #					DMANOWAIT2        で +6 insts.
 #
 #    +--------------+------------+------------+------------+
 #    |G_RDPHALF_1   |                                      |
 #    +--------------+------------+------------+------------+
 #    |           Pointer for ucode (Data section)          |
 #    +--------------+------------+------------+------------+
 #    |G_SWITCH_UCODE|            |   (ucode_data size)-1   |
 #    +--------------+------------+------------+------------+
 #    |           Pointer for ucode (Text section)          |
 #    +--------------+------------+------------+------------+
 #
case_G_SWITCH_UCODE:	
#if	(defined(DMANOWAIT2))
	addi	$6, outp, -(RSP_OUTPUT_OFFSET+1)
	bgezal	$6, OutputCloseFlush
	nop
#endif
#if	(defined(DMA2BUF)||defined(DMANOWAIT)||defined(DMANOWAIT2))
	jal	DMAwait
	lw	$6,  RSP_STATEP_FIFO_OUTP(zero)
	mtc0	$6,  CMD_END
#endif
	# これ以降共通のコードとなる
	addi	$19, gfx1, 0				# Text Section
	sw	gfx1, (RSP_TASK_OFFSET+OS_TASK_OFF_UCODE)(zero)
							# Ucode の保存
#ifdef	SMARTINP
	add	inp, inp, dinp
	sub	inp, inp, dlcount
#endif
	sw	inp, (RSP_TASK_OFFSET+OS_TASK_OFF_DATA)(zero)
	addi	$20, zero, TASKBASELO			# Load into IMEM
	jal	DMAread
	addi	$18, zero, (0x1000-0x0080-26*4-1)	# gloaduc
	lw	$19, RSP_STATEP_RDPHALF(zero)		# Data Section
	addi	$20, zero, 0x0000			# Load into DMEM
	jal	DMAread
	andi	$18, gfx0, 0xffff			# Get length
	addi	$1, zero, RSP_TASK_OFFSET		# Set taskp
	addi	return, zero, TASKBASELO	# Wiat DMA & Jump to ucode top
#endif

 #--------------------------------
 #  DMA 待ち	4 insts.
 #
.name	tmp,		$11
DMAwait:		
		mfc0	tmp, DMA_BUSY
		bne	tmp, zero, DMAwait
		nop
		jr	return
.unname	tmp

 #--------------------------------
 #  DMA 処理	11 insts.
 #
.name	mem_addr,	$20
.name	dram_addr,	$19
.name	dma_len,	$18
.name	iswrite,	$17
.name	tmp,		$11

DMAread:	add	iswrite, zero, zero
DMAproc:	mfc0	tmp, DMA_FULL
		bne	tmp, zero, DMAproc
		nop
	# set DMA registers:
		mtc0	mem_addr, DMA_CACHE
	# handle writes:
		bgtz	iswrite, DMAWrite
 		mtc0	dram_addr, DMA_DRAM
		jr	return
		mtc0	dma_len, DMA_READ_LENGTH
	DMAWrite:
		jr	return
		mtc0	dma_len, DMA_WRITE_LENGTH
.unname	mem_addr
.unname	dram_addr
.unname	dma_len
.unname	iswrite
.unname	tmp