gimm.s 16.9 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 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721

/**************************************************************************
 *								          *
 *               Copyright (C) 1994, Silicon Graphics, Inc.       	  *
 *								          *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *								          *
 *************************************************************************/

/*
 * File:		gimm.s
 * Creator:		hsa@sgi.com
 * Create Date:		Fri Jun 24 13:55:27 PDT 1994
 *
 * This file holds the top-level of the IMM command processing, and
 * related routines.
 *
 */

 ############################################################################	
 #
 # The following code processes the IMM type display list commands.
 # Registers on input:	
 #	gfx0	- first word of display list command
 #	gfx1	- second word of display list command
 #	dinp	- points to *next* DL cmd, so back up for this one.
 #	
		.ent	doIMM
doIMM:
	# $2 is shifted in the delay slot of the branch that 
	# brought us here...
		
	# 'switch' to correct IMM command:
		andi	$2, $2, 0xfe		# shifted up 1 for offset
		lh	$2,(IMM_JMP_ADD)($2)

		jr	$2
	# consolidate some of the similar decoding...
		lbu	$1, (0-1)(dinp)	# pick off first field

		.end	doIMM
 #
 #
 #
 ############################################################################	


#ifdef LINE3D
	
 #############################################################################
 #
 # This code handles G_LINE3D. It's basically modified from Steve's triangle
 # code above. It picks off the two vertex indicies and calls the line code 
 #
 #
.name v0,	$1
.name v1,	$2
.name wd,	$3
.name vn,	$4
.name n,	$5

	
		
		.ent 	case_G_LINE3D
			
  case_G_LINE3D:
	# pick off flag field
		lbu	n, (0-4)(dinp)	# which normal?	
	# dinp points to next dl cmd, so back up to get line indices
 		lbu	v0, (0-3)(dinp)
		lbu	v1, (0-2)(dinp)
	# which normal?
		sll	n, n, 2			# word-size offset

	# this is a hack. we get the width, add 3 (0 means 'min' width)
	# and store it back to an unused DMEM location. We'll retrieve
	# it later and use it...
 		lbu	wd, (0-1)(dinp)
		addi	wd, wd, 3
		sh	wd, CLIP_STATE_TABLE(zero)

	# translate indices into DMEM offsets. Point buffer entries are
	# 40 bytes (yuk!) each... The interface (mbi.h) pre-multiplies
	# the indices by 10, so we just have to multiply by 4.
		sll	v0, v0, 2
		sll	v1, v1, 2

		
		addi	v0, v0, RSP_POINTS_OFFSET
		addi	v1, v1, RSP_POINTS_OFFSET
	
		sw	v0, (0+RSP_SCRATCH_OFFSET)(zero)
		sw	v1, (4+RSP_SCRATCH_OFFSET)(zero)
		lw	vn, RSP_SCRATCH_OFFSET(n)
	
		jal	doClip
		nop   	# delay slot, might do something useful here later
		j	GfxDone
		nop	# delay slot, might do something useful here later
		
		.end	case_G_LINE3D
	
.unname v0
.unname v1
.unname wd
.unname vn
.unname n
 #
 #
 #
 #############################################################################

 #############################################################################
 #
 # This code handles G_TRI1 in the line microcode.  It draws 3 lines (the edges
 # of the triangle).

