;/* depack5.s */

;****************************************************************************
;*
;*  Copyright (C) 2000-2001 Eli-Jean R. Leyssens, aka Pervect of Topix
;*
;*  This file is part of the CodePressor package.
;*
;*  CodePressor 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 2 of the License, or
;*  (at your option) any later version.
;*
;*  CodePressor 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 CodePressor; if not, write to the Free Software
;*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
;*
;*  Eli-Jean R. Leyssens can be reached via email at eli@dnd.utwente.nl
;*  snail: E-J.R. Leyssens, Schivelbeinerstr. 5, 10439 Berlin, Germany
;*
;***************************************************************************/

		AREA 	|C$$code|, CODE, READONLY

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
link	RN 14
		EXPORT	|depack5_part0_begin|
		EXPORT	|depack5_part0_start|
		EXPORT	|depack5_part0_jump_program|
		EXPORT	|depack5_part0_end|

|depack5_part0_begin|
; /////////////////////////////////////////////////////////////////////////
|depack5_part0_start|
;		adr	r4, |depack5_part0_begin|
		adr	r2, depack5_data
|depack5_main_loop|
		tst 	r4, #3
 		strb 	r5, [ r4], #-1	; We don't care about overwrite of
					; lower byte of part0_start
		ldreqb 	r3, [ r2], #1
		andeqs 	r0, r3, #&f0
		bne	depack5_part0_continue
		adr	r6, |depack5_part0_begin| - 4
|depack5_eor_loop|
		ldrb	r5, [ r4, #1]!
		ldrb	r3, [ r4, #4]
		eor	r3, r3, r5
		strb	r3, [ r4, #4]
		cmp	r4, r6
		blt	depack5_eor_loop
		swi	"XOS_SynchroniseCodeAreas"
|depack5_part0_jump_program|
		b	|depack5_part0_jump_program|
|depack5_part0_continue|
	   	movs 	r3, r3, lsr #1
		ldrccb	r5, [ r4, r0, lsr #2]
		ldrcsb	r5, [ r2], #1
		b	depack5_main_loop

|depack5_data|
; /////////////////////////////////////////////////////////////////////////
|depack5_part0_end|

		END
