<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Cyanne's Studies]]></title><description><![CDATA[Where I learn new abilities and write about it]]></description><link>https://cyanne.study</link><image><url>https://substackcdn.com/image/fetch/$s_!hBnJ!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3dac1417-9ee9-44df-97fc-82c4f273a6e1_534x534.png</url><title>Cyanne&apos;s Studies</title><link>https://cyanne.study</link></image><generator>Substack</generator><lastBuildDate>Wed, 08 Apr 2026 08:50:37 GMT</lastBuildDate><atom:link href="https://cyanne.study/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Cyanne — All rights reserved.]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[cyanne@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[cyanne@substack.com]]></itunes:email><itunes:name><![CDATA[Cyanne]]></itunes:name></itunes:owner><itunes:author><![CDATA[Cyanne]]></itunes:author><googleplay:owner><![CDATA[cyanne@substack.com]]></googleplay:owner><googleplay:email><![CDATA[cyanne@substack.com]]></googleplay:email><googleplay:author><![CDATA[Cyanne]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[ASM day 5: Stacks, and my burger stacking program (Part I)]]></title><description><![CDATA[The start of making something interactive]]></description><link>https://cyanne.study/p/day-5-stacks-and-my-burger-stacking</link><guid isPermaLink="false">https://cyanne.study/p/day-5-stacks-and-my-burger-stacking</guid><dc:creator><![CDATA[Cyanne]]></dc:creator><pubDate>Mon, 23 Jan 2023 03:18:44 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/5b85c260-5434-4514-91d5-683452d067ba_764x580.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome back to my assembly learning diary once again! Today I&#8217;m learning about the <em>stack</em> ability of the 6502 processor. Then, I&#8217;ll try to apply this knowledge by making a program that you can run online in <a href="https://skilldrick.github.io/easy6502/">Easy6502</a>.</p><p>First off, what I know beforehand, is that a stack is something to put values into and read values out of quickly. I presume different types of stacks have different patterns like first or last in, first or last out (<em>FIFO</em> comes to mind). I presume the 6502 will only allow for one such type though.</p><h4>A stack of dishes</h4><p>This time I consulted both <a href="https://skilldrick.github.io/easy6502/#stack">Easy6502</a> and <a href="https://chubakbidpaa.com/retro/2020/12/15/6502-stack-copy.html">this other blog post</a>.</p><p>A stack is something you &#8220;push&#8221; values onto, and &#8220;pull&#8221; values off of. This is what the <em>Push Accumulator </em>(<code>PHA</code>) and <em>Pull Accumulator</em> (<code>PLA</code>) instructions do, which I previously only knew the name of.</p><p>The <em>stack</em> is &#8220;last in, first out&#8221;. It&#8217;s compared to as a stack of dishes, where you are only able to put on a dish or take off a dish from <em>the top</em> of the stack. There is an illustration from Wikipedia for this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uqwU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uqwU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png 424w, https://substackcdn.com/image/fetch/$s_!uqwU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png 848w, https://substackcdn.com/image/fetch/$s_!uqwU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png 1272w, https://substackcdn.com/image/fetch/$s_!uqwU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uqwU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png" width="580" height="404.98046875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:715,&quot;width&quot;:1024,&quot;resizeWidth&quot;:580,&quot;bytes&quot;:26927,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uqwU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png 424w, https://substackcdn.com/image/fetch/$s_!uqwU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png 848w, https://substackcdn.com/image/fetch/$s_!uqwU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png 1272w, https://substackcdn.com/image/fetch/$s_!uqwU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59aa46be-336f-4159-8e57-b97f90055ca0_1024x715.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">In addition, Wikipedia also features a picture of a literal stack of dishes. <a href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)">[Source]</a></figcaption></figure></div><p>I do not know the exact use for this feature, but considering the limited instructions and cycles we get on the 6502 I can certainly imagine it to be an effective way to handle a list of data. With these types of analogies, I can also think of a way to demonstrate this concept visually with a program. More on this later&#8230; &#127828;</p><p>I analyzed the <a href="https://skilldrick.github.io/easy6502/#stack">example program</a> and added comments to make sense of it. In short, we can store values into the stack with PHA and take them off with PLA. The S register (stack pointer) lets us know where in memory the &#8220;top&#8221; of the stack is currently. <code>TSX</code> and <code>TXS</code> let us read and manipulate this value directly.</p><h4>A tangent: making interactive code</h4><p>If we are able to manipulate a stack in my program, then I want to make it user interactive. Luckily, Easy6502 has a simple register <code>$ff</code> that contains the last key the user has pressed while running the program, as an 8-bit ASCII code.</p><p>Because we also want to know <em>when</em> a key is pressed, we have to come up with another part of the logic ourselves. For this test program, every time you press a key a new pixel is &#8220;typed&#8221; to the screen. This is what I made:<br>(<a href="https://gist.github.com/Cyanne/fb50bd7f008ff490b7cd0ea862767c1e">code available here</a>)</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NSJK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NSJK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif 424w, https://substackcdn.com/image/fetch/$s_!NSJK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif 848w, https://substackcdn.com/image/fetch/$s_!NSJK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif 1272w, https://substackcdn.com/image/fetch/$s_!NSJK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NSJK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif" width="604" height="308" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:308,&quot;width&quot;:604,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:162843,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NSJK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif 424w, https://substackcdn.com/image/fetch/$s_!NSJK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif 848w, https://substackcdn.com/image/fetch/$s_!NSJK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif 1272w, https://substackcdn.com/image/fetch/$s_!NSJK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95ffac99-072f-4037-a46d-b6f8a4510211_604x308.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The color is the low nibble of the keycode. </figcaption></figure></div><p>In that recording I&#8217;m mashing a whole bunch of keys, and as you can you see it&#8217;s working as it should! By achieving reliable input polling, we open the doors for all new kinds of programs.</p><h4>The burger stacking program</h4><p>My idea is to demonstrate the stack by using a hamburger analogy. Burgers are made of various ingredients stacked together, so this is allows us to visualize what&#8217;s in stack memory in a very blatant way! My plan is that you can use the 1 to 7 number keys on your keyboard to place the various pieces such as the buns, lettuce and patties. Then by pressing 0, you remove the topmost ingredient &#8212; exactly like how the stack works inside of the 6502.</p><p>Starting off, I created the burger sprites.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6O5n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6O5n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png 424w, https://substackcdn.com/image/fetch/$s_!6O5n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png 848w, https://substackcdn.com/image/fetch/$s_!6O5n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png 1272w, https://substackcdn.com/image/fetch/$s_!6O5n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6O5n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png" width="1030" height="480" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:480,&quot;width&quot;:1030,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:5769,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6O5n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png 424w, https://substackcdn.com/image/fetch/$s_!6O5n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png 848w, https://substackcdn.com/image/fetch/$s_!6O5n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png 1272w, https://substackcdn.com/image/fetch/$s_!6O5n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a71ddf3-8ab2-4001-b0c1-168256b0c607_1030x480.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Left: the individual slices to be placed into the program. Right: a mockup of what an assembled burger should look like.</figcaption></figure></div><p>I had a ton of fun drawing this. I tried to make each piece look as tasty as possible, all while looking at pictures of burgers for reference (making me incredibly hungry). I caught myself talking out loud, tastefully describing how each line of pixels makes the burger look more nice and delicious, resembling some kind of fast food-minded Bob Ross.</p><p>I used very specific constraints in order to get the maximum effect out of minimal programming:</p><ul><li><p>Each piece only uses 1 color.</p><ul><li><p>This way, I can use simple <a href="https://en.wikipedia.org/wiki/Run-length_encoding">run length encoding</a>. As an imagined &#8220;pen&#8221; moves across the screen, the only thing I need to specify is when it&#8217;s down (drawing), and when it&#8217;s lifted. This saves memory, lines of code, and speeds up drawing.</p></li></ul></li><li><p>Each piece is 4 pixels high, starting at the red pixels.</p><ul><li><p>This means the bigger pieces (the meat and buns) are made up of two slices while looking like one. The program code will need to place both of them at the same time, but that&#8217;s about it.</p></li></ul></li><li><p>The 4th row at the pink dots is what I call &#8220;overhang&#8221;, and is drawn over the piece beneath it.</p><ul><li><p>This achieves a more complex looking effect by simply drawing the slices with 1 pixel of overlap. The mockup shows how effective this is, with the dripping cheese overlapping the meat patty.</p></li></ul></li></ul><p>I think assembling burgers is as much fun as I can provide you with a simple program right now. c:</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Cyanne&#8217;s Debug Room! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h4>The structure of the program</h4><p>I have not finished the program of this day yet, and as such it is merely Part One. For reference, <a href="https://gist.github.com/Cyanne/3ee4434a627ad356da503375bb33fafe">the work in progress code can be found here.</a></p><p>This is the plan I have in mind:</p><h5>The pieces</h5><p>Each piece will have its own value, so that the stack in memory plainly lists out the pieces in consecutive bytes.</p><pre><code>; Burger pieces:
;  #$00 - nothing
;  #$01 - bottom bread A
;  #$02 - bottom bread B
;  #$03 - sauce
;  #$04 - lettuce
;  #$05 - tomato
;  #$06 - patty A
;  #$07 - patty B
;  #$08 - cheese
;  #$09 - top bread A
;  #$0a - top bread B</code></pre><h5>Init:</h5><p>In memory addresses <code>$00</code> to <code>$08</code> we will store the colors that the individual pieces should be drawn with. The address numbers match up with the values above.</p><p>We should also initialize the stack for the first time here.</p><h5>StoreGraphics:</h5><p>Here we will write to memory each of the &#8220;pen down&#8221; and &#8220;pen up&#8221; timings for all slice types, using the aforementioned <a href="https://en.wikipedia.org/wiki/Run-length_encoding">RLE</a>. I&#8217;m hoping this is less work and more effective than storing each pixel individually.</p><h5>FillBG: Starting off with a colored screen</h5><p>As in my mockup, I think the graphics will look better without a black background this time. I figured out how to draw to the entire screen in a simple way. Here is the code!</p><pre><code>FillBG_init:
 LDA #$02          ; &#9582; X/$11: Drawing page/high byte
 TAX               ; &#9583;
 LDA #$00          ; &#9582; Y: Drawing position
 TAY               ; &#9583;
 LDA $00           ; Load background color into A
