<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/" version="2.0">
    <channel>
        <title>Tao Te Ka-Ching</title>
        <link>http://www.taotekaching.com/Default.aspx</link>
        <description>Working the cash register of the Great Tao</description>
        <language>en-US</language>
        <copyright>ZagNut</copyright>
        <generator>Subtext Version 2.5.1.19</generator>
        <image>
            <title>Tao Te Ka-Ching</title>
            <url>http://www.taotekaching.com/images/RSS2Image.gif</url>
            <link>http://www.taotekaching.com/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TaoTeKaChing" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="taotekaching" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://feeds.feedburner.com/TaoTeKaChing" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2FTaoTeKaChing" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
            <title>Programming the Atari 2600, and Me &amp;ndash; Part 3</title>
            <category>Programming</category>
            <link>http://www.taotekaching.com/archive/2010/07/24/Atari-2600-Programming-and-Me-ndash-Part-3.aspx</link>
            <description>&lt;p&gt;In our &lt;a href="http://www.taotekaching.com/archive/2010/07/12/Programming-the-Atari-2600-and-Me-ndash-Part-2.aspx"&gt;previous post in this series&lt;/a&gt;, we went over the environment within which our 2600 game must live.  It is a harsh, barren environment by today’s standards, which makes this all the more bitchin’.  Anyway, let’s take a quick look at what we’ve covered:&lt;/p&gt;  &lt;p&gt;Our game will be running through a 1.19Mhz 6507 CPU.  This CPU can direct commands to a custom Atari chip – the Television Interface Adapter (TIA) – which we use for updating the display, receiving collision notifications, and initiating audio.  The TIA, indeed the entire system, is clocked so that it is in sync with the &lt;a href="http://electronics.howstuffworks.com/tv7.htm"&gt;television’s raster scan process&lt;/a&gt;.  Our code should, therefore, break into at least the following two parts: initialization and main loop.  The main loop must consist of at least the vertical sync, followed by vertical blank, followed by display scans, and then overscan.  Using the &lt;a href="http://pdf.textfiles.com/technical/stella.pdf"&gt;2600 programming guide&lt;/a&gt; noted in the &lt;a href="http://www.taotekaching.com/archive/2010/07/12/Programming-the-Atari-2600-and-Me-ndash-Part-2.aspx"&gt;previous post&lt;/a&gt; (from now on, Stella programming guide, or just Stella), we should actually be able to piece something called a ‘kernel’ (see Stella, pg.1 bottom) together:&lt;/p&gt;  &lt;div style="line-height: normal; background-color: white; width: 450px; font-family: courier; color: #909090; font-size: 8pt; overflow: auto"&gt;   &lt;pre&gt;&lt;br /&gt;            processor &lt;font color="red"&gt;6502&lt;/font&gt;&lt;br /&gt;         &lt;font color="blue"&gt;   include&lt;/font&gt; "vcs.h"   ; DASM pseudo-op to include mnemonics for TIA / RIOT registers&lt;br /&gt;&lt;br /&gt;         &lt;font color="blue"&gt;   seg&lt;/font&gt; &lt;br /&gt;         &lt;font color="blue"&gt;   org&lt;/font&gt; $F000   ; our ROM starts at the beginning of the second 4K block&lt;br /&gt;&lt;br /&gt;label_Reset&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;150&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; COLUBK   ; set out background color to a nice blue&lt;br /&gt;&lt;br /&gt;; ---------------------------  our "kernel" starts here&lt;br /&gt;label_Frame&lt;br /&gt;&lt;br /&gt;; ---------------------------  do the v-sync (Stella, §3.3)&lt;br /&gt;label_Vsync&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;2&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; VSYNC   ; enable D1 bit at VSYNC to start vertical sync&lt;br /&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC   ; our 3 scanlines&lt;br /&gt;&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;0&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; VSYNC   ; disable D1 but to finish vertical sync&lt;br /&gt;            &lt;br /&gt;; ---------------------------  do the v-blank (Stella, §3.3)&lt;br /&gt;label_Vblank&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;2&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; VBLANK   ; enable D1 bit at VBLANK to start vertical blank&lt;br /&gt;            &lt;br /&gt;         &lt;font color="blue"&gt;   repeat&lt;/font&gt; &lt;font color="red"&gt;37&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC   ; do 37 scanlines using DASM "REPEAT" pseudo-op&lt;br /&gt;         &lt;font color="blue"&gt;   repend&lt;/font&gt; &lt;br /&gt;&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;0&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; VBLANK   ; disable D1 bit at VBLANK to finish vertical blank&lt;br /&gt;&lt;br /&gt;; ---------------------------  do the picture lines (Stella, §&lt;u&gt;TELEVISION PROTOCOL&lt;/u&gt;)&lt;br /&gt;label_Picture&lt;br /&gt;         &lt;font color="blue"&gt;   repeat&lt;/font&gt; &lt;font color="red"&gt;192&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC   ; do 192 scanlines using DASM "REPEAT" pseudo-op&lt;br /&gt;         &lt;font color="blue"&gt;   repend&lt;/font&gt; &lt;br /&gt;&lt;br /&gt;; ---------------------------  do the scanlines (Stella, §&lt;u&gt;TELEVISION PROTOCOL&lt;/u&gt;)&lt;br /&gt;label_Overscan&lt;br /&gt;         &lt;font color="blue"&gt;   repeat&lt;/font&gt; &lt;font color="red"&gt;30&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC   ; do 30 scanlines using DASM "REPEAT" pseudo-op&lt;br /&gt;         &lt;font color="blue"&gt;   repend&lt;/font&gt; &lt;br /&gt;&lt;br /&gt;; ---------------------------  do it all over again, 60 times per second!&lt;br /&gt;         &lt;font color="black"&gt;JMP&lt;/font&gt; label_Frame&lt;br /&gt;&lt;br /&gt;         &lt;font color="blue"&gt;   org&lt;/font&gt; $FFFA&lt;br /&gt;            &lt;br /&gt;            .word label_Reset          ; NMI&lt;br /&gt;            .word label_Reset          ; RESET&lt;br /&gt;            .word label_Reset          ; IRQ&lt;br /&gt;&lt;br /&gt;      &lt;font color="blue"&gt;      end&lt;/font&gt; &lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;Copy and paste this code into &lt;a href="http://www.scintilla.org/SciTE.html"&gt;SciTE&lt;/a&gt; and run it (see the &lt;a href="http://www.taotekaching.com/archive/2010/07/02/Programming-the-Atari-2600-and-Me-ndash-Part-1.aspx"&gt;first post on setting up our IDE&lt;/a&gt;).  You should see something like the following (click to see if full-size image):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/Atari2600ProgrammingandMePart3_10582/kernel_0_2.gif" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="kernel_0" border="0" alt="kernel_0" src="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/Atari2600ProgrammingandMePart3_10582/kernel_0_thumb.gif" width="450" height="225" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;There’s several important things to go over here.  First, the most important following an IDE build/run environment:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/Atari2600ProgrammingandMePart3_10582/stella-framerate_2.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stella-framerate" border="0" alt="stella-framerate" src="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/Atari2600ProgrammingandMePart3_10582/stella-framerate_thumb.png" width="239" height="139" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Using &lt;a href="http://stella.sourceforge.net/"&gt;Stella&lt;/a&gt; as the emulator to test your game is extremely helpful just for the info you see in the picture.  This info’s display is toggled using the Alt-L combo.  Notice we have what we want: 262 scanlines (3 vertical-sync, 37 vertical-blank, 192 display, 30 overscan) at 60 frames per second, thereby designating an NTSC display.  This is the very first point of troubleshooting, and why this series will be focusing for the long run on NTSC development.  I could have easily chosen PAL instead.  What’s important is that those number match exactly our target television’s specs, because that means we are meeting the proper machine cycles per scanline, scanlines per frame, and vertical-sync and –blank criteria; in other words, our code is humming nicely along with the TV’s scanning.&lt;/p&gt;

