{"id":43,"date":"2017-06-26T13:37:02","date_gmt":"2017-06-26T13:37:02","guid":{"rendered":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/?p=43"},"modified":"2022-05-21T14:09:22","modified_gmt":"2022-05-21T14:09:22","slug":"drawing-the-cursor","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/2017\/06\/26\/drawing-the-cursor\/","title":{"rendered":"Drawing the Cursor"},"content":{"rendered":"<p><a href=\"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-content\/uploads\/sites\/22\/2017\/06\/corrupted_cursor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-46\" src=\"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-content\/uploads\/sites\/22\/2017\/06\/corrupted_cursor.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-content\/uploads\/sites\/22\/2017\/06\/corrupted_cursor.png 640w, https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-content\/uploads\/sites\/22\/2017\/06\/corrupted_cursor-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a> Seems like our Chef Horst Hummel got impatient and sliced the hourglass cleanly in half..<\/p>\n<p>The 16&#215;16 cursor image is stored as a bitmap like the newspaper images I described in my previous post on <a href=\"https:\/\/joefish-gsoc.blogspot.de\/2017\/06\/image-rendering-and-animation.html\">graphics and animation in Supernova<\/a>. The black outline and red filling are rendered seperately, both <a href=\"https:\/\/github.com\/Joefish\/scummvm\/blob\/supernova\/engines\/supernova\/msn_def.h#L130\">taking 32 bytes<\/a>.<\/p>\n<p>I skimmed through my code and could not find a shift that possibly corrupted the cursor data. But how to fix it? Well, it seems the image is split right at 8 pixels and since they are represented by one byte we could just do a wordRoll that swaps its bytes like <code>wapped = (i &gt;&gt; 8) | (i &lt;&lt; 8)<\/code>.<\/p>\n<p>The disassembly shows the critical part for drawing the black outline<\/p>\n<blockquote class=\"tr_bq\">\n<pre><span class=\"c\">next_line:<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1887\"><\/a><span class=\"c\">          lodsw<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1888\"><\/a><span class=\"c\">          mov cx,dx<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1889\"><\/a>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1890\"><\/a><span class=\"c\">next_pixel:<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1891\"><\/a><span class=\"c\">          shl ax,1<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1892\"><\/a><span class=\"c\">          jc skip1<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1893\"><\/a><span class=\"c\">          mov byte es:[di],0<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1894\"><\/a><span class=\"c\">skip1:<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1895\"><\/a><span class=\"c\">          inc di<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1896\"><\/a><span class=\"c\">          loop next_pixel<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1897\"><\/a>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1898\"><\/a><span class=\"c\">          add di,320<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1899\"><\/a><span class=\"c\">          sub di,dx<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1900\"><\/a><span class=\"c\">          dec bh<\/span>\r\n<a href=\"https:\/\/www.blogger.com\/null\" name=\"msn.c-1901\"><\/a><span class=\"c\">          jnz next_line\r\n<\/span><\/pre>\n<\/blockquote>\n<p><b>lodsw<\/b>&#8230; The first endianess bug in this project that I got stuck on&#8230;<br \/>\nAt least now it&#8217;s working and I can keep going with more important stuff like actually making it playable and hopefully won&#8217;t get distracted by those small things again&#8230;<\/p>\n<p><a href=\"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-content\/uploads\/sites\/22\/2017\/06\/scummvm00001.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-47\" src=\"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-content\/uploads\/sites\/22\/2017\/06\/scummvm00001.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-content\/uploads\/sites\/22\/2017\/06\/scummvm00001.png 640w, https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-content\/uploads\/sites\/22\/2017\/06\/scummvm00001-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Seems like our Chef Horst Hummel got impatient and sliced the hourglass cleanly in half.. The 16&#215;16 cursor image is stored as a bitmap like the newspaper images I described in my previous post on graphics and animation in Supernova. The black outline and red filling are rendered seperately, both taking 32 bytes. I skimmed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":49,"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/posts\/43\/revisions\/49"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/joefish-gsoc\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}