FillBG_loop:
 STX $11           ; &#9582; Draw background color pixel
 STA ($10),Y       ; &#9583; to screen using indirect addrs.
 INY               ; Increment screen position
 CPY #$00          ; &#9582; Check if Y has overflowed,
 BNE FillBG_loop   ; &#9583; otherwise loop.
 INX               ; Increment page
 CPX #$06          ; &#9582; Check if X passed enough pages,
 BNE FillBG_loop   ; &#9583; otherwise loop.</code></pre><p>Because we will have to draw to more than 8 vertical lines this time, we need to be able to address more than 256 pixels. If we can&#8217;t do this, then there&#8217;s no way we will be able to draw burger pieces all over the screen either!</p><p>At the core of this is the indirect addressing mode, <a href="https://cyanne.study/p/day-4-grappling-with-addressing-modes#%C2%A7figuring-out-what-modes-do-in-practice">as I learned about on the previous day</a>. While we keep the drawing position (<code>Y</code>) in a register like usual, this time we will also keep track of what page in memory we are on (the first byte <code>$XX</code> <code>00</code> of an address), and store it in both X and <code>$11</code>. That&#8217;s how we store our address of interest for later reference in memory. Indirect addressing will read from <code>$10</code> to find the 16-bit screen address we want to write to. We simply offset that address with Y like normal. All of this is through: <code>STA ($10),Y</code> &#8212; indirect addressing is highly effective!</p><p>We use branching to keep two loops going. First we loop until the entire page is filled with our color value. Then we break out of it, increment the page counter, and go back to fill the next page. When that is done 6 times, we break out of the whole program.</p><p>Here is what this looks like:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4Pb0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4Pb0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif 424w, https://substackcdn.com/image/fetch/$s_!4Pb0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif 848w, https://substackcdn.com/image/fetch/$s_!4Pb0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif 1272w, https://substackcdn.com/image/fetch/$s_!4Pb0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4Pb0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif" width="605" height="415" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:415,&quot;width&quot;:605,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:111262,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4Pb0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif 424w, https://substackcdn.com/image/fetch/$s_!4Pb0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif 848w, https://substackcdn.com/image/fetch/$s_!4Pb0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif 1272w, https://substackcdn.com/image/fetch/$s_!4Pb0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89c43ce2-4c06-4916-8c1e-51fa0d24210d_605x415.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h5>DrawBurger:</h5><p>Aside from the pen on/pen off technique I use as compression, I have all kinds of approaches in mind here.</p><p>When we are stacking the burger, there&#8217;s no problem with just drawing each new on top of the the previous one. But because we can take <em>off</em> pieces too, I want a 4 row high rectangle to draw over the discarded piece, (also clearing the &#8220;overhang&#8221; with it), and then have the top piece redrawn. This way we don&#8217;t have to slowly redraw the entire burger stack each time.</p><h5>PollInput:</h5><p>This is where a modified version of <a href="https://cyanne.study/p/day-5-stacks-and-my-burger-stacking#%C2%A7a-tangent-making-interactive-code">the input polling code I shared above</a> will run. Nothing needs to happen on screen while the program checks if you hit the 1-7 or 0 keys.</p><h5>UpdateStack:</h5><p>Once a key is registered, we break out of the polling loop and add the correct piece or take the last piece off the stack in memory. If a piece is taken off, maybe I will set a flag in memory to trigger <code>DrawBurger</code> to erase the graphic properly.</p><h4>A short conclusion</h4><p>From now on, I am unlikely to finish these more complex programs within a single &#8220;day&#8221;. However, I will still report to you what I&#8217;ve learned right after I&#8217;ve done it, such is the concept! That means programs will be written over multiple posts, but on the flip side, I won&#8217;t be held back by what&#8217;s possible within a single session. It should allow me to be as ambitious as I want to be!</p><p>Thanks a lot for reading this. I hope you will stick with me until we can both be stacking burgers in the program!</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-5-stacks-and-my-burger-stacking?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">&#171; <a href="https://cyanne.study/p/day-4-grappling-with-addressing-modes">Day 4</a> &#12539; Day 5</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-5-stacks-and-my-burger-stacking?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://cyanne.study/p/day-5-stacks-and-my-burger-stacking?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><p></p>]]></content:encoded></item><item><title><![CDATA[ASM day 4: Grappling with addressing modes]]></title><description><![CDATA[And rewriting my very first program to be much smarter]]></description><link>https://cyanne.study/p/day-4-grappling-with-addressing-modes</link><guid isPermaLink="false">https://cyanne.study/p/day-4-grappling-with-addressing-modes</guid><dc:creator><![CDATA[Cyanne]]></dc:creator><pubDate>Wed, 18 Jan 2023 03:13:25 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/ba0ea9c4-f2ea-4752-85c7-4f88e034990f_1280x1280.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome back to day 4 of my classic development journey, where for the moment I&#8217;m following the <em>Easy6502</em> tutorial that you may find <a href="https://skilldrick.github.io/easy6502/">here</a>.</p><p>I&#8217;ve been memorizing the 6502 processor&#8217;s table of opcodes before I even knew what any of it meant, but straight away I noticed the instructions are <strong>duplicated</strong> many times over. By now, I know that these are the different <em>addressing mode</em> flavors that each of the instructions come in.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9KIR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9KIR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png 424w, https://substackcdn.com/image/fetch/$s_!9KIR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png 848w, https://substackcdn.com/image/fetch/$s_!9KIR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png 1272w, https://substackcdn.com/image/fetch/$s_!9KIR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9KIR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png" width="1456" height="591" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:591,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:166696,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9KIR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png 424w, https://substackcdn.com/image/fetch/$s_!9KIR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png 848w, https://substackcdn.com/image/fetch/$s_!9KIR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png 1272w, https://substackcdn.com/image/fetch/$s_!9KIR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d7ce139-a4c7-433e-a581-5b4fd7d636c6_2172x882.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Did you know: the 6502 is the first generation in its series and has 151 opcodes to memorize, just like Pokemon. :) <a href="https://www.masswerk.at/6502/6502_instruction_set.html">[Source</a>]</figcaption></figure></div><p>An addressing mode is one of the various ways in which you can use an instruction, either by giving it a byte to handle directly, or a memory address, or perhaps a memory address with an <em>offset</em>. It kind of reminds me of how in normal programming a function can have multiple arguments, but here it is within a much more limited structure.</p><p>We have many of these modes to learn: <em>implied</em>, <em>absolute (X/Y-indexed), zeropage (X/Y-indexed), immediate, relative, X-indexed indirect and Indirect, Y-indexed. </em>This was a <strong>lot</strong> to take in for me, and just trying to understand it and taking my notes took up most of the time I had planned for the day. Hence, I&#8217;m not writing this on the same day I did these exercises. </p><p>Here are the notes I took:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nPaW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nPaW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png 424w, https://substackcdn.com/image/fetch/$s_!nPaW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png 848w, https://substackcdn.com/image/fetch/$s_!nPaW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png 1272w, https://substackcdn.com/image/fetch/$s_!nPaW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nPaW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png" width="963" height="753" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:753,&quot;width&quot;:963,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:110024,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nPaW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png 424w, https://substackcdn.com/image/fetch/$s_!nPaW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png 848w, https://substackcdn.com/image/fetch/$s_!nPaW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png 1272w, https://substackcdn.com/image/fetch/$s_!nPaW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0c7c9762-9981-464f-8565-65c37e3faa7e_963x753.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>Figuring out what modes do in practice</strong></h4><p>So because this amount of information is hard to summarize, I will focus on how these various addressing modes may be used in practice.</p><ul><li><p><strong>Implied mode<br></strong>The most simple mode: we do not need to specify anything for this instruction, as it knows what to do by just by calling its name. Say: <code>INX</code>, or &#8220;Increment X&#8221;, and nothing more is needed.</p></li><li><p><strong>Immediate mode<br></strong>For when we want to pass a single byte (an 8-bit, 0-255 value) to the instruction. Say: <code>LDA #$01</code>. We&#8217;ve loaded the number 1 into the Accumulator. As we&#8217;ve learned before, the <code>#</code> indicates the <code>01</code> value is a number, not an address.</p></li><li><p><strong>Zeropage mode<br></strong>We can indicate an address to the instruction using a single byte, as long as it&#8217;s on the zeroth page of memory: <code>$0000</code> to <code>$00ff</code>. Say: <code>LDA $01</code>, shorthand for &#8216;load the value at address <code>$0001</code> into the Accumulator&#8217;.</p><ul><li><p>This makes the first 256 positions in memory kind of special. I&#8217;ve heard the zeropaged addresses may be treated as second rank registers in addition to X and Y.</p></li></ul></li><li><p><strong>Zeropage X/Y-indexed modes<br></strong>This is how we can finally state: &#8216;read or write from &#8220;this + X&#8221; or &#8220;that + Y&#8221; address&#8217;. Following with:</p></li><li><p><strong>Absolute, and Absolute X/Y-indexed modes<br></strong>We can pass the instruction a full address (say: <code>JMP $1234</code>), or offset it by X or Y. Say: <code>STA $1000,X</code>. If X is 1, this means &#8216;store the value at <code>$1001</code> into the Accumulator&#8217;.</p></li></ul><p>We now know enough to be able to fill the screen with random colors, which is something we previously couldn&#8217;t do! </p><pre><code> LDA #$00    ; Immediate mode: Initialize A
 LDX #$00    ; Immediate mode: Initialize X, the screen position
