<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.sizecoding.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=42Bastian</id>
		<title>SizeCoding - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://www.sizecoding.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=42Bastian"/>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/wiki/Special:Contributions/42Bastian"/>
		<updated>2026-05-01T23:52:08Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.0</generator>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=Atari_Jaguar&amp;diff=1124</id>
		<title>Atari Jaguar</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Atari_Jaguar&amp;diff=1124"/>
				<updated>2022-03-11T12:07:30Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: /* Sound */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Atari Jaguar ==&lt;br /&gt;
The Atari Jaguar is a home video game console developed by Atari Corporation and released in North America in November 1993. Part of the fifth generation of video game consoles, it competed with the 16-bit Sega Genesis and Super NES and the 32-bit 3DO Interactive Multiplayer that launched the same year. Despite its two custom 32-bit processors — Tom and Jerry — in addition to a Motorola 68000, Atari marketed it as the world's first 64-bit game system, emphasizing its 64-bit bus used by the blitter.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* Assembler: &lt;br /&gt;
There are several approaches to the Jaguar. The most complete is likely [https://reboot-games.com/jagstudio/ JagStudio] but it is mainly used for C (or BASIC with a BASIC to C converter).&lt;br /&gt;
&lt;br /&gt;
[https://github.com/42Bastian/new_bjl new_bjl] is currently evolving from old BJL and is focused on Assembly.&lt;br /&gt;
&lt;br /&gt;
* Emulator(s): &lt;br /&gt;
There are quiet some emulators around, like Phoenix, Project Tempest and VisualJaguar. Of the VisualJaguar exist a [https://github.com/djipi/Virtual-Jaguar-Rx port] which allows minimal debugging.&lt;br /&gt;
&lt;br /&gt;
In common of all these emulators is, that they are not 100% accurate. Not cycle wise and also hardware register wise. But [https://github.com/djipi/Virtual-Jaguar-Rx Virtual-Jaguar-Rx ] is actively developed.&lt;br /&gt;
&lt;br /&gt;
* Hardware:&lt;br /&gt;
In order to test the final result one should have a [https://www.retrohq.co.uk/products/atari-jaguar-gd-flash-cartridge Jaguar GameDrive] which allows booting the final ROM as a normal card.&lt;br /&gt;
For development a [https://atariage.com/forums/topic/201788-everything-you-wanted-to-know-about-the-skunkboard/ SKUNK board] is a cheaper solution.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
&lt;br /&gt;
The JAGUAR is video wise a complicated beast. It can display up to 720x240 pixels in various ways.&lt;br /&gt;
This can be 24 bit RGB, 16 bit RGB, 16bit CRY (a special color format) and CLUT modes (which use either 16bit mode).&lt;br /&gt;
&lt;br /&gt;
CRY use 8bit for the color and 8bit for luminosity.&lt;br /&gt;
&lt;br /&gt;
The OP (object processor) handles all this. It can be used as sprite engine displaying multiple objects at different positions on the screen. Some them even scaled or reflected.&lt;br /&gt;
But since a simple object needs already 16bytes (JAGUAR talk: two phrases) it is likely that intros with less or equal 512bytes won't exploit all its features.&lt;br /&gt;
The objects are stored in an object list which start is given the OP. It will run through the list for every scan line to check if some shall be displayed.&lt;br /&gt;
&lt;br /&gt;
For a start a bitmap object of a 320x240x8 frame buffer would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
OBL0:&lt;br /&gt;
	.objproc&lt;br /&gt;
	.org	$10000&lt;br /&gt;
	bitmap screen, 9, 41, 320/8, 320/8, 240, 3, 0, NOTRANS, 0 ,1&lt;br /&gt;
        stop&lt;br /&gt;
	.68000&lt;br /&gt;
OBL0_end:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
The pity about the OP is, that is _consumes_ the object list. Means certain parts are modified and must be restored every vertical blank.&lt;br /&gt;
&lt;br /&gt;
The above example place a bitmap object at &amp;lt;code&amp;gt;(9/41)&amp;lt;/code&amp;gt;. The data is stored at &amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt; and uses 8 bits (1 &amp;lt;&amp;lt; &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;). A specialty is that widths of objects are always in phrases (8bytes), therefore we have to divide &amp;lt;code&amp;gt;320&amp;lt;/code&amp;gt;by 8. The first &amp;lt;code&amp;gt;320/8&amp;lt;/code&amp;gt; defines the displayed image width, the second the width of the image.&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;0, NOTRANS, 0 ,1&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; defines the CLUT index to be added,&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;NOTRANS&amp;lt;/code&amp;gt; makes the object opaque, else color index 0 is transparent&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; defines the first pixel, this allows pixel wise scrolling&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; is the pitch, that is the distance from one phrase to another. This is mainly used for Z buffering to store the Z information along the pixel without displaying them.&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
&lt;br /&gt;
The JAGUAR does not have a sound chip but only a DAC which is connected via I²S interface. &amp;lt;br&amp;gt;&lt;br /&gt;
A minimal setup needs to initialize the I²S baudrate and the just write at a desired frequency data to the send registers.&lt;br /&gt;
&lt;br /&gt;
This will enable a sampleing rate of 24kHz.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
;; I2S&lt;br /&gt;
move.l	#26600000/64/24000,$f1a150&lt;br /&gt;
moveq.l	#5,d0&lt;br /&gt;
move.l	d0,$f1a150&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below code will out put a saw tooth with 8kHz:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  // setup a counter which counts from 0...$ffff with 8kHz&lt;br /&gt;
  move.l #(3324&amp;lt;&amp;lt;16)|$ffff,$F10000&lt;br /&gt;
  suba.l a4,a4&lt;br /&gt;
main:&lt;br /&gt;
  // wait for a change&lt;br /&gt;
  move.w $f10038,d6&lt;br /&gt;
  cmp.w	d6,a4&lt;br /&gt;
  beq.s	main&lt;br /&gt;
  move.w d6,a4&lt;br /&gt;
  // send to DAC&lt;br /&gt;
  move.l d6, $f1a148 &lt;br /&gt;
  bra.s main&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* [https://github.com/42Bastian/new_bjl/tree/main/exp Sourcecode for various Sizecoded Atari Jaguar intros]&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=Atari_Jaguar&amp;diff=1123</id>
		<title>Atari Jaguar</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Atari_Jaguar&amp;diff=1123"/>
				<updated>2022-03-11T12:07:08Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: /* Sound */ 1st&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Atari Jaguar ==&lt;br /&gt;
The Atari Jaguar is a home video game console developed by Atari Corporation and released in North America in November 1993. Part of the fifth generation of video game consoles, it competed with the 16-bit Sega Genesis and Super NES and the 32-bit 3DO Interactive Multiplayer that launched the same year. Despite its two custom 32-bit processors — Tom and Jerry — in addition to a Motorola 68000, Atari marketed it as the world's first 64-bit game system, emphasizing its 64-bit bus used by the blitter.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* Assembler: &lt;br /&gt;
There are several approaches to the Jaguar. The most complete is likely [https://reboot-games.com/jagstudio/ JagStudio] but it is mainly used for C (or BASIC with a BASIC to C converter).&lt;br /&gt;
&lt;br /&gt;
[https://github.com/42Bastian/new_bjl new_bjl] is currently evolving from old BJL and is focused on Assembly.&lt;br /&gt;
&lt;br /&gt;
* Emulator(s): &lt;br /&gt;
There are quiet some emulators around, like Phoenix, Project Tempest and VisualJaguar. Of the VisualJaguar exist a [https://github.com/djipi/Virtual-Jaguar-Rx port] which allows minimal debugging.&lt;br /&gt;
&lt;br /&gt;
In common of all these emulators is, that they are not 100% accurate. Not cycle wise and also hardware register wise. But [https://github.com/djipi/Virtual-Jaguar-Rx Virtual-Jaguar-Rx ] is actively developed.&lt;br /&gt;
&lt;br /&gt;
* Hardware:&lt;br /&gt;
In order to test the final result one should have a [https://www.retrohq.co.uk/products/atari-jaguar-gd-flash-cartridge Jaguar GameDrive] which allows booting the final ROM as a normal card.&lt;br /&gt;
For development a [https://atariage.com/forums/topic/201788-everything-you-wanted-to-know-about-the-skunkboard/ SKUNK board] is a cheaper solution.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
&lt;br /&gt;
The JAGUAR is video wise a complicated beast. It can display up to 720x240 pixels in various ways.&lt;br /&gt;
This can be 24 bit RGB, 16 bit RGB, 16bit CRY (a special color format) and CLUT modes (which use either 16bit mode).&lt;br /&gt;
&lt;br /&gt;
CRY use 8bit for the color and 8bit for luminosity.&lt;br /&gt;
&lt;br /&gt;
The OP (object processor) handles all this. It can be used as sprite engine displaying multiple objects at different positions on the screen. Some them even scaled or reflected.&lt;br /&gt;
But since a simple object needs already 16bytes (JAGUAR talk: two phrases) it is likely that intros with less or equal 512bytes won't exploit all its features.&lt;br /&gt;
The objects are stored in an object list which start is given the OP. It will run through the list for every scan line to check if some shall be displayed.&lt;br /&gt;
&lt;br /&gt;
For a start a bitmap object of a 320x240x8 frame buffer would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
OBL0:&lt;br /&gt;
	.objproc&lt;br /&gt;
	.org	$10000&lt;br /&gt;
	bitmap screen, 9, 41, 320/8, 320/8, 240, 3, 0, NOTRANS, 0 ,1&lt;br /&gt;
        stop&lt;br /&gt;
	.68000&lt;br /&gt;
OBL0_end:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
The pity about the OP is, that is _consumes_ the object list. Means certain parts are modified and must be restored every vertical blank.&lt;br /&gt;
&lt;br /&gt;
The above example place a bitmap object at &amp;lt;code&amp;gt;(9/41)&amp;lt;/code&amp;gt;. The data is stored at &amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt; and uses 8 bits (1 &amp;lt;&amp;lt; &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;). A specialty is that widths of objects are always in phrases (8bytes), therefore we have to divide &amp;lt;code&amp;gt;320&amp;lt;/code&amp;gt;by 8. The first &amp;lt;code&amp;gt;320/8&amp;lt;/code&amp;gt; defines the displayed image width, the second the width of the image.&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;0, NOTRANS, 0 ,1&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; defines the CLUT index to be added,&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;NOTRANS&amp;lt;/code&amp;gt; makes the object opaque, else color index 0 is transparent&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; defines the first pixel, this allows pixel wise scrolling&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; is the pitch, that is the distance from one phrase to another. This is mainly used for Z buffering to store the Z information along the pixel without displaying them.&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
&lt;br /&gt;
The JAGUAR does not have a sound chip but only a DAC which is connected via I²S interface. &amp;lt;br&amp;gt;&lt;br /&gt;
A minimal setup needs to initialize the I²S baudrate and the just write at a desired frequency data to the send registers.&lt;br /&gt;
&lt;br /&gt;
This will enable a sampleing rate of 24kHz.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
;; I2S&lt;br /&gt;
move.l	#26600000/64/24000,$f1a150&lt;br /&gt;
moveq.l	#5,d0&lt;br /&gt;
move.l	d0,$f1a150&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Below code will out put a saw tooth with 8kHz:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  // setup a counter which counts from 0...$ffff with 8kHz&lt;br /&gt;
  move.l #(3324&amp;lt;&amp;lt;16)|$ffff,$F10000&lt;br /&gt;
  suba.l a4,a4&lt;br /&gt;
main:&lt;br /&gt;
  // wait for a change&lt;br /&gt;
  move.w $f10038,d6&lt;br /&gt;
  cmp.w	d6,a4&lt;br /&gt;
  beq.s	main&lt;br /&gt;
  move.w d6,a4&lt;br /&gt;
  // send to DAC&lt;br /&gt;
  move.l d6, $f1a148 &lt;br /&gt;
  bra.s main&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* [https://github.com/42Bastian/new_bjl/tree/main/exp Sourcecode for various Sizecoded Atari Jaguar intros]&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=Atari_Jaguar&amp;diff=1122</id>
		<title>Atari Jaguar</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Atari_Jaguar&amp;diff=1122"/>
				<updated>2022-03-11T11:56:14Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: /* Video display */ 1st&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Atari Jaguar ==&lt;br /&gt;
The Atari Jaguar is a home video game console developed by Atari Corporation and released in North America in November 1993. Part of the fifth generation of video game consoles, it competed with the 16-bit Sega Genesis and Super NES and the 32-bit 3DO Interactive Multiplayer that launched the same year. Despite its two custom 32-bit processors — Tom and Jerry — in addition to a Motorola 68000, Atari marketed it as the world's first 64-bit game system, emphasizing its 64-bit bus used by the blitter.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* Assembler: &lt;br /&gt;
There are several approaches to the Jaguar. The most complete is likely [https://reboot-games.com/jagstudio/ JagStudio] but it is mainly used for C (or BASIC with a BASIC to C converter).&lt;br /&gt;
&lt;br /&gt;
[https://github.com/42Bastian/new_bjl new_bjl] is currently evolving from old BJL and is focused on Assembly.&lt;br /&gt;
&lt;br /&gt;
* Emulator(s): &lt;br /&gt;
There are quiet some emulators around, like Phoenix, Project Tempest and VisualJaguar. Of the VisualJaguar exist a [https://github.com/djipi/Virtual-Jaguar-Rx port] which allows minimal debugging.&lt;br /&gt;
&lt;br /&gt;
In common of all these emulators is, that they are not 100% accurate. Not cycle wise and also hardware register wise. But [https://github.com/djipi/Virtual-Jaguar-Rx Virtual-Jaguar-Rx ] is actively developed.&lt;br /&gt;
&lt;br /&gt;
* Hardware:&lt;br /&gt;
In order to test the final result one should have a [https://www.retrohq.co.uk/products/atari-jaguar-gd-flash-cartridge Jaguar GameDrive] which allows booting the final ROM as a normal card.&lt;br /&gt;
For development a [https://atariage.com/forums/topic/201788-everything-you-wanted-to-know-about-the-skunkboard/ SKUNK board] is a cheaper solution.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
&lt;br /&gt;
The JAGUAR is video wise a complicated beast. It can display up to 720x240 pixels in various ways.&lt;br /&gt;
This can be 24 bit RGB, 16 bit RGB, 16bit CRY (a special color format) and CLUT modes (which use either 16bit mode).&lt;br /&gt;
&lt;br /&gt;
CRY use 8bit for the color and 8bit for luminosity.&lt;br /&gt;
&lt;br /&gt;
The OP (object processor) handles all this. It can be used as sprite engine displaying multiple objects at different positions on the screen. Some them even scaled or reflected.&lt;br /&gt;
But since a simple object needs already 16bytes (JAGUAR talk: two phrases) it is likely that intros with less or equal 512bytes won't exploit all its features.&lt;br /&gt;
The objects are stored in an object list which start is given the OP. It will run through the list for every scan line to check if some shall be displayed.&lt;br /&gt;
&lt;br /&gt;
For a start a bitmap object of a 320x240x8 frame buffer would look like this:&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
OBL0:&lt;br /&gt;
	.objproc&lt;br /&gt;
	.org	$10000&lt;br /&gt;
	bitmap screen, 9, 41, 320/8, 320/8, 240, 3, 0, NOTRANS, 0 ,1&lt;br /&gt;
        stop&lt;br /&gt;
	.68000&lt;br /&gt;
OBL0_end:&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
The pity about the OP is, that is _consumes_ the object list. Means certain parts are modified and must be restored every vertical blank.&lt;br /&gt;
&lt;br /&gt;
The above example place a bitmap object at &amp;lt;code&amp;gt;(9/41)&amp;lt;/code&amp;gt;. The data is stored at &amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt; and uses 8 bits (1 &amp;lt;&amp;lt; &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;). A specialty is that widths of objects are always in phrases (8bytes), therefore we have to divide &amp;lt;code&amp;gt;320&amp;lt;/code&amp;gt;by 8. The first &amp;lt;code&amp;gt;320/8&amp;lt;/code&amp;gt; defines the displayed image width, the second the width of the image.&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;code&amp;gt;0, NOTRANS, 0 ,1&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; defines the CLUT index to be added,&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;NOTRANS&amp;lt;/code&amp;gt; makes the object opaque, else color index 0 is transparent&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; defines the first pixel, this allows pixel wise scrolling&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; is the pitch, that is the distance from one phrase to another. This is mainly used for Z buffering to store the Z information along the pixel without displaying them.&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
No information yet&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* [https://github.com/42Bastian/new_bjl/tree/main/exp Sourcecode for various Sizecoded Atari Jaguar intros]&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=Atari_Jaguar&amp;diff=1121</id>
		<title>Atari Jaguar</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Atari_Jaguar&amp;diff=1121"/>
				<updated>2022-03-11T11:21:28Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: 1st&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Atari Jaguar ==&lt;br /&gt;
The Atari Jaguar is a home video game console developed by Atari Corporation and released in North America in November 1993. Part of the fifth generation of video game consoles, it competed with the 16-bit Sega Genesis and Super NES and the 32-bit 3DO Interactive Multiplayer that launched the same year. Despite its two custom 32-bit processors — Tom and Jerry — in addition to a Motorola 68000, Atari marketed it as the world's first 64-bit game system, emphasizing its 64-bit bus used by the blitter.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* Assembler: &lt;br /&gt;
There are several approaches to the Jaguar. The most complete is likely [https://reboot-games.com/jagstudio/ JagStudio] but it is mainly used for C (or BASIC with a BASIC to C converter).&lt;br /&gt;
&lt;br /&gt;
[https://github.com/42Bastian/new_bjl new_bjl] is currently evolving from old BJL and is focused on Assembly.&lt;br /&gt;
&lt;br /&gt;
* Emulator(s): &lt;br /&gt;
There are quiet some emulators around, like Phoenix, Project Tempest and VisualJaguar. Of the VisualJaguar exist a [https://github.com/djipi/Virtual-Jaguar-Rx port] which allows minimal debugging.&lt;br /&gt;
&lt;br /&gt;
In common of all these emulators is, that they are not 100% accurate. Not cycle wise and also hardware register wise. But [https://github.com/djipi/Virtual-Jaguar-Rx Virtual-Jaguar-Rx ] is actively developed.&lt;br /&gt;
&lt;br /&gt;
* Hardware:&lt;br /&gt;
In order to test the final result one should have a [https://www.retrohq.co.uk/products/atari-jaguar-gd-flash-cartridge Jaguar GameDrive] which allows booting the final ROM as a normal card.&lt;br /&gt;
For development a [https://atariage.com/forums/topic/201788-everything-you-wanted-to-know-about-the-skunkboard/ SKUNK board] is a cheaper solution.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
No information yet&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
No information yet&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* [https://github.com/42Bastian/new_bjl/tree/main/exp Sourcecode for various Sizecoded Atari Jaguar intros]&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=6502&amp;diff=1008</id>
		<title>6502</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=6502&amp;diff=1008"/>
				<updated>2022-01-31T09:19:56Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: /* Atari Lynx */ add some tricks&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Wanting to start sizecoding on a 6502 platform in this day and age can be tough. &lt;br /&gt;
&lt;br /&gt;
[[File:6502.jpg|thumb]]&lt;br /&gt;
&lt;br /&gt;
So here is a bit of help to get you started:&lt;br /&gt;
&lt;br /&gt;
=== The 6502 processor  ===&lt;br /&gt;
The 6502 processor can be seen as the 8-bit micro ARM chip. &lt;br /&gt;
It has only has 3 registers (Accumulator, X and Y registers) and a handful of instructions to work with.&lt;br /&gt;
&lt;br /&gt;
=== Adressing modes ===&lt;br /&gt;
To be added.&lt;br /&gt;
&lt;br /&gt;
=== Zero page ===&lt;br /&gt;
When using the 6502 for sizecoding, you'll mostly be working from zeropage&lt;br /&gt;
&lt;br /&gt;
=== General 6502 Resources ===&lt;br /&gt;
* 6502.org http://www.6502.org/&lt;br /&gt;
* 6502 instruction reference http://www.6502.org/tutorials/6502opcodes.html&lt;br /&gt;
* 6502 books http://retro.hansotten.nl/6502-sbc/&lt;br /&gt;
* 6502 Assembler tutorial https://dwheeler.com/6502/oneelkruns/asm1step.html&lt;br /&gt;
* Easy 6502 code tester https://skilldrick.github.io/easy6502/&lt;br /&gt;
* Synthetic instructions https://wiki.nesdev.com/w/index.php/Synthetic_instructions#8-bit_rotate&lt;br /&gt;
&lt;br /&gt;
== Atari 8-bit family ==&lt;br /&gt;
The systems in this family are: Atari 400, 800, 5200, 1200XL, 600XL, 800XL, 130XE, 65XE, 800XE and XEGS.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Atari 8-bit systems consists of the 6502 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari 8bit systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: MADS Assembler - This assembler has nice macros for creating Binaries and SNA snapshot files out of the box. You can download it at https://mads.atari8.info/&lt;br /&gt;
* Emulator(s): I Found Altirra to work best for my usecase. Make sure to use the original Rev2 rom for best compatibility.&lt;br /&gt;
&lt;br /&gt;
==== Special Memory Adresses ====&lt;br /&gt;
* FRAMECOUNTER_HIGH = 19&lt;br /&gt;
* FRAMECOUNTER_LOW  = 20&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Atari 8bit systems use the ANTIC and GTIA chips. Information can be found here:&lt;br /&gt;
* https://en.wikipedia.org/wiki/ANTIC&lt;br /&gt;
* https://www.atariarchives.org/agagd/chapter1.php&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
      lda RTCLOK+2&lt;br /&gt;
waits&lt;br /&gt;
      cmp RTCLOK+2&lt;br /&gt;
      beq waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or if you don't mind trashing RTCLOK&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
waits&lt;br /&gt;
      lsr RTCLOK+2&lt;br /&gt;
      bcc waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which is two bytes shorter.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
;fill screen with charset,(88,89)=an address&lt;br /&gt;
 org $600; free 6th page:600-6ff&lt;br /&gt;
 ldy #0&lt;br /&gt;
fl: tya&lt;br /&gt;
 sta(88),y&lt;br /&gt;
 iny&lt;br /&gt;
 bne fl&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
SDMCTL	= $022f&lt;br /&gt;
HPOSP0  = $d000&lt;br /&gt;
SIZEP0  = $d008&lt;br /&gt;
GRAFP0  = $d00d&lt;br /&gt;
COLPM0  = $d012&lt;br /&gt;
&lt;br /&gt;
FRAMECOUNTER_HIGH = 19&lt;br /&gt;
FRAMECOUNTER = 20&lt;br /&gt;
WSYNC	= $d40a&lt;br /&gt;
VCOUNT	= $d40b&lt;br /&gt;
&lt;br /&gt;
sinewave	= $0600		; to $06ff&lt;br /&gt;
&lt;br /&gt;
		org $80&lt;br /&gt;
&lt;br /&gt;
main	&lt;br /&gt;
	; disable all graphics/colors&lt;br /&gt;
	ldx #0&lt;br /&gt;
	stx SDMCTL	&lt;br /&gt;
&lt;br /&gt;
	ldy #$7f&lt;br /&gt;
	sty SIZEP0	; size p0=127&lt;br /&gt;
		&lt;br /&gt;
	ldx #0&lt;br /&gt;
	ldy #$3f&lt;br /&gt;
make_sine:&lt;br /&gt;
value_lo&lt;br /&gt;
			lda #0&lt;br /&gt;
			clc&lt;br /&gt;
delta_lo&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_lo+1&lt;br /&gt;
value_hi&lt;br /&gt;
			lda #0&lt;br /&gt;
delta_hi&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_hi+1&lt;br /&gt;
 &lt;br /&gt;
			sta sinewave+$c0,x&lt;br /&gt;
			sta sinewave+$80,y&lt;br /&gt;
			eor #$7f&lt;br /&gt;
			sta sinewave+$40,x&lt;br /&gt;
			sta sinewave+$00,y&lt;br /&gt;
 &lt;br /&gt;
			lda delta_lo+1&lt;br /&gt;
			adc #8&lt;br /&gt;
			sta delta_lo+1&lt;br /&gt;
			bcc nothing&lt;br /&gt;
			inc delta_hi+1&lt;br /&gt;
nothing&lt;br /&gt;
			inx&lt;br /&gt;
			dey&lt;br /&gt;
			bpl make_sine&lt;br /&gt;
&lt;br /&gt;
updateloop:&lt;br /&gt;
		; vblank&lt;br /&gt;
		lda VCOUNT&lt;br /&gt;
		bne updateloop&lt;br /&gt;
&lt;br /&gt;
		; clear graphics&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		ldy #0&lt;br /&gt;
		lda #47&lt;br /&gt;
		sta COLPM0&lt;br /&gt;
yloop:&lt;br /&gt;
		tya           ; graphics shape = y&lt;br /&gt;
		sta WSYNC&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		; a = sin(frame+y)+48&lt;br /&gt;
		tya	&lt;br /&gt;
		adc FRAMECOUNTER&lt;br /&gt;
		tax&lt;br /&gt;
		lda sinewave,x&lt;br /&gt;
		adc #48&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
                &lt;br /&gt;
                iny&lt;br /&gt;
                bne yloop&lt;br /&gt;
		jmp updateloop&lt;br /&gt;
&lt;br /&gt;
		run main&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Atari 8-bit use the POKEY chip to generate sound.&lt;br /&gt;
* https://en.wikipedia.org/wiki/POKEY&lt;br /&gt;
&lt;br /&gt;
==== BASIC ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
; from Analog, 1985-09,pp.25-32&lt;br /&gt;
*=$2000&lt;br /&gt;
AUDF1=$D200&lt;br /&gt;
AUDC1=$D201&lt;br /&gt;
AUDCTL=$D208&lt;br /&gt;
SKCTL=$D20F&lt;br /&gt;
&lt;br /&gt;
.MACRO SOUND ; voice,pitch,dist,vol;,dur&lt;br /&gt;
	lda #%2&lt;br /&gt;
	sta AUDF1+2*%1&lt;br /&gt;
    lda #[[%3 * 16] | %4] ;lda #[[%3 shl 4] or %4]&lt;br /&gt;
    sta AUDC1+2*%1&lt;br /&gt;
.ENDM&lt;br /&gt;
&lt;br /&gt;
 lda #0&lt;br /&gt;
 sta AUDCTL&lt;br /&gt;
 lda #3&lt;br /&gt;
 sta SKCTL&lt;br /&gt;
&lt;br /&gt;
 SOUND 0,121,10,8&lt;br /&gt;
&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
Sizecoding resource for the Atari 8bit are:&lt;br /&gt;
* Mapping the Atari https://www.atariarchives.org/mapping/&lt;br /&gt;
* Atari 8bit Memory map https://www.atariarchives.org/mapping/memorymap.php&lt;br /&gt;
* Fready's undocumented 6502 opcodes https://github.com/FreddyOffenga/6502&lt;br /&gt;
* Atari OS Rev2 disassembly for MADS assembler https://github.com/ilmenit/A800-OS-XL-Rev2&lt;br /&gt;
* Fready's github https://github.com/FreddyOffenga/&lt;br /&gt;
&lt;br /&gt;
== Commodore 64 ==&lt;br /&gt;
The Commodore system consists of a 6502-compatible MOS 6510 processor with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Commodore systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: To be added&lt;br /&gt;
* Emulator(s): VICE is the way to go&lt;br /&gt;
&lt;br /&gt;
=== Memory map ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
    0-1          $0-$1      PROCESSOR PORT REGISTERS, not usable as RAM&lt;br /&gt;
   0-255         $0-$FF     ZEROPAGE, mostly used by BASIC interpreter and Kernal&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-600      $200-$258    INPUT BUFFER&lt;br /&gt;
  601-630      $259-$276    FILE SYSTEM DATA&lt;br /&gt;
  631-640      $277-$280    KEYBOARD BUFFER, filled by Kernal ISR upon key presses &lt;br /&gt;
  641-678      $281-$2A6    VARIOUS KERNAL VARIABLES&lt;br /&gt;
  679-767      $2A7-$2FF    Unused (89 byte)&lt;br /&gt;
  768-779      $300-$30B    KERNAL VECTORS&lt;br /&gt;
  780-783      $30C-$30F    REGISTER VALUES A,X,Y,SR for SYS&lt;br /&gt;
  784-819      $310-$333    KERNAL VECTORS&lt;br /&gt;
  820-827      $334-$33B    Unused (8 byte)&lt;br /&gt;
  828-1019     $33C-$3FB    DATASETTE BUFFER&lt;br /&gt;
 1020-1023     $3FC-$3FF    Unused (4 byte)&lt;br /&gt;
 1024-2023     $400-$7E7    SCREEN MEMORY (25 lines times 40 columns)&lt;br /&gt;
 2024-2039     $7E8-$7F7    Unused (16 byte)&lt;br /&gt;
 2040-2047     $7F8-$7FF    SPRITE COSTUME POINTERS&lt;br /&gt;
 2048          $800         must contain a value of 0 so that the BASIC program can be RUN&lt;br /&gt;
 2049-40959    $801-$9FFF   BASIC AREA (code, variables, arrays, strings)&lt;br /&gt;
40960-49151   $A000-$BFFF   BASIC ROM (unused RAM underneath)&lt;br /&gt;
49152-53247   $C000-$CFFF   UPPER RAM AREA (unused)&lt;br /&gt;
53248-53294   $D000-$D02E   VIC-II, memory-mapped graphics chip registers)&lt;br /&gt;
54272-54300   $D400-$D41C   SID, memory-mapped sound chip registers)&lt;br /&gt;
55296-56295   $D800-$DBE7   Color RAM, only lower 4 bits are stored, higher nibble undefined&lt;br /&gt;
56296-56319   $DBE8-$DBFF   Unused (24 half-bytes)&lt;br /&gt;
56320-56335   $DC00-$DC0F   CIA#1, memory-mapped I/O chip registers for keyboard, joystick, mouse, datasette, IRQ control&lt;br /&gt;
56576-56591   $DD00-$DD0F   CIA#1, memory-mapped I/O chip registers for serial bus, RS232, NMI control&lt;br /&gt;
57344-65535   $E000-$FFFF   KERNAL ROM&lt;br /&gt;
65534-65535   $FFFE-$FFFF   Execution address of interrupt service routine, can only be set if KERNAL is turned off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a detailed explanation of the C64 memory map check out [https://sta.c64.org/cbm64mem.html Commodore 64 memory map] on Joe Forster/STA homepage.&lt;br /&gt;
&lt;br /&gt;
=== Program file overhead ===&lt;br /&gt;
&lt;br /&gt;
A standard CBM file consists of a 2 byte loading address followed by the data that is placed into memory starting at this address. In addition, if your machine program should be able to be started with &amp;quot;RUN&amp;quot;, you need a BASIC stub that is loaded into memory from $0801 to $080c, typically followed by your machine program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0801&lt;br /&gt;
        .word $080b   ;address of next BASIC line&lt;br /&gt;
        .word LINENO  ;line number, can be chosen between 0 and 63999&lt;br /&gt;
        .byte $9e     ;token for SYS command&lt;br /&gt;
        .byte $32,$30,$35,$39  ;address to jump to in ASCII code: &amp;quot;2059&amp;quot; &lt;br /&gt;
        .byte $00     ;end of BASIC line&lt;br /&gt;
start   lax #0        ;actually address of next BASIC line, $xx00 means end of BASIC program, use $xx for an opcode&lt;br /&gt;
; your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the 2 byte load address, this makes an overhead of 14 bytes for your program, coming with A and X initialised to 0. To reduce this, you can&lt;br /&gt;
* omit the BASIC line and tell users to start your program by directly entering &amp;quot;SYS ''address''&amp;quot;&lt;br /&gt;
* save your program from $0802 on, the byte at $0801 is recovered automatically after loading by the relink function. This reduces your program file size by 1 byte&lt;br /&gt;
* accept the loss and use the 2 byte establishing LINENO for something good, they are copied to zeropage addresses $39/$3a automatically, saving you the effort of initializing the addresses&lt;br /&gt;
* use an autostart method (see below)&lt;br /&gt;
&lt;br /&gt;
Some compos also specify that the BASIC loader does not count towards the overall filesize, check the rules before you worry.&lt;br /&gt;
&lt;br /&gt;
=== Autostart ===&lt;br /&gt;
&lt;br /&gt;
Unlike the Commodore 128, the Commodore 64 has no dedicated built-in auto-boot feature, but it is possible to autorun a program after loading by specifying the load address so that it overwrites a vector or address that is called by the operating system. There are multiple possibilities:&lt;br /&gt;
&lt;br /&gt;
==== Overwriting  CHROUT vector at $326-$327 ====&lt;br /&gt;
&lt;br /&gt;
The vector at address $326-$327 points at the CHROUT routine, normally at address $F1CA.&lt;br /&gt;
If you put the entry address of your program into $326/27, your code will be called when the operating system wants to print &amp;quot;READY.&amp;quot; after loading.&lt;br /&gt;
Note that the vector at address $328-$329 points at the STOP routine that checks the status of Stop key indicator. Since this routine is called multiple times before your code is done loading, its default value $F6ED needs to be preserved. &lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0326&lt;br /&gt;
        .word start              &lt;br /&gt;
        .byte $ed,$f6&lt;br /&gt;
start&lt;br /&gt;
; rest of code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address, the overwritten CHROUT vector and the preserved STOP vector, your program file will have a deadweight of 6 byte: $26 $03 $0a $03 $ed $f6, less than half of the standard version with a BASIC stub with SYS&lt;br /&gt;
&lt;br /&gt;
Caveat:&lt;br /&gt;
* If your program after $32a is longer than 214 byte, part of your program will load into the screen at $400. Thus, issuing a clear screen will overwrite your program. It is possible to move the screen memory somewhere else, but that requires storing a new value into address $D018, which when done with an LDA # / STA pair will cost you 5 byte&lt;br /&gt;
* Since you changed the CHROUT pointer, standard KERNAL functions for printing won't work. For output of single characters, you can still use the direct address $F1CA. Alternatively, you can restore the vectors by calling $FD15, which will overwrite the memory $314 to $333 with the default values.&lt;br /&gt;
* The memory area $33C-$3FB is the datasette buffer, thus loading a program into this area won't work when loading from a cassette.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting BASIC idle loop vector at $302-$303 ====&lt;br /&gt;
&lt;br /&gt;
After loading the program, the BASIC idle loop will be called. By overwriting the vector at $302/$303 it is possible to autostart your program. Since the memory before $302 can be safely overwritten, the program would be arranged so that $303 is the '''last''' address of your program. If your program requires a loop back to the start, the vector can be used as part of a JMP where the following two bytes are already there, saving one byte in comparison to a loop done with a branch command.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$304 - (end - start)&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
        ; ...&lt;br /&gt;
        jmp     start    ;the address for start lies in $302/$303, thus will be called by the Kernal after loading&lt;br /&gt;
end:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In cases where the vector has a practical use, the overhead in filesize is only the 2 byte loading address. For programs larger than 93 byte keep in mind that addresses before $2A7 are in use by the Kernal.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting return address on stack at $1F8 ====&lt;br /&gt;
&lt;br /&gt;
When the load routine is called, the stack pointer is always at $FA at a stock C64. Thus the return address from the loading process is stored in memory address $1F8 (low byte) and $1F9 (high byte). During the loading routine, stack usage will clobber the stack below $1F8, but a program loaded to $1F8 and above will be fine and the overwritten address stored at $1F8/$1F9 will be called after loading.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$1F8&lt;br /&gt;
        .word start-1   ;adjust for the RTS command pulling the address from stack and increasing it by 1&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For programs larger than 95 byte keep in mind that addresses after $259 are in use by the Kernal, you might overwrite some values here if you don't have disk operations, but better check the memory map beforehand.&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address and the overwritten address at $1F8/$1F9, your program file will have a deadweight of 4 byte when using this method.&lt;br /&gt;
&lt;br /&gt;
==== Putting your program into zeropage overwriting part of CHRGET ====&lt;br /&gt;
&lt;br /&gt;
CHRGET is a machine code routine for the BASIC interpreter that is placed in the zero page at $73-$8A. By putting your program at $7C and following, the CHRGET routine runs directly into your code.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$7C&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this method, there is no need for a start address vector. The only deadweight in your program is the loading address. However, the zero page is a busy place, if your program extends beyond address $8f (that is it has more than 22 bytes on disk) you have to deal with some parts of your program being overwritten, for example, the status byte in $90 is set after loading.&lt;br /&gt;
&lt;br /&gt;
Loading data into address $A9 has an interesting side effect - the vector of $AE/$AF defines the address where the loaded bytes are written to. If $AE gets overwritten with, for example, $40, the next byte will be written to $41 (because the vector is incremented after the write). This can be used to split your program into different parts of memory.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Commodore has the following native video modes:&lt;br /&gt;
* Standard text mode, 40x25 characters, 1 individual foreground color per character, 1 common background color&lt;br /&gt;
* Multicolor text mode, 40x25 characters, only 8 foreground colors, can be mixed with hires chars, foreground &amp;lt; 8 denotes a hires char, with foreground &amp;gt;= 8 a pair of two bits (brick pixel) define color: background, foreground &amp;amp; %111, common color 1+2&lt;br /&gt;
* Extended background color text mode, 40x25 characters, 1 individual foreground color per character, 1 out of 4 background colors, only 64 chars&lt;br /&gt;
* Hires bitmap, 320x200 pixels, an 8x8 field can have an individual foreground and an individual background color&lt;br /&gt;
* Multicolor bitmap, 160x200 pixels, a pair of two bits (brick pixel) define color: background, screen color lower nibble, screen color higher nibble, color from color RAM&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&lt;br /&gt;
Depending on the VIC type, there are 262/263 raster lines (NTSC) or 312 raster lines (PAL-B). Therefore, the VIC uses register at $D012 and the highest bit of register $D011 to represent the current raster line. Checking only the lower 8 bits and waiting for them to be 0 would therefore not work because this happens two times per frame. However, any number greater than 64 will only trigger once. Using a value of 255, we would sync to a rasterline at the end of the screen, well below the part where graphics are normally displayed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
waitsync:&lt;br /&gt;
        ldx $D012&lt;br /&gt;
        inx&lt;br /&gt;
        bne waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as there have more than 63 cycles passed since the snyc, the next sync will happen at the next frame.&lt;br /&gt;
This works fine as long as we don't miss the line 255 due to an interrupt. If your program has interrupts that are not synced to a rasterline, you can change the condition as follows&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda #$E3&lt;br /&gt;
waitsync:&lt;br /&gt;
        cmp $D012&lt;br /&gt;
        bcs waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we have a window between raster line $E4 and $FF to trigger our sync, which we will meet even if a standard Kernal interrupt comes in-between. Of course, our main program now has to burn around 1700 cycles to avoid a retriggering in the same frame.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&lt;br /&gt;
Output a character:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #C       ;C must be the char code according to the PETSCII code table&lt;br /&gt;
        jsr     $FFD2    ;you can also use the direct address $FC1A, function preserves A,X,Y and enables interrupt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the [https://en.wikipedia.org/wiki/PETSCII#Character_set PETSCII code table] contains also control characters, this method can be also used to clear the screen, move the cursor or set the text color. However, some functions are shorter (and faster) by directly calling the respective KERNAL function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
Clear screen             JSR $E544&lt;br /&gt;
Cursor home position     JSR $E566&lt;br /&gt;
Output newline character JSR $AAD7&lt;br /&gt;
Set text color           LDA #COLOR, STA $286&lt;br /&gt;
Set border color         LDA #COLOR, STA $D020   ;not possible with a PETSCII control code&lt;br /&gt;
Set background color     LDA #COLOR, STA $D021   ;not possible with a PETSCII control code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy characters directly to screen memory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm   ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
LINE=5    ;for example&lt;br /&gt;
COLUMN=10 ;for example&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the text needs to be stored in '''screen code''' format, not in PETSCII (see [https://sta.c64.org/cbm64pettoscr.html Commodore 64 PETSCII code to screen code conversion] for the differences). Furthermore, the example above only writes to the screen memory, not the color RAM, assuming that the color RAM already contains the intended text color. This is the case after issuing a clear screen on most C64 machines, except for some old ROM revisions. To be on the save side you would have to write to color RAM as well, which costs another 5 byte:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm     ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
COLOR_RAM  =$D800&lt;br /&gt;
LINE       =5    ;for example&lt;br /&gt;
COLUMN     =10   ;for example&lt;br /&gt;
COLOR      =1    ;white&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        lda     #COLOR&lt;br /&gt;
        sta     COLOR_RAM  +LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Commodore 64 uses the famous SID chip to generate sound.&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Useful Kernal functions ===&lt;br /&gt;
&lt;br /&gt;
==== Get a pseudo random number ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #1   &lt;br /&gt;
        jsr     $E09A&lt;br /&gt;
        lda     $63&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The sequence of random numbers is always the same after a cold start or reset, the first 20 numbers are:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 4,24,231,4,177,170,193,101,231,18,196,1,75,48,149,36,124,53,65,154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Increment a zero page counter, return in X register, clear Y register ====&lt;br /&gt;
&lt;br /&gt;
This is part of the string handling function in the BASIC ROM, but the code could be useful for some loop stuff.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        jsr     $B5FF    ;does inc $23, ldx $23, ldy #$00, rts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Codebase 64 https://codebase64.org/doku.php?id=base:start&lt;br /&gt;
* Commodore 64 Memory map https://sta.c64.org/cbm64mem.html&lt;br /&gt;
* C64 BASIC &amp;amp; KERNAL ROM Disassembly https://www.pagetable.com/c64ref/c64disasm/&lt;br /&gt;
* No More Secrets https://csdb.dk/release/?id=198357 Everything about illegal opcodes and their use in a C64 system&lt;br /&gt;
&lt;br /&gt;
== Apple II ==&lt;br /&gt;
The Apple II is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* ACME 6502 cross-assembler(https://sourceforge.net/projects/acme-crossass/)&lt;br /&gt;
* Apple Commander (http://applecommander.sourceforge.net) for batch compilation&lt;br /&gt;
* AppleWin emulator (https://github.com/AppleWin/AppleWin/releases). Supports Mockingboard card(AY-8910+speech synthesier), HDD, Z80 card(for CP/M), mouse etc.&lt;br /&gt;
* CiderPress(https://a2ciderpress.com)&lt;br /&gt;
&lt;br /&gt;
Compilation can be done as follows (master.dsk can be found with applewin) &lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
acme hl.asm&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -d master.dsk hl&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -p master.dsk hl B 24576 &amp;lt; hl.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Memory Map ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
   0-255	 $0-$FF     ZERO-PAGE SYSTEM STORAGE&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-767      $200-$2FF    KEYBOARD CHARACTER BUFFER&lt;br /&gt;
  768-975      $300-$3CF    OFTEN AVAILABLE AS FREE SPACE FOR USER PROGRAMS&lt;br /&gt;
  976-1023     $3D0-3FF     SYSTEM VECTORS&lt;br /&gt;
 1024-2047     $400-$7FF    TEXT AND LO-RES GRAPHICS PAGE 1 &amp;lt;--- !!!&lt;br /&gt;
 2048-LOMEM    $800-LOMEM   PROGRAM STORAGE&lt;br /&gt;
 2048-3071     $800-$BFF    TEXT AND LO-RES GRAPHICS PAGE 2 OR FREE SPACE&lt;br /&gt;
 3072-8191     $C00-$1FFF   FREE SPACE UNLESS RAM APPLESOFT IS IN USE&lt;br /&gt;
 8192-16383   $2000-$3FFF   HI-RES PAGE 1 OR FREE SPACE &amp;lt;--- !!!&lt;br /&gt;
16384-24575   $4000-$5FFF   HI-RES PAGE 2 OR FREE SPACE&lt;br /&gt;
24576-38999   $6000-$95FF   FREE SPACE AND STRING STORAGE&lt;br /&gt;
38400-49151   $9600-$BFFF   DOS&lt;br /&gt;
49152-53247   $C000-$CFFF   I/O HARDWARE (RESERVED)&lt;br /&gt;
53248-57343   $D000-$DFFF   APPLESOFT IN LANGUAGE CARD OR ROM&lt;br /&gt;
57344-63487   $E000-$F7FF   APPLESOFT OR INTEGER BASIC IN LANGUAGE CARD OR ROM&lt;br /&gt;
63488-65535   $F800-$FFFF   SYSTEM MONITOR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Display ===&lt;br /&gt;
&lt;br /&gt;
=== Graphics Modes ===&lt;br /&gt;
: Text Mode 40x24, for Apple IIe available 80x25 - use PR#3 for switch mode, or hardware switch&lt;br /&gt;
: LowRes 40x48, 16 colors: https://en.wikipedia.org/wiki/Apple_II_graphics &lt;br /&gt;
: Hires mode 280x192,6 colors: https://www.xtof.info/blog/?p=768&lt;br /&gt;
https://mrob.com/pub/xapple2/colors.html&lt;br /&gt;
https://archive.org/details/HiRes_Color_Graphics_on_the_Apple_II_Computer_by_Wozniak&lt;br /&gt;
&lt;br /&gt;
However for sizecoding, you almost never want to do direct-access to graphics for Apple II in size-coding because the Apple II graphics modes are horrible.  The only fast way to do things is with large lookup tables.  To do hires you need to divide by 7 which as you can imagine is a bit difficult to do compactly on 6502. Double-hires is even crazier on top of that.  Deater did manage a color-bar style effect in double-hires in 128B but that was doing some crazy tricks with the firmware BASIC routines, definitely not direct-access.&lt;br /&gt;
&lt;br /&gt;
Lores and Hires can be mixed modes and full-graphics&lt;br /&gt;
The screen structure is called memory holes(https://retrocomputing.stackexchange.com/questions/2534/what-are-the-screen-holes-in-apple-ii-graphics). The GBASCALC($F847) procedure is used to calculate the address of the horizontal line : IN:reg.A=Y, out : GBASL/GBASH($26/$27)=address. See also https://www.callapple.org/uncategorized/use-of-apple-ii-color-graphics-in-assembly-language/&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
Here is an example of a XOR texture, created by g0blinish&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
GBASL	=	$26&lt;br /&gt;
GBASH	=	$27&lt;br /&gt;
SETGR    =     $FB40 ; setup LoRes&lt;br /&gt;
GBASCALC = $F847 ; calc Address&lt;br /&gt;
&lt;br /&gt;
CLRTEXT =  $C050 ;display graphics &lt;br /&gt;
SETTEXT =  $C051 ;display text &lt;br /&gt;
&lt;br /&gt;
CLRMIXED = $C052 ;clear mixed mode- enable full graphics &lt;br /&gt;
SETMIXED = $C053 ;enable graphics/text mixed mode &lt;br /&gt;
&lt;br /&gt;
PAGE1 =    $C054 ;select text/graphics page1 &lt;br /&gt;
PAGE2 =    $C055 ;select text/graphics page2 &lt;br /&gt;
&lt;br /&gt;
CLRHIRES = $C056 ;select Lo-res &lt;br /&gt;
SETHIRES = $C057 ;select Hi-res &lt;br /&gt;
&lt;br /&gt;
TMP= $FA&lt;br /&gt;
&lt;br /&gt;
	JSR   SETGR      ;GR&lt;br /&gt;
	BIT CLRMIXED ; full screen&lt;br /&gt;
&lt;br /&gt;
	LDA #0 ; A=0&lt;br /&gt;
	STA TMP ; POKE $FA,A&lt;br /&gt;
&lt;br /&gt;
YLP ;&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
;	LSR ; A=A/2&lt;br /&gt;
	JSR GBASCALC&lt;br /&gt;
	LDY #0;Y=0&lt;br /&gt;
&lt;br /&gt;
XLP TYA ; A=Y&lt;br /&gt;
	EOR TMP ; A=A xor PEEK($FA)&lt;br /&gt;
	and #$0F ; A=A and 15&lt;br /&gt;
	TAX ; X=A&lt;br /&gt;
	LDA COLORS,X ;A=PEEK(COLORS+X)&lt;br /&gt;
	STA(GBASL),Y ; POKE PEEK($26)+256*PEEK($27)+Y,A&lt;br /&gt;
	INY ; Y=Y+1&lt;br /&gt;
	CPY #40 ; Y=40?&lt;br /&gt;
	BNE XLP&lt;br /&gt;
	INC TMP ; POKE $FA,PEEK($FA)+1&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
	CMP #24 ; A=24?&lt;br /&gt;
	BNE YLP&lt;br /&gt;
	&lt;br /&gt;
M1 JMP M1 ; replace to RTS&lt;br /&gt;
&lt;br /&gt;
COLORS ;N*17, pixel format is AAAABBBB, AAAA - upper dot, BBBB - lower dot&lt;br /&gt;
!byte $00,$11,$22,$33,$44,$55,$66,$77&lt;br /&gt;
!byte $88,$99,$AA,$BB,$CC,$DD,$EE,$FF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sound  ====&lt;br /&gt;
Here is an example for using the speaker, based onthe following basic program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;basic&amp;quot;&amp;gt;&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
;start&lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
ini:&lt;br /&gt;
	lda #70&lt;br /&gt;
	sta cnt+1&lt;br /&gt;
	lda #music&amp;amp;255&lt;br /&gt;
	sta gotbyte+1&lt;br /&gt;
	lda #music/256&lt;br /&gt;
	sta gotbyte+2&lt;br /&gt;
&lt;br /&gt;
lop:&lt;br /&gt;
;V&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L300&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
;P&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L301&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	clc&lt;br /&gt;
	adc #1&lt;br /&gt;
	sta L320&lt;br /&gt;
	jsr beep&lt;br /&gt;
	&lt;br /&gt;
	dec cnt+1&lt;br /&gt;
cnt lda #70&lt;br /&gt;
	bne lop&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
	jmp ini&lt;br /&gt;
gotbyte&lt;br /&gt;
	lda music&lt;br /&gt;
	inc gotbyte+1&lt;br /&gt;
	bne noinch&lt;br /&gt;
	inc gotbyte+2&lt;br /&gt;
noinch&lt;br /&gt;
	rts&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
beep:&lt;br /&gt;
	ldy #1&lt;br /&gt;
	ldx #1&lt;br /&gt;
loc_302:&lt;br /&gt;
		LDA	$C030&lt;br /&gt;
&lt;br /&gt;
loc_305:&lt;br /&gt;
		DEY&lt;br /&gt;
		BNE	loc_30D&lt;br /&gt;
		DEC	L301&lt;br /&gt;
loc_30B:&lt;br /&gt;
		BEQ	loc_316&lt;br /&gt;
&lt;br /&gt;
loc_30D:&lt;br /&gt;
		DEX&lt;br /&gt;
		BNE	loc_305&lt;br /&gt;
		LDX	L300&lt;br /&gt;
		JMP	loc_302&lt;br /&gt;
loc_316:&lt;br /&gt;
		DEC	L320&lt;br /&gt;
		BNE	loc_30B&lt;br /&gt;
		RTS&lt;br /&gt;
L301 !byte 0&lt;br /&gt;
L300 !byte 0&lt;br /&gt;
L320 !byte 0&lt;br /&gt;
music&lt;br /&gt;
 !word 76,192,85,64,96,64,102,64,114,128,114,64,96,64,102,64,114,64,128,64&lt;br /&gt;
 !word 114,64,152,64,171,64,152,512,76,192,85,64,96,64,102,64,114,128,114,64&lt;br /&gt;
 !word 96,64,102,64,114,64,128,64,114,64,152,64,171,64,152,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,128,114,64,128,64,114,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,64,128,128,96,64,85,64,96,64,102,64,114,64,114,64&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Deater's page on Apple II sizecoding http://www.deater.net/weave/vmwprod/demos/sizecoding.html (with an additional presentation at https://www.youtube.com/watch?v=kJ-EXbnw0kQ )&lt;br /&gt;
* Article on double hi-res http://www.battlestations.zone/2017/04/apple-ii-double-hi-res-from-ground-up.html&lt;br /&gt;
* Applesoft Hi-Res Subroutines : http://hackzapple.org/scripts_php/index.php?menu=5&amp;amp;mod=ASM&amp;amp;sub=AAL&amp;amp;sub2=8112&amp;amp;PHPSESSID=f65fabfd0cdbf56b6bdc0ddac25117c6#a2&lt;br /&gt;
&lt;br /&gt;
== Atari Lynx ==&lt;br /&gt;
The Atari Lynx consists of the 65C02 with custom hardware for graphics and sound.&amp;lt;br&amp;gt;&lt;br /&gt;
If you come from Atari 8bit or Apple, there are no illegal opcodes anymore like &amp;lt;b&amp;gt;lax&amp;lt;/b&amp;gt;, but a lot new nice opcodes like &amp;lt;b&amp;gt;stz&amp;lt;/b&amp;gt;. :-)&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari Lynx:&lt;br /&gt;
&lt;br /&gt;
* Assembler:&lt;br /&gt;
Below size coding examples use [https://github.com/42Bastian/lyxass Lyxass] as assembler and are using the in-official DevKit [https://github.com/42Bastian/new_bll new_bll].&amp;lt;br&amp;gt;&lt;br /&gt;
But any other 6502 assembler is suitable. Best if it can assemble the extra opcodes of the 65C02 (like &amp;lt;b&amp;gt;BBRx&amp;lt;/b&amp;gt; or &amp;lt;b&amp;gt;RMBx&amp;lt;/b&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Encryption&lt;br /&gt;
The Lynx boot ROM will decrypt the &amp;quot;boot sector&amp;quot; of a Lynx card image. It is done in chunks of 50bytes. Maximum are 5 chunks, hence the limit of a &amp;quot;boot sector&amp;quot; is 250 bytes, but the last byte &amp;lt;b&amp;gt;must&amp;lt;/b&amp;gt; be zero.&lt;br /&gt;
&lt;br /&gt;
* Emulator(s): &lt;br /&gt;
Currently Felix is the most accurate Emulator, though only running yet on Windows platform.&amp;lt;br&amp;gt;&lt;br /&gt;
It is currently available via [https://github.com/laoo/Felix GitHub].&lt;br /&gt;
&lt;br /&gt;
* Hardware:&lt;br /&gt;
If you want to run the code on a real Lynx, you should have a SD card for the Lynx (AgaCard, LynxGD) and also a USB&amp;lt;-&amp;gt;Serial adapter.&lt;br /&gt;
&lt;br /&gt;
=== Initial values ===&lt;br /&gt;
After the boot-rom has decrypted the boot-sector, some things are pre-defined:&lt;br /&gt;
* CPU Registers:&lt;br /&gt;
  A = 0&lt;br /&gt;
  X = 0&lt;br /&gt;
  Y = 2&lt;br /&gt;
  P = undefined&lt;br /&gt;
  S = undefined&lt;br /&gt;
&lt;br /&gt;
* Zero page&lt;br /&gt;
&lt;br /&gt;
 $00 - 0&lt;br /&gt;
 $01 - 0&lt;br /&gt;
 $02 - 0&lt;br /&gt;
&lt;br /&gt;
* Main&lt;br /&gt;
&lt;br /&gt;
Main memory is cleared to zero despite a $5000..%$50aa where decryption code is placed.&lt;br /&gt;
&lt;br /&gt;
* Bank switching&lt;br /&gt;
&lt;br /&gt;
ROM, Mikey and Suzy are mapped, Vector table is ROM.&lt;br /&gt;
&lt;br /&gt;
* Suzy&lt;br /&gt;
The sprite engine is &amp;lt;b&amp;gt;not&amp;lt;/b&amp;gt; setup.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
The Lynx display is 160x102 pixels which are linear organized as 4 bit per pixel. Hence the screen is little less than 8K.&lt;br /&gt;
The pixel value is a pointer to the color look up table.&lt;br /&gt;
The Lynx can display black and 4095 colors. The color table is split up into a green and an blue-red part (so not RGB but GBR).&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
After the ROM has deciphered the boot sector the display memory is at $2000, background color (that is pen 0) is black, all other entries are $f despite entry 14 which is also 0.&lt;br /&gt;
&lt;br /&gt;
So to fill the screen simply do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lda #$ff&lt;br /&gt;
ldx #0&lt;br /&gt;
ldy #$20   ; round(160*102/2/256)&lt;br /&gt;
loop:&lt;br /&gt;
    sta $2000,x&lt;br /&gt;
    inx&lt;br /&gt;
  bne loop&lt;br /&gt;
  inc loop+2 ; Self modify&lt;br /&gt;
  dey&lt;br /&gt;
bne loop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tips 'n' tricks ===&lt;br /&gt;
A nice trick with the new opcodes to limit a counter:&lt;br /&gt;
* 6502&lt;br /&gt;
  lda counter  ; 2&lt;br /&gt;
  inc          ; 1&lt;br /&gt;
  and #3       ; 2&lt;br /&gt;
  sta counter  ; 2 = 7 bytes&lt;br /&gt;
&lt;br /&gt;
* 65C02&lt;br /&gt;
  inc counter ; 2&lt;br /&gt;
  rmb2 counter ; 2 =&amp;gt; 4 bytes&lt;br /&gt;
&lt;br /&gt;
Set a counter (previously 0) to a power-of-two (here 32)&lt;br /&gt;
&lt;br /&gt;
* 6502&lt;br /&gt;
  lda #32     ; 2&lt;br /&gt;
  sta counter ; 2 =&amp;gt; 4&lt;br /&gt;
&lt;br /&gt;
* 65C02&lt;br /&gt;
  smb5 counter ; 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
*[https://www.monlynx.de/lynx/lynxdoc.html Hardware documentation]&lt;br /&gt;
*[https://github.com/42Bastian/lynx_hacking/tree/master/248b Size coding examples.]&lt;br /&gt;
*[https://github.com/42Bastian/lynx-encryption-tools Lynx encryption-tools]&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=6502&amp;diff=1007</id>
		<title>6502</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=6502&amp;diff=1007"/>
				<updated>2022-01-31T09:11:51Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: /* Getting something on screen */ fix code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Wanting to start sizecoding on a 6502 platform in this day and age can be tough. &lt;br /&gt;
&lt;br /&gt;
[[File:6502.jpg|thumb]]&lt;br /&gt;
&lt;br /&gt;
So here is a bit of help to get you started:&lt;br /&gt;
&lt;br /&gt;
=== The 6502 processor  ===&lt;br /&gt;
The 6502 processor can be seen as the 8-bit micro ARM chip. &lt;br /&gt;
It has only has 3 registers (Accumulator, X and Y registers) and a handful of instructions to work with.&lt;br /&gt;
&lt;br /&gt;
=== Adressing modes ===&lt;br /&gt;
To be added.&lt;br /&gt;
&lt;br /&gt;
=== Zero page ===&lt;br /&gt;
When using the 6502 for sizecoding, you'll mostly be working from zeropage&lt;br /&gt;
&lt;br /&gt;
=== General 6502 Resources ===&lt;br /&gt;
* 6502.org http://www.6502.org/&lt;br /&gt;
* 6502 instruction reference http://www.6502.org/tutorials/6502opcodes.html&lt;br /&gt;
* 6502 books http://retro.hansotten.nl/6502-sbc/&lt;br /&gt;
* 6502 Assembler tutorial https://dwheeler.com/6502/oneelkruns/asm1step.html&lt;br /&gt;
* Easy 6502 code tester https://skilldrick.github.io/easy6502/&lt;br /&gt;
* Synthetic instructions https://wiki.nesdev.com/w/index.php/Synthetic_instructions#8-bit_rotate&lt;br /&gt;
&lt;br /&gt;
== Atari 8-bit family ==&lt;br /&gt;
The systems in this family are: Atari 400, 800, 5200, 1200XL, 600XL, 800XL, 130XE, 65XE, 800XE and XEGS.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Atari 8-bit systems consists of the 6502 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari 8bit systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: MADS Assembler - This assembler has nice macros for creating Binaries and SNA snapshot files out of the box. You can download it at https://mads.atari8.info/&lt;br /&gt;
* Emulator(s): I Found Altirra to work best for my usecase. Make sure to use the original Rev2 rom for best compatibility.&lt;br /&gt;
&lt;br /&gt;
==== Special Memory Adresses ====&lt;br /&gt;
* FRAMECOUNTER_HIGH = 19&lt;br /&gt;
* FRAMECOUNTER_LOW  = 20&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Atari 8bit systems use the ANTIC and GTIA chips. Information can be found here:&lt;br /&gt;
* https://en.wikipedia.org/wiki/ANTIC&lt;br /&gt;
* https://www.atariarchives.org/agagd/chapter1.php&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
      lda RTCLOK+2&lt;br /&gt;
waits&lt;br /&gt;
      cmp RTCLOK+2&lt;br /&gt;
      beq waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or if you don't mind trashing RTCLOK&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
waits&lt;br /&gt;
      lsr RTCLOK+2&lt;br /&gt;
      bcc waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which is two bytes shorter.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
;fill screen with charset,(88,89)=an address&lt;br /&gt;
 org $600; free 6th page:600-6ff&lt;br /&gt;
 ldy #0&lt;br /&gt;
fl: tya&lt;br /&gt;
 sta(88),y&lt;br /&gt;
 iny&lt;br /&gt;
 bne fl&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
SDMCTL	= $022f&lt;br /&gt;
HPOSP0  = $d000&lt;br /&gt;
SIZEP0  = $d008&lt;br /&gt;
GRAFP0  = $d00d&lt;br /&gt;
COLPM0  = $d012&lt;br /&gt;
&lt;br /&gt;
FRAMECOUNTER_HIGH = 19&lt;br /&gt;
FRAMECOUNTER = 20&lt;br /&gt;
WSYNC	= $d40a&lt;br /&gt;
VCOUNT	= $d40b&lt;br /&gt;
&lt;br /&gt;
sinewave	= $0600		; to $06ff&lt;br /&gt;
&lt;br /&gt;
		org $80&lt;br /&gt;
&lt;br /&gt;
main	&lt;br /&gt;
	; disable all graphics/colors&lt;br /&gt;
	ldx #0&lt;br /&gt;
	stx SDMCTL	&lt;br /&gt;
&lt;br /&gt;
	ldy #$7f&lt;br /&gt;
	sty SIZEP0	; size p0=127&lt;br /&gt;
		&lt;br /&gt;
	ldx #0&lt;br /&gt;
	ldy #$3f&lt;br /&gt;
make_sine:&lt;br /&gt;
value_lo&lt;br /&gt;
			lda #0&lt;br /&gt;
			clc&lt;br /&gt;
delta_lo&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_lo+1&lt;br /&gt;
value_hi&lt;br /&gt;
			lda #0&lt;br /&gt;
delta_hi&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_hi+1&lt;br /&gt;
 &lt;br /&gt;
			sta sinewave+$c0,x&lt;br /&gt;
			sta sinewave+$80,y&lt;br /&gt;
			eor #$7f&lt;br /&gt;
			sta sinewave+$40,x&lt;br /&gt;
			sta sinewave+$00,y&lt;br /&gt;
 &lt;br /&gt;
			lda delta_lo+1&lt;br /&gt;
			adc #8&lt;br /&gt;
			sta delta_lo+1&lt;br /&gt;
			bcc nothing&lt;br /&gt;
			inc delta_hi+1&lt;br /&gt;
nothing&lt;br /&gt;
			inx&lt;br /&gt;
			dey&lt;br /&gt;
			bpl make_sine&lt;br /&gt;
&lt;br /&gt;
updateloop:&lt;br /&gt;
		; vblank&lt;br /&gt;
		lda VCOUNT&lt;br /&gt;
		bne updateloop&lt;br /&gt;
&lt;br /&gt;
		; clear graphics&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		ldy #0&lt;br /&gt;
		lda #47&lt;br /&gt;
		sta COLPM0&lt;br /&gt;
yloop:&lt;br /&gt;
		tya           ; graphics shape = y&lt;br /&gt;
		sta WSYNC&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		; a = sin(frame+y)+48&lt;br /&gt;
		tya	&lt;br /&gt;
		adc FRAMECOUNTER&lt;br /&gt;
		tax&lt;br /&gt;
		lda sinewave,x&lt;br /&gt;
		adc #48&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
                &lt;br /&gt;
                iny&lt;br /&gt;
                bne yloop&lt;br /&gt;
		jmp updateloop&lt;br /&gt;
&lt;br /&gt;
		run main&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Atari 8-bit use the POKEY chip to generate sound.&lt;br /&gt;
* https://en.wikipedia.org/wiki/POKEY&lt;br /&gt;
&lt;br /&gt;
==== BASIC ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
; from Analog, 1985-09,pp.25-32&lt;br /&gt;
*=$2000&lt;br /&gt;
AUDF1=$D200&lt;br /&gt;
AUDC1=$D201&lt;br /&gt;
AUDCTL=$D208&lt;br /&gt;
SKCTL=$D20F&lt;br /&gt;
&lt;br /&gt;
.MACRO SOUND ; voice,pitch,dist,vol;,dur&lt;br /&gt;
	lda #%2&lt;br /&gt;
	sta AUDF1+2*%1&lt;br /&gt;
    lda #[[%3 * 16] | %4] ;lda #[[%3 shl 4] or %4]&lt;br /&gt;
    sta AUDC1+2*%1&lt;br /&gt;
.ENDM&lt;br /&gt;
&lt;br /&gt;
 lda #0&lt;br /&gt;
 sta AUDCTL&lt;br /&gt;
 lda #3&lt;br /&gt;
 sta SKCTL&lt;br /&gt;
&lt;br /&gt;
 SOUND 0,121,10,8&lt;br /&gt;
&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
Sizecoding resource for the Atari 8bit are:&lt;br /&gt;
* Mapping the Atari https://www.atariarchives.org/mapping/&lt;br /&gt;
* Atari 8bit Memory map https://www.atariarchives.org/mapping/memorymap.php&lt;br /&gt;
* Fready's undocumented 6502 opcodes https://github.com/FreddyOffenga/6502&lt;br /&gt;
* Atari OS Rev2 disassembly for MADS assembler https://github.com/ilmenit/A800-OS-XL-Rev2&lt;br /&gt;
* Fready's github https://github.com/FreddyOffenga/&lt;br /&gt;
&lt;br /&gt;
== Commodore 64 ==&lt;br /&gt;
The Commodore system consists of a 6502-compatible MOS 6510 processor with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Commodore systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: To be added&lt;br /&gt;
* Emulator(s): VICE is the way to go&lt;br /&gt;
&lt;br /&gt;
=== Memory map ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
    0-1          $0-$1      PROCESSOR PORT REGISTERS, not usable as RAM&lt;br /&gt;
   0-255         $0-$FF     ZEROPAGE, mostly used by BASIC interpreter and Kernal&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-600      $200-$258    INPUT BUFFER&lt;br /&gt;
  601-630      $259-$276    FILE SYSTEM DATA&lt;br /&gt;
  631-640      $277-$280    KEYBOARD BUFFER, filled by Kernal ISR upon key presses &lt;br /&gt;
  641-678      $281-$2A6    VARIOUS KERNAL VARIABLES&lt;br /&gt;
  679-767      $2A7-$2FF    Unused (89 byte)&lt;br /&gt;
  768-779      $300-$30B    KERNAL VECTORS&lt;br /&gt;
  780-783      $30C-$30F    REGISTER VALUES A,X,Y,SR for SYS&lt;br /&gt;
  784-819      $310-$333    KERNAL VECTORS&lt;br /&gt;
  820-827      $334-$33B    Unused (8 byte)&lt;br /&gt;
  828-1019     $33C-$3FB    DATASETTE BUFFER&lt;br /&gt;
 1020-1023     $3FC-$3FF    Unused (4 byte)&lt;br /&gt;
 1024-2023     $400-$7E7    SCREEN MEMORY (25 lines times 40 columns)&lt;br /&gt;
 2024-2039     $7E8-$7F7    Unused (16 byte)&lt;br /&gt;
 2040-2047     $7F8-$7FF    SPRITE COSTUME POINTERS&lt;br /&gt;
 2048          $800         must contain a value of 0 so that the BASIC program can be RUN&lt;br /&gt;
 2049-40959    $801-$9FFF   BASIC AREA (code, variables, arrays, strings)&lt;br /&gt;
40960-49151   $A000-$BFFF   BASIC ROM (unused RAM underneath)&lt;br /&gt;
49152-53247   $C000-$CFFF   UPPER RAM AREA (unused)&lt;br /&gt;
53248-53294   $D000-$D02E   VIC-II, memory-mapped graphics chip registers)&lt;br /&gt;
54272-54300   $D400-$D41C   SID, memory-mapped sound chip registers)&lt;br /&gt;
55296-56295   $D800-$DBE7   Color RAM, only lower 4 bits are stored, higher nibble undefined&lt;br /&gt;
56296-56319   $DBE8-$DBFF   Unused (24 half-bytes)&lt;br /&gt;
56320-56335   $DC00-$DC0F   CIA#1, memory-mapped I/O chip registers for keyboard, joystick, mouse, datasette, IRQ control&lt;br /&gt;
56576-56591   $DD00-$DD0F   CIA#1, memory-mapped I/O chip registers for serial bus, RS232, NMI control&lt;br /&gt;
57344-65535   $E000-$FFFF   KERNAL ROM&lt;br /&gt;
65534-65535   $FFFE-$FFFF   Execution address of interrupt service routine, can only be set if KERNAL is turned off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a detailed explanation of the C64 memory map check out [https://sta.c64.org/cbm64mem.html Commodore 64 memory map] on Joe Forster/STA homepage.&lt;br /&gt;
&lt;br /&gt;
=== Program file overhead ===&lt;br /&gt;
&lt;br /&gt;
A standard CBM file consists of a 2 byte loading address followed by the data that is placed into memory starting at this address. In addition, if your machine program should be able to be started with &amp;quot;RUN&amp;quot;, you need a BASIC stub that is loaded into memory from $0801 to $080c, typically followed by your machine program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0801&lt;br /&gt;
        .word $080b   ;address of next BASIC line&lt;br /&gt;
        .word LINENO  ;line number, can be chosen between 0 and 63999&lt;br /&gt;
        .byte $9e     ;token for SYS command&lt;br /&gt;
        .byte $32,$30,$35,$39  ;address to jump to in ASCII code: &amp;quot;2059&amp;quot; &lt;br /&gt;
        .byte $00     ;end of BASIC line&lt;br /&gt;
start   lax #0        ;actually address of next BASIC line, $xx00 means end of BASIC program, use $xx for an opcode&lt;br /&gt;
; your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the 2 byte load address, this makes an overhead of 14 bytes for your program, coming with A and X initialised to 0. To reduce this, you can&lt;br /&gt;
* omit the BASIC line and tell users to start your program by directly entering &amp;quot;SYS ''address''&amp;quot;&lt;br /&gt;
* save your program from $0802 on, the byte at $0801 is recovered automatically after loading by the relink function. This reduces your program file size by 1 byte&lt;br /&gt;
* accept the loss and use the 2 byte establishing LINENO for something good, they are copied to zeropage addresses $39/$3a automatically, saving you the effort of initializing the addresses&lt;br /&gt;
* use an autostart method (see below)&lt;br /&gt;
&lt;br /&gt;
Some compos also specify that the BASIC loader does not count towards the overall filesize, check the rules before you worry.&lt;br /&gt;
&lt;br /&gt;
=== Autostart ===&lt;br /&gt;
&lt;br /&gt;
Unlike the Commodore 128, the Commodore 64 has no dedicated built-in auto-boot feature, but it is possible to autorun a program after loading by specifying the load address so that it overwrites a vector or address that is called by the operating system. There are multiple possibilities:&lt;br /&gt;
&lt;br /&gt;
==== Overwriting  CHROUT vector at $326-$327 ====&lt;br /&gt;
&lt;br /&gt;
The vector at address $326-$327 points at the CHROUT routine, normally at address $F1CA.&lt;br /&gt;
If you put the entry address of your program into $326/27, your code will be called when the operating system wants to print &amp;quot;READY.&amp;quot; after loading.&lt;br /&gt;
Note that the vector at address $328-$329 points at the STOP routine that checks the status of Stop key indicator. Since this routine is called multiple times before your code is done loading, its default value $F6ED needs to be preserved. &lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0326&lt;br /&gt;
        .word start              &lt;br /&gt;
        .byte $ed,$f6&lt;br /&gt;
start&lt;br /&gt;
; rest of code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address, the overwritten CHROUT vector and the preserved STOP vector, your program file will have a deadweight of 6 byte: $26 $03 $0a $03 $ed $f6, less than half of the standard version with a BASIC stub with SYS&lt;br /&gt;
&lt;br /&gt;
Caveat:&lt;br /&gt;
* If your program after $32a is longer than 214 byte, part of your program will load into the screen at $400. Thus, issuing a clear screen will overwrite your program. It is possible to move the screen memory somewhere else, but that requires storing a new value into address $D018, which when done with an LDA # / STA pair will cost you 5 byte&lt;br /&gt;
* Since you changed the CHROUT pointer, standard KERNAL functions for printing won't work. For output of single characters, you can still use the direct address $F1CA. Alternatively, you can restore the vectors by calling $FD15, which will overwrite the memory $314 to $333 with the default values.&lt;br /&gt;
* The memory area $33C-$3FB is the datasette buffer, thus loading a program into this area won't work when loading from a cassette.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting BASIC idle loop vector at $302-$303 ====&lt;br /&gt;
&lt;br /&gt;
After loading the program, the BASIC idle loop will be called. By overwriting the vector at $302/$303 it is possible to autostart your program. Since the memory before $302 can be safely overwritten, the program would be arranged so that $303 is the '''last''' address of your program. If your program requires a loop back to the start, the vector can be used as part of a JMP where the following two bytes are already there, saving one byte in comparison to a loop done with a branch command.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$304 - (end - start)&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
        ; ...&lt;br /&gt;
        jmp     start    ;the address for start lies in $302/$303, thus will be called by the Kernal after loading&lt;br /&gt;
end:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In cases where the vector has a practical use, the overhead in filesize is only the 2 byte loading address. For programs larger than 93 byte keep in mind that addresses before $2A7 are in use by the Kernal.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting return address on stack at $1F8 ====&lt;br /&gt;
&lt;br /&gt;
When the load routine is called, the stack pointer is always at $FA at a stock C64. Thus the return address from the loading process is stored in memory address $1F8 (low byte) and $1F9 (high byte). During the loading routine, stack usage will clobber the stack below $1F8, but a program loaded to $1F8 and above will be fine and the overwritten address stored at $1F8/$1F9 will be called after loading.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$1F8&lt;br /&gt;
        .word start-1   ;adjust for the RTS command pulling the address from stack and increasing it by 1&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For programs larger than 95 byte keep in mind that addresses after $259 are in use by the Kernal, you might overwrite some values here if you don't have disk operations, but better check the memory map beforehand.&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address and the overwritten address at $1F8/$1F9, your program file will have a deadweight of 4 byte when using this method.&lt;br /&gt;
&lt;br /&gt;
==== Putting your program into zeropage overwriting part of CHRGET ====&lt;br /&gt;
&lt;br /&gt;
CHRGET is a machine code routine for the BASIC interpreter that is placed in the zero page at $73-$8A. By putting your program at $7C and following, the CHRGET routine runs directly into your code.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$7C&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this method, there is no need for a start address vector. The only deadweight in your program is the loading address. However, the zero page is a busy place, if your program extends beyond address $8f (that is it has more than 22 bytes on disk) you have to deal with some parts of your program being overwritten, for example, the status byte in $90 is set after loading.&lt;br /&gt;
&lt;br /&gt;
Loading data into address $A9 has an interesting side effect - the vector of $AE/$AF defines the address where the loaded bytes are written to. If $AE gets overwritten with, for example, $40, the next byte will be written to $41 (because the vector is incremented after the write). This can be used to split your program into different parts of memory.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Commodore has the following native video modes:&lt;br /&gt;
* Standard text mode, 40x25 characters, 1 individual foreground color per character, 1 common background color&lt;br /&gt;
* Multicolor text mode, 40x25 characters, only 8 foreground colors, can be mixed with hires chars, foreground &amp;lt; 8 denotes a hires char, with foreground &amp;gt;= 8 a pair of two bits (brick pixel) define color: background, foreground &amp;amp; %111, common color 1+2&lt;br /&gt;
* Extended background color text mode, 40x25 characters, 1 individual foreground color per character, 1 out of 4 background colors, only 64 chars&lt;br /&gt;
* Hires bitmap, 320x200 pixels, an 8x8 field can have an individual foreground and an individual background color&lt;br /&gt;
* Multicolor bitmap, 160x200 pixels, a pair of two bits (brick pixel) define color: background, screen color lower nibble, screen color higher nibble, color from color RAM&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&lt;br /&gt;
Depending on the VIC type, there are 262/263 raster lines (NTSC) or 312 raster lines (PAL-B). Therefore, the VIC uses register at $D012 and the highest bit of register $D011 to represent the current raster line. Checking only the lower 8 bits and waiting for them to be 0 would therefore not work because this happens two times per frame. However, any number greater than 64 will only trigger once. Using a value of 255, we would sync to a rasterline at the end of the screen, well below the part where graphics are normally displayed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
waitsync:&lt;br /&gt;
        ldx $D012&lt;br /&gt;
        inx&lt;br /&gt;
        bne waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as there have more than 63 cycles passed since the snyc, the next sync will happen at the next frame.&lt;br /&gt;
This works fine as long as we don't miss the line 255 due to an interrupt. If your program has interrupts that are not synced to a rasterline, you can change the condition as follows&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda #$E3&lt;br /&gt;
waitsync:&lt;br /&gt;
        cmp $D012&lt;br /&gt;
        bcs waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we have a window between raster line $E4 and $FF to trigger our sync, which we will meet even if a standard Kernal interrupt comes in-between. Of course, our main program now has to burn around 1700 cycles to avoid a retriggering in the same frame.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&lt;br /&gt;
Output a character:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #C       ;C must be the char code according to the PETSCII code table&lt;br /&gt;
        jsr     $FFD2    ;you can also use the direct address $FC1A, function preserves A,X,Y and enables interrupt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the [https://en.wikipedia.org/wiki/PETSCII#Character_set PETSCII code table] contains also control characters, this method can be also used to clear the screen, move the cursor or set the text color. However, some functions are shorter (and faster) by directly calling the respective KERNAL function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
Clear screen             JSR $E544&lt;br /&gt;
Cursor home position     JSR $E566&lt;br /&gt;
Output newline character JSR $AAD7&lt;br /&gt;
Set text color           LDA #COLOR, STA $286&lt;br /&gt;
Set border color         LDA #COLOR, STA $D020   ;not possible with a PETSCII control code&lt;br /&gt;
Set background color     LDA #COLOR, STA $D021   ;not possible with a PETSCII control code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy characters directly to screen memory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm   ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
LINE=5    ;for example&lt;br /&gt;
COLUMN=10 ;for example&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the text needs to be stored in '''screen code''' format, not in PETSCII (see [https://sta.c64.org/cbm64pettoscr.html Commodore 64 PETSCII code to screen code conversion] for the differences). Furthermore, the example above only writes to the screen memory, not the color RAM, assuming that the color RAM already contains the intended text color. This is the case after issuing a clear screen on most C64 machines, except for some old ROM revisions. To be on the save side you would have to write to color RAM as well, which costs another 5 byte:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm     ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
COLOR_RAM  =$D800&lt;br /&gt;
LINE       =5    ;for example&lt;br /&gt;
COLUMN     =10   ;for example&lt;br /&gt;
COLOR      =1    ;white&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        lda     #COLOR&lt;br /&gt;
        sta     COLOR_RAM  +LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Commodore 64 uses the famous SID chip to generate sound.&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Useful Kernal functions ===&lt;br /&gt;
&lt;br /&gt;
==== Get a pseudo random number ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #1   &lt;br /&gt;
        jsr     $E09A&lt;br /&gt;
        lda     $63&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The sequence of random numbers is always the same after a cold start or reset, the first 20 numbers are:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 4,24,231,4,177,170,193,101,231,18,196,1,75,48,149,36,124,53,65,154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Increment a zero page counter, return in X register, clear Y register ====&lt;br /&gt;
&lt;br /&gt;
This is part of the string handling function in the BASIC ROM, but the code could be useful for some loop stuff.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        jsr     $B5FF    ;does inc $23, ldx $23, ldy #$00, rts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Codebase 64 https://codebase64.org/doku.php?id=base:start&lt;br /&gt;
* Commodore 64 Memory map https://sta.c64.org/cbm64mem.html&lt;br /&gt;
* C64 BASIC &amp;amp; KERNAL ROM Disassembly https://www.pagetable.com/c64ref/c64disasm/&lt;br /&gt;
* No More Secrets https://csdb.dk/release/?id=198357 Everything about illegal opcodes and their use in a C64 system&lt;br /&gt;
&lt;br /&gt;
== Apple II ==&lt;br /&gt;
The Apple II is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* ACME 6502 cross-assembler(https://sourceforge.net/projects/acme-crossass/)&lt;br /&gt;
* Apple Commander (http://applecommander.sourceforge.net) for batch compilation&lt;br /&gt;
* AppleWin emulator (https://github.com/AppleWin/AppleWin/releases). Supports Mockingboard card(AY-8910+speech synthesier), HDD, Z80 card(for CP/M), mouse etc.&lt;br /&gt;
* CiderPress(https://a2ciderpress.com)&lt;br /&gt;
&lt;br /&gt;
Compilation can be done as follows (master.dsk can be found with applewin) &lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
acme hl.asm&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -d master.dsk hl&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -p master.dsk hl B 24576 &amp;lt; hl.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Memory Map ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
   0-255	 $0-$FF     ZERO-PAGE SYSTEM STORAGE&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-767      $200-$2FF    KEYBOARD CHARACTER BUFFER&lt;br /&gt;
  768-975      $300-$3CF    OFTEN AVAILABLE AS FREE SPACE FOR USER PROGRAMS&lt;br /&gt;
  976-1023     $3D0-3FF     SYSTEM VECTORS&lt;br /&gt;
 1024-2047     $400-$7FF    TEXT AND LO-RES GRAPHICS PAGE 1 &amp;lt;--- !!!&lt;br /&gt;
 2048-LOMEM    $800-LOMEM   PROGRAM STORAGE&lt;br /&gt;
 2048-3071     $800-$BFF    TEXT AND LO-RES GRAPHICS PAGE 2 OR FREE SPACE&lt;br /&gt;
 3072-8191     $C00-$1FFF   FREE SPACE UNLESS RAM APPLESOFT IS IN USE&lt;br /&gt;
 8192-16383   $2000-$3FFF   HI-RES PAGE 1 OR FREE SPACE &amp;lt;--- !!!&lt;br /&gt;
16384-24575   $4000-$5FFF   HI-RES PAGE 2 OR FREE SPACE&lt;br /&gt;
24576-38999   $6000-$95FF   FREE SPACE AND STRING STORAGE&lt;br /&gt;
38400-49151   $9600-$BFFF   DOS&lt;br /&gt;
49152-53247   $C000-$CFFF   I/O HARDWARE (RESERVED)&lt;br /&gt;
53248-57343   $D000-$DFFF   APPLESOFT IN LANGUAGE CARD OR ROM&lt;br /&gt;
57344-63487   $E000-$F7FF   APPLESOFT OR INTEGER BASIC IN LANGUAGE CARD OR ROM&lt;br /&gt;
63488-65535   $F800-$FFFF   SYSTEM MONITOR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Display ===&lt;br /&gt;
&lt;br /&gt;
=== Graphics Modes ===&lt;br /&gt;
: Text Mode 40x24, for Apple IIe available 80x25 - use PR#3 for switch mode, or hardware switch&lt;br /&gt;
: LowRes 40x48, 16 colors: https://en.wikipedia.org/wiki/Apple_II_graphics &lt;br /&gt;
: Hires mode 280x192,6 colors: https://www.xtof.info/blog/?p=768&lt;br /&gt;
https://mrob.com/pub/xapple2/colors.html&lt;br /&gt;
https://archive.org/details/HiRes_Color_Graphics_on_the_Apple_II_Computer_by_Wozniak&lt;br /&gt;
&lt;br /&gt;
However for sizecoding, you almost never want to do direct-access to graphics for Apple II in size-coding because the Apple II graphics modes are horrible.  The only fast way to do things is with large lookup tables.  To do hires you need to divide by 7 which as you can imagine is a bit difficult to do compactly on 6502. Double-hires is even crazier on top of that.  Deater did manage a color-bar style effect in double-hires in 128B but that was doing some crazy tricks with the firmware BASIC routines, definitely not direct-access.&lt;br /&gt;
&lt;br /&gt;
Lores and Hires can be mixed modes and full-graphics&lt;br /&gt;
The screen structure is called memory holes(https://retrocomputing.stackexchange.com/questions/2534/what-are-the-screen-holes-in-apple-ii-graphics). The GBASCALC($F847) procedure is used to calculate the address of the horizontal line : IN:reg.A=Y, out : GBASL/GBASH($26/$27)=address. See also https://www.callapple.org/uncategorized/use-of-apple-ii-color-graphics-in-assembly-language/&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
Here is an example of a XOR texture, created by g0blinish&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
GBASL	=	$26&lt;br /&gt;
GBASH	=	$27&lt;br /&gt;
SETGR    =     $FB40 ; setup LoRes&lt;br /&gt;
GBASCALC = $F847 ; calc Address&lt;br /&gt;
&lt;br /&gt;
CLRTEXT =  $C050 ;display graphics &lt;br /&gt;
SETTEXT =  $C051 ;display text &lt;br /&gt;
&lt;br /&gt;
CLRMIXED = $C052 ;clear mixed mode- enable full graphics &lt;br /&gt;
SETMIXED = $C053 ;enable graphics/text mixed mode &lt;br /&gt;
&lt;br /&gt;
PAGE1 =    $C054 ;select text/graphics page1 &lt;br /&gt;
PAGE2 =    $C055 ;select text/graphics page2 &lt;br /&gt;
&lt;br /&gt;
CLRHIRES = $C056 ;select Lo-res &lt;br /&gt;
SETHIRES = $C057 ;select Hi-res &lt;br /&gt;
&lt;br /&gt;
TMP= $FA&lt;br /&gt;
&lt;br /&gt;
	JSR   SETGR      ;GR&lt;br /&gt;
	BIT CLRMIXED ; full screen&lt;br /&gt;
&lt;br /&gt;
	LDA #0 ; A=0&lt;br /&gt;
	STA TMP ; POKE $FA,A&lt;br /&gt;
&lt;br /&gt;
YLP ;&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
;	LSR ; A=A/2&lt;br /&gt;
	JSR GBASCALC&lt;br /&gt;
	LDY #0;Y=0&lt;br /&gt;
&lt;br /&gt;
XLP TYA ; A=Y&lt;br /&gt;
	EOR TMP ; A=A xor PEEK($FA)&lt;br /&gt;
	and #$0F ; A=A and 15&lt;br /&gt;
	TAX ; X=A&lt;br /&gt;
	LDA COLORS,X ;A=PEEK(COLORS+X)&lt;br /&gt;
	STA(GBASL),Y ; POKE PEEK($26)+256*PEEK($27)+Y,A&lt;br /&gt;
	INY ; Y=Y+1&lt;br /&gt;
	CPY #40 ; Y=40?&lt;br /&gt;
	BNE XLP&lt;br /&gt;
	INC TMP ; POKE $FA,PEEK($FA)+1&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
	CMP #24 ; A=24?&lt;br /&gt;
	BNE YLP&lt;br /&gt;
	&lt;br /&gt;
M1 JMP M1 ; replace to RTS&lt;br /&gt;
&lt;br /&gt;
COLORS ;N*17, pixel format is AAAABBBB, AAAA - upper dot, BBBB - lower dot&lt;br /&gt;
!byte $00,$11,$22,$33,$44,$55,$66,$77&lt;br /&gt;
!byte $88,$99,$AA,$BB,$CC,$DD,$EE,$FF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sound  ====&lt;br /&gt;
Here is an example for using the speaker, based onthe following basic program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;basic&amp;quot;&amp;gt;&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
;start&lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
ini:&lt;br /&gt;
	lda #70&lt;br /&gt;
	sta cnt+1&lt;br /&gt;
	lda #music&amp;amp;255&lt;br /&gt;
	sta gotbyte+1&lt;br /&gt;
	lda #music/256&lt;br /&gt;
	sta gotbyte+2&lt;br /&gt;
&lt;br /&gt;
lop:&lt;br /&gt;
;V&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L300&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
;P&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L301&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	clc&lt;br /&gt;
	adc #1&lt;br /&gt;
	sta L320&lt;br /&gt;
	jsr beep&lt;br /&gt;
	&lt;br /&gt;
	dec cnt+1&lt;br /&gt;
cnt lda #70&lt;br /&gt;
	bne lop&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
	jmp ini&lt;br /&gt;
gotbyte&lt;br /&gt;
	lda music&lt;br /&gt;
	inc gotbyte+1&lt;br /&gt;
	bne noinch&lt;br /&gt;
	inc gotbyte+2&lt;br /&gt;
noinch&lt;br /&gt;
	rts&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
beep:&lt;br /&gt;
	ldy #1&lt;br /&gt;
	ldx #1&lt;br /&gt;
loc_302:&lt;br /&gt;
		LDA	$C030&lt;br /&gt;
&lt;br /&gt;
loc_305:&lt;br /&gt;
		DEY&lt;br /&gt;
		BNE	loc_30D&lt;br /&gt;
		DEC	L301&lt;br /&gt;
loc_30B:&lt;br /&gt;
		BEQ	loc_316&lt;br /&gt;
&lt;br /&gt;
loc_30D:&lt;br /&gt;
		DEX&lt;br /&gt;
		BNE	loc_305&lt;br /&gt;
		LDX	L300&lt;br /&gt;
		JMP	loc_302&lt;br /&gt;
loc_316:&lt;br /&gt;
		DEC	L320&lt;br /&gt;
		BNE	loc_30B&lt;br /&gt;
		RTS&lt;br /&gt;
L301 !byte 0&lt;br /&gt;
L300 !byte 0&lt;br /&gt;
L320 !byte 0&lt;br /&gt;
music&lt;br /&gt;
 !word 76,192,85,64,96,64,102,64,114,128,114,64,96,64,102,64,114,64,128,64&lt;br /&gt;
 !word 114,64,152,64,171,64,152,512,76,192,85,64,96,64,102,64,114,128,114,64&lt;br /&gt;
 !word 96,64,102,64,114,64,128,64,114,64,152,64,171,64,152,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,128,114,64,128,64,114,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,64,128,128,96,64,85,64,96,64,102,64,114,64,114,64&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Deater's page on Apple II sizecoding http://www.deater.net/weave/vmwprod/demos/sizecoding.html (with an additional presentation at https://www.youtube.com/watch?v=kJ-EXbnw0kQ )&lt;br /&gt;
* Article on double hi-res http://www.battlestations.zone/2017/04/apple-ii-double-hi-res-from-ground-up.html&lt;br /&gt;
* Applesoft Hi-Res Subroutines : http://hackzapple.org/scripts_php/index.php?menu=5&amp;amp;mod=ASM&amp;amp;sub=AAL&amp;amp;sub2=8112&amp;amp;PHPSESSID=f65fabfd0cdbf56b6bdc0ddac25117c6#a2&lt;br /&gt;
&lt;br /&gt;
== Atari Lynx ==&lt;br /&gt;
The Atari Lynx consists of the 65C02 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari Lynx:&lt;br /&gt;
&lt;br /&gt;
* Assembler:&lt;br /&gt;
Below size coding examples use [https://github.com/42Bastian/lyxass Lyxass] as assembler and are using the in-official DevKit [https://github.com/42Bastian/new_bll new_bll].&amp;lt;br&amp;gt;&lt;br /&gt;
But any other 6502 assembler is suitable. Best if it can assemble the extra opcodes of the 65C02 (like &amp;lt;b&amp;gt;BBRx&amp;lt;/b&amp;gt; or &amp;lt;b&amp;gt;RMBx&amp;lt;/b&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Encryption&lt;br /&gt;
The Lynx boot ROM will decrypt the &amp;quot;boot sector&amp;quot; of a Lynx card image. It is done in chunks of 50bytes. Maximum are 5 chunks, hence the limit of a &amp;quot;boot sector&amp;quot; is 250 bytes, but the last byte &amp;lt;b&amp;gt;must&amp;lt;/b&amp;gt; be zero.&lt;br /&gt;
&lt;br /&gt;
* Emulator(s): &lt;br /&gt;
Currently Felix is the most accurate Emulator, though only running yet on Windows platform.&amp;lt;br&amp;gt;&lt;br /&gt;
It is currently available via [https://github.com/laoo/Felix GitHub].&lt;br /&gt;
&lt;br /&gt;
* Hardware:&lt;br /&gt;
If you want to run the code on a real Lynx, you should have a SD card for the Lynx (AgaCard, LynxGD) and also a USB&amp;lt;-&amp;gt;Serial adapter.&lt;br /&gt;
&lt;br /&gt;
=== Initial values ===&lt;br /&gt;
After the boot-rom has decrypted the boot-sector, some things are pre-defined:&lt;br /&gt;
* CPU Registers:&lt;br /&gt;
  A = 0&lt;br /&gt;
  X = 0&lt;br /&gt;
  Y = 2&lt;br /&gt;
  P = undefined&lt;br /&gt;
  S = undefined&lt;br /&gt;
&lt;br /&gt;
* Zero page&lt;br /&gt;
&lt;br /&gt;
 $00 - 0&lt;br /&gt;
 $01 - 0&lt;br /&gt;
 $02 - 0&lt;br /&gt;
&lt;br /&gt;
* Main&lt;br /&gt;
&lt;br /&gt;
Main memory is cleared to zero despite a $5000..%$50aa where decryption code is placed.&lt;br /&gt;
&lt;br /&gt;
* Bank switching&lt;br /&gt;
&lt;br /&gt;
ROM, Mikey and Suzy are mapped, Vector table is ROM.&lt;br /&gt;
&lt;br /&gt;
* Suzy&lt;br /&gt;
The sprite engine is &amp;lt;b&amp;gt;not&amp;lt;/b&amp;gt; setup.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
The Lynx display is 160x102 pixels which are linear organized as 4 bit per pixel. Hence the screen is little less than 8K.&lt;br /&gt;
The pixel value is a pointer to the color look up table.&lt;br /&gt;
The Lynx can display black and 4095 colors. The color table is split up into a green and an blue-red part (so not RGB but GBR).&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
After the ROM has deciphered the boot sector the display memory is at $2000, background color (that is pen 0) is black, all other entries are $f despite entry 14 which is also 0.&lt;br /&gt;
&lt;br /&gt;
So to fill the screen simply do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lda #$ff&lt;br /&gt;
ldx #0&lt;br /&gt;
ldy #$20   ; round(160*102/2/256)&lt;br /&gt;
loop:&lt;br /&gt;
    sta $2000,x&lt;br /&gt;
    inx&lt;br /&gt;
  bne loop&lt;br /&gt;
  inc loop+2 ; Self modify&lt;br /&gt;
  dey&lt;br /&gt;
bne loop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
*[https://www.monlynx.de/lynx/lynxdoc.html Hardware documentation]&lt;br /&gt;
*[https://github.com/42Bastian/lynx_hacking/tree/master/248b Size coding examples.]&lt;br /&gt;
*[https://github.com/42Bastian/lynx-encryption-tools Lynx encryption-tools]&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=6502&amp;diff=1006</id>
		<title>6502</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=6502&amp;diff=1006"/>
				<updated>2022-01-31T09:01:30Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: /* Atari Lynx */ add more info&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Wanting to start sizecoding on a 6502 platform in this day and age can be tough. &lt;br /&gt;
&lt;br /&gt;
[[File:6502.jpg|thumb]]&lt;br /&gt;
&lt;br /&gt;
So here is a bit of help to get you started:&lt;br /&gt;
&lt;br /&gt;
=== The 6502 processor  ===&lt;br /&gt;
The 6502 processor can be seen as the 8-bit micro ARM chip. &lt;br /&gt;
It has only has 3 registers (Accumulator, X and Y registers) and a handful of instructions to work with.&lt;br /&gt;
&lt;br /&gt;
=== Adressing modes ===&lt;br /&gt;
To be added.&lt;br /&gt;
&lt;br /&gt;
=== Zero page ===&lt;br /&gt;
When using the 6502 for sizecoding, you'll mostly be working from zeropage&lt;br /&gt;
&lt;br /&gt;
=== General 6502 Resources ===&lt;br /&gt;
* 6502.org http://www.6502.org/&lt;br /&gt;
* 6502 instruction reference http://www.6502.org/tutorials/6502opcodes.html&lt;br /&gt;
* 6502 books http://retro.hansotten.nl/6502-sbc/&lt;br /&gt;
* 6502 Assembler tutorial https://dwheeler.com/6502/oneelkruns/asm1step.html&lt;br /&gt;
* Easy 6502 code tester https://skilldrick.github.io/easy6502/&lt;br /&gt;
* Synthetic instructions https://wiki.nesdev.com/w/index.php/Synthetic_instructions#8-bit_rotate&lt;br /&gt;
&lt;br /&gt;
== Atari 8-bit family ==&lt;br /&gt;
The systems in this family are: Atari 400, 800, 5200, 1200XL, 600XL, 800XL, 130XE, 65XE, 800XE and XEGS.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Atari 8-bit systems consists of the 6502 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari 8bit systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: MADS Assembler - This assembler has nice macros for creating Binaries and SNA snapshot files out of the box. You can download it at https://mads.atari8.info/&lt;br /&gt;
* Emulator(s): I Found Altirra to work best for my usecase. Make sure to use the original Rev2 rom for best compatibility.&lt;br /&gt;
&lt;br /&gt;
==== Special Memory Adresses ====&lt;br /&gt;
* FRAMECOUNTER_HIGH = 19&lt;br /&gt;
* FRAMECOUNTER_LOW  = 20&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Atari 8bit systems use the ANTIC and GTIA chips. Information can be found here:&lt;br /&gt;
* https://en.wikipedia.org/wiki/ANTIC&lt;br /&gt;
* https://www.atariarchives.org/agagd/chapter1.php&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
      lda RTCLOK+2&lt;br /&gt;
waits&lt;br /&gt;
      cmp RTCLOK+2&lt;br /&gt;
      beq waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or if you don't mind trashing RTCLOK&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
waits&lt;br /&gt;
      lsr RTCLOK+2&lt;br /&gt;
      bcc waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which is two bytes shorter.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
;fill screen with charset,(88,89)=an address&lt;br /&gt;
 org $600; free 6th page:600-6ff&lt;br /&gt;
 ldy #0&lt;br /&gt;
fl: tya&lt;br /&gt;
 sta(88),y&lt;br /&gt;
 iny&lt;br /&gt;
 bne fl&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
SDMCTL	= $022f&lt;br /&gt;
HPOSP0  = $d000&lt;br /&gt;
SIZEP0  = $d008&lt;br /&gt;
GRAFP0  = $d00d&lt;br /&gt;
COLPM0  = $d012&lt;br /&gt;
&lt;br /&gt;
FRAMECOUNTER_HIGH = 19&lt;br /&gt;
FRAMECOUNTER = 20&lt;br /&gt;
WSYNC	= $d40a&lt;br /&gt;
VCOUNT	= $d40b&lt;br /&gt;
&lt;br /&gt;
sinewave	= $0600		; to $06ff&lt;br /&gt;
&lt;br /&gt;
		org $80&lt;br /&gt;
&lt;br /&gt;
main	&lt;br /&gt;
	; disable all graphics/colors&lt;br /&gt;
	ldx #0&lt;br /&gt;
	stx SDMCTL	&lt;br /&gt;
&lt;br /&gt;
	ldy #$7f&lt;br /&gt;
	sty SIZEP0	; size p0=127&lt;br /&gt;
		&lt;br /&gt;
	ldx #0&lt;br /&gt;
	ldy #$3f&lt;br /&gt;
make_sine:&lt;br /&gt;
value_lo&lt;br /&gt;
			lda #0&lt;br /&gt;
			clc&lt;br /&gt;
delta_lo&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_lo+1&lt;br /&gt;
value_hi&lt;br /&gt;
			lda #0&lt;br /&gt;
delta_hi&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_hi+1&lt;br /&gt;
 &lt;br /&gt;
			sta sinewave+$c0,x&lt;br /&gt;
			sta sinewave+$80,y&lt;br /&gt;
			eor #$7f&lt;br /&gt;
			sta sinewave+$40,x&lt;br /&gt;
			sta sinewave+$00,y&lt;br /&gt;
 &lt;br /&gt;
			lda delta_lo+1&lt;br /&gt;
			adc #8&lt;br /&gt;
			sta delta_lo+1&lt;br /&gt;
			bcc nothing&lt;br /&gt;
			inc delta_hi+1&lt;br /&gt;
nothing&lt;br /&gt;
			inx&lt;br /&gt;
			dey&lt;br /&gt;
			bpl make_sine&lt;br /&gt;
&lt;br /&gt;
updateloop:&lt;br /&gt;
		; vblank&lt;br /&gt;
		lda VCOUNT&lt;br /&gt;
		bne updateloop&lt;br /&gt;
&lt;br /&gt;
		; clear graphics&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		ldy #0&lt;br /&gt;
		lda #47&lt;br /&gt;
		sta COLPM0&lt;br /&gt;
yloop:&lt;br /&gt;
		tya           ; graphics shape = y&lt;br /&gt;
		sta WSYNC&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		; a = sin(frame+y)+48&lt;br /&gt;
		tya	&lt;br /&gt;
		adc FRAMECOUNTER&lt;br /&gt;
		tax&lt;br /&gt;
		lda sinewave,x&lt;br /&gt;
		adc #48&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
                &lt;br /&gt;
                iny&lt;br /&gt;
                bne yloop&lt;br /&gt;
		jmp updateloop&lt;br /&gt;
&lt;br /&gt;
		run main&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Atari 8-bit use the POKEY chip to generate sound.&lt;br /&gt;
* https://en.wikipedia.org/wiki/POKEY&lt;br /&gt;
&lt;br /&gt;
==== BASIC ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
; from Analog, 1985-09,pp.25-32&lt;br /&gt;
*=$2000&lt;br /&gt;
AUDF1=$D200&lt;br /&gt;
AUDC1=$D201&lt;br /&gt;
AUDCTL=$D208&lt;br /&gt;
SKCTL=$D20F&lt;br /&gt;
&lt;br /&gt;
.MACRO SOUND ; voice,pitch,dist,vol;,dur&lt;br /&gt;
	lda #%2&lt;br /&gt;
	sta AUDF1+2*%1&lt;br /&gt;
    lda #[[%3 * 16] | %4] ;lda #[[%3 shl 4] or %4]&lt;br /&gt;
    sta AUDC1+2*%1&lt;br /&gt;
.ENDM&lt;br /&gt;
&lt;br /&gt;
 lda #0&lt;br /&gt;
 sta AUDCTL&lt;br /&gt;
 lda #3&lt;br /&gt;
 sta SKCTL&lt;br /&gt;
&lt;br /&gt;
 SOUND 0,121,10,8&lt;br /&gt;
&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
Sizecoding resource for the Atari 8bit are:&lt;br /&gt;
* Mapping the Atari https://www.atariarchives.org/mapping/&lt;br /&gt;
* Atari 8bit Memory map https://www.atariarchives.org/mapping/memorymap.php&lt;br /&gt;
* Fready's undocumented 6502 opcodes https://github.com/FreddyOffenga/6502&lt;br /&gt;
* Atari OS Rev2 disassembly for MADS assembler https://github.com/ilmenit/A800-OS-XL-Rev2&lt;br /&gt;
* Fready's github https://github.com/FreddyOffenga/&lt;br /&gt;
&lt;br /&gt;
== Commodore 64 ==&lt;br /&gt;
The Commodore system consists of a 6502-compatible MOS 6510 processor with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Commodore systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: To be added&lt;br /&gt;
* Emulator(s): VICE is the way to go&lt;br /&gt;
&lt;br /&gt;
=== Memory map ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
    0-1          $0-$1      PROCESSOR PORT REGISTERS, not usable as RAM&lt;br /&gt;
   0-255         $0-$FF     ZEROPAGE, mostly used by BASIC interpreter and Kernal&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-600      $200-$258    INPUT BUFFER&lt;br /&gt;
  601-630      $259-$276    FILE SYSTEM DATA&lt;br /&gt;
  631-640      $277-$280    KEYBOARD BUFFER, filled by Kernal ISR upon key presses &lt;br /&gt;
  641-678      $281-$2A6    VARIOUS KERNAL VARIABLES&lt;br /&gt;
  679-767      $2A7-$2FF    Unused (89 byte)&lt;br /&gt;
  768-779      $300-$30B    KERNAL VECTORS&lt;br /&gt;
  780-783      $30C-$30F    REGISTER VALUES A,X,Y,SR for SYS&lt;br /&gt;
  784-819      $310-$333    KERNAL VECTORS&lt;br /&gt;
  820-827      $334-$33B    Unused (8 byte)&lt;br /&gt;
  828-1019     $33C-$3FB    DATASETTE BUFFER&lt;br /&gt;
 1020-1023     $3FC-$3FF    Unused (4 byte)&lt;br /&gt;
 1024-2023     $400-$7E7    SCREEN MEMORY (25 lines times 40 columns)&lt;br /&gt;
 2024-2039     $7E8-$7F7    Unused (16 byte)&lt;br /&gt;
 2040-2047     $7F8-$7FF    SPRITE COSTUME POINTERS&lt;br /&gt;
 2048          $800         must contain a value of 0 so that the BASIC program can be RUN&lt;br /&gt;
 2049-40959    $801-$9FFF   BASIC AREA (code, variables, arrays, strings)&lt;br /&gt;
40960-49151   $A000-$BFFF   BASIC ROM (unused RAM underneath)&lt;br /&gt;
49152-53247   $C000-$CFFF   UPPER RAM AREA (unused)&lt;br /&gt;
53248-53294   $D000-$D02E   VIC-II, memory-mapped graphics chip registers)&lt;br /&gt;
54272-54300   $D400-$D41C   SID, memory-mapped sound chip registers)&lt;br /&gt;
55296-56295   $D800-$DBE7   Color RAM, only lower 4 bits are stored, higher nibble undefined&lt;br /&gt;
56296-56319   $DBE8-$DBFF   Unused (24 half-bytes)&lt;br /&gt;
56320-56335   $DC00-$DC0F   CIA#1, memory-mapped I/O chip registers for keyboard, joystick, mouse, datasette, IRQ control&lt;br /&gt;
56576-56591   $DD00-$DD0F   CIA#1, memory-mapped I/O chip registers for serial bus, RS232, NMI control&lt;br /&gt;
57344-65535   $E000-$FFFF   KERNAL ROM&lt;br /&gt;
65534-65535   $FFFE-$FFFF   Execution address of interrupt service routine, can only be set if KERNAL is turned off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a detailed explanation of the C64 memory map check out [https://sta.c64.org/cbm64mem.html Commodore 64 memory map] on Joe Forster/STA homepage.&lt;br /&gt;
&lt;br /&gt;
=== Program file overhead ===&lt;br /&gt;
&lt;br /&gt;
A standard CBM file consists of a 2 byte loading address followed by the data that is placed into memory starting at this address. In addition, if your machine program should be able to be started with &amp;quot;RUN&amp;quot;, you need a BASIC stub that is loaded into memory from $0801 to $080c, typically followed by your machine program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0801&lt;br /&gt;
        .word $080b   ;address of next BASIC line&lt;br /&gt;
        .word LINENO  ;line number, can be chosen between 0 and 63999&lt;br /&gt;
        .byte $9e     ;token for SYS command&lt;br /&gt;
        .byte $32,$30,$35,$39  ;address to jump to in ASCII code: &amp;quot;2059&amp;quot; &lt;br /&gt;
        .byte $00     ;end of BASIC line&lt;br /&gt;
start   lax #0        ;actually address of next BASIC line, $xx00 means end of BASIC program, use $xx for an opcode&lt;br /&gt;
; your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the 2 byte load address, this makes an overhead of 14 bytes for your program, coming with A and X initialised to 0. To reduce this, you can&lt;br /&gt;
* omit the BASIC line and tell users to start your program by directly entering &amp;quot;SYS ''address''&amp;quot;&lt;br /&gt;
* save your program from $0802 on, the byte at $0801 is recovered automatically after loading by the relink function. This reduces your program file size by 1 byte&lt;br /&gt;
* accept the loss and use the 2 byte establishing LINENO for something good, they are copied to zeropage addresses $39/$3a automatically, saving you the effort of initializing the addresses&lt;br /&gt;
* use an autostart method (see below)&lt;br /&gt;
&lt;br /&gt;
Some compos also specify that the BASIC loader does not count towards the overall filesize, check the rules before you worry.&lt;br /&gt;
&lt;br /&gt;
=== Autostart ===&lt;br /&gt;
&lt;br /&gt;
Unlike the Commodore 128, the Commodore 64 has no dedicated built-in auto-boot feature, but it is possible to autorun a program after loading by specifying the load address so that it overwrites a vector or address that is called by the operating system. There are multiple possibilities:&lt;br /&gt;
&lt;br /&gt;
==== Overwriting  CHROUT vector at $326-$327 ====&lt;br /&gt;
&lt;br /&gt;
The vector at address $326-$327 points at the CHROUT routine, normally at address $F1CA.&lt;br /&gt;
If you put the entry address of your program into $326/27, your code will be called when the operating system wants to print &amp;quot;READY.&amp;quot; after loading.&lt;br /&gt;
Note that the vector at address $328-$329 points at the STOP routine that checks the status of Stop key indicator. Since this routine is called multiple times before your code is done loading, its default value $F6ED needs to be preserved. &lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0326&lt;br /&gt;
        .word start              &lt;br /&gt;
        .byte $ed,$f6&lt;br /&gt;
start&lt;br /&gt;
; rest of code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address, the overwritten CHROUT vector and the preserved STOP vector, your program file will have a deadweight of 6 byte: $26 $03 $0a $03 $ed $f6, less than half of the standard version with a BASIC stub with SYS&lt;br /&gt;
&lt;br /&gt;
Caveat:&lt;br /&gt;
* If your program after $32a is longer than 214 byte, part of your program will load into the screen at $400. Thus, issuing a clear screen will overwrite your program. It is possible to move the screen memory somewhere else, but that requires storing a new value into address $D018, which when done with an LDA # / STA pair will cost you 5 byte&lt;br /&gt;
* Since you changed the CHROUT pointer, standard KERNAL functions for printing won't work. For output of single characters, you can still use the direct address $F1CA. Alternatively, you can restore the vectors by calling $FD15, which will overwrite the memory $314 to $333 with the default values.&lt;br /&gt;
* The memory area $33C-$3FB is the datasette buffer, thus loading a program into this area won't work when loading from a cassette.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting BASIC idle loop vector at $302-$303 ====&lt;br /&gt;
&lt;br /&gt;
After loading the program, the BASIC idle loop will be called. By overwriting the vector at $302/$303 it is possible to autostart your program. Since the memory before $302 can be safely overwritten, the program would be arranged so that $303 is the '''last''' address of your program. If your program requires a loop back to the start, the vector can be used as part of a JMP where the following two bytes are already there, saving one byte in comparison to a loop done with a branch command.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$304 - (end - start)&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
        ; ...&lt;br /&gt;
        jmp     start    ;the address for start lies in $302/$303, thus will be called by the Kernal after loading&lt;br /&gt;
end:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In cases where the vector has a practical use, the overhead in filesize is only the 2 byte loading address. For programs larger than 93 byte keep in mind that addresses before $2A7 are in use by the Kernal.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting return address on stack at $1F8 ====&lt;br /&gt;
&lt;br /&gt;
When the load routine is called, the stack pointer is always at $FA at a stock C64. Thus the return address from the loading process is stored in memory address $1F8 (low byte) and $1F9 (high byte). During the loading routine, stack usage will clobber the stack below $1F8, but a program loaded to $1F8 and above will be fine and the overwritten address stored at $1F8/$1F9 will be called after loading.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$1F8&lt;br /&gt;
        .word start-1   ;adjust for the RTS command pulling the address from stack and increasing it by 1&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For programs larger than 95 byte keep in mind that addresses after $259 are in use by the Kernal, you might overwrite some values here if you don't have disk operations, but better check the memory map beforehand.&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address and the overwritten address at $1F8/$1F9, your program file will have a deadweight of 4 byte when using this method.&lt;br /&gt;
&lt;br /&gt;
==== Putting your program into zeropage overwriting part of CHRGET ====&lt;br /&gt;
&lt;br /&gt;
CHRGET is a machine code routine for the BASIC interpreter that is placed in the zero page at $73-$8A. By putting your program at $7C and following, the CHRGET routine runs directly into your code.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$7C&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this method, there is no need for a start address vector. The only deadweight in your program is the loading address. However, the zero page is a busy place, if your program extends beyond address $8f (that is it has more than 22 bytes on disk) you have to deal with some parts of your program being overwritten, for example, the status byte in $90 is set after loading.&lt;br /&gt;
&lt;br /&gt;
Loading data into address $A9 has an interesting side effect - the vector of $AE/$AF defines the address where the loaded bytes are written to. If $AE gets overwritten with, for example, $40, the next byte will be written to $41 (because the vector is incremented after the write). This can be used to split your program into different parts of memory.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Commodore has the following native video modes:&lt;br /&gt;
* Standard text mode, 40x25 characters, 1 individual foreground color per character, 1 common background color&lt;br /&gt;
* Multicolor text mode, 40x25 characters, only 8 foreground colors, can be mixed with hires chars, foreground &amp;lt; 8 denotes a hires char, with foreground &amp;gt;= 8 a pair of two bits (brick pixel) define color: background, foreground &amp;amp; %111, common color 1+2&lt;br /&gt;
* Extended background color text mode, 40x25 characters, 1 individual foreground color per character, 1 out of 4 background colors, only 64 chars&lt;br /&gt;
* Hires bitmap, 320x200 pixels, an 8x8 field can have an individual foreground and an individual background color&lt;br /&gt;
* Multicolor bitmap, 160x200 pixels, a pair of two bits (brick pixel) define color: background, screen color lower nibble, screen color higher nibble, color from color RAM&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&lt;br /&gt;
Depending on the VIC type, there are 262/263 raster lines (NTSC) or 312 raster lines (PAL-B). Therefore, the VIC uses register at $D012 and the highest bit of register $D011 to represent the current raster line. Checking only the lower 8 bits and waiting for them to be 0 would therefore not work because this happens two times per frame. However, any number greater than 64 will only trigger once. Using a value of 255, we would sync to a rasterline at the end of the screen, well below the part where graphics are normally displayed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
waitsync:&lt;br /&gt;
        ldx $D012&lt;br /&gt;
        inx&lt;br /&gt;
        bne waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as there have more than 63 cycles passed since the snyc, the next sync will happen at the next frame.&lt;br /&gt;
This works fine as long as we don't miss the line 255 due to an interrupt. If your program has interrupts that are not synced to a rasterline, you can change the condition as follows&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda #$E3&lt;br /&gt;
waitsync:&lt;br /&gt;
        cmp $D012&lt;br /&gt;
        bcs waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we have a window between raster line $E4 and $FF to trigger our sync, which we will meet even if a standard Kernal interrupt comes in-between. Of course, our main program now has to burn around 1700 cycles to avoid a retriggering in the same frame.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&lt;br /&gt;
Output a character:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #C       ;C must be the char code according to the PETSCII code table&lt;br /&gt;
        jsr     $FFD2    ;you can also use the direct address $FC1A, function preserves A,X,Y and enables interrupt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the [https://en.wikipedia.org/wiki/PETSCII#Character_set PETSCII code table] contains also control characters, this method can be also used to clear the screen, move the cursor or set the text color. However, some functions are shorter (and faster) by directly calling the respective KERNAL function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
Clear screen             JSR $E544&lt;br /&gt;
Cursor home position     JSR $E566&lt;br /&gt;
Output newline character JSR $AAD7&lt;br /&gt;
Set text color           LDA #COLOR, STA $286&lt;br /&gt;
Set border color         LDA #COLOR, STA $D020   ;not possible with a PETSCII control code&lt;br /&gt;
Set background color     LDA #COLOR, STA $D021   ;not possible with a PETSCII control code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy characters directly to screen memory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm   ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
LINE=5    ;for example&lt;br /&gt;
COLUMN=10 ;for example&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the text needs to be stored in '''screen code''' format, not in PETSCII (see [https://sta.c64.org/cbm64pettoscr.html Commodore 64 PETSCII code to screen code conversion] for the differences). Furthermore, the example above only writes to the screen memory, not the color RAM, assuming that the color RAM already contains the intended text color. This is the case after issuing a clear screen on most C64 machines, except for some old ROM revisions. To be on the save side you would have to write to color RAM as well, which costs another 5 byte:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm     ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
COLOR_RAM  =$D800&lt;br /&gt;
LINE       =5    ;for example&lt;br /&gt;
COLUMN     =10   ;for example&lt;br /&gt;
COLOR      =1    ;white&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        lda     #COLOR&lt;br /&gt;
        sta     COLOR_RAM  +LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Commodore 64 uses the famous SID chip to generate sound.&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Useful Kernal functions ===&lt;br /&gt;
&lt;br /&gt;
==== Get a pseudo random number ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #1   &lt;br /&gt;
        jsr     $E09A&lt;br /&gt;
        lda     $63&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The sequence of random numbers is always the same after a cold start or reset, the first 20 numbers are:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 4,24,231,4,177,170,193,101,231,18,196,1,75,48,149,36,124,53,65,154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Increment a zero page counter, return in X register, clear Y register ====&lt;br /&gt;
&lt;br /&gt;
This is part of the string handling function in the BASIC ROM, but the code could be useful for some loop stuff.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        jsr     $B5FF    ;does inc $23, ldx $23, ldy #$00, rts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Codebase 64 https://codebase64.org/doku.php?id=base:start&lt;br /&gt;
* Commodore 64 Memory map https://sta.c64.org/cbm64mem.html&lt;br /&gt;
* C64 BASIC &amp;amp; KERNAL ROM Disassembly https://www.pagetable.com/c64ref/c64disasm/&lt;br /&gt;
* No More Secrets https://csdb.dk/release/?id=198357 Everything about illegal opcodes and their use in a C64 system&lt;br /&gt;
&lt;br /&gt;
== Apple II ==&lt;br /&gt;
The Apple II is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* ACME 6502 cross-assembler(https://sourceforge.net/projects/acme-crossass/)&lt;br /&gt;
* Apple Commander (http://applecommander.sourceforge.net) for batch compilation&lt;br /&gt;
* AppleWin emulator (https://github.com/AppleWin/AppleWin/releases). Supports Mockingboard card(AY-8910+speech synthesier), HDD, Z80 card(for CP/M), mouse etc.&lt;br /&gt;
* CiderPress(https://a2ciderpress.com)&lt;br /&gt;
&lt;br /&gt;
Compilation can be done as follows (master.dsk can be found with applewin) &lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
acme hl.asm&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -d master.dsk hl&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -p master.dsk hl B 24576 &amp;lt; hl.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Memory Map ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
   0-255	 $0-$FF     ZERO-PAGE SYSTEM STORAGE&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-767      $200-$2FF    KEYBOARD CHARACTER BUFFER&lt;br /&gt;
  768-975      $300-$3CF    OFTEN AVAILABLE AS FREE SPACE FOR USER PROGRAMS&lt;br /&gt;
  976-1023     $3D0-3FF     SYSTEM VECTORS&lt;br /&gt;
 1024-2047     $400-$7FF    TEXT AND LO-RES GRAPHICS PAGE 1 &amp;lt;--- !!!&lt;br /&gt;
 2048-LOMEM    $800-LOMEM   PROGRAM STORAGE&lt;br /&gt;
 2048-3071     $800-$BFF    TEXT AND LO-RES GRAPHICS PAGE 2 OR FREE SPACE&lt;br /&gt;
 3072-8191     $C00-$1FFF   FREE SPACE UNLESS RAM APPLESOFT IS IN USE&lt;br /&gt;
 8192-16383   $2000-$3FFF   HI-RES PAGE 1 OR FREE SPACE &amp;lt;--- !!!&lt;br /&gt;
16384-24575   $4000-$5FFF   HI-RES PAGE 2 OR FREE SPACE&lt;br /&gt;
24576-38999   $6000-$95FF   FREE SPACE AND STRING STORAGE&lt;br /&gt;
38400-49151   $9600-$BFFF   DOS&lt;br /&gt;
49152-53247   $C000-$CFFF   I/O HARDWARE (RESERVED)&lt;br /&gt;
53248-57343   $D000-$DFFF   APPLESOFT IN LANGUAGE CARD OR ROM&lt;br /&gt;
57344-63487   $E000-$F7FF   APPLESOFT OR INTEGER BASIC IN LANGUAGE CARD OR ROM&lt;br /&gt;
63488-65535   $F800-$FFFF   SYSTEM MONITOR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Display ===&lt;br /&gt;
&lt;br /&gt;
=== Graphics Modes ===&lt;br /&gt;
: Text Mode 40x24, for Apple IIe available 80x25 - use PR#3 for switch mode, or hardware switch&lt;br /&gt;
: LowRes 40x48, 16 colors: https://en.wikipedia.org/wiki/Apple_II_graphics &lt;br /&gt;
: Hires mode 280x192,6 colors: https://www.xtof.info/blog/?p=768&lt;br /&gt;
https://mrob.com/pub/xapple2/colors.html&lt;br /&gt;
https://archive.org/details/HiRes_Color_Graphics_on_the_Apple_II_Computer_by_Wozniak&lt;br /&gt;
&lt;br /&gt;
However for sizecoding, you almost never want to do direct-access to graphics for Apple II in size-coding because the Apple II graphics modes are horrible.  The only fast way to do things is with large lookup tables.  To do hires you need to divide by 7 which as you can imagine is a bit difficult to do compactly on 6502. Double-hires is even crazier on top of that.  Deater did manage a color-bar style effect in double-hires in 128B but that was doing some crazy tricks with the firmware BASIC routines, definitely not direct-access.&lt;br /&gt;
&lt;br /&gt;
Lores and Hires can be mixed modes and full-graphics&lt;br /&gt;
The screen structure is called memory holes(https://retrocomputing.stackexchange.com/questions/2534/what-are-the-screen-holes-in-apple-ii-graphics). The GBASCALC($F847) procedure is used to calculate the address of the horizontal line : IN:reg.A=Y, out : GBASL/GBASH($26/$27)=address. See also https://www.callapple.org/uncategorized/use-of-apple-ii-color-graphics-in-assembly-language/&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
Here is an example of a XOR texture, created by g0blinish&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
GBASL	=	$26&lt;br /&gt;
GBASH	=	$27&lt;br /&gt;
SETGR    =     $FB40 ; setup LoRes&lt;br /&gt;
GBASCALC = $F847 ; calc Address&lt;br /&gt;
&lt;br /&gt;
CLRTEXT =  $C050 ;display graphics &lt;br /&gt;
SETTEXT =  $C051 ;display text &lt;br /&gt;
&lt;br /&gt;
CLRMIXED = $C052 ;clear mixed mode- enable full graphics &lt;br /&gt;
SETMIXED = $C053 ;enable graphics/text mixed mode &lt;br /&gt;
&lt;br /&gt;
PAGE1 =    $C054 ;select text/graphics page1 &lt;br /&gt;
PAGE2 =    $C055 ;select text/graphics page2 &lt;br /&gt;
&lt;br /&gt;
CLRHIRES = $C056 ;select Lo-res &lt;br /&gt;
SETHIRES = $C057 ;select Hi-res &lt;br /&gt;
&lt;br /&gt;
TMP= $FA&lt;br /&gt;
&lt;br /&gt;
	JSR   SETGR      ;GR&lt;br /&gt;
	BIT CLRMIXED ; full screen&lt;br /&gt;
&lt;br /&gt;
	LDA #0 ; A=0&lt;br /&gt;
	STA TMP ; POKE $FA,A&lt;br /&gt;
&lt;br /&gt;
YLP ;&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
;	LSR ; A=A/2&lt;br /&gt;
	JSR GBASCALC&lt;br /&gt;
	LDY #0;Y=0&lt;br /&gt;
&lt;br /&gt;
XLP TYA ; A=Y&lt;br /&gt;
	EOR TMP ; A=A xor PEEK($FA)&lt;br /&gt;
	and #$0F ; A=A and 15&lt;br /&gt;
	TAX ; X=A&lt;br /&gt;
	LDA COLORS,X ;A=PEEK(COLORS+X)&lt;br /&gt;
	STA(GBASL),Y ; POKE PEEK($26)+256*PEEK($27)+Y,A&lt;br /&gt;
	INY ; Y=Y+1&lt;br /&gt;
	CPY #40 ; Y=40?&lt;br /&gt;
	BNE XLP&lt;br /&gt;
	INC TMP ; POKE $FA,PEEK($FA)+1&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
	CMP #24 ; A=24?&lt;br /&gt;
	BNE YLP&lt;br /&gt;
	&lt;br /&gt;
M1 JMP M1 ; replace to RTS&lt;br /&gt;
&lt;br /&gt;
COLORS ;N*17, pixel format is AAAABBBB, AAAA - upper dot, BBBB - lower dot&lt;br /&gt;
!byte $00,$11,$22,$33,$44,$55,$66,$77&lt;br /&gt;
!byte $88,$99,$AA,$BB,$CC,$DD,$EE,$FF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sound  ====&lt;br /&gt;
Here is an example for using the speaker, based onthe following basic program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;basic&amp;quot;&amp;gt;&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
;start&lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
ini:&lt;br /&gt;
	lda #70&lt;br /&gt;
	sta cnt+1&lt;br /&gt;
	lda #music&amp;amp;255&lt;br /&gt;
	sta gotbyte+1&lt;br /&gt;
	lda #music/256&lt;br /&gt;
	sta gotbyte+2&lt;br /&gt;
&lt;br /&gt;
lop:&lt;br /&gt;
;V&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L300&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
;P&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L301&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	clc&lt;br /&gt;
	adc #1&lt;br /&gt;
	sta L320&lt;br /&gt;
	jsr beep&lt;br /&gt;
	&lt;br /&gt;
	dec cnt+1&lt;br /&gt;
cnt lda #70&lt;br /&gt;
	bne lop&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
	jmp ini&lt;br /&gt;
gotbyte&lt;br /&gt;
	lda music&lt;br /&gt;
	inc gotbyte+1&lt;br /&gt;
	bne noinch&lt;br /&gt;
	inc gotbyte+2&lt;br /&gt;
noinch&lt;br /&gt;
	rts&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
beep:&lt;br /&gt;
	ldy #1&lt;br /&gt;
	ldx #1&lt;br /&gt;
loc_302:&lt;br /&gt;
		LDA	$C030&lt;br /&gt;
&lt;br /&gt;
loc_305:&lt;br /&gt;
		DEY&lt;br /&gt;
		BNE	loc_30D&lt;br /&gt;
		DEC	L301&lt;br /&gt;
loc_30B:&lt;br /&gt;
		BEQ	loc_316&lt;br /&gt;
&lt;br /&gt;
loc_30D:&lt;br /&gt;
		DEX&lt;br /&gt;
		BNE	loc_305&lt;br /&gt;
		LDX	L300&lt;br /&gt;
		JMP	loc_302&lt;br /&gt;
loc_316:&lt;br /&gt;
		DEC	L320&lt;br /&gt;
		BNE	loc_30B&lt;br /&gt;
		RTS&lt;br /&gt;
L301 !byte 0&lt;br /&gt;
L300 !byte 0&lt;br /&gt;
L320 !byte 0&lt;br /&gt;
music&lt;br /&gt;
 !word 76,192,85,64,96,64,102,64,114,128,114,64,96,64,102,64,114,64,128,64&lt;br /&gt;
 !word 114,64,152,64,171,64,152,512,76,192,85,64,96,64,102,64,114,128,114,64&lt;br /&gt;
 !word 96,64,102,64,114,64,128,64,114,64,152,64,171,64,152,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,128,114,64,128,64,114,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,64,128,128,96,64,85,64,96,64,102,64,114,64,114,64&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Deater's page on Apple II sizecoding http://www.deater.net/weave/vmwprod/demos/sizecoding.html (with an additional presentation at https://www.youtube.com/watch?v=kJ-EXbnw0kQ )&lt;br /&gt;
* Article on double hi-res http://www.battlestations.zone/2017/04/apple-ii-double-hi-res-from-ground-up.html&lt;br /&gt;
* Applesoft Hi-Res Subroutines : http://hackzapple.org/scripts_php/index.php?menu=5&amp;amp;mod=ASM&amp;amp;sub=AAL&amp;amp;sub2=8112&amp;amp;PHPSESSID=f65fabfd0cdbf56b6bdc0ddac25117c6#a2&lt;br /&gt;
&lt;br /&gt;
== Atari Lynx ==&lt;br /&gt;
The Atari Lynx consists of the 65C02 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari Lynx:&lt;br /&gt;
&lt;br /&gt;
* Assembler:&lt;br /&gt;
Below size coding examples use [https://github.com/42Bastian/lyxass Lyxass] as assembler and are using the in-official DevKit [https://github.com/42Bastian/new_bll new_bll].&amp;lt;br&amp;gt;&lt;br /&gt;
But any other 6502 assembler is suitable. Best if it can assemble the extra opcodes of the 65C02 (like &amp;lt;b&amp;gt;BBRx&amp;lt;/b&amp;gt; or &amp;lt;b&amp;gt;RMBx&amp;lt;/b&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* Encryption&lt;br /&gt;
The Lynx boot ROM will decrypt the &amp;quot;boot sector&amp;quot; of a Lynx card image. It is done in chunks of 50bytes. Maximum are 5 chunks, hence the limit of a &amp;quot;boot sector&amp;quot; is 250 bytes, but the last byte &amp;lt;b&amp;gt;must&amp;lt;/b&amp;gt; be zero.&lt;br /&gt;
&lt;br /&gt;
* Emulator(s): &lt;br /&gt;
Currently Felix is the most accurate Emulator, though only running yet on Windows platform.&amp;lt;br&amp;gt;&lt;br /&gt;
It is currently available via [https://github.com/laoo/Felix GitHub].&lt;br /&gt;
&lt;br /&gt;
* Hardware:&lt;br /&gt;
If you want to run the code on a real Lynx, you should have a SD card for the Lynx (AgaCard, LynxGD) and also a USB&amp;lt;-&amp;gt;Serial adapter.&lt;br /&gt;
&lt;br /&gt;
=== Initial values ===&lt;br /&gt;
After the boot-rom has decrypted the boot-sector, some things are pre-defined:&lt;br /&gt;
* CPU Registers:&lt;br /&gt;
  A = 0&lt;br /&gt;
  X = 0&lt;br /&gt;
  Y = 2&lt;br /&gt;
  P = undefined&lt;br /&gt;
  S = undefined&lt;br /&gt;
&lt;br /&gt;
* Zero page&lt;br /&gt;
&lt;br /&gt;
 $00 - 0&lt;br /&gt;
 $01 - 0&lt;br /&gt;
 $02 - 0&lt;br /&gt;
&lt;br /&gt;
* Main&lt;br /&gt;
&lt;br /&gt;
Main memory is cleared to zero despite a $5000..%$50aa where decryption code is placed.&lt;br /&gt;
&lt;br /&gt;
* Bank switching&lt;br /&gt;
&lt;br /&gt;
ROM, Mikey and Suzy are mapped, Vector table is ROM.&lt;br /&gt;
&lt;br /&gt;
* Suzy&lt;br /&gt;
The sprite engine is &amp;lt;b&amp;gt;not&amp;lt;/b&amp;gt; setup.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
The Lynx display is 160x102 pixels which are linear organized as 4 bit per pixel. Hence the screen is little less than 8K.&lt;br /&gt;
The pixel value is a pointer to the color look up table.&lt;br /&gt;
The Lynx can display black and 4095 colors. The color table is split up into a green and an blue-red part (so not RGB but GBR).&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
After the ROM has deciphered the boot sector the display memory is at $2000, background color (that is pen 0) is black, all other entries are $f despite entry 14 which is also 0.&lt;br /&gt;
&lt;br /&gt;
So to fill the screen simply do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lda #$ff&lt;br /&gt;
ldx #0&lt;br /&gt;
ldy #$20   ; round(160*102/2/256)&lt;br /&gt;
loop:&lt;br /&gt;
    sta $2000,x&lt;br /&gt;
    inx&lt;br /&gt;
  bne loop&lt;br /&gt;
  dey&lt;br /&gt;
bne loop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
*[https://www.monlynx.de/lynx/lynxdoc.html Hardware documentation]&lt;br /&gt;
*[https://github.com/42Bastian/lynx_hacking/tree/master/248b Size coding examples.]&lt;br /&gt;
*[https://github.com/42Bastian/lynx-encryption-tools Lynx encryption-tools]&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=6502&amp;diff=1005</id>
		<title>6502</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=6502&amp;diff=1005"/>
				<updated>2022-01-31T08:19:29Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: /* Additional Resources */ added links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Wanting to start sizecoding on a 6502 platform in this day and age can be tough. &lt;br /&gt;
&lt;br /&gt;
[[File:6502.jpg|thumb]]&lt;br /&gt;
&lt;br /&gt;
So here is a bit of help to get you started:&lt;br /&gt;
&lt;br /&gt;
=== The 6502 processor  ===&lt;br /&gt;
The 6502 processor can be seen as the 8-bit micro ARM chip. &lt;br /&gt;
It has only has 3 registers (Accumulator, X and Y registers) and a handful of instructions to work with.&lt;br /&gt;
&lt;br /&gt;
=== Adressing modes ===&lt;br /&gt;
To be added.&lt;br /&gt;
&lt;br /&gt;
=== Zero page ===&lt;br /&gt;
When using the 6502 for sizecoding, you'll mostly be working from zeropage&lt;br /&gt;
&lt;br /&gt;
=== General 6502 Resources ===&lt;br /&gt;
* 6502.org http://www.6502.org/&lt;br /&gt;
* 6502 instruction reference http://www.6502.org/tutorials/6502opcodes.html&lt;br /&gt;
* 6502 books http://retro.hansotten.nl/6502-sbc/&lt;br /&gt;
* 6502 Assembler tutorial https://dwheeler.com/6502/oneelkruns/asm1step.html&lt;br /&gt;
* Easy 6502 code tester https://skilldrick.github.io/easy6502/&lt;br /&gt;
* Synthetic instructions https://wiki.nesdev.com/w/index.php/Synthetic_instructions#8-bit_rotate&lt;br /&gt;
&lt;br /&gt;
== Atari 8-bit family ==&lt;br /&gt;
The systems in this family are: Atari 400, 800, 5200, 1200XL, 600XL, 800XL, 130XE, 65XE, 800XE and XEGS.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Atari 8-bit systems consists of the 6502 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari 8bit systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: MADS Assembler - This assembler has nice macros for creating Binaries and SNA snapshot files out of the box. You can download it at https://mads.atari8.info/&lt;br /&gt;
* Emulator(s): I Found Altirra to work best for my usecase. Make sure to use the original Rev2 rom for best compatibility.&lt;br /&gt;
&lt;br /&gt;
==== Special Memory Adresses ====&lt;br /&gt;
* FRAMECOUNTER_HIGH = 19&lt;br /&gt;
* FRAMECOUNTER_LOW  = 20&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Atari 8bit systems use the ANTIC and GTIA chips. Information can be found here:&lt;br /&gt;
* https://en.wikipedia.org/wiki/ANTIC&lt;br /&gt;
* https://www.atariarchives.org/agagd/chapter1.php&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
      lda RTCLOK+2&lt;br /&gt;
waits&lt;br /&gt;
      cmp RTCLOK+2&lt;br /&gt;
      beq waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or if you don't mind trashing RTCLOK&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
waits&lt;br /&gt;
      lsr RTCLOK+2&lt;br /&gt;
      bcc waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which is two bytes shorter.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
;fill screen with charset,(88,89)=an address&lt;br /&gt;
 org $600; free 6th page:600-6ff&lt;br /&gt;
 ldy #0&lt;br /&gt;
fl: tya&lt;br /&gt;
 sta(88),y&lt;br /&gt;
 iny&lt;br /&gt;
 bne fl&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
SDMCTL	= $022f&lt;br /&gt;
HPOSP0  = $d000&lt;br /&gt;
SIZEP0  = $d008&lt;br /&gt;
GRAFP0  = $d00d&lt;br /&gt;
COLPM0  = $d012&lt;br /&gt;
&lt;br /&gt;
FRAMECOUNTER_HIGH = 19&lt;br /&gt;
FRAMECOUNTER = 20&lt;br /&gt;
WSYNC	= $d40a&lt;br /&gt;
VCOUNT	= $d40b&lt;br /&gt;
&lt;br /&gt;
sinewave	= $0600		; to $06ff&lt;br /&gt;
&lt;br /&gt;
		org $80&lt;br /&gt;
&lt;br /&gt;
main	&lt;br /&gt;
	; disable all graphics/colors&lt;br /&gt;
	ldx #0&lt;br /&gt;
	stx SDMCTL	&lt;br /&gt;
&lt;br /&gt;
	ldy #$7f&lt;br /&gt;
	sty SIZEP0	; size p0=127&lt;br /&gt;
		&lt;br /&gt;
	ldx #0&lt;br /&gt;
	ldy #$3f&lt;br /&gt;
make_sine:&lt;br /&gt;
value_lo&lt;br /&gt;
			lda #0&lt;br /&gt;
			clc&lt;br /&gt;
delta_lo&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_lo+1&lt;br /&gt;
value_hi&lt;br /&gt;
			lda #0&lt;br /&gt;
delta_hi&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_hi+1&lt;br /&gt;
 &lt;br /&gt;
			sta sinewave+$c0,x&lt;br /&gt;
			sta sinewave+$80,y&lt;br /&gt;
			eor #$7f&lt;br /&gt;
			sta sinewave+$40,x&lt;br /&gt;
			sta sinewave+$00,y&lt;br /&gt;
 &lt;br /&gt;
			lda delta_lo+1&lt;br /&gt;
			adc #8&lt;br /&gt;
			sta delta_lo+1&lt;br /&gt;
			bcc nothing&lt;br /&gt;
			inc delta_hi+1&lt;br /&gt;
nothing&lt;br /&gt;
			inx&lt;br /&gt;
			dey&lt;br /&gt;
			bpl make_sine&lt;br /&gt;
&lt;br /&gt;
updateloop:&lt;br /&gt;
		; vblank&lt;br /&gt;
		lda VCOUNT&lt;br /&gt;
		bne updateloop&lt;br /&gt;
&lt;br /&gt;
		; clear graphics&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		ldy #0&lt;br /&gt;
		lda #47&lt;br /&gt;
		sta COLPM0&lt;br /&gt;
yloop:&lt;br /&gt;
		tya           ; graphics shape = y&lt;br /&gt;
		sta WSYNC&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		; a = sin(frame+y)+48&lt;br /&gt;
		tya	&lt;br /&gt;
		adc FRAMECOUNTER&lt;br /&gt;
		tax&lt;br /&gt;
		lda sinewave,x&lt;br /&gt;
		adc #48&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
                &lt;br /&gt;
                iny&lt;br /&gt;
                bne yloop&lt;br /&gt;
		jmp updateloop&lt;br /&gt;
&lt;br /&gt;
		run main&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Atari 8-bit use the POKEY chip to generate sound.&lt;br /&gt;
* https://en.wikipedia.org/wiki/POKEY&lt;br /&gt;
&lt;br /&gt;
==== BASIC ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
; from Analog, 1985-09,pp.25-32&lt;br /&gt;
*=$2000&lt;br /&gt;
AUDF1=$D200&lt;br /&gt;
AUDC1=$D201&lt;br /&gt;
AUDCTL=$D208&lt;br /&gt;
SKCTL=$D20F&lt;br /&gt;
&lt;br /&gt;
.MACRO SOUND ; voice,pitch,dist,vol;,dur&lt;br /&gt;
	lda #%2&lt;br /&gt;
	sta AUDF1+2*%1&lt;br /&gt;
    lda #[[%3 * 16] | %4] ;lda #[[%3 shl 4] or %4]&lt;br /&gt;
    sta AUDC1+2*%1&lt;br /&gt;
.ENDM&lt;br /&gt;
&lt;br /&gt;
 lda #0&lt;br /&gt;
 sta AUDCTL&lt;br /&gt;
 lda #3&lt;br /&gt;
 sta SKCTL&lt;br /&gt;
&lt;br /&gt;
 SOUND 0,121,10,8&lt;br /&gt;
&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
Sizecoding resource for the Atari 8bit are:&lt;br /&gt;
* Mapping the Atari https://www.atariarchives.org/mapping/&lt;br /&gt;
* Atari 8bit Memory map https://www.atariarchives.org/mapping/memorymap.php&lt;br /&gt;
* Fready's undocumented 6502 opcodes https://github.com/FreddyOffenga/6502&lt;br /&gt;
* Atari OS Rev2 disassembly for MADS assembler https://github.com/ilmenit/A800-OS-XL-Rev2&lt;br /&gt;
* Fready's github https://github.com/FreddyOffenga/&lt;br /&gt;
&lt;br /&gt;
== Commodore 64 ==&lt;br /&gt;
The Commodore system consists of a 6502-compatible MOS 6510 processor with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Commodore systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: To be added&lt;br /&gt;
* Emulator(s): VICE is the way to go&lt;br /&gt;
&lt;br /&gt;
=== Memory map ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
    0-1          $0-$1      PROCESSOR PORT REGISTERS, not usable as RAM&lt;br /&gt;
   0-255         $0-$FF     ZEROPAGE, mostly used by BASIC interpreter and Kernal&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-600      $200-$258    INPUT BUFFER&lt;br /&gt;
  601-630      $259-$276    FILE SYSTEM DATA&lt;br /&gt;
  631-640      $277-$280    KEYBOARD BUFFER, filled by Kernal ISR upon key presses &lt;br /&gt;
  641-678      $281-$2A6    VARIOUS KERNAL VARIABLES&lt;br /&gt;
  679-767      $2A7-$2FF    Unused (89 byte)&lt;br /&gt;
  768-779      $300-$30B    KERNAL VECTORS&lt;br /&gt;
  780-783      $30C-$30F    REGISTER VALUES A,X,Y,SR for SYS&lt;br /&gt;
  784-819      $310-$333    KERNAL VECTORS&lt;br /&gt;
  820-827      $334-$33B    Unused (8 byte)&lt;br /&gt;
  828-1019     $33C-$3FB    DATASETTE BUFFER&lt;br /&gt;
 1020-1023     $3FC-$3FF    Unused (4 byte)&lt;br /&gt;
 1024-2023     $400-$7E7    SCREEN MEMORY (25 lines times 40 columns)&lt;br /&gt;
 2024-2039     $7E8-$7F7    Unused (16 byte)&lt;br /&gt;
 2040-2047     $7F8-$7FF    SPRITE COSTUME POINTERS&lt;br /&gt;
 2048          $800         must contain a value of 0 so that the BASIC program can be RUN&lt;br /&gt;
 2049-40959    $801-$9FFF   BASIC AREA (code, variables, arrays, strings)&lt;br /&gt;
40960-49151   $A000-$BFFF   BASIC ROM (unused RAM underneath)&lt;br /&gt;
49152-53247   $C000-$CFFF   UPPER RAM AREA (unused)&lt;br /&gt;
53248-53294   $D000-$D02E   VIC-II, memory-mapped graphics chip registers)&lt;br /&gt;
54272-54300   $D400-$D41C   SID, memory-mapped sound chip registers)&lt;br /&gt;
55296-56295   $D800-$DBE7   Color RAM, only lower 4 bits are stored, higher nibble undefined&lt;br /&gt;
56296-56319   $DBE8-$DBFF   Unused (24 half-bytes)&lt;br /&gt;
56320-56335   $DC00-$DC0F   CIA#1, memory-mapped I/O chip registers for keyboard, joystick, mouse, datasette, IRQ control&lt;br /&gt;
56576-56591   $DD00-$DD0F   CIA#1, memory-mapped I/O chip registers for serial bus, RS232, NMI control&lt;br /&gt;
57344-65535   $E000-$FFFF   KERNAL ROM&lt;br /&gt;
65534-65535   $FFFE-$FFFF   Execution address of interrupt service routine, can only be set if KERNAL is turned off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a detailed explanation of the C64 memory map check out [https://sta.c64.org/cbm64mem.html Commodore 64 memory map] on Joe Forster/STA homepage.&lt;br /&gt;
&lt;br /&gt;
=== Program file overhead ===&lt;br /&gt;
&lt;br /&gt;
A standard CBM file consists of a 2 byte loading address followed by the data that is placed into memory starting at this address. In addition, if your machine program should be able to be started with &amp;quot;RUN&amp;quot;, you need a BASIC stub that is loaded into memory from $0801 to $080c, typically followed by your machine program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0801&lt;br /&gt;
        .word $080b   ;address of next BASIC line&lt;br /&gt;
        .word LINENO  ;line number, can be chosen between 0 and 63999&lt;br /&gt;
        .byte $9e     ;token for SYS command&lt;br /&gt;
        .byte $32,$30,$35,$39  ;address to jump to in ASCII code: &amp;quot;2059&amp;quot; &lt;br /&gt;
        .byte $00     ;end of BASIC line&lt;br /&gt;
start   lax #0        ;actually address of next BASIC line, $xx00 means end of BASIC program, use $xx for an opcode&lt;br /&gt;
; your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the 2 byte load address, this makes an overhead of 14 bytes for your program, coming with A and X initialised to 0. To reduce this, you can&lt;br /&gt;
* omit the BASIC line and tell users to start your program by directly entering &amp;quot;SYS ''address''&amp;quot;&lt;br /&gt;
* save your program from $0802 on, the byte at $0801 is recovered automatically after loading by the relink function. This reduces your program file size by 1 byte&lt;br /&gt;
* accept the loss and use the 2 byte establishing LINENO for something good, they are copied to zeropage addresses $39/$3a automatically, saving you the effort of initializing the addresses&lt;br /&gt;
* use an autostart method (see below)&lt;br /&gt;
&lt;br /&gt;
Some compos also specify that the BASIC loader does not count towards the overall filesize, check the rules before you worry.&lt;br /&gt;
&lt;br /&gt;
=== Autostart ===&lt;br /&gt;
&lt;br /&gt;
Unlike the Commodore 128, the Commodore 64 has no dedicated built-in auto-boot feature, but it is possible to autorun a program after loading by specifying the load address so that it overwrites a vector or address that is called by the operating system. There are multiple possibilities:&lt;br /&gt;
&lt;br /&gt;
==== Overwriting  CHROUT vector at $326-$327 ====&lt;br /&gt;
&lt;br /&gt;
The vector at address $326-$327 points at the CHROUT routine, normally at address $F1CA.&lt;br /&gt;
If you put the entry address of your program into $326/27, your code will be called when the operating system wants to print &amp;quot;READY.&amp;quot; after loading.&lt;br /&gt;
Note that the vector at address $328-$329 points at the STOP routine that checks the status of Stop key indicator. Since this routine is called multiple times before your code is done loading, its default value $F6ED needs to be preserved. &lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0326&lt;br /&gt;
        .word start              &lt;br /&gt;
        .byte $ed,$f6&lt;br /&gt;
start&lt;br /&gt;
; rest of code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address, the overwritten CHROUT vector and the preserved STOP vector, your program file will have a deadweight of 6 byte: $26 $03 $0a $03 $ed $f6, less than half of the standard version with a BASIC stub with SYS&lt;br /&gt;
&lt;br /&gt;
Caveat:&lt;br /&gt;
* If your program after $32a is longer than 214 byte, part of your program will load into the screen at $400. Thus, issuing a clear screen will overwrite your program. It is possible to move the screen memory somewhere else, but that requires storing a new value into address $D018, which when done with an LDA # / STA pair will cost you 5 byte&lt;br /&gt;
* Since you changed the CHROUT pointer, standard KERNAL functions for printing won't work. For output of single characters, you can still use the direct address $F1CA. Alternatively, you can restore the vectors by calling $FD15, which will overwrite the memory $314 to $333 with the default values.&lt;br /&gt;
* The memory area $33C-$3FB is the datasette buffer, thus loading a program into this area won't work when loading from a cassette.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting BASIC idle loop vector at $302-$303 ====&lt;br /&gt;
&lt;br /&gt;
After loading the program, the BASIC idle loop will be called. By overwriting the vector at $302/$303 it is possible to autostart your program. Since the memory before $302 can be safely overwritten, the program would be arranged so that $303 is the '''last''' address of your program. If your program requires a loop back to the start, the vector can be used as part of a JMP where the following two bytes are already there, saving one byte in comparison to a loop done with a branch command.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$304 - (end - start)&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
        ; ...&lt;br /&gt;
        jmp     start    ;the address for start lies in $302/$303, thus will be called by the Kernal after loading&lt;br /&gt;
end:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In cases where the vector has a practical use, the overhead in filesize is only the 2 byte loading address. For programs larger than 93 byte keep in mind that addresses before $2A7 are in use by the Kernal.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting return address on stack at $1F8 ====&lt;br /&gt;
&lt;br /&gt;
When the load routine is called, the stack pointer is always at $FA at a stock C64. Thus the return address from the loading process is stored in memory address $1F8 (low byte) and $1F9 (high byte). During the loading routine, stack usage will clobber the stack below $1F8, but a program loaded to $1F8 and above will be fine and the overwritten address stored at $1F8/$1F9 will be called after loading.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$1F8&lt;br /&gt;
        .word start-1   ;adjust for the RTS command pulling the address from stack and increasing it by 1&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For programs larger than 95 byte keep in mind that addresses after $259 are in use by the Kernal, you might overwrite some values here if you don't have disk operations, but better check the memory map beforehand.&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address and the overwritten address at $1F8/$1F9, your program file will have a deadweight of 4 byte when using this method.&lt;br /&gt;
&lt;br /&gt;
==== Putting your program into zeropage overwriting part of CHRGET ====&lt;br /&gt;
&lt;br /&gt;
CHRGET is a machine code routine for the BASIC interpreter that is placed in the zero page at $73-$8A. By putting your program at $7C and following, the CHRGET routine runs directly into your code.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$7C&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this method, there is no need for a start address vector. The only deadweight in your program is the loading address. However, the zero page is a busy place, if your program extends beyond address $8f (that is it has more than 22 bytes on disk) you have to deal with some parts of your program being overwritten, for example, the status byte in $90 is set after loading.&lt;br /&gt;
&lt;br /&gt;
Loading data into address $A9 has an interesting side effect - the vector of $AE/$AF defines the address where the loaded bytes are written to. If $AE gets overwritten with, for example, $40, the next byte will be written to $41 (because the vector is incremented after the write). This can be used to split your program into different parts of memory.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Commodore has the following native video modes:&lt;br /&gt;
* Standard text mode, 40x25 characters, 1 individual foreground color per character, 1 common background color&lt;br /&gt;
* Multicolor text mode, 40x25 characters, only 8 foreground colors, can be mixed with hires chars, foreground &amp;lt; 8 denotes a hires char, with foreground &amp;gt;= 8 a pair of two bits (brick pixel) define color: background, foreground &amp;amp; %111, common color 1+2&lt;br /&gt;
* Extended background color text mode, 40x25 characters, 1 individual foreground color per character, 1 out of 4 background colors, only 64 chars&lt;br /&gt;
* Hires bitmap, 320x200 pixels, an 8x8 field can have an individual foreground and an individual background color&lt;br /&gt;
* Multicolor bitmap, 160x200 pixels, a pair of two bits (brick pixel) define color: background, screen color lower nibble, screen color higher nibble, color from color RAM&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&lt;br /&gt;
Depending on the VIC type, there are 262/263 raster lines (NTSC) or 312 raster lines (PAL-B). Therefore, the VIC uses register at $D012 and the highest bit of register $D011 to represent the current raster line. Checking only the lower 8 bits and waiting for them to be 0 would therefore not work because this happens two times per frame. However, any number greater than 64 will only trigger once. Using a value of 255, we would sync to a rasterline at the end of the screen, well below the part where graphics are normally displayed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
waitsync:&lt;br /&gt;
        ldx $D012&lt;br /&gt;
        inx&lt;br /&gt;
        bne waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as there have more than 63 cycles passed since the snyc, the next sync will happen at the next frame.&lt;br /&gt;
This works fine as long as we don't miss the line 255 due to an interrupt. If your program has interrupts that are not synced to a rasterline, you can change the condition as follows&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda #$E3&lt;br /&gt;
waitsync:&lt;br /&gt;
        cmp $D012&lt;br /&gt;
        bcs waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we have a window between raster line $E4 and $FF to trigger our sync, which we will meet even if a standard Kernal interrupt comes in-between. Of course, our main program now has to burn around 1700 cycles to avoid a retriggering in the same frame.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&lt;br /&gt;
Output a character:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #C       ;C must be the char code according to the PETSCII code table&lt;br /&gt;
        jsr     $FFD2    ;you can also use the direct address $FC1A, function preserves A,X,Y and enables interrupt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the [https://en.wikipedia.org/wiki/PETSCII#Character_set PETSCII code table] contains also control characters, this method can be also used to clear the screen, move the cursor or set the text color. However, some functions are shorter (and faster) by directly calling the respective KERNAL function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
Clear screen             JSR $E544&lt;br /&gt;
Cursor home position     JSR $E566&lt;br /&gt;
Output newline character JSR $AAD7&lt;br /&gt;
Set text color           LDA #COLOR, STA $286&lt;br /&gt;
Set border color         LDA #COLOR, STA $D020   ;not possible with a PETSCII control code&lt;br /&gt;
Set background color     LDA #COLOR, STA $D021   ;not possible with a PETSCII control code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy characters directly to screen memory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm   ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
LINE=5    ;for example&lt;br /&gt;
COLUMN=10 ;for example&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the text needs to be stored in '''screen code''' format, not in PETSCII (see [https://sta.c64.org/cbm64pettoscr.html Commodore 64 PETSCII code to screen code conversion] for the differences). Furthermore, the example above only writes to the screen memory, not the color RAM, assuming that the color RAM already contains the intended text color. This is the case after issuing a clear screen on most C64 machines, except for some old ROM revisions. To be on the save side you would have to write to color RAM as well, which costs another 5 byte:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm     ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
COLOR_RAM  =$D800&lt;br /&gt;
LINE       =5    ;for example&lt;br /&gt;
COLUMN     =10   ;for example&lt;br /&gt;
COLOR      =1    ;white&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        lda     #COLOR&lt;br /&gt;
        sta     COLOR_RAM  +LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Commodore 64 uses the famous SID chip to generate sound.&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Useful Kernal functions ===&lt;br /&gt;
&lt;br /&gt;
==== Get a pseudo random number ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #1   &lt;br /&gt;
        jsr     $E09A&lt;br /&gt;
        lda     $63&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The sequence of random numbers is always the same after a cold start or reset, the first 20 numbers are:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 4,24,231,4,177,170,193,101,231,18,196,1,75,48,149,36,124,53,65,154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Increment a zero page counter, return in X register, clear Y register ====&lt;br /&gt;
&lt;br /&gt;
This is part of the string handling function in the BASIC ROM, but the code could be useful for some loop stuff.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        jsr     $B5FF    ;does inc $23, ldx $23, ldy #$00, rts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Codebase 64 https://codebase64.org/doku.php?id=base:start&lt;br /&gt;
* Commodore 64 Memory map https://sta.c64.org/cbm64mem.html&lt;br /&gt;
* C64 BASIC &amp;amp; KERNAL ROM Disassembly https://www.pagetable.com/c64ref/c64disasm/&lt;br /&gt;
* No More Secrets https://csdb.dk/release/?id=198357 Everything about illegal opcodes and their use in a C64 system&lt;br /&gt;
&lt;br /&gt;
== Apple II ==&lt;br /&gt;
The Apple II is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* ACME 6502 cross-assembler(https://sourceforge.net/projects/acme-crossass/)&lt;br /&gt;
* Apple Commander (http://applecommander.sourceforge.net) for batch compilation&lt;br /&gt;
* AppleWin emulator (https://github.com/AppleWin/AppleWin/releases). Supports Mockingboard card(AY-8910+speech synthesier), HDD, Z80 card(for CP/M), mouse etc.&lt;br /&gt;
* CiderPress(https://a2ciderpress.com)&lt;br /&gt;
&lt;br /&gt;
Compilation can be done as follows (master.dsk can be found with applewin) &lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
acme hl.asm&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -d master.dsk hl&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -p master.dsk hl B 24576 &amp;lt; hl.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Memory Map ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
   0-255	 $0-$FF     ZERO-PAGE SYSTEM STORAGE&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-767      $200-$2FF    KEYBOARD CHARACTER BUFFER&lt;br /&gt;
  768-975      $300-$3CF    OFTEN AVAILABLE AS FREE SPACE FOR USER PROGRAMS&lt;br /&gt;
  976-1023     $3D0-3FF     SYSTEM VECTORS&lt;br /&gt;
 1024-2047     $400-$7FF    TEXT AND LO-RES GRAPHICS PAGE 1 &amp;lt;--- !!!&lt;br /&gt;
 2048-LOMEM    $800-LOMEM   PROGRAM STORAGE&lt;br /&gt;
 2048-3071     $800-$BFF    TEXT AND LO-RES GRAPHICS PAGE 2 OR FREE SPACE&lt;br /&gt;
 3072-8191     $C00-$1FFF   FREE SPACE UNLESS RAM APPLESOFT IS IN USE&lt;br /&gt;
 8192-16383   $2000-$3FFF   HI-RES PAGE 1 OR FREE SPACE &amp;lt;--- !!!&lt;br /&gt;
16384-24575   $4000-$5FFF   HI-RES PAGE 2 OR FREE SPACE&lt;br /&gt;
24576-38999   $6000-$95FF   FREE SPACE AND STRING STORAGE&lt;br /&gt;
38400-49151   $9600-$BFFF   DOS&lt;br /&gt;
49152-53247   $C000-$CFFF   I/O HARDWARE (RESERVED)&lt;br /&gt;
53248-57343   $D000-$DFFF   APPLESOFT IN LANGUAGE CARD OR ROM&lt;br /&gt;
57344-63487   $E000-$F7FF   APPLESOFT OR INTEGER BASIC IN LANGUAGE CARD OR ROM&lt;br /&gt;
63488-65535   $F800-$FFFF   SYSTEM MONITOR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Display ===&lt;br /&gt;
&lt;br /&gt;
=== Graphics Modes ===&lt;br /&gt;
: Text Mode 40x24, for Apple IIe available 80x25 - use PR#3 for switch mode, or hardware switch&lt;br /&gt;
: LowRes 40x48, 16 colors: https://en.wikipedia.org/wiki/Apple_II_graphics &lt;br /&gt;
: Hires mode 280x192,6 colors: https://www.xtof.info/blog/?p=768&lt;br /&gt;
https://mrob.com/pub/xapple2/colors.html&lt;br /&gt;
https://archive.org/details/HiRes_Color_Graphics_on_the_Apple_II_Computer_by_Wozniak&lt;br /&gt;
&lt;br /&gt;
However for sizecoding, you almost never want to do direct-access to graphics for Apple II in size-coding because the Apple II graphics modes are horrible.  The only fast way to do things is with large lookup tables.  To do hires you need to divide by 7 which as you can imagine is a bit difficult to do compactly on 6502. Double-hires is even crazier on top of that.  Deater did manage a color-bar style effect in double-hires in 128B but that was doing some crazy tricks with the firmware BASIC routines, definitely not direct-access.&lt;br /&gt;
&lt;br /&gt;
Lores and Hires can be mixed modes and full-graphics&lt;br /&gt;
The screen structure is called memory holes(https://retrocomputing.stackexchange.com/questions/2534/what-are-the-screen-holes-in-apple-ii-graphics). The GBASCALC($F847) procedure is used to calculate the address of the horizontal line : IN:reg.A=Y, out : GBASL/GBASH($26/$27)=address. See also https://www.callapple.org/uncategorized/use-of-apple-ii-color-graphics-in-assembly-language/&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
Here is an example of a XOR texture, created by g0blinish&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
GBASL	=	$26&lt;br /&gt;
GBASH	=	$27&lt;br /&gt;
SETGR    =     $FB40 ; setup LoRes&lt;br /&gt;
GBASCALC = $F847 ; calc Address&lt;br /&gt;
&lt;br /&gt;
CLRTEXT =  $C050 ;display graphics &lt;br /&gt;
SETTEXT =  $C051 ;display text &lt;br /&gt;
&lt;br /&gt;
CLRMIXED = $C052 ;clear mixed mode- enable full graphics &lt;br /&gt;
SETMIXED = $C053 ;enable graphics/text mixed mode &lt;br /&gt;
&lt;br /&gt;
PAGE1 =    $C054 ;select text/graphics page1 &lt;br /&gt;
PAGE2 =    $C055 ;select text/graphics page2 &lt;br /&gt;
&lt;br /&gt;
CLRHIRES = $C056 ;select Lo-res &lt;br /&gt;
SETHIRES = $C057 ;select Hi-res &lt;br /&gt;
&lt;br /&gt;
TMP= $FA&lt;br /&gt;
&lt;br /&gt;
	JSR   SETGR      ;GR&lt;br /&gt;
	BIT CLRMIXED ; full screen&lt;br /&gt;
&lt;br /&gt;
	LDA #0 ; A=0&lt;br /&gt;
	STA TMP ; POKE $FA,A&lt;br /&gt;
&lt;br /&gt;
YLP ;&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
;	LSR ; A=A/2&lt;br /&gt;
	JSR GBASCALC&lt;br /&gt;
	LDY #0;Y=0&lt;br /&gt;
&lt;br /&gt;
XLP TYA ; A=Y&lt;br /&gt;
	EOR TMP ; A=A xor PEEK($FA)&lt;br /&gt;
	and #$0F ; A=A and 15&lt;br /&gt;
	TAX ; X=A&lt;br /&gt;
	LDA COLORS,X ;A=PEEK(COLORS+X)&lt;br /&gt;
	STA(GBASL),Y ; POKE PEEK($26)+256*PEEK($27)+Y,A&lt;br /&gt;
	INY ; Y=Y+1&lt;br /&gt;
	CPY #40 ; Y=40?&lt;br /&gt;
	BNE XLP&lt;br /&gt;
	INC TMP ; POKE $FA,PEEK($FA)+1&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
	CMP #24 ; A=24?&lt;br /&gt;
	BNE YLP&lt;br /&gt;
	&lt;br /&gt;
M1 JMP M1 ; replace to RTS&lt;br /&gt;
&lt;br /&gt;
COLORS ;N*17, pixel format is AAAABBBB, AAAA - upper dot, BBBB - lower dot&lt;br /&gt;
!byte $00,$11,$22,$33,$44,$55,$66,$77&lt;br /&gt;
!byte $88,$99,$AA,$BB,$CC,$DD,$EE,$FF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sound  ====&lt;br /&gt;
Here is an example for using the speaker, based onthe following basic program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;basic&amp;quot;&amp;gt;&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
;start&lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
ini:&lt;br /&gt;
	lda #70&lt;br /&gt;
	sta cnt+1&lt;br /&gt;
	lda #music&amp;amp;255&lt;br /&gt;
	sta gotbyte+1&lt;br /&gt;
	lda #music/256&lt;br /&gt;
	sta gotbyte+2&lt;br /&gt;
&lt;br /&gt;
lop:&lt;br /&gt;
;V&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L300&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
;P&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L301&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	clc&lt;br /&gt;
	adc #1&lt;br /&gt;
	sta L320&lt;br /&gt;
	jsr beep&lt;br /&gt;
	&lt;br /&gt;
	dec cnt+1&lt;br /&gt;
cnt lda #70&lt;br /&gt;
	bne lop&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
	jmp ini&lt;br /&gt;
gotbyte&lt;br /&gt;
	lda music&lt;br /&gt;
	inc gotbyte+1&lt;br /&gt;
	bne noinch&lt;br /&gt;
	inc gotbyte+2&lt;br /&gt;
noinch&lt;br /&gt;
	rts&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
beep:&lt;br /&gt;
	ldy #1&lt;br /&gt;
	ldx #1&lt;br /&gt;
loc_302:&lt;br /&gt;
		LDA	$C030&lt;br /&gt;
&lt;br /&gt;
loc_305:&lt;br /&gt;
		DEY&lt;br /&gt;
		BNE	loc_30D&lt;br /&gt;
		DEC	L301&lt;br /&gt;
loc_30B:&lt;br /&gt;
		BEQ	loc_316&lt;br /&gt;
&lt;br /&gt;
loc_30D:&lt;br /&gt;
		DEX&lt;br /&gt;
		BNE	loc_305&lt;br /&gt;
		LDX	L300&lt;br /&gt;
		JMP	loc_302&lt;br /&gt;
loc_316:&lt;br /&gt;
		DEC	L320&lt;br /&gt;
		BNE	loc_30B&lt;br /&gt;
		RTS&lt;br /&gt;
L301 !byte 0&lt;br /&gt;
L300 !byte 0&lt;br /&gt;
L320 !byte 0&lt;br /&gt;
music&lt;br /&gt;
 !word 76,192,85,64,96,64,102,64,114,128,114,64,96,64,102,64,114,64,128,64&lt;br /&gt;
 !word 114,64,152,64,171,64,152,512,76,192,85,64,96,64,102,64,114,128,114,64&lt;br /&gt;
 !word 96,64,102,64,114,64,128,64,114,64,152,64,171,64,152,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,128,114,64,128,64,114,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,64,128,128,96,64,85,64,96,64,102,64,114,64,114,64&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Deater's page on Apple II sizecoding http://www.deater.net/weave/vmwprod/demos/sizecoding.html (with an additional presentation at https://www.youtube.com/watch?v=kJ-EXbnw0kQ )&lt;br /&gt;
* Article on double hi-res http://www.battlestations.zone/2017/04/apple-ii-double-hi-res-from-ground-up.html&lt;br /&gt;
* Applesoft Hi-Res Subroutines : http://hackzapple.org/scripts_php/index.php?menu=5&amp;amp;mod=ASM&amp;amp;sub=AAL&amp;amp;sub2=8112&amp;amp;PHPSESSID=f65fabfd0cdbf56b6bdc0ddac25117c6#a2&lt;br /&gt;
&lt;br /&gt;
== Atari Lynx ==&lt;br /&gt;
The Atari Lynx consists of the 6502 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari Lynx:&lt;br /&gt;
&lt;br /&gt;
* Assembler: -&lt;br /&gt;
* Emulator(s): -&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
The Lynx display is 160x102 pixels which are linear organized as 4 bit per pixel. Hence the screen is little less than 8K.&lt;br /&gt;
The pixel value is a pointer to the color look up table.&lt;br /&gt;
The Lynx can display black and 4095 colors. The color table is split up into a green and an blue-red part (so not RGB but GBR).&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
After the ROM has deciphered the boot sector the display memory is at $2000, background color (that is pen 0) is black, all other entries are $f despite entry 14 which is also 0.&lt;br /&gt;
&lt;br /&gt;
So to fill the screen simply do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lda #$ff&lt;br /&gt;
ldx #0&lt;br /&gt;
ldy #$20   ; round(160*102/2/256)&lt;br /&gt;
loop:&lt;br /&gt;
    sta $2000,x&lt;br /&gt;
    inx&lt;br /&gt;
  bne loop&lt;br /&gt;
  dey&lt;br /&gt;
bne loop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
*[https://www.monlynx.de/lynx/lynxdoc.html Hardware documentation]&lt;br /&gt;
*[https://github.com/42Bastian/lynx_hacking/tree/master/248b Size coding examples.]&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=6502&amp;diff=1004</id>
		<title>6502</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=6502&amp;diff=1004"/>
				<updated>2022-01-31T08:16:14Z</updated>
		
		<summary type="html">&lt;p&gt;42Bastian: Initial text.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
Wanting to start sizecoding on a 6502 platform in this day and age can be tough. &lt;br /&gt;
&lt;br /&gt;
[[File:6502.jpg|thumb]]&lt;br /&gt;
&lt;br /&gt;
So here is a bit of help to get you started:&lt;br /&gt;
&lt;br /&gt;
=== The 6502 processor  ===&lt;br /&gt;
The 6502 processor can be seen as the 8-bit micro ARM chip. &lt;br /&gt;
It has only has 3 registers (Accumulator, X and Y registers) and a handful of instructions to work with.&lt;br /&gt;
&lt;br /&gt;
=== Adressing modes ===&lt;br /&gt;
To be added.&lt;br /&gt;
&lt;br /&gt;
=== Zero page ===&lt;br /&gt;
When using the 6502 for sizecoding, you'll mostly be working from zeropage&lt;br /&gt;
&lt;br /&gt;
=== General 6502 Resources ===&lt;br /&gt;
* 6502.org http://www.6502.org/&lt;br /&gt;
* 6502 instruction reference http://www.6502.org/tutorials/6502opcodes.html&lt;br /&gt;
* 6502 books http://retro.hansotten.nl/6502-sbc/&lt;br /&gt;
* 6502 Assembler tutorial https://dwheeler.com/6502/oneelkruns/asm1step.html&lt;br /&gt;
* Easy 6502 code tester https://skilldrick.github.io/easy6502/&lt;br /&gt;
* Synthetic instructions https://wiki.nesdev.com/w/index.php/Synthetic_instructions#8-bit_rotate&lt;br /&gt;
&lt;br /&gt;
== Atari 8-bit family ==&lt;br /&gt;
The systems in this family are: Atari 400, 800, 5200, 1200XL, 600XL, 800XL, 130XE, 65XE, 800XE and XEGS.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Atari 8-bit systems consists of the 6502 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari 8bit systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: MADS Assembler - This assembler has nice macros for creating Binaries and SNA snapshot files out of the box. You can download it at https://mads.atari8.info/&lt;br /&gt;
* Emulator(s): I Found Altirra to work best for my usecase. Make sure to use the original Rev2 rom for best compatibility.&lt;br /&gt;
&lt;br /&gt;
==== Special Memory Adresses ====&lt;br /&gt;
* FRAMECOUNTER_HIGH = 19&lt;br /&gt;
* FRAMECOUNTER_LOW  = 20&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Atari 8bit systems use the ANTIC and GTIA chips. Information can be found here:&lt;br /&gt;
* https://en.wikipedia.org/wiki/ANTIC&lt;br /&gt;
* https://www.atariarchives.org/agagd/chapter1.php&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
      lda RTCLOK+2&lt;br /&gt;
waits&lt;br /&gt;
      cmp RTCLOK+2&lt;br /&gt;
      beq waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or if you don't mind trashing RTCLOK&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
RTCLOK      equ $0012&lt;br /&gt;
waits&lt;br /&gt;
      lsr RTCLOK+2&lt;br /&gt;
      bcc waits&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which is two bytes shorter.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
;fill screen with charset,(88,89)=an address&lt;br /&gt;
 org $600; free 6th page:600-6ff&lt;br /&gt;
 ldy #0&lt;br /&gt;
fl: tya&lt;br /&gt;
 sta(88),y&lt;br /&gt;
 iny&lt;br /&gt;
 bne fl&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
SDMCTL	= $022f&lt;br /&gt;
HPOSP0  = $d000&lt;br /&gt;
SIZEP0  = $d008&lt;br /&gt;
GRAFP0  = $d00d&lt;br /&gt;
COLPM0  = $d012&lt;br /&gt;
&lt;br /&gt;
FRAMECOUNTER_HIGH = 19&lt;br /&gt;
FRAMECOUNTER = 20&lt;br /&gt;
WSYNC	= $d40a&lt;br /&gt;
VCOUNT	= $d40b&lt;br /&gt;
&lt;br /&gt;
sinewave	= $0600		; to $06ff&lt;br /&gt;
&lt;br /&gt;
		org $80&lt;br /&gt;
&lt;br /&gt;
main	&lt;br /&gt;
	; disable all graphics/colors&lt;br /&gt;
	ldx #0&lt;br /&gt;
	stx SDMCTL	&lt;br /&gt;
&lt;br /&gt;
	ldy #$7f&lt;br /&gt;
	sty SIZEP0	; size p0=127&lt;br /&gt;
		&lt;br /&gt;
	ldx #0&lt;br /&gt;
	ldy #$3f&lt;br /&gt;
make_sine:&lt;br /&gt;
value_lo&lt;br /&gt;
			lda #0&lt;br /&gt;
			clc&lt;br /&gt;
delta_lo&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_lo+1&lt;br /&gt;
value_hi&lt;br /&gt;
			lda #0&lt;br /&gt;
delta_hi&lt;br /&gt;
			adc #0&lt;br /&gt;
			sta value_hi+1&lt;br /&gt;
 &lt;br /&gt;
			sta sinewave+$c0,x&lt;br /&gt;
			sta sinewave+$80,y&lt;br /&gt;
			eor #$7f&lt;br /&gt;
			sta sinewave+$40,x&lt;br /&gt;
			sta sinewave+$00,y&lt;br /&gt;
 &lt;br /&gt;
			lda delta_lo+1&lt;br /&gt;
			adc #8&lt;br /&gt;
			sta delta_lo+1&lt;br /&gt;
			bcc nothing&lt;br /&gt;
			inc delta_hi+1&lt;br /&gt;
nothing&lt;br /&gt;
			inx&lt;br /&gt;
			dey&lt;br /&gt;
			bpl make_sine&lt;br /&gt;
&lt;br /&gt;
updateloop:&lt;br /&gt;
		; vblank&lt;br /&gt;
		lda VCOUNT&lt;br /&gt;
		bne updateloop&lt;br /&gt;
&lt;br /&gt;
		; clear graphics&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		ldy #0&lt;br /&gt;
		lda #47&lt;br /&gt;
		sta COLPM0&lt;br /&gt;
yloop:&lt;br /&gt;
		tya           ; graphics shape = y&lt;br /&gt;
		sta WSYNC&lt;br /&gt;
		sta GRAFP0&lt;br /&gt;
&lt;br /&gt;
		; a = sin(frame+y)+48&lt;br /&gt;
		tya	&lt;br /&gt;
		adc FRAMECOUNTER&lt;br /&gt;
		tax&lt;br /&gt;
		lda sinewave,x&lt;br /&gt;
		adc #48&lt;br /&gt;
		sta HPOSP0&lt;br /&gt;
                &lt;br /&gt;
                iny&lt;br /&gt;
                bne yloop&lt;br /&gt;
		jmp updateloop&lt;br /&gt;
&lt;br /&gt;
		run main&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Atari 8-bit use the POKEY chip to generate sound.&lt;br /&gt;
* https://en.wikipedia.org/wiki/POKEY&lt;br /&gt;
&lt;br /&gt;
==== BASIC ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
; from Analog, 1985-09,pp.25-32&lt;br /&gt;
*=$2000&lt;br /&gt;
AUDF1=$D200&lt;br /&gt;
AUDC1=$D201&lt;br /&gt;
AUDCTL=$D208&lt;br /&gt;
SKCTL=$D20F&lt;br /&gt;
&lt;br /&gt;
.MACRO SOUND ; voice,pitch,dist,vol;,dur&lt;br /&gt;
	lda #%2&lt;br /&gt;
	sta AUDF1+2*%1&lt;br /&gt;
    lda #[[%3 * 16] | %4] ;lda #[[%3 shl 4] or %4]&lt;br /&gt;
    sta AUDC1+2*%1&lt;br /&gt;
.ENDM&lt;br /&gt;
&lt;br /&gt;
 lda #0&lt;br /&gt;
 sta AUDCTL&lt;br /&gt;
 lda #3&lt;br /&gt;
 sta SKCTL&lt;br /&gt;
&lt;br /&gt;
 SOUND 0,121,10,8&lt;br /&gt;
&lt;br /&gt;
 jmp *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
Sizecoding resource for the Atari 8bit are:&lt;br /&gt;
* Mapping the Atari https://www.atariarchives.org/mapping/&lt;br /&gt;
* Atari 8bit Memory map https://www.atariarchives.org/mapping/memorymap.php&lt;br /&gt;
* Fready's undocumented 6502 opcodes https://github.com/FreddyOffenga/6502&lt;br /&gt;
* Atari OS Rev2 disassembly for MADS assembler https://github.com/ilmenit/A800-OS-XL-Rev2&lt;br /&gt;
* Fready's github https://github.com/FreddyOffenga/&lt;br /&gt;
&lt;br /&gt;
== Commodore 64 ==&lt;br /&gt;
The Commodore system consists of a 6502-compatible MOS 6510 processor with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Commodore systems is quite easy, first get the following tools:&lt;br /&gt;
&lt;br /&gt;
* Assembler: To be added&lt;br /&gt;
* Emulator(s): VICE is the way to go&lt;br /&gt;
&lt;br /&gt;
=== Memory map ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
    0-1          $0-$1      PROCESSOR PORT REGISTERS, not usable as RAM&lt;br /&gt;
   0-255         $0-$FF     ZEROPAGE, mostly used by BASIC interpreter and Kernal&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-600      $200-$258    INPUT BUFFER&lt;br /&gt;
  601-630      $259-$276    FILE SYSTEM DATA&lt;br /&gt;
  631-640      $277-$280    KEYBOARD BUFFER, filled by Kernal ISR upon key presses &lt;br /&gt;
  641-678      $281-$2A6    VARIOUS KERNAL VARIABLES&lt;br /&gt;
  679-767      $2A7-$2FF    Unused (89 byte)&lt;br /&gt;
  768-779      $300-$30B    KERNAL VECTORS&lt;br /&gt;
  780-783      $30C-$30F    REGISTER VALUES A,X,Y,SR for SYS&lt;br /&gt;
  784-819      $310-$333    KERNAL VECTORS&lt;br /&gt;
  820-827      $334-$33B    Unused (8 byte)&lt;br /&gt;
  828-1019     $33C-$3FB    DATASETTE BUFFER&lt;br /&gt;
 1020-1023     $3FC-$3FF    Unused (4 byte)&lt;br /&gt;
 1024-2023     $400-$7E7    SCREEN MEMORY (25 lines times 40 columns)&lt;br /&gt;
 2024-2039     $7E8-$7F7    Unused (16 byte)&lt;br /&gt;
 2040-2047     $7F8-$7FF    SPRITE COSTUME POINTERS&lt;br /&gt;
 2048          $800         must contain a value of 0 so that the BASIC program can be RUN&lt;br /&gt;
 2049-40959    $801-$9FFF   BASIC AREA (code, variables, arrays, strings)&lt;br /&gt;
40960-49151   $A000-$BFFF   BASIC ROM (unused RAM underneath)&lt;br /&gt;
49152-53247   $C000-$CFFF   UPPER RAM AREA (unused)&lt;br /&gt;
53248-53294   $D000-$D02E   VIC-II, memory-mapped graphics chip registers)&lt;br /&gt;
54272-54300   $D400-$D41C   SID, memory-mapped sound chip registers)&lt;br /&gt;
55296-56295   $D800-$DBE7   Color RAM, only lower 4 bits are stored, higher nibble undefined&lt;br /&gt;
56296-56319   $DBE8-$DBFF   Unused (24 half-bytes)&lt;br /&gt;
56320-56335   $DC00-$DC0F   CIA#1, memory-mapped I/O chip registers for keyboard, joystick, mouse, datasette, IRQ control&lt;br /&gt;
56576-56591   $DD00-$DD0F   CIA#1, memory-mapped I/O chip registers for serial bus, RS232, NMI control&lt;br /&gt;
57344-65535   $E000-$FFFF   KERNAL ROM&lt;br /&gt;
65534-65535   $FFFE-$FFFF   Execution address of interrupt service routine, can only be set if KERNAL is turned off&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a detailed explanation of the C64 memory map check out [https://sta.c64.org/cbm64mem.html Commodore 64 memory map] on Joe Forster/STA homepage.&lt;br /&gt;
&lt;br /&gt;
=== Program file overhead ===&lt;br /&gt;
&lt;br /&gt;
A standard CBM file consists of a 2 byte loading address followed by the data that is placed into memory starting at this address. In addition, if your machine program should be able to be started with &amp;quot;RUN&amp;quot;, you need a BASIC stub that is loaded into memory from $0801 to $080c, typically followed by your machine program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0801&lt;br /&gt;
        .word $080b   ;address of next BASIC line&lt;br /&gt;
        .word LINENO  ;line number, can be chosen between 0 and 63999&lt;br /&gt;
        .byte $9e     ;token for SYS command&lt;br /&gt;
        .byte $32,$30,$35,$39  ;address to jump to in ASCII code: &amp;quot;2059&amp;quot; &lt;br /&gt;
        .byte $00     ;end of BASIC line&lt;br /&gt;
start   lax #0        ;actually address of next BASIC line, $xx00 means end of BASIC program, use $xx for an opcode&lt;br /&gt;
; your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the 2 byte load address, this makes an overhead of 14 bytes for your program, coming with A and X initialised to 0. To reduce this, you can&lt;br /&gt;
* omit the BASIC line and tell users to start your program by directly entering &amp;quot;SYS ''address''&amp;quot;&lt;br /&gt;
* save your program from $0802 on, the byte at $0801 is recovered automatically after loading by the relink function. This reduces your program file size by 1 byte&lt;br /&gt;
* accept the loss and use the 2 byte establishing LINENO for something good, they are copied to zeropage addresses $39/$3a automatically, saving you the effort of initializing the addresses&lt;br /&gt;
* use an autostart method (see below)&lt;br /&gt;
&lt;br /&gt;
Some compos also specify that the BASIC loader does not count towards the overall filesize, check the rules before you worry.&lt;br /&gt;
&lt;br /&gt;
=== Autostart ===&lt;br /&gt;
&lt;br /&gt;
Unlike the Commodore 128, the Commodore 64 has no dedicated built-in auto-boot feature, but it is possible to autorun a program after loading by specifying the load address so that it overwrites a vector or address that is called by the operating system. There are multiple possibilities:&lt;br /&gt;
&lt;br /&gt;
==== Overwriting  CHROUT vector at $326-$327 ====&lt;br /&gt;
&lt;br /&gt;
The vector at address $326-$327 points at the CHROUT routine, normally at address $F1CA.&lt;br /&gt;
If you put the entry address of your program into $326/27, your code will be called when the operating system wants to print &amp;quot;READY.&amp;quot; after loading.&lt;br /&gt;
Note that the vector at address $328-$329 points at the STOP routine that checks the status of Stop key indicator. Since this routine is called multiple times before your code is done loading, its default value $F6ED needs to be preserved. &lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$0326&lt;br /&gt;
        .word start              &lt;br /&gt;
        .byte $ed,$f6&lt;br /&gt;
start&lt;br /&gt;
; rest of code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address, the overwritten CHROUT vector and the preserved STOP vector, your program file will have a deadweight of 6 byte: $26 $03 $0a $03 $ed $f6, less than half of the standard version with a BASIC stub with SYS&lt;br /&gt;
&lt;br /&gt;
Caveat:&lt;br /&gt;
* If your program after $32a is longer than 214 byte, part of your program will load into the screen at $400. Thus, issuing a clear screen will overwrite your program. It is possible to move the screen memory somewhere else, but that requires storing a new value into address $D018, which when done with an LDA # / STA pair will cost you 5 byte&lt;br /&gt;
* Since you changed the CHROUT pointer, standard KERNAL functions for printing won't work. For output of single characters, you can still use the direct address $F1CA. Alternatively, you can restore the vectors by calling $FD15, which will overwrite the memory $314 to $333 with the default values.&lt;br /&gt;
* The memory area $33C-$3FB is the datasette buffer, thus loading a program into this area won't work when loading from a cassette.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting BASIC idle loop vector at $302-$303 ====&lt;br /&gt;
&lt;br /&gt;
After loading the program, the BASIC idle loop will be called. By overwriting the vector at $302/$303 it is possible to autostart your program. Since the memory before $302 can be safely overwritten, the program would be arranged so that $303 is the '''last''' address of your program. If your program requires a loop back to the start, the vector can be used as part of a JMP where the following two bytes are already there, saving one byte in comparison to a loop done with a branch command.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$304 - (end - start)&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
        ; ...&lt;br /&gt;
        jmp     start    ;the address for start lies in $302/$303, thus will be called by the Kernal after loading&lt;br /&gt;
end:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In cases where the vector has a practical use, the overhead in filesize is only the 2 byte loading address. For programs larger than 93 byte keep in mind that addresses before $2A7 are in use by the Kernal.&lt;br /&gt;
&lt;br /&gt;
==== Overwriting return address on stack at $1F8 ====&lt;br /&gt;
&lt;br /&gt;
When the load routine is called, the stack pointer is always at $FA at a stock C64. Thus the return address from the loading process is stored in memory address $1F8 (low byte) and $1F9 (high byte). During the loading routine, stack usage will clobber the stack below $1F8, but a program loaded to $1F8 and above will be fine and the overwritten address stored at $1F8/$1F9 will be called after loading.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$1F8&lt;br /&gt;
        .word start-1   ;adjust for the RTS command pulling the address from stack and increasing it by 1&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For programs larger than 95 byte keep in mind that addresses after $259 are in use by the Kernal, you might overwrite some values here if you don't have disk operations, but better check the memory map beforehand.&lt;br /&gt;
&lt;br /&gt;
Together with the two byte load address and the overwritten address at $1F8/$1F9, your program file will have a deadweight of 4 byte when using this method.&lt;br /&gt;
&lt;br /&gt;
==== Putting your program into zeropage overwriting part of CHRGET ====&lt;br /&gt;
&lt;br /&gt;
CHRGET is a machine code routine for the BASIC interpreter that is placed in the zero page at $73-$8A. By putting your program at $7C and following, the CHRGET routine runs directly into your code.&lt;br /&gt;
&lt;br /&gt;
Application example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
*=$7C&lt;br /&gt;
start:&lt;br /&gt;
        ;your code here&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this method, there is no need for a start address vector. The only deadweight in your program is the loading address. However, the zero page is a busy place, if your program extends beyond address $8f (that is it has more than 22 bytes on disk) you have to deal with some parts of your program being overwritten, for example, the status byte in $90 is set after loading.&lt;br /&gt;
&lt;br /&gt;
Loading data into address $A9 has an interesting side effect - the vector of $AE/$AF defines the address where the loaded bytes are written to. If $AE gets overwritten with, for example, $40, the next byte will be written to $41 (because the vector is incremented after the write). This can be used to split your program into different parts of memory.&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
Video display on the Commodore has the following native video modes:&lt;br /&gt;
* Standard text mode, 40x25 characters, 1 individual foreground color per character, 1 common background color&lt;br /&gt;
* Multicolor text mode, 40x25 characters, only 8 foreground colors, can be mixed with hires chars, foreground &amp;lt; 8 denotes a hires char, with foreground &amp;gt;= 8 a pair of two bits (brick pixel) define color: background, foreground &amp;amp; %111, common color 1+2&lt;br /&gt;
* Extended background color text mode, 40x25 characters, 1 individual foreground color per character, 1 out of 4 background colors, only 64 chars&lt;br /&gt;
* Hires bitmap, 320x200 pixels, an 8x8 field can have an individual foreground and an individual background color&lt;br /&gt;
* Multicolor bitmap, 160x200 pixels, a pair of two bits (brick pixel) define color: background, screen color lower nibble, screen color higher nibble, color from color RAM&lt;br /&gt;
&lt;br /&gt;
==== Sync with frame  ====&lt;br /&gt;
&lt;br /&gt;
Depending on the VIC type, there are 262/263 raster lines (NTSC) or 312 raster lines (PAL-B). Therefore, the VIC uses register at $D012 and the highest bit of register $D011 to represent the current raster line. Checking only the lower 8 bits and waiting for them to be 0 would therefore not work because this happens two times per frame. However, any number greater than 64 will only trigger once. Using a value of 255, we would sync to a rasterline at the end of the screen, well below the part where graphics are normally displayed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
waitsync:&lt;br /&gt;
        ldx $D012&lt;br /&gt;
        inx&lt;br /&gt;
        bne waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As long as there have more than 63 cycles passed since the snyc, the next sync will happen at the next frame.&lt;br /&gt;
This works fine as long as we don't miss the line 255 due to an interrupt. If your program has interrupts that are not synced to a rasterline, you can change the condition as follows&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda #$E3&lt;br /&gt;
waitsync:&lt;br /&gt;
        cmp $D012&lt;br /&gt;
        bcs waitsync&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we have a window between raster line $E4 and $FF to trigger our sync, which we will meet even if a standard Kernal interrupt comes in-between. Of course, our main program now has to burn around 1700 cycles to avoid a retriggering in the same frame.&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
&lt;br /&gt;
Output a character:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #C       ;C must be the char code according to the PETSCII code table&lt;br /&gt;
        jsr     $FFD2    ;you can also use the direct address $FC1A, function preserves A,X,Y and enables interrupt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since the [https://en.wikipedia.org/wiki/PETSCII#Character_set PETSCII code table] contains also control characters, this method can be also used to clear the screen, move the cursor or set the text color. However, some functions are shorter (and faster) by directly calling the respective KERNAL function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
Clear screen             JSR $E544&lt;br /&gt;
Cursor home position     JSR $E566&lt;br /&gt;
Output newline character JSR $AAD7&lt;br /&gt;
Set text color           LDA #COLOR, STA $286&lt;br /&gt;
Set border color         LDA #COLOR, STA $D020   ;not possible with a PETSCII control code&lt;br /&gt;
Set background color     LDA #COLOR, STA $D021   ;not possible with a PETSCII control code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy characters directly to screen memory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm   ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
LINE=5    ;for example&lt;br /&gt;
COLUMN=10 ;for example&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the text needs to be stored in '''screen code''' format, not in PETSCII (see [https://sta.c64.org/cbm64pettoscr.html Commodore 64 PETSCII code to screen code conversion] for the differences). Furthermore, the example above only writes to the screen memory, not the color RAM, assuming that the color RAM already contains the intended text color. This is the case after issuing a clear screen on most C64 machines, except for some old ROM revisions. To be on the save side you would have to write to color RAM as well, which costs another 5 byte:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
.macpack cbm     ;scrcode macro&lt;br /&gt;
SCREEN_BASE=$400&lt;br /&gt;
COLOR_RAM  =$D800&lt;br /&gt;
LINE       =5    ;for example&lt;br /&gt;
COLUMN     =10   ;for example&lt;br /&gt;
COLOR      =1    ;white&lt;br /&gt;
&lt;br /&gt;
        ldx     #endtext-text-1&lt;br /&gt;
@loop:  lda     text,x&lt;br /&gt;
        sta     SCREEN_BASE+LINE*40+COLUMN,x&lt;br /&gt;
        lda     #COLOR&lt;br /&gt;
        sta     COLOR_RAM  +LINE*40+COLUMN,x&lt;br /&gt;
        dex&lt;br /&gt;
        bpl     @loop&lt;br /&gt;
text:   scrcode &amp;quot;hello world!&amp;quot;&lt;br /&gt;
endtext:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
The Commodore 64 uses the famous SID chip to generate sound.&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Useful Kernal functions ===&lt;br /&gt;
&lt;br /&gt;
==== Get a pseudo random number ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        lda     #1   &lt;br /&gt;
        jsr     $E09A&lt;br /&gt;
        lda     $63&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The sequence of random numbers is always the same after a cold start or reset, the first 20 numbers are:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 4,24,231,4,177,170,193,101,231,18,196,1,75,48,149,36,124,53,65,154&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Increment a zero page counter, return in X register, clear Y register ====&lt;br /&gt;
&lt;br /&gt;
This is part of the string handling function in the BASIC ROM, but the code could be useful for some loop stuff.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
        jsr     $B5FF    ;does inc $23, ldx $23, ldy #$00, rts&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Codebase 64 https://codebase64.org/doku.php?id=base:start&lt;br /&gt;
* Commodore 64 Memory map https://sta.c64.org/cbm64mem.html&lt;br /&gt;
* C64 BASIC &amp;amp; KERNAL ROM Disassembly https://www.pagetable.com/c64ref/c64disasm/&lt;br /&gt;
* No More Secrets https://csdb.dk/release/?id=198357 Everything about illegal opcodes and their use in a C64 system&lt;br /&gt;
&lt;br /&gt;
== Apple II ==&lt;br /&gt;
The Apple II is an 8-bit home computer and one of the world's first highly successful mass-produced microcomputer products. It was designed primarily by Steve Wozniak.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
* ACME 6502 cross-assembler(https://sourceforge.net/projects/acme-crossass/)&lt;br /&gt;
* Apple Commander (http://applecommander.sourceforge.net) for batch compilation&lt;br /&gt;
* AppleWin emulator (https://github.com/AppleWin/AppleWin/releases). Supports Mockingboard card(AY-8910+speech synthesier), HDD, Z80 card(for CP/M), mouse etc.&lt;br /&gt;
* CiderPress(https://a2ciderpress.com)&lt;br /&gt;
&lt;br /&gt;
Compilation can be done as follows (master.dsk can be found with applewin) &lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
acme hl.asm&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -d master.dsk hl&lt;br /&gt;
java -jar AppleCommander-1.3.5.jar -p master.dsk hl B 24576 &amp;lt; hl.bin&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Memory Map ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
   0-255	 $0-$FF     ZERO-PAGE SYSTEM STORAGE&lt;br /&gt;
  256-511      $100-$1FF    SYSTEM STACK&lt;br /&gt;
  512-767      $200-$2FF    KEYBOARD CHARACTER BUFFER&lt;br /&gt;
  768-975      $300-$3CF    OFTEN AVAILABLE AS FREE SPACE FOR USER PROGRAMS&lt;br /&gt;
  976-1023     $3D0-3FF     SYSTEM VECTORS&lt;br /&gt;
 1024-2047     $400-$7FF    TEXT AND LO-RES GRAPHICS PAGE 1 &amp;lt;--- !!!&lt;br /&gt;
 2048-LOMEM    $800-LOMEM   PROGRAM STORAGE&lt;br /&gt;
 2048-3071     $800-$BFF    TEXT AND LO-RES GRAPHICS PAGE 2 OR FREE SPACE&lt;br /&gt;
 3072-8191     $C00-$1FFF   FREE SPACE UNLESS RAM APPLESOFT IS IN USE&lt;br /&gt;
 8192-16383   $2000-$3FFF   HI-RES PAGE 1 OR FREE SPACE &amp;lt;--- !!!&lt;br /&gt;
16384-24575   $4000-$5FFF   HI-RES PAGE 2 OR FREE SPACE&lt;br /&gt;
24576-38999   $6000-$95FF   FREE SPACE AND STRING STORAGE&lt;br /&gt;
38400-49151   $9600-$BFFF   DOS&lt;br /&gt;
49152-53247   $C000-$CFFF   I/O HARDWARE (RESERVED)&lt;br /&gt;
53248-57343   $D000-$DFFF   APPLESOFT IN LANGUAGE CARD OR ROM&lt;br /&gt;
57344-63487   $E000-$F7FF   APPLESOFT OR INTEGER BASIC IN LANGUAGE CARD OR ROM&lt;br /&gt;
63488-65535   $F800-$FFFF   SYSTEM MONITOR&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Display ===&lt;br /&gt;
&lt;br /&gt;
=== Graphics Modes ===&lt;br /&gt;
: Text Mode 40x24, for Apple IIe available 80x25 - use PR#3 for switch mode, or hardware switch&lt;br /&gt;
: LowRes 40x48, 16 colors: https://en.wikipedia.org/wiki/Apple_II_graphics &lt;br /&gt;
: Hires mode 280x192,6 colors: https://www.xtof.info/blog/?p=768&lt;br /&gt;
https://mrob.com/pub/xapple2/colors.html&lt;br /&gt;
https://archive.org/details/HiRes_Color_Graphics_on_the_Apple_II_Computer_by_Wozniak&lt;br /&gt;
&lt;br /&gt;
However for sizecoding, you almost never want to do direct-access to graphics for Apple II in size-coding because the Apple II graphics modes are horrible.  The only fast way to do things is with large lookup tables.  To do hires you need to divide by 7 which as you can imagine is a bit difficult to do compactly on 6502. Double-hires is even crazier on top of that.  Deater did manage a color-bar style effect in double-hires in 128B but that was doing some crazy tricks with the firmware BASIC routines, definitely not direct-access.&lt;br /&gt;
&lt;br /&gt;
Lores and Hires can be mixed modes and full-graphics&lt;br /&gt;
The screen structure is called memory holes(https://retrocomputing.stackexchange.com/questions/2534/what-are-the-screen-holes-in-apple-ii-graphics). The GBASCALC($F847) procedure is used to calculate the address of the horizontal line : IN:reg.A=Y, out : GBASL/GBASH($26/$27)=address. See also https://www.callapple.org/uncategorized/use-of-apple-ii-color-graphics-in-assembly-language/&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
Here is an example of a XOR texture, created by g0blinish&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
GBASL	=	$26&lt;br /&gt;
GBASH	=	$27&lt;br /&gt;
SETGR    =     $FB40 ; setup LoRes&lt;br /&gt;
GBASCALC = $F847 ; calc Address&lt;br /&gt;
&lt;br /&gt;
CLRTEXT =  $C050 ;display graphics &lt;br /&gt;
SETTEXT =  $C051 ;display text &lt;br /&gt;
&lt;br /&gt;
CLRMIXED = $C052 ;clear mixed mode- enable full graphics &lt;br /&gt;
SETMIXED = $C053 ;enable graphics/text mixed mode &lt;br /&gt;
&lt;br /&gt;
PAGE1 =    $C054 ;select text/graphics page1 &lt;br /&gt;
PAGE2 =    $C055 ;select text/graphics page2 &lt;br /&gt;
&lt;br /&gt;
CLRHIRES = $C056 ;select Lo-res &lt;br /&gt;
SETHIRES = $C057 ;select Hi-res &lt;br /&gt;
&lt;br /&gt;
TMP= $FA&lt;br /&gt;
&lt;br /&gt;
	JSR   SETGR      ;GR&lt;br /&gt;
	BIT CLRMIXED ; full screen&lt;br /&gt;
&lt;br /&gt;
	LDA #0 ; A=0&lt;br /&gt;
	STA TMP ; POKE $FA,A&lt;br /&gt;
&lt;br /&gt;
YLP ;&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
;	LSR ; A=A/2&lt;br /&gt;
	JSR GBASCALC&lt;br /&gt;
	LDY #0;Y=0&lt;br /&gt;
&lt;br /&gt;
XLP TYA ; A=Y&lt;br /&gt;
	EOR TMP ; A=A xor PEEK($FA)&lt;br /&gt;
	and #$0F ; A=A and 15&lt;br /&gt;
	TAX ; X=A&lt;br /&gt;
	LDA COLORS,X ;A=PEEK(COLORS+X)&lt;br /&gt;
	STA(GBASL),Y ; POKE PEEK($26)+256*PEEK($27)+Y,A&lt;br /&gt;
	INY ; Y=Y+1&lt;br /&gt;
	CPY #40 ; Y=40?&lt;br /&gt;
	BNE XLP&lt;br /&gt;
	INC TMP ; POKE $FA,PEEK($FA)+1&lt;br /&gt;
	LDA TMP ; A=PEEK($FA)&lt;br /&gt;
	CMP #24 ; A=24?&lt;br /&gt;
	BNE YLP&lt;br /&gt;
	&lt;br /&gt;
M1 JMP M1 ; replace to RTS&lt;br /&gt;
&lt;br /&gt;
COLORS ;N*17, pixel format is AAAABBBB, AAAA - upper dot, BBBB - lower dot&lt;br /&gt;
!byte $00,$11,$22,$33,$44,$55,$66,$77&lt;br /&gt;
!byte $88,$99,$AA,$BB,$CC,$DD,$EE,$FF&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sound  ====&lt;br /&gt;
Here is an example for using the speaker, based onthe following basic program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;basic&amp;quot;&amp;gt;&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;6502&amp;quot;&amp;gt;&lt;br /&gt;
 *=$6000&lt;br /&gt;
 !to &amp;quot;HL.bin&amp;quot;, plain	; set output file and format&lt;br /&gt;
 !cpu 6502		; set processor type&lt;br /&gt;
&lt;br /&gt;
;start&lt;br /&gt;
; 95  FOR K = 1 TO N: READ V(K),P(K): NEXT K&lt;br /&gt;
; 100  FOR K = 1 TO N:V = V(K):P = P(K)&lt;br /&gt;
ini:&lt;br /&gt;
	lda #70&lt;br /&gt;
	sta cnt+1&lt;br /&gt;
	lda #music&amp;amp;255&lt;br /&gt;
	sta gotbyte+1&lt;br /&gt;
	lda #music/256&lt;br /&gt;
	sta gotbyte+2&lt;br /&gt;
&lt;br /&gt;
lop:&lt;br /&gt;
;V&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L300&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
;P&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	sta L301&lt;br /&gt;
	jsr gotbyte&lt;br /&gt;
	clc&lt;br /&gt;
	adc #1&lt;br /&gt;
	sta L320&lt;br /&gt;
	jsr beep&lt;br /&gt;
	&lt;br /&gt;
	dec cnt+1&lt;br /&gt;
cnt lda #70&lt;br /&gt;
	bne lop&lt;br /&gt;
; 110  GOSUB 50&lt;br /&gt;
; 50  POKE 768,V: POKE 769,P - 255 *  INT (P / 256): POKE 800,1 + P / 256&lt;br /&gt;
; 60  CALL 770: RETURN &lt;br /&gt;
	jmp ini&lt;br /&gt;
gotbyte&lt;br /&gt;
	lda music&lt;br /&gt;
	inc gotbyte+1&lt;br /&gt;
	bne noinch&lt;br /&gt;
	inc gotbyte+2&lt;br /&gt;
noinch&lt;br /&gt;
	rts&lt;br /&gt;
;!byte 173,48,192,136,208,5,206,1,3,240,9,202,208,245,174,0,3,76,2,3,206,32,3,208,240,96&lt;br /&gt;
beep:&lt;br /&gt;
	ldy #1&lt;br /&gt;
	ldx #1&lt;br /&gt;
loc_302:&lt;br /&gt;
		LDA	$C030&lt;br /&gt;
&lt;br /&gt;
loc_305:&lt;br /&gt;
		DEY&lt;br /&gt;
		BNE	loc_30D&lt;br /&gt;
		DEC	L301&lt;br /&gt;
loc_30B:&lt;br /&gt;
		BEQ	loc_316&lt;br /&gt;
&lt;br /&gt;
loc_30D:&lt;br /&gt;
		DEX&lt;br /&gt;
		BNE	loc_305&lt;br /&gt;
		LDX	L300&lt;br /&gt;
		JMP	loc_302&lt;br /&gt;
loc_316:&lt;br /&gt;
		DEC	L320&lt;br /&gt;
		BNE	loc_30B&lt;br /&gt;
		RTS&lt;br /&gt;
L301 !byte 0&lt;br /&gt;
L300 !byte 0&lt;br /&gt;
L320 !byte 0&lt;br /&gt;
music&lt;br /&gt;
 !word 76,192,85,64,96,64,102,64,114,128,114,64,96,64,102,64,114,64,128,64&lt;br /&gt;
 !word 114,64,152,64,171,64,152,512,76,192,85,64,96,64,102,64,114,128,114,64&lt;br /&gt;
 !word 96,64,102,64,114,64,128,64,114,64,152,64,171,64,152,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,128,114,64,128,64,114,512,85,64,85,64&lt;br /&gt;
 !word 85,64,96,64,144,128,144,64,128,64,76,128,85,64,96,64,144,128,114,64&lt;br /&gt;
 !word 96,64,102,128,114,64,128,64,128,64,128,128,96,64,85,64,96,64,102,64,114,64,114,64&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
* Deater's page on Apple II sizecoding http://www.deater.net/weave/vmwprod/demos/sizecoding.html (with an additional presentation at https://www.youtube.com/watch?v=kJ-EXbnw0kQ )&lt;br /&gt;
* Article on double hi-res http://www.battlestations.zone/2017/04/apple-ii-double-hi-res-from-ground-up.html&lt;br /&gt;
* Applesoft Hi-Res Subroutines : http://hackzapple.org/scripts_php/index.php?menu=5&amp;amp;mod=ASM&amp;amp;sub=AAL&amp;amp;sub2=8112&amp;amp;PHPSESSID=f65fabfd0cdbf56b6bdc0ddac25117c6#a2&lt;br /&gt;
&lt;br /&gt;
== Atari Lynx ==&lt;br /&gt;
The Atari Lynx consists of the 6502 with custom hardware for graphics and sound.&lt;br /&gt;
&lt;br /&gt;
=== Setting up ===&lt;br /&gt;
Setting up your development platform for the Atari Lynx:&lt;br /&gt;
&lt;br /&gt;
* Assembler: -&lt;br /&gt;
* Emulator(s): -&lt;br /&gt;
&lt;br /&gt;
=== Video display ===&lt;br /&gt;
The Lynx display is 160x102 pixels which are linear organized as 4 bit per pixel. Hence the screen is little less than 8K.&lt;br /&gt;
The pixel value is a pointer to the color look up table.&lt;br /&gt;
The Lynx can display black and 4095 colors. The color table is split up into a green and an blue-red part (so not RGB but GBR).&lt;br /&gt;
&lt;br /&gt;
==== Getting something on screen ====&lt;br /&gt;
After the ROM has deciphered the boot sector the display memory is at $2000, background color (that is pen 0) is black, all other entries are $f despite entry 14 which is also 0.&lt;br /&gt;
&lt;br /&gt;
So to fill the screen simply do:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lda #$ff&lt;br /&gt;
ldx #0&lt;br /&gt;
ldy #$20   ; round(160*102/2/256)&lt;br /&gt;
loop:&lt;br /&gt;
    sta $2000,x&lt;br /&gt;
    inx&lt;br /&gt;
  bne loop&lt;br /&gt;
  dey&lt;br /&gt;
bne loop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sound ===&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
==== Make some noise ====&lt;br /&gt;
To be added soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional Resources ===&lt;br /&gt;
Sizecoding resource for the Atari Lynx are sparse&lt;br /&gt;
* 42Bastian's website (link to be added)&lt;/div&gt;</summary>
		<author><name>42Bastian</name></author>	</entry>

	</feed>