Coder Social home page Coder Social logo

unzx0_68000's People

Contributors

emmanuel-marty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

unzx0_68000's Issues

Hypothetical bug for literals or match copies >64 KB

Hi there,

thank you for your implementation of the zx0 decompressor. Much appreciated!

I just noticed that both .copy_lits and .copy_match are using dbra for looping over the literal/match length in d0, which is assumed to be a long word as can be seen from the preceding subq.l #1,d0 instruction and the addx.l d0,d0 in .get_elias . However, dbra only uses word size for d0, and thus the decoder would not work correctly if a block has a length >65535.

I know this is a very unlikely thing to happen except for storing large blocks of random noise or e.g. very large duplicated or empty blocks of data. But if this edge case is unsupported anyway, the operations on d0 could be cut down to word size, halving the number of cycles on 68000 for these operations.

An easy fix is to move the subq.l #1,d0 inside the loop and use a bne.s instead of dbra at the cost of performance (same code size).

More complicated solutions would keep the dbra and test the upper word of d0 for zero. For example:

    swap d0
    tst.w d0
    beq.s .copy_lits_done
    swap d0
    bra.s .copy_lits
.copy_lits_done

or

.copy_lits_next_64k
        subq.l  #1,d0           ; dbf will loop until d0 is -1, not 0
.copy_lits
        move.b  (a0)+,(a1)+     ; copy literal byte
        dbra    d0,.copy_lits   ; loop for all literal bytes
        addq.l  #1,d0
        bne.s .copy_lits_next64k

(I do like the latter solution, it looks elegant and only adds 2 * 4 bytes to your version and 16 cycles per block).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.