<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.temlib.org/AtariForumWiki/index.php?action=history&amp;feed=atom&amp;title=Earxtutchap2</id>
	<title>Earxtutchap2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.temlib.org/AtariForumWiki/index.php?action=history&amp;feed=atom&amp;title=Earxtutchap2"/>
	<link rel="alternate" type="text/html" href="https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;action=history"/>
	<updated>2026-07-26T07:36:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.2</generator>
	<entry>
		<id>https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;diff=13010&amp;oldid=prev</id>
		<title>&gt;Wongck at 15:30, 12 October 2011</title>
		<link rel="alternate" type="text/html" href="https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;diff=13010&amp;oldid=prev"/>
		<updated>2011-10-12T15:30:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:30, 12 October 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l432&quot;&gt;Line 432:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 432:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Back to [[ASM_Tutorial]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Back to [[ASM_Tutorial]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Programming&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Making optimized assembly code by Earx&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>&gt;Wongck</name></author>
	</entry>
	<entry>
		<id>https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;diff=13009&amp;oldid=prev</id>
		<title>&gt;Silver Surfer: Added category</title>
		<link rel="alternate" type="text/html" href="https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;diff=13009&amp;oldid=prev"/>
		<updated>2009-05-02T17:10:06Z</updated>

		<summary type="html">&lt;p&gt;Added category&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:10, 2 May 2009&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l432&quot;&gt;Line 432:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 432:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Back to [[ASM_Tutorial]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Back to [[ASM_Tutorial]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Programming]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>&gt;Silver Surfer</name></author>
	</entry>
	<entry>
		<id>https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;diff=13008&amp;oldid=prev</id>
		<title>&gt;Zorro 2 at 08:07, 9 October 2006</title>
		<link rel="alternate" type="text/html" href="https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;diff=13008&amp;oldid=prev"/>
		<updated>2006-10-09T08:07:06Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 04:07, 9 October 2006&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l430&quot;&gt;Line 430:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 430:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;                        understands.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;                        understands.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Back to [[ASM_Tutorial]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>&gt;Zorro 2</name></author>
	</entry>
	<entry>
		<id>https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;diff=13007&amp;oldid=prev</id>
		<title>&gt;Simonsunnyboy at 17:45, 6 October 2006</title>
		<link rel="alternate" type="text/html" href="https://www.temlib.org/AtariForumWiki/index.php?title=Earxtutchap2&amp;diff=13007&amp;oldid=prev"/>
		<updated>2006-10-06T17:45:30Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
              .               .      _      *     .&lt;br /&gt;
                      *             / \                 *&lt;br /&gt;
    .          .  *        CHAPTER 2 : PIXELPUSHING            .&lt;br /&gt;
          .              *          \_/          .      .&lt;br /&gt;
&lt;br /&gt;
This part of the book is all about the basics of Atari graphics. To put&lt;br /&gt;
something on the screen (a pixel for instance), you need to put your&lt;br /&gt;
CPU in a special mode called SuPeRViSoRMoDe.. This allows you machine&lt;br /&gt;
(and program) to access all kinds of chips that normally can't be&lt;br /&gt;
approached. If you should try to access those nasty chips in the normal&lt;br /&gt;
mode, you'll get two bombs on screen. So, here's how you set the Super-&lt;br /&gt;
visormode:&lt;br /&gt;
&lt;br /&gt;
        clr.l   -(sp)&lt;br /&gt;
        move.w  #32,-(sp)&lt;br /&gt;
        trap    #1&lt;br /&gt;
        addq.l  #6,sp&lt;br /&gt;
&lt;br /&gt;
Now a longword that is very important is put in register D0 by the system.&lt;br /&gt;
You should back this up somewhere in the memory, because you need it to&lt;br /&gt;
return safely to the desktop. It's called the User-stackpointer so you&lt;br /&gt;
should put it under a label called something like 'oldsp' or 'old_stack'&lt;br /&gt;
or something. Here we go:&lt;br /&gt;
&lt;br /&gt;
        move.l  d0,oldsp&lt;br /&gt;
&lt;br /&gt;
If you want to exit your program you should use the 'oldsp' value again&lt;br /&gt;
and do like this before calling you termination routine:&lt;br /&gt;
&lt;br /&gt;
        move.l  oldsp,-(sp)&lt;br /&gt;
        move.w  #32,-(sp)&lt;br /&gt;
        trap    #1&lt;br /&gt;
        addq    #6,sp&lt;br /&gt;
&lt;br /&gt;
You should reserve a LONGWORD for 'oldsp' like this:&lt;br /&gt;
&lt;br /&gt;
oldsp:  ds.l    1&lt;br /&gt;
&lt;br /&gt;
You probably know that you need something called a screenaddress. This is&lt;br /&gt;
simply a 24 bits long number that points to the first pixel on screen. In&lt;br /&gt;
order to get the screenaddress you can use a systemroutine. Just type in&lt;br /&gt;
this:&lt;br /&gt;
&lt;br /&gt;
        move    #2,-(sp)&lt;br /&gt;
        trap    #14&lt;br /&gt;
        addq    #2,sp&lt;br /&gt;
&lt;br /&gt;
The screenaddress is returned in d0, so you can now put in an&lt;br /&gt;
addressregister with something like:&lt;br /&gt;
&lt;br /&gt;
        move.l  d0,a0&lt;br /&gt;
&lt;br /&gt;
Now it's time to put a pixel on screen.&lt;br /&gt;
&lt;br /&gt;
        move.w  #$ffff,(a0)&lt;br /&gt;
&lt;br /&gt;
This makes the first pixel in the screen white. Simply moving to the next&lt;br /&gt;
pixel is done with:&lt;br /&gt;
&lt;br /&gt;
        move.w  #$ffff,(a0)+&lt;br /&gt;
&lt;br /&gt;
But this only goes for the Falcon truecolor mode. This mode is far more&lt;br /&gt;
easy to use than the normal ST resolutions. The ST uses a type of screen-&lt;br /&gt;
layout known as BITPLANES.. (aaarrrggghh!) You might also know that the&lt;br /&gt;
ST works with a pallette of 16 colors. This makes 4 bits for every color.&lt;br /&gt;
(If you didn't know that please don't continue to read this..)&lt;br /&gt;
&lt;br /&gt;
A complete ST-LOW screen of 320*200 4bit pixels makes up a total of&lt;br /&gt;
320*200*4 bits = 256000 bits = 32000 bytes. Each screenline has 320*4 =&lt;br /&gt;
1280 bits = 160 bytes.&lt;br /&gt;
&lt;br /&gt;
Each of those 4-bit values points to a piece of color information the video-&lt;br /&gt;
chip can use. Now you probably assume that the screenbuffer just consists of&lt;br /&gt;
a bucketload of 4-bit values just put next to each other, like this:&lt;br /&gt;
&lt;br /&gt;
1st pix  2nd pix  3rd pix  4th pix  5th pix  6th pix&lt;br /&gt;
&lt;br /&gt;
|  0110  |  0101  |  0000  |  1100  |  0110  |  1001  | -&amp;gt; etc -&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     1st byte           2nd byte          3rd byte&lt;br /&gt;
&lt;br /&gt;
I'm very sorry but it just isn't as logical as this.... :( It would have&lt;br /&gt;
been much nicer if Atari had done like the above method, because it's much&lt;br /&gt;
handier for 3d and easier to understand for beginners. Here's how the&lt;br /&gt;
situation really is:&lt;br /&gt;
&lt;br /&gt;
4 bitplane mode (ST LOW):&lt;br /&gt;
&lt;br /&gt;
  1 word &lt;br /&gt;
 /      \&lt;br /&gt;
 ------- ------- ------- ------- ------- ------- ------- -------&lt;br /&gt;
|plane 0|plane 1|plane 2|plane 3|plane 0|plane 1|plane 2|plane 3| etc.&lt;br /&gt;
 ------- ------- ------- ------- ------- ------- ------- -------&lt;br /&gt;
&lt;br /&gt;
A bundle of 4 consequent words make up 16 pixels in the screen. There are&lt;br /&gt;
20 of such bundles (or chunks or whatever you want to call them) in one&lt;br /&gt;
screenline (20*16 = 320 pixels).&lt;br /&gt;
&lt;br /&gt;
                        value of 1st pixel&lt;br /&gt;
  +------------------+-------0110-------+------------------+&lt;br /&gt;
  |                  |                  |                  |&lt;br /&gt;
| 0101101011100100 | 1011100101101110 | 1100001100011010 | 0101010101110101&lt;br /&gt;
&lt;br /&gt;
1st word           2nd word           3rd word           4th word&lt;br /&gt;
&lt;br /&gt;
(This value is 0110 so that's &amp;gt; color 6 &amp;lt; in plain English)&lt;br /&gt;
&lt;br /&gt;
Yikes! That is indeed a whole lot more complicated!! You see the actual&lt;br /&gt;
value of each consequent pixel is got out of the consequent bits from&lt;br /&gt;
4 consequent words.. Sounds difficult? In order to code well on an ST you&lt;br /&gt;
should at least have figured out how this works. I'm gonna give you some&lt;br /&gt;
more examples:&lt;br /&gt;
&lt;br /&gt;
                        value of 2nd pixel&lt;br /&gt;
   +------------------+-------1101-------+------------------+&lt;br /&gt;
   |                  |                  |                  |&lt;br /&gt;
| 0101101011100100 | 1011100101101110 | 1100001100011010 | 0101010101110101&lt;br /&gt;
&lt;br /&gt;
1st word           2nd word           3rd word           4th word&lt;br /&gt;
&lt;br /&gt;
( &amp;gt; color 13 &amp;lt; )&lt;br /&gt;
&lt;br /&gt;
For the next pixel you just take the bits that are positioned right from&lt;br /&gt;
the current bit in each word. Putting all those bits toghether in one 4-bit&lt;br /&gt;
number gives the actual code.&lt;br /&gt;
&lt;br /&gt;
When you reach the seventeenth pixel you need to move on to the next 4&lt;br /&gt;
words. This is because each of those 4 word blocks hold 16 pixels. Get the&lt;br /&gt;
value of the 17th pixel like this:&lt;br /&gt;
&lt;br /&gt;
                        value of 17th pixel&lt;br /&gt;
  +------------------+-------0111-------+------------------+&lt;br /&gt;
  |                  |                  |                  |&lt;br /&gt;
| 1101010101010100 | 1000110101110010 | 1011011100101010 | 0111010110100010&lt;br /&gt;
&lt;br /&gt;
5th word!          6th word!          7th word!          8th word!&lt;br /&gt;
&lt;br /&gt;
( &amp;gt; color 7 &amp;lt; )&lt;br /&gt;
&lt;br /&gt;
Now let's skip this confusing theory and go on with some more practical&lt;br /&gt;
approach to these bitplanes...&lt;br /&gt;
Let's assume that we got our screenaddress in a0 again! In order to make&lt;br /&gt;
the first pixel on screen color 0 you do this:&lt;br /&gt;
&lt;br /&gt;
* Clear most right bit of 1st word.&lt;br /&gt;
        andi.w  #%0111111111111111,(a0)+&lt;br /&gt;
* Clear most right bit of 2nd word.&lt;br /&gt;
        andi.w  #%0111111111111111,(a0)+&lt;br /&gt;
* Clear most right bit of 3rd word.&lt;br /&gt;
        andi.w  #%0111111111111111,(a0)+&lt;br /&gt;
* Clear most right bit if 4th word.&lt;br /&gt;
        andi.w  #%0111111111111111,(a0)+&lt;br /&gt;
&lt;br /&gt;
So now, 4 cleared bits make 0000 which happens to be color 0, hurrah!!&lt;br /&gt;
But now we want to give the pixel at the coordinates (165, 45) the color&lt;br /&gt;
11. Keep in mind that all the screenlines are directly behind eachother.&lt;br /&gt;
The upper screenline starts at offset 0, the second at 160, the third at&lt;br /&gt;
320, the fourth at 480, etc, etc.&lt;br /&gt;
&lt;br /&gt;
* First adjust the address to the right couple of words.&lt;br /&gt;
* Adjust it down 45 lines. (45 times the number of bytes in each line)&lt;br /&gt;
        adda.l  #45*160,a0&lt;br /&gt;
* Adjust it to the right 4 word block. 165pixels/16pixels per block=10&lt;br /&gt;
* So the pixel is in the 10th block on the line and each block is 8 bytes&lt;br /&gt;
* large so, you need to add 10*8.&lt;br /&gt;
        adda.l  #10*8,a0&lt;br /&gt;
* Now which pixel to address in this block? If you calculate the remainder&lt;br /&gt;
* of the 165/16 division, you've got the answer.&lt;br /&gt;
* 165 - (165/10)*10 = 165 - 16*10 = 165 - 160 = 5, or:&lt;br /&gt;
* 165 MOD 16 = 5 as some people like to put it.&lt;br /&gt;
* Set the 5th right bit in the 1st word.&lt;br /&gt;
        ori.w   #%000010000000000,(a0)+&lt;br /&gt;
* Set the 5th right bit in the 2nd word.&lt;br /&gt;
        ori.w   #%000010000000000,(a0)+&lt;br /&gt;
* Clear the 5th right bit in the 3rd word.&lt;br /&gt;
        andi.w  #%111101111111111,(a0)+&lt;br /&gt;
* Set the 5th right bit in the 4th word.&lt;br /&gt;
        ori.w   #%000010000000000,(a0)+&lt;br /&gt;
&lt;br /&gt;
So, as you can see this is a question of clearing and setting the&lt;br /&gt;
appropriate bits in the corresponding couple of words. OK, that's that for&lt;br /&gt;
those bits at the moment.&lt;br /&gt;
&lt;br /&gt;
Now, suppose you want to reconfigure all the colors in the pallette so you&lt;br /&gt;
don't have those ugly bright 16 desktop colors, but a more atmospheric&lt;br /&gt;
pallette.. For this you really need SUPERVISOR-MODE again. Make sure you&lt;br /&gt;
put that supervisor routine at the beginning of all your programs!&lt;br /&gt;
&lt;br /&gt;
OK, let's show something about those colorvalues. Everytime the Video-chip&lt;br /&gt;
converts 4-bits into a color to put on screen, it looks up the pallette&lt;br /&gt;
registers. These contain all sixteen red, green and blue brightnesses for&lt;br /&gt;
the colors.&lt;br /&gt;
&lt;br /&gt;
A colorregister is one word with bits for red green and blue.&lt;br /&gt;
&lt;br /&gt;
ST(e) Colorregister:&lt;br /&gt;
&lt;br /&gt;
+----+----+----+----+&lt;br /&gt;
|xxxx|Rrrr|Gggg|Bbbb|&lt;br /&gt;
+----+----+----+----+&lt;br /&gt;
&lt;br /&gt;
The three r's represent the brightness of red with a value that can range&lt;br /&gt;
from 0 to 7. The g's and b's do the same for the colors green and blue.&lt;br /&gt;
The x's do nothing and you don't need to mess around with these.&lt;br /&gt;
The Capital letters are for STe/Falcon/TT only. They give twice the&lt;br /&gt;
precision of brightness for each color. I won't use 'em in here, because&lt;br /&gt;
they are kinda confusing.&lt;br /&gt;
The registers are located in high memory. At $ffff8240 to $ffff8260 to be&lt;br /&gt;
exact. (These are hexa-decimal numbers. If you don't know what they are,&lt;br /&gt;
please don't go on!)&lt;br /&gt;
Now you want to make all the colors (0 to 15) bright yellow. You just set&lt;br /&gt;
the maximum of red and green(green+red makes yellow!). The value of a&lt;br /&gt;
register would look like this:&lt;br /&gt;
&lt;br /&gt;
 xxxx Rrrr Gggg Bbbb&lt;br /&gt;
+----+----+----+----+&lt;br /&gt;
|0000|0111|0111|0000|&lt;br /&gt;
+----+----+----+----+&lt;br /&gt;
&lt;br /&gt;
If you want to do this with all the registers you do this:&lt;br /&gt;
&lt;br /&gt;
        move.l  #$ffff8240,a0               * Put address of first color in a0.&lt;br /&gt;
        move.w  #16-1,d7                    * Prepare for looping 16 times.&lt;br /&gt;
loop:   move.w  #%0000011101110000,(a0)+    * Make register bright yellow.&lt;br /&gt;
        dbra    d7,loop                     * Loop 16 times.&lt;br /&gt;
&lt;br /&gt;
Make sure you set supervisor mode first! Now you have a totally yellow&lt;br /&gt;
screen. You now see how easy it is to change the color in the 16 color mode.&lt;br /&gt;
If you wanted to do this in Falcon True color it would be very easy to code&lt;br /&gt;
as well. The principles are a bit different, but it's not a bit harder. It's&lt;br /&gt;
only takes the CPU much longer to execute! Since you have no pallette in&lt;br /&gt;
True-color you need to adjust the color for every pixel!&lt;br /&gt;
But OK, let's explain how a Falcon-16 bit pixel is put together. It's a bit&lt;br /&gt;
like the pallette register of the ST(e):&lt;br /&gt;
&lt;br /&gt;
Falcon 16-bit truecolor pixel:&lt;br /&gt;
&lt;br /&gt;
+-----+------+-----+&lt;br /&gt;
|rrrrr|gggggg|bbbbb|&lt;br /&gt;
+-----+------+-----+&lt;br /&gt;
&lt;br /&gt;
The r's give the value of red from 0 to 31. The g's give the value of green&lt;br /&gt;
from 0 to 63. The b's give the value of blue from 0 to 31.&lt;br /&gt;
&lt;br /&gt;
Now for the routine (the screenaddress is in a0):&lt;br /&gt;
&lt;br /&gt;
        move.w  #64000-1,d7                 * Prepare for looping 64000 times.&lt;br /&gt;
loop:   move.w  #%1111111111100000,(a0)+    * Make a pixel yellow.&lt;br /&gt;
        dbra    d7,loop                     * Loop 64000 times.&lt;br /&gt;
&lt;br /&gt;
Simple, but very SLOW, because you need to do the loop 64000 times for&lt;br /&gt;
320*200 resolution!!&lt;br /&gt;
&lt;br /&gt;
Phew! Now that that stuff is done you know some stuff about giving the&lt;br /&gt;
screen all kinds of colors for both the Falcon and the ST. With certain&lt;br /&gt;
looping structures and combinations of putting pixels you can make all sorts&lt;br /&gt;
of graphical effects. But more about that in Chapter 6.&lt;br /&gt;
What we're worried about now is the flickering of the screen when you change&lt;br /&gt;
something on screen. Let's say you want to change the 16 colors of the ST&lt;br /&gt;
when you're displaying a picture. When you do this without synchronisation&lt;br /&gt;
you'll get some ugly flickering on screen. This is because when the video-&lt;br /&gt;
chip is still transfering picture-signals to your monitor/TV the colors&lt;br /&gt;
change in the middle of the screen. Sounds difficult? I'll explain here:&lt;br /&gt;
&lt;br /&gt;
Let's assume your whole screenbuffer is filled with color 3. In the curremt&lt;br /&gt;
situation this is blue. You want to change it to red....&lt;br /&gt;
&lt;br /&gt;
Picture 1:&lt;br /&gt;
&lt;br /&gt;
Color 3 is still blue. The Video-chip is halfway through reading the buffer&lt;br /&gt;
and so the monitor is halfway through refreshing the picture on screen.&lt;br /&gt;
&lt;br /&gt;
                        +------------+&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;|&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;|&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;      |&lt;br /&gt;
                        |            |&lt;br /&gt;
                        +------------+&lt;br /&gt;
&lt;br /&gt;
&amp;quot; = blue&lt;br /&gt;
&lt;br /&gt;
The current position of where the screen is refreshing is where the &amp;quot;'s end.&lt;br /&gt;
&lt;br /&gt;
Picture 2:&lt;br /&gt;
&lt;br /&gt;
The palette is now changed and color 3 becomes red. The screen is now&lt;br /&gt;
updates a bit further and you can see blue bits are still on screen!!&lt;br /&gt;
&lt;br /&gt;
                        +------------+&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;|&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;|&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;!!    |&lt;br /&gt;
                        |            |&lt;br /&gt;
                        +------------+&lt;br /&gt;
&lt;br /&gt;
&amp;quot; = blue  ! = red&lt;br /&gt;
&lt;br /&gt;
The current position of refreshing is where the !'s end.&lt;br /&gt;
&lt;br /&gt;
Picture 3:&lt;br /&gt;
&lt;br /&gt;
The video-chip finishes reading the screenbuffer and the monitor finishes&lt;br /&gt;
refreshing. The upper half of the screen is now blue and the lower half is&lt;br /&gt;
red!!&lt;br /&gt;
&lt;br /&gt;
                        +------------+&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;|&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;|&lt;br /&gt;
                        |&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;&amp;quot;!!!!!!|&lt;br /&gt;
                        |!!!!!!!!!!!!|&lt;br /&gt;
                        +------------+&lt;br /&gt;
&lt;br /&gt;
&amp;quot; = blue  ! = red&lt;br /&gt;
&lt;br /&gt;
Now the monitor and video-chip have stopped reading/refreshing for a moment&lt;br /&gt;
and went into Vertical Blank. This is a moment when the monitor adjusts the&lt;br /&gt;
Cathode Ray Tube to start in the top-left corner again. In this so called&lt;br /&gt;
Vertical Blank or VBL nothing is put on screen... Conclusion: if you want&lt;br /&gt;
flickerless colorchanging you need to adjust the colors in the VBL!!&lt;br /&gt;
OK, you say, but how do I do this in assembly code Mr. Smartypants? Well,&lt;br /&gt;
you can easily do this with a systemroutine:&lt;br /&gt;
&lt;br /&gt;
        move.w  #37,-(sp)&lt;br /&gt;
        trap    #14&lt;br /&gt;
        addq    #2,sp&lt;br /&gt;
&lt;br /&gt;
This simply waits and executes no other instructions untill the VBL is&lt;br /&gt;
reached. If you simply put this in your code before you start kicking around&lt;br /&gt;
some pixels, you will have no flickering! Yeh!!&lt;br /&gt;
&lt;br /&gt;
This VBL-syncing stuff works fair enough with only a few pixels on screen,&lt;br /&gt;
but still you need one extra trick if the drawing of graphics costs quite&lt;br /&gt;
alot of time. You remember the funky ASCII representations of our screen&lt;br /&gt;
=) ? Well, even if you start drawing when a VBL occurs, the CRT can catch up&lt;br /&gt;
with your drawing in the screenbuffer and again you've got flickering.&lt;br /&gt;
&lt;br /&gt;
What to do about this now? '!|: Double bufferinG :|!'&lt;br /&gt;
Always draw your pixeldata on a screenbuffer that isn't read by the&lt;br /&gt;
videochip. When you've finished drawing, wait until the VBL occurs and then&lt;br /&gt;
give the screenbuffer-address to the videochip. When drawing the next frame&lt;br /&gt;
for your animation you draw to another screenbuffers (yes, you have TWO&lt;br /&gt;
screenbuffers, hence the word &amp;quot;double&amp;quot; in double buffering =)).&lt;br /&gt;
&lt;br /&gt;
The code will now look like this:&lt;br /&gt;
&lt;br /&gt;
*=/\_ Funky '!|Double buffeR|!' examplE _/\====================================&lt;br /&gt;
&lt;br /&gt;
* 0) Initialize screenaddresses.&lt;br /&gt;
* The basic ST(fm) must always have it's screenaddress aligned on a 256 byte&lt;br /&gt;
* boundary. Keep this in mind when coding for a basic ST!&lt;br /&gt;
        move.l  #screenbuffer+255,d0            * Get bufferaddress+256 in d0.&lt;br /&gt;
        sub.b   d0,d0                           * Make it 256 byte aligned.&lt;br /&gt;
        move.l  d0,physical_screen              * Store first address.&lt;br /&gt;
        addi.l  #160*200,d0                     * Move to next screenaddress.&lt;br /&gt;
        move.l  d0,logical_screen               * Store second address.&lt;br /&gt;
&lt;br /&gt;
drawing_loop:&lt;br /&gt;
* 1) Draw some stuff on the logical screen.&lt;br /&gt;
;&lt;br /&gt;
;&lt;br /&gt;
&lt;br /&gt;
* 2) Swap the screenaddresses. i.e. swap the logical and physical addresses.&lt;br /&gt;
        move.l  logical_screen,d0&lt;br /&gt;
        move.l  physical_screen,logical_screen&lt;br /&gt;
        move.l  d0,physical_screen&lt;br /&gt;
* 3) Kick in the new physical screen.&lt;br /&gt;
        lsr.w   #8,d0                           * Get mid byte in low byte.&lt;br /&gt;
        move.l  d0,$ffff8200.w                  * Kick in new screenaddress.&lt;br /&gt;
* 4) Wait for the VBL...&lt;br /&gt;
        move.w  #37,-(sp)&lt;br /&gt;
        trap    #14&lt;br /&gt;
        addq    #2,sp&lt;br /&gt;