.name v0,	$1
.name v1,	$2
.name wd,	$3
.name vn,	$4
.name n,	$5

		.ent	case_G_TRI1
  case_G_TRI1:	
		jal	Tri1_getnormal
		lbu	n, (0-4)(dinp)	# which normal?

		jal	Tri1_presetup
		nop
		jal	doClip		# draw first line
		nop

		jal	Tri1_getnormal
		lbu	n, (0-4)(dinp)	# which normal?

		jal	Tri1_presetup
		lbu	v0, (0-1)(dinp)
		jal	doClip		# draw first line
		nop
		
		jal	Tri1_getnormal
		lbu	n, (0-4)(dinp)	# which normal?

		jal	Tri1_presetup
		lbu	v1, (0-1)(dinp)
		jal	doClip		# draw first line
		nop
		
		j	GfxDone
	

  Tri1_presetup:
	# Use min width (0 + 3)
		addi	wd, zero, 3
		sh	wd, CLIP_STATE_TABLE(zero)

	# translate indices into DMEM offsets. Point buffer entries are
	# 40 bytes (yuk!) each... The interface (mbi.h) pre-multiplies
	# the indices by 10, so we just have to multiply by 4.
		sll	v0, v0, 2
		sll	v1, v1, 2
		
		addi	v0, v0, RSP_POINTS_OFFSET
		jr	return
		addi	v1, v1, RSP_POINTS_OFFSET

  Tri1_getnormal:
	# pick off flag field
	# dinp points to next dl cmd, so back up to get tri indices
		lbu	v0, (0-3)(dinp)
		lbu	v1, (0-2)(dinp)
		lbu	vn, (0-1)(dinp)
	# which normal?
		sll	n, n, 2			# word-size offset

		sw	v0, (0+RSP_SCRATCH_OFFSET)(zero)
		sw	v1, (4+RSP_SCRATCH_OFFSET)(zero)
		sw	vn, (8+RSP_SCRATCH_OFFSET)(zero)
		lw	vn, RSP_SCRATCH_OFFSET(n)

		sll	vn, v0, 2
		jr	return
		addi	vn, vn, RSP_POINTS_OFFSET


		.end	case_G_TRI1

.unname v0
.unname v1
.unname wd
.unname vn
.unname n
 #
 #
 #
 #############################################################################


#endif /* LINE3D */

#ifdef FAST3D	
		
 #############################################################################
 #
 # This code handles G_TRI1. It picks off the three vertex indicies and
 # calls the triangle setup code. 
 #
 #
.name v0,		$1
.name v1,		$2
.name v2,		$3
.name vn,		$4
.name n,		$5
.name tmp,		$6

		.ent	case_G_TRI1
	
  case_G_TRI1:	
	# pick off flag field
		lbu	n, (0-4)(dinp)	# which normal?
	# dinp points to next dl cmd, so back up to get tri indices
		lbu	v0, (0-3)(dinp)
		lbu	v1, (0-2)(dinp)
		lbu	v2, (0-1)(dinp)
	# which normal?
		sll	n, n, 2			# word-size offset

	# translate indices into DMEM offsets. Point buffer entries are
	# 40 bytes (yuk!) each... The interface (mbi.h) pre-multiplies
	# the indices by 10, so we just have to multiply by 4.
		sll	v0, v0, 2
		sll	v1, v1, 2
		sll	v2, v2, 2
	
		addi	v0, v0, RSP_POINTS_OFFSET
		addi	v1, v1, RSP_POINTS_OFFSET
		addi	v2, v2, RSP_POINTS_OFFSET
	
		sw	v0, (0+RSP_SCRATCH_OFFSET)(zero)
		sw	v1, (4+RSP_SCRATCH_OFFSET)(zero)
		sw	v2, (8+RSP_SCRATCH_OFFSET)(zero)
		lw	vn, RSP_SCRATCH_OFFSET(n)
	
		j	clipAndSetup
		lh	return_save,GFXDONE(zero)	# return to GfxDone:
		.end	case_G_TRI1

.unname v0
.unname v1
.unname v2
.unname vn
.unname n
.unname tmp
 #
 #
 #
 #############################################################################

#endif /* FAST3D */

#ifndef SPRITE2D
		
 #############################################################################
 #
 # This code handles G_POPMTX. It checks the stack depth, backs up the
 # stack pointer, then DMA's the matrix into DMEM, updates the state,
 # and loads the registers.
 # 
 #
