
	opt at-
	opt m-
	opt c+

	SECTION .text
	
	xdef transformVertexListLong
	xdef f1

	cnop 0,4
f1
	; simple leaf function
	;.frame sp,0,ra	; frame pointer is sp+0, return address in ra
	; incoming args: a0..a3 & 4*4(sp)
	; regs available: t0..t9
	; a0 = addr of string
	
	move	t1,a0
@b1
	lbu		t0,(a0)		; load unsigned byte pointed to by a0 into t0
	addu	a0,1		; add 1 to a0
	bne		t0,zero,@b1	; branch back to 1 if t0!=0
	subu	v0,a0,t1	; subtract t1 for a0, result in v0
	subu	v0,1		; subtract 1 from v0

	; v0 = length of string
	; ret values = v0..v1

	j	ra				; return to caller


	cnop 0,4
transformVertexListLong
	; args were VECTOR *longVerts, long numverts, long *transverts, long *transdepths

	subu sp,sp,12
	sw s0,0(sp)
	sw s1,4(sp)
	sw s2,8(sp)


	lw		t9,(a0)		; longVerts
	lw		a1,4(a0)	; numVerts
	lw		a2,8(a0)	; transVerts
	lw		a3,12(a0)	; transDepths

	lw		s0,16(a0)	; x,y,z translations
	lw		s1,20(a0)
	lw		s2,24(a0)

	sll		a1,a1,2		; multiply by four
	addu	a1,a3


	; get vertex 0
	lw		t0,(t9)		; load x
	lw		t1,4(t9)	; load y
	lw		t2,8(t9)	; load z

	add		t0,t0,s0
	add		t1,t1,s1
	add		t2,t2,s2

	sll		t1,t1,16	; shift y up (these two must add up to 16)
	and		t0,t0,0xffff
	or		t0,t0,t1	; combine x & y in one register

	and		t1,t2,0xffff

	; get vertex 1
	lw		t2,16(t9)	; load x
	lw		t3,20(t9)	; load y
	lw		t4,24(t9)	; load z

	add		t2,t2,s0
	add		t3,t3,s1
	add		t4,t4,s2
	
	sll		t3,t3,16	; shift y up (these two must add up to 16)
	and		t2,t2,0xffff
	or		t2,t2,t3	; combine x & y in one register

	and		t3,t4,0xffff

	; get vertex 2
	lw		t4,32(t9)	; load x
	lw		t5,36(t9)	; load y
	lw		t6,40(t9)	; load z

	add		t4,t4,s0
	add		t5,t5,s1
	add		t6,t6,s2

	sll		t5,t5,16	; shift y up (these two must add up to 16)
	and		t4,t4,0xffff
	or		t4,t4,t5	; combine x & y in one register

	and		t5,t6,0xffff



@transVertexLoop
	mtc2	t0, r0		; load gte registers
	mtc2	t1, r1	
	mtc2	t2, r2	
	mtc2	t3, r3	
	mtc2	t4, r4	
	mtc2	t5, r5


	; get vertex 0
	lw		t0,48(t9)	; load x
	lw		t1,52(t9)	; load y
	lw		t2,56(t9)	; load z

	add		t0,t0,s0
	add		t1,t1,s1
	add		t2,t2,s2

	sll		t1,t1,16	; shift y up (these two must add up to 16)
	and		t0,t0,0xffff
	or		t0,t0,t1	; combine x & y in one register

	and		t1,t2,0xffff

	; get vertex 1
	lw		t2,64(t9)	; load x
	lw		t3,68(t9)	; load y
	lw		t4,72(t9)	; load z

	add		t2,t2,s0
	add		t3,t3,s1
	add		t4,t4,s2
	
	sll		t3,t3,16	; shift y up (these two must add up to 16)
	and		t2,t2,0xffff
	or		t2,t2,t3	; combine x & y in one register

	and		t3,t4,0xffff

	RTPT				; equiv. gte_rtpt_b


	; get vertex 2
	lw		t4,80(t9)	; load x
	lw		t5,84(t9)	; load y
	lw		t6,88(t9)	; load z

	add		t4,t4,s0
	add		t5,t5,s1
	add		t6,t6,s2
	
	sll		t5,t5,16	; shift y up (these two must add up to 16)
	and		t4,t4,0xffff
	or		t4,t4,t5	; combine x & y in one register

	and		t5,t6,0xffff


	swc2	r12,(a2)	; store screen verts
	swc2	r13,4(a2)
	swc2	r14,8(a2)

	swc2	r17,(a3)	; store screen depths
	swc2	r18,4(a3)
	swc2	r19,8(a3)

	addu	a2,12
	addu	a3,12

	slt		at,a3,a1
	bne		at,zero,@transVertexLoop
	addu	t9,48		; use branch delay slot!


	lw s0,0(sp)
	lw s1,4(sp)
	lw s2,8(sp)
	addu sp,sp,12


	j	ra
	nop

