;/* depack3.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	|depack3_part0_begin|
		EXPORT	|depack3_part0_start|
		EXPORT	|depack3_part0_adrdata|
		EXPORT	|depack3_part0_jump_program|
		EXPORT	|depack3_part0_data|
		EXPORT	|depack3_part0_end|


|depack3_part0_begin|
; /////////////////////////////////////////////////////////////////////////
|depack3_part0_start|
;		adr	r4, |depack3_part0_begin|
|depack3_part0_adrdata|
		adr	r8, |depack3_part0_data|
		mov	r9, #0
|depack3_main_loop|
		bl	depack3_get_nibble
		ldr	r10, [ r4, r3, lsl #2]
		ldrb	r2, [ r8], #1
		mov	r0, #32
|depack3_decompress_nibbles_loop|
		movs 	r2, r2, lsr #1
		blcs	depack3_get_nibble
		subs	r0, r0, #4
		bgt	depack3_decompress_nibbles_loop
		str	r10, [ r4, #-4]!
		cmp	r4, #&8000
		bne	depack3_main_loop
;		mov	r0, #0
		swi	"XOS_SynchroniseCodeAreas"
|depack3_part0_jump_program|
		b	|depack3_part0_jump_program|

|depack3_get_nibble|
		eors	r9, r9, #1<<31
		ldrmib	r7, [ r8], #1
		movpl	r7, r7, lsr #4
		and	r3, r7, #15
		eor	r10, r10, r3, ror r0
		mov	pc, r14

|depack3_part0_data|
; /////////////////////////////////////////////////////////////////////////
|depack3_part0_end|

		END