&lt;br /&gt;
        bra     drawing_loop                    * And loop once more...&lt;br /&gt;
&lt;br /&gt;
******** DATA MEMORY SECTION ********&lt;br /&gt;
&lt;br /&gt;
        DATA&lt;br /&gt;
&lt;br /&gt;
physical_screen:&lt;br /&gt;
        DS.L    1                               * Address of visible screen.&lt;br /&gt;
logical_screen:&lt;br /&gt;
        DS.L    1                               * Address of invisible screen.&lt;br /&gt;
&lt;br /&gt;
******** RESERVED MEMORY SECTION ********&lt;br /&gt;
&lt;br /&gt;
        BSS&lt;br /&gt;
&lt;br /&gt;
screenbuffer:&lt;br /&gt;
        DS.B        256                         * For 256 byte aligning!&lt;br /&gt;
        DS.B        160*200                     * Reserve one ST-LOW screen.&lt;br /&gt;
        DS.B        160*200                     * Reserve one ST-LOW screen.&lt;br /&gt;
&lt;br /&gt;
*==============================================================================&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, that's about all for this chapter. I hope you now know the basics of&lt;br /&gt;
how you can put something on screen. Here's a summary of what you have seen&lt;br /&gt;
in this chapter. I hope you remember them:&lt;br /&gt;
&lt;br /&gt;
Bitplanes:             A couple of words(16-bits) in the screenbuffer that&lt;br /&gt;
                       contain the bits of 16 pixels in a very illogical order.&lt;br /&gt;