&lt;p&gt;Now try altering the picture lines code with:&lt;/p&gt;

&lt;div style="line-height: normal; background-color: white; width: 450px; font-family: courier; color: #909090; font-size: 8pt; overflow: auto"&gt;
  &lt;pre&gt;&lt;br /&gt;; ---------------------------  do the picture lines (Stella, §&lt;u&gt;TELEVISION PROTOCOL&lt;/u&gt;)&lt;br /&gt;label_Picture&lt;br /&gt;         &lt;font color="blue"&gt;   repeat&lt;/font&gt; &lt;font color="red"&gt;34&lt;/font&gt; ; 4 NOPs ( = 8 cycles ) short of the 76 cycles for a complete scan line&lt;br /&gt;         &lt;font color="black"&gt;NOP&lt;/font&gt; ; = 2 cycles&lt;br /&gt;         &lt;font color="blue"&gt;   repend&lt;/font&gt; &lt;br /&gt;            &lt;br /&gt;         &lt;font color="blue"&gt;   repeat&lt;/font&gt; &lt;font color="red"&gt;191&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC   ; do 192 scanlines using DASM "REPEAT" pseudo-op&lt;br /&gt;         &lt;font color="blue"&gt;   repend&lt;/font&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Stella should now display:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/Atari2600ProgrammingandMePart3_10582/stella-framerate2_2.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stella-framerate2" border="0" alt="stella-framerate2" src="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/Atari2600ProgrammingandMePart3_10582/stella-framerate2_thumb.png" width="239" height="139" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Hmmm…we’re off.  We know why, of course, but this “technique” has so far helped me out many, many times simply when I’ve counted cycles wrong (we’ll get to this).&lt;/p&gt;

