R0	RN	0
R1	RN	1
R2	RN	2
R3	RN	3
R4	RN	4
R5	RN	5
R6	RN	6
R7	RN	7
R8	RN	8
R9	RN	9
R10	RN	10
R11	RN	11
R12	RN	12
R13	RN	13
R14	RN	14
PC	RN	15

	AREA	arm_tpf, CODE, READONLY

	EXPORT TpfDraw_ARM_DoDrawList

TpfDraw_ARM_DoDrawList
	STMFD R13!,{R0-R12,R14}
	ADD R4,R13,#14*4
	LDR R4,[R4] ; Get list ptr
	; r0 = screen width
	; r1 = screen height
	; r2 = screen stride
	; r3 = screen buffer
	; r4 = pointer to draw list
	ADD R2,R2,R0 ; Get screen width in bytes
xloop
	LDR R9,[R4],#4 ; Get first object ptr
objloop
	CMP R9,#0
	BEQ list_end
objloop2
	MOV R11,R3 ; Updatable screen ptr
	MOV R12,R1 ; Updatable height
	; Now load data from object...
	LDMIA R9,{R5-R9} ; R5=Z, R6=texture ptr, R7=y, R8=y scale, R9=next ptr
drawloop
	MOVS R10,R7,ASR #16 ; Fit CMP R10,#0 in here...
	BLT skippix ; Skip single pixel
	LDRB R10,[R6,R10] ; Get pixel
	CMP R10,#255 ; Use white as mask colour
	STRNEB R10,[R11]
skippix
	ADD R7,R7,R8 ; Increase sprite pos
	CMP R7,#&400000 ; Skip rest of sprite if gone off bottom
	BGE objloop
	ADD R11,R11,R2 ; Next line
	SUBS R12,R12,#1 ; Decrease count
	BGT drawloop
	CMP R9,#0
	BNE objloop2 ; Next object
list_end ; Next x pos...
	ADD R3,R3,#1
	SUBS R0,R0,#1
	BGT xloop
	LDMFD R13!,{R0-R12,PC}^
