<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>6502 Basics on Programming the Atari VCS in Assembly</title><link>https://cdeever.github.io/atari-vcs/docs/6502-basics/</link><description>Recent content in 6502 Basics on Programming the Atari VCS in Assembly</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://cdeever.github.io/atari-vcs/docs/6502-basics/index.xml" rel="self" type="application/rss+xml"/><item><title>Registers &amp; Status Flags</title><link>https://cdeever.github.io/atari-vcs/docs/6502-basics/registers/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://cdeever.github.io/atari-vcs/docs/6502-basics/registers/</guid><description>&lt;h1 id="registers--status-flags"&gt;Registers &amp;amp; Status Flags&lt;a class="anchor" href="#registers--status-flags"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The 6502 has astonishingly few places to keep data — &lt;strong&gt;three 8-bit working registers&lt;/strong&gt;, and that scarcity shapes how every program is written. You can&amp;rsquo;t spread work across a bank of registers the way you would on a bigger CPU; values are constantly shuttled between these three and &lt;a href="https://cdeever.github.io/atari-vcs/docs/prerequisites/memory-mapped/"&gt;memory&lt;/a&gt;.&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th&gt;Register&lt;/th&gt;
 &lt;th&gt;Width&lt;/th&gt;
 &lt;th&gt;Role&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;A&lt;/strong&gt; (accumulator)&lt;/td&gt;
 &lt;td&gt;8-bit&lt;/td&gt;
 &lt;td&gt;The workhorse. The &lt;em&gt;only&lt;/em&gt; register that does arithmetic and logic (&lt;code&gt;ADC&lt;/code&gt;, &lt;code&gt;SBC&lt;/code&gt;, &lt;code&gt;AND&lt;/code&gt;, &lt;code&gt;ORA&lt;/code&gt;, &lt;code&gt;EOR&lt;/code&gt;). Almost all data flows through it.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;X&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;8-bit&lt;/td&gt;
 &lt;td&gt;Index/counter. Used to offset addresses (&lt;code&gt;LDA table,X&lt;/code&gt;) and to count loops. Also the bridge to the stack pointer (&lt;code&gt;TXS&lt;/code&gt;/&lt;code&gt;TSX&lt;/code&gt;).&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;Y&lt;/strong&gt;&lt;/td&gt;
 &lt;td&gt;8-bit&lt;/td&gt;
 &lt;td&gt;The other index/counter. Similar to X, with its own indexed modes.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;S&lt;/strong&gt; (stack pointer)&lt;/td&gt;
 &lt;td&gt;8-bit&lt;/td&gt;
 &lt;td&gt;Points at the top of the &lt;a href="https://cdeever.github.io/atari-vcs/docs/6502-basics/stack-and-subroutines/"&gt;stack&lt;/a&gt;.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;PC&lt;/strong&gt; (program counter)&lt;/td&gt;
 &lt;td&gt;16-bit&lt;/td&gt;
 &lt;td&gt;Address of the next instruction to execute.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;&lt;strong&gt;P&lt;/strong&gt; (status)&lt;/td&gt;
 &lt;td&gt;8-bit&lt;/td&gt;
 &lt;td&gt;The processor flags — see below.&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;A, X, and Y are &lt;em&gt;not&lt;/em&gt; interchangeable: only A computes, only X and Y index, and each has instructions the others lack. Choosing which value lives in which register is a real part of writing tight 6502 code.&lt;/p&gt;</description></item><item><title>Addressing Modes</title><link>https://cdeever.github.io/atari-vcs/docs/6502-basics/addressing-modes/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://cdeever.github.io/atari-vcs/docs/6502-basics/addressing-modes/</guid><description>&lt;h1 id="addressing-modes"&gt;Addressing Modes&lt;a class="anchor" href="#addressing-modes"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;An instruction like &lt;code&gt;LDA&lt;/code&gt; doesn&amp;rsquo;t just load — it loads &lt;em&gt;from somewhere&lt;/em&gt;, and the &lt;strong&gt;addressing mode&lt;/strong&gt; is how that somewhere is specified. The same &lt;code&gt;LDA&lt;/code&gt; comes in several forms, and they differ in both what they can reach and &lt;strong&gt;how many cycles they cost&lt;/strong&gt; — which, on the VCS, is the part you care about most. &lt;a href="https://cdeever.github.io/atari-vcs/docs/prerequisites/reading-assembly/"&gt;Reading 6502 Assembly&lt;/a&gt; introduced the &lt;code&gt;#&lt;/code&gt;/&lt;code&gt;$&lt;/code&gt;/&lt;code&gt;,X&lt;/code&gt; notation; here is what each mode actually does.&lt;/p&gt;</description></item><item><title>The Instruction Set</title><link>https://cdeever.github.io/atari-vcs/docs/6502-basics/instruction-set/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://cdeever.github.io/atari-vcs/docs/6502-basics/instruction-set/</guid><description>&lt;h1 id="the-instruction-set"&gt;The Instruction Set&lt;a class="anchor" href="#the-instruction-set"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The 6502&amp;rsquo;s instruction set is small — about 56 mnemonics — and you can write whole games with maybe two dozen of them. This page is a grouped tour, not an exhaustive datasheet: enough to recognize what you read and reach for what you need. Cycle counts live in &lt;a href="https://cdeever.github.io/atari-vcs/docs/6502-basics/cycles-and-timing/"&gt;Cycles &amp;amp; Timing&lt;/a&gt;; flag effects are in &lt;a href="https://cdeever.github.io/atari-vcs/docs/6502-basics/registers/"&gt;Registers &amp;amp; Status Flags&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="moving-data"&gt;Moving data&lt;a class="anchor" href="#moving-data"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The most common instructions by far — nothing computes until data is in a register.&lt;/p&gt;</description></item><item><title>Cycles &amp; Timing</title><link>https://cdeever.github.io/atari-vcs/docs/6502-basics/cycles-and-timing/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://cdeever.github.io/atari-vcs/docs/6502-basics/cycles-and-timing/</guid><description>&lt;h1 id="cycles--timing"&gt;Cycles &amp;amp; Timing&lt;a class="anchor" href="#cycles--timing"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;On most computers an instruction&amp;rsquo;s cycle count is trivia. On the VCS it is the &lt;strong&gt;central fact of the craft&lt;/strong&gt;: every visible scanline is &lt;a href="https://cdeever.github.io/atari-vcs/docs/tia-racing-the-beam/"&gt;76 CPU cycles&lt;/a&gt;, and a kernel that needs 77 doesn&amp;rsquo;t run slow — it tears the picture. This page is the reference for counting them.&lt;/p&gt;