Cathode Ray Tube:      The tube in a TV or monitor that spits out electrons&lt;br /&gt;
                       on the phospor-screen so that you can see colors.&lt;br /&gt;
Double buffering:      Technique used to avoid flickering and stripes on the&lt;br /&gt;
                       screen. Without this, no flickerless animation! Used in&lt;br /&gt;
                       combination with VBL-syncing.&lt;br /&gt;
DS:                    Assembler command used for reserving memory space at an&lt;br /&gt;
                       address (label).&lt;br /&gt;
Flickering:            Flickering of the picture on screen.&lt;br /&gt;
Logical screen:        The actual invisible screen.&lt;br /&gt;
Pallette-registers:    The 16 hardware registers that contain red, green and&lt;br /&gt;
                       blue values for each value that is read from the&lt;br /&gt;
                       bitplanes. They are used for the ST 16 color mode.&lt;br /&gt;
Physical screen:       The actual visible screen.&lt;br /&gt;
Screenaddress:         The address of the first pixel or bitplane in the&lt;br /&gt;
                       screenmemory. In the Atari the screenmemory is held&lt;br /&gt;
                       in the main RAM.&lt;br /&gt;
Supervisor-mode:       A special mode your 680x0 needs to be in access&lt;br /&gt;
                       pallette-registers and other nasty bits.&lt;br /&gt;
User-stackpointer:     A value that needs to be saved when you called the&lt;br /&gt;
                       supervisor-setting routine. It needs to be given to&lt;br /&gt;
                       the routine that exits supervisor-mode.&lt;br /&gt;
Vertical Blank or VBL: A period when the monitor and video-chip have stopped&lt;br /&gt;
                       reading/refreshing and nothing is put on screen.&lt;br /&gt;
Video-chip:            A chip in your Atari that reads from the screen-&lt;br /&gt;
                       memory/pallette register and converts the digital&lt;br /&gt;
                       color-values into a analog signal that your monitor&lt;br /&gt;
                       understands.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>&gt;Simonsunnyboy</name></author>
	</entry>
</feed>