Difference between revisions of "Source Codes"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
(Graphics)
(Graphics)
(9 intermediate revisions by 3 users not shown)
Line 11: Line 11:
 
*[[Z80_-_undocumented_opcodes|Z80 - undocumented opcodes]]
 
*[[Z80_-_undocumented_opcodes|Z80 - undocumented opcodes]]
 
*[[Where to learn?]]
 
*[[Where to learn?]]
 +
*[[A little optimization for Z80 Assembler]]
  
 
== Algorithms ==
 
== Algorithms ==
Line 26: Line 27:
 
*[[Programming:Square Root|Square Root]]
 
*[[Programming:Square Root|Square Root]]
 
*[[Programming:Precalculated square|Precalculated square]]
 
*[[Programming:Precalculated square|Precalculated square]]
 +
*[[Programming:Maze generation|Maze generation]]
 
*[[Programming:Random Number Generator|Random Number Generator]]
 
*[[Programming:Random Number Generator|Random Number Generator]]
 
*[[Programming:Reverse A|Reverse A]]
 
*[[Programming:Reverse A|Reverse A]]
Line 62: Line 64:
 
*[[Programming:An example to read a file byte-by-byte|An example to read a file byte-by-byte]]
 
*[[Programming:An example to read a file byte-by-byte|An example to read a file byte-by-byte]]
 
*[[Programming:An example to write a file byte-by-byte|An example to write a file byte-by-byte]]
 
*[[Programming:An example to write a file byte-by-byte|An example to write a file byte-by-byte]]
 +
*[[Programming:Read/Write a file quickly byte-by-byte|Read or write a file quickly byte-by-byte]]
 
*[[Programming:A simple file copier using firmware functions (copies byte-by-byte)|A simple file copier using firmware functions (copies byte-by-byte)]]
 
*[[Programming:A simple file copier using firmware functions (copies byte-by-byte)|A simple file copier using firmware functions (copies byte-by-byte)]]
 
*[[Programming:Loading a file|Loading a file]]
 
*[[Programming:Loading a file|Loading a file]]
Line 78: Line 81:
 
*[[Programming:Reading and writing the boot sector of a SYSTEM/VENDOR disc|Reading and writing the boot sector of a SYSTEM/VENDOR disc]]
 
*[[Programming:Reading and writing the boot sector of a SYSTEM/VENDOR disc|Reading and writing the boot sector of a SYSTEM/VENDOR disc]]
 
*[[Programming:Writing a sector to disc|Writing a sector to disc]]
 
*[[Programming:Writing a sector to disc|Writing a sector to disc]]
 +
 +
== Games ==
 +
*[[Programming:Coding a simple BASIC game into Assembly]]
  
 
== Graphics ==
 
== Graphics ==
 +
 +
*[[Programming:Calculating xpos,ypos to screen address in assembly|Calculating xpos,ypos to screen address]]
 
*[[Programming:Display a 8-bit number in binary|Display a 8-bit number in binary]]
 
*[[Programming:Display a 8-bit number in binary|Display a 8-bit number in binary]]
 
*[[Programming:Display a 8-bit number in hex|Display a 8-bit number in hex]]
 
*[[Programming:Display a 8-bit number in hex|Display a 8-bit number in hex]]
Line 88: Line 96:
 
*[[Programming:Fast Sprites|Fast Sprites]] by [[User:Executioner|Executioner]]
 
*[[Programming:Fast Sprites|Fast Sprites]] by [[User:Executioner|Executioner]]
 
*[[Programming:Fast Textoutput|Fast Textoutput]] by [[Prodatron]]
 
*[[Programming:Fast Textoutput|Fast Textoutput]] by [[Prodatron]]
*[[Programming:Fastest Character Print in Mode 2|Fastest Character Print in Mode 2 in all screen positions]] by [[FG Brain]]
+
*[[Fastest_Character_Print_in_Mode_2|Fastest Character Print in Mode 2 in all screen positions]] by [[FG Brain]]
 
*[[Programming:Hardware scrolling|Hardware Scrolling]] by [[User:Executioner|Executioner]]
 
*[[Programming:Hardware scrolling|Hardware Scrolling]] by [[User:Executioner|Executioner]]
 
*[[Programming:Hardware scrolling 2|Hardware Scrolling 2]]
 
*[[Programming:Hardware scrolling 2|Hardware Scrolling 2]]
Line 117: Line 125:
 
*[[Programming:Dumping the data of BASIC or AMSDOS or an expansion rom|Dumping the data of BASIC or AMSDOS or an expansion rom]]
 
*[[Programming:Dumping the data of BASIC or AMSDOS or an expansion rom|Dumping the data of BASIC or AMSDOS or an expansion rom]]
 
*[[Programming:Dumping the data of the lower rom|Dumping the data of the lower rom]]
 
*[[Programming:Dumping the data of the lower rom|Dumping the data of the lower rom]]
 +
*[[Programming:Storing and Retrieving Screens from the extra 64kb|Storing and Retrieving Screens from the extra 64kb]]
  
 
== Sound ==
 
== Sound ==

Revision as of 07:49, 25 December 2018

This article contains source codes and programming examples. You may also have a look at


Assembler

Algorithms

CP/M

CPC Plus

Devices

File access

Floppy disk

Games

Graphics

Interrupts

Keyboard

Other routines

Sound

Cross Development

General Notes

  • Memory range for programs is &0040-&a700. This avoids firmware and memory allocated by AMSDOS disc ROM.

This is safe for the purpose of loading and being compatible with the firmware. 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.

  • Programs on cassette and disc have a header that define the load address, length and execution address.

In Pasmo assembler use the "end" mnemonic to define the label which is the execution address and use "--amsdos" to put an AMSDOS header on it.

  • Basic programs start at &170.
  • Firmware uses interrupt mode 1 of the Z80 (interrupts jump to &0038)
  • Lowest place you can LOAD a binary file to with BASIC is &389 e.g.:
openout"d"
memory <address>-1
closeout
load "code",<address>
call <exec>
  • Screen is normally at &c000-&ffff. (It can be changed using firmware, or using CRTC R12/R13)
  • Stack is normally at &c000 and goes down.
  • Extra registers (BC', AF', HL', DE' are reserved by the firmware). Avoid if you are using firmware functions.
  • Lower rom (containing OS) can be paged into memory between &0000-&3fff.
  • Upper rom is selectable, examples are BASIC and AMSDOS. They can be paged into memory between &c000-&ffff.
  • From basic, a game is run with:
RUN"<filename>

keep it in the safe memory ranges and it'll run from cassette and disc.

  • 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.
  • Screen is bitmapped. You must draw/erase your own sprites and text.
  • 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.
  • Firmware can be "turned off", by disabling lower ROM, redirecting interrupts and not calling firmware functions.
  • 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's not continuous, it's in 8 seperate blocks, but it's enough to store data and code.