&lt;p&gt;A &amp;ldquo;machine cycle&amp;rdquo; is one tick of the 6507&amp;rsquo;s ~1.19 MHz clock; the TIA runs at three times that, so &lt;strong&gt;one CPU cycle = three color clocks (three pixels)&lt;/strong&gt;. You budget in CPU cycles and the picture pays out in pixels.&lt;/p&gt;</description></item><item><title>The Stack &amp; Subroutines</title><link>https://cdeever.github.io/atari-vcs/docs/6502-basics/stack-and-subroutines/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://cdeever.github.io/atari-vcs/docs/6502-basics/stack-and-subroutines/</guid><description>&lt;h1 id="the-stack--subroutines"&gt;The Stack &amp;amp; Subroutines&lt;a class="anchor" href="#the-stack--subroutines"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;The &lt;strong&gt;stack&lt;/strong&gt; is the 6502&amp;rsquo;s scratch area for return addresses and saved values, and subroutines (&lt;code&gt;JSR&lt;/code&gt;/&lt;code&gt;RTS&lt;/code&gt;) are built on it. On most 6502 systems it&amp;rsquo;s an afterthought. On the VCS it deserves real care, because the stack and your variables &lt;strong&gt;share the same 128 bytes of RAM&lt;/strong&gt; — and can run into each other.&lt;/p&gt;
&lt;h2 id="how-the-stack-works"&gt;How the stack works&lt;a class="anchor" href="#how-the-stack-works"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The stack pointer &lt;strong&gt;S&lt;/strong&gt; is an 8-bit offset into a fixed region, and it grows &lt;em&gt;downward&lt;/em&gt;:&lt;/p&gt;</description></item></channel></rss>