<rss version="2.0">
  <channel>
    <title>Programming on Rene van Belzen</title>
    <link>https://renevanbelzen.micro.blog/categories/programming/</link>
    <description></description>
    
    <language>en</language>
    
    <lastBuildDate>Sat, 03 May 2025 08:21:52 +0100</lastBuildDate>
    
    <item>
      <title>Testing primality with Free Pascal</title>
      <link>https://renevanbelzen.micro.blog/2025/05/03/testing-primality-with-free-pascal.html</link>
      <pubDate>Sat, 03 May 2025 08:21:52 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2025/05/03/testing-primality-with-free-pascal.html</guid>
      <description>&lt;p&gt;I refined my Free Pascal program to accept 64-bit unsigned integers, which allows up to 19 decimal digits. However, testing with &lt;a href=&#34;https://bigprimes.org&#34;&gt;Big Primes&lt;/a&gt;, it is only usable up to 15 decimal digits on my Raspberry Pi 4. Any bigger primes take forever to test, in human perspective. The problem seems to be in how primes are generated in the primality test. The prime number generator uses a simple algorithm of odd numbers greater than one, and less than the square root of of the number of which its primality is tested. For small numbers it&amp;rsquo;s fine, but for larger numbers testing with odd numbers instead of actual prime numbers is a bit of waste of precious CPU time.&lt;/p&gt;
&lt;p&gt;Still, being able to test primality with a relatively simple algorithm is rather awesome as a first attempt.&lt;/p&gt;
&lt;p&gt;The slow-down in the algorithm is not caused by testing primality, but by the inefficiency of generating prime numbers. So I need a faster algorithm to do just that. I&amp;rsquo;ve looked around, but it requires me to learn new concepts in mathematics. I could do that, or, come back to it later when I&amp;rsquo;m more versed in writing in Pascal, or even stop here, since I don&amp;rsquo;t really have any incentives to create a full-blown efficient prime number generator, in other words, reinvent the wheel.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;program isPrime3;
uses crt;

const
  zero  : qword = 0;
  one   : qword = 1;
  two   : qword = 2;
  three : qword = 3;

var
  num   : qword;
  again : char;
  
function isprime(num : qword) : boolean;
var
  iscomposite : boolean;
  test        : qword;

begin
  if num = one then 
    isprime := false
  else 
    if (num = two) or (num = three) then
      isprime := true
    else
      if (num mod two) = zero then
        isprime := false
      else begin
        iscomposite := false;
        test     := three;
        while (test * test) &amp;lt;= num do begin
          if (num mod test) = zero then
            iscomposite := true;
          test := test + two;
        end;
        isprime := not iscomposite;
      end;
end;

