{"id":190,"date":"2020-06-28T12:00:02","date_gmt":"2020-06-28T12:00:02","guid":{"rendered":"https:\/\/blogs.scummvm.org\/djsrv\/?p=190"},"modified":"2022-05-25T00:24:14","modified_gmt":"2022-05-25T00:24:14","slug":"back-to-bytecode","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/djsrv\/2020\/06\/28\/back-to-bytecode\/","title":{"rendered":"Back to Bytecode"},"content":{"rendered":"<section class=\"body\">This week I wrapped up work on parent scripts and factories, starting with some bug fixes and minor refactoring. The Lingo in <em>Lingo Workshop<\/em>\u2019s Bug Garden movie now fully works!<\/section>\n<section class=\"body\"><div style=\"width: 480px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-190-1\" width=\"480\" height=\"360\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blogs.scummvm.org\/djsrv\/wp-content\/uploads\/sites\/4\/2022\/05\/Bug-Garden-QDM4wUz2Oo4.mp4?_=1\" \/><a href=\"https:\/\/blogs.scummvm.org\/djsrv\/wp-content\/uploads\/sites\/4\/2022\/05\/Bug-Garden-QDM4wUz2Oo4.mp4\">https:\/\/blogs.scummvm.org\/djsrv\/wp-content\/uploads\/sites\/4\/2022\/05\/Bug-Garden-QDM4wUz2Oo4.mp4<\/a><\/video><\/div><\/p>\n<p>After getting Bug Garden working, I began implementation of the bytecode versions of parent scripts and factories. For those not familiar with the Director engine, there are two ways we load Lingo scripts. From Director 2-3, Lingo was stored in Director movies as source code, which we parse and compile to custom bytecode. Starting in Director 4, Lingo was compiled to a <a href=\"http:\/\/fileformats.archiveteam.org\/wiki\/Lingo_bytecode\">bytecode<\/a> which is similar to our own, but it has a good number of differences. This bytecode is stored within movies&#8217; <code>Lscr<\/code> chunks, which also contain script metadata, much of which we don\u2019t yet handle. Due to the bytecode differences and unhandled metadata, parent scripts and factories only worked when the Lingo was loaded from source code, not from <code>Lscr<\/code>.<\/p>\n<p>For this, I needed to get back to my Director roots, which started with reverse-engineering <code>Lscr<\/code> for the development of <a href=\"https:\/\/github.com\/Earthquake-Project\/ProjectorRays\">ProjectorRays<\/a>, a Lingo bytecode decompiler. I already knew how to handle parent scripts from ProjectorRays, but factories were a mystery, so I needed to go back to the old strategy of incrementally changing test movies and watching what data changes. I\u2019ll spare you the fine details of how factories are stored, but basically scripts which contain factories are split into multiple <code>Lscr<\/code> chunks, with one chunk for each factory, and there\u2019s some metadata which ties these chunks together. With that work done, parent scripts and factories can now be loaded from bytecode.<\/p>\n<p>I also did some more work with events, which I will continue this coming week. Last week I said that only one object is supposed to handle each event, which is only partially true. Sev pointed out that an event handler can call <code>pass<\/code>, which will pass the event to the next object in the chain of potential handlers, so I needed to make further changes to event delegation to handle that. Now I\u2019m in the process of checking event execution order against different versions of Director, and then it\u2019s on to implementing windows.<\/p>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>This week I wrapped up work on parent scripts and factories, starting with some bug fixes and minor refactoring. The Lingo in Lingo Workshop\u2019s Bug Garden movie now fully works! After getting Bug Garden working, I began implementation of the bytecode versions of parent scripts and factories. For those not familiar with the Director engine, [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-190","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/posts\/190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"predecessor-version":[{"id":236,"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/posts\/190\/revisions\/236"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/djsrv\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}