;/* depack7.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	|depack7_part0_begin|
		EXPORT	|depack7_part0_start|
		EXPORT	|depack7_part0_jump_program|
		EXPORT	|depack7_part0_end|

|depack7_part0_begin|
; /////////////////////////////////////////////////////////////////////////
|depack7_part0_start|
;		adr	r4, depack7_part0_begin
		adr	r8, depack7_data
		mov	r9, #1<<27
|depack7_main_loop|
		mvn	r0, #2 ; -3 + 4 = 1
		bl	|depack7_get_bits|
		mov	r0, r3, lsl #2
		bl	|depack7_get_bits|
		orr	r5, r3, #1<<8
		subs	r3, r3, #&fe
		beq     depack7_done
		bgt     depack7_short
		mvn	r0, #2 ; -3 + 4 = 1
		bl	|depack7_get_bits|
		add	r0, r3, r3, lsl #1
		bl	|depack7_get_bits|
|depack7_short|
		ldr	r10, [ r4, r3, lsl #2]
|depack7_decompress_nibbles_loop|
		movs	r5, r5, lsr #1
		blhi	|depack7_get_bits|
		cmp     r5, #0
		movne	r10, r10, ror #4
		bne	|depack7_decompress_nibbles_loop|
		str	r10, [ r4, #-4]!
		b 	depack7_main_loop

|depack7_done|
;		mov	r0, #0
		swi	"XOS_SynchroniseCodeAreas"
|depack7_part0_jump_program|
		b	|depack7_part0_jump_program|

|depack7_get_bits|
		add	r0, r0, #4
		mov	r3, #0
|depack7_get_bits_loop|
		subs	r9, r9, #1<<27
		ldreq	r7, [ r8], #4
		movs	r7, r7, lsr #1
		adc	r3, r3, r3
		subs	r0, r0, #1
		bgt	|depack7_get_bits_loop|
		eor	r10, r10, r3
		mov	pc, link
|depack7_data|
; /////////////////////////////////////////////////////////////////////////
|depack7_part0_end|

		END