loop:
 LDA $fe     ; Zeropage mode: Load a value from the randomizer register
 STA $0200,X ; Zeropage X-indexed mode: Write to an offset screen position
 INX         ; Implied mode: Increment the screen position
 JMP loop    ; Absolute mode: the 'loop' label is actually a full address.</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AS-U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AS-U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif 424w, https://substackcdn.com/image/fetch/$s_!AS-U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif 848w, https://substackcdn.com/image/fetch/$s_!AS-U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif 1272w, https://substackcdn.com/image/fetch/$s_!AS-U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AS-U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif" width="166" height="166" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:160,&quot;width&quot;:160,&quot;resizeWidth&quot;:166,&quot;bytes&quot;:22038,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AS-U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif 424w, https://substackcdn.com/image/fetch/$s_!AS-U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif 848w, https://substackcdn.com/image/fetch/$s_!AS-U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif 1272w, https://substackcdn.com/image/fetch/$s_!AS-U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3f97940-1ba3-4c88-b436-761b70e92b9d_160x160.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Note this doesn&#8217;t actually fill the <em>entire</em> screen with colors, because we can only offset our screen writing address by a value up to 255. </figcaption></figure></div><ul><li><p><strong>Relative mode<br></strong>This is what Branching instructions use to jump a relative amount of bytes through the program. Once again it&#8217;s only an 8-bit value, so that&#8217;s why it can&#8217;t jump too far back or ahead.</p></li></ul><p>And finally, that leaves us with the indirect modes:</p><ul><li><p><strong>Indirect mode (vanilla)<br></strong>We point the instruction to a full address, which at that position should contain the actual address of interest for the instruction to act on. <br>Because of how the 6502 reads values of two bytes in reverse (a fact we just have to accept)<em>, </em>it reads the second byte as the first part and the first byte as the second part.<br>Let&#8217;s visualize what &#8220;<code>JMP (40f0)&#8221;</code> does. The parentheses indicate that it&#8217;s indirectly addressed. As you can see below, it starts to read the value starting at <code>$40f0</code> in memory in reverse, and that&#8217;s the address you get to jump to:<code> $cc01</code>.</p></li></ul><pre><code>MEMORY      40f0 40f1 40f2 40f3
VALUE         01   cc   00   00
                \ /
                / \
