Prints a ROM character on a given byte-aligned position on the screen in Mode 2 (640x200 px, 2 colours).

C Definition

void cpct_drawCharM2 (void* video_memory, u8 pen, u8 ascii)

Input Parameters (4 Bytes)

(2B DE) video_memoryVideo memory location where the character will be drawn
(1B C ) penColour configuration (!=0 Normal / =0 Inverted)
(1B B ) asciiCharacter to be printed (ASCII code)

Assembly call (Input parameters on registers)

call cpct_drawCharM2_asm

Parameter Restrictions

  • video_memory could theoretically be any 16-bit memory location.  It will work outside current screen memory boundaries, which is useful if you use any kind of double buffer.  However, be careful where you use it, as it does no kind of check or clipping, and it could overwrite data if you select a wrong place to draw.
  • pen 0 = Inverted, >0 = Normal.  Normal means foreground colour = PEN 1, background colour = PEN 0.  Inverted means the contrary of normal.
  • ascii could be any 8-bit value, as 256 characters are available in ROM.

Requirements and limitations

  • Do not put this function’s code below 0x4000 in memory.  In order to read characters from ROM, this function enables Lower ROM (which is located 0x0000-0x3FFF), so CPU would read code from ROM instead of RAM in first bank, effectively shadowing this piece of code.  This would lead to undefined results (typically program would hang or crash).
  • Screen must be configured in Mode 2 (640x200 px, 2 colours)
  • This function requires the CPC firmware to be DISABLED.  Otherwise, random crashes might happen due to side effects.
  • This function disables interrupts during main loop (character printing), and re-enables them at the end.
  • This function will not work from ROM, as it uses self-modifying code.


This function reads a character from ROM and draws it at a given byte-aligned video memory location, that corresponds to the upper-left corner of the character.  As this function assumes screen is configured for Mode 2 (640x200, 2 colours), it means that the character can only be drawn at module-8 pixel columns (0, 8, 16, 24...), because each byte contains 8 pixels in Mode 2.  It can print the character in 2 different colour configurations: Normal - PEN 1 over PEN 0 (pen > 0) Inverted - PEN 0 over PEN 1 (pen = 0)

Destroyed Register values


Required memory

76 bytes

Time Measures

  Case     | Cycles | microSecs (us)
  Best     |   759  |   189.75
  Worst    |   803  |   200.75
Asm saving |   -63  |   -15.75
Prints a ROM character on a given byte-aligned position on the screen in Mode 2 (640x200 px, 2 colours).
unsigned char (u8 = unsigned 8-bits, 1 byte )