begin
  again := &#39;Y&#39;;
  while (again =&#39;y&#39;) or (again = &#39;Y&#39;) or (again = chr(13)) do begin
    num := zero;
    while num &amp;lt; one do begin
      write(&#39;Give a whole positive number: &#39;);
      readln(num);
    end;
    if isprime(num) then
      writeln(num, &#39; is prime&#39;)
    else
      writeln(num, &#39; is not prime&#39;);
    write(&#39;again? [Y/n] &#39;);
    again := readkey;
    writeln(again);
  end;
end.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;P.S. I fixed a bug that caused a press on the Enter key to exit the program, instead of continuing it as I meant it to do. Checking additionally for the Enter key &lt;code&gt;chr(13)&lt;/code&gt; was easy enough. There are still bugs, though, but it&amp;rsquo;s usable enough for now, as throw-away code, not meant for application in a realworld app.&lt;/p&gt;
&lt;p&gt;P.P.S.S. You can test this code on TutorialsPoint, which has a &lt;a href=&#34;https://www.tutorialspoint.com/compilers/online-pascal-compiler.htm&#34;&gt;Pascal IDE&lt;/a&gt;, you could type the source code in, or copy and paste it from this article.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2025/05/01/i-refined-yesterdays-pascal-program.html</link>
      <pubDate>Thu, 01 May 2025 13:16:41 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2025/05/01/i-refined-yesterdays-pascal-program.html</guid>
      <description>&lt;p&gt;I refined yesterday&amp;rsquo;s Pascal program to have somewhat more functionality, and found a way to turn the contents of a terminal window into a PNG. It is a bit unwieldy, though. I&amp;rsquo;m curious how Timeline will possibly balk on this. I suppose &lt;a href=&#34;https://micro.blog/manton&#34;&gt;@manton&lt;/a&gt; will have to tweak things a bit.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2025/img-1974.png&#34; width=&#34;600&#34; height=&#34;700&#34; alt=&#34;The image shows a code editor containing a Pascal program that checks if a number is prime, with highlighted comments and test outputs.&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2025/04/30/more-pascal-programming-in-free.html</link>
      <pubDate>Wed, 30 Apr 2025 18:44:25 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2025/04/30/more-pascal-programming-in-free.html</guid>
      <description>&lt;p&gt;More Pascal programming in Free Pascal on Raspberry Pi OS. Apparently, the robot understands programming, since the alt description is spot on.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2025/2025-04-30-193849-1920x1080-scrot.png&#34; width=&#34;600&#34; height=&#34;781&#34; alt=&#34;A terminal window on a Raspberry Pi is displaying a program written in Pascal to test if numbers are prime, with examples of its execution for the numbers 3 and 1021.&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2025/04/29/remember-pascal-its-still-around.html</link>
      <pubDate>Tue, 29 Apr 2025 12:00:43 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2025/04/29/remember-pascal-its-still-around.html</guid>
      <description>&lt;p&gt;Remember Pascal? It&amp;rsquo;s still around. Here I&amp;rsquo;m running Free Pascal in a RaspberryPi OS terminal window.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2025/2025-04-29-125455-1920x1080-scrot.png&#34; width=&#34;600&#34; height=&#34;407&#34; alt=&#34;A terminal window displays a user compiling and running a Pascal program called hello.pas on a Raspberry Pi, resulting in the output Hello world!.&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/12/19/im-going-to.html</link>
      <pubDate>Thu, 19 Dec 2024 10:43:16 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/12/19/im-going-to.html</guid>
      <description>&lt;p&gt;I&amp;rsquo;m going to ignore Nvidea&amp;rsquo;s CEO charged statement people shouldn&amp;rsquo;t learn how to code anymore. I think &lt;a href=&#34;https://bbcbasic.co.uk&#34;&gt;BBC Basic&lt;/a&gt; is an excellent language for someone like myself, AI be damned!&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/2024-12-19-103736-1920x1080-scrot.png&#34; width=&#34;600&#34; height=&#34;337&#34; alt=&#34;A scenic mountain landscape serves as the desktop background for a computer screen, with several open folders and text editing programs displayed.&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/21/a-little-thing.html</link>
      <pubDate>Sun, 21 Jan 2024 11:24:44 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/21/a-little-thing.html</guid>
      <description>&lt;p&gt;A &amp;ldquo;little&amp;rdquo; thing as a broken iPad won&amp;rsquo;t stop me from making art. I made this when the iPad was almost gone.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7991.gif&#34; width=&#34;600&#34; height=&#34;600&#34; alt=&#34;simple animated GIF showing a cat and a pirate&#34;&gt;
&lt;p&gt;And the other piece I made with a &lt;a href=&#34;http://www.kameli.net/marq/?page_id=2717&#34;&gt;PETSCII editor&lt;/a&gt; on my RPi, based on a piece I did &lt;a href=&#34;https://renevanbelzen.micro.blog/2024/01/12/its-always-good.html&#34;&gt;earlier this month&lt;/a&gt;.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/petscii-boyswillbeboys-onc64-2024012101.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;PETSCII art of Boys Will Be Boys&#34;&gt;
&lt;p&gt;Not having a backup for my Raspberry Pi makes me a bit nervous, as it should&lt;br&gt;🎨🐱👨‍💻🕹️👾&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/18/this-was-taxing.html</link>
      <pubDate>Thu, 18 Jan 2024 16:58:34 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/18/this-was-taxing.html</guid>
      <description>&lt;p&gt;This was taxing my iPad. Youtube in Safari with adblocker as picture in picture on top of a drawing app. The strokes had to be placed tactically to allow for overall sluggishness. Also, very distractive drawing and watching a video.&lt;br&gt;🎨👨‍💻📺&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7979.jpeg&#34; width=&#34;600&#34; height=&#34;438&#34; alt=&#34;screenshot of drawing in ibisPaint X with a Youtube video floating above it&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/18/as-hannabarbera-cartoons.html</link>
      <pubDate>Thu, 18 Jan 2024 14:48:56 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/18/as-hannabarbera-cartoons.html</guid>
      <description>&lt;p&gt;As Hanna-Barbera cartoons of the eighties have taught us, cats can without most clothes, except the most essential, like a hat or a cane.&lt;br&gt;🎨🐱👨‍💻🕹️👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7978.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 multi-color bitmap painting of an antromorphized cat behind a pile of clothes&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/16/i-find-it.html</link>
      <pubDate>Tue, 16 Jan 2024 17:29:53 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/16/i-find-it.html</guid>
      <description>&lt;p&gt;I find it always such a surprise how a pixel art drawing I made subtly (or sometimes radically) changes to conform to the rigors of the C64 multicolor bitmap.&lt;/p&gt;
&lt;p&gt;Other than that, I used some of the edging techniques (sharp, lost and soft edges). So there&amp;rsquo;s that too. Happy 😊 camper here!&lt;br&gt;🎨👽👨‍💻🕹️👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/rick-deccard-onc64-2024011602.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 multipaint drawing of an anime version of Rick Deccard&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/16/searching-on-flickr.html</link>
      <pubDate>Tue, 16 Jan 2024 10:59:54 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/16/searching-on-flickr.html</guid>
      <description>&lt;p&gt;Searching on Flickr for Creative Commons photos of kittens I found &lt;a href=&#34;https://www.flickr.com/photos/allison_dc/1355648599/&#34;&gt;this cute black and white one&lt;/a&gt;. I used it as reference for my C64 hi-res bitmap pixel art drawing.&lt;/p&gt;
&lt;p&gt;Sometimes less color is better. Especially if the one depicted is staring into your soul.&lt;br&gt;🎨👨‍💻👾🕹️🐱😈&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7955.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 hi-res pixel art drawing of a black and white kitten&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/15/i-didnt-get.html</link>
      <pubDate>Mon, 15 Jan 2024 15:58:29 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/15/i-didnt-get.html</guid>
      <description>&lt;p&gt;I didn&amp;rsquo;t get to experiment with edges. Still, I drew something I love, so that&amp;rsquo;s good.&lt;/p&gt;
&lt;p&gt;Maybe advice from an oil painter doesn&amp;rsquo;t translate all that well to pixel art. Pixel art has more in common with decorative art (like embroidery) than with traditional art you can hang on a wall.&lt;br&gt;🎨🐱👨‍💻🕹️👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/kittensonc64-2024011501.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 multipaint illustration of two kittens, one sniffing a flower&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/14/public-domain-now.html</link>
      <pubDate>Sun, 14 Jan 2024 18:22:50 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/14/public-domain-now.html</guid>
      <description>&lt;p&gt;Public domain now?&lt;br&gt;🎨👨‍💻🕹️👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7940.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 multicolor illustration of a cartoon mouse holding a piece of cheese and a drink&#34;&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/imb-2jbffx.gif&#34; width=&#34;600&#34; height=&#34;374&#34; alt=&#34;animated GIF of drawing process&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/13/i-suppose-the.html</link>
      <pubDate>Sat, 13 Jan 2024 09:46:38 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/13/i-suppose-the.html</guid>
      <description>&lt;p&gt;I suppose the lesson to be learned here is:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Don&amp;rsquo;t look into the spiral, or you&amp;rsquo;ll go cuckoo, bananas, Dada&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A quick peek is no problem, though.&lt;br&gt;
🎨👨‍💻🕹️👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/spiral-2024011301.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 hires bitmap image showing a spiral and a confused artist&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/12/another-day-another.html</link>
      <pubDate>Fri, 12 Jan 2024 16:02:30 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/12/another-day-another.html</guid>
      <description>&lt;p&gt;Another day, another cat drawing. This time our more blocky version of a feline fellow creature. Sketch in ibisPaint X and final drawing in Commodore 64 multicolor bitmap (160 x 200 resolution, 16 colors). If I could, I&amp;rsquo;d knit him a cozy sweater.&lt;br&gt;
🐱🎨👨‍💻🕹️👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7908.png&#34; width=&#34;600&#34; height=&#34;375&#34; alt=&#34;illustration of a stylized cat with chunk in blocked letters written underneath&#34;&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/cat-2024011201.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 multicolor bitmap image of a chunky cat illustration&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/11/i-think-im.html</link>
      <pubDate>Thu, 11 Jan 2024 15:15:25 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/11/i-think-im.html</guid>
      <description>&lt;p&gt;I think I&amp;rsquo;m starting to grasp how to draw in C64 multicolor. You get three colors that can be used anywhere, and per 8 by 8 pixels block you get to pick another color out of 16 possible colors. Careful placement of the pixels is key. If you do it right, you can have a very colorful image&lt;br&gt;🎨👨‍💻🕹️👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/boyswillbeboys-2024011103.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;cheeky multicolor illustration on the Commodore 64, stating that boys will be boys&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/10/another-day-another.html</link>
      <pubDate>Wed, 10 Jan 2024 13:55:31 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/10/another-day-another.html</guid>
      <description>&lt;p&gt;Another day, another cat drawing for the old Commodore 64&lt;br&gt;😻 🎨 👨‍💻 🕹️ 👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/catonc64-2024011001.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 multicolor drawing of a blue cat on a red background&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/10/i-reworked-an.html</link>
      <pubDate>Wed, 10 Jan 2024 00:23:47 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/10/i-reworked-an.html</guid>
      <description>&lt;p&gt;I reworked an older self-portrait that I made last year as a pixel art drawing, and turned it into an image on the Commodore 64. I like that the limited color palette doesn&amp;rsquo;t seem to limit me as much as it used to. It takes some effort (well, a lot of effort), but I think it was worth the time.&lt;br&gt;🎨 👨‍💻 🕹️ 👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/selfiec64-2024010903.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Commodore 64 multicolor selfie&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/09/here-are-some.html</link>
      <pubDate>Tue, 09 Jan 2024 11:32:11 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/09/here-are-some.html</guid>
      <description>&lt;p&gt;Here are some of the steps I took to create a multicolor pixel art drawing of a cat.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7885.png&#34; width=&#34;600&#34; height=&#34;375&#34; alt=&#34;grayscale image of a cat drawn in ibisPaint X&#34;&gt;
&lt;p&gt;&lt;em&gt;drawn in ibisPaint X in 4 colors&lt;/em&gt;&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7886.png&#34; width=&#34;600&#34; height=&#34;375&#34; alt=&#34;colored pixel art of the same cat in Pixaki&#34;&gt;
&lt;p&gt;&lt;em&gt;traced and redrawn in Pixaki&lt;/em&gt;&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7887.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;colored pixel art of the cat display in VICE C64&#34;&gt;
&lt;p&gt;&lt;em&gt;made into C64 runnable multicolor art with MultiPaint, loaded into VICE C64&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a process, taking many hours to complete. I think I&amp;rsquo;m improving.&lt;/p&gt;
&lt;p&gt;👨‍💻🎨&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/08/making-room-for.html</link>
      <pubDate>Mon, 08 Jan 2024 20:49:31 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/08/making-room-for.html</guid>
      <description>&lt;p&gt;Making room for two text screens, so I can use them for buffering is great, but running it from C64 Basic is one ugly hack, and slow too. But I&amp;rsquo;ve done it, which is great, since I learned a lot from it, and that was the whole point here. The code I keep, in case I need (some of) it 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/screenshot-2024010801.png&#34; width=&#34;600&#34; height=&#34;463&#34; alt=&#34;screenshot of Commodore 64 Basic code in VS Code&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/08/i-fired-up.html</link>
      <pubDate>Mon, 08 Jan 2024 08:28:00 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/08/i-fired-up.html</guid>
      <description>&lt;p&gt;I fired up my art app and sculpted on a canvas the size of a retro-computer&amp;rsquo;s text character (8 pixel wide and 8 pixels high). I had to struggle, because the app wanted it to look nicer than it really was.&lt;/p&gt;
&lt;p&gt;I suppose you can already guess what it represents. You can do a lot in 64 bits of data 👨‍💻🎨&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7882.png&#34; width=&#34;600&#34; height=&#34;600&#34; alt=&#34;8 by 8 sprite of a black cat&#34;&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/imb-r4jkne.gif&#34; width=&#34;320&#34; height=&#34;320&#34; alt=&#34;animated GIF of drawing process of an 8 by 8 sprite of a black cat&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/07/okay-i-have.html</link>
      <pubDate>Sun, 07 Jan 2024 20:34:13 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/07/okay-i-have.html</guid>
      <description>&lt;p&gt;Okay, I have a Basic loader with M/L code that enables a screen buffer and has a handy relocatable M/L routine at &lt;code&gt;$C000&lt;/code&gt; that copies 1024 bytes. Bits 4 - 7 of &lt;code&gt;$D018&lt;/code&gt; control which part of memory is used to display the screen. Now I have all I need for moving a block of characters in C64 Basic, right? 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Make room for a screen buffer in C64 Basic</title>
      <link>https://renevanbelzen.micro.blog/2024/01/07/make-room-for.html</link>
      <pubDate>Sun, 07 Jan 2024 13:51:48 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/07/make-room-for.html</guid>
      <description>&lt;p&gt;In my &lt;a href=&#34;https://renevanbelzen.micro.blog/2024/01/06/moving-a-box.html&#34;&gt;previous post&lt;/a&gt; in which I moved a box across the screen with a Basic program, I wanted to use a screen buffer. The default screen location starts in memory at &lt;code&gt;$0400&lt;/code&gt; (1024 decimal), and we can move the screen in units of 1024 bytes. The next location would be &lt;code&gt;$0800&lt;/code&gt; (2048 decimal), which is where Basic text lives. Luckily we can move the start of Basic up with a &lt;code&gt;poke&lt;/code&gt; at location 44, but we also have to move the bytes of the Basic text to the new location, or you&amp;rsquo;d get a jibberish Basic text. The most obvious location is &lt;code&gt;$0c01&lt;/code&gt; (3097 decimal), and it makes sense to do this outside of Basic, with the raw power of the 6510 CPU.&lt;/p&gt;
&lt;p&gt;The machine language (M/L) program &lt;code&gt;enablebuffer&lt;/code&gt; does just that. Here&amp;rsquo;s the source code listing. It has some Basic code to run the M/L code and relocate the start of Basic text. The M/L code is a bit more complicated than it needed to be, but I like some headroom in case I want to include more Basic text in front of the M/L code or put some M/L code in a convenient location, so we can &lt;code&gt;sys&lt;/code&gt; or &lt;code&gt;usr()&lt;/code&gt; to it. The code should be able to copy Basic text in front of the M/L code, no matter how big it would grow.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
; enablebuffer.asm
;
; Move the start of basic from $0801 to $0c01
;
; Now both 1024 - 2023 and 2048 - 3047
;      can be used as screen memory.
; This makes it possible to use a screen buffer
;      in Basic.
 
                PROCESSOR 6502

                ORG $0801
            
; Basic text in front of ML code
; 10 SYSXXXX:POKE44,12:CLR

BASIC1:
    HEX 14 08 0a 00 9e 

    .dc sys_address             ; replaces the &#34;XXXX&#34;

BASIC2:
    HEX 3a 97 34 34 2c 31 32 3a 9c 00 00 00

sys_address:    eqm (start_ML)d

; start of ML code

start_ML:

vect1:          eqm $02
vect2:          eqm $04
BASstart:       eqm $2B

                LDA BASstart+1
                CMP #$08        ; is start of basic at $0801 ?
                BNE exit        ; no, then exit

; set up copy process
; copy $0801 to $0C01 until the end of file
; copy start at the end towards the beginning


                CLC
                LDA #&lt;exit
                STA vect1
                STA vect2
                LDA #&gt;exit
                STA vect1+1
                ADC #$04        ; move 1024 positions higher in memory
                STA vect2+1
                LDY #$00

loop1:          LDA vect1+1     ; copy in blocks of 256 bytes
                CMP #$08        ; less than 256 bytes to copy?
                BEQ loop2       ; yes, then loop2 instead
loop1a:         LDA (vect1),Y   ; fast copy 256 bytes
                STA (vect2),Y
                DEY
                BNE loop1a
                DEC vect1       ; next 256 byte
                DEC vect2
                BNE loop1
                DEC vect1+1
                DEC vect2+1
                BNE loop1

loop2:          LDA (vect1),Y   ; copy remainder of bytes
                STA (vect2),Y   ; between 1 and 255
                DEC vect1
                DEC vect2
                BNE loop2b
                DEC vect1+1
                DEC vect2+1
loop2b:         LDA vect1+1
                CMP #$07
                BNE loop2

exit:           RTS
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can load the program as an ordinary Basic program and then run it.&lt;/p&gt;
&lt;p&gt;After that we can &lt;code&gt;new&lt;/code&gt; the Basic program and start writing a new Basic program, at location &lt;code&gt;$0C01&lt;/code&gt; instead of the default &lt;code&gt;$0801&lt;/code&gt;! Of course, the M/L code will be overwritten by that new Basic program, but that&amp;rsquo;s okay, since we no longer need it at that point.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/06/with-all-the.html</link>
      <pubDate>Sat, 06 Jan 2024 23:21:04 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/06/with-all-the.html</guid>
      <description>&lt;p&gt;With all the blogging I do daily, I wanted to automate correct capitalization. I reworked an shortcut that no longer worked to a &lt;a href=&#34;https://www.icloud.com/shortcuts/cb86a137f93a4790a3ee0d2d99f12eef&#34;&gt;working state&lt;/a&gt;. Select text, share, pick one, paste.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;all lower case&lt;/li&gt;
&lt;li&gt;UPPER CASE&lt;/li&gt;
&lt;li&gt;Title Case in Case You Want It&lt;/li&gt;
&lt;li&gt;Capitalize A Okay&lt;/li&gt;
&lt;li&gt;Sentence. After each. Sentence.&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Moving a box across the text screen in C64 Basic</title>
      <link>https://renevanbelzen.micro.blog/2024/01/06/moving-a-box.html</link>
      <pubDate>Sat, 06 Jan 2024 17:09:04 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/06/moving-a-box.html</guid>
      <description>&lt;p&gt;I was wondering how to move a collection of characters (e.g. a box) across a Commodore 64 text screen. It&amp;rsquo;s rather easy to do this destructively. In Basic, I wrote something that horizontally moves a 3-by-3 character rectangle constructed out of PETSCII characters.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
10 rem ***
11 rem *** setup
12 rem ***
20 restore:read w,h:for i=0 to w*h-1
30 read a(i):next i
40 data 3,3
50 data 112,64,110,93,32,93,109,64,125
60 te=200
100 rem ***
101 rem *** main loop
102 rem ***
110 os=0
120 for p=1024+12*40top+40-w
130 gosub 200:gosub 300:next p
140 os=w-1
150 for p=1024+13*40-w to p-39+w step-1
160 gosub 200:gosub 300:next p
170 goto 100
199 end
200 rem ***
201 rem *** draw a box
202 rem ***
210 for x=0 to w-1:for y=0 to h-1
220 poke p+y*40+x,a(y*w+x)
230 nexty:nextx:fort=0tote:nextt:return
300 rem ***
301 rem *** clear column
302 rem ***
310 for y=0toh-1:poke p+y*40+os,32:next
320 return
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The program has to do some clean-up after it has drawn a box with the subroutine &lt;code&gt;draw a box&lt;/code&gt;. It fills the box&amp;rsquo;s trailing text column with space characters (screen code 32). For instance, if the box moves to the right and the box has been drawn in its current position, the left-most text column of that box has to be &amp;ldquo;cleared&amp;rdquo; (filled with spaces). Otherwise it will leave behind box characters when the next position of the box is drawn—one position to the right. The &lt;code&gt;main loop&lt;/code&gt; uses the variable &lt;code&gt;os&lt;/code&gt; (offset) to determine which text column should be filled with spaces, using the same subroutine &lt;code&gt;clear column&lt;/code&gt; when moving the text box to the left or to the right.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s all very limited in what this program can do. It can move the box either one character position to the right or the same to the left, nothing more.&lt;/p&gt;
&lt;p&gt;For a more sophisticated &lt;code&gt;draw a box&lt;/code&gt; subroutine, it has to know where it was before:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;restore the original content of the previous position (if any)&lt;/li&gt;
&lt;li&gt;read the current content where the box will appear and store it for later&lt;/li&gt;
&lt;li&gt;draw the box onto its position on the text screen&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We can do this in Basic as well, even though it&amp;rsquo;s rather slow and has clear visual artifacts. Here&amp;rsquo;s the code for the same 3 by 3 text box, now jumping to arbitrary positions on the screen, while keeping the screen intact.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
10 rem ***
11 rem *** setup
12 rem ***
20 restore:read w,h:for i=0 to w*h-1
30 read a(i):next i
40 data 3,3
50 data 112,64,110,93,32,93,109,64,125
60 te=200
70 first = (1 = 1)
100 rem ***
101 rem *** main loop
102 rem ***
110 x=int(rnd(ti)*(40-w))
120 y=int(rnd(ti)*(25-h))
130 gosub 200
140 goto 100
199 end
200 rem ***
201 rem *** draw a box
202 rem ***
210 rem *** restore any orig&#39;l content
211 rem ***
220 if first then first=(1=0):goto 300
230 for xx =0 to w-1:for yy=0 to h-1
240 poke p+yy*40+xx,a1(yy*w+xx)
250 nextyy:nextxx
300 rem ***
301 rem *** read current text content
302 rem ***
310 p=1024+40*y+x
320 for xx=0 to w-1:for yy=0 to h-1
330 a1(xx+yy*w)=peek(p+xx+yy*40):
340 nextyy:nextxx
400 rem ***
401 rem *** put box on screen
402 rem ***
410 for xx=0 to w-1:for yy=0 to h-1
420 poke p+yy*40+xx,a(yy*w+xx)
440 nextyy:nextxx
450 for t=0 to te:next
460 return
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The long wait loop (which makes the program perform so slow) is so that you can spot the random 3-by-3 box, while also making the artifacts less noticeable. You can see the box long enough, so it disappearing from screen will feel less jarring. A better solution than waiting a while would be to use a screen buffer to do the drawing and switch screen buffers when all the drawing is done for the new position of the box.&lt;/p&gt;
&lt;p&gt;I guess that would require some machine language I have yet to write.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/06/i-wondered-if.html</link>
      <pubDate>Sat, 06 Jan 2024 11:42:25 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/06/i-wondered-if.html</guid>
      <description>&lt;p&gt;I wondered if a sprite rendered as a text character would make sense. It would have to move to one of the 1000 positions on a text screen of 25 lines and 40 columns in a C64. The character is 2 by 2 text characters, has 3 walking poses, and two extra text characters for the SFX. It could work 👨‍💻&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7878.gif&#34; alt=&#34;animated GIF of little sprite walking down a C64 screen moving as a text character&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/05/i-would-prefer.html</link>
      <pubDate>Fri, 05 Jan 2024 15:35:55 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/05/i-would-prefer.html</guid>
      <description>&lt;p&gt;I would prefer owning a Mac, but I simply can’t rationalize the &amp;ldquo;Apple tax.&amp;rdquo; I used to be Mac or Die. A computer is more like a way to access the Internet nowadays, anyway 👨‍💻👾&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/3517a82512.png&#34; width=&#34;600&#34; height=&#34;375&#34; alt=&#34;Cartoon drawing in C64 multicolor format. &#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/05/its-all-very.html</link>
      <pubDate>Fri, 05 Jan 2024 10:20:12 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/05/its-all-very.html</guid>
      <description>&lt;p&gt;It&amp;rsquo;s all very technical, this Commodore 64 multicolor mode. I made a special 2x1 grid in my iPad pixel editor to help me, but still I need to check in an actual multicolor editor if I made a mistake. Anyway, I&amp;rsquo;m improving as a C64 pixel artist, and that&amp;rsquo;s very cool 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7865.png&#34; width=&#34;600&#34; height=&#34;750&#34; alt=&#34;concept and C64 multicolor drawings of a sunny day in nature&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/04/creating-something-colorful.html</link>
      <pubDate>Thu, 04 Jan 2024 12:11:52 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/04/creating-something-colorful.html</guid>
      <description>&lt;p&gt;Creating something colorful that can be displayed on a Commodore 64 by loading and running a file involved a lot of (impossible to automate) creative steps. It took me around 4 hours for this simple drawing of my cat Aziz. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7847.png&#34; width=&#34;600&#34; height=&#34;375&#34; alt=&#34;original drawing in ibisPaint X at 320 by 200 pixels&#34;&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7846.png&#34; width=&#34;600&#34; height=&#34;375&#34; alt=&#34;multicolor version with the Multipaint application&#34;&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7844.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;loading screen in VICE C64 of the binary file containing the multicolor image&#34;&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7845.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;multicolor image being displayed in VICE C64&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/03/i-found-an.html</link>
      <pubDate>Wed, 03 Jan 2024 17:46:18 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/03/i-found-an.html</guid>
      <description>&lt;p&gt;I found an image editor that is able to draw Commodore 64 multicolor images. It can load PNG images, so I could draw on my iPad and color in this Java app on my Raspberry Pi-400. Yay!&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m still learning, though. Also found a SID tracker to compose music on the C64, and my musical knowledge is meh.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7835.png&#34; width=&#34;600&#34; height=&#34;375&#34; alt=&#34;pixel art of a cat head in C64 multicolor&#34;&gt;
</description>
    </item>
    
    <item>
      <title>Basic music theory—the musical interval</title>
      <link>https://renevanbelzen.micro.blog/2024/01/02/basic-music-theorythe.html</link>
      <pubDate>Tue, 02 Jan 2024 15:19:41 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/02/basic-music-theorythe.html</guid>
      <description>&lt;p&gt;Realizing how little to nothing I know about music theory, I started watching videos on the subject recommended to me by YouTube. Apart from that those videos aren&amp;rsquo;t really vetted, I don&amp;rsquo;t know how useful those are, even if they&amp;rsquo;re accurate. So there&amp;rsquo;s my caveat to you, the reader.&lt;/p&gt;
&lt;p&gt;Today I researched the &lt;em&gt;musical interval,&lt;/em&gt; i.e. the ratio in frequency value between musical notes.&lt;/p&gt;
&lt;p&gt;In &lt;a href=&#34;https://www.youtube.com/watch?v=lvmzgVtZtUQ&#34;&gt;Why Does Music Only Use 12 Different Notes?&lt;/a&gt; presenter David Bennett explains how musical notes work in popular and classical music, which most of us listen to on a daily basis.&lt;/p&gt;
&lt;p&gt;There are the following 12 notes (semitones) in an octave (using letters, while in some countries other notations are used, like do-re-mi):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;C&lt;/li&gt;
&lt;li&gt;C#&lt;/li&gt;
&lt;li&gt;D&lt;/li&gt;
&lt;li&gt;D#&lt;/li&gt;
&lt;li&gt;E&lt;/li&gt;
&lt;li&gt;F&lt;/li&gt;
&lt;li&gt;F#&lt;/li&gt;
&lt;li&gt;G&lt;/li&gt;
&lt;li&gt;G#&lt;/li&gt;
&lt;li&gt;A&lt;/li&gt;
&lt;li&gt;A#&lt;/li&gt;
&lt;li&gt;B&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When a note has a frequency twice as high as another note, the distance (interval) between them is called an octave. Playing two notes an octave apart sounds pleasing (consonant) to our human ears.&lt;/p&gt;
&lt;p&gt;Inside an octave there are 12 notes. Playing two of those notes together gives a certain mood (how humans perceive the combination of notes, pleasing or less pleasing). The first of those 12 notes is called the root. Playing the root and the same note an octave higher gives us the most consonant combination of notes.&lt;/p&gt;
&lt;p&gt;On a scale from most consonant to most dissonant, there are twelve musical intervals (between brackets is the frequency ratio between both notes in the interval). The intervals numbered 1 - 7 in this list are considered consonant in Western music, 8 and higher dissonant.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Octave, aka 8ve, (2:1)&lt;/li&gt;
&lt;li&gt;Perfect 5th, aka P5 (3:2)&lt;/li&gt;
&lt;li&gt;Perfect 4th, aka P4 (4:3)&lt;/li&gt;
&lt;li&gt;Major 3rd, aka M3 (5:4)&lt;/li&gt;
&lt;li&gt;minor 6th, aka m6 (8:5)&lt;/li&gt;
&lt;li&gt;minor 3rd, aka m3 (6:5)&lt;/li&gt;
&lt;li&gt;Major 6th, aka M6 (5:3)&lt;/li&gt;
&lt;li&gt;Major 2nd, aka M2 (9:8)&lt;/li&gt;
&lt;li&gt;minor 7th, aka m7 (9:5)&lt;/li&gt;
&lt;li&gt;minor 2nd, aka m2 (16:15)&lt;/li&gt;
&lt;li&gt;Major 7th, aka M7 (15:8)&lt;/li&gt;
&lt;li&gt;Tritone (7:5)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Below that, sounding even less pleasant, there are quarter-tones, and even further divided intervals, that sound even more unpleasant.&lt;/p&gt;
&lt;p&gt;Ordered on frequency (how they appear on a piano keyboard, using both  white and black keys):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
[root] [m2] [M2] [m3] [M3] [P4] [Tritone] [P5] [m6] [M6] [m7] [M7] [8ve]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With 12 notes in an octave we have a limited set of frequencies. It is a practical compromise, really, limited to only the most useful musical intervals, excluding others. However, this compromise is still not enough. With the ratios mentioned above, we can only play in a fixed key (root note). If we want to transpose a piece of music to a different key with the ratios kept intact, the musical intervals sound all weird. This is because this theoretical &lt;em&gt;just intonation&lt;/em&gt; doesn&amp;rsquo;t allow for transposition. To fix it, so we can play in any key we want, the intervals must be changed. This slight alterations in musical intervals is called temperament (tempering the intervals so music can be played in arbitrary keys, not just one single key).&lt;/p&gt;
&lt;p&gt;There have been several temperaments over the millenia and ages. The system we use today is called &lt;a href=&#34;https://en.wikipedia.org/wiki/12_equal_temperament&#34;&gt;12 Tone Equal Temperament&lt;/a&gt;. Each semitone is a factor of the 12th root of two higher than the previous semitone.&lt;/p&gt;
&lt;p&gt;Here are the tempered values of the intervals. They are very close to their just intonation, between brackets:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;m2 1.0595 (1.0667)&lt;/li&gt;
&lt;li&gt;M2 1.1225 (1.1250)&lt;/li&gt;
&lt;li&gt;m3 1.2892 (1.2000)&lt;/li&gt;
&lt;li&gt;M3 1.2599 (1.2500)&lt;/li&gt;
&lt;li&gt;P4 1.3348 (1.3333)&lt;/li&gt;
&lt;li&gt;Tritone 1.4142 (1.4000)&lt;/li&gt;
&lt;li&gt;P5 1.4983 (1.5000)&lt;/li&gt;
&lt;li&gt;m6 1.5874 (1.6000)&lt;/li&gt;
&lt;li&gt;M6 1.6818 (1.6667)&lt;/li&gt;
&lt;li&gt;m7 1.7818 (1,8000)&lt;/li&gt;
&lt;li&gt;M7 1.8877 (1.8750)&lt;/li&gt;
&lt;li&gt;8ve 2.0000 (2.0000)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Except for the octave, these intervals are slightly out of tune compared to the ideal, but not enough to be noticeable, especially the perfect 4th and 5th are extremely close in value to a just intonation. Using this temperament musicians can play in any key without the music sounding strange. Anyway, the music most of us listen to (Western music) has been already in 12 tone equal temperament for hundreds of years. Most of us (including myself) probably don&amp;rsquo;t know any better.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a small, yet important part of music theory.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/02/i-realized-i.html</link>
      <pubDate>Tue, 02 Jan 2024 08:48:53 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/02/i-realized-i.html</guid>
      <description>&lt;p&gt;I realized I needed four extra characters to be able to create lines that are 4 pixels wide. In the 6-pixel wide versions I already had them ($59 - $5B), rounding corners. So I added them to my existing modified character set, at $75 - $78.&lt;/p&gt;
&lt;p&gt;Tools: &lt;a href=&#34;http://petscii.krissz.hu&#34;&gt;PETSCII editor&lt;/a&gt;, &lt;a href=&#34;https://vice-emu.sourceforge.io&#34;&gt;VICE&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;👨‍💻 &lt;em&gt;day 2/366 days of coding&lt;/em&gt;&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7820.png&#34; width=&#34;600&#34; height=&#34;425&#34; alt=&#34;Fake C64 screen with hexadecimal screen codes and their changed graphical representation&#34;&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7822.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Screenshot of VICE C64 showing a Basic instruction using POKE commands to display the modified screen codes&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2024/01/01/its-day-one.html</link>
      <pubDate>Mon, 01 Jan 2024 11:53:10 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2024/01/01/its-day-one.html</guid>
      <description>&lt;p&gt;It&amp;rsquo;s day one of a year long self-challenge to code a video game for the Commodore 64. It won&amp;rsquo;t be all spent behind a keyboard and monitor. There&amp;rsquo;s a lot of study ahead, reading books and articles, playing retro-games, etc. Also making pixel art and chiptunes. It&amp;rsquo;ll be a blast 🥳 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2024/img-7816.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Fake Commodore 64 screen with the text 366 Days of Coding&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/31/my-retrocomputer-powered.html</link>
      <pubDate>Sun, 31 Dec 2023 23:59:00 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/31/my-retrocomputer-powered.html</guid>
      <description>&lt;p&gt;My retro-computer∗ powered best wishes from the Netherlands!&lt;/p&gt;
&lt;p&gt;May all your best wishes for &lt;em&gt;&lt;strong&gt;2024&lt;/strong&gt;&lt;/em&gt; come true.&lt;/p&gt;
&lt;p&gt;👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7812.gif&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Screenshot of a Commodore 64 screen wishing us a happy New Year&#34;&gt;
&lt;p&gt;∗ (V.I.C.E. actually, and a little after effect with my iPad)&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/31/took-some-effort.html</link>
      <pubDate>Sun, 31 Dec 2023 12:44:26 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/31/took-some-effort.html</guid>
      <description>&lt;p&gt;Took some effort, yet I have my character set of programmable characters to draw a design I&amp;rsquo;ve been working on lately. I wrote a Basic loader, which when run puts the character set in memory, so I can be used. Still lots to do, though. I&amp;rsquo;ll write a longer piece about it  in the New Year. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7809.jpeg&#34; width=&#34;600&#34; height=&#34;454&#34; alt=&#34;Screenshot of a Commodore 64 screen in VICE, showing new characters, a Basic listing, and a Basic instruction POKEing screen codes into screen memory&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/30/second-partial-attempt.html</link>
      <pubDate>Sat, 30 Dec 2023 10:21:14 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/30/second-partial-attempt.html</guid>
      <description>&lt;p&gt;Second (partial) attempt at a a 2-color bitmap image on a C64 as a collection of  characters (8-by-8 pixels tiles, still only 39). This is very laborious—if done by hand. I had to change the original rather drastically, and reuse tiles with care. There&amp;rsquo;s still a good resemblance, of course. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7805.png&#34; width=&#34;600&#34; height=&#34;409&#34; alt=&#34;design of Commodore screen image with the 39 tiles that are already used on the side&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/29/i-wonder-if.html</link>
      <pubDate>Fri, 29 Dec 2023 16:23:48 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/29/i-wonder-if.html</guid>
      <description>&lt;p&gt;I wonder if it&amp;rsquo;s possible to render this as 8 by 8 tiles, and if so, how to do it. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/4d3c9aa267.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;Design for a Commodore 64 background image&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/28/i-made-start.html</link>
      <pubDate>Thu, 28 Dec 2023 18:13:24 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/28/i-made-start.html</guid>
      <description>&lt;p&gt;I made start with software sprites using programmable characters on a Commodore 64. For now, there are just programmable characters; there&amp;rsquo;s no background, nor a software sprite that should move over the background in one of the 1000 possible positions on a 25 rows by 40 columns text screen.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/screenshot-blackonwhitetext.png&#34; width=&#34;370&#34; height=&#34;280&#34; alt=&#34;screenshot of VICE C64 screen showing a listing of a Basic program in black text on an all white background&#34;&gt;
</description>
    </item>
    
    <item>
      <title>How to draw software sprites</title>
      <link>https://renevanbelzen.micro.blog/2023/12/27/how-to-draw.html</link>
      <pubDate>Wed, 27 Dec 2023 09:28:04 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/27/how-to-draw.html</guid>
      <description>&lt;p&gt;While in the &lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/24/philosophizing-about-software.html&#34;&gt;previous article&lt;/a&gt; I was only philosophizing, in this one, I&amp;rsquo;m getting somewhat less theoretical. It&amp;rsquo;s still a ways away from having working code, though.&lt;/p&gt;
&lt;p&gt;I found an &lt;a href=&#34;https://retrocomputing.stackexchange.com/questions/24133/how-were-sprites-in-dos-games-programmed&#34;&gt;answer&lt;/a&gt; on the Retrocomputing Stackexchange site, explaining how software sprites &amp;ldquo;work&amp;rdquo;. In my own words:&lt;/p&gt;
&lt;p&gt;Sprites are rectangles of image data that are put in video memory, so the video processor can display them on a video screen. Sprites always need one of the colors to be transparent (invisible). In a two-color display that usually is black (0), while the visible color is non-black (1). The invisible color could be considered the background color, the visible color the foreground color. However, with a background drawn on screen, things can get confusing.&lt;/p&gt;
&lt;p&gt;To enable mixing of sprite images with the background image, for every sprite image there should be a mask to punch a whole into the background. The mask contains 0s where the sprite image is visible; 1s where the sprite image is transparent. It makes sense to precompute mask data for efficiency.&lt;/p&gt;
&lt;p&gt;Sprite data is drawn on top of image data. First, the background is masked out where the sprite will appear, resulting in a &amp;ldquo;hole&amp;rdquo; in the background. Second, this hole is filled with sprite data. Of course, if the sprite was moved, the original background image of that previous location should be restored too.&lt;/p&gt;
&lt;p&gt;On older PCs (read: in certain display modes) colors are planar, which means that each color is stored in its own block of memory, instead of combined into a single memory block (one or more bytes of color information per pixel). Each color plane has to be processed first by punching a hole with the same mask and then filling the hole with sprite image data, specific for that color.&lt;/p&gt;
&lt;p&gt;The (generic) algorithm for drawing sprites is as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;erase the previous position, if any, by copying the original background at the previous location&lt;/li&gt;
&lt;li&gt;establish the address of the rectangle in video memory where the sprite should appear&lt;/li&gt;
&lt;li&gt;apply AND with the mask on this rectangle to &amp;ldquo;cut&amp;rdquo; data behind the mask; now there is a hole in the background where the mask is&lt;/li&gt;
&lt;li&gt;apply OR with the sprite image data to insert it into the background image; OR will only draw inside the cut mask&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;On the C64, things are quite different if bitmap graphics is to be ignored (too slow in most cases). In two-color (monochrome) character display, there are 1000 character positions (25 lines of 40 characters). The characters can be programmed by changing their image data (8 rows of 8 columns of pixels). In character generator memory, blocks of 8 bytes (8 by 8 pixels) are stored for each of the 256 characters that are in a character set. To display a character, its code is stored in screen memory, depending on the character&amp;rsquo;s location (column and row) on the video screen.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s imagine a single 8 by 8 character (organized as 8 rows of 8 bits, 64 bits in total). Since the characters don&amp;rsquo;t represent text, but rather images, it&amp;rsquo;s probably better to  refer to them with the more generic term &amp;ldquo;glyph&amp;rdquo;. A glyph can be a character, but also an image, e.g. a sprite.&lt;/p&gt;
&lt;p&gt;To remove a sprite from the previous position, the previous glyph code that represented the background in that position is put back in screen memory. The background glyph code should be stored somewhere separately if it isn&amp;rsquo;t possible to determine that code from its position alone.&lt;/p&gt;
&lt;p&gt;To put a sprite in its new position, some bit manipulation has to be done, combining the original image data of the background glyph with that of the sprite and store the result into image data for the glyph that displays a sprite-on-background.&lt;/p&gt;
&lt;p&gt;The data structure that contains a sprite could look something like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;memory address in screen memory (2 bytes)&lt;/li&gt;
&lt;li&gt;background glyph code (1 byte)&lt;/li&gt;
&lt;li&gt;sprite-on-background glyph code (1 byte)&lt;/li&gt;
&lt;li&gt;sprite image data (8 bytes)&lt;/li&gt;
&lt;li&gt;sprite mask image data (8 bytes)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That is 20 bytes in total for displaying a single 8 by 8 square of pixels. That could be 8 bytes less if the sprite mask image data is computed on the fly.&lt;/p&gt;
&lt;p&gt;From the steps above in the general case, the C64-specific steps would look like as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;if the sprite was already being displayed, write the background glyph code into the memory address in screen memory&lt;/li&gt;
&lt;li&gt;calculate the current memory address in screen memory, based on the given sprite location&lt;/li&gt;
&lt;li&gt;store the glyph code in the memory address in screen memory in the background glyph code&lt;/li&gt;
&lt;li&gt;AND every of the 8 bytes of mask data with the corresponding bytes of background image data, as determined by the background glyph code and store the result in the 8 bytes of image data for the glyph that displays sprite-on-background&lt;/li&gt;
&lt;li&gt;OR every of the 8 bytes of sprite image data with the corresponding 8 bytes of the sprite-on-background image; store the result back into the sprite-on-background image&lt;/li&gt;
&lt;li&gt;write the sprite-on-background glyph into the current memory address in screen memory&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That is a lot of overhead and storage space for sprite the size of a single character of text. If the sprite needs to be able to be moved left and right, up and down, with the resolution of a single pixel, things can get even more complicated and require even more resources (instruction cycles and storage space). It&amp;rsquo;s doubtful if this kind of accurate positioning is sensible, if one could use hardware sprites for pixel-wise movement instead.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m curious how this could be coded, and then recoded for efficiency (storage-wise and/or instruction-cycle-wise). I&amp;rsquo;m sure it depends on what is needed for the game.&lt;/p&gt;
&lt;p&gt;To make it more interesting for video games, one would like to introduce colors, like in multi-color character mode, and bigger sprites. I might not get to this, because monochrome character mode seems daunting enough for me.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Philosophizing about software sprites</title>
      <link>https://renevanbelzen.micro.blog/2023/12/24/philosophizing-about-software.html</link>
      <pubDate>Sun, 24 Dec 2023 10:38:12 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/24/philosophizing-about-software.html</guid>
      <description>&lt;p&gt;While reading through some articles about hardware sprites, sometimes called movable object blocks (MOBs), I realized that the C64 is probably too slow to move software driven sprites. In 1/60 s at ± 1.02 Mhz there are 17000 instruction cycles for an interrupt, or (&lt;code&gt;17000 / 4 =&lt;/code&gt;) 4250 average instructions per interrupt cycle.&lt;/p&gt;
&lt;p&gt;A typical copy operation is with zero page indexed addressing in a loop requires 14 instruction cycles per copied byte. Add to this a bit shift in a buffer (add another 4 cycles), and an area of 32 by 23 pixels to hold a 24 by 21 pixel MOB, then a back of the envelope calculation gives us (&lt;code&gt;4 x 23 x 18 =&lt;/code&gt;) 1656 instruction cycles per pixel shifting MOB, at 60 fps. With nothing else to do, that would give us (&lt;code&gt;17000 /  1656 =&lt;/code&gt;) 10 MOBs at most.&lt;/p&gt;
&lt;p&gt;If the Kernal is supposed to do something, like being able to run Basic, then it&amp;rsquo;s probably feasible to maintain 3 MOBs at most.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7793.gif&#34; width=&#34;338&#34; height=&#34;190&#34; alt=&#34;animated brave little warrior running across the screen past a still warrior&#34;&gt;
&lt;p&gt;Another calculation. What if one wanted to fill a whole screen, all 1000 bytes at 14 instruction cycles per byte? With the interrupt disabled, that would make a refresh cycle possible of at most 1/7th of a second, which is clearly noticeable. It makes sense in that case to use a frame buffer, and switch buffers after a buffer has been updated. This would enable slowly animating backgrounds, in other words, choppy animation, which could be interesting in some cases. There wouldn&amp;rsquo;t be any redrawing of the screen, breaking suspension of disbelief in most players.&lt;/p&gt;
&lt;p&gt;Of course, it&amp;rsquo;s possible to rewrite only a part of the buffer, so the frame rate can be increased. Using the estimated 3 MOBs per 1/60 s. That is (&lt;code&gt;(4 MOBs of 23 rows of 4 bytes) / (40 bytes per line) =&lt;/code&gt;) 9 lines per 1/60 s, or around (&lt;code&gt;9 / 25 ≈&lt;/code&gt;)  ⅓ of the screen which can be believably animated using a frame buffer. This needn&amp;rsquo;t be a contiguous areas. Disparate parts of the screen could be animated, at some instruction cycle cost to update zero page pointers to new values.&lt;/p&gt;
&lt;p&gt;I should emphasize, this is all theoretical (philosophical?) and for 2-color MOBs. With multi-colored MOBs more bytes need to be updated, reducing the frame rate by at least 50 percent. The &amp;ldquo;claims&amp;rdquo; above have to be proven by code first.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7792.gif&#34; width=&#34;210&#34; height=&#34;210&#34; alt=&#34;animated floating cute chibi girl and its larger version non-animated&#34;&gt;
&lt;p&gt;It was fun dreaming about such an endeavor, and see what the possible limits would be. For snappy code, one should really disable the Kernal interrupt routine, and use one&amp;rsquo;s own instead. I suppose this is why most video games require a reset to return to Basic. If Basic has to coexist, it will limit what kind of games can be played. Fast moving action-based games are probably not among those. In that case, you&amp;rsquo;re probably already committed to using hardware sprites.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/23/i-have-a.html</link>
      <pubDate>Sat, 23 Dec 2023 19:59:53 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/23/i-have-a.html</guid>
      <description>&lt;p&gt;I have a very unoptimized way to fill a rectangle on a C64 video screen with characters, as in a MOB (movable object) instead of a hardware sprite. It&amp;rsquo;s around 25 times faster than using Basic, and has &amp;ldquo;frame rate&amp;rdquo; of around 12 fps on a 50 Hz monitor. I&amp;rsquo;m sure it can be much faster. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/imb-xmda9j.gif&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;slide show of the several output screens of my program on the Commodore 64 that tests both a Basic and a machine language version&#34;&gt;
</description>
    </item>
    
    <item>
      <title>POKEing to the Commodore 64 screen</title>
      <link>https://renevanbelzen.micro.blog/2023/12/23/pokeing-to-the.html</link>
      <pubDate>Sat, 23 Dec 2023 08:31:52 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/23/pokeing-to-the.html</guid>
      <description>&lt;p&gt;I was looking through the &lt;em&gt;Commodore 64 Programmer&amp;rsquo;s Reference Guide,&lt;/em&gt; in the chapter about graphics, how I could POKE screen codes to the screen, so to speak, in 6502 assembly. Here is what I came up with.&lt;/p&gt;
&lt;p&gt;First of all, what do I mean with &amp;ldquo;POKE&amp;rdquo; and &amp;ldquo;screen codes&amp;rdquo;?&lt;/p&gt;
&lt;p&gt;POKE is a CBM Basic 2.0 command, also available on many Microsoft Basic variants on 1980&amp;rsquo;s and 1990&amp;rsquo;s home computers. It allowed the programmer to place a value anywhere in the 64 Kb of memory addressing space available to the Central Processing Unit (CPU, which is the 6510, a variant of the 6502). Since the screen in the default configuration is located at memory addresses 1024 to 2023, one could put a value A into column C and row R as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
POKE 1024 + 40*R + C, A
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0 &amp;lt;= R &amp;lt;= 24&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0 &amp;lt;= C &amp;lt;= 39&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0 &amp;lt;= A &amp;lt;= 255&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is all well and good, but it seems rather slow, even if we invoked these commands in 6502 machine code. I&amp;rsquo;ll come to that later.&lt;/p&gt;
&lt;p&gt;Screen codes are Commodore specific values, which are used internally to represent characters. There is a direct correlation between a screen code an its position in the character ROM. The codes are different than the codes used for printing (which codes are collectively called PETSCII, Commodore&amp;rsquo;s own version of ASCII). For instance the letter &amp;lsquo;A&amp;rsquo; is the value 1 in screen code and 65 in PETSCII.&lt;/p&gt;
&lt;p&gt;Why do I even want to POKE screen codes to the screen, if the same can be done using PETSCII and printing? Well, I want to put blocks of screen codes onto screen, using a self-defined character set, to use for a video game. In that case the Basic commands and even the routines in the underlying operating system (Kernal) are just too slow. I need custom routines to put screencodes onto screen.&lt;/p&gt;
&lt;p&gt;So I started to explore what is needed.&lt;/p&gt;
&lt;p&gt;It seems the video chip, the VIC II, can only &amp;ldquo;see&amp;rdquo; a quarter of the 64 Kb of addressing space, i.e. 16 Kb, in four banks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;bank 0, $0000 - $3FFF (default)&lt;/li&gt;
&lt;li&gt;bank 1, $4000 - $7FFF&lt;/li&gt;
&lt;li&gt;bank 2, $8000 - $BFFF&lt;/li&gt;
&lt;li&gt;bank 3, $C000 - $FFFF&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is controlled through bits 0 and 1 of data register A (DRA) of the Complex Interface Adapter (CIA) chip. There are four possible values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;%11 VIC II bank 0 (default)&lt;/li&gt;
&lt;li&gt;%10 VIC II bank 1&lt;/li&gt;
&lt;li&gt;%01 VIC II bank 2&lt;/li&gt;
&lt;li&gt;%00 VIC II bank 3&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So bits 0 and 1 have to be inverted to get the binary value of the VIC II bank. Furthermore, in order to read data register A, their bits have to be set to zero selectively in the data direction register (DDRA) for data register A. All the other bits of DDRA have to left alone.&lt;/p&gt;
&lt;p&gt;Within the 16 Kb available at one time to the VIC II, there are 16 possible relative locations of screen memory (25 lines of 40 characters, or 1000 bytes):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$0000 - $03E7&lt;/li&gt;
&lt;li&gt;$0400 - $07E7 (default)&lt;/li&gt;
&lt;li&gt;$0800 - $0BE7&lt;/li&gt;
&lt;li&gt;$0C00 - $0FE7&lt;/li&gt;
&lt;li&gt;$1000 - $13E7&lt;/li&gt;
&lt;li&gt;$1400 - $17E7&lt;/li&gt;
&lt;li&gt;$1800 - $1BE7&lt;/li&gt;
&lt;li&gt;$1C00 - $1FE7&lt;/li&gt;
&lt;li&gt;$2000 - $23E7&lt;/li&gt;
&lt;li&gt;$2400 - $27E7&lt;/li&gt;
&lt;li&gt;$2800 - $2BE7&lt;/li&gt;
&lt;li&gt;$2C00 - $2FE7&lt;/li&gt;
&lt;li&gt;$3000 - $33E7&lt;/li&gt;
&lt;li&gt;$3400 - $37E7&lt;/li&gt;
&lt;li&gt;$3800 - $3BE7&lt;/li&gt;
&lt;li&gt;$3C00 - $3FE7&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The relative base address of screen memory is controlled by the lower 4 bits of register 24 of the VIC II. Again, only these bits should be manipulated, while the upper 4 bits should not be changed for selecting the screen location. Of course, I am only reading the bits, so I&amp;rsquo;m safe in that regard.&lt;/p&gt;
&lt;p&gt;The Kernal has (half) a pointer to the full address of the beginning of screen memory, the high-byte. This pointer is stored in location 648 ($288). I can either use that, or calculate it myself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$288 (648): high-byte of pointer to the base of screen memory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Of course, if I would relocate the screen, I would have to change this pointer in my code, so there&amp;rsquo;s value in knowing how to calculate this high-byte, even if it isn&amp;rsquo;t needed if I don&amp;rsquo;t change the screen location in memory. I could just as well use the value in $288.&lt;/p&gt;
&lt;p&gt;I calculated the high-byte of this pointer as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
; some addresses defined

vicmemptr       eqm $d018       ; VIC II memory pointer register
cia2rega        eqm $dd00       ; CIA 2 register A
cia2ddra        eqm $dd02       ; CIA 2 data direction register A

; determine location of screen memory
; returns .A hi byte of base address of screen memory
; modifies .A, flags

screenbas:

                ; determine the VIC II base address

                lda cia2ddra    ; set
                and #%11111100  ; bits 0, 1
                sta cia2ddra    ; of reg A to &#34;read&#34;
                lda cia2rega    ; read reg A
                and #%00000011  ; only bits 0, 1
                eor #%00000011  ; invert bits 0, 1
                lsr             ; optimization -&gt; shift into bits 6, 7
                ror             ; in effect, multiply by 2^6
                sta screenb1+1  ; self-mod code

                ; determine location of screen memory inside the 16 Kb VIC II bank

                lda vicmemptr   ; get
                and #%11110000  ; upper 4 bits
                lsr
                ror             ; make it hi byte * 2^2

                ; add base address of VIC II to relative base address of screen memory

                clc
screenb1:       adc #$ff        ; self-modded
                rts
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I hope you didn&amp;rsquo;t mind my code self-modification trick, but it does work in RAM. In ROM one would do it differently, naturally.&lt;/p&gt;
&lt;p&gt;Now I know where the screen is located in memory, how can I put a screen code into a particular column and row? There are 40 columns and 25 rows, numbered from 0 to 39, and to 25, respectively. This means the memory location, based on column and row value can be calculated as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;screen base + column * 40 + row&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I&amp;rsquo;ll use indirect indexing to point to this address, where the .Y register serves as the index:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
                 sta (putadr),y ; store it in the yth column
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where &lt;code&gt;putadr&lt;/code&gt; holds the address of the first row of the column on screen. The .Y register then accesses the Y-th column in the instruction above. It makes sense to store the column value in the .Y register (the same as the Kernal does).&lt;/p&gt;
&lt;p&gt;Adding address values is pretty straight forward, but how to calculate times forty?&lt;/p&gt;
&lt;p&gt;Remember that the 6502 has a shift left instruction, which is equivalent to multiplying by two. So, with some shifting and adding it is possible to get to times forty quicker than doing it traditionally (multiply two 8-bit values into a 16-bit value):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;value * 40 = ( value + (value * 2^2) ) * 2^3&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That is 5 left shifts and 2 additions. However, while five times a column value still fits into a single byte, multiplying it by 8 doesn&amp;rsquo;t fit in that single byte anymore. At that point two bytes are needed.&lt;/p&gt;
&lt;p&gt;Here is the code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
; put screen code onto screen
; parameters:
;     .A screen code
;     .Y screen column, between 0 and 39
;     .X screen row, between 0 and 24
; returns:
;     carry flag set means an error occurred
; all registers are affected
; bits 0, 1 of DDRA of CIA 2 ($DD02) are set to zero (read)
; zero page $02, $03 are used

putadr:          eqm $02        ; 2-byte screen address

putonscn:        cpy #40        ; column &gt;= 40 ?
                 bcs putexit    ; yes, then exit w/ error
                 cpx #25        ; row &gt;= 25 ?
                 bcs putexit    ; yes, then exit w/ error
                 pha            ; save for later
                 stx putadr     ; initialyze screen address
                 txa            ; transfer row to .A
                 asl
                 asl            ; row * 2^2
                 adc putadr     ; row * 2^2 + row
                 sta putadr
                 ldx # 0        ; zero hi byte
                 stx putadr+1   ; of screen address
                 asl
                 rol putadr+1
                 asl
                 rol putadr+1
                 asl
                 rol putadr+1
                 sta putadr     ; (row * 5) * 2^3
                 jsr screenbas  ; add hi byte of screen base address
                 adc putadr+1
                 sta putadr+1   ; baseadr + (row * 40)
                 pla            ; get screen code back
                 sta (putadr),y ; store it in the yth column
                 clc            ; no errors
putexit          rts
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To check if this code actually works I added a combination of assembly and Basic language, so it could run from the Basic prompt on the Commodore 64 with the RUN command.&lt;/p&gt;
&lt;p&gt;It working made me a happy coder.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/22/on-the-c.html</link>
      <pubDate>Fri, 22 Dec 2023 22:01:55 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/22/on-the-c.html</guid>
      <description>&lt;p&gt;On the C64, using the Kernal, you can set the cursor position (one routine) and then print a character (another routine). I wanted a single routine to put a screen code onto the screen, at a particular colomn and row, wherever the screen was located in memory. So I wrote it, and it works, yay! 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/21/i-installed-droid.html</link>
      <pubDate>Thu, 21 Dec 2023 13:16:29 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/21/i-installed-droid.html</guid>
      <description>&lt;p&gt;I installed &lt;a href=&#34;https://droid64.sourceforge.net/&#34;&gt;droid64&lt;/a&gt;, a Java application to manipulate Commodore disk images and copy files between your host OS and a disk image (e.g. a file with a D64 extension). I needed it to be able to play new games. I also put a SPEEDLINK SL-650212-BKRD Competition PRO USB joystick on my Amazon wish list 🎮&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Challenge the challenger (or: a little help wanted here)</title>
      <link>https://renevanbelzen.micro.blog/2023/12/21/challenge-the-challenger.html</link>
      <pubDate>Thu, 21 Dec 2023 08:44:53 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/21/challenge-the-challenger.html</guid>
      <description>&lt;p&gt;It is said, by some, that there&amp;rsquo;s nothing magical about January 1. So resolutions seem rather nonsensical, at least, putting a start date on something. Just start, which is what I just did, by writing and publishing this blog post. And, I warn you in advance, I will ramble and meander through my &amp;ldquo;ideascape&amp;rdquo; (if that&amp;rsquo;s even a word—it now is).&lt;/p&gt;
&lt;p&gt;As announced in &lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/19/goal-for-making.html&#34;&gt;my previous post&lt;/a&gt;, and I&amp;rsquo;m still calling it that, my self-challenge is called &lt;em&gt;&lt;strong&gt;366 Days of Coding.&lt;/strong&gt;&lt;/em&gt; The year 2024 will become the year that I finally produced a video game. I&amp;rsquo;ve tried many times before, but was held back by lack of confidence, mostly. I&amp;rsquo;ve worked on that in 2023, and my improved mental hygiene should give me the protection against self-doubt I need.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7777.png&#34; width=&#34;640&#34; height=&#34;480&#34; alt=&#34;Commodore 64 screen drawing stating 366 days of code, in 2024 I will create a Commodore 64 video game&#34;&gt;
&lt;p&gt;Now how is this going to work, what will be my general overarching workflow? Well, I don&amp;rsquo;t know… I&amp;rsquo;ve never been much of a planner. I always let deadlines pass by, and brushed it off as proof that I&amp;rsquo;m worthless, because, well, see! That&amp;rsquo;s no way to live. First of all, seeing how long indie games are in beta, testing and debugging seems a rather important part of software development. Also, it&amp;rsquo;s good to have a second opinion to rely on, which means beta-testers. However, on my first try I&amp;rsquo;ll have to do most of that myself, since I lack any reputation to call for outside help, and actually receive help.&lt;/p&gt;
&lt;p&gt;I can imagine it&amp;rsquo;s like writing one&amp;rsquo;s first novel. It takes such a long time, because a lot has to be learned, especially accepting outside help from a closed reader group, who give positive feedback on one&amp;rsquo;s writing. In that first attempt, as a new writer, I guess most figure that out for themselves, perhaps by using a partner or close friends as &amp;ldquo;guinea pigs&amp;rdquo;, or whatever is available to them. Purposefully looking for a group of dedicated beta-readers, often means one has been oneself first. I suppose being an avid reader is a prerequisite for becoming a writer, why else would one even want to write a book? In fact, helping a writer out with positive critique may give the critic ideas on how to become a writer themselve. From that perspepctive, gathering a group of beta-readers seems to me like paying something forward, from the writer&amp;rsquo;s point of view.&lt;/p&gt;
&lt;p&gt;However, there are many more readers of books than there are players of retro-games. It&amp;rsquo;s a self-selecting group of mostly older people with nostalgia, and younger people who can identify with the &lt;em&gt;old times,&lt;/em&gt; as an esthetic. They will be opinionated, perhaps even rude, since they are far off the beaten path, into a barren land (space-time, actually) that once was great and thriving, and only is accessible through personal memory and documentation (books, magazines, videos, etc.). On the other hand, retro-gaming is having a revival, as all things eighties of the previous century. Things in the current news are rather grim, and there is certainly a hunkering for the &lt;em&gt;good old days,&lt;/em&gt; even in those who never lived through those.&lt;/p&gt;
&lt;p&gt;So, however I will go about things, testers are an essential part of software development. After all, a video game, like a book, is to be experienced by others than the author/creator. It makes sense to accept input by those others, not what or how to make something, but how they experienced what you made. Still, there are always those who think they know better than you, and offer how-to tips. They might know better, but you are the person making, on your terms, schedule and responsibility. Whatever you make, it is always a compromise between what you aim at (aim as high as you can), how much time you have (besides daily chores, work, etc.), and what you can put up with and still enjoy it (mostly).&lt;/p&gt;
&lt;p&gt;If you have no idea of the final product, don&amp;rsquo;t have the time, and don&amp;rsquo;t like the process, this is not for you.&lt;/p&gt;
&lt;p&gt;I have some ideas what to make, so many, that I need to pick one. My first task, then, is to explore the world of indie gaming on retro computers, briefly (!), and see what I like and don&amp;rsquo;t like. There are no original ideas—well so few that they don&amp;rsquo;t stand out—but there are original spins on existing ideas. With a shortlist of ideas I can think about what my take would be. This will lead to an opinionated product, some will like, others won&amp;rsquo;t. That is a good thing, since you don&amp;rsquo;t want a bland product no one hates, but also no one prefers. You can&amp;rsquo;t please everyone. Heck, it&amp;rsquo;s hard to please anyone nowadays, with the world being as polarized as it currently is.&lt;/p&gt;
&lt;p&gt;After having a list of possible ideas, it&amp;rsquo;s time to prototype, and see what appeals to me. This is often done on paper or in a design document, rough, yet playable, if you do the mechanics of the game yourself. In the final game this is all automated, but in this rough stage, you are the driver, leaving room to change mechanics on the fly.&lt;/p&gt;
&lt;p&gt;Now comes the hard part, picking and committing. You can always go back and pick something else once you hit a dead end, but that shouldn&amp;rsquo;t be par for the course.&lt;/p&gt;
&lt;p&gt;What comes after that is still blurry to me, because I&amp;rsquo;ve never done something like this before. I&amp;rsquo;m sure to keep you posted once I discover the intricacies of game development, at least, how I perceive those. This is an experiment of one. You shouldn&amp;rsquo;t copy someone else&amp;rsquo;s workflow, but, instead, learn from it, to improve yours. This doubly applies to a newbie like myself, looking at how other, more seasoned developers go about things.&lt;/p&gt;
&lt;p&gt;It will be educational. Of that I&amp;rsquo;m sure.&lt;/p&gt;
&lt;p&gt;Thanks for sticking with it until the end of this thought piece. I&amp;rsquo;m sure I got most things (slightly) wrong. Please feel free to comment and enlighten me with your bright ideas, maybe suggest (parts of) how to do what I&amp;rsquo;m planning to do. I&amp;rsquo;m sure I will learn something from it, and, reciprocally, by formulating your ideas in clear words, you might as well.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/20/i-redid-the.html</link>
      <pubDate>Wed, 20 Dec 2023 14:54:03 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/20/i-redid-the.html</guid>
      <description>&lt;p&gt;I redid the random maze program in assembly language. If you load and RUN the program, it displays the maze, waits for the user to press a key, then clears the screen and returns to the BASIC prompt. It&amp;rsquo;s simple, but it made me proud nonetheless that it actually works.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/2023-12-20-144737-1920x1080-scrot.png&#34; width=&#34;600&#34; height=&#34;337&#34; alt=&#34;screenshot of a Commodore 64 screen showing a random maze&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/20/i-have-found.html</link>
      <pubDate>Wed, 20 Dec 2023 09:46:54 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/20/i-have-found.html</guid>
      <description>&lt;p&gt;I have found a better way to assemble 6502 code than &lt;a href=&#34;https://www.masswerk.at/6502/assembler.html&#34;&gt;Virtual 6502 Assembler&lt;/a&gt;. I installed &lt;a href=&#34;https://dasm-assembler.github.io&#34;&gt;DASM&lt;/a&gt; from the official Pi OS repository on my Raspberry Pi-400, rewrote the KickAss source code, and assembled that into a BASIC loader program. Took long, because of differing assembler directives, and a nasty typo 🤬&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7770.png&#34; width=&#34;600&#34; height=&#34;337&#34; alt=&#34;screenshot of a Rasberry Pi OS desktop, running the helloworld program in a C64 emulator&#34;&gt;
</description>
    </item>
    
    <item>
      <title>Getting a foothold into 6502 machine language, bonus part</title>
      <link>https://renevanbelzen.micro.blog/2023/12/19/getting-a-foothold.html</link>
      <pubDate>Tue, 19 Dec 2023 14:29:25 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/19/getting-a-foothold.html</guid>
      <description>&lt;p&gt;The file I assembled and downloaded as a .PRG file, using the Virtual 6502 Assembler, I smart attached in the V.I.C.E. C128 emulator. I then attached an empty .D64 disk file, and used Basic 7.0 to save memory location $C000 to $C12F to a binary file, called &amp;ldquo;usrfunc04.c000&amp;rdquo;. I detached the .D64 file, and closed V.I.C.E. C128. In the C64 emulator I rewrote the previous C64 Basic program so it loads this binary file from disk. It then proceeds to checking of primality of numbers between 0 and 65535. I saved this Basic program to the same disk as the binary file, and copied it as text in the listing below.&lt;/p&gt;
&lt;p&gt;[
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/13/getting-a-foothold.html&#34;&gt;part 1&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/14/getting-a-foothold.html&#34;&gt;part 2&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/15/getting-a-foothold.html&#34;&gt;part 3&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/16/getting-a-foothold.html&#34;&gt;part 4&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/17/getting-a-foothold.html&#34;&gt;part 5&lt;/a&gt;
]&lt;/p&gt;
&lt;p&gt;It was a bit of a hassle, but it all works, and that&amp;rsquo;s what counts here.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
0 rem testusrf-0-4.bas
1 rem version 6 - test completed usr function
10 on s goto 20,40
20 print &#34;loading binary file...&#34;:print
30 s=2:load&#34;usrfunc04.c000&#34;,8,1
40 poke 785,0: poke 786,192:rem usr function at $c000
50 print &#34;... (tests between 0 and 65535)&#34;:print
60 for n=0 to 65535
70 m = usr(n)
80 print n;&#34;is &#34;;: if not m then print &#34;not &#34;;
90 print &#34;prime&#34;
100 print &#34;any key to continue&#34;
110 poke 198,0:wait198,1:poke198,0
120 next n
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/19/i-had-to.html</link>
      <pubDate>Tue, 19 Dec 2023 11:52:49 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/19/i-had-to.html</guid>
      <description>&lt;p&gt;I had to search for a particular Commodore 128 command, and found it &lt;a href=&#34;https://www.commodore.ca/commodore-128-system-guide-complete-with-graphics-and-basic-7-cp-m/&#34;&gt;here&lt;/a&gt;, which, BTW, I typed in myself from a book, and corrected many errors in that book. It now is the definitive guide on the web for Commodore 128 retro-computer users. It is anonymous, though, since I haven&amp;rsquo;t written the book.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Goal for 2024, making games for the Commodore 64</title>
      <link>https://renevanbelzen.micro.blog/2023/12/19/goal-for-making.html</link>
      <pubDate>Tue, 19 Dec 2023 07:54:42 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/19/goal-for-making.html</guid>
      <description>&lt;p&gt;In the Commodore 64 Programmer&amp;rsquo;s Reference Guide, published by Commodore Business Machines, Inc. and Howard W. Sams &amp;amp; Co., Inc. in 1982, there is a chapter on programming graphics with history&amp;rsquo;s most popular retro-computer. Graphics are an essential part of computing, and understanding how it works &lt;em&gt;under the hood&lt;/em&gt; is essential for the C64, since it has no Basic commands to manipulate graphics. It all has to be done with PEEKs and POKEs.&lt;/p&gt;
&lt;p&gt;I want to use C64 graphics to create a simple game, maybe a few games. There are a few characteristics to a video game:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;introduction screen (typically colored bitmap graphics) while loading the code and assets&lt;/li&gt;
&lt;li&gt;game area, which has to be somewhat fast, which rules out bitmap graphics, instead what&amp;rsquo;s mostly used is:
&lt;ul&gt;
&lt;li&gt;standard character mode with programmable characters for black and white games&lt;/li&gt;
&lt;li&gt;multi-color character mode with programmable characters for color games&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Modes can be mixed, using interrupts when the electron beam isn&amp;rsquo;t displaying anything. Of course, this is an advanced programming technique, and doesn&amp;rsquo;t always render perfectly.&lt;/p&gt;
&lt;p&gt;On top of that there are hardware sprites, all 8 of them, but those can be multiplied virtually, by moving them lower on the screen after they have been displayed by the VIC-II chip. It all comes down to timing, and, hence, using optimized 6502 machine language. Sprites, since they are moving, can bump into each other, which is only possible doing convincingly using machine code. It seems all very exciting and challenging.&lt;/p&gt;
&lt;p&gt;If the world of the game is larger than what fits on a video screen, &lt;em&gt;side scrolling&lt;/em&gt;  can be used. Side scrolling is a video game genre in its own right. There&amp;rsquo;s also &lt;em&gt;free scrolling,&lt;/em&gt; where the screen is a window on the game world that can move up, down, left and right.&lt;/p&gt;
&lt;p&gt;Since there is a limited amount of memory in the computer, it makes sense to use repeating patterns to represent the game world. The screen then exists of tiles of the same content, which together represent grass, forest, pavement, etc. It is part of game design.&lt;/p&gt;
&lt;p&gt;The game logic could be written in Basic, though, since it doesn&amp;rsquo;t have to be so snappy, responding to user input. This also allows users to modify the game, which is a bonus, in my opinion. However, in order for Basic to work, RAM becomes inaccessible while Basic and Kernal ROM is being switched on, to enable Basic to run. There are ways around this, since, while switched away, RAM is still available, can even be written to, just not read from (and not be used while a Basic program runs).&lt;/p&gt;
&lt;p&gt;The thing is, that the Commodore 64 is a very quirky computer, with many restrictions, that can be worked around, but need special attention from the coder, in other words, creative solutions.&lt;/p&gt;
&lt;p&gt;To not get bogged down by details, maybe it&amp;rsquo;s more effective to start simple, and only make things more complicated if there&amp;rsquo;s a need for it. It&amp;rsquo;s better to write a minimal viable solution than keep putting off finishing, because it could be &amp;ldquo;so much more awesome.&amp;rdquo; Yes, it would, but will it ever see the light of day? Like real artists, real software developers ship.&lt;/p&gt;
&lt;p&gt;Even games written in Basic can be quite appealing. Sometimes Basic isn&amp;rsquo;t fast enough, and in those cases one can use some machine language to speed things up. Games completely written in 6502 assembly language are often developed on another computer. Nowadays that would be a Mac or Windows computer.&lt;/p&gt;
&lt;p&gt;The idea that the game player can change things appeals to me. Of course, that needn&amp;rsquo;t be in Basic. There are other programming languages. A popular one nowadays is Lua (free and open source, easy to implement in your own code). However, Basic is already there, so why not use it?&lt;/p&gt;
&lt;p&gt;This is going to be a long haul, isn&amp;rsquo;t it?&lt;/p&gt;
&lt;p&gt;Since it probably is, it would be such a nice goal for the end of 2024 to have developed and published a game for the Commodore 64, one I feel proud of.&lt;/p&gt;
&lt;p&gt;Who knows, it might even be several games. For now, being realistic, let me stick to promising that I will finish at least one game.&lt;/p&gt;
&lt;p&gt;However the gaming dice will roll for me, 2024 will be my &amp;ldquo;266 days of coding.&amp;rdquo; Yep, it&amp;rsquo;s a leap year.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/18/oh-wow-i.html</link>
      <pubDate>Mon, 18 Dec 2023 16:25:04 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/18/oh-wow-i.html</guid>
      <description>&lt;p&gt;Oh wow! I went to &lt;a href=&#34;https://github.com&#34;&gt;Github.com&lt;/a&gt; on my iPad, clicked on one of my repo&amp;rsquo;s, connected an USB keyboard and pressed the period key &amp;ldquo;.&amp;rdquo; 🤯&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Doing the work, needing the tool (read: iPad Air, perhaps?)</title>
      <link>https://renevanbelzen.micro.blog/2023/12/18/doing-the-work.html</link>
      <pubDate>Mon, 18 Dec 2023 08:04:33 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/18/doing-the-work.html</guid>
      <description>&lt;p&gt;Here&amp;rsquo;s an exercise from the book &amp;ldquo;Programming the 6502&amp;rdquo;, 4th edition, by Rodnay Zaks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Exercise 1.12:&lt;/strong&gt; &lt;em&gt;Complete the following additions. Indicate the result, the carry C, the overflow V, and whether the result is correct or not:&lt;/em&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
10111111  (_______)
11000001  (_______)
------------------ ﹢
________  (_______)

V:____ C:____
[ ] CORRECT [ ] ERROR
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
11111010  (_______)
11111001  (_______)
------------------ ﹢
________  (_______)

V:____ C:____
[ ] CORRECT [ ] ERROR
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
00010000  (_______)
01000000  (_______)
------------------ ﹢
________  (_______)

V:____ C:____
[ ] CORRECT [ ] ERROR
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
01111110 (_______)
00101010 (_______)
------------------ ﹢
________  (_______)

V:____ C:____
[ ] CORRECT [ ] ERROR
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To say that this was easy to transcode in Markdown/HTML would be a grand understatement. My &amp;ldquo;code editor&amp;rdquo;, the Drafts app was fighting me all the way, and, while split view was showing me the PDF of the book in the Documents app, Apple&amp;rsquo;s native Files app was having a &lt;em&gt;grand mal.&lt;/em&gt; So much so, that I had to reboot my iPad to get the Files app &lt;em&gt;unjammed&lt;/em&gt; (it was completely locked up, unresponsive, frozen). I guess the 9th generation iPad isn&amp;rsquo;t cut out to do any &amp;ldquo;professional&amp;rdquo; work, like code-editing HTML 😅&lt;/p&gt;
&lt;p&gt;I suppose if there was ever a reason to need a more pro version of the iPad, here it is. I guess an iPad Air would do much better, even if it costs twice as much as the &amp;ldquo;primary school iPad&amp;rdquo;—cough—iPad 9th generation.&lt;/p&gt;
&lt;p&gt;I have a Raspberry Pi-400, but it has drawbacks as well, a gleaming one being lack of any good application software. Linux on the desktop is always &amp;ldquo;just a year away&amp;rdquo;, permanently 😉&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m told 2024 will be &amp;ldquo;the year of the iPad.&amp;rdquo; I&amp;rsquo;m hoping it is, because not only is my current iPad underpowered, its battery also is getting old. You see, I&amp;rsquo;m not using it casually, as a beginner iPad user, but as a full-fledged work computer, so to say. In a school setting it would&amp;rsquo;ve been replaced, no doubt, or, at least, sent to an authorized Apple Service Center for maintenance &amp;amp; repair.&lt;/p&gt;
&lt;p&gt;So, yay for 2024, may it bring me a nicer iPad.&lt;/p&gt;
&lt;p&gt;🙄 I&amp;rsquo;m such a consumer, totally in the Apple camp of things…&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Getting a foothold into 6502 machine language, part 5</title>
      <link>https://renevanbelzen.micro.blog/2023/12/17/getting-a-foothold.html</link>
      <pubDate>Sun, 17 Dec 2023 17:06:55 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/17/getting-a-foothold.html</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve rewritten the code I developed earlier and extended it into a full-fledged &lt;code&gt;usr&lt;/code&gt; machine language routine. However, it needed testing, because of all the rewrites. So I grabbed my copy of &lt;a href=&#34;https://workingcopy.app&#34;&gt;Working Copy&lt;/a&gt; on my iPad and started Git-versioning both the assembly and the Basic code. It was invaluable for getting the code to work correctly.&lt;/p&gt;
&lt;p&gt;[
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/13/getting-a-foothold.html&#34;&gt;part 1&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/14/getting-a-foothold.html&#34;&gt;part 2&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/15/getting-a-foothold.html&#34;&gt;part 3&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/16/getting-a-foothold.html&#34;&gt;part 4&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/19/getting-a-foothold.html&#34;&gt;bonus&lt;/a&gt;
]&lt;/p&gt;
&lt;p&gt;Here are some of the major changes I made:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the input and output of functions now use the .A, .X and .Y registers&lt;/li&gt;
&lt;li&gt;the prime function now picks out of a list of all the 54 prime numbers that smaller than 256&lt;/li&gt;
&lt;li&gt;a main routine was added that tests the primality of the value put into the &lt;code&gt;usr&lt;/code&gt; function in Basic, and returns either a zero (false) or minus one (true)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After every part was tested, I ended up with a collection of documents, I&amp;rsquo;ll share next. These are the algorithm, assembly code, and Basic test program (the machine code already loaded in locations $c000, or 49152, and higher). I did away with a machine code loader in data statements, because that became too much of a chore. The point of this whole exercise was to learn something about coding for the Commodore 64, particularly in 6502 assembly language.&lt;/p&gt;
&lt;p&gt;And that I have accomplished. It isn&amp;rsquo;t the most efficient 6502 machine language routine, but it does work. And that always makes me happy 😃&lt;/p&gt;
&lt;code&gt;
&#34;algorithm.txt&#34;
&lt;p&gt;&lt;strong&gt;main routine:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;convert the real number from Basic into a 16-bit unsigned integer, called &amp;ldquo;testnum&amp;rdquo;&lt;/li&gt;
&lt;li&gt;set primality flag to &amp;ldquo;false&amp;rdquo;&lt;/li&gt;
&lt;li&gt;for each of the 54 prime numbers that are less than 256,
&lt;ul&gt;
&lt;li&gt;if (testnum == prime) then set primality flag to &amp;ldquo;true&amp;rdquo;, and go to step 6&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;set primality flag to &amp;ldquo;true&amp;rdquo;&lt;/li&gt;
&lt;li&gt;for every next prime, starting with the 0th,
&lt;ul&gt;
&lt;li&gt;if ( (prime * prime) == testnum) then set primality flag to &amp;ldquo;false&amp;rdquo;, and go to step 6&lt;/li&gt;
&lt;li&gt;if ( (prime * prime) &amp;gt; testnum ) then go to step 6&lt;/li&gt;
&lt;li&gt;if ( (testnum modulo prime) == 0) then set primality flag to &amp;ldquo;false&amp;rdquo;, and go to step 6&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;convert the primality flag into a real value and return it to Basic&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;prime function:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;pick the n-th element out of a list of 54 primes, where n starts from zero, up to 53&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;square function:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;start with a zero value for the 16-bit square&lt;/li&gt;
&lt;li&gt;shift square  8 times to the left, and each time
&lt;ul&gt;
&lt;li&gt;shift the 8-bit number to be squared left into the carry bit&lt;/li&gt;
&lt;li&gt;if there&amp;rsquo;s a carry, then add the original value of number to square&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;modulo function:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;shift the 16-bit dividend 16 times into the 16-bit remainder, and each time
&lt;ul&gt;
&lt;li&gt;after each shift, test subtract divisor from remainder, and only store in remainder for positive values&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/code&gt;
&lt;pre&gt;&lt;code&gt;
&#34;usrfunction-0-4.asm&#34;

; usrfunction-0-4.asm

        getadr = $b7f7
        givayf = $b391
        
        *= $c000
        
                jsr getadr      ; convert real into unsigned int 
                                ; in .A &amp; .Y (hi/lo)
                sty testnum     ; save for later use
                sta testnum+1
                ldx #$00
                stx isprime     ; assume it is not a prime
                cpy #$02        ; is testnum less than 2?
                lda testnum+1
                sbc #$00
                bcs okay        ; testnum &gt;= 2
                jmp foundit     ; no, then output value of isprime
        okay:

        ; test if test number is equal to one of the prime numbers

                ldx #53
                stx order       ; start with 53th prime
        loop1:        
                ldx order
                bmi loop1x      ; if &lt; 0 then exit loop

                jsr prime       ; get nth prime in .X
                cpx testnum     ; is testnum == prime?
                bne loop1a      ; no, then next prime
                lda testnum+1
                bne loop1a

                ldy #$ff        ; yes, then
                sty isprime     ; it is a prime
                bne foundit     ; skip to the end
        loop1a:
                dec order       ; try previous prime
                clc
                bcc loop1       ; continue loop
        loop1x: 
        
                lda #$ff
                sta isprime     ; assume testnum is prime
                
                lda #$00
                sta order       ; start with 0th prime
                
        loop2:
                ldx order
                jsr prime       ; find the nth prime
                stx temp        ; store for later use
                txa
                jsr square      ; square the prime
                
                cmp testnum     ; prime * prime == testnum ?
                bne loop2a
                cpy testnum+1
                bne loop2a
                ldy #$00
                sty isprime     ; yes, then it is not a prime
                beq foundit
                
        loop2a:
                cmp testnum     ; is prime * prime &gt; testnum?
                tya
                sbc testnum+1
                bcs foundit     ; then exit the loop
                
                ldx temp        ; prime is divisor
                lda testnum     ; testnum is dividend
                ldy testnum+1
                jsr modulo
                
                cmp #$00        ; is remainder zero?
                bne loop2b      ; no, then next prime
                cpy #$00
                bne loop2b
                ldy #$00        ; yes, then
                sty isprime     ; it is not a prime
                beq foundit
                
        loop2b:
                inc order       ; try next prime
                clc
                bcc loop2       ; continue loop
                
        foundit:
                lda isprime     ; primality flag is
                tay             ; either $0000 or $ffff
                jmp givayf      ; make it real &amp; return to Basic
    
        
        testnum:
                .word $ffff     ; container for number to be tested
        order:
                .byte $ff       ; container for n, as in nth prime
        isprime:
                .byte $ff       ; container for flag that signals
                                ; primality
        temp
                .byte $ff       ; temporary storage for prime


; prime
; Finds the nth prime on the number line.
; E.g. prime(0) = 2, prime(1) = 3, etc.
;
; input .X order n
;
; output .X nth prime number
;
; effects on .A, .X, .M, .Z
                                
        prime:
                lda primes,x    ; load from list of primes
                tax             ; put it in .X
                rts
        ; ordered list of all 54 prime numbers less than 256
        primes  .byte   2,   3,   5,   7,  11 
                .byte  13,  17,  19,  23,  29
                .byte  31,  37,  41,  43,  47
                .byte  53,  59,  61,  67,  71
                .byte  73,  79,  83,  89,  97
                .byte 101, 103, 107, 109, 113
                .byte 127, 131, 137, 139, 149
                .byte 151, 157, 163, 167, 173
                .byte 179, 181, 191, 193, 197
                .byte 199, 211, 223, 227, 229
                .byte 233, 239, 241, 251
        
                
; square
; Calculates the 16-bit unsigned square of an 8-bit unsigned integer.
;
; input .A number to be squared
; output .A, .Y squared number (lo/hi)
;
; Destroys all registers.

        number = $61            ; 8-bit value to be squared
        nsquare = $62           ; 16-bit value of squared number
        tnumber = $64           ; temporary storage for number
        
        square:
                sta number      ; put .A in number
                lda #$00        ; clear A
                sta nsquare     ; clear square low byte
                                ; (no need to clear the high byte,
                                ; it gets shifted out)
                lda number      ; get number in .A
                sta tnumber     ; save original for later use
                ldx #$08        ; 8 bits to process
        sqloop:
                asl nsquare     ; shift square to left
                rol nsquare+1   ; (i.e. multiply by 2)
                asl a           ; get next highest bit of number
                bcc sqnoadd     ; don&#39;t do add if carry is zero
                tay             ; save .A for later use
                clc
                lda tnumber     ; add original number value
                adc nsquare     ; to square
                sta nsquare
                lda #$00        ; add a possible carry
                adc nsquare+1   ; to the high byte of square
                sta nsquare+1
                tya             ; get .A back
        sqnoadd:
                dex             ; decrement bit counter
                bne sqloop      ; go do next bit
                lda nsquare     ; lo byte of square in .A
                ldy nsquare+1   ; hi byte of square in .Y
                rts
                
                
; modulo
; Calculate the modulo of an 8-bit number with a 16-bit number.
;
; input .A, .Y dividend
;       .X divisor
;
; output .A, .Y remainder
;
; Destroys all registers.

        num1 = $61      ; 16-bit dividend
        num2 = $63      ; 8-bit divisor
        rem = $64       ; 16-bit remainder
        
modulo:
        sta num1        ; .A lo byte of dividend
        sty num1+1      ; .Y hi byte of dividend
        stx num2        ; .X divisor
        lda #$00        ; clear remainder
        sta rem
        sta rem+1
        ldx #16         ; do 16 bits
modloop:
        asl num1        ; shift num1 to the left
        rol num1+1
        rol rem         ; into remainder
        rol rem+1
        sec
        lda rem         ; do trial subtraction
        sbc num2        ; with divisor
        tay
        lda rem+1
        sbc #$00        ; divisor is 8-bit value
        bcc modnosub    ; was there a borrow, 
                        ; then skip subtraction
        sta rem+1       ; save the result
        sty rem
modnosub:
        dex             ; repeat for 16 bits
        bne modloop
        lda rem         ; lo byte of remainder in .A
        ldy rem+1       ; hi byte of remainder in .Y
        rts
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;
&#34;testusrf-0-4.bas&#34;

0 rem testusrf-0-4.bas
1 rem version 5 - test completed usr function
10 poke 785,0: poke 786,192:rem usr function at $c000
20 input &#34;number&#34;;n
30 m = usr(n)
40 print n;&#34;is &#34;;: if not m then print &#34;not &#34;;
50 print &#34;prime&#34;
60 print &#34;any key to continue&#34;
70 poke 198,0:wait198,1:poke198,0
80 goto 20
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/17/writing-correct-code.html</link>
      <pubDate>Sun, 17 Dec 2023 09:30:25 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/17/writing-correct-code.html</guid>
      <description>&lt;p&gt;Writing correct code is such a hassle, yet it has to be done to be able to run it, preferably without error in code, nor confusion in user.&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7767.jpeg&#34; width=&#34;600&#34; height=&#34;438&#34; alt=&#34;screenshot of iPad, showing the text of a C64 Basic program&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/16/getting-the-formatting.html</link>
      <pubDate>Sat, 16 Dec 2023 14:44:36 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/16/getting-the-formatting.html</guid>
      <description>&lt;p&gt;Getting the formatting in a source code list right takes a lot of time and effort, if you&amp;rsquo;re doing it by hand. I guess I should just write about writing source code instead of showing it. Yeah, I know, the common saying is &amp;ldquo;show, don&amp;rsquo;t tell&amp;rdquo;, but showing is exhausting. Maybe I need a GitHub account.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Getting a foothold into 6502 machine language, part 4</title>
      <link>https://renevanbelzen.micro.blog/2023/12/16/getting-a-foothold.html</link>
      <pubDate>Sat, 16 Dec 2023 14:19:49 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/16/getting-a-foothold.html</guid>
      <description>&lt;p&gt;Yeah, I know, I know. I promised a completed function to test if a number is prime. However, I want to write an article a day, and there&amp;rsquo;s only so much one can code in a day. This time I used code by other programmers, because, you know, I&amp;rsquo;m a novice. I did, however, try to understand the code, so I could rewrite where it was needed.&lt;/p&gt;
&lt;p&gt;[
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/13/getting-a-foothold.html&#34;&gt;part 1&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/14/getting-a-foothold.html&#34;&gt;part 2&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/15/getting-a-foothold.html&#34;&gt;part 3&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/17/getting-a-foothold.html&#34;&gt;part 5&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/19/getting-a-foothold.html&#34;&gt;bonus&lt;/a&gt;
]&lt;/p&gt;
&lt;p&gt;As established in part 3, we need two functions, one to square a number and one to take the modulo between two numbers. These will be the subjects of today&amp;rsquo;s article. I will analyze the original code, rewrite it, and test it with a Basic program, containing a machine code loader in data statements.&lt;/p&gt;
&lt;p&gt;Here we go!&lt;/p&gt;
&lt;h2 id=&#34;binary-division-and-the-binary-square&#34;&gt;Binary division and the binary square&lt;/h2&gt;
&lt;p&gt;Suppose we wanted a 16-bit unsigned number to be divided by a non-zero 8-bit number to obtain its quotient and remainder. We are particularly interested in the remainder, since it&amp;rsquo;s the result of the modulo operation &lt;code&gt;dividend mod divisor&lt;/code&gt;, and we need it for checking divisibility (true if the remainder of a division is zero, otherwise false).&lt;/p&gt;
&lt;p&gt;On the website LLX.com about the Apple II, I found an article called &lt;a href=&#34;https://www.llx.com/Neil/a2/mult.html&#34;&gt;Multiplying and Dividing on the 6502&lt;/a&gt;, written by Neil Parker. In the section &amp;ldquo;Dividing Arbitrary Numbers&amp;rdquo; it gets interesting for our purposes (modulo).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;We will shift the bits of the dividend, one at a time, into a work area, and then try subtracting the divisor from the work area. If the subtraction succeeded, we replace the work area with the result of the subtraction and record a 1 bit in the quotient. If the subtraction failed, we discard its result and record a 0 bit in the quotient. The process is repeated until all bits of the dividend are used up.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Here are the steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;clear the remainder&lt;/li&gt;
&lt;li&gt;set the bit counter to 16&lt;/li&gt;
&lt;li&gt;shift the dividend to the left into the remainder&lt;/li&gt;
&lt;li&gt;trial subtract the divisor from the remainder&lt;/li&gt;
&lt;li&gt;was there a borrow (negative result), then step 8&lt;/li&gt;
&lt;li&gt;store the result in remainder&lt;/li&gt;
&lt;li&gt;increment the dividend (quotient)&lt;/li&gt;
&lt;li&gt;decrement bit counter&lt;/li&gt;
&lt;li&gt;if bit counter not zero, then step 3&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;There are three 16-bit registers, remainder, dividend and divisor. After exiting the routine, the dividend has become the quotient.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
            LDA #0      ;Initialize REM to 0
            STA REM
            STA REM+1
            LDX #16     ;There are 16 bits in NUM1
    L1      ASL NUM1    ;Shift hi bit of NUM1 into REM
            ROL NUM1+1  ;(vacating the lo bit, which will be used for the quotient)
            ROL REM
            ROL REM+1
            LDA REM
            SEC         ;Trial subtraction
            SBC NUM2
            TAY
            LDA REM+1
            SBC NUM2+1
            BCC L2      ;Did subtraction succeed?
            STA REM+1   ;If yes, save it
            STY REM
            INC NUM1    ;and record a 1 in the quotient
    L2      DEX
            BNE L1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since we aren&amp;rsquo;t interested in the quotient, just the remainder, we can eliminate the &lt;code&gt;INC NUM1&lt;/code&gt;  the listing above. The divisor is smaller than 256, so an 8-bit version will do. We still need to go through 16 bits, though. We can set &lt;code&gt;NUM2+1&lt;/code&gt; in Neil&amp;rsquo;s listing above to zero, by replacing &lt;code&gt;SBC NUM2+1&lt;/code&gt; with &lt;code&gt;SBC #$00&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the new routine, I call &amp;ldquo;modulo&amp;rdquo;. For testing it in basic with a &lt;code&gt;SYS&lt;/code&gt; command, I&amp;rsquo;ll use the freely available zero page addresses $FA through $FE to store the values. We start by POKEing the dividend in locations 250 and 251 (lo/hi bytes) and the divisor in location 252. The result will be in locations 253 and 254 (lo/hi bytes).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
; modulo.asm

; Calculate the modulo of an 8-bit number with a 16-bit number.
; Destroys all registers.

        num1 = $fa      ; 16-bit dividend
        num2 = $fc      ; 8-bit divisor
        rem = $fd       ; 16-bit remainder

        *=$c000         ; can be called from Basic with SYS 49152

modulo:
        lda #$00        ; clear remainder
        sta rem
        sta rem+1
        ldx #16         ; do 16 bits
modloop:
        asl num1        ; shift num1 to the left
        rol num1+1
        rol rem         ; into remainder
        rol rem+1
        sec
        lda rem         ; do trial subtraction
        sbc num2        ; with divisor
        tay
        lda rem+1
        sbc #$00        ; divisor is 8-bit value
        bcc modskip     ; was there a borrow, then next bit
        sta rem+1       ; save the result
        sty rem
modskip:
        dex             ; repeat for 16 bits
        bne modloop
        rts
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&amp;rsquo;s my test program, called &amp;ldquo;testmod 0.1&amp;rdquo;. It contains the converted hexdump from the &lt;a href=&#34;https://www.masswerk.at/6502/assembler.html&#34;&gt;Virtual 6502 Assembler&lt;/a&gt; after pasting in the above source listing &amp;ldquo;modulo.asm&amp;rdquo;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
10 rem testmod 0.1
20 forn=49152to49187:readb:poken,b:next:rem read in machine code
30 data 169,000,133,253,133,254,162,016
31 data 006,250,038,251,038,253,038,254
32 data 165,253,056,229,252,168,165,254
33 data 233,000,144,004,133,254,132,253
34 data 202,208,229,096
40 input &#34;dividend&#34;;dd
50 input &#34;divisor&#34;;dv
60 poke 251, int(dd/256):poke 250,dd-256*peek(251): rem poke dividend to memory
70 poke 252,dv:rem poke divisor to memory
80 sys 49152
90 rm=peek(253)+256*peek(254)
100 print &#34;remainder is&#34;;rm
110 print &#34;press any key to repeat&#34;
120 poke 198,0:wait 198,1:poke 198,0:goto 40
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is some input and output I created in the C64 Basic interpreter of the V.I.C.E. C64 emulator on my Raspberry Pi-400, running Raspberry Pi OS.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
run
dividend? 61
divisor? 3
remainder is 1
press any key to repeat
dividend?  65535
divisor? 16
remainder is 15
press any key to repeat
dividend?  17
divisor? 4
remainder is 1
press any key to repeat

break in 120
ready.
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;It seems to work, nice job, me 😊&lt;/p&gt;
&lt;p&gt;The same article on the site LLX.com mentions how to do multiplication, but what we need is a square function (a number multiplied by itself). So I found another resource on 6502.org, called &lt;a href=&#34;http://www.6502.org/source/integers/square.htm&#34;&gt;Square Calculator&lt;/a&gt; and was written by by Lee Davison. It deals with signed integers, but we only need unsigned 8-bit integers, so there&amp;rsquo;s probably some rewriting to do, simplifying the code.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the full listing.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
; Calculates the 16 bit unsigned integer square of the signed 16 bit integer in
; Numberl/Numberh.  The result is always in the range 0 to 65025 and is held in
; Squarel/Squareh
;
; The maximum input range is only +/-255 and no checking is done to ensure that
; this is so.
;
; This routine is useful if you are trying to draw circles as for any circle
;
; x^2+y^2=r^2 where x and y are the co-ordinates of any point on the circle and
; r is the circle radius
;
; Destroys all registers
    
    *= 8000                     ; these must be in RAM
    
    Numberl                     ; number to square low byte
    Numberh = Numberl+1         ; number to square high byte
        .word $FFFF
    
    Squarel                     ; square low byte
    Squareh = Squarel+1         ; square high byte
        .word $FFFF
    
    Tempsq:                     ; temp byte for intermediate result
        .byte $00
    
    *= 8192                     ; any address will do
    
    Square:
            LDA #$00            ; clear A
            STA Squarel         ; clear square low byte
                                ; (no need to clear the high byte, it gets
                                ; shifted out)
            LDA Numberl         ; get number low byte
            LDX Numberh         ; get number high  byte
            BPL NoNneg          ; if +ve don&#39;t negate it
                                ; else do a two&#39;s complement
            EOR #$FF            ; invert
            SEC                 ; +1
            ADC #$00            ; and add it
    
    NoNneg:
            STA Tempsq          ; save ABS(number)
            LDX #$08            ; set bit count
    
    Nextr2bit:
            ASL Squarel         ; low byte *2
            ROL Squareh         ; high byte *2+carry from low
            ASL A               ; shift number byte
            BCC NoSqadd         ; don&#39;t do add if C = 0
            TAY                 ; save A
            CLC                 ; clear carry for add
            LDA Tempsq          ; get number
            ADC Squarel         ; add number^2 low byte
            STA Squarel         ; save number^2 low byte
            LDA #$00            ; clear A
            ADC Squareh         ; add number^2 high byte
            STA Squareh         ; save number^2 high byte
            TYA                 ; get A back
    
    NoSqadd:
            DEX                 ; decrement bit count
            BNE Nextr2bit       ; go do next bit
            RTS
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I like the coding practices of this author. The source code is easy to read and to the point.&lt;/p&gt;
&lt;p&gt;After modifying Lee&amp;rsquo;s excellent source code listing, I came up with this listing, called &amp;ldquo;square.asm&amp;rdquo;. It squares an 8-bit unsigned integer into a 16-bit unsigned integer. Since I wanted to test it in Basic, I used the zero page addresses $FA through $FD, that are unused by the OS.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
; square.asm
;
; Calculates the 16-bit unsigned square of an 8-bit unsigned integer.
; Destroys all registers.

        number = $fa            ; 8-bit number to be squared

        squarel = $fb           ; 16-bit squared number
        squareh = squarel+1

        tempsq = $fd            ; temporary storage of original number

        *=$c000                 ; can be called from Basic with SYS 49152

        square:
                lda #$00        ; clear A
                sta squarel     ; clear square low byte
                                ; (no need to clear the high byte,
                                ; it gets shifted out)
                lda number      ; get number in .A
                sta tempsq      ; save original for later use
                ldx #$08        ; 8 bits to process
        sqloop:
                asl squarel     ; shift square to left
                rol squareh     ; (i.e. multiply by 2)
                asl a           ; get next highest bit of number
                bcc sqnoadd     ; don&#39;t do add if carry is zero
                tay             ; save .A for later use
                clc
                lda tempsq      ; add original number value
                adc squarel     ; to square
                sta squarel
                lda #$00        ; add a possible carry
                adc squareh     ; to the high byte of square
                sta squareh
                tya             ; get .A back
        sqnoadd:
                dex             ; decrement bit counter
                bne sqloop      ; go do next bit
                rts
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, I assembled the assembly listing into a hexdump, pasting it into the source code field of the &lt;a href=&#34;https://www.masswerk.at/6502/assembler.html&#34;&gt;Virtual 6502 Assembler&lt;/a&gt;. I converted the hexdump into data statements for the following Basic program, called &amp;ldquo;tsquare 0.1&amp;rdquo;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
0 rem tsquare 0.1
10 forn=49152to49187:readb:poken,b:next:rem read in machine code
20 data 169,000,133,251,165,250,133,253
21 data 162,008,006,251,038,252,010,144
22 data 015,168,024,165,253,101,251,133
23 data 251,169,000,101,252,133,252,152
24 data 202,208,231,096
30 input &#34;number&#34;;n
40 poke 250,n
50 sys 49152
60 s = peek(251)+256*peek(252)
70 print &#34;square is&#34;;s
80 print &#34;press any key to repeat&#34;
90 poke 198,0:wait 198,1:poke 198,0:goto 30
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&amp;rsquo;s some values I tried:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
run
number? 2
square is 4
press any key to repeat
number? 5
square is 25
press any key to repeat
number? 49
square is 2401
press any key to repeat
number? 255
square is 65025
press any key to repeat
number? 0
square is 0
press any key to repeat

break in 90
ready.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I love when code works at first attempt. Of course, I had lots of help from people from the past. Still, it&amp;rsquo;s satisfying if things work as they should.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/16/reading-through-assembly.html</link>
      <pubDate>Sat, 16 Dec 2023 11:46:38 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/16/reading-through-assembly.html</guid>
      <description>&lt;p&gt;Reading through 6502 assembly code listings for my current article on assembly programming on the C64, I can see there&amp;rsquo;s an art to writing clear and easy-to-read code. Some are better at it than others. I suppose I should &amp;ldquo;steal&amp;rdquo; some of those practices (read: make them my own).&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Getting a foothold into 6502 machine language, part 3</title>
      <link>https://renevanbelzen.micro.blog/2023/12/15/getting-a-foothold.html</link>
      <pubDate>Fri, 15 Dec 2023 19:13:58 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/15/getting-a-foothold.html</guid>
      <description>&lt;p&gt;This should get more interesting than the previous two parts. We want a &lt;code&gt;usr&lt;/code&gt; function that tests if a number between 0 and 65535, inclusive, is a prime number. We expect an a result of this &lt;code&gt;usr&lt;/code&gt; function either a &lt;code&gt;-1&lt;/code&gt; (true) or a &lt;code&gt;0&lt;/code&gt; (false). I really should split this whole thing into four parts to keep it somewhat manageable (for those who follow along):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;thinking about the problem&lt;/li&gt;
&lt;li&gt;formulating a rough algorithm in words&lt;/li&gt;
&lt;li&gt;formulating an assembly language routine&lt;/li&gt;
&lt;li&gt;testing an confirming if the code is correct&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;[
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/13/getting-a-foothold.html&#34;&gt;part 1&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/14/getting-a-foothold.html&#34;&gt;part 2&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/16/getting-a-foothold.html&#34;&gt;part 4&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/17/getting-a-foothold.html&#34;&gt;part 5&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/19/getting-a-foothold.html&#34;&gt;bonus&lt;/a&gt;
]&lt;/p&gt;
&lt;p&gt;As for the assembly language routine, I will limit myself in this part to a generator of possible prime numbers. I can use this generator to test primality of a number that was input through the &lt;code&gt;usr&lt;/code&gt; function in Basic. But since I wanted to finish this article in a day, the completed function will have to wait until part 4.&lt;/p&gt;
&lt;p&gt;Coding correctly takes time, after all.&lt;/p&gt;
&lt;h2 id=&#34;some-logical-reasoning-about-a-prime-number-sieve-algorithm&#34;&gt;Some logical reasoning about a prime number sieve algorithm&lt;/h2&gt;
&lt;p&gt;Using the &lt;a href=&#34;https://www.geeksforgeeks.org/prime-numbers/&#34;&gt;article on Geeks for Geeks&lt;/a&gt; on prime numbers, I did some simple logical reasoning to determine an algorithm to find out whether or not a number is prime. We can easily generate prime numbers between 2 and 43, inclusive. This means we can quickly test a number&amp;rsquo;s primality up to the value 1850. After that, we need to use the formula &lt;code&gt;6 * n ± 1&lt;/code&gt; for values of &lt;code&gt;n&lt;/code&gt; larger than 7 thereafter, though not all of those are primes.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a prime number is a whole number larger than one that is only divisible by one and itself.&lt;/li&gt;
&lt;li&gt;the number 2 is the only even prime number&lt;/li&gt;
&lt;li&gt;the number 3 is the lowest odd prime number&lt;/li&gt;
&lt;li&gt;the number 5 is the one but lowest odd prime number&lt;/li&gt;
&lt;li&gt;the number 7 is the two but lowest odd prime number, and also the lowest consecutive odd number larger than 1 that is prime&lt;/li&gt;
&lt;li&gt;any odd number not divisible by either 2, nor 3 is a candidate prime number, meaning any candidate prime number larger than 3 is of the formula:&lt;br&gt;… &lt;code&gt;6 * n - 1&lt;/code&gt;, or&lt;br&gt;… &lt;code&gt;6 * n + 1&lt;/code&gt;,&lt;br&gt;… with &lt;code&gt;n&lt;/code&gt; equal to a whole positive number&lt;br&gt;… after having tested for the values 2, 3, 5, and 7, &lt;code&gt;n&lt;/code&gt; must be a whole number larger than one&lt;/li&gt;
&lt;li&gt;a non-prime is the product of two primes, and the largest possible product of two primes that is equal to a non-prime is the square of a prime, in other words, if a number isn&amp;rsquo;t divisible by prime numbers that are less than or equal to the square root of that number, that number is prime, in yet other words:&lt;br&gt;… when testing a number for divisibility by primes, then highest possible prime number to test for is:&lt;br&gt;… &lt;code&gt;p &amp;lt;= sqrt(n)&lt;/code&gt;, where&lt;br&gt;… &lt;code&gt;p&lt;/code&gt; is a prime number and &lt;code&gt;n&lt;/code&gt; is the number to be tested for primality&lt;/li&gt;
&lt;li&gt;since 7 is the lowest consecutive odd prime, we can determine the highest value of &lt;code&gt;n&lt;/code&gt; that  gives a number that is always prime, never a non-prime&lt;br&gt;… &lt;code&gt;(6 * n - 1 &amp;lt; 7 * 7)&lt;/code&gt; or &lt;code&gt;(6 * n + 1 &amp;lt; 7 * 7)&lt;/code&gt;,&lt;br&gt;… &lt;code&gt;(n &amp;lt; (7 * 7 + 1) / 6)&lt;/code&gt; or &lt;code&gt;(n &amp;lt; (7 * 7 - 1) / 6)&lt;/code&gt;&lt;br&gt;… &lt;code&gt;n &amp;lt; 8&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;summarizing (some of) the above, primes between 2 and 43 can be determined by being equal to:&lt;br&gt;… &lt;code&gt;2, 3, 5, 7&lt;/code&gt;&lt;br&gt;… or calculated as:&lt;br&gt;… &lt;code&gt;6 * n - 1&lt;/code&gt;, &lt;code&gt;6 * n + 1&lt;/code&gt; for &lt;code&gt;1 &amp;lt; n &amp;lt; 8&lt;/code&gt;&lt;br&gt;… the lowest non-prime that can&amp;rsquo;t be easily determined by using these primes is an odd number larger than the square of 43, which is 1851.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;an-algorithm-for-testing-primality&#34;&gt;An algorithm for testing primality&lt;/h2&gt;
&lt;p&gt;So, up to a value of 1850 we can generate primes to test if a number is prime. For higher numbers we can only generate possible primes, though that isn&amp;rsquo;t a problem, since if a number is divisible by a product of primes, it isn&amp;rsquo;t prime either. It would be nice, though, to have a method to eliminate some of the non-primes to test with. The article on Geeks for Geeks mentions some additional methods to do just that. However, let us first use what is somewhat easy to understand, without a degree in mathematics.&lt;/p&gt;
&lt;p&gt;As a first approach, using the &lt;code&gt;6 * n ± 1&lt;/code&gt; formula to generate primes to test with is a solid method. We need a &amp;ldquo;next prime&amp;rdquo; function, where the input value &lt;code&gt;k&lt;/code&gt;   determines the k-th prime, with &lt;code&gt;k &amp;gt;= 0&lt;/code&gt;. For primes up to 43 we can simply test if a number is equal to the output of this function, since every output number is a prime. However, we only have to test for primes which square values are smaller than the number that is being tested.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;clear primality flag (assume it&amp;rsquo;s not a prime)&lt;/li&gt;
&lt;li&gt;endless loop
&lt;ul&gt;
&lt;li&gt;fetch next prime&lt;/li&gt;
&lt;li&gt;if &lt;code&gt;number &amp;lt; prime * prime&lt;/code&gt; then exit loop&lt;/li&gt;
&lt;li&gt;if &lt;code&gt;number == prime&lt;/code&gt; then set primality flag, exit loop&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;return primality flag&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If a prime number from the prime number generator function becomes larger than 43, we must stop testing for equality (since the value that is output isn&amp;rsquo;t necessarily prime), and start testing for divisibility instead. We want it to be tested as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;set primality flag (assume it&amp;rsquo;s a prime)&lt;/li&gt;
&lt;li&gt;endless loop
&lt;ul&gt;
&lt;li&gt;fetch next prime&lt;/li&gt;
&lt;li&gt;if &lt;code&gt;number &amp;lt; prime * prime&lt;/code&gt; then exit loop&lt;/li&gt;
&lt;li&gt;if &lt;code&gt;number mod prime == 0&lt;/code&gt;  then it&amp;rsquo;s no prime, exit loop&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;return primality flag&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To distinguish between the two:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;if &lt;code&gt;number &amp;lt;= 43&lt;/code&gt; then compare with primes, else test with &amp;ldquo;primes&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;putting-it-all-together&#34;&gt;Putting it all together&lt;/h2&gt;
&lt;p&gt;Time to fetch the code editor and start mashing keys.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s first test our prime number generator. It has to output a whole positive number based on a whole non-negative number input. However, remember that we only have a function in ROM to output a signed integer, so we have to convert our unsigned integer to a signed one, and convert it back to an unsigned integer in Basic, by subtracting and adding 32768, respectively.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;*= $c000

; usrfunction 0.3
; generate a candidate prime number, 
;     based on the 16-bit unsigned integer input, 
;     representing the order of the prime
; output the prime number as a signed 16-bit integer
;     to work around the limitation of the Basic ROM
;     (there&#39;s no function to convert a unsigned integer 
;      into a real number)
;     in basic, add 32768 to the output of the usr function
; for example (ignoring that the output is signed)
;     prime(0) = 2
;     prime(1) = 3
;     prime(2) = 5
; etc.

getadr = $b7f7
givayf = $b391
fac1int = $64
fac2int = $66
        jsr getadr      ;convert real into unsigned int in .A and .Y (hi/lo)
        jsr prime       ;generate the nth prime
        sec
        sbc #%10000000  ;subtract $8000 (32678) to make it a signed integer
        jmp givayf      ;make it real and return to Basic

prime:
        ;generate the nth prime number
        ;input  .A and .Y as hi/lo byte of 16-bit unsigned integer
        ;       indicating the order of the prime
        ;output .A and .Y as hi/lo byte of 16-bit unsigned integer
        ;       containing the nth prime number on the number line
        ;e.g. prime(0) -&gt; 2, prime(1) -&gt; 3, prime(2) -&gt; 5, etc.
        ;only numbers generated up to 43 are guaranteed prime,
        ;    larger numbers may be prime, 
        ;    or co-prime (product of 2 or more primes)
        cmp #0
        bne prime2      ;order is too big, skip 0 and 1
        cpy #0          ;order == 0?
        bne prime1      ;no, check for 1
        ldy #2          ;prime(0) = 2
        rts
prime1:
        cpy #1          ;order == 1?
        bne prime2      ;no, check for 2 and up
        ldy #3          ;prime(1) = 3
        rts
prime2:
        ;calculate primes for (order &gt; 1)
        ;in the formula (6 * n ± 1), where n is equal to (order / 2),
        lsr             ;n = (order / 2)
        sta fac1int
        tya
        ror             
        sta fac1int+1
        asl fac1int+1   ;k = n * 2 
        rol fac1int
        lda fac1int     ;m = n * 2
        ldx fac1int+1
        sta fac2int
        stx fac2int+1
        asl fac2int+1   ;m = n * 4
        rol fac2int
        clc             ;add m to k, to get (6 * n)
        lda fac1int+1
        adc fac2int+1
        sta fac1int+1
        lda fac1int
        adc fac2int
        sta fac1int
        tya             ;retrieve original lo byte of order
        and #1          ;is it odd?
        cmp #1
        beq prime3      ;then add 1 to (6 * n)
        sec             ;else subtract 1 from (6 * n)
        lda fac1int+1
        sbc #1
        tay             ;lo byte of ((6 * n) - 1) in .Y
        lda fac1int
        sbc #0          ;hi byte of ((6 * n) - 1) in .A
        rts
prime3:
        clc             ;add 1 to (6 * n)
        lda fac1int+1
        adc #1
        tay             ;lo byte of ((6 * n) + 1) in .Y
        lda fac1int
        adc #0          ;hi byte of ((6 * n) + 1) in .A
        rts&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;give-our-code-a-spin-testing-its-validity&#34;&gt;Give our code a spin, testing its validity&lt;/h2&gt;
&lt;p&gt;I pasted the source code into &lt;a href=&#34;https://www.masswerk.at/6502/assembler.html&#34;&gt;Virtual 6502 Assembler&lt;/a&gt;, copied the hexdump, and converted with a calculator app into decimal values of data statements in the Basic program &amp;ldquo;testusrf 0.3&amp;rdquo; below.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0 rem testusrf 0.3
10 poke 785,0:poke 786,192:rem set usr address to $c000
20 forn=49152to49246:readb:poken,b:next:rem read in machine code
30 data 032,247,183,032,012,192,056,233
31 data 128,076,145,179,201,000,208,014
32 data 192,000,208,003,160,002,096,192
33 data 001,208,003,160,003,096,074,133
34 data 100,152,106,133,101,006,101,038
35 data 100,165,100,166,101,133,102,134
36 data 103,006,103,038,102,024,165,101
37 data 101,103,133,101,165,100,101,102
38 data 133,100,152,041,001,201,001,240
39 data 011,056,165,101,233,001,168,165
40 data 100,233,000,096,024,165,101,105
41 data 001,168,165,100,105,000,096
50 for x = 0 to 9:gosub 100:next
99 end
100 print &#34;x =&#34;;x;&#34;, usr(x) =&#34;;usr(x)+32768:return&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Running this program for the first 100 &amp;ldquo;primes&amp;rdquo; gave this output:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;list 50

50 for x=00000 to 00099:gosub 100:next

ready.
run
 2  3  5  7  11  13  17  19  23  25  29
 31  35  37  41  43  47  49  53  55  59
 61  65  67  71  73  77  79  83  85  89
 91  95  97  101  103  107  109  113  11
5  119  121  125  127  131  133  137  13
9  143  145  149  151  155  157  161  16
3  167  169  173  175  179  181  185  18
7  191  193  197  199  203  205  209  21
1  215  217  221  223  227  229  233  23
5  239  241  245  247  251  253  257  25
9  263  265  269  271  275  277  281  28
3  287  289  293  295
ready.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I noticed this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;print usr(21845)+32768,usr(21846)+32768
 65533     1

ready.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is because the prime number generator doesn&amp;rsquo;t check for any value overflow. The value &lt;code&gt;1&lt;/code&gt; is actually the value &lt;code&gt;65537&lt;/code&gt;, but the 17th bit of the latter number doesn&amp;rsquo;t exist, so the value wraps around to &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;print (65533 - 1)/6
 10922

ready.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So the prime function gives valid answers up to the 10922th prime, which is more than enough to test if the largest 16-bit unsigned value (65535) is prime. For that we need at most a prime of the square root of that value, which is slightly less than 256. These &amp;ldquo;primes&amp;rdquo; are already visible in the first 100 &amp;ldquo;primes&amp;rdquo;.&lt;/p&gt;
&lt;h1 id=&#34;did-i-do-it-right&#34;&gt;Did I do it right?&lt;/h1&gt;
&lt;p&gt;To check, you can compare the output of the prime number generator with the &lt;a href=&#34;https://en.wikipedia.org/wiki/List_of_prime_numbers&#34;&gt;List of Prime Numbers&lt;/a&gt; on Wikipedia. We are only concerned with primes less than 256, since it&amp;rsquo;s the square root of the value 65536. 65536 is already higher than the maximal value of a 16-bit unsigned integer number (65535). To speed things up, we could&amp;rsquo;ve just as well hard-coded the list of 54 primes that are less than 256. The routine would need more bytes, though.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
2   3 	5   7   11  13  17  19  23  29
31  37 	41  43  47  53  59  61  67  71
73  79 	83  89  97  101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The prime numbers from the Wikipedia page are all included in the output of &amp;ldquo;testusrf 0.3&amp;rdquo; in the listing above. The prime generator does output some extra (non-prime) numbers, that don&amp;rsquo;t do any harm when testing for primality.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Getting a foothold into 6502 machine language, part 2</title>
      <link>https://renevanbelzen.micro.blog/2023/12/14/getting-a-foothold.html</link>
      <pubDate>Thu, 14 Dec 2023 16:00:40 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/14/getting-a-foothold.html</guid>
      <description>&lt;p&gt;I mentioned in part 1 that there&amp;rsquo;s a convenient routine to convert a real number into a signed 16-bit integer. However, Basic line numbers are 16-bit unsigned numbers when parsed into Basic code. So there has to be a routine to turn a real value in &lt;strong&gt;fac1&lt;/strong&gt; into a 16-bit integer as part of the interpretation of Basic text that starts with a line number.&lt;/p&gt;
&lt;p&gt;[
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/13/getting-a-foothold.html&#34;&gt;part 1&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/15/getting-a-foothold.html&#34;&gt;part 3&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/16/getting-a-foothold.html&#34;&gt;part 4&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/17/getting-a-foothold.html&#34;&gt;part 5&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/19/getting-a-foothold.html&#34;&gt;bonus&lt;/a&gt;
]&lt;/p&gt;
&lt;p&gt;And indeed there is. It is called &lt;strong&gt;getadr&lt;/strong&gt; and is located at $b7f7. It supposedly is to turn a real value between zero and 65536 into a 16-bit unsigned integer. For both values the floating point accumulator &lt;strong&gt;fac1&lt;/strong&gt; is used. The resulting integer value is stored in locations $64 and $65 of &lt;strong&gt;fac1&lt;/strong&gt;, high byte first.&lt;/p&gt;
&lt;p&gt;Since the &lt;code&gt;usr&lt;/code&gt; machine language routine stores the function value entered in Basic into &lt;strong&gt;fac1&lt;/strong&gt; as a real number, the next steps should be easy:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;call &lt;strong&gt;getadr&lt;/strong&gt; ($b7f7) to convert a real into a unsigned 16-bit integer&lt;/li&gt;
&lt;li&gt;read $64 in .A and $65 in .Y, both part of &lt;strong&gt;fac1&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;process the integer&lt;/em&gt; into a value stored in .A and .Y&lt;/li&gt;
&lt;li&gt;subtract 32768 to convert the unsigned integer into a signed integer value between -32768 and 32767, which &lt;strong&gt;givayf&lt;/strong&gt; needs&lt;/li&gt;
&lt;li&gt;turn .A and .Y into a real, by calling the &lt;strong&gt;givayf&lt;/strong&gt; ($b391) routine&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To not over-complicate things at this point, we should interpret the &amp;ldquo;process the integer&amp;rdquo; as &amp;ldquo;do nothing&amp;rdquo;, effectively skipping the processing step. We will develop our &amp;ldquo;is this number prime&amp;rdquo; routine later. All we want to know if the supplied value between 0 and 65536 is accepted and can be used as such.&lt;/p&gt;
&lt;p&gt;This method is certainly somewhat error-prone (never underestimate the power of typos), because it requires some workaround in Basic to deal with the signed integer value that our &lt;code&gt;usr&lt;/code&gt; machine language routine returns to Basic.&lt;/p&gt;
&lt;p&gt;After entering the source code in the assembly listing &amp;ldquo;usrfunction 0.2&amp;rdquo;, I copied the hexdump from &lt;a href=&#34;https://www.masswerk.at/6502/assembler.html&#34;&gt;Virtual 6502 Assembler&lt;/a&gt; and wrote the Basic program &amp;ldquo;testusrf 0.2&amp;rdquo; in the next listing to see if I got it right. This was what I wanted to test:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;boundaries 0 and 65535&lt;/li&gt;
&lt;li&gt;fractional numbers between 0 and 65536, exclusive—use a few values of the expression &lt;code&gt;65536*rnd(ti)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;errors with numbers that are &amp;lt; 0 or &amp;gt;= 65536 (use -1 and 65536)&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;*= $c000

; usrfunction 0.2
; use an unsigned integer
; and, for now, do nothing with it

getadr = $b7f7
givayf = $b391
fac1int = $64

        jsr getadr      ;convert real into unsigned int
        lda fac1int     ;load high byte in .A
        ldy fac1int+1   ;load low byte in .Y
        nop             ;do nothing for now
        sec
        sbc #%10000000  ;subtract $8000 (32678) to make it a signed integer
        jmp givayf      ;make it real and return to Basic&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;0 rem testusrf 0.2
10 poke 785,0:poke 786,192:rem set usr address to $c000
20 forn=49152to49165:readb:poken,b:next:rem read in machine code
30 data 32,247,183,165,100,164,101,234
40 data 56,233,128,76,145,179
70 x=0:gosub 100
80 x=65535:gosub 100
90 for i=0 to 9:x=rnd(ti)*65536:gosub 100:next
99 end
100 print &#34;x =&#34;;x;&#34;, usr(x) =&#34;;usr(x)+32768:return&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the output of that Basic program, with two values entered by hand, which should throw error messages:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;run
x = 0 , usr(x) = 0
x = 65535 , usr(x) = 65535
x = 12161.1233 , usr(x) = 12161
x = 3073.54893 , usr(x) = 3073
x = 54247.0177 , usr(x) = 54247
x = 36356.0453 , usr(x) = 36356
x = 58801.1164 , usr(x) = 58801
x = 37546.6392 , usr(x) = 37546
x = 54977.7024 , usr(x) = 54977
x = 61029.0648 , usr(x) = 61029
x = 12345.8034 , usr(x) = 12345
x = 63762.592 , usr(x) = 63762

ready.
?usr(-1)

?illegal quantity  error
ready.
?usr(65536)

?illegal quantity  error
ready.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It worked, which is always a relief.&lt;/p&gt;
&lt;p&gt;Now the routine we want (&amp;ldquo;is this number prime?&amp;quot;) doesn&amp;rsquo;t have to result into an unsigned 16-bit value. We only want to be able to input such a value. The output we expect is either a &amp;ldquo;Yes&amp;rdquo; (-1) or &amp;ldquo;No&amp;rdquo; (0). So a signed 16-bit integer is exactly what we need.&lt;/p&gt;
&lt;p&gt;So why did I do this workaround? I wanted to know if it is at all possible to work around this limitation, in case I ever needed that. It certainly is, as the Basic example shows.&lt;/p&gt;
&lt;p&gt;In part 3 I will (finally) start coding for the question whether or not the supplied number is a prime number. This should be interesting.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Getting a foothold into 6502 machine language, part 1</title>
      <link>https://renevanbelzen.micro.blog/2023/12/13/getting-a-foothold.html</link>
      <pubDate>Wed, 13 Dec 2023 20:43:13 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/13/getting-a-foothold.html</guid>
      <description>&lt;p&gt;It seems in Commodore Basic version 2 the preferred way to get a value into a user-defined 6502 machine language routine (and to get a value back), is the &lt;code&gt;usr&lt;/code&gt; function. It took me some trial and error to get it to work. Luckily, Google is Your Friend, or, in my case DuckDuckGo. I also used &amp;ldquo;Mapping the Commodore 64&amp;rdquo;, by Sheldon Leemon, which can be downloaded as PDF on Archive.org. If you&amp;rsquo;re serious about 6502 assembly language on the Commodore 64, I highly recommend this book.&lt;/p&gt;
&lt;p&gt;[
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/14/getting-a-foothold.html&#34;&gt;part 2&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/15/getting-a-foothold.html&#34;&gt;part 3&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/16/getting-a-foothold.html&#34;&gt;part 4&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/17/getting-a-foothold.html&#34;&gt;part 5&lt;/a&gt; |
&lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/19/getting-a-foothold.html&#34;&gt;bonus&lt;/a&gt;
]&lt;/p&gt;
&lt;p&gt;First of all, how do we get the &lt;code&gt;usr&lt;/code&gt; function to work? Simply running &lt;code&gt;print usr(42)&lt;/code&gt; results in an error message.&lt;/p&gt;
&lt;p&gt;Apparently, one has to set the address of the start of one&amp;rsquo;s own machine language routine. After (re)booting the operating system the value is set to $b248 (&lt;strong&gt;fcerr&lt;/strong&gt; routine, which prints an &lt;code&gt;illegal quantity&lt;/code&gt; error). Taking a step back, the final step of the routine in Basic ROM that interprets the &lt;code&gt;usr&lt;/code&gt; function is jumping to address $0310 in RAM:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0310  4c 48 b2    jmp $b248&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So all one has to do is overwrite the address of this &lt;code&gt;jmp&lt;/code&gt; instruction so it points to the user defined machine language routine. This address is located at $311 and $312, in the usual low byte high byte order of the 6502 machine language. If the user defined routine is, for example, located at $c000 (49152), the values $00 and $c0 have to be written in $311 and $312, respectively.&lt;/p&gt;
&lt;p&gt;In Basic we use decimal instead of hexadecimal:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$311 is 785 decimal&lt;/li&gt;
&lt;li&gt;$312 is 786 decimal&lt;/li&gt;
&lt;li&gt;$c0 is 192 decimal&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code&gt;10 poke 785,0:poke 786,192&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We always have to keep in mind that Commodore Basic uses real values, never integers. The value we supplied to the &lt;code&gt;usr&lt;/code&gt; function in our Basic code is stored into &lt;strong&gt;fac1,&lt;/strong&gt; which consists of six bytes, starting at location $61. Luckily, this isn&amp;rsquo;t all that important here, since there are two handy functions to convert real values back and forth into &lt;em&gt;16-bit signed integer values,&lt;/em&gt; using &lt;strong&gt;fac1.&lt;/strong&gt; They are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$b1aa – Convert a Floating Point Number to a Signed Integer in .A and .Y Registers, which calls the &lt;strong&gt;ayint&lt;/strong&gt; routine (located at $b1bf), and loads the resulting signed 16-bit integer value into registers .Y and .A (lo/hi).&lt;/li&gt;
&lt;li&gt;$b391 – &lt;strong&gt;givayf&lt;/strong&gt; Convert 16-Bit Signed Integer in registers .Y and .A (lo/hi) to a Floating Point Number&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In both instances the registers .Y and .A contain the low byte, and high byte of the 16-bit signed integer, respectively.&lt;/p&gt;
&lt;p&gt;But, wait, what is a &amp;ldquo;16-bit signed integer&amp;rdquo; exactly? Well, in the 6502 architecture, this is the 2&amp;rsquo;s-complement representation of a whole number between -32768 and 32767, inclusive. It simplifies addition and subtraction of whole numbers, either positive, negative, or zero. If you want to know more, read the &lt;a href=&#34;https://en.wikipedia.org/wiki/Two%27s_complement&#34;&gt;relevant Wikipedia article&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The thing is that if you pass a zero or a positive value into the &lt;code&gt;usr&lt;/code&gt; function and convert it into an integer in your machine language routine, it has to be between 0 and 32767, inclusive. If your machine code routine can deal with that restriction, you&amp;rsquo;re okay. Of course, you could use the real value instead, or use some trickery to use integers between 0 and 65535, inclusive. Whatever the routine does exactly is up to you, since you are defining it.&lt;/p&gt;
&lt;p&gt;Perhaps I should give an example of how to &lt;em&gt;use the &lt;code&gt;usr&lt;/code&gt; function in a useful manner&lt;/em&gt; 😉&lt;/p&gt;
&lt;p&gt;What if I wanted to know if a value I put into the &lt;code&gt;usr&lt;/code&gt; function is a prime number, divisible only by itself or one, but no other whole positive number? That is a tricky problem to solve, since the 6502 has no division, nor multiplication instructions built in (it has to be done in software instead, using a set of instructions). Other than that, finding out a whole number is prime isn&amp;rsquo;t straightforward either, at least, if you want the method to be efficient and correct.&lt;/p&gt;
&lt;p&gt;To not reinvent the wheel, I looked for someone who had done the work before, and found &lt;a href=&#34;https://www.geeksforgeeks.org/prime-numbers/&#34;&gt;Geeks For Geeks - Prime Numbers&lt;/a&gt; as a resource. Let&amp;rsquo;s go with that!&lt;/p&gt;
&lt;p&gt;Anyway, the result of our &lt;code&gt;usr&lt;/code&gt; function should be either true or false, which is in Commodore Basic represented by a &lt;code&gt;-1&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt;, respectively:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;print 1=1,1=0
-1         0

ready.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To understand all this, I used a minimal viable solution. My code should test if the value put into the &lt;code&gt;usr&lt;/code&gt; function and converted into a signed integer is even. If so, it should return a &lt;code&gt;-1&lt;/code&gt;, else a &lt;code&gt;0&lt;/code&gt;. We still need to convert the result of parity test into a real number before exiting our routine in 6502 assembly language.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;*= $c000

; usrfunction 0.1
; test if the usr function even works
; as a test, check for even parity

getayf = $b1aa
givayf = $b391

        jsr getayf
        tya               ;lo byte
        and #%00000001    ;mask out every bit except bit 0
        cmp #0
        beq iseven
        lda #$00          ;false, which is 0 in 16-bit signed integer
        tay               ;corresponding to the hex value $0000
        jmp givayf        ;make it real, return to Basic
        iseven:
        lda #$ff          ;true, which is -1 in 16-bit signed integer
        tay               ;corresponding to the hex value $ffff
        jmp givayf        ;make it real, return to Basic&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I wrote this routine in the Textastic app on my iPad, used the &lt;a href=&#34;https://www.masswerk.at/6502/assembler.html&#34;&gt;Virtual 6502 assembler&lt;/a&gt; to create a hex dump, used it to create the Basic program below, typed that into the V.I.C.E. C64 emulator on my Raspberry PI-400 running Raspberry Pi OS, and ran it.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;10 poke 785,0:poke 786,192: rem set usr address to $c000 (49152)
20 forn=49152to49173:readb:poken,b:next:rem read in machine code
30 x=int(rnd(ti)*100):rem random number between 0 and 99, inclusive
40 print x;&#34; is &#34;;
50 if usr(x) then print &#34;even&#34;:goto 70
60 print &#34;odd&#34;
70 data 32,170,177,152,41,1,201,0,240,6
80 data 169,0,168,76,145,179,169,255,168,76,145,179&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It worked. Pfew!&lt;/p&gt;
&lt;p&gt;Now we can tackle more complicated matters, but that has to wait until part 2, because this article is already much longer than I anticipated, and I started to make mistakes. I need a break.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/12/currently-reading-mapping.html</link>
      <pubDate>Tue, 12 Dec 2023 07:56:27 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/12/currently-reading-mapping.html</guid>
      <description>&lt;p&gt;Currently reading: &lt;a href=&#34;https://micro.blog/books/094238623X&#34;&gt;Mapping the Commodore 64&lt;/a&gt; by Sheldon Leemon 📚&lt;/p&gt;
&lt;p&gt;Why would you even want to use the C64, it&amp;rsquo;s an old computer? It isn&amp;rsquo;t old, it&amp;rsquo;s retro!&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-7766.png&#34; width=&#34;150&#34; height=&#34;200&#34; alt=&#34;book cover of Mapping the Commodore 64 by Sheldon Leemon&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/11/i-got-a.html</link>
      <pubDate>Mon, 11 Dec 2023 17:47:02 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/11/i-got-a.html</guid>
      <description>&lt;p&gt;I got a taste of what it is to write a computer program on the C64 (see &lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/11/advent-of-code.html&#34;&gt;here&lt;/a&gt; and &lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/11/172539.html&#34;&gt;here&lt;/a&gt;). For now, that is enough for me, and I&amp;rsquo;ll refrain from doing any more for the Advent of Code. It&amp;rsquo;s just too hardcore for me! I need something less intimidating.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Advent of Code 2023, day 1, part one—Hunting down the bug</title>
      <link>https://renevanbelzen.micro.blog/2023/12/11/172539.html</link>
      <pubDate>Mon, 11 Dec 2023 17:25:39 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/11/172539.html</guid>
      <description>&lt;p&gt;This is a continuation of &lt;a href=&#34;https://renevanbelzen.micro.blog/2023/12/11/advent-of-code.html&#34;&gt;this article&lt;/a&gt; I wrote earlier today.&lt;/p&gt;
&lt;p&gt;There was a bug in my Basic program when calculating the value of the two-digit number:&lt;/p&gt;
&lt;code&gt;
140 p=f+10*l:sm=sm+p:print n,p,sm
&lt;/code&gt;
&lt;p&gt;That should of course be:&lt;/p&gt;
&lt;code&gt;
140 p=f*10+l:sm=sm+p:print n,p,sm
&lt;/code&gt;
&lt;p&gt;After rewriting the code I got this answer:&lt;/p&gt;
&lt;code&gt;
 999 : 33 ,  53194
&lt;/code&gt;
&lt;p&gt;So adding 999 two-digit numbers gave me 53194. Would that be the correct answer?&lt;/p&gt;
&lt;p&gt;Yes!&lt;/p&gt;
&lt;p&gt;What have I learned?&lt;/p&gt;
&lt;p&gt;Always use simple examples to test your algorithm.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/10/so-i-wrote.html</link>
      <pubDate>Sun, 10 Dec 2023 13:03:49 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/10/so-i-wrote.html</guid>
      <description>&lt;p&gt;So I wrote some Commodore 64 assembly code in Textastic on iPad, assembled in an online 6502 assembler, into a .PRG file, and loaded that into the V.I.C.E. C64 emulator. You can see the ML monitor output and the output of the program. Note that clearing the screen isn&amp;rsquo;t needed, simply:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SYS 49176
&lt;/code&gt;&lt;/pre&gt;&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/2023-12-10-random-maze-machine-code-monitor.png&#34; width=&#34;600&#34; height=&#34;453&#34; alt=&#34;random maze machine code monitor in V.I.C.E.&#34;&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/2023-12-10-random-maze-output.png&#34; width=&#34;600&#34; height=&#34;453&#34; alt=&#34;random maze output in V.I.C.E.&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/12/06/my-code-is.html</link>
      <pubDate>Wed, 06 Dec 2023 11:32:25 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/12/06/my-code-is.html</guid>
      <description>&lt;p&gt;My code is almost twice as fast as the original Print Maze routine,&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;10 printchr$(205.5+rnd(1));:goto 10
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;0 d=205.5:fori=.to39:printchr$(d+rnd(.));:next:goto
&lt;/code&gt;&lt;/pre&gt;&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2023/img-3105.jpeg&#34; width=&#34;600&#34; height=&#34;449&#34; alt=&#34;screenshot of Commodore 64 Basic code for a random maze&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2023/10/02/til-apple-tried.html</link>
      <pubDate>Mon, 02 Oct 2023 10:49:04 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2023/10/02/til-apple-tried.html</guid>
      <description>&lt;p&gt;TIL: Apple tried to create their own CPU much earlier than you may know, &lt;a href=&#34;https://www.youtube.com/watch?v=v7dNorB47Qw&#34;&gt;Secret History: Apple&amp;rsquo;s first attempt at making a CPU&lt;/a&gt;, by RetroBytes on YouTube.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/11/29/oooh-fancy-ascii.html</link>
      <pubDate>Tue, 29 Nov 2022 21:51:21 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/11/29/oooh-fancy-ascii.html</guid>
      <description>&lt;p&gt;Oooh 😯 fancy ascii art for the coding aficionados (front end developers) among Flickr users&lt;br&gt;
🔠👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2022/4086c6ad39.jpg&#34; width=&#34;600&#34; height=&#34;388&#34; alt=&#34;html code of page source, showing ascii art&#34;&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/11/20/repeat-in-the.html</link>
      <pubDate>Sun, 20 Nov 2022 07:54:45 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/11/20/repeat-in-the.html</guid>
      <description>&lt;h1 id=&#34;repeat&#34;&gt;Repeat&lt;/h1&gt;
&lt;p&gt;In the olden days we all could still write computer programs to illustrate today&amp;rsquo;s prompt. It isn&amp;rsquo;t old, though, but retro. It was a brief period when one person could still fully grasp every aspect of their computer and create carefree.&lt;br&gt;
🎨🍂✍️👨‍💻&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2022/f4e5697fb6.jpg&#34; alt=&#34;ballpoint sketch of Commodore 64 computer and monitor, displaying basic program and its output from a for-next loop&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/11/11/cathode-ray-tube.html</link>
      <pubDate>Fri, 11 Nov 2022 08:11:49 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/11/11/cathode-ray-tube.html</guid>
      <description>&lt;h1 id=&#34;cathode-ray-tube-display&#34;&gt;Cathode Ray Tube Display&lt;/h1&gt;
&lt;p&gt;As Adrian Black often explains on his retro computer &lt;a href=&#34;https://www.youtube.com/channel/UCE5dIscvDxrb7CD5uiJJOiw&#34;&gt;YouTube channel&lt;/a&gt;, cathode ray tubes are disposables, meaning they wear with use. Either they are dim or don&amp;rsquo;t work at all, but can be revived sometimes, making Adrian exclaim with enthusiasm. &lt;br&gt;
🎨👨‍💻🍂✍️&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2022/6a4c74642e.jpg&#34; alt=&#34;ballpoint sketch of man sitting in front of an Apple II computer with CRT display on top of it&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/11/05/after-having-gone.html</link>
      <pubDate>Sat, 05 Nov 2022 10:39:20 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/11/05/after-having-gone.html</guid>
      <description>&lt;p&gt;After having gone through the HTML Tutorial on W3Schools at almost breakneck speed (for my doing), I&amp;rsquo;ve hit a roadblock at HTML Layout. I guess I need to study this more thoroughly before continuing. HTML5 certainly was a step up from previous versions.&lt;/p&gt;
&lt;p&gt;👨‍💻🎓🕸🏗&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/11/01/it-appears-mastodon.html</link>
      <pubDate>Tue, 01 Nov 2022 07:35:31 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/11/01/it-appears-mastodon.html</guid>
      <description>&lt;p&gt;It appears Mastodon has no valid rss feeds for a user&amp;rsquo;s posts, other than if you run a bot on your own server that watches that user&amp;rsquo;s Mastodon feed and creates an rss feed on the fly. Or something similar. Mastodon is like Twitter in that respect, a closed web application 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/10/31/i-finished-the.html</link>
      <pubDate>Mon, 31 Oct 2022 19:18:25 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/10/31/i-finished-the.html</guid>
      <description>&lt;p&gt;I finished the Cloudcannon tutorial, and as usual, it went totally off the rails for me with too advanced stuff. Ah well, it seemingly only was to wet one&amp;rsquo;s appetite to start learning Hugo. &lt;a href=&#34;https://renevanbelzen.writeas.com/i-finished-the-cloudcannon-tutorial-and-as-usual-it-went-totally-off-the&#34;&gt;Read more&amp;hellip;&lt;/a&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/09/13/isnt-it-customary.html</link>
      <pubDate>Tue, 13 Sep 2022 15:59:33 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/09/13/isnt-it-customary.html</guid>
      <description>&lt;p&gt;Isn&amp;rsquo;t it customary for people who need their iPhone to work, to wait for at least a point update, like 16.1? 👨‍💻📱&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/01/09/i-can-easily.html</link>
      <pubDate>Sun, 09 Jan 2022 22:10:47 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/01/09/i-can-easily.html</guid>
      <description>&lt;p&gt;I can easily spend 2 hours researching a simple question and not finding any answers. Google search isn&amp;rsquo;t as good as it used to be—I suspect foul play through SEO 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2022/01/09/developing-c-programs.html</link>
      <pubDate>Sun, 09 Jan 2022 15:31:06 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2022/01/09/developing-c-programs.html</guid>
      <description>&lt;p&gt;Developing C64 programs with Kick Assembler, VICE and Visual Studio Code on my Raspberry PI 400 😱 It&amp;rsquo;s a hassle, yet doable. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2022/5a3ba23901.png&#34; width=&#34;600&#34; height=&#34;337&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/12/09/im-in-that.html</link>
      <pubDate>Thu, 09 Dec 2021 09:49:00 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/12/09/im-in-that.html</guid>
      <description>&lt;p&gt;I&amp;rsquo;m in that part of my Go language course where things might get confusing. That would be pointer arithmetic ‍😱 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/12/05/i-can-has.html</link>
      <pubDate>Sun, 05 Dec 2021 18:00:43 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/12/05/i-can-has.html</guid>
      <description>&lt;p&gt;I 😊 can has Go on iPad running on Pi 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/63e055bd30.png&#34; width=&#34;458&#34; height=&#34;600&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/12/03/this-new-go.html</link>
      <pubDate>Fri, 03 Dec 2021 07:37:17 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/12/03/this-new-go.html</guid>
      <description>&lt;p&gt;This new Go course on Udemy is much better suited for me, at least, so far. The presenter is not cutting corners and patiently digs into each line of code to explain the underlying concepts 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/11/26/trying-to-teach.html</link>
      <pubDate>Fri, 26 Nov 2021 10:50:20 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/11/26/trying-to-teach.html</guid>
      <description>&lt;p&gt;Trying to teach myself the Go language. I&amp;rsquo;m still lacking a pet project to bring me to the next level of beginner Go programmer 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/44e5af9eea.png&#34; width=&#34;600&#34; height=&#34;452&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/11/24/ive-upgraded-my.html</link>
      <pubDate>Wed, 24 Nov 2021 19:04:48 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/11/24/ive-upgraded-my.html</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve upgraded my Raspberry Pi 4 to the newest OS, 11 Bullseye, and reinstalled the third-party software. What I like is that new updates are automatically shown in the task bar. No longer needlessly typing &lt;code&gt;sudo apt update&lt;/code&gt;. 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/14/thinking-about-consumerism.html</link>
      <pubDate>Tue, 14 Sep 2021 09:34:11 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/14/thinking-about-consumerism.html</guid>
      <description>&lt;p&gt;Thinking about consumerism… I have no need for new gadgets, so I&amp;rsquo;ll skip Apple&amp;rsquo;s presentation today. It&amp;rsquo;s just another sales pitch to unload some of the burden of having disposable income, preying on FOMO of the tech and adjacent enthusiasts. This is how I rationalize it 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/11/and-then-everything.html</link>
      <pubDate>Sat, 11 Sep 2021 16:41:00 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/11/and-then-everything.html</guid>
      <description>&lt;p&gt;And then everything broke, SMB, SSH, on my Pi. So I removed all the software, turned off the services. Should teach me not to install 3rd-party software. Back to file exchange via USB-sticks.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/11/the-official-hugo.html</link>
      <pubDate>Sat, 11 Sep 2021 14:03:00 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/11/the-official-hugo.html</guid>
      <description>&lt;p&gt;The official &lt;a href=&#34;https://gohugo.io/templates/introduction/&#34;&gt;Hugo primer&lt;/a&gt; is already way above my pay grade. The intro by Mike Dane is much gentler, and doesn&amp;rsquo;t assume any prior knowledge as the official primer seems to do. 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/11/i-can-has.html</link>
      <pubDate>Sat, 11 Sep 2021 08:10:00 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/11/i-can-has.html</guid>
      <description>&lt;p&gt;I can has Remote Desktop Access to my Pi 🥧 now, with TeamViewer for personal use (free) 🤓 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/9c82874f13.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/06/when-in-doubt.html</link>
      <pubDate>Mon, 06 Sep 2021 08:43:39 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/06/when-in-doubt.html</guid>
      <description>&lt;p&gt;💡When in doubt about a feature on Linux Desktop, try the Windows equivalent. My question was: &amp;ldquo;What key combo is used to switch between apps?&amp;rdquo; &lt;code&gt;Alt+Tab&lt;/code&gt; on both Windows and Linux Desktop 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/05/web-coding-in.html</link>
      <pubDate>Sun, 05 Sep 2021 17:52:51 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/05/web-coding-in.html</guid>
      <description>&lt;p&gt;Web coding in Hugo, while watching a YouTube video on the page generated by the local Hugo server, running on my brand new Raspberry Pi 400. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/dc0fde8bda.png&#34; width=&#34;600&#34; height=&#34;337&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/03/its-nice-to.html</link>
      <pubDate>Fri, 03 Sep 2021 22:04:15 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/03/its-nice-to.html</guid>
      <description>&lt;p&gt;It&amp;rsquo;s nice to have extra space instead of the stock 16 GiB that comes with the Raspberry Pi 400. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/e82bdaed65.png&#34; width=&#34;600&#34; height=&#34;432&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/03/since-linux-desktop.html</link>
      <pubDate>Fri, 03 Sep 2021 17:13:18 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/03/since-linux-desktop.html</guid>
      <description>&lt;p&gt;Since Linux Desktop has limited support for emoji and no good input method editor (IME) I could find, I&amp;rsquo;ll have to use a cheat sheet with Unicodes. Most emoji are unsupported, though, which is a shame. To enter, press the ctrl+shift+u key combo, followed by the hex-digits. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/eb39f6ba49.png&#34; width=&#34;600&#34; height=&#34;417&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/09/02/writing-a-long.html</link>
      <pubDate>Thu, 02 Sep 2021 06:54:28 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/09/02/writing-a-long.html</guid>
      <description>&lt;p&gt;Writing a long form post about my experiences learning how to modify micro∙blog themes… I expect part 1 to be out some time next week. I have the computer set up, software all installed. There&amp;rsquo;s education ahead! 😃👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/821af92a02.png&#34; width=&#34;600&#34; height=&#34;438&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/08/30/trying-to-understand.html</link>
      <pubDate>Mon, 30 Aug 2021 18:55:04 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/08/30/trying-to-understand.html</guid>
      <description>&lt;p&gt;Trying to understand the templating language behind micro∙blog is hurting my brain. I have really no idea how to tackle my problem of site navigation, where the previous post is out of scope of the current section—or the next post if the current post is last in its section. 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/07/04/reading-the-command.html</link>
      <pubDate>Sun, 04 Jul 2021 08:35:02 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/07/04/reading-the-command.html</guid>
      <description>&lt;p&gt;Reading the &lt;a href=&#34;https://clig.dev/&#34;&gt;Command Line Interface Guidelines&lt;/a&gt; 👨‍💻&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Yet with its creaky, decades-old constraints and inexplicable quirks, the command line is still the most versatile corner of the computer.&lt;/p&gt;
&lt;/blockquote&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/28/what-weve-built.html</link>
      <pubDate>Mon, 28 Jun 2021 17:13:11 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/28/what-weve-built.html</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://writings.stephenwolfram.com/2019/05/what-weve-built-is-a-computational-language-and-thats-very-important/&#34;&gt;What We’ve Built Is a Computational Language (and That’s Very Important!)—Stephen Wolfram Writings&lt;/a&gt; Language both humans and computers can understand, as important as the introduction of Math symbols &amp;ldquo;+&amp;rdquo;, &amp;ldquo;-&amp;rdquo;, &amp;ldquo;=&amp;rdquo;, etc. centuries ago. 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/24/python-vs-swift.html</link>
      <pubDate>Thu, 24 Jun 2021 06:50:09 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/24/python-vs-swift.html</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://youtu.be/UTFFR61xVbs&#34;&gt;Python vs Swift&lt;/a&gt; Unlike many languages, Swift behaves like Maths, passing objects as values instead of as references, which saves a huge performance hit of having to clone objects to avoid other processes changing those objects unexpectedly. In Python everything has a pointer👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/17/data-serialization-the.html</link>
      <pubDate>Thu, 17 Jun 2021 18:58:08 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/17/data-serialization-the.html</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://docs.python-guide.org/scenarios/serialization/&#34;&gt;Data Serialization — The Hitchhiker&amp;rsquo;s Guide to Python&lt;/a&gt; Always handy to know if you have rolled your own, and wondered if this is a solved solution. In fact, there are several solutions. 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/16/pass-of-a.html</link>
      <pubDate>Wed, 16 Jun 2021 22:39:28 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/16/pass-of-a.html</guid>
      <description>&lt;p&gt;Pass 1 of a 2-pass assembler in Pythonista 3 seems to work for a 256 times 8-bit word memory. I hadn&amp;rsquo;t done that before, so it&amp;rsquo;s a win in my book 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/733ee3185a.png&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/15/while-reading-all.html</link>
      <pubDate>Tue, 15 Jun 2021 07:42:33 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/15/while-reading-all.html</guid>
      <description>&lt;p&gt;While reading all about how &amp;ldquo;modern&amp;rdquo; computers do all kinds of tricks to load executable code on the fly, doing this on an 1980s 8-bit computer seems rather cool, yet overkill. Though, combining built-in ROM routines and Basic with external executable modules is appealing 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/13/currently-reading-assemblers.html</link>
      <pubDate>Sun, 13 Jun 2021 19:09:44 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/13/currently-reading-assemblers.html</guid>
      <description>&lt;img src=&#34;https://cdn.micro.blog/books/9780914894230/cover.jpg&#34; align=&#34;left&#34; class=&#34;microblog_book&#34; style=&#34;max-width: 60px; margin-right: 20px; margin-top: 0px; padding-top: 0px;&#34;&gt;
&lt;p&gt;Currently reading: &lt;a href=&#34;https://micro.blog/books/9780914894230&#34;&gt;Assemblers, compilers, and program translation (Computer software engineering series)&lt;/a&gt; by Peter Calingaert 📚 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/13/watching-pdp-assembly.html</link>
      <pubDate>Sun, 13 Jun 2021 11:38:30 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/13/watching-pdp-assembly.html</guid>
      <description>&lt;p&gt;Watching &lt;a href=&#34;https://www.youtube.com/watch?v=Zy52kFzRGCY&#34;&gt;PDP-11 Assembly Lesson 3 - Conditions, branches and loops - YouTube&lt;/a&gt; to learn about how to do assembly language for this (then) groundbreaking computer. 👨‍💻 🏛‍🖥&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/ce1cff4646.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/13/clearly-if-it.html</link>
      <pubDate>Sun, 13 Jun 2021 09:22:49 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/13/clearly-if-it.html</guid>
      <description>&lt;p&gt;Clearly, 🐱‍💻 ≠ 👨‍💻! If it were true, 🐈‍⬛ would rule the 🌎. Or maybe they already do, and we just don&amp;rsquo;t know it.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/13/before-i-write.html</link>
      <pubDate>Sun, 13 Jun 2021 08:23:08 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/13/before-i-write.html</guid>
      <description>&lt;p&gt;Before I write a basic assembler in Pythonista 3, I should be able to process a source file and output the result into an object file. Here I reversed each word in a text file. It&amp;rsquo;s very basic, doesn&amp;rsquo;t take into account punctuation, but it works, and that&amp;rsquo;s enough. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/b4048901e5.jpg&#34; width=&#34;600&#34; height=&#34;434&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/12/i-think-i.html</link>
      <pubDate>Sat, 12 Jun 2021 16:50:04 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/12/i-think-i.html</guid>
      <description>&lt;p&gt;I think I should implement this one-pass and two-pass assembler in Pythonista 3 on iPad. The project is from the book Assemblers and Loaders. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/a4e2dfc23c.png&#34; width=&#34;224&#34; height=&#34;600&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/11/writing-a-print.html</link>
      <pubDate>Fri, 11 Jun 2021 15:48:38 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/11/writing-a-print.html</guid>
      <description>&lt;p&gt;Writing a print file extension in Pythonista 3 seemed so easy… I had to learn a few new things, so, in the end, it&amp;rsquo;s all good. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/d0195d737c.png&#34; width=&#34;600&#34; height=&#34;432&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/06/currently-reading-programming.html</link>
      <pubDate>Sun, 06 Jun 2021 07:36:15 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/06/currently-reading-programming.html</guid>
      <description>&lt;img src=&#34;https://cdn.micro.blog/books/9780893037895/cover.jpg&#34; align=&#34;left&#34; class=&#34;microblog_book&#34; style=&#34;max-width: 60px; margin-right: 20px; margin-top: 0px; padding-top: 0px;&#34;&gt;
&lt;p&gt;Currently reading: &lt;a href=&#34;https://micro.blog/books/9780893037895&#34;&gt;Programming the 65816: Including the 6502, 65C02, and 65802&lt;/a&gt; by David Eyes 📚 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/05/i-made-a.html</link>
      <pubDate>Sat, 05 Jun 2021 19:00:21 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/05/i-made-a.html</guid>
      <description>&lt;p&gt;I made a very basic and working 1-pass cross-assembler in Pythonista. It was more of a proof of concept, to help me understand the book I&amp;rsquo;m reading (Assemblers and Loaders) 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/d199a641ca.png&#34; width=&#34;600&#34; height=&#34;435&#34; alt=&#34;&#34; /&gt;
&lt;p&gt;PS Notice it&amp;rsquo;s still big-endian, while it should be little-endian. 😬&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/04/currently-reading-assemblers.html</link>
      <pubDate>Fri, 04 Jun 2021 14:19:35 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/04/currently-reading-assemblers.html</guid>
      <description>&lt;img src=&#34;https://cdn.micro.blog/books/9780130525642/cover.jpg&#34; align=&#34;left&#34; class=&#34;microblog_book&#34; style=&#34;max-width: 60px; margin-right: 20px; margin-top: 0px; padding-top: 0px;&#34;&gt;
&lt;p&gt;Currently reading: &lt;a href=&#34;https://micro.blog/books/9780130525642&#34;&gt;Assemblers and Loaders (Ellis Horwood Series in Computers &amp;amp; Their Applications)&lt;/a&gt; by David Salomon 📚 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/04/i-wondered-about.html</link>
      <pubDate>Fri, 04 Jun 2021 11:23:55 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/04/i-wondered-about.html</guid>
      <description>&lt;p&gt;I wondered about how to build (in Python) a linked list of tagged items, and how to print its tagged items. Each item has three containers: a link to the next same-tagged item (-1 if it&amp;rsquo;s the last item with that tag), a tag and a value. Here&amp;rsquo;s my solution. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/104b0b44e5.png&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/03/getting-to-grips.html</link>
      <pubDate>Thu, 03 Jun 2021 09:06:00 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/03/getting-to-grips.html</guid>
      <description>&lt;p&gt;Learning about iOS&amp;rsquo;s sandbox limitations. Pythonista has full access to its own private folders (on device and/or iCloud). You can edit external files, even run Python scripts, but iOS gives scripts no access to files outside mentioned private folders, unless files are shared to it. 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/02/i-guess-i.html</link>
      <pubDate>Wed, 02 Jun 2021 05:51:15 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/02/i-guess-i.html</guid>
      <description>&lt;p&gt;I guess I need superior knowledge, not reinvent the wheel. For creating a proper assembler, I need to know how others build those, and better non-fiction writing is a good thing too, since I&amp;rsquo;ll be communicating to others (including my future self) via code and comments. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/4e7b776524.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/06/01/i-find-it.html</link>
      <pubDate>Tue, 01 Jun 2021 05:28:31 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/06/01/i-find-it.html</guid>
      <description>&lt;p&gt;I find it empowering that one can build somehing useful inside a computer. What I do, I don&amp;rsquo;t think qualifies as programming, but is more like scripting, using macros, which is useful in its own way, though not as generic as an app on a phone or on the web. Doesn&amp;rsquo;t need to be. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/ab2d9d850c.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/31/continuing-my-c.html</link>
      <pubDate>Mon, 31 May 2021 08:38:41 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/31/continuing-my-c.html</guid>
      <description>&lt;p&gt;Continuing my 65c02 assembler project in Python 3, with defining &amp;ldquo;the rules.&amp;rdquo; Without rules, there&amp;rsquo;s unruliness, right? 😉 The script still runs. If it wouldn&amp;rsquo;t have, I could&amp;rsquo;ve rolled back using the Working Copy app. PS, notice the typo! 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/3f82bb362d.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/30/now-im-seemingly.html</link>
      <pubDate>Sun, 30 May 2021 09:34:12 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/30/now-im-seemingly.html</guid>
      <description>&lt;p&gt;Now I&amp;rsquo;m (seemingly) successfully able to filter syntax elements into their own tagged bins, now the question arises how to turn that into object code (byte values)? So I still call it version 0.0.1, very premature, possibly, yet again, stillborn. I hope not the latter, though. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/c7e476b571.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/29/i-have-no.html</link>
      <pubDate>Sat, 29 May 2021 15:10:44 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/29/i-have-no.html</guid>
      <description>&lt;p&gt;I have no idea what the best method is to approach an assembler, specifically for the 65c02 CPU. So I scrapped my previous approach and started anew. I also bought the newest version of Pythonista, because the old version crashed too often (new version seems rock-solid). 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/13e77c5c1b.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/27/so-version-of.html</link>
      <pubDate>Thu, 27 May 2021 20:57:02 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/27/so-version-of.html</guid>
      <description>&lt;p&gt;So, version 0.1 of my Python 🐍 65c02 assembler is ✅ I&amp;rsquo;m sure there are still bugs, but it works. I enter in assembly code and the program stores it in a dictionary object, which could be saved into a file on disk. Not sure when I come to that. First priority is testing the code. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/755f572fe7.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/27/im-getting-closer.html</link>
      <pubDate>Thu, 27 May 2021 17:18:28 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/27/im-getting-closer.html</guid>
      <description>&lt;p&gt;😃I&amp;rsquo;m getting closer with my 65c02 assembler in Python. I ripped out the mnemonics processing, which worked perfectly, but was messy code, and got the other stuff to work, like labels, addressing input, program counter manipulation, etc. I also started using the Working Copy app. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/04a5c187c8.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/26/okay-its-still.html</link>
      <pubDate>Wed, 26 May 2021 14:51:54 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/26/okay-its-still.html</guid>
      <description>&lt;p&gt;Okay, it&amp;rsquo;s still very clunky, but I can (sorta) write in assembler, type the hexcode in HexIt and save the file to my local Commander X16 folder, and it runs! I couldn&amp;rsquo;t do this before, unless I coded the hexcode by hand, which was rather error-prone. So, yay? 😁 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/22b4477b89.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/26/while-awaiting-the.html</link>
      <pubDate>Wed, 26 May 2021 09:47:40 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/26/while-awaiting-the.html</guid>
      <description>&lt;p&gt;While awaiting the glaziers for replacing some windows, I&amp;rsquo;ve made progress with my 65c02 Python assembler project. It now creates a list of strings, each with a program counter, a colon, and a series of opcode and operand bytes, all in hex characters and in the proper order 😃 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/3b50ea8a60.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/25/i-had-some.html</link>
      <pubDate>Tue, 25 May 2021 16:27:54 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/25/i-had-some.html</guid>
      <description>&lt;p&gt;I had some great progress on my Python 65c02 assembler project. I have all opcodes tested and  can check if an instruction is valid. For instance, &lt;code&gt;lda 30,y&lt;/code&gt; is not a valid instruction, while &lt;code&gt;lda 30,x&lt;/code&gt; is valid. Now it&amp;rsquo;s up to me to test some instructions. 👨‍💻&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/6804ce86e6.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/42fb67598e.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/24/getting-closer-inchbyinch.html</link>
      <pubDate>Mon, 24 May 2021 14:37:20 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/24/getting-closer-inchbyinch.html</guid>
      <description>&lt;p&gt;Getting closer, inch-by-inch, to processing 65c02 instructions in Python… 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/a031468880.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/23/i-discovered-a.html</link>
      <pubDate>Sun, 23 May 2021 17:39:01 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/23/i-discovered-a.html</guid>
      <description>&lt;p&gt;I discovered a superpower, yield in Python 😲 awesome! 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/4a0bc9d5ac.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/23/in-other-news.html</link>
      <pubDate>Sun, 23 May 2021 07:51:48 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/23/in-other-news.html</guid>
      <description>&lt;p&gt;In other news, Textastic, a great code editor on iOS, stopped working when I updated my iPad to 14.5.1 from pre-14.5. It had worked for 5 years after the last update, and it was great. So I did a paid upgrade of Textastic to the latest version. There&amp;rsquo;s code hacking ahead! 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/23/this-website-made.html</link>
      <pubDate>Sun, 23 May 2021 07:23:06 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/23/this-website-made.html</guid>
      <description>&lt;p&gt;🤩 &lt;a href=&#34;https://www.masswerk.at/6502/assembler.html&#34;&gt;this website&lt;/a&gt; made me reconsider how to construct my 65c02 cross assembler. I guess I need to whip up a spec sheet before I start coding in Python. All the work is not for naught, since I learned some regular expressions. 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/22/i-simplified-and.html</link>
      <pubDate>Sat, 22 May 2021 15:16:18 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/22/i-simplified-and.html</guid>
      <description>&lt;p&gt;I simplified and extended my Python 65c02 assembler. It now checks the source code for valid opcodes and addressing modes. It still doesn&amp;rsquo;t check if any label value is valid. For labels to work, it has to established their values first (in a first pass of two passes). More to do… 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/82d8ebdb67.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/21/im-sure-there.html</link>
      <pubDate>Fri, 21 May 2021 22:26:13 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/21/im-sure-there.html</guid>
      <description>&lt;p&gt;I&amp;rsquo;m sure there are much easier ways to find the possible addressing modes of the 65c02 cpu. Even so, I spent many hours of code hacking today to get this result, with many failed attempts. Obviously, I&amp;rsquo;m not good at coding, nor problem solving. Practicing it must be a good thing. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/770a2ce812.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/19/okay-i-can.html</link>
      <pubDate>Wed, 19 May 2021 15:42:27 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/19/okay-i-can.html</guid>
      <description>&lt;p&gt;Okay, I can has implied, immediate, (indirect), (absolute indirect) addressing modes in this Python script I&amp;rsquo;m working on. It also makes a symbol table for code origin, labels and definitions (equates), used to calculate values and addresses. It&amp;rsquo;s a thing, 65c02 assembly on iPad. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/c08dc08296.png&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/18/instead-of-futzing.html</link>
      <pubDate>Tue, 18 May 2021 13:21:59 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/18/instead-of-futzing.html</guid>
      <description>&lt;p&gt;Instead of futzing around with Python, I decided to create a two-pass assembler, and wrote a version of the first pass, in which the label definitions are dealt with, both explicit and inline. I won&amp;rsquo;t create a professional grade assembler, just a hobby one. 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/0a4ec745b3.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/16/computer-science-is.html</link>
      <pubDate>Sun, 16 May 2021 21:01:35 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/16/computer-science-is.html</guid>
      <description>&lt;p&gt;Computer science is giving me headaches. Reflection and regular expressions. Argh! I could just as well hand-code machine code instead. 👨‍💻&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://renevanbelzen.micro.blog/2021/05/16/writing-my-own.html</link>
      <pubDate>Sun, 16 May 2021 14:25:42 +0100</pubDate>
      
      <guid>http://renevanbelzen.micro.blog/2021/05/16/writing-my-own.html</guid>
      <description>&lt;p&gt;Writing my own 65c02 assembler in Python on the iPad, because I can ♥︎ 👨‍💻&lt;/p&gt;
&lt;img src=&#34;https://cdn.uploads.micro.blog/6439/2021/d73a7f3e7a.png&#34; width=&#34;600&#34; height=&#34;450&#34; alt=&#34;&#34; /&gt;
</description>
    </item>
    
  </channel>
</rss>