JMP (40f0) -&gt; $cc  01</code></pre><ul><li><p><strong>X-indexed indirect mode<br></strong>This is the same as before, but it starts reading from the specified address <em>offset by X</em>.<strong> </strong>Also, we can now only read from zeropaged addresses.</p></li></ul><ul><li><p><strong>Indirect mode, Y-indexed</strong></p><p>It starts reading from the zeropaged address we hand the instruction, then finds the register of interest and adds Y to it.</p></li></ul><p>As this is going on for long enough, I will leave writing a program with Indirect mode for a later day.</p><h4>Rewriting my first program to be smarter!</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xF8u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xF8u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png 424w, https://substackcdn.com/image/fetch/$s_!xF8u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png 848w, https://substackcdn.com/image/fetch/$s_!xF8u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png 1272w, https://substackcdn.com/image/fetch/$s_!xF8u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xF8u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png" width="608" height="312" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:312,&quot;width&quot;:608,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15093,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xF8u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png 424w, https://substackcdn.com/image/fetch/$s_!xF8u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png 848w, https://substackcdn.com/image/fetch/$s_!xF8u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png 1272w, https://substackcdn.com/image/fetch/$s_!xF8u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc2b70bb-4efd-47ba-9b0a-ccf7fb713cfa_608x312.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">My Day 1 program.</figcaption></figure></div><p>Not long ago I wrote this simple program only by loading values and storing them back into screen memory by hand. It&#8217;s simple, and actually very efficient. But now instead of simply listing out the pixels, our mission is to create these laser gun images again but through <strong>logic</strong>.</p><p>Let&#8217;s start by storing the laser gun graphics into memory so we&#8217;re able to reuse it, kind of like a sprite. The guns aren&#8217;t only drawn four times over, but many parts of it are repeated. Therefore we can use the familiar LDA and STA commands to store the image&#8217;s 4 unique rows neatly in memory:</p><pre><code>0000: 00 06 0e 03 01 03 0e 06 00 00 06 0e 01 0e 06 00 
0010: 00 00 0b 0b 0c 0c 0f 0f 00 0b 0a 0c 0c 0f 0f 0c  </code></pre><p>We then jot down some logic to make these lines appear back on the screen in the most simple fashion. We use X to keep track of the <em>memory position</em> we read the color at, and Y to keep track of the <em>screen position</em> we write our color <em>to</em>. We then repeat through this code using a loop, and read and write at incrementing positions through zeropage memory offsets.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tz1P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tz1P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png 424w, https://substackcdn.com/image/fetch/$s_!tz1P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png 848w, https://substackcdn.com/image/fetch/$s_!tz1P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png 1272w, https://substackcdn.com/image/fetch/$s_!tz1P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tz1P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png" width="608" height="422" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:608,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26506,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tz1P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png 424w, https://substackcdn.com/image/fetch/$s_!tz1P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png 848w, https://substackcdn.com/image/fetch/$s_!tz1P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png 1272w, https://substackcdn.com/image/fetch/$s_!tz1P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf4f39bb-40be-40c7-a2b8-9dd64da69820_608x422.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The Monitor is showing the image&#8217;s data we stored into memory.</figcaption></figure></div><p>Now I tried to write each 8 pixels of the image on its own line, by adding the screen width of <code>#$20</code> (32 pixels) to Y after 8 pixels are drawn.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!br4Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!br4Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif 424w, https://substackcdn.com/image/fetch/$s_!br4Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif 848w, https://substackcdn.com/image/fetch/$s_!br4Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif 1272w, https://substackcdn.com/image/fetch/$s_!br4Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!br4Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif" width="604" height="308" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:308,&quot;width&quot;:604,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:298995,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!br4Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif 424w, https://substackcdn.com/image/fetch/$s_!br4Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif 848w, https://substackcdn.com/image/fetch/$s_!br4Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif 1272w, https://substackcdn.com/image/fetch/$s_!br4Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6df0c4e8-499e-48ac-a491-348d99fdba02_604x308.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Oops, I didn&#8217;t think the addition through&#8230; We were already 8 pixels in and trigger the Branch at 9, so we have to add the whole screen&#8217;s width <em>minus 9</em> to Y instead.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!27-P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!27-P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png 424w, https://substackcdn.com/image/fetch/$s_!27-P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png 848w, https://substackcdn.com/image/fetch/$s_!27-P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png 1272w, https://substackcdn.com/image/fetch/$s_!27-P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!27-P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png" width="606" height="392" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/23827442-a612-4b60-b784-c2c014bf8f31_606x392.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:392,&quot;width&quot;:606,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26151,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!27-P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png 424w, https://substackcdn.com/image/fetch/$s_!27-P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png 848w, https://substackcdn.com/image/fetch/$s_!27-P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png 1272w, https://substackcdn.com/image/fetch/$s_!27-P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23827442-a612-4b60-b784-c2c014bf8f31_606x392.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>There, we successfully wrote the graphics data stored in memory to the screen in its compressed state. We now have to write logic to repeat lines, and elongate the image into its original shape.</p><p>Since the X and Y registers are already taken now, we&#8217;re going to have to use page zero to store more variables than just those two. When we do some operations, we&#8217;ll have to back up our Y register temporarily. I really wanted to prevent this, but I could not think of a way to use less variables than this.</p><p>We will have an area in memory starting at <code>$20</code> that indicates where every line needs to start reading in the sprite data area. By pointing to a position in the sprite data, each line is simple to repeat and define. If we say for line 1 to 16 you start reading at 0, where the blue laser beam is, then we now drawn 4 long laser beam images. In effect, this is kind of like a <em>tile map</em>. This data looks as follows:</p><pre><code>0020: 00 60 68 00 00 60 68 68 00 60 68 00 00 60 68 60 
0030: 08 18 70 18 10 10 10 10 10 10 10 10 10 10 10 10 
0040: ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 </code></pre><p>Then, for our new zeropage area variables:</p><p><code>$50</code> will count at which line we are at.<br><code>$52</code> will count at which line we are at.<br><code>$61</code> will be where we backup Y.</p><p>In a loop, we keep reading colors from a zeropaged offset address through <code>LDA $00,X</code>, and keep storing them into screen memory with an absolute offset address through <code>STA $0200,Y</code>, because <code>$0200</code> is where the screen memory starts.</p><p>We branch to the <code>AddLine</code> label when we&#8217;ve completed 8 pixels (<code>LDA $52</code>, <code>CMP #$09</code>), and increment the line order and line progress counters. We look back into line order memory (<code>$20</code>+) to see at what position in the graphics memory we should start reading the colors for the next line, which we set X to. If our line order starting position returns <code>$ff</code>, then the program knows to branch to the <code>exit</code> label and <code>BRK</code>.</p><p>We have to juggle some variables around, and I had to do a lot of reasoning in my head when the program just didn&#8217;t draw anything coherent. Luckily, I found out that the Debugger can jump to any label, so I could step through specific parts without having to step through the whole program.</p><p>And things started to take shape:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wIQG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wIQG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png 424w, https://substackcdn.com/image/fetch/$s_!wIQG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png 848w, https://substackcdn.com/image/fetch/$s_!wIQG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png 1272w, https://substackcdn.com/image/fetch/$s_!wIQG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wIQG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png" width="610" height="495" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:495,&quot;width&quot;:610,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27131,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wIQG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png 424w, https://substackcdn.com/image/fetch/$s_!wIQG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png 848w, https://substackcdn.com/image/fetch/$s_!wIQG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png 1272w, https://substackcdn.com/image/fetch/$s_!wIQG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b45f25b-663f-4867-92cf-1fd4b9262710_610x495.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">I made some <em>off by one </em>errors&#8230;</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xB74!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xB74!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png 424w, https://substackcdn.com/image/fetch/$s_!xB74!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png 848w, https://substackcdn.com/image/fetch/$s_!xB74!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png 1272w, https://substackcdn.com/image/fetch/$s_!xB74!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xB74!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png" width="605" height="462" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:462,&quot;width&quot;:605,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:33388,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xB74!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png 424w, https://substackcdn.com/image/fetch/$s_!xB74!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png 848w, https://substackcdn.com/image/fetch/$s_!xB74!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png 1272w, https://substackcdn.com/image/fetch/$s_!xB74!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b7e8e88-32c3-46fb-9829-81dc06fd3298_605x462.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">&#8230;and fixed them.</figcaption></figure></div><p>And there we are back to the original result from Day 1, but this time drawn with more complicated logic!</p><p>Actually, it&#8217;s missing the differently colored LEDs, but instead of storing unique graphics lines for that, let&#8217;s one-up our old result and make the <em>laser beams</em> different colors instead.</p><p>We don&#8217;t have enough space to fit all the new colored graphics into memory, so we cheat and continue our sprite area from address <code>$60</code> onwards. I pick some nice colors so we now have red and green laser beams too!</p><p>The program can draw each beam differently by simply changing where each line should start in graphics memory.</p><pre><code> LDA #$00   ; Gun 1 Blue Laser Upper Row
 STA $20
 LDA #$60   ; Gun 2 Red Laser Upper Row
 STA $21
 LDA #$68   ; Gun 3 Green Laser Upper Row
 STA $22
 LDA #$00   ; Gun 4 Blue Laser Upper Row
 STA $23</code></pre><p>It&#8217;s quite easy to do this now: we just change each of the lines we want, and leave the &#8220;body&#8221; of the guns alone to draw the same lines from graphics memory for all 4 guns.</p><p>So finally, for the grand result:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5s7M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5s7M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png 424w, https://substackcdn.com/image/fetch/$s_!5s7M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png 848w, https://substackcdn.com/image/fetch/$s_!5s7M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png 1272w, https://substackcdn.com/image/fetch/$s_!5s7M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5s7M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png" width="606" height="462" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:462,&quot;width&quot;:606,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26151,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5s7M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png 424w, https://substackcdn.com/image/fetch/$s_!5s7M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png 848w, https://substackcdn.com/image/fetch/$s_!5s7M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png 1272w, https://substackcdn.com/image/fetch/$s_!5s7M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b74e880-85de-4fb7-8299-8603c5af9062_606x462.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">To show how easily I can swap out graphics lines, I made the fourth gun a cool combination of the other three!</figcaption></figure></div><ul><li><p><a href="https://gist.github.com/Cyanne/c7a97b4be30ad515ddbd5cdeb1c81055">The code for this program is available here.</a></p></li></ul><p>And that brings us to the end! There are still some loose ends regarding addressing modes.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> I need to consider how to deal with these topics that want to take up more than a single day. There&#8217;s much to learn for me, which is most definitely the point of everything I&#8217;m doing here.</p><p>Thanks a lot for reading this day&#8217;s post, and see you in the next one. ^-^</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-4-grappling-with-addressing-modes?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption"><a href="https://cyanne.study/p/day-3-i-figure-out-branching-and">&#171; Day 3</a> &#12539; Day 4 &#12539; <a href="https://cyanne.study/p/day-5-stacks-and-my-burger-stacking">Day 5</a> &#187;</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-4-grappling-with-addressing-modes?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://cyanne.study/p/day-4-grappling-with-addressing-modes?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>The final program contains a bug in its logic, and it only works when I initialize the line order counter (<code>$50</code>) as <code>#$01</code>. I cannot figure out why. If you do know the reason for my bug, then I&#8217;d love if you told me.</p></div></div>]]></content:encoded></item><item><title><![CDATA[ASM day 3: I figure out branching and play Sporcle]]></title><description><![CDATA[Learning assembly by heart]]></description><link>https://cyanne.study/p/day-3-i-figure-out-branching-and</link><guid isPermaLink="false">https://cyanne.study/p/day-3-i-figure-out-branching-and</guid><dc:creator><![CDATA[Cyanne]]></dc:creator><pubDate>Wed, 11 Jan 2023 00:51:52 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/318ffabb-ff11-41aa-8b7e-a95b0968ec04_640x640.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Without further ado, we&#8217;re diving into the <em>Branching</em> section of <a href="https://skilldrick.github.io/easy6502/">the 6502 tutorial I&#8217;m following</a>. I&#8217;m hopeful to learn how to use the equivalent of <code>if</code> statements in assembly.</p><p>The following program is given as an example of branching:</p><pre><code>  LDX #$08