&lt;p&gt;I’ll leave off here with some code to play around with.  Run it, then look over the code to see the changes from our first simple “kernel” at the beginning of this post.  Try to figure out what’s going on, and review the &lt;a href="http://pdf.textfiles.com/technical/stella.pdf"&gt;Stella guide&lt;/a&gt;.  Next post, I’ll get into a bit more with troubleshooting our code and breaking down our simple kernel.&lt;/p&gt;

&lt;div style="background-color:white;color:#909090;width:450px;overflow:auto;font-family:courier;font-size:8pt;line-height:normal;"&gt;&lt;pre&gt;&lt;br /&gt;            processor &lt;font color="red"&gt;6502&lt;/font&gt;&lt;br /&gt;         &lt;font color="blue"&gt;   include&lt;/font&gt; "vcs.h"   ; DASM pseudo-op to include mnemonics for TIA / RIOT registers&lt;br /&gt;&lt;br /&gt;         &lt;font color="blue"&gt;   seg&lt;/font&gt; &lt;br /&gt;         &lt;font color="blue"&gt;   org&lt;/font&gt; $F000   ; our ROM starts at the beginning of the second 4K block&lt;br /&gt;            &lt;br /&gt;atColor            = $80&lt;br /&gt;&lt;br /&gt;label_Reset&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;255&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; atColor&lt;br /&gt;&lt;br /&gt;; ---------------------------  our "kernel" starts here&lt;br /&gt;label_Frame&lt;br /&gt;&lt;br /&gt;; ---------------------------  do the v-sync (Stella, §3.3)&lt;br /&gt;label_Vsync&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;2&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; VSYNC   ; enable D1 bit at VSYNC to start vertical sync&lt;br /&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC   ; our 3 scanlines&lt;br /&gt;&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;0&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; VSYNC   ; disable D1 but to finish vertical sync&lt;br /&gt;            &lt;br /&gt;; ---------------------------  do the v-blank (Stella, §3.3)&lt;br /&gt;label_Vblank&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;2&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; VBLANK   ; enable D1 bit at VBLANK to start vertical blank&lt;br /&gt;            &lt;br /&gt;         &lt;font color="blue"&gt;   repeat&lt;/font&gt; &lt;font color="red"&gt;36&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC&lt;br /&gt;         &lt;font color="blue"&gt;   repend&lt;/font&gt; &lt;br /&gt;            &lt;br /&gt;         &lt;font color="black"&gt;DEC&lt;/font&gt; atColor&lt;br /&gt;         &lt;font color="black"&gt;LDY&lt;/font&gt; atColor&lt;br /&gt;         &lt;font color="black"&gt;LDX&lt;/font&gt; #&lt;font color="red"&gt;192&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC&lt;br /&gt;&lt;br /&gt;         &lt;font color="black"&gt;LDA&lt;/font&gt; #&lt;font color="red"&gt;0&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; VBLANK   ; disable D1 bit at VBLANK to finish vertical blank&lt;br /&gt;&lt;br /&gt;; ---------------------------  do the picture lines (Stella, §&lt;u&gt;TELEVISION PROTOCOL&lt;/u&gt;)&lt;br /&gt;label_Picture&lt;br /&gt;         &lt;font color="black"&gt;INY&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STY&lt;/font&gt; COLUBK&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC   ; do 192 scanlines using DASM "REPEAT" pseudo-op&lt;br /&gt;         &lt;font color="black"&gt;DEX&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;CPX&lt;/font&gt; #&lt;font color="red"&gt;0&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;BNE&lt;/font&gt; label_Picture&lt;br /&gt;&lt;br /&gt;; ---------------------------  do the scanlines (Stella, §&lt;u&gt;TELEVISION PROTOCOL&lt;/u&gt;)&lt;br /&gt;label_Overscan&lt;br /&gt;         &lt;font color="blue"&gt;   repeat&lt;/font&gt; &lt;font color="red"&gt;30&lt;/font&gt;&lt;br /&gt;         &lt;font color="black"&gt;STA&lt;/font&gt; WSYNC   ; do 30 scanlines using DASM "REPEAT" pseudo-op&lt;br /&gt;         &lt;font color="blue"&gt;   repend&lt;/font&gt; &lt;br /&gt;&lt;br /&gt;; ---------------------------  do it all over again, 60 times per second!&lt;br /&gt;         &lt;font color="black"&gt;JMP&lt;/font&gt; label_Frame&lt;br /&gt;&lt;br /&gt;         &lt;font color="blue"&gt;   org&lt;/font&gt; $FFFA&lt;br /&gt;            &lt;br /&gt;            .word label_Reset          ; NMI&lt;br /&gt;            .word label_Reset          ; RESET&lt;br /&gt;            .word label_Reset          ; IRQ&lt;br /&gt;&lt;br /&gt;      &lt;font color="blue"&gt;      end&lt;/font&gt; &lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;~ZagNut&lt;/p&gt;
&lt;div style="display:none;"&gt;&lt;a href="http://www.taotekaching.com/search.aspx?q=SciTE" rel="tag"&gt;SciTE&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=DASM" rel="tag"&gt;DASM&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=Stella" rel="tag"&gt;Stella&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=Atari" rel="tag"&gt;Atari&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=Atari%202600" rel="tag"&gt;Atari%202600&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=2600" rel="tag"&gt;2600&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=6502" rel="tag"&gt;6502&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=6507" rel="tag"&gt;6507&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=Kernel" rel="tag"&gt;Kernel&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=TIA" rel="tag"&gt;TIA&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=RIOT" rel="tag"&gt;RIOT&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.taotekaching.com/aggbug/83.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>ZagNut</dc:creator>
            <guid>http://www.taotekaching.com/archive/2010/07/24/Atari-2600-Programming-and-Me-ndash-Part-3.aspx</guid>
            <pubDate>Sat, 24 Jul 2010 14:23:29 GMT</pubDate>
            <comments>http://www.taotekaching.com/archive/2010/07/24/Atari-2600-Programming-and-Me-ndash-Part-3.aspx#feedback</comments>
            <wfw:commentRss>http://www.taotekaching.com/comments/commentRss/83.aspx</wfw:commentRss>
            <trackback:ping>http://www.taotekaching.com/services/trackbacks/83.aspx</trackback:ping>
        </item>
        <item>
            <title>How Does One Acquire That Skill, and Me&amp;hellip;</title>
            <link>http://www.taotekaching.com/archive/2010/07/23/How-Does-One-Acquire-That-Skill-and-Mehellip.aspx</link>
            <description>&lt;p&gt;On my Dice.com jobs feed today.  I didn’t realize there’s more than one:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/HowDoesOneAcquireThatSkillandMe_100E9/dice-feed-072310.1809_2.png" rel="lightbox"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="dice-feed-072310.1809" border="0" alt="dice-feed-072310.1809" src="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/HowDoesOneAcquireThatSkillandMe_100E9/dice-feed-072310.1809_thumb.png" width="454" height="173" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;~ZagNut&lt;/p&gt;  &lt;div style="display:none;"&gt;&lt;a href="http://www.taotekaching.com/search.aspx?q=congo" rel="tag"&gt;congo&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=cognos" rel="tag"&gt;cognos&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=dice.com" rel="tag"&gt;dice.com&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=wtf" rel="tag"&gt;wtf&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.taotekaching.com/aggbug/82.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>ZagNut</dc:creator>
            <guid>http://www.taotekaching.com/archive/2010/07/23/How-Does-One-Acquire-That-Skill-and-Mehellip.aspx</guid>
            <pubDate>Fri, 23 Jul 2010 22:16:56 GMT</pubDate>
            <comments>http://www.taotekaching.com/archive/2010/07/23/How-Does-One-Acquire-That-Skill-and-Mehellip.aspx#feedback</comments>
            <wfw:commentRss>http://www.taotekaching.com/comments/commentRss/82.aspx</wfw:commentRss>
            <trackback:ping>http://www.taotekaching.com/services/trackbacks/82.aspx</trackback:ping>
        </item>
        <item>
            <title>Programming the Atari 2600, and Me &amp;ndash; Part 2</title>
            <category>Programming</category>
            <link>http://www.taotekaching.com/archive/2010/07/12/Programming-the-Atari-2600-and-Me-ndash-Part-2.aspx</link>
            <description>&lt;p&gt;Greetings.&lt;/p&gt;  &lt;p&gt;Now that we have an &lt;a href="http://www.taotekaching.com/archive/2010/07/02/Programming-the-Atari-2600-and-Me-ndash-Part-1.aspx"&gt;IDE set up for creating our 2600 game&lt;/a&gt;, we need to know what we’re actually having to program.  Here’s a breakdown of (what I’ve garnered is) the core of the Atari 2600 architecture:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/ProgrammingtheAtari2600andMePart2_FEF8/schematic_2.jpg" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="schematic" border="0" alt="schematic" src="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/ProgrammingtheAtari2600andMePart2_FEF8/schematic_thumb.jpg" width="454" height="336" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We have a game cartridge [A], our program ROM.  We have [B], a &lt;a href="http://en.wikipedia.org/wiki/MOS_Technology_6532"&gt;MOS 6532 RAM / IO/ Timer (RIOT) chip&lt;/a&gt;.  [C] is a &lt;a href="http://en.wikipedia.org/wiki/MOS_Technology_6507"&gt;MOS 6507 microprocessor&lt;/a&gt;, practically identical to &lt;a href="http://en.wikipedia.org/wiki/MOS_Technology_6502"&gt;the 6502 of fame&lt;/a&gt;.  Last we have [D], a custom &lt;a href="http://en.wikipedia.org/wiki/Atari_TIA"&gt;Television Integrated Adapter (TIA) chip&lt;/a&gt; designed specifically for the machine.&lt;/p&gt;  &lt;p&gt;The links above will give you more than enough information to discern the relationship between these circuits, but in a nutshell, the Atari 2600 basically has 8K of addressable space to work with.  4K is reserved for the RIOT chip, the other 4K for our program.  The RIOT chip generously provides us 128 BYTES (not KILO-bytes, but BYTES for crying out loud) of RAM (0x0080 through 0x00FF), as well as I/O and timer functions (0x0280 through 0x0297), I/O referring to the joysticks, paddles, etc.  If you’ve downloaded DASM, a file VCS.h should have come with it.  This header already has the RIOT and TIA mnemonics mapped out to the appropriate addresses.  The TIA chip handles the presentation “stuff” for us, basically drawing to the TV display and registering collisions and I guess what you could call audio.  In our 8K of addressable space, addresses 0x0000 through 0x003F are TIA chip stuff.  Again, the VCS.h file has these mapped out to their official mnemonics.&lt;/p&gt;  &lt;p&gt;I don’t feign to be an electrical engineer or care to be an expert on the internal workings of televisions, because I believe our modern newfangled LCD, projection and plasma HDTVs probably don’t work this way, but at least when the TIA was designed, it was designed to handle synchronizing the game logic and output with the TV’s rasterized method of rendering it’s display.  An electron beam will hit a portion of phosphor on the TV screen, lighting that point to a particular degree of intensity.  It will do this for each of three colors: red, green, and blue (well, and white for luminosity).  Doing this for a color at a particular point is referred to as a color-clock.&lt;/p&gt;  &lt;p&gt;The beam will do this across the screen until it is done with the line it is working on (the scan-line), take a moment to reposition back on the other side of the screen at the next line (a duration called the horizontal blank), and then start again.  When all the lines are “finished”, we say a frame has been completed, and when a frame has been completed, the beam returns all the way back kiddy-corner to start a new frame (a duration called the vertical blank).  &lt;a href="http://en.wikipedia.org/wiki/NTSC"&gt;NTSC&lt;/a&gt;-based systems will do 262.5 lines 60-times per second (or 525 interlaced at 30 frames per second), &lt;a href="http://en.wikipedia.org/wiki/PAL"&gt;PAL&lt;/a&gt;-based systems 312.5 lines at 50-times per second.  There other systems out there (like SECAM, whatever that is), but from here on in this series, I will just be dealing with all things NTSC unless otherwise noted.  Also, these lines-per-frame-per-second numbers are approximate for purposes of this series.  The links provided go to respective Wikipedia articles with much more detail (and accuracy).  We only need to know so much, and the TIA chip takes care of the rest.  :)&lt;/p&gt;  &lt;p&gt;…but I digress.&lt;/p&gt;  &lt;p&gt;Below is a simple diagram of how my aging brain is grokking all this (it could therefore obviously be incredibly wrong):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/ProgrammingtheAtari2600andMePart2_FEF8/cycles_2.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="cycles" border="0" alt="cycles" src="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/ProgrammingtheAtari2600andMePart2_FEF8/cycles_thumb.png" width="454" height="416" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With the TV knowledge and this delicious diagram in hand, we now can see how we bridge the TV and gaming platform gap via the TIA chip.  The “motherboard” is architected such that a machine cycle – the unit of time used for measuring the duration of a completed 6507 instruction – equals the time it takes for all the colors for a given point on the TV (do not think pixel; analog TVs apparently do not have pixels) to be scanned.  That is, scanning a set of color-clocks for one point on the screen equals a machine cycle, and machine cycles are how we measure program execution timing.  So, if the 6507 chip takes 2 machine cycles to perform an instruction – say, LDA #5, or Load-Accumulator with integer 5 – and a given point on a scan line is made up of 3 (or 4 counting the white luminescence one) color-clocks, then that LDA instruction will take the equivalent of 6 color-clocks to complete.  This leads us to another important image:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/ProgrammingtheAtari2600andMePart2_FEF8/cycles2_2.png" rel="lightbox"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="cycles2" border="0" alt="cycles2" src="http://www.taotekaching.com/images/www_taotekaching_com/WindowsLiveWriter/ProgrammingtheAtari2600andMePart2_FEF8/cycles2_thumb.png" width="454" height="385" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We see that, according to the TIA, we have 228 color-clocks before a scan line is “finished”: 68 for the horizontal blank, and 160 for the actual TV picture.  The first 3 scan lines perform a &lt;a href="http://en.wikipedia.org/wiki/Vertical_synchronization"&gt;vertical sync&lt;/a&gt;, then 37 more account for the &lt;a href="http://en.wikipedia.org/wiki/Vertical_blanking_interval"&gt;vertical blank&lt;/a&gt;.  The next 192 are our display lines.  A final 30 are &lt;a href="http://en.wikipedia.org/wiki/Overscan"&gt;overscan&lt;/a&gt; lines.  Also, the TIA is synchronized such that 3 color-clocks equal one machine cycle.  Therefore, in the time a TV completes a scan line and returns to the next line, 76 machine cycles will have occurred.  That’s &lt;em&gt;at most&lt;/em&gt; 38 instructions.  And we have 262 of these we can do before the process starts all over again, less than 10,000 instructions.  Sweet.&lt;/p&gt;  &lt;p&gt;So, a quick recap of this concept: game logic processing by the 6507 is literally in sync with the rasterization process of the TV.  The TIA chip is our bridge between what the 6507 is doing and what the TV is doing.  Ergo, while your program is executing, the TV is scanning lines, so your program itself needs to take this into account and know when as well as what to tell the TV to do while its scanning.&lt;/p&gt;  &lt;p&gt;We actually have a bunch more constraints believe it or not.  Just positioning something horizontally is kind of a nightmare.  Basically, you have to write to a register on the TIA when you want the object to appear at the same time on the following scan line.  We’ll get to that giant ugly later.  For now, I, like you, will sit and zen on this a bit.  We’ll pick up next time from here and actually look at executing some code in Stella.  In the meantime, here are several good links / documents / tools to start looking at:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.atariage.com/2600/programming"&gt;AtariAge&lt;/a&gt; – This seems to be a de facto site for Atari 2600 enthusiasts and programmers &lt;/li&gt;    &lt;li&gt;&lt;a href="http://home.pacbell.net/michal_k/6502.html"&gt;6502 simulator&lt;/a&gt; – Excellent tool for testing your 65xx code.  Really helps for developing small routines like random number generators. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://pdf.textfiles.com/technical/2600_guide.pdf"&gt;2600 Programmer’s Guide&lt;/a&gt; – Our bible from now on.  &lt;a href="http://pdf.textfiles.com/technical/stella.pdf"&gt;This&lt;/a&gt; is a much better version, but my advice is print out the former because chicks will dig it when they see it…&lt;/li&gt;    &lt;li&gt;&lt;a href="http://pdf.textfiles.com/technical/2600_tia.pdf"&gt;TIA documentation&lt;/a&gt; - ‘nuff said. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://nocash.emubase.de/2k6specs.htm"&gt;All 2600 specs ever (it seems)&lt;/a&gt; – Crazy good site documenting the 2600. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;~ZagNut&lt;/p&gt;
&lt;div style="display:none;"&gt;&lt;a href="http://www.taotekaching.com/search.aspx?q=SciTE" rel="tag"&gt;SciTE&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=DASM" rel="tag"&gt;DASM&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=Stella" rel="tag"&gt;Stella&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=Atari" rel="tag"&gt;Atari&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=Atari%202600" rel="tag"&gt;Atari%202600&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=2600" rel="tag"&gt;2600&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=6502" rel="tag"&gt;6502&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=6507" rel="tag"&gt;6507&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=TIA" rel="tag"&gt;TIA&lt;/a&gt;,&lt;a href="http://www.taotekaching.com/search.aspx?q=RIOT" rel="tag"&gt;RIOT&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.taotekaching.com/aggbug/81.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>ZagNut</dc:creator>
            <guid>http://www.taotekaching.com/archive/2010/07/12/Programming-the-Atari-2600-and-Me-ndash-Part-2.aspx</guid>
            <pubDate>Mon, 12 Jul 2010 14:22:01 GMT</pubDate>
            <comments>http://www.taotekaching.com/archive/2010/07/12/Programming-the-Atari-2600-and-Me-ndash-Part-2.aspx#feedback</comments>
            <wfw:commentRss>http://www.taotekaching.com/comments/commentRss/81.aspx</wfw:commentRss>
            <trackback:ping>http://www.taotekaching.com/services/trackbacks/81.aspx</trackback:ping>
        </item>
    </channel>
</rss>
