Difference between revisions of "Programming:Cartridges"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
(a start!)
 
Line 28: Line 28:
 
|}
 
|}
  
when a ROM bank is mapped into lower ROM (0x0000) or higher ROM (0xC000), reads will go to ROM and writes will go to RAM and mapped ROM is only seen by the CPU.
+
When a ROM bank is mapped into lower ROM (0x0000) or higher ROM (0xC000), reads will go to ROM and writes will go to RAM and mapped ROM is only seen by the CPU.
  
 
This is important because the gate array can only see RAM when drawing the screen.
 
This is important because the gate array can only see RAM when drawing the screen.
Line 34: Line 34:
 
The idea is mapping on higher ROM any of the banks as we need them, and we can use that data with RAM from 0x4000 to 0xffff, leaving on lower ROM the bank 0 with our code.
 
The idea is mapping on higher ROM any of the banks as we need them, and we can use that data with RAM from 0x4000 to 0xffff, leaving on lower ROM the bank 0 with our code.
  
It is easy to support both CPC+ and Dandanator from a single code base using macros.
+
It is '''easy to support both CPC+ and Dandanator from a single code base''' using macros.
  
Then generating both CRT and Dandanator ROMs is easy. For example, these [https://github.com/reidrac/cpr-tools simple tools to make/dump CPC+ CPR cartridge files] can generate both formats (use RAW and padding flags to get a Dandanator ROM).
+
Then generating both CRT and Dandanator ROMs is trivial. For example, these [https://github.com/reidrac/cpr-tools simple tools to make/dump CPC+ CPR cartridge files] can generate both formats (use RAW and padding flags to get a Dandanator ROM).
  
 
== Dandanator ==
 
== Dandanator ==

Revision as of 02:03, 30 May 2022

Overview

The main media to distribute software on the CPC was cassettes and 3 inch floppy disks. The Plus models, including the GX4000 console, introduced cartridges.

As the original media is harder to find (3" discs specially), cartridges are becoming one of the best options to distribute CPC software, for example:

  • Dandanator mini –page only in Spanish–: is a cartridge format to be plugged in the expansion port that provides a number of generic and advanced features, including support for 512K of ROM (in 16K banks), and it works on any CPC without jumpers or special configuration.
  • DES: the Dandanator Entertainment System, which is an interface that goes to the expansion port and supports cartridges. It has the same functionality as the Dandanator, with the difference that the expansion contains most of the functionality, and the cartridges are simpler –and cheaper–.
  • Plus2CPC: provides a cheap way to plug CPC Plus cartridges on any CPC and, as long as the cartridge doesn’t use any Plus features, it will work. It also offers 512K of ROM, just like the Dandanator, and uses the regular ROM mapping functions of the CPC.
  • the M4 board: can load CRT files on any CPC.
  • C4CPC: can load CRT files on the GX4000.

Strategy

When the CPC boots from cartridge, the code will start executing at address 0x0000 and we have the first 16K bank mapped on that address (lower ROM).

Address Size Type Function
0x0000 16K ROM Code
0x4000 16K ROM R/W Data
0x8000 16K RAM R/W Data
0xc000 16K RAM/ROM Video memory/Mapped cart bank

When a ROM bank is mapped into lower ROM (0x0000) or higher ROM (0xC000), reads will go to ROM and writes will go to RAM and mapped ROM is only seen by the CPU.

This is important because the gate array can only see RAM when drawing the screen.

The idea is mapping on higher ROM any of the banks as we need them, and we can use that data with RAM from 0x4000 to 0xffff, leaving on lower ROM the bank 0 with our code.

It is easy to support both CPC+ and Dandanator from a single code base using macros.

Then generating both CRT and Dandanator ROMs is trivial. For example, these simple tools to make/dump CPC+ CPR cartridge files can generate both formats (use RAW and padding flags to get a Dandanator ROM).

Dandanator

Init the cart (not needed in CPC+ carts):

   ; SDCC syntax
   ; the byte pointed by iy will be overwritten
   di
   ld a, #0x8a
   .db 0xfd, 0xfd
   ld 0 (iy), a
   ei

Bank switch higher ROM:

   ; SDCC syntax
   ; defined as __z88dk_fastcall in C - parameter in l
   ; the byte pointed by iy will be overwritten
   di
   ld c, l
   .db 0xfd, 0xfd
   ld 0 (iy), c
   ei


Unmap higher ROM (have regular RAM in 0xc000):

   ; SDCC syntax
   ; the byte pointed by iy will be overwritten
   di
   ld c, #32
   .db 0xfd, 0xfd
   ld 0 (iy), c
   ei

CPC+ carts (CRT)

Bank switch higher ROM:

   ; SDCC syntax
   ; defined as __z88dk_fastcall in C - parameter in l
   di
   ld a, l
   ; cart slots 0 - 31 start at 128
   or #128
   ld c, a
   ld b, #0xdf
   out (c),c
   ld bc, #0x7f80
   out (c),c
   ei

Unmap higher ROM (have regular RAM in 0xc000):

   ; SDCC syntax
   di
   ld bc, #0x7f88
   out (c),c
   ei

References

Sources (used with permission; CC BY NC SA 4.0):