decrement:
  DEX
  STX $0200
  CPX #$03
  BNE decrement
  STX $0201
  BRK</code></pre><p>First off, I notice a <em>label</em> called <code>decrement</code>. Instead of <code>JMP</code>ing to an exact address figured out through disassembly, we can instead simply refer to a label. That makes things easier straight off the bat.</p><p>I interpreted this program as follows: We store value 8 in the <code>X</code> register. After the <code>decrement</code> label, we then store <code>X</code>&#8217;s value at memory address <code>$0200</code>, which I later realize is the start of screen memory (<code>$0200</code>-<code>$05ff</code>). With <code>CPX</code> we compare 3 to X. If it&#8217;s not equal, we jump back to the address of the <code>decrement</code> label. Else, we keep running and store X at memory address <code>$0201</code>. The program exits.</p><p>Reading the explanation, it is the <em>Compare</em> instructions (<code>CMP</code>, <code>CPX</code>, <code>CPY</code>) that set or clear the Zero flag in the Processor&#8217;s status register. This is why BEQ is documented as Branch on EQual <em>zero set</em>, and BNE as Branch Not Equal <em>zero clear</em>.  Branch on Carry Clear and Branch on Carry Set incorporate how they react to this flag within their names. It checks for the <code>Z</code> flag to determine whether to branch. In pseudocode, I see it as:</p><pre><code>BEQ: if (Z) { branch(); }
BNE: if (!Z) { branch(); }

BCC: if (!C) { branch(); }
BCS: if (C) { branch(); }</code></pre><p>The tutorial then offers you two challenges:</p><h4>Exercise 1: Try writing a program that uses <em>Branch on Equal</em></h4><p>I got to work and started experimenting. The logic is clear enough to me, but drawing single pixels to the screen isn&#8217;t. I decided to draw a pixel heart with <code>STA</code> commands so we have a nice visual to see what&#8217;s happening.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iakY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iakY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png 424w, https://substackcdn.com/image/fetch/$s_!iakY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png 848w, https://substackcdn.com/image/fetch/$s_!iakY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png 1272w, https://substackcdn.com/image/fetch/$s_!iakY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iakY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png" width="602" height="306" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:306,&quot;width&quot;:602,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16349,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iakY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png 424w, https://substackcdn.com/image/fetch/$s_!iakY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png 848w, https://substackcdn.com/image/fetch/$s_!iakY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png 1272w, https://substackcdn.com/image/fetch/$s_!iakY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19feb7fe-43e2-49b7-8802-ca87128ed81c_602x306.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I add the following loop logic to redraw the heart in cycled colors.</p><pre><code> INX
 CPX #$ff
 BEQ skip
 BNE loop
skip:
 BRK</code></pre><p>We keep incrementing <code>X</code> to change colors and redraw the heart to reflect the change. Once <code>X</code> hits <code>$ff</code>, we break out of the loop.</p><p>With the simulator running quickly, I want to count to <code>$ff</code> before changing colors so that there is a bit of delay. I use <code>X</code> as the timer multiplier that determines how many times <code>Y</code> should wrap back to $<code>00</code> before continuing:</p><pre><code>LDX #$05                ; Set timer multiplier to 5 times
draw:
 {Draw heart}
wait:
 INY
 CPY #$00
 BNE wait               ; Go back to wait: until Y has wrapped around
 DEX
 CPX #$00
 BNE wait               ; Go back to wait: until X has become zero.
 {Change drawing color}
 JMP draw               ; Back to drawing.</code></pre><p>This lets me have all the control I want: I can change the colors each loop, and by adding more logic I can even decide how many loops each color should last for. Adding everything I know so far together, I created a pulsating heart animation.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pFsV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pFsV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif 424w, https://substackcdn.com/image/fetch/$s_!pFsV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif 848w, https://substackcdn.com/image/fetch/$s_!pFsV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif 1272w, https://substackcdn.com/image/fetch/$s_!pFsV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pFsV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif" width="602" height="527" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:527,&quot;width&quot;:602,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:107306,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pFsV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif 424w, https://substackcdn.com/image/fetch/$s_!pFsV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif 848w, https://substackcdn.com/image/fetch/$s_!pFsV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif 1272w, https://substackcdn.com/image/fetch/$s_!pFsV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e6011c-5d88-4f60-b479-f50c5c4dd30f_602x527.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I included the entire code because it fit. ^-^ I was quite happy per usual. In this GIF, we can see how the <code>Y</code> register keeps counting up, triggering the <code>X</code> register to count down to zero where it is then reset to a multiplier value of my choice. One that&#8217;s shorter for the dark color, and another that&#8217;s longer for the light color, mimicking the rhythm of a heartbeat. As a fancy experiment, I store both the colors and their multipliers in memory at <code>$0000</code> and <code>$0001</code>. <a href="https://gist.github.com/Cyanne/69f57f3d46495fa53639d9c45b616947">The code is available here</a>.</p><p>This code includes the <code>BEQ</code> instruction, so I consider the exercise done!</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Cyanne&#8217;s Debug Room! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h4>Exercise 2: Write a program that uses <em>Branch on Carry Clear</em> or <em>Set</em></h4><p>Ignoring the mathematical purpose the Carry flag may actually be for, I just focused on what I know it does in effect: set once the Accumulator overflows.</p><p>The Accumulator will be the timer counter this time, counting up to <code>$ff</code> letting <code>Y</code> increase every time <code>Carry</code> is set. <code>X</code> will be the drawing color. The looping logic is similar to before.</p><p>We define a palette of five fading colors in memory addresses <code>$0001</code> to <code>$0005</code> so that we only need to define their values once. Y increments, and we handpick each of the values where Y triggers a branch to a different part of the program. These parts each load different values from memory to set the drawing color <code>X</code>. Once we have cycled through all colors we set <code>Y</code> back to the starting value we stored at address <code>$0010</code>. This is the result:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tgbG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tgbG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif 424w, https://substackcdn.com/image/fetch/$s_!tgbG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif 848w, https://substackcdn.com/image/fetch/$s_!tgbG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif 1272w, https://substackcdn.com/image/fetch/$s_!tgbG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tgbG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif" width="602" height="441" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:441,&quot;width&quot;:602,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:121846,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tgbG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif 424w, https://substackcdn.com/image/fetch/$s_!tgbG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif 848w, https://substackcdn.com/image/fetch/$s_!tgbG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif 1272w, https://substackcdn.com/image/fetch/$s_!tgbG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfd5923c-f096-4b67-8dda-33a06cd9b847_602x441.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p> <a href="https://gist.github.com/Cyanne/02eb7c634b57ff113394c59914b68e0e">The code is available here.</a> </p><p>I think it achieved the effect I had in mind, and it&#8217;s thanks to branching that I can now create something like this at all. I look forward to learn much more effective ways to achieve this same logic.</p><h4>I challenge you to beat my WRs on Sporcle!</h4><p>Now something I have been distracting myself with that still relates to this journey is <a href="https://www.sporcle.com">Sporcle</a>. In short it&#8217;s a website where you can play memory quizzes and create ones yourself as well. I decided to make my own 6502 themed quizzes:</p><ul><li><p><strong>Can you name the 6502 Instruction Set?</strong> <a href="https://www.sporcle.com/games/Cyanne/6502-instructions-easy">https://www.sporcle.com/games/Cyanne/6502-instructions-easy</a><br><em>My current best time: all 56 in <strong>00:41.</strong></em></p></li><li><p><strong>Can you name the 6502 Instruction Set (Blind)?</strong> <a href="https://www.sporcle.com/games/Cyanne/6502-instructions-blind">https://www.sporcle.com/games/Cyanne/6502-instructions-blind</a><br><em>My current best time: all 56 in <strong>01:35.</strong></em></p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Pg70!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Pg70!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png 424w, https://substackcdn.com/image/fetch/$s_!Pg70!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png 848w, https://substackcdn.com/image/fetch/$s_!Pg70!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png 1272w, https://substackcdn.com/image/fetch/$s_!Pg70!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Pg70!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png" width="941" height="719" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/64048ca9-206b-4411-bd8d-014999e57db2_941x719.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:719,&quot;width&quot;:941,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:81237,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Pg70!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png 424w, https://substackcdn.com/image/fetch/$s_!Pg70!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png 848w, https://substackcdn.com/image/fetch/$s_!Pg70!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png 1272w, https://substackcdn.com/image/fetch/$s_!Pg70!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64048ca9-206b-4411-bd8d-014999e57db2_941x719.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p><strong>Can you name the 6502 Opcode Table? (tough!) </strong><a href="https://www.sporcle.com/games/Cyanne/6502-opcode-table">https://www.sporcle.com/games/Cyanne/6502-opcode-table</a><br><em>My current best: 71 instructions or 47%.</em></p></li></ul><p>I&#8217;m going to have much more fun with this in my downtime, so maybe you&#8217;ll find these quizzes or completely different ones fun as well.</p><p>See you next time!<br></p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-3-i-figure-out-branching-and?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption"><a href="https://cyanne.study/p/day-2-getting-up-to-speed-by-learning">&#171; Day 2</a> &#12539; Day 3 &#12539; <a href="https://cyanne.study/p/day-4-grappling-with-addressing-modes">Day 4 &#187;</a></p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-3-i-figure-out-branching-and?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://cyanne.study/p/day-3-i-figure-out-branching-and?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><p></p>]]></content:encoded></item><item><title><![CDATA[ASM day 2: Getting up to speed by learning as much as I can]]></title><description><![CDATA[You're introducing me to Envee B'dizuk already..?]]></description><link>https://cyanne.study/p/day-2-getting-up-to-speed-by-learning</link><guid isPermaLink="false">https://cyanne.study/p/day-2-getting-up-to-speed-by-learning</guid><dc:creator><![CDATA[Cyanne]]></dc:creator><pubDate>Sun, 08 Jan 2023 02:48:25 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!UM5U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome to day 2 of my personal path to learning assembly. As before I will be using the Easy6502 simulator found <a href="https://skilldrick.github.io/easy6502/">here</a>, and this is also where you can follow along with the tutorial I&#8217;m studying.</p><p>Through my own curiosity and getting new things kindly taught to me, I&#8217;ve learned just a bit more about the basics.</p><h4>How the program is read</h4><p>I now know that the &#8220;PC&#8221; value I noticed in the debugger is the <em>Program Counter</em> register, counting up in 16 bits. This is what keeps track of what position the program is at in the machine code.</p><p>Going through my program with the Step button, I quickly noticed the counter does not increment one by one, or even consistently. The key that helped me understand this behavior is the Disassemble button. For the first example program it showed me the following:</p><pre><code>Address  Hexdump   Disassembly
