Prints a ROM character on a given even-pixel position (byte-aligned) on the screen in Mode 0 (160x200 px, 16 colours).
C Definition
void cpct_drawCharM0 (void* video_memory, u8 fg_pen, u8 bg_pen, u8 ascii)
Input Parameters (5 Bytes)
(2B DE) video_memory | Video memory location where the character will be drawn |
(1B C ) fg_pen | Foreground palette colour index (Similar to BASIC’s PEN, 0-15) |
(1B B ) bg_pen | Background palette colour index (PEN, 0-15) |
(1B A ) ascii | Character to be drawn (ASCII code) |
Assembly call (Input parameters on registers)
call cpct_drawCharM0_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.
- fg_pen must be in the range [0-15]. It is used to access a colour mask table and, so, a value greater than 15 will return a random colour mask giving unpredictable results (typically bad character rendering, with odd colour bars).
- bg_pen must be in the range [0-15], with identical reasons to fg_pen.
- 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 0 (160x200 px, 16 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.
Details
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 0 (160x200, 16 colours), it means that the character can only be drawn at even pixel columns (0, 2, 4, 8...), because each byte contains 2 pixels in Mode 0. It prints the character in 2 colours (PENs) one for foreground (fg_pen), and the other for background (bg_pen).
Destroyed Register values
AF, BC, DE, HL
Required memory
157 bytes (16 bytes conversion table, 141 bytes code)
Time Measures
Case | Cycles | microSecs (us)
--------------------------------
Best | 3730 | 932.50
Worst | 4410 | 1102.50
--------------------------------
Asm saving | -80 | -20
--------------------------------