<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.amstrad-cpc.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gougoutt</id>
	<title>CPCWiki - THE Amstrad CPC encyclopedia! - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.amstrad-cpc.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Gougoutt"/>
	<link rel="alternate" type="text/html" href="https://wiki.amstrad-cpc.net/wiki/Special:Contributions/Gougoutt"/>
	<updated>2026-09-04T00:09:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.amstrad-cpc.net/index.php?title=Source_Codes&amp;diff=9183</id>
		<title>Source Codes</title>
		<link rel="alternate" type="text/html" href="https://wiki.amstrad-cpc.net/index.php?title=Source_Codes&amp;diff=9183"/>
		<updated>2023-10-28T18:55:32Z</updated>

		<summary type="html">&lt;p&gt;Gougoutt: Add link to &amp;#039;A Survey of Advanced Assembly Language Programming Techniques on the MOS 6502 and Zilog Z80&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Programming]]&lt;br /&gt;
&#039;&#039;This article contains source codes and programming examples. You may also have a look at&#039;&#039;&lt;br /&gt;
* [[Programming software]]&lt;br /&gt;
* [[BIOS Functions]]&lt;br /&gt;
* [[Technical documentation]]s&lt;br /&gt;
* [[Locomotive BASIC]]&lt;br /&gt;
* [[Type Ins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Assembler ==&lt;br /&gt;
*[[Z80_-_undocumented_opcodes|Z80 - undocumented opcodes]]&lt;br /&gt;
*[[Where to learn?]]&lt;br /&gt;
*[[A little optimization for Z80 Assembler]]&lt;br /&gt;
*[https://github.com/sebastiengoutal/publications/blob/cae9abe5d684f98912571e4e713fc7af5f70760c/A%20Survey%20of%20Advanced%20Assembly%20Language%20Programming%20Techniques%20on%20the%20MOS%206502%20and%20Zilog%20Z80.pdf A publication on advanced assembly programming techniques on the Z80]&lt;br /&gt;
&lt;br /&gt;
== Algorithms ==&lt;br /&gt;
*[[Programming:Bubble sort|Bubble sort]]&lt;br /&gt;
*[[Programming:CPC OS floating point routines|CPC OS floating point routines]]&lt;br /&gt;
*[[Programming:CRC16|CRC16]]&lt;br /&gt;
*[[Programming:CRC32|CRC32]]&lt;br /&gt;
*[[Programming:Integer Division|Integer Division]]&lt;br /&gt;
*[[Programming:Integer Multiplication|Integer Multiplication]]&lt;br /&gt;
*[[Programming:Logarithm|Logarithm]]&lt;br /&gt;
*[[Programming:Ultrafast Multiplication|Ultrafast Multiplication]] by [[Prodatron]]&lt;br /&gt;
*[[Programming:Fast Square Root|Fast Square Root]]&lt;br /&gt;
*[[Programming:Fast 16 bit Square Root|Fast 16 bit Square Root]] by [[User:Executioner|Executioner]]&lt;br /&gt;
*[[Programming:Filling memory with a byte|Filling memory with a byte]]&lt;br /&gt;
*[[Programming:Square Root|Square Root]]&lt;br /&gt;
*[[Programming:Precalculated square|Precalculated square]]&lt;br /&gt;
*[[Programming:Maze generation|Maze generation]]&lt;br /&gt;
*[[Programming:Random Number Generator|Random Number Generator]]&lt;br /&gt;
*[[Programming:Reverse A|Reverse A]]&lt;br /&gt;
*[[Programming:Quicksort|Quicksort]]&lt;br /&gt;
*[[Programming:Sin/Cos calculation|Sin/Cos calculation]]&lt;br /&gt;
&lt;br /&gt;
== CP/M ==&lt;br /&gt;
*[[Programming:A simple &#039;Hello World&#039; program for CP/M using BDOS|A simple &#039;Hello World&#039; program for CP/M using BDOS]]&lt;br /&gt;
*[[Programming:A simple &#039;Hello World&#039; program for CP/M using BIOS|A simple &#039;Hello World&#039; program for CP/M using BIOS]]&lt;br /&gt;
*[[Programming:Executing firmware functions from within CP/M 2.1|Executing firmware functions from within CP/M 2.1]]&lt;br /&gt;
*[[Programming:Executing firmware functions from within CP/M 2.1 or CP/M plus|Executing firmware functions from within CP/M 2.1 or CP/M plus]]&lt;br /&gt;
*[[Programming:Executing firmware functions from within CP/M 2.1|Executing firmware functions from within CP/M 2.1]]&lt;br /&gt;
*[[Programming:Executing firmware functions from within CP/M plus|Executing firmware functions from within CP/M plus]]&lt;br /&gt;
&lt;br /&gt;
== CPC Plus ==&lt;br /&gt;
*[[Amstrad CPC plus sprite format]]&lt;br /&gt;
*[[Programming:Convert CPC sprites to Plus hardware sprites|Convert CPC sprites to Plus hardware sprites]]&lt;br /&gt;
*[[Sprites Multiplexing]]&lt;br /&gt;
*[[Programming:CPC Plus Hardware Sprites|Hardware sprites]]&lt;br /&gt;
*[[Programming:CPC Plus Horizontal scroll|Horizontal scroll]]&lt;br /&gt;
*[[Programming:CPC Plus RLE Hardware Sprites|RLE hardware sprites]]&lt;br /&gt;
*[[Programming:CPC Plus Screen Splitting|Screen splitting]]&lt;br /&gt;
*[[Programming:CPC Plus Vertical scroll|Vertical scroll]]&lt;br /&gt;
*[[Operation of Z80 interrupt mode 0 in the CPC plus design]]&lt;br /&gt;
*[[Programming:Simple Raster Example 2 (uses CPC plus features)|Simple Raster Example 1 (uses CPC plus features)]]&lt;br /&gt;
*[[Programming:Simple Raster Example 3 (uses CPC plus features)|Simple Raster Example 2 (uses CPC plus features)]]&lt;br /&gt;
*[[Programming:Unlocking ASIC|Unlocking ASIC]]&lt;br /&gt;
&lt;br /&gt;
== Devices ==&lt;br /&gt;
*[[Programming:CPC Booster|CPC Booster]]&lt;br /&gt;
*[[Programming:Digiblaster|Digiblaster]]&lt;br /&gt;
*[[Programming:Program to save the ROM of the Multiface 2|Program to save the ROM of the Multiface 2]]&lt;br /&gt;
*[[Programming:SYMBiFACE II|SYMBiFACE II]]&lt;br /&gt;
&lt;br /&gt;
== File access ==&lt;br /&gt;
*[[Programming:An example to read a file byte-by-byte|An example to read a file byte-by-byte]]&lt;br /&gt;
*[[Programming:An example to write a file byte-by-byte|An example to write a file byte-by-byte]]&lt;br /&gt;
*[[Programming:Read/Write a file quickly byte-by-byte|Read or write a file quickly byte-by-byte]]&lt;br /&gt;
*[[Programming:A simple file copier using firmware functions (copies byte-by-byte)|A simple file copier using firmware functions (copies byte-by-byte)]]&lt;br /&gt;
*[[Programming:Loading a file|Loading a file]]&lt;br /&gt;
*[[Programming:Saving a file|Saving a file]]&lt;br /&gt;
*[[Programming:Unlocking a protected basic file|Unlocking a protected basic file]]&lt;br /&gt;
*[[Programming:Undo delete of file|Undo delete of file]]&lt;br /&gt;
&lt;br /&gt;
== Floppy disk ==&lt;br /&gt;
*[[Programming:A simple disc copier using BDOS functions|A simple disc copier using BDOS functions]]&lt;br /&gt;
*[[Programming:A simple disc formatter using BDOS functions|A simple disc formatter using BDOS functions]]&lt;br /&gt;
*[[Programming:An example loader|An example loader]]&lt;br /&gt;
*[[Programming:Catalog a disc and retrieve a directory|Catalog a disc and retrieve a directory]]&lt;br /&gt;
*[[Programming:Detecting an Amstrad or Vortex disc controler|Detecting an Amstrad or Vortex disc controler]]&lt;br /&gt;
*[[Programming:Formatting a track on a disc|Formatting a track on a disc]]&lt;br /&gt;
*[[Programming:Reading a sector from a disc|Reading a sector from a disc]]&lt;br /&gt;
*[[Programming:Reading and writing the boot sector of a SYSTEM/VENDOR disc|Reading and writing the boot sector of a SYSTEM/VENDOR disc]]&lt;br /&gt;
*[[Programming:Writing a sector to disc|Writing a sector to disc]]&lt;br /&gt;
&lt;br /&gt;
== Games ==&lt;br /&gt;
*[[Programming:Coding a simple BASIC game into Assembly]]&lt;br /&gt;
&lt;br /&gt;
== Graphics ==&lt;br /&gt;
&lt;br /&gt;
*[[Programming:Calculating xpos,ypos to screen address in assembly|Calculating xpos,ypos to screen address]]&lt;br /&gt;
*[[Programming:Display a 8-bit number in binary|Display a 8-bit number in binary]]&lt;br /&gt;
*[[Programming:Display a 8-bit number in hex|Display a 8-bit number in hex]]&lt;br /&gt;
*[[Programming:Display a byte as a 3-digit decimal number|Display a byte as a 3-digit decimal number]]&lt;br /&gt;
*[[Programming:Display and update Scores|Display and update Scores]]&lt;br /&gt;
*[[Programming:Distorting the screen using register 2 of the CRTC (Horizontal Sync Position)|Distorting the screen using register 2 of the CRTC (Horizontal Sync Position)]]&lt;br /&gt;
*[[Programming:Fast plot|Fast plot]]&lt;br /&gt;
*[[Programming:Fast Sprites|Fast Sprites]] by [[User:Executioner|Executioner]]&lt;br /&gt;
*[[Programming:Fast Textoutput|Fast Textoutput]] by [[Prodatron]]&lt;br /&gt;
*[[Fastest_Character_Print_in_Mode_2|Fastest Character Print in Mode 2 in all screen positions]] by [[FG Brain]]&lt;br /&gt;
*[[Programming:Hardware scrolling|Hardware Scrolling]] by [[User:Executioner|Executioner]]&lt;br /&gt;
*[[Programming:Hardware scrolling 2|Hardware Scrolling 2]]&lt;br /&gt;
*[[Programming:Hardware scrolling the screen horizontally byte-by-byte using the CRTC|Hardware scrolling the screen horizontally byte-by-byte using the CRTC]]&lt;br /&gt;
*[[Programming:Hardware scrolling the screen using the CRTC|Hardware scrolling the screen using the CRTC]]&lt;br /&gt;
*[[Programming:Next / previous line calculation|Next / previous line calculation]]&lt;br /&gt;
*[[Programming:Overscan|Overscan]]&lt;br /&gt;
*[[Programming:Plotting a sprite using character matrices|Plotting a sprite using character matrices]]&lt;br /&gt;
*[[Mode 4 (two bitplane emulation)| 4th Mode of CPCs: Plotting sprites on 2 bitplanes]]&lt;br /&gt;
*[[Screen refresh rate|Set the screen refresh rate]]&lt;br /&gt;
*[[Programming:Simple Raster Example 1|Simple Raster Example]]&lt;br /&gt;
*[[Programming:Simple Split Raster Example 1|Simple Split Raster Example]]&lt;br /&gt;
*[[Synchronising with the CRTC and display]]&lt;br /&gt;
*[[CRTC change colour (fill) test with precise timing]] by [[User:Matahari|Matahari]]&lt;br /&gt;
*[[256 byte Overscan MEGATEXT Intro - (features 50Hz fullscreen scroll)]] by [[User:Matahari|Matahari]]&lt;br /&gt;
&lt;br /&gt;
== Interrupts ==&lt;br /&gt;
* [[Reliable use of interrupt mode 2 on the CPC]]&lt;br /&gt;
&lt;br /&gt;
== Keyboard ==&lt;br /&gt;
*[[Programming:Keyboard scanning|Keyboard scanning]]&lt;br /&gt;
*[[Programming:Keyboard_redefinition|Keyboard redefinition]]&lt;br /&gt;
&lt;br /&gt;
== Cartridges ==&lt;br /&gt;
*[[Programming:Cartridges|Cartridges]]&lt;br /&gt;
*[[Programming:Crt0Cart|CRT0 for SDCC]] to init a CPR cart&lt;br /&gt;
&lt;br /&gt;
== Other routines ==&lt;br /&gt;
*[[Programming:An example boot sector (executed with rsx command CPM)|An example boot sector (executed with rsx command CPM)]]&lt;br /&gt;
*[[Programming:An example to define a RSX|An example to define a RSX]]&lt;br /&gt;
*[[Programming:Calling a RSX from outside of BASIC|Calling a RSX from outside of BASIC]]&lt;br /&gt;
*[[Programming:Dumping the data of BASIC or AMSDOS or an expansion rom|Dumping the data of BASIC or AMSDOS or an expansion rom]]&lt;br /&gt;
*[[Programming:Dumping the data of the lower rom|Dumping the data of the lower rom]]&lt;br /&gt;
*[[Programming:Storing and Retrieving Screens from the extra 64kb|Storing and Retrieving Screens from the extra 64kb]]&lt;br /&gt;
&lt;br /&gt;
== Sound ==&lt;br /&gt;
*[[How to access the PSG via PPI]]&lt;br /&gt;
*[[Programming:Tutorial - Understanding the fundamentals of BASIC SOUND and the Firmware SOUND QUEUE|Tutorial - Understanding the fundamentals of BASIC SOUND and the Firmware SOUND QUEUE]]&lt;br /&gt;
*[[Programming:Source code to show 0x0ff is always returned when reading PSG port B|Source code to show 0x0ff is always returned when reading PSG port B]]&lt;br /&gt;
*[[Programming:Source code to show it is possible to store data in PSG register 14 and 15 (port A and port B)|Source code to show it is possible to store data in PSG register 14 and 15 (port A and port B)]]&lt;br /&gt;
*[[Programming:Source code to show it is possible to store data in PSG register 14 and 15 even if the port has been set to input|Source code to show it is possible to store data in PSG register 14 and 15 even if the port has been set to input]]&lt;br /&gt;
*[[Programming:Source code to show that some registers always return 0 in some bits|Source code to show that some registers always return 0 in some bits]]&lt;br /&gt;
*[[Programming:Source code to show that when a port is read in output mode; the data read will be ANDed with the inputs to that port|Source code to show that when a port is read in output mode; the data read will be ANDed with the inputs to that port]]&lt;br /&gt;
&lt;br /&gt;
== Cross Development ==&lt;br /&gt;
*[[Programming:Cross Development|Cross Development]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Source code]]&lt;br /&gt;
&lt;br /&gt;
== General Notes ==&lt;br /&gt;
&lt;br /&gt;
* Memory range for programs is &amp;amp;0040-&amp;amp;a700. This avoids firmware and memory allocated by AMSDOS disc ROM.&lt;br /&gt;
This is safe for the purpose of loading and being compatible with the firmware.&lt;br /&gt;
After loading, if you disable the firmware, you can re-use the firmware areas as you want, but you need to do everything yourself (scanning keyboard, drawing, sound etc).If you need to use these areas, a common thing to do is to load most into the safe area, some into the screen, and relocate it after loading.&lt;br /&gt;
* Programs on cassette and disc have a header that define the load address, length and execution address.&lt;br /&gt;
&lt;br /&gt;
In Pasmo assembler use the &amp;quot;end&amp;quot; mnemonic to define the label which is the execution address and use &amp;quot;--amsdos&amp;quot; to put an AMSDOS header on it.&lt;br /&gt;
&lt;br /&gt;
* Basic programs start at &amp;amp;170.&lt;br /&gt;
* Firmware uses interrupt mode 1 of the Z80 (interrupts jump to &amp;amp;0038)&lt;br /&gt;
* Lowest place you can LOAD a binary file to with BASIC is &amp;amp;389 e.g.:&lt;br /&gt;
&lt;br /&gt;
 openout&amp;quot;d&amp;quot;&lt;br /&gt;
 memory &amp;lt;address&amp;gt;-1&lt;br /&gt;
 closeout&lt;br /&gt;
 load &amp;quot;code&amp;quot;,&amp;lt;address&amp;gt;&lt;br /&gt;
 call &amp;lt;exec&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Screen is normally at &amp;amp;c000-&amp;amp;ffff. (It can be changed using firmware, or using CRTC R12/R13)&lt;br /&gt;
*Stack is normally at &amp;amp;c000 and goes down.&lt;br /&gt;
*Extra registers (BC&#039;, AF&#039;, HL&#039;, DE&#039; are reserved by the firmware). Avoid if you are using firmware functions.&lt;br /&gt;
*Lower rom (containing OS) can be paged into memory between &amp;amp;0000-&amp;amp;3fff.&lt;br /&gt;
*Upper rom is selectable, examples are BASIC and AMSDOS. They can be paged into memory between &amp;amp;c000-&amp;amp;ffff.&lt;br /&gt;
*From basic, a game is run with:&lt;br /&gt;
&lt;br /&gt;
 RUN&amp;quot;&amp;lt;filename&amp;gt;&lt;br /&gt;
&lt;br /&gt;
keep it in the safe memory ranges and it&#039;ll run from cassette and disc.&lt;br /&gt;
*Screen is normally 40 crtc chars wide (CRTC R1=40), 25 crtc chars tall (CRTC R6=25). 8 scan lines per char (R9=7). Firmware functions assume this.&lt;br /&gt;
*Screen is bitmapped. You must draw/erase your own sprites and text.&lt;br /&gt;
*Firmware refreshes the palette every 50th of a second, so you need to turn off the firmware and use the hardware directly, or set the colours using firmware.&lt;br /&gt;
*Firmware can be &amp;quot;turned off&amp;quot;, by disabling lower ROM, redirecting interrupts and not calling firmware functions.&lt;br /&gt;
*Screen can be resized the same as the Spectrum. Provided you do not use hardware scrolling, this gives you extra space although because of the layout of the screen, it&#039;s not continuous, it&#039;s in 8 seperate blocks, but it&#039;s enough to store data and code.&lt;/div&gt;</summary>
		<author><name>Gougoutt</name></author>
	</entry>
</feed>