.name param,		$1
.name mstack_p,		$19
.name mstack_max,	$3
.name mat_sz,		$18
.name mat_p,		$20
	
		.ent	case_G_POPMTX
	
  case_G_POPMTX:	
	# 'param' already filled in but not used

	# we can only pop the MODELVIEW stack

	# get pointer and stack size
		sbv     vconst[6],RSP_STATE_L_LEN(rsp_state)            # hi bit = light recalc
		lw	mstack_p,  RSP_STATE_MMTX_STACK_P(rsp_state)	# stack ptr
		lw	mstack_max, RSP_STATE_MMTX_STACK_MAX(rsp_state)	# end of stack
		addi	mat_p, zero, RSP_CURR_MMTX_OFFSET		# where to DMA matrix
		addi	mat_sz, zero, 63	# DMA expects sz-1	# DMA length -1
		sub	mstack_max, mstack_max, mstack_p		# size of stack
		addi	mstack_max, mstack_max, (-10*64)		#  ... - max size of stck
	
	# check matrix stack depth, bail if == 0
		bgez	mstack_max, GfxDone				# anything on stack?
		addi	mstack_p, mstack_p, -64				# stack is 1 mtx smaller
 ### BRANCH OCCURS TO GfxDone: IF NOTHING ON STACK


		jal	DMAproc						# DMA matrix from stack
		addi	$17, zero, 0					# DMA is a READ
	
		jal	DMAwait						# wait for DMA to finish
		addi    $3, zero, RSP_CURR_MPMTX_OFFSET                 # where to put MP matrix
	
	# update state, then jump to pre-multiply MxP
		j	mtx_MxP						# mult model * proj mtx
		sw	mstack_p,  RSP_STATE_MMTX_STACK_P(rsp_state)	# store new stack size

	
		.end	case_G_POPMTX
.unname param
.unname mstack_p
.unname mstack_max
.unname mat_sz
.unname mat_p
 #
 #
 #
 #############################################################################
	
#else /* SPRITE2D */		

 #############################################################################
 #
 # This code handles G_SPRITE2D_SCALEFLIP in the sprite microcode. 
 # It stuffs the user specified scale{x|y}, flip{x|y} parameters into
 # the sprite dmem structure	

.name fx,	$1
.name fy,	$2
.name sx,	$3
.name sy,	$4

		.ent	case_G_SPRITE2D_SCALEFLIP
  case_G_SPRITE2D_SCALEFLIP:	

		lbu	fx,	(0-6)(dinp) # flip x?
		lbu	fy,	(0-5)(dinp) # flip y?
		lhu	sx,	(0-4)(dinp) # scalex value
		lhu	sy,	(0-2)(dinp) # scaley value

		# Now stuff values into sprite structure
		sb	fx,	RSP_SP_FLIPX(in_bufp)
		sb	fy,	RSP_SP_FLIPY(in_bufp)
		sh	sx,	RSP_SP_SCALEX(in_bufp)
		sh	sy,	RSP_SP_SCALEY(in_bufp)
				
		j	GfxDone
		nop	# delay slot	

		.end	case_G_SPRITE2D_SCALEFLIP

.unname fx
.unname fy
.unname sx
.unname sy
 #
 #
 #
 #############################################################################

 #############################################################################
 #
 # This code handles G_SPRITE2D_DRAW in the sprite microcode. 
 # It stuffs the user specified screen{x|y} parameters into
 # the sprite dmem structure and then draws the sprite with
 # the values previously sent down for the other parameters

.name px,	$1
.name py,	$2

		.ent	case_G_SPRITE2D_DRAW
  case_G_SPRITE2D_DRAW:	

		lhu	px,	(0-4)(dinp) # scalex value
		lhu	py,	(0-2)(dinp) # scaley value

		# Now stuff values into sprite structure
		sh	px,	RSP_SP_PSCREENX(in_bufp)
		sh	py,	RSP_SP_PSCREENY(in_bufp)

		# Now actually draw the sprite

.unname px
.unname py
	
#include "gsprite.s"	
				
		j	GfxDone
		nop	# delay slot	

		.end	case_G_SPRITE2D_DRAW

 #
 #
 #
 #############################################################################
	
		

#endif /* SPRITE2D */
		
 #############################################################################
 #
 # this handles the G_MOVEWORD command, moving 1 word into dmem
 #
 #	
.name target,	$1
.name outptr,	$5
.name offset,	$2
	
		.ent	case_G_MOVEWORD
	
  case_G_MOVEWORD:	
 #	lbu	target, (0-6)(dinp)		  # index to address
 #	lbu	offset, (0-5)(dinp)		  # offset from address
		lbu	target, (0-5)(dinp)		  # index to address
		lhu	offset, (0-7)(dinp)		  # offset from address
		lh	outptr,(MOVEWORD_TBL)(target) # actual address
		add	outptr,outptr,offset		  #   ...plus offset
		j	GfxDone				  #
		sw	gfx1, 0(outptr)			  # store @ addr + off

		.end	case_G_MOVEWORD
	
.unname target
.unname outptr
.unname offset
 #
 #
 #############################################################################

 #############################################################################
 #
 # This code handles the G_TEXTURE.
 #
 #
.name	rmode, 		$2
.name	mask, 		$3
.name	sscale,		$4
.name	tscale,		$5
.name	tile,		$6
	
		.ent	case_G_TEXTURE
	
  case_G_TEXTURE:	

	# turn texture on or off:
		sw	gfx0, RSP_STATE_TEX_CMD(rsp_state)
		sw	gfx1, RSP_STATE_TEX_SCALE_S(rsp_state)
		lh	rmode, RSP_STATE_RENDER_L(rsp_state)
		andi	rmode, rmode, 0xfffd	# clear texture state
		andi	mask, gfx0, 0x01	# on bit
		sll	mask, mask, 1
		or	rmode, rmode, mask	# set texture on (maybe)
 		j	GfxDone
		sh	rmode, RSP_STATE_RENDER_L(rsp_state)
	
		.end	case_G_TEXTURE
	
.unname	rmode
.unname	mask
.unname	sscale
.unname	tscale
.unname	tile
	
 #############################################################################
 #
 # This code handles G_SETOTHERMODE_*.
 #
 #
.name modewd,	$3
 #		.name mask,	$4
.name mask,	$2
.name lenth,	$5
.name shft,	$6
.name waddr,	$7
.name minus1,	$8
	
		.ent	case_G_OTHERMODE
	
  case_G_SETOTHERMODE_H:
		j	doOtherMode
		addi	waddr, rsp_state, RSP_STATE_OTHER_H # delay slot
	
  case_G_SETOTHERMODE_L:
		addi	waddr, rsp_state, RSP_STATE_OTHER_L
	
		# this code is the same for both OTHERMODE commands...
 	doOtherMode:
		lw	modewd, 0(waddr)
		addi	minus1, zero, -1
	
		lbu	lenth, (0-5)(dinp)
		lbu	shft,  (0-6)(dinp)
	
		addi	mask, zero, 0x01
		sllv	mask, mask, lenth
		addi	mask, mask, -1
		sllv	mask, mask, shft
		xor	mask, mask, minus1
		and	mask, mask, modewd
		or	modewd, mask, gfx1
		sw	modewd, 0(waddr)
	
	# output to RDP
	# writes 64-bits at once. cmd byte already there.
	# use the regular RDP output routine, sharing code.
		lw	gfx0, RSP_STATE_OTHER_H(rsp_state)
		j	doRDPSend
		lw	gfx1, RSP_STATE_OTHER_L(rsp_state)

		.end	case_G_OTHERMODE
	
.unname modewd
.unname mask
.unname lenth
.unname shft
.unname waddr
.unname minus1
 #
 #
 #
 #############################################################################

#ifndef SPRITE2D	

 #############################################################################
 #
 # This code handles G_CULLDL.
 #
 # Ends display list if vertices n through m are mutually trivially rejected
 # (ie the volume described by these vertices is completely outside of the
 # trivial reject volume).
 #
.name cc,	$2
.name tmp,	$3
	
		.ent	case_G_CULLDL
case_G_CULLDL:
		andi	gfx0, gfx0, 0x3ff		# vertex to start on

#ifdef NEAR_CLIP_OFF
		ori	cc, zero, 0x7030		# initialize cc
#else /* NEAR_CLIP_OFF */
		ori	cc, zero, 0x7070		# initialize cc
#endif /* NEAR_CLIP_OFF */

VolCulLoop:
		lh	tmp, (RSP_POINTS_OFFSET+RSP_PTS_CC)(gfx0)
		addi	gfx0, gfx0, RSP_PTS_LEN
		bne	gfx0, gfx1, VolCulLoop		# loop through vtx's
		and	cc, cc, tmp			# is this vtx clipped?
 ### LOOP OCCURS if not all points have been checked

		beq	cc, zero, GfxDone		# continue if not culled
 # NOTE Delay Slot!!
							# If culled End DL
	
		.end	case_G_CULLDL
.unname cc
.unname tmp
 #
 #
 #
 #############################################################################

#endif /* SPRITE2D */	
	
 ### IMPORTANT!!!!  Do not place any code betweeen case_G_CULLDL and G_ENDDL

 #############################################################################
 #
 # This code handles G_ENDDL.
 #
 # Causes a 'pop' of the display list stack. If we pop an empty 
 # display list stack, that's an error and we end.
 #
.name stack_sz,	$2
.name stack_p,	$3
	
		.ent	case_G_ENDDL
	
  case_G_ENDDL:	
	# pop display list
		lb	stack_sz, RSP_STATE_DL_N(rsp_state)
		addi	stack_sz, stack_sz, -4
		bltz	stack_sz, TaskDone		# empty stack
		addi	stack_p, stack_sz, RSP_DLSTACK_OFFSET
		lw	inp,     0(stack_p)	# pointer of DL
		sb	stack_sz, RSP_STATE_DL_N(rsp_state)
 		j	GfxDone
		addi	dlcount, zero, 0
	
		.end	case_G_ENDDL
	
.unname stack_sz
.unname stack_p
 #
 #
 #
 #############################################################################

	
 #############################################################################
 #
 # This code handles G_SETGEOMETRYRMODE
 #
 # Any bit set 'on' in the incoming command is 'set' in the state.
 # Assumes gfx1 is all 0's, except some of the lower 16 bits.
 #
.name	rmode, 		$2
	
		.ent	case_G_SETGEOMETRYMODE
	
  case_G_SETGEOMETRYMODE:	
		lw	rmode, RSP_STATE_RENDER(rsp_state)
		or	rmode, rmode, gfx1
 		j	GfxDone
		sw	rmode, RSP_STATE_RENDER(rsp_state) # delay slot
	
		.end	case_G_SETGEOMETRYMODE
	
.unname	rmode
 #
 #
 #
 #############################################################################
	
	
 #############################################################################
 #
 # This code handles G_CLEARGEOMETRYMODE
 #
 # Any bit set 'on' in the incoming command is 'cleared' in the state.
 # Assumes gfx1 is all 0's, except some of the lower 16 bits.
 #
.name	rmode, 		$2
.name	mask, 		$3
	
		.ent	case_G_CLEARGEOMETRYMODE
	
  case_G_CLEARGEOMETRYMODE:	
		lw	rmode, RSP_STATE_RENDER(rsp_state)
		addi	mask, zero, -1
		xor	mask, mask, gfx1
		and	rmode, rmode, mask
 		j	GfxDone
		sw	rmode, RSP_STATE_RENDER(rsp_state) # delay slot
	
		.end	case_G_CLEARGEOMETRYMODE
	
.unname	rmode
.unname	mask
 #
 #
 #
 #############################################################################

 #############################################################################
 #
 # This code handles G_RDPHALF_1
 #
 # This received the 3rd quarter of a texrect or texrectflip command
 #
 		.ent	case_G_RDPHALF_1
	
    case_G_RDPHALF_1:
 		j	noYield			   # don't yield mid cmd
		sw	gfx1, RSP_STATE_RDPHALF(rsp_state) # save for later...
	
 		.end	case_G_RDPHALF_1
 #
 #
 #
 #############################################################################

 #############################################################################
 #
 # This code handles G_RDPHALF_CONT
 #
 # This received the 2nd 32 bits of a 64 bit string to send to the RDP.
 # It sends it (using the G_RDPHALF_2 code below) AND disables yield
 # so the data will not get interrupted by a yield.  This shoulb be used
 # only to send data which will be followed by more data from a G_RDPHALF_1
 # and G_RDPHALF_2 pair (or a G_RDPHALF_1 and G_RDPHALF_CONT pair).
 #
 		.ent	case_G_RDPHALF_CONT
	
    case_G_RDPHALF_CONT:
		ori	$2, zero, 0		# disable yield

 		.end	case_G_RDPHALF_CONT
 #
 #
 #
 #############################################################################

 #############################################################################
 #
 # This code handles G_RDPHALF_2
 #
 # This received the 4rd quarter of a texrect or texrectflip command
 # and sends it and the 3rd quarter (ie the 2nd half) to the rdp.
 #
 		.ent	case_G_RDPHALF_2
	
    case_G_RDPHALF_2:
 		j	doRDPSend		   # jmp to send routine
		lw	gfx0, RSP_STATE_RDPHALF(rsp_state) # retrieve 3rd qtr
	
 		.end	case_G_RDPHALF_2
 #
 #
 #
 #############################################################################