This article contains source codes and programming examples. You may also have a look at
Assembler
Algorithms
- Bubble sort
- CPC OS floating point routines
- CRC16
- CRC32
- Integer Division
- Integer Multiplication
- Logarithm
- Ultrafast Multiplication by Prodatron
- Fast Square Root
- Fast 16 bit Square Root by Executioner
- Filling memory with a byte
- Square Root
- Precalculated square
- Random Number Generator
- Reverse A
- Quicksort
- Sin/Cos calculation
CP/M
- A simple 'Hello World' program for CP/M using BDOS
- A simple 'Hello World' program for CP/M using BIOS
- Executing firmware functions from within CP/M 2.1
- Executing firmware functions from within CP/M 2.1 or CP/M plus
- Executing firmware functions from within CP/M 2.1
- Executing firmware functions from within CP/M plus
CPC Plus
- Amstrad CPC plus sprite format
- Convert CPC sprites to Plus hardware sprites
- Sprites Multiplexing
- Hardware sprites
- Horizontal scroll
- RLE hardware sprites
- Screen splitting
- Vertical scroll
- Operation of Z80 interrupt mode 0 in the CPC plus design
- Simple Raster Example 1 (uses CPC plus features)
- Simple Raster Example 2 (uses CPC plus features)
- Unlocking ASIC
Devices
File access
Floppy disk
- A simple disc copier using BDOS functions
- A simple disc formatter using BDOS functions
- An example loader
- Catalog a disc and retrieve a directory
- Detecting an Amstrad or Vortex disc controler
- Formatting a track on a disc
- Reading a sector from a disc
- Reading and writing the boot sector of a SYSTEM/VENDOR disc
- Writing a sector to disc
Graphics
- Display a 8-bit number in binary
- Display a 8-bit number in hex
- Display a byte as a 3-digit decimal number
- Display and update Scores
- Distorting the screen using register 2 of the CRTC (Horizontal Sync Position)
- Fast plot
- Fast Sprites by Executioner
- Fast Textoutput by Prodatron
- Hardware Scrolling by Executioner
- Hardware Scrolling 2
- Hardware scrolling the screen horizontally byte-by-byte using the CRTC
- Hardware scrolling the screen using the CRTC
- Next / previous line calculation
- Overscan
- Plotting a sprite using character matrices
- 4th Mode of CPCs: Plotting sprites on 2 bitplanes
- Set the screen refresh rate
- Simple Raster Example
- Simple Split Raster Example
- Synchronising with the CRTC and display
- CRTC change colour (fill) test with precise timing by Matahari
- 256 byte Overscan MEGATEXT Intro - (features 50Hz fullscreen scroll) by Matahari
Interrupts
Keyboard
Other routines
Sound
- How to access the PSG via PPI
- Tutorial - Understanding the fundamentals of BASIC SOUND and the Firmware SOUND QUEUE
- Source code to show 0x0ff is always returned when reading PSG port B
- 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 even if the port has been set to input
- Source code to show that some registers always return 0 in some bits
- 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
Cross Development
General Notes
- Memory range for programs is &0040-&a700. This avoids firmware and memory allocated by AMSDOS disc ROM.
- 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.