include	clib.inc
include	conio.inc

	public	@rsunzipch
	public	@rsunzipat

_TEXT	SEGMENT

@rsunzipat PROC
	lodsb
	mov	dl,al
	and	dl,0F0h
	cmp	dl,0F0h
	jne	rcunzipat_01
	mov	ah,al
	lodsb
	and	ax,0FFFh
	mov	dx,ax
	lodsb
	call	rcunzipat_04
    rcunzipat_00:
	stosb
	inc	di
	dec	dx
	jz	rcunzipat_02
	dec	cx
	jnz	rcunzipat_00
	jmp	rcunzipat_03
    rcunzipat_01:
	call	rcunzipat_04
	stosb
	inc	di
    rcunzipat_02:
	dec	cx
	jnz	@rsunzipat
    rcunzipat_03:
	ret
    rcunzipat_04:
	xor	bx,bx
	mov	ah,al
	and	ax,0FF0h
	shr	al,4
	mov	bl,al
	mov	al,ss:[bx+at_background]
	mov	bl,ah
	or	al,ss:[bx+at_foreground]
	ret
@rsunzipat ENDP

@rsunzipch PROC
	lodsb
	mov	dl,al
	and	dl,0F0h
	cmp	dl,0F0h
	jnz	rsunzipch_01
	mov	ah,al
	lodsb
	and	ax,0FFFh
	mov	bx,ax
	lodsb
    rsunzipch_00:
	stosb
	inc	di
	dec	bx
	jz	rsunzipch_02
	dec	cx
	jnz	rsunzipch_00
	jmp	rsunzipch_03
    rsunzipch_01:
	stosb
	inc	di
    rsunzipch_02:
	dec	cx
	jnz	@rsunzipch
    rsunzipch_03:
	ret
@rsunzipch ENDP

_TEXT	ENDS

	END