Exomizer

Aus Deutsches CPCWiki
Wechseln zu: Navigation, Suche

Bei Exomizer handelt es sich um einen effizienten Packer für den auch entsprechende Entpacker auf dem CPC existieren.

Entpacker-Code für SDAS

; ******************************************************
; **       Librería de rutinas SDCC para Amstrad CPC  **
; **       Raúl Simarro (Artaburu)    -   2009, 2012  **
; ******************************************************


;*************************************
; UNEXO
;*************************************


; Exomizer 2 Z80 decoder
; by Metalbrain
;
; optimized by Antonio Villena
;
; compression algorithm by Magnus Lind

;input: 	hl=compressed data start
;		de=uncompressed destination start
;
;		you may change exo_mapbasebits to point to any free buffer


.globl _cpc_UnExo

_cpc_UnExo::

;	POP AF
;	POP HL	;DESTINATION ADDRESS
;	POP DE	;SPRITE DATA	
;	PUSH AF
	
	LD IX,#2
	ADD IX,SP
	LD e,2 (IX)
	LD d,3 (IX)	;DESTINO
   	LD l,0 (IX)
	LD h,1 (IX)	;TEXTO ORIGEN
		
	;di
	;call deexo
	;ei
	;ret

deexo:          ld      iy, #exo_mapbasebits+11
                ld      a, (hl)
                inc     hl
                ld      b, #52
                push    de
                cp      a
exo_initbits:   ld      c, #16
                jr      nz, exo_get4bits
				.db #0xdd
				.db #0x69
				
                ;ld      ixl, c
                ld      de, #1           ;DE=b2
exo_get4bits:   call    exo_getbit      ;get one bit
                rl      c
                jr      nc, exo_get4bits
                inc     c
                push    hl
                ld      hl, #1
                ld      41(iy), c      ;bits[i]=b1 (and opcode 41 == add hl,hl)
exo_setbit:     dec     c
                jr      nz, exo_setbit-1 ;jump to add hl,hl instruction
                ld      -11(iy), e
                ld      93(iy), d      ;base[i]=b2
                add     hl, de
                ex      de, hl
                inc     iy
                pop     hl
                ;dec     ixl
				.db #0xdd
				.db #0x2d
				
                djnz    exo_initbits
                pop     de
                jr      exo_mainloop
exo_literalrun: ld      e, c            ;DE=1
exo_getbits:    dec     b
                ret     z
exo_getbits1:   call    exo_getbit
                rl      e
                rl      d
                jr      nc, exo_getbits
                ld      b, d
                ld      c, e
                pop     de
exo_literalcopy:ldir
exo_mainloop:   inc     c
                call    exo_getbit      ;literal?
                jr      c, exo_literalcopy
                ld      c, #239
exo_getindex:   call    exo_getbit
                inc     c
                jr      nc,exo_getindex
                ret     z
                push    de
                ld      d, b
                jp      p, exo_literalrun
                ld      iy, #exo_mapbasebits-229
                call    exo_getpair
                push    de
                rlc     d
                jr      nz, exo_dontgo
                dec     e
                ld      bc, #512+32      ;2 bits, 48 offset
                jr      z, exo_goforit
                dec     e               ;2?
exo_dontgo:     ld      bc, #1024+16     ;4 bits, 32 offset
                jr      z, exo_goforit
                ld      de, #0
                ld      c, d            ;16 offset
exo_goforit:    call    exo_getbits1
                ld      iy, #exo_mapbasebits+27
                add     iy, de
                call    exo_getpair
                pop     bc
                ex      (sp), hl
                push    hl
                sbc     hl, de
                pop     de
                ldir
                pop     hl
                jr      exo_mainloop    ;Next!

exo_getpair:    add     iy, bc
                ld      e, d
                ld      b, 41(iy)
                call    exo_getbits
                ex      de, hl
                ld      c, -11(iy)
                ld      b, 93(iy)
                add     hl, bc          ;Always clear C flag
                ex      de, hl
                ret

exo_getbit:     srl     a
                ret     nz
                ld      a, (hl)
                inc     hl
                rra
                ret
                                 
exo_mapbasebits:.ds    156             ;tables for bits, baseL, baseH

C-Code für SDCC zum Aufruf des Entpackers

void cpc_UnExo(const char *quelle, unsigned int ziel);

quelle: Zeigt auf die gepackten Daten ziel: Wohin soll entpackt werden