don't click here

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,718
    10
    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:
    Code (Text):
    1. // Required headers
    2. #include <stdint.h>
    3. #include <string.h>
    4.  
    5. //---------------------------------------------------------------------------
    6. // decrunch
    7. //
    8. // This code tries to gimmick the decompressing subroutine found in Mr. Nutz
    9. // 2 (yes, I have been examining that :V). Seems to be a very simple LZ-like
    10. // algorithm, with 8-bit token groups, 4-bit lengths and 12-bit offsets.
    11. // Wasn't very hard to understand, really (the original asm code is just 33
    12. // lines long).
    13. //
    14. // @param src .... Pointer to the compressed data
    15. // @param dest ... Where to store the uncompressed data
    16. //---------------------------------------------------------------------------
    17. // <Sik> I just tried to gimmick what the original subroutine did, so
    18. // probably it needs some major clean up.
    19. //---------------------------------------------------------------------------
    20.  
    21. void decrunch(uint8_t* src, uint8_t* dest)
    22. {
    23. &nbsp;&nbsp; // Skip header
    24. &nbsp;&nbsp; src += 4;
    25.  
    26. &nbsp;&nbsp; // Get data length
    27. &nbsp;&nbsp; size_t length = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
    28. &nbsp;&nbsp; uint8_t* endaddr = dest + length;
    29. &nbsp;&nbsp; src += 4;
    30.  
    31. &nbsp;&nbsp; // Go through all data
    32. &nbsp;&nbsp; for (;;) {
    33. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get token information
    34. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uint8_t tokens = *src;
    35. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src++;
    36.  
    37. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Process all tokens in this byte
    38. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t I;
    39. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (I = 0; I < 8; I++) {
    40. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Is it a compressed block?
    41. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (tokens & 0x80) {
    42. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get address of data to copy
    43. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t offset = (src[0] << 4 & 0x0F00) | src[1];
    44. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uint8_t* block = dest - offset;
    45.  
    46. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get amount of data to copy
    47. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size_t amount = (src[0] & 0x0F) + 3;
    48.  
    49. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Copy data!
    50. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memcpy(dest, block, amount);
    51. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest += amount;
    52.  
    53. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Advance pointer :P
    54. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src += 2;
    55. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
    56.  
    57. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Uncompressed byte, copy it as-is
    58. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {
    59. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*dest = *src;
    60. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest++;
    61. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src++;
    62. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
    63.  
    64. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // End of data?
    65. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (dest >= endaddr)
    66. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
    67.  
    68. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Next token
    69. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tokens <<= 1;
    70. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    71. &nbsp;&nbsp; }
    72. }
    EDIT: tell me if I had accidentally entered some bug :P
     
  2. SegaLoco

    SegaLoco

    W)(at did you say? Banned
    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,718
    10
    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
    50
    2
    8
    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 Hidden Palace.
     
  5. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    10
    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

    Just pining for the fjords Tech Member
    755
    21
    18
    Heart of NASCAR
    Doom CD32X Fusion
    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,718
    10
    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

    Just pining for the fjords Tech Member
    755
    21
    18
    Heart of NASCAR
    Doom CD32X Fusion
    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
    50
    2
    8
    These:

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    [​IMG]

    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
    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,718
    10
    0
    being an asshole =P
    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
    1
    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

    Professional Electromancer Oldbie
    4,812
    475
    63
    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
    1
    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,314
    35
    28
    Nunya
    Rock Band 3 Deluxe
    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
    1
    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

    Professional Electromancer Oldbie
    4,812
    475
    63
    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,314
    35
    28
    Nunya
    Rock Band 3 Deluxe
    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
    1
    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.