# The 'Spectrum port'

## Why convert a Spectrum game to the CPC?

Many Sinclair Spectrum games were converted to the Amstrad for the following reasons:

- Both the CPC and Spectrum have a Z80 CPU, the source code to the game could be rebuilt for the CPC easily. In the original code where the Spectrum hardware (the display, the keyboard, sound) was accessed, these would now access CPC code which would perform the same action (e.g. plot a sprite on the screen).
- The display of the Spectrum could be simulated, to some degree, on the CPC. So you could re-use the graphics and convert them into a format the CPC version of the game could use,
- The market for CPC games was smaller than that of the Spectrum, but large enough to warrant a CPC version of the game, and since many of the assets used to create the Spectrum could be reused for the CPC version, the cost of this development was small,
- To convert the Spectrum version of the game to the CPC took a short length of time (often as little as two weeks). Once the CPC specific game functions were written, and the tools to convert the graphics and sound to the CPC, you did not need to write them again for each game that required conversion.

Therefore, converting a Spectrum version of a game to the CPC was used extensively.

Unfortunatly many companies did not have the time/money or motivation to take advantage of the Amstrad's colours and range of video modes, so the CPC version was often inferior. Some games had less colour (they were monochrome), and were slower. A game that had been converted in this way was called a 'Spectrum port' (the game was 'transported from the Spectrum').

## Simulating the Spectrum's display

The Spectrum screen is 256 pixels wide and 192 pixels tall. The pixels are square, and are the same resolution as Amstrad's graphics mode 1.

The screen dimensions can be simulated by programming the CRTC, the resolution by programming the Gate Array.

The screen properties are:

- 32 CRTC characters in width,
- 24 CRTC characters in height,
- 8 CRTC raster lines per CRTC character,

The following Z80 assembly code will set the size of the CPC's display to match that of the Spectrum's:

    ;; set width of screen in characters
    ld bc,&bc01
    out (c),c
    ld bc,&bd00+32
    out (c),c

    ;; set horizontal position of screen so that it is centralised
    ld bc,&bc02
    out (c),c
    ld bc,&bd00+46
    out (c),c

    ;; set height of screen in CRTC characters
    ld bc,&bc06
    out (c),c
    ld bc,&bd00+24
    out (c),c

    ;; set 8 raster lines per CRTC character line
    ld bc,&bc09
    out (c),c
    ld bc,&bd00+7
    out (c),c

    ;; set vertical position of screen so that it is centralised
    ld bc,&bc07
    out (c),c
    ld bc,&bd00+29
    out (c),c

The following Z80 assembly code will set the CPC's screen mode to 1, which matches the pixel size and pixel aspect of the Spectrum's display:

    ld bc,&7f00+%10001110
    out (c),c

Differences between the CPC's display and the Spectrum's:

- The Spectrum uses 'display attributes' to define the foreground and background colour of a 8x8 pixel cell. Using this method it can display all of the possible 16 colours allowed by it's hardware (8 different colours with 2 levels of brightness for each colour).
- The memory address corresponding to a byte on the screen is different between the CPC and Spectrum, and the equivalent SCR PREV BYTE, SCR NEXT BYTE, SCR PREV LINE and SCR NEXT LINE functions are different. The Amstrad's mode 1 is more limited. It is possible to display , therefore an Amstrad conversion of a Spectrum game is normally 2 colours.

- ## Other points

  If the screen is static (it is not scrolled using the hardware) then some of the screen memory is invisible. Therefore it is possible to use these areas to store program code and data.

  Calculating the invisible regions:

  Screen properties:

  - 32 CRTC characters in width,
  - 24 CRTC characters in height,
  - 8 CRTC raster lines per CRTC character,
  - 2 bytes per CRTC character.

  There are 2 bytes per CRTC character. The first scan-line for each CRTC character follows on from each other: i.e. Character line 1, raster line 1: offset 0-63, Character line 1, raster line 2: offset 2048-2111 Character line 2, raster line 1: offset 64-127, 64*24 = 1536 2048 - 1536 = 512 bytes free