gtmain.s 10.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438

/*
 * Copyright 1995, Silicon Graphics, Inc.
 * ALL RIGHTS RESERVED
 *
 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
 * States.   Use of a copyright notice is precautionary only and does not
 * imply publication or disclosure.
 *
 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:	
 * Use, duplication or disclosure by the Government is subject to restrictions
 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
 * Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
 *
 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
 * GRAPHICS, INC.
 *
 */
	
/*
 * File:		gtmain.s
 * Creator:		hsa@sgi.com
 * Create Date:		Wed Oct 11 14:14:50 PDT 1995
 *
 * This is the main file for the TURBO 3D graphics task for the RSP.
 * The 'turbo' task has a _greatly_ reduced feature set, but draws
 * very fast. Use at your own risk.
 *
 */


#include <rsp.h>
#include <rcp.h>
#include <sptask.h>
#include <mbi.h>

		.text	TASKBASE	# this is coordinated with rspboot.s
		.data	0x0
	
#include "gtdmem.h"	
#include "../gfx_regs.h"

.unname return_save	# make room for third DL word
.name	gfx2,	$30

		.text

	#################################################################
	#
	#  Begin task initialization
	#
	#  Register $1 holds the task header address
	# format for the task header:
	#
	# (see sptask.h)
	#

	# set state pointer:
		addi	rsp_state, zero, RSP_STATE_OFFSET

#include "gtinit.s"
	
		.ent	main

	#################################################################
	#
	# Note about display list command processing:	
	#
	#    - 'inp' always points to the "next" DL command in DRAM. This
	# 	is the pointer pushed on the stack and used to retrieve the
	#	next block of DL commands.
	#
	#    - 'dinp' is the local pointer in DMEM to the part of the display
	#	list in DMEM.
	#
	#    - 'dlcount' parallels dinp, counting down the remaining DL
	#	commands in DMEM.
	#
	# So when (dlcount == 0) we need to fetch more display list.
	#
	#################################################################

DMAWaitDL:
		jal	DMAwait
		nop
	
.name	gfx3,	$3	# global state (used briefly)
 	# process gfx list:	
		addi	dinp, zero, RSP_DLINPUT_OFFSET
DecodeDL:	lw	gfx3,  0(dinp)	# global state
		lw	gfx0,  4(dinp)
		lw	gfx1,  8(dinp)
		lw	gfx2, 12(dinp)

	# advance these pointers after consuming gfx0/1/2/3:
		addi	inp, inp, 16
		addi	dinp, dinp, 16
		addi	dlcount, dlcount, -16
	
	# load global state. If statep == 0, then skip
		beq	gfx3, zero, SkipGlob
 		add	$19, zero, gfx3
		jal	AddrFixup
		addi	$20, zero, RSP_GLOB_STATE_OFFSET
 		addi	$18, zero, RSP_GLOB_STATE_SIZE8 - 1
		jal	DMAproc
		addi	$17, zero, 0
	
	# wait for state to load. Can't do anything while we wait
		jal	DMAwait
		nop
	
	# process global state
		jal	GlobStateProc
		nop
.unname gfx3
	
    SkipGlob:
	# load object state. If statep == 0, then the
	# display list is done. (no more objects)
		beq	gfx0, zero, TaskDone
 		add	$19, zero, gfx0
		jal	AddrFixup
		addi	$20, zero, RSP_OBJ_STATE_OFFSET
 		addi	$18, zero, RSP_OBJ_STATE_SIZE8 - 64 - 1
		jal	DMAproc
		addi	$17, zero, 0

	# wait for state to load:
		jal	DMAwait
		nop

	# start vertex load (if !NULL):
.name	n, $5
.name  v0, $6
		beq	gfx1, zero, VtxDontLoad
 		add	$19, zero, gfx1
		lb	n, RSP_STATE_VTXCOUNT(rsp_state)
		lb	v0, RSP_STATE_VTXV0(rsp_state)
		jal	AddrFixup
		addi	$20, zero, RSP_POINTS_OFFSET
	# offset by v0:
		sll	v0, v0, 4
		add	$20, $20, v0
	# bring in n*16 bytes of data:	
		sll	n, n, 4
		addi	$18, n, -1
.unname n
.unname v0
		jal	DMAproc
		addi	$17, zero, 0
    VtxDontLoad:
	
	# do state processing:
		jal	ObjStateProc
		nop

	# wait for vertex load:
		jal	DMAwait
		nop

.name	n, $5
.name	tmp, $6
#if 1
	# check state for XFM_ONLY
		lb	n, RSP_STATE_FLAG(rsp_state)
		andi	tmp, n, GT_FLAG_XFM_ONLY
		bgtz	tmp, TriDontLoad
#endif
.unname	tmp

	# start tri load (if !NULL):
		lb	n, RSP_STATE_TRICOUNT(rsp_state)
		beq	n, zero, TriDontLoad
 		add	$19, zero, gfx2
		jal	AddrFixup
		addi	$20, zero, RSP_TRIN_OFFSET
		sll	n, n, 2
 		addi	$18, n, -1
		lb	n, RSP_STATE_FLAG(rsp_state)	# prepare for vtx
		jal	DMAproc
		addi	$17, zero, 0
    TriDontLoad:
		
	# check state, see if we need to transform points:
#if 1
		andi	n, n, GT_FLAG_NO_XFM
		bgtz	n, VtxDontXFM
		nop
#endif

.unname n
	# transform vertex list:
		jal	VtxProc
		nop

    VtxDontXFM:
	# wait for tri list load (or vertex write):
		jal	DMAwait
		nop

	# process tri list:
		jal	TrinProc
		nop


GfxDone: 	# we're done with this one, do the next one (if available)...
	#
	# stick our head up, see if we need to yield the SP. If so,
	# checkpoint everything then exit.
	#		
.name 	yield,		$2
.name	overeturn,	$21	# return address from loadOverlay
		mfc0	yield, SP_STATUS		# need to yield?
		andi	yield, yield, SP_STATUS_YIELD	#
		bne	yield, zero, RSPYield		#
		nop
.unname yield						#
.unname overeturn

noYield:						#
 		bgtz	dlcount, DecodeDL		#
		nop					#
		j	LoadDL				#
		lh	return, DMAWAITDL(zero)		# return to DMAWaitDL
							#
		.end	main				#
							#
#include "../gdone.s"
	#
	#
	##################################################################

	##################################################################
	#
	# start the DMA of the display list into DMEM.
	#
	# Always reads RSP_DLINPUT_SIZE8 bytes into the buffer.
	#
	# Registers upon call:
	#		inp	pointer to read from
	#		return	where to go when we're done
	#
	# Registers upon return:
	#		dlcount	size actually read (bytes)
	#		dinp	pointer to data we read in
	#
	# Registers used:
	#		return, zero, inp, dlcount, dinp
	#
		.ent	LoadDL
LoadDL:		
 		addi	dlcount, zero, RSP_DLINPUT_SIZE8
		add	$21, zero, return
 		addi	$20, zero, RSP_DLINPUT_OFFSET
		add	$19, zero, inp
 		addi	$18, zero, (RSP_DLINPUT_SIZE8 - 1)
		jal	DMAproc
		addi	$17, zero, 0
		jr	$21
		addi	dinp, zero, RSP_DLINPUT_OFFSET # delay slot

		.end LoadDL
	#
	#
	##################################################################

	##################################################################
	#
	# Address Fix-up routine.
	#
	# Takes a segment/offset address in register $19, computes
	# the proper DRAM address using the segment table. Returns
	# the answer in register $19
	#
	# (The use of register $19 is NOT random... It's the DRAM
	# address used in DMAproc, often the next thing called.)
	#
	# This code is shared among several routines, the registers
	# used are chosen not to conflict with those.
	#
.name dma_addr,	$19
.name mask, 	$11
.name seg_id,	$12
.name seg_ptr,	$13
		.ent	AddrFixup
    AddrFixup:
		lw	mask, SEGADDR_MASK_OFFSET(zero)
		srl	seg_id, dma_addr, 22
		andi	seg_id, seg_id, 0x3c
		and	dma_addr, dma_addr, mask
		add	seg_ptr, zero, seg_id
		lw	seg_id, RSP_SEG_OFFSET(seg_ptr)
		jr	return
		add	dma_addr, dma_addr, seg_id	# delay slot
		.end	AddrFixup
.unname dma_addr
.unname mask
.unname seg_id
.unname seg_ptr
	#
	##################################################################
	

	##################################################################
	#
	# Procedure to do DMA reads/writes.
	#
	# Registers:
	#
	#	$20	mem_addr
	#	$19	dram_addr
	#	$18	dma_len
	#	$17	iswrite?
	#
	#	$11	used as tmp
	#
.name	mem_addr,	$20
.name	dram_addr,	$19
.name	dma_len,	$18
.name	iswrite,	$17
.name	tmp,		$11

DMAproc:
	# request DMA access: (get semaphore)
		mfc0	tmp, SP_RESERVED
		bne	tmp, zero, DMAproc		
		# note delay slot
	# wait for not FULL:
	DMAFull:
		mfc0	tmp, DMA_FULL
		bne	tmp, zero, DMAFull
		nop
	# set DMA registers:
		mtc0	mem_addr, DMA_CACHE
	# handle writes:
		bgtz	iswrite, DMAWrite
 		mtc0	dram_addr, DMA_DRAM

		j	DMADone
		mtc0	dma_len, DMA_READ_LENGTH

	DMAWrite:
		mtc0	dma_len, DMA_WRITE_LENGTH
	DMADone:				
		jr	return
		mtc0	zero, SP_RESERVED	# delay slot
.unname	mem_addr
.unname	dram_addr
.unname	dma_len
.unname	iswrite
.unname	tmp
	#
	#
	##################################################################
	
	##################################################################
	#
	# Procedure to do DMA waits.
	#
	# Registers:
	#
	#	$11	used as tmp
	#
.name	tmp,	$11
	
DMAwait:		
	# request DMA access: (get semaphore)
		mfc0	tmp, SP_RESERVED
		bne	tmp, zero, DMAwait
		# note delay slot
	WaitSpin:
		mfc0	tmp, DMA_BUSY
		bne	tmp, zero, WaitSpin
		nop
		jr	return
		mtc0	zero, SP_RESERVED	# delay slot
.unname	tmp
	#
	#
	##################################################################
	
	##################################################################
	#
	# other "modules" are appended by #include
	#

 #============================================================================
 #==== Yield module
 #============================================================================
#define YIELD_RESTART
#define YIELD_STOP
#include "../gyield.s"
#undef YIELD_STOP
#undef YIELD_RESTART

 #============================================================================
 #==== Output module (either DRAM or directly to XBUS)
 #============================================================================
#ifdef OUTPUT_DRAM
#   include "../goutdram.s"
#else
#ifdef OUTPUT_FIFO
#   include "../goutfifo.s"
#else
#   include "../goutxbus.s"
#endif
#endif

 #============================================================================
 #==== Process the 'state' of the object 
 #============================================================================
#include "gtstate.s"
	
 #============================================================================
 #==== Process the vertices of the object
 #============================================================================
#include "gtvtx.s"
	
 #============================================================================
 #==== Process the triangles of the object
 #============================================================================
#include "gtsetup.s"

	EndOfProg:
		.print	__FILE__
		.print	" : IMEM used %d instructions ", (EndOfProg - 0x04001000)/4
		.print  "(must be < 1024).\n"
		.dmax	4096
	#
	#
	##################################################################