{"id":21,"date":"2008-06-09T10:42:06","date_gmt":"2008-06-09T08:42:06","guid":{"rendered":"https:\/\/blogs.scummvm.org\/buddha\/?p=21"},"modified":"2022-04-15T10:42:40","modified_gmt":"2022-04-15T08:42:40","slug":"some-procrastination-and-preparation-for-opcode-comparison","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/buddha\/2008\/06\/09\/some-procrastination-and-preparation-for-opcode-comparison\/","title":{"rendered":"Some procrastination and preparation for opcode comparison"},"content":{"rendered":"<p>Hello everyone. There\u2019s been some procrastination in the air so to speak. I\u2019ve been working on making an opcode comparison between different Operation Stealth versions in order to discover which opcodes are platform specific (Amiga\/PC\/ST), which are extensively used etc. The idea is that once I know that then I\u2019ll know which opcodes to try to implement first. <a href=\"http:\/\/wiki.scummvm.org\/index.php\/User:Sev\">Sev<\/a> pointed out to me a standalone resource file unpacker and script decompiler for <a href=\"http:\/\/wiki.scummvm.org\/index.php\/Cine\">Cin\u00e9matique<\/a>.<\/p>\n<p><!--more--><\/p>\n<p>My first problem was what files to decompress i.e. knowing which files are resource files. Well, I looked at \u2018vol.1\u2019 \u2013 \u2018vol.9\u2019 files. They seemed to be simply text files containing lists of at least some of the resource files (Maybe all of them, don\u2019t know). Then I got interested in how <a href=\"http:\/\/wiki.scummvm.org\/index.php\/Cine\">Cine<\/a> currently figures out which resources files to unpack and it seemed it doesn\u2019t use the \u2018vol.?\u2019 files at all but instead it uses a \u2018vol.cnf\u2019 file. Well, I tried to figure out the code that deciphers the \u2018vol.cnf\u2019 file and now I understand it. I started a page about <a href=\"http:\/\/wiki.scummvm.org\/index.php\/Cine\">Cin\u00e9matique<\/a>\u2018s internals, file formats etc in ScummVM\u2019s wiki at the <a href=\"http:\/\/wiki.scummvm.org\/index.php\/Cine\/Specifications\">Cine Specifications<\/a> page and wrote some documentation about the \u2018vol.cnf\u2019 file format there.<\/p>\n<p>The standalone resource file unpacker and script decompiler didn\u2019t have any support for wildcards or directory recursion so I wanted to try to use Python to do the directory tree walking and call the external unpacker or script decompiler when necessary. Hadn\u2019t done directory tree walking or cleanly done command line options parsing before in Python so it took some time to learn to use those. Eventually after some tryings I used <a href=\"http:\/\/docs.python.org\/lib\/module-getopt.html\">getopt.getopt<\/a> for command line parsing and <a href=\"http:\/\/docs.python.org\/lib\/os-file-dir.html\">os.walk<\/a> for directory tree walking.<\/p>\n<p>I also was somehow torn with what to do in Python and what to do in C. The resource file unpacker and script decompiler were in C. If I were to call them from Python what about error handling? I couldn\u2019t find a nice way to pass info back to the Python script from the external programs \u2013 I tried <a href=\"http:\/\/docs.python.org\/lib\/module-popen2.html\">popen3<\/a> a bit but maybe the stdin\/stdout\/stderr passing only works on Unix, dunno, or maybe I just didn\u2019t try hard enough :-).<\/p>\n<p>Eventually after some procrastination and different ways of trying things I\u2019m now quite convinced it\u2019s probably a good compromise and use of resources to let low-level stuff be done in the C code (Bit manipulation, unpacking etc) and the higher level stuff (Calculating scripts\u2019 opcode statistics etc) be done in Python because that way I\u2019m using both of the languages\u2019 strengths (i.e. use them for what they\u2019re best for) instead of trying to do most or all of the stuff in one language only.<\/p>\n<p>So now I\u2019m at the point that I\u2019ll just combine the Python and C programs to do the unpacking of all the resource files for the different game versions and then modify the script decompiler to output in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Comma-separated_values\">.CSV<\/a> format so that it\u2019s easy to read the C program\u2019s output in with Python or Open Office. Once I have the data parsed I can do the opcode statistics calculations. There\u2019s a question though about how to detect what files are script files and what are not so I know which files to call the script decompiler on. Well, we shall see\u2026<\/p>\n<p>BTW sometimes understanding C code that deals with pointers and C library calls can be a bit of a PITA (And no, I don\u2019t mean <a href=\"http:\/\/en.wikipedia.org\/wiki\/Pita\">the eatable kind<\/a>). Just compare fixVolCnfName()\u2019s <a href=\"http:\/\/scummvm.svn.sourceforge.net\/viewvc\/scummvm\/scummvm\/trunk\/engines\/cine\/part.cpp?revision=31444&amp;view=markup&amp;sortby=date#l_73\">old C code version<\/a> and <a href=\"http:\/\/scummvm.svn.sourceforge.net\/viewvc\/scummvm\/scummvm\/trunk\/engines\/cine\/part.cpp?revision=32618&amp;view=markup&amp;sortby=date#l_73\">the more C++ style version<\/a> I did of it with some comments. Now I can understand what it does :-).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello everyone. There\u2019s been some procrastination in the air so to speak. I\u2019ve been working on making an opcode comparison between different Operation Stealth versions in order to discover which opcodes are platform specific (Amiga\/PC\/ST), which are extensively used etc. The idea is that once I know that then I\u2019ll know which opcodes to try [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":1,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":22,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/posts\/21\/revisions\/22"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/buddha\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}