; ARM code for screen.c V1.21 30/08/04
; Copyright 2008 Jeffrey Lee
; This file is part of WOUM.
; WOUM is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
; WOUM is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; You should have received a copy of the GNU General Public License
; along with WOUM.  If not, see <http://www.gnu.org/licenses/>.

	GET	bindings.s

	AREA	armscreen, CODE, READONLY

	EXPORT	screen_qcls

	FBEGIN screen_qcls,1
	; R0 -> screen, R1 = length
	STMFD R13!,{R4-R11,R14}
	; Re-position cursor...
	SWI &100+31
	SWI &100
	SWI &100
	; Screens are meant to be a multiple of 256 bytes, or 64 words...
	; R2-R12,R14 are free, 12 words in total...
	MOV R2,#0
	MOV R3,#0
	MOV R4,#0
	MOV R5,#0
	MOV R6,#0
	MOV R7,#0
	MOV R8,#0
	MOV R9,#0
	MOV R10,#0
	MOV R11,#0
	MOV R12,#0
	MOV R14,#0
screen_qclsloop
	STMIA R0!,{R2-R12,R14} ; 12
	STMIA R0!,{R2-R12,R14} ; 24
	STMIA R0!,{R2-R12,R14} ; 36
	STMIA R0!,{R2-R12,R14} ; 48
	STMIA R0!,{R2-R12,R14} ; 60
	STMIA R0!,{R2-R5} ; 64
	SUBS R1,R1,#256
	LDMEQFD R13!,{R4-R11,PC}
	CMP R1,#256
	BLT screen_qcls_uhoh ; For dodgy screens or my bad memory
	STMIA R0!,{R2-R12,R14} ; 12
	STMIA R0!,{R2-R12,R14} ; 24
	STMIA R0!,{R2-R12,R14} ; 36
	STMIA R0!,{R2-R12,R14} ; 48
	STMIA R0!,{R2-R12,R14} ; 60
	STMIA R0!,{R2-R5} ; 64
	SUBS R1,R1,#256
	LDMEQFD R13!,{R4-R11,PC}
	CMP R1,#256
	BLT screen_qcls_uhoh
	STMIA R0!,{R2-R12,R14} ; 12
	STMIA R0!,{R2-R12,R14} ; 24
	STMIA R0!,{R2-R12,R14} ; 36
	STMIA R0!,{R2-R12,R14} ; 48
	STMIA R0!,{R2-R12,R14} ; 60
	STMIA R0!,{R2-R5} ; 64
	SUBS R1,R1,#256
	LDMEQFD R13!,{R4-R11,PC}
	CMP R1,#256
	BLT screen_qcls_uhoh
	STMIA R0!,{R2-R12,R14} ; 12
	STMIA R0!,{R2-R12,R14} ; 24
	STMIA R0!,{R2-R12,R14} ; 36
	STMIA R0!,{R2-R12,R14} ; 48
	STMIA R0!,{R2-R12,R14} ; 60
	STMIA R0!,{R2-R5} ; 64
	SUBS R1,R1,#256
	LDMEQFD R13!,{R4-R11,PC}
	CMP R1,#256
	BGE screen_qclsloop
screen_qcls_uhoh
	STR R2,[R0],#4 ; Easy way out :)
	SUBS R1,R1,#4
	BGT screen_qcls_uhoh
	LDMFD R13!,{R4-R11,PC}

	END