-------------------------------
$0600    a9 01     LDA #$01
$0602    8d 00 02  STA $0200
$0605    a9 05     LDA #$05
$0607    8d 01 02  STA $0201</code></pre><p>I was taught that the first <code>a9</code> in the &#8220;Hexdump&#8221; column is there to signal the <code>LDA</code> instruction to the processor. The Program Counter increments, and then reads the value of 01 (the <code>#$01</code> that the LDA was provided as an &#8216;argument&#8217;). That&#8217;s it for that line of assembly code, the <code>PC</code> increments and then there&#8217;s the <code>8d</code> for the next <code>STA</code> instruction, which continues to span over the next two bytes. Now it makes sense that the <code>PC</code> doesn&#8217;t increase consistently: in the Debugger we see it stop after every line of assembly code, and that can be one or more bytes in machine language!</p><p>I deduced that the processor must know how many bytes should follow after that first number, the <em>opcode</em>. It&#8217;s also interesting to note that the opcode will change depending on what the argument tells it to do.</p><pre><code>Address  Hexdump   Disassembly
-------------------------------
$0600    a9 10     LDA #$10
$0602    a5 10     LDA $10</code></pre><p>Opcode <code>a9</code> specifies that a literal value <code>$10</code> should be loaded into <code>A</code>, while opcode <code>a5</code> tells the processor that register <code>$10</code>&#8217;s content is to be loaded into <code>A</code>. It might be the same <code>LDA</code> instruction in assembly language, but it&#8217;s not the same opcode in <em>machine</em> language. When you consider that you&#8217;re literally telling it to do two different things, it does make sense.</p><p>All of these opcodes can be found in a supposedly logical order in a big table. It goes over my head right now, but it&#8217;s interesting! Masswerk&#8217;s page I found <a href="https://www.masswerk.at/6502/6502_instruction_set.html">here</a> seemed so useful that I quickly took a few screenshots and constructed a cheat sheet from it:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UM5U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UM5U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png 424w, https://substackcdn.com/image/fetch/$s_!UM5U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png 848w, https://substackcdn.com/image/fetch/$s_!UM5U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png 1272w, https://substackcdn.com/image/fetch/$s_!UM5U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UM5U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png" width="211" height="245.34546703296704" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1693,&quot;width&quot;:1456,&quot;resizeWidth&quot;:211,&quot;bytes&quot;:330789,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UM5U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png 424w, https://substackcdn.com/image/fetch/$s_!UM5U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png 848w, https://substackcdn.com/image/fetch/$s_!UM5U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png 1272w, https://substackcdn.com/image/fetch/$s_!UM5U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3704572-eae9-4b97-8c64-95f64a02a35e_1558x1812.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>Brain Training</h4><p>So I will not deny that all of this is a lot information for me to take in. However, I really want to have as much of this knowledge memorized as possible. Even if I don&#8217;t understand what it all means yet, I&#8217;d rather know it by heart than having to keep looking it up, especially when trying to fluently read and write code.</p><p>While I have struggled with memorization, what has worked best for me is something called a <a href="https://en.wikipedia.org/wiki/Spaced_repetition">spaced repetition system</a>, a clever way to use flash cards for any data you want to remember. <a href="https://apps.ankiweb.net/">Anki</a> being the most used software for this.</p><p>I got to work and created a deck of flash cards with the instruction abbreviation as the question and the full name as the answer. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aCX5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aCX5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png 424w, https://substackcdn.com/image/fetch/$s_!aCX5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png 848w, https://substackcdn.com/image/fetch/$s_!aCX5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png 1272w, https://substackcdn.com/image/fetch/$s_!aCX5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aCX5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png" width="821" height="443" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:443,&quot;width&quot;:821,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:25831,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aCX5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png 424w, https://substackcdn.com/image/fetch/$s_!aCX5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png 848w, https://substackcdn.com/image/fetch/$s_!aCX5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png 1272w, https://substackcdn.com/image/fetch/$s_!aCX5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43613460-d1c3-4ccd-85e8-75e533f4fa26_821x443.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><ul><li><p><a href="https://gist.github.com/Cyanne/4e8cccbb36a497239ec256f1253dc754">I&#8217;ve made this &#8220;6502 Instruction names&#8221; deck available here</a> to import into Anki, if you are interested.</p></li></ul><p>I tested myself on the entire deck of 68 cards (it also quizzes you on some registers and flag abbreviations), and just as I had hoped I already feel more confident. I got a slight feel for how things are called and what things might be possible.</p><p>Because we&#8217;re dealing with hexadecimal numbers a lot, I decided to memorize the 256 8-bit values in the same way, from hexadecimal to decimal and vice versa. This was a bit more taxing than the instruction names to be quizzed about, and all this calculating gave me flashbacks to DS Brain Training&#8230; But similarly here, I&#8217;m already more comfortable converting between &#8220;hex&#8221; and &#8220;dec&#8221; now.</p><ul><li><p><a href="https://gist.github.com/Cyanne/111f5abcf399a7e3c0920ecc1ddd2d0f">My &#8220;Hexadecimal and Decimal&#8221; deck is available for download here, too.</a></p></li></ul><h4>Applying some new knowledge</h4><p>I decided to spice up my previous little program a bit. Starting with adding comments, because I know that last day&#8217;s <a href="https://gist.github.com/Cyanne/c421b83bc1abc96f9a423634170be862">long list of instructions drawing the laser guns</a> was not very kind to read. I happened to find out that the semicolon can be used to comment out any text, so let&#8217;s do something about this! I used <code>BRK</code> (BReaK) statements for the first time to stop the program from running at certain points of interest. That way I could easily figure out what was happening there and add in a few comments.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZyYo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZyYo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png 424w, https://substackcdn.com/image/fetch/$s_!ZyYo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png 848w, https://substackcdn.com/image/fetch/$s_!ZyYo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png 1272w, https://substackcdn.com/image/fetch/$s_!ZyYo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZyYo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png" width="260" height="402" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:402,&quot;width&quot;:260,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16682,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZyYo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png 424w, https://substackcdn.com/image/fetch/$s_!ZyYo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png 848w, https://substackcdn.com/image/fetch/$s_!ZyYo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png 1272w, https://substackcdn.com/image/fetch/$s_!ZyYo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1fe93643-8785-4feb-ab2e-97a380387eff_260x402.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Furthermore, thanks to the Disassembly option I now know which program addresses correspond with which lines in assembly code. And I really wanted to see if I could make the <code>JMP</code> (<strong>J</strong>u<strong>MP</strong>) instruction work. Loops are important in pretty much any program! And without much trouble I added a <code>JMP $09c0</code> at the end and it worked exactly as I thought it would. Why&#8217;s that you ask? It&#8217;s because rabbits know how to <code>JMP</code>. ^-^</p><p>In Easy6502, the <code>$fe</code>  register returns a random value for each instruction. A random value equals a random color! So I figured out the position of the laser gun LEDs, and decided to make them throw an RGB rave party&#8212;</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bct0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bct0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif 424w, https://substackcdn.com/image/fetch/$s_!bct0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif 848w, https://substackcdn.com/image/fetch/$s_!bct0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif 1272w, https://substackcdn.com/image/fetch/$s_!bct0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bct0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif" width="604" height="308" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:308,&quot;width&quot;:604,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:240371,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bct0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif 424w, https://substackcdn.com/image/fetch/$s_!bct0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif 848w, https://substackcdn.com/image/fetch/$s_!bct0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif 1272w, https://substackcdn.com/image/fetch/$s_!bct0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb319e8e-97b5-49f9-80ef-e82110ddc887_604x308.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I won&#8217;t deny that I&#8217;m quite happy with this result! When there&#8217;s so little I can do as of now, small achievements count a lot for me.</p><ul><li><p><a href="https://gist.github.com/Cyanne/9e63046191a13ab0a70faa34bfdd8e42">The code is available on my GitHub Gists.</a></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Cyanne&#8217;s Debug Room! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><h4>The tutorial - Registers, flags, and weird names</h4><p>It turns out the SR or <em>Status Register</em> is something the processor provides for you to read from, so that you can find out what certain effects an instructions may have had. The register uses 7 flags, each with its own bit. It&#8217;s also refered to as <code>NV-BDIZC</code>. This is a jumble of letters representing each of the flag&#8217;s meanings. </p><p><strong>N</strong>egative - o<strong>V</strong>erflow, <strong>B</strong>reak - <strong>D</strong>ecimal - <strong>I</strong>nterrupt - <strong>Z</strong>ero - <strong>C</strong>arry.</p><p>I tried to make this easier to remember. Hmm, <code>NV-BDIZC</code>? Let&#8217;s pronounce it <em>Envee B&#8217;dizuk</em>, an odd name, but it actually made me able to recall the Negative oVerflow etc etc. line of bits in order! Mnemonics are powerful enough to be worth the embarrassing nonsense it makes you come up with.</p><p>The tutorial shows how the Carry flag is triggered once the Accumulator overflows past <code>$ff</code> after an ADC (AdD with Carry) instruction. For people who like old games as I do, that overflow is pretty famous for causing all kinds of unintended results. I wouldn&#8217;t have guessed there is a flag to catch this type of error.</p><p>I did memory monitoring for the first time. I could see a value being put into a memory address amidst a sea of <code>00</code>s. It&#8217;s cool to me.</p><p>I got to play around with TAX (Transport A to X), TAY (Transport A to Y), TXA (Transport X to A) and TYA (Transport Y to A) instructions (I&#8217;ve already got these memorized c: ). I wrote this for the exercise:</p><pre><code>LDA #$fa  ; Load the hex value $c0 into the A register
TAX       ; Transfer the value in the A register to X
INX       ; Increment X register
TXA       ; Transfer X register to Accumulator
ADC #$01  ; Add with Carry the Accumulator
TAY       ; Transfer Accumulator to Y register
INY       ; Increment Y register
TYA       ; Transfer Y register to Accumulator
JMP $0602 ; Loop</code></pre><p>It was fun to watch the register values and flags jump around in the Debugger, as pointless as the program itself is. It shows you how the Carry flag is only triggered when overflow happens with the <code>ADC</code> instruction, not the increment instructions.</p><p>For some reason, doing any SBC (SuBtract with Carry) instruction triggers the Carry flag, and I do not understand why. I made a timer counting a register down to 0, where it then triggers the Zero flag. Next up is learning how to do something with that!</p><p>And that concludes this day. Thank you for being along for this journey with me. ^-^</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-2-getting-up-to-speed-by-learning?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption"><a href="https://cyanne.study/p/day-1-i-started-the-easy-6502-tutorial">&#171; Day 1</a> &#12539; Day 2 &#12539; <a href="https://cyanne.study/p/day-3-i-figure-out-branching-and">Day 3 &#187;</a></p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-2-getting-up-to-speed-by-learning?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://cyanne.study/p/day-2-getting-up-to-speed-by-learning?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div>]]></content:encoded></item><item><title><![CDATA[ASM day 1: I started the "Easy 6502" tutorial]]></title><description><![CDATA[Writing my very first assembly program]]></description><link>https://cyanne.study/p/day-1-i-started-the-easy-6502-tutorial</link><guid isPermaLink="false">https://cyanne.study/p/day-1-i-started-the-easy-6502-tutorial</guid><dc:creator><![CDATA[Cyanne]]></dc:creator><pubDate>Thu, 05 Jan 2023 01:34:25 GMT</pubDate><enclosure url="https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/8dbe354b-a830-413b-a811-ac467b7ec253_321x168.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Thank you for tuning in, my dear new reader. ^-^</p><p>Firstly as a short introduction, I am not a developer by trade. I appreciate the art of writing software a ton, but my only programming experience has been with the nice and easy to use <a href="https://en.wikipedia.org/wiki/GameMaker">GameMaker</a>. This time however, I&#8217;m curious about approaching it from the complete opposite end.</p><h4>I challenge myself to learn assembly programming</h4><p>Just for fun! I&#8217;ve always wondered about it! It&#8217;s like an intimidating puzzle that my brain may or may not be able to grasp. I&#8217;m curious if I can do it, and I&#8217;d like to take you along for the ride. Even if I don&#8217;t get anywhere, I hope my struggles may be interesting to you.</p><p>Being fond of the NES and SNES, and also being curious about the PC Engine, deciding on <strong>the 6502 family of processors</strong> seemed like a sensible enough choice to me.</p><p>After expressing my newfound wish, I was soon recommended the <a href="https://skilldrick.github.io/easy6502/">Easy 6502 tutorial</a>. It has a built-in miniature 6502 environment, and this is what I&#8217;ll be referring to in the next days of getting started. Its rules are described like this:</p><blockquote><p>Memory location <code>$fe</code> contains a new random byte on every instruction. Memory location <code>$ff</code> contains the ASCII code of the last key pressed.</p><p>Memory locations <code>$200</code> to <code>$5ff</code> map to the screen pixels. Different values (<code>$0-$f</code>) will draw different color pixels.</p></blockquote><h4>What I learned from the first tutorial section</h4><p>Going in, I know that computer processors know of <em>values</em>, and <em>registers</em> to put these values into. The way the values and registers are manipulated is through <em>instructions</em> written as short mnemonic names in assembly language. Hardware has registers that will act on whatever you put into them, which is super enticing to me when I think of games hardware.</p><p>One of the only things I know about the 6502 is that it has an &#8220;Accumulator&#8221;, which I understood as that feature calculators have where they keep track of the previous answer, which you are then able to use for your next calculation.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p><p>In the first section of the tutorial, &#8220;Our first program&#8221;, I can see that two instructions are used: <code>LDA</code> and <code>STA</code>. </p><pre><code>LDA #$01
STA $0200
LDA #$05
STA $0201
LDA #$08
STA $0202</code></pre><p>Apparently they stand for <strong>L</strong>oa<strong>D</strong> <strong>A</strong>ccumulator and <strong>ST</strong>ore <strong>A</strong>ccumulator respectively. Putting a value into a specific register seems to take these two instructions. LDA defines the value and stores it into register <code>A</code> (I suppose for Accumulator), and STA defines where it is stored. I feel like I remember seeing this done on a single line when looking at other assembly code, so I wonder about that.</p><p>I never knew that values (&#8220;literal number values&#8221;) were written as <code>#$xx</code>, while <code>$xxxx</code> portrays a register value.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Cyanne&#8217;s Debug Room! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h4>Playing with my first two instructions</h4><p>The example program draws three differently colored pixels.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!R2mO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!R2mO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png 424w, https://substackcdn.com/image/fetch/$s_!R2mO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png 848w, https://substackcdn.com/image/fetch/$s_!R2mO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png 1272w, https://substackcdn.com/image/fetch/$s_!R2mO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!R2mO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png" width="608" height="312" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:312,&quot;width&quot;:608,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8232,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!R2mO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png 424w, https://substackcdn.com/image/fetch/$s_!R2mO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png 848w, https://substackcdn.com/image/fetch/$s_!R2mO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png 1272w, https://substackcdn.com/image/fetch/$s_!R2mO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F0de4c937-d02d-4a1f-b480-e13b1e533337_608x312.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Once I started playing around with the values and got the hang of the screen position and color values, I couldn&#8217;t help try to draw something on the black screen. The end result is these blue beams shooting out of laser guns, I guess!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hVgf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hVgf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png 424w, https://substackcdn.com/image/fetch/$s_!hVgf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png 848w, https://substackcdn.com/image/fetch/$s_!hVgf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png 1272w, https://substackcdn.com/image/fetch/$s_!hVgf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hVgf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png" width="608" height="312" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/cf02a790-10d5-4351-b007-375dba698808_608x312.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:312,&quot;width&quot;:608,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15093,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hVgf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png 424w, https://substackcdn.com/image/fetch/$s_!hVgf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png 848w, https://substackcdn.com/image/fetch/$s_!hVgf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png 1272w, https://substackcdn.com/image/fetch/$s_!hVgf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf02a790-10d5-4351-b007-375dba698808_608x312.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><a href="https://gist.github.com/Cyanne/c421b83bc1abc96f9a423634170be862">My code can be found here.</a></p><p>Finally, I noticed this section includes challenges. </p><ul><li><p>Try changing the color of the three pixels.</p><ul><li><p>Done!</p></li></ul></li><li><p>Add more instructions to draw extra pixels.</p><ul><li><p>Done!</p></li></ul></li><li><p>Change one of the pixels to draw at the bottom-right corner (memory location <code>$05ff</code>).</p><ul><li><p>Oh, let me do that. </p></li></ul></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6jve!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6jve!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png 424w, https://substackcdn.com/image/fetch/$s_!6jve!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png 848w, https://substackcdn.com/image/fetch/$s_!6jve!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png 1272w, https://substackcdn.com/image/fetch/$s_!6jve!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6jve!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png" width="612" height="312" data-attrs="{&quot;src&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:312,&quot;width&quot;:612,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16075,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6jve!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png 424w, https://substackcdn.com/image/fetch/$s_!6jve!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png 848w, https://substackcdn.com/image/fetch/$s_!6jve!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png 1272w, https://substackcdn.com/image/fetch/$s_!6jve!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F7146c10f-3ff0-43ea-aec5-5a47965ebf24_612x312.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>There you go, that&#8217;s no trouble for us now! ^-^</p><p>And that is all for today. Thank you for reading!</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-1-i-started-the-easy-6502-tutorial?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Day 1 &#12539; <a href="https://cyanne.study/p/day-2-getting-up-to-speed-by-learning">Day 2 &#187;</a></p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/p/day-1-i-started-the-easy-6502-tutorial?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://cyanne.study/p/day-1-i-started-the-easy-6502-tutorial?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>If my understanding is wrong on this or anything else in my posts, then please do not hesitate to correct me by posting a comment.</p></div></div>]]></content:encoded></item><item><title><![CDATA[Introduction]]></title><description><![CDATA[I will use Substack to chronicle my journey of learning classic software development, so stay tuned.]]></description><link>https://cyanne.study/p/introduction</link><guid isPermaLink="false">https://cyanne.study/p/introduction</guid><dc:creator><![CDATA[Cyanne]]></dc:creator><pubDate>Mon, 02 Jan 2023 15:21:57 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!hBnJ!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3dac1417-9ee9-44df-97fc-82c4f273a6e1_534x534.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://cyanne.study/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Cyanne&#8217;s Debug Room! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>