News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Arnaud

exoopt / cpc_unexo in C

Started by Arnaud, 13:02, 15 October 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Arnaud

Hello,

i'm looking for exoopt / cpc_unexo exomizer decruncher coded in C, in order to add this nice feature to wincpctelera.

I used exodecr.c from exomizer but it's not compatible with exoopt used on CPC.

I haven't found a C version on internet but maybe someone knows it.

Thanks,
Arnaud.

roudoudou

Exomizer isn't slow enough you want to use a C version of it?


You can put the assembly decrunch version of metalbrain in a C function, it will be faster to execute and smaller in code size.

Arnaud

Quote from: roudoudou on 15:04, 15 October 16
Exomizer isn't slow enough you want to use a C version of it?


You can put the assembly decrunch version of metalbrain in a C function, it will be faster to execute and smaller in code size.

It's for my Windows API implementation of CPCTelera, speed is not a problem on my Core i5  ;D

roudoudou


Arnaud

#4
Quote from: roudoudou on 17:55, 15 October 16
ok, so exodecr is in the archive in ANSI-C
https://bitbucket.org/magli143/exomizer/wiki/downloads/exomizer209.zip

Thanks, but it's exactly my problem, exodecr or exoraw is not compatible with exoopt.exe (it's my analysis)
In order to decrunch file compressed with exoopt we have to use UnExoOpt.s from cpcrslib (cpc_UnExo function) or decompressor from https://sourceforge.net/p/emuscriptoria/code/HEAD/tree/deexo/.

[attach=2]

But all decrunch functions are coded in Z80 assembly and i am not able to convert them to C ansi to use in my Windows code.

SRS

how about running it inside a sub-programm-c-z80 emulator under windows and giving back result to your code ?

like using http://www.mathematik.uni-ulm.de/users/ag/yaze-ag/ ?

Docent

#6
Quote from: Arnaud on 20:24, 15 October 16
Thanks, but it's exactly my problem, exodecr or exoraw is not compatible with exoopt.exe (it's my analysis)
In order to decrunch file compressed with exoopt we have to use UnExoOpt.s from cpcrslib (cpc_UnExo function) or decompressor from https://sourceforge.net/p/emuscriptoria/code/HEAD/tree/deexo/.

[attach=2]

But all decrunch functions are coded in Z80 assembly and i am not able to convert them to C ansi to use in my Windows code.

Did you check this one?
https://sourceforge.net/p/emuscriptoria/code/HEAD/tree/deexo/exoopt.c
EDIT: Ok, it seems to be an encoder in c and decoder in asm ...


SRS

or you may go the "primitive way" as I like to call it :)

like

void bla() {
short a,b,c;
int de;
        a=b;  // ld a,b
        a-=4; // sub    #4
        a=a && 15; // and    #15
        if a<>0 goto exo_node1; //jr    nz,exo_node1
        de=1; // ld    de,#1        ;DE=b2
exo_node1:   
            c=16; // ld    c,#16
...

Arnaud

Quote from: SRS on 22:07, 16 October 16
or you may go the "primitive way" as I like to call it :)

like

void bla() {
short a,b,c;
int de;
        a=b;  // ld a,b
        a-=4; // sub    #4
        a=a && 15; // and    #15
        if a<>0 goto exo_node1; //jr    nz,exo_node1
        de=1; // ld    de,#1        ;DE=b2
exo_node1:   
            c=16; // ld    c,#16
...


You're right this the best way to do. l'll try.

Arnaud

#9
I worked on C conversion and there're some assembler code i don't understand:

First problem :

exo_setbit:   
        add    hl,hl
        dec    c
        jr    nz,exo_setbit
        ld    52 (iy),e
        ld    104 (iy),d    ;base[i]=b2
        add    hl,de
        ex    de,hl
        inc    iy
        pop    hl
        djnz    exo_initbits
        inc    c


Here my problem, i'm not sure when i converted :
ld 52 (iy),e
into
char iy[] = {..};
iy[52] = e;


Second problem :
exo_get4bits:   
        call    exo_getbit
        rl    c
        jr    nc,exo_get4bits
        ld    (iy),c    ;bits[i]=b1
        push    hl
        ld    hl,#1
        .db    #210        ;3 bytes nop (JP NC)


i have no idea how convert :
.db    #210
What it's for ?
It's directly opcode value ?

Thanks.

Here full source asm code :
[attach=2]

PulkoMandy

As you can see from the linked file above (exoopt.c), the decruncher is generated specifically for each compressed file, depending on which features of exomizer the file uses. So, you must first decide:
- Which direction you want (back or forward)
- Wether you need to support literal sequences
- If you want to use the tweaked "mapbase", or not

There is a 4th parameter which defines the kind of optimization (for speed, for smaller size of decompressor code, or a compromise).

I think these are the only changes from "normal" exomizer to the z80 optimized version. There may be some endian-swapping in some places, too.
Maybe you can compare the exoopt assembler routine to the normal exomizer one for z80 asm, and report the changes to the C version.

Or maybe you can write a "de-optimizer" that takes an exoopt file and convert it back to the normal exomizer format (the reverse of exoopt.exe operation).

SRS

Quote from: Arnaud on 19:41, 22 November 16
I worked on C conversion and there're some assembler code i don't understand:

        ld    hl,#1
        .db    #210        ;3 bytes nop (JP NC)[/code]

i have no idea how convert :
.db    #210
What it's for ?
It's directly opcode value ?

Self modifying ASM. Thats where I gave up the ASM to C conversion I was trying to assist your cool approach. :(

Arnaud

Quote from: SRS on 21:35, 28 November 16
Self modifying ASM. Thats where I gave up the ASM to C conversion I was trying to assist your cool approach. :(

I see why i wasn't able to understand how convert it  :D


Docent

Quote from: Arnaud on 19:41, 22 November 16
I worked on C conversion and there're some assembler code i don't understand:

Second problem :
exo_get4bits:   
        call    exo_getbit
        rl    c
        jr    nc,exo_get4bits
        ld    (iy),c    ;bits[i]=b1
        push    hl
        ld    hl,#1
        .db    #210        ;3 bytes nop (JP NC)


i have no idea how convert :
.db    #210
What it's for ?
It's directly opcode value ?
Its 0xd2 opcode, ie jp nc, xx
From the source code it looks like the jump will never get executed due to carry flag set by earlier jr nc loop.
It serves here as a way to skip first execution of add hl,hl; dec c - these two instructions will be skipped because they will be used to build the destination address for jp nc.



Docent

Quote from: SRS on 21:35, 28 November 16
Self modifying ASM. Thats where I gave up the ASM to C conversion I was trying to assist your cool approach. :(
it is not self modifying code, see my comment.

SRS

QuoteCode: ld 52 (iy),einto
Code: char iy[] = {..};
iy[52] = e;

Not sure if you got this by now but thats for accessing the exo_mapbasebits:
         ;defs   156   ;tables for bits, baseL, baseH
         .db #0,#0,#0,#0,#0,#0,#0,#0,#0,#0,#0,#0

"array". so having the exxop_mapbasebits(156) = {0,0,0,...} and

then ld   l, 52 (iy) translates to l = exxop...(52); and viceversa

Powered by SMFPacks Menu Editor Mod