Mr. Nutz 2 decompression subroutine C-icized

Discussion in 'Technical Discussion' started by Sik, May 9, 2010.

  1. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    So, I was looking at the source code of Mr. Nutz 2 MD that got released, and found a "decrunch" subroutine (decompression, bah). I've translated the code to C, in case somebody is interested:
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// Required headers
    #include <stdint.h>
    #include <string.h>

    //---------------------------------------------------------------------------
    // decrunch
    //
    // This code tries to gimmick the decompressing subroutine found in Mr. Nutz
    // 2 (yes, I have been examining that :V). Seems to be a very simple LZ-like
    // algorithm, with 8-bit token groups, 4-bit lengths and 12-bit offsets.
    // Wasn't very hard to understand, really (the original asm code is just 33
    // lines long).
    //
    // @param src .... Pointer to the compressed data
    // @param dest ... Where to store the uncompressed data
    //---------------------------------------------------------------------------
    // <Sik> I just tried to gimmick what the original subroutine did, so
    // probably it needs some major clean up.
    //---------------------------------------------------------------------------

    void decrunch(uint8_t* src, uint8_t* dest)
    {
    &nbsp;&nbsp; // Skip header
    &nbsp;&nbsp; src += 4;

    &nbsp;&nbsp; // Get data length
    &nbsp;&nbsp; size_t length = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
    &nbsp;&nbsp; uint8_t* endaddr = dest + length;
    &nbsp;&nbsp; src += 4;

    &nbsp;&nbsp; // Go through all data
    &nbsp;&nbsp; for (;;) {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get token information
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uint8_t tokens = *src;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src++;

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Process all tokens in this byte
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t I;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (I = 0; I < 8; I++) {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Is it a compressed block?
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (tokens & 0x80) {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get address of data to copy
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t offset = (src[0] << 4 & 0x0F00) | src[1];
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uint8_t* block = dest - offset;

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get amount of data to copy
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t amount = (src[0] & 0x0F) + 3;

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Copy data!
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memcpy(dest, block, amount);
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest += amount;

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Advance pointer :P
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src += 2;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Uncompressed byte, copy it as-is
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*dest = *src;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest++;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src++;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // End of data?
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (dest >= endaddr)
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Next token
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tokens <<= 1;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp; }
    }<!--c2--></div><!--ec2-->
    EDIT: tell me if I had accidentally entered some bug :P
     
  2. SegaLoco

    SegaLoco

    W)(at did you say? Misfit
    Do you have the original assembly for comparrison? I'd love to give it a swing of my own. :P
     
  3. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    Wasn't it on Cult or Hidden Palace? I don't remember from where did I get it and I'm posting through a phone right now.
     
  4. Wesker

    Wesker

    Member
    43
    0
    6
    If I'm not mistaken, this leaked source code is actually from the original Amiga version (Mr. Nutz: Hoppin' Mad) rather than from the unreleased Mega Drive port (Mr. Nutz 2).

    At least that was what someone told at <a href="http://forums.hidden-palace.org/viewtopic.php?t=2802&sid=a626fbe39e9ad04c17ca00bc2916f171" target="_blank">Hidden Palace</a>.
     
  5. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    Nope, the code I have is definitely for the Mega Drive... and very unoptimized code, at that. I'm sure of this because the code for handling the VDP.
     
  6. Chilly Willy

    Chilly Willy

    Tech Member
    746
    0
    0
    Doom 32X
    I've got EUAE setup with DevPac and ReSource (among other things) and still use them on occasion, but where the hell do you find OMA these days?? Even the Amiga Applications dump on usenet doesn't have a version of it, and the only thing on AmiNet is the original demo.

    I don't suppose another assembler will do in place of OMA?
     
  7. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    Well, asm68k won't build it... Although I should retry with different settings. That said, the code is full of zero-lenght branches too, and that only can be built as a word branch... Etc. The code is a total mess and I'd suggest to try looking at the functions and remaking them from scratch.
     
  8. Chilly Willy

    Chilly Willy

    Tech Member
    746
    0
    0
    Doom 32X
    I noticed it had genam settings in one directory. Could be they were trying DevPac at some point. The project is a complete and utter mess - whoever wrote it should be shot. :)
     
  9. ICEknight

    ICEknight

    Researcher Researcher
    Weren't there some pictures (or footage?) of this prototype running on an emulator? You'd think it must be possible to compile this thing...
     
  10. Wesker

    Wesker

    Member
    43
    0
    6
    <!--quoteo(post=458711:date=May 24 2010, 08:39 PM:name=ICEknight)--><div class='quotetop'>QUOTE (ICEknight @ May 24 2010, 08:39 PM) <a href="index.php?act=findpost&pid=458711"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Weren't there some pictures (or footage?) of this prototype running on an emulator? You'd think it must be possible to compile this thing...<!--QuoteEnd--></div><!--QuoteEEnd-->

    These:

    <img src="http://www.segasaturno.com/portal/files/posted_images/2/mr_nutz_2_megadrive01.jpg" border="0" class="linked-image" />

    <img src="http://www.segasaturno.com/portal/files/posted_images/2/mr_nutz_2_megadrive02.jpg" border="0" class="linked-image" />

    <img src="http://www.segasaturno.com/portal/files/posted_images/2/mr_nutz_2_megadrive03.jpg" border="0" class="linked-image" />

    <img src="http://www.segasaturno.com/portal/files/posted_images/2/mr_nutz_2_megadrive04.jpg" border="0" class="linked-image" />

    <img src="http://www.segasaturno.com/portal/files/posted_images/2/mr_nutz_2_megadrive05.jpg" border="0" class="linked-image" />

    <img src="http://www.segasaturno.com/portal/files/posted_images/2/mr_nutz_2_megadrive06.jpg" border="0" class="linked-image" />

    They are not exactly related to this source code, however.

    These pics come from the NEON Studios founder and main programmer of this game, Peter Thierolf. He took them by petition of a Digitpress member and using the ROM of the final version of the game he has.

    He is not planning to release this ROM due to fear to possible legal issues, unfortunately.
     
  11. ICEknight

    ICEknight

    Researcher Researcher
    <!--quoteo(post=458806:date=May 24 2010, 05:34 PM:name=Wesker)--><div class='quotetop'>QUOTE (Wesker @ May 24 2010, 05:34 PM) <a href="index.php?act=findpost&pid=458806"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->He is not planning to release this ROM due to fear to possible legal issues, unfortunately.<!--QuoteEnd--></div><!--QuoteEEnd-->
    Somebody else might have the ROM and release it anonymously on an unknown forum, keeping his privacy safe. And that somebody else could or could not be himself... :ssh:
     
  12. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    <!--quoteo(post=458711:date=May 24 2010, 03:39 PM:name=ICEknight)--><div class='quotetop'>QUOTE (ICEknight @ May 24 2010, 03:39 PM) <a href="index.php?act=findpost&pid=458711"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Weren't there some pictures (or footage?) of this prototype running on an emulator? You'd think it must be possible to compile this thing...<!--QuoteEnd--></div><!--QuoteEEnd-->
    I hadn't even put effort into it to be fair, I should retry =P All I know though is that local labels start with a dot, not with @, which is why asm68k probably complained back then. Luckily there's an option to change the symbol used, so I should use that and check what else goes wrong...
     
  13. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    0
    0
    Writing my own MD/Genesis sound driver :D
    Ok this has taken forever to materialize so BUMP.

    What exactly would I need to build this source? What I can gather from here is: an Amiga emulator, an Amiga setup typical of models around 1995 (what Workbench version? what system requirements?), DevPac, genam, ReSource, and OMA. (And even then, no guarantees finding the software on Underground Gamer would result in an unmodified (so to speak) ROM... sneaky pirates? =P)
     
  14. Cooljerk

    Cooljerk

    NotEqual Tech, Inc - VR & Game Dev Oldbie
    4,292
    3
    18
    Whoa, I had no idea there was a Mr. Nutz 2. I loved the amiga version, anyone know if there was an Amiga version of this game in the works at one point?

    Commodore went belly up in 1994, so the A4000 and CD32 are pretty much the last amigas released. I dunno if you can compile genesis hardware on any A1200 variant, though, since it uses a 32-bit CPU instead of the M68k that the A500 and A1000 used.
     
  15. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    0
    0
    Writing my own MD/Genesis sound driver :D
    The MD Mr. Nutz 2 is a port of the released Amiga game I think it was called Mr. Nutz: Hoppin' Mad. And the use of a 32-bit CPU won't matter because the output is going to be an MD binary, not an Amiga executable =P (And besides, the code is likely not going to have any 68020+ opcodes, which are mostly for dealing with coprocessors...) But thanks for the information!
     
  16. LocalH

    LocalH

    roxoring your soxors Tech Member
    3,268
    2
    18
    wouldn't you like to know
    Super Guitar Hero II
    I'd recommend KS/WB 3.1 on an emulated A4000/040 so you can add plenty of RAM (16MB of fast RAM should be enough). Make your Amiga boot drive a folder unless there are compatibility problems with the toolchain, if so then go with a hardfile (doesn't need to be that big, I'd be surprised if you needed more than 100-200MB). If you do need to go with a hardfile, then make an additional folder drive as well so you can just copy the ROM out to it after assembling it. I wouldn't worry about an RTG graphics card, since you're setting up a single-purpose installation.

    I've got a ton of Amiga apps on my laptop, pretty sure I have Devpac and ReSource, not sure about the rest. Gimme a bit and I'll package up the ADFs I do have. If you don't feel like waiting, Zophar's is actually a really good place to get Amiga disk images. Let me know if you don't feel like faffing about finding Kickstart or Workbench, I have them.
     
  17. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    0
    0
    Writing my own MD/Genesis sound driver :D
    Sure, send me what you have, that would help. And thanks for the configuration information!
     
  18. Cooljerk

    Cooljerk

    NotEqual Tech, Inc - VR & Game Dev Oldbie
    4,292
    3
    18
    So I looked all this up, and turns out Mr. Nutz on the Amiga IS this game. Mr. Nutz 1 was apparently SNES and Genesis exclusive, and the Amiga version was radically different. Thus, when they were porting the Amiga version to the genesis, they retitled it Mr. Nutz 2.

    I went and looked up some videos of the console versions of Mr. Nutz and man it looks bad. The Amiga version is a 100% different, and much much better game. Easily one of the best platformers on the platform. Console gamers really missed out with their shoddy release.
     
  19. LocalH

    LocalH

    roxoring your soxors Tech Member
    3,268
    2
    18
    wouldn't you like to know
    Super Guitar Hero II
    While packaging up what I've got, I have one question as to the Amiga apps used - any indication as to which versions? I have several versions of Devpac, ranging from v2.14 from 1989 through v3.02 from 1992, v3.14 from 1994, and v3.18 from 1997. v2.14 and v3.02 are two disks, v3.14 and v3.18 are one. I also have v4 and v5 of ReSource, both two disks. I don't seem to have either genam or OMA (I'm seeing some demo versions looking around a bit, but no full versions). Anyone have a full title for OMA or is that it?

    Also, it turns out that Zophar's is no longer a good source for ADF files >_<

    Edit: genam is the assembler used in Devpac, so never mind that, all I'm trying to find now is a non-demo OMA. All I can find besides that link above is a reference to a crack intro by the German crew Supreme (which makes sense, I guess as it seems OMA was coded by Germans) but cannot find the actual crack itself.

    Edit 2: Ok, I found a copy of the Mr. Nutz 2 source, but out of curiousity, anyone got the original upload that also contained Turrican III stuffs?

    Edit 3: Ok, thanks to box scans of OMA v2 and v3 I determined that the title is "Optimierender Makro-Assembler". Doing a search found that listed in a huge Amiga app torrent on TPB which I am currently downloading (stupid single 7z file). Luckily there are four seeds and I'm getting about 750KB/s so I should have it within the half hour. I thought I'd downloaded this torrent at one point in the past but it's not anywhere around here that I can find quickly so it's faster to just download again =P

    Edit 4: While the torrent was downloading, I did some more searching and now I have the following:

    Optimierender Makro Assembler (1992)(Heidrich, D.)(DE)(Disk 1 of 3)
    Optimierender Makro Assembler (1992)(Heidrich, D.)(DE)(Disk 2 of 3)
    Optimierender Makro Assembler (1992)(Heidrich, D.)(DE)(Disk 3 of 3)[Includes 3.1]
    OMA v2.0 (1994)(ICP-Innovativ)(Disk 1 of 3)[WB]
    OMA v2.0 (1994)(ICP-Innovativ)(Disk 2 of 3)[WB]
    OMA v2.0 (1994)(ICP-Innovativ)(Disk 3 of 3)[WB]

    I would assume that 2.0 is the desired version? Can't find 3.0 anywhere but I know it exists, see second box scan above.

    Also, before I zip anything up, Andlabs, do you have a preferred archive format?
     
  20. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    0
    0
    Writing my own MD/Genesis sound driver :D
    Just send everything; I'll use trial-and-error to see what works, perhaps through Irene (I'm on Long Island) =P Thanks.

    I think the full source package is at the end of Wesker's post on Sega-16 which is linked from another topic on this forum on Mr. Nutz 2.