cpct_px2byteM0

Transforms 2 pixel colour values [0-15] into a byte value in the video memory pixel format for Mode 0.

C Definition

u8 cpct_px2byteM0 (u8 px0, u8 px1);

Input Parameters (2 Bytes)

(1B H) px0Firmware colour value for left pixel (pixel 0) [0-15]
(1B L) px1Firmware colour value for right pixel (pixel 1) [0-15]

Returns

u8byte with px0 and px1 colour information in screen pixel format.

Assembly call

call cpct_px2byteM0_asm

Parameter Restrictions

  • px0 and px1 must be firmware colour values in the range [0-15].  If any of them is greater than 15, unexpected colours may appear on screen.  px0 and px1 are used as indexes in a colour conversion table, and values greater than 15 would point outside the table, getting random memory values, which will lead to random colours on screen.

Details

Converts 2 firmware colour values for 2 consecutive pixels into a byte value in the video memory pixel format for Mode 0.  This video memory pixel format is the way pixel colour values are encoded in video memory.  Concretely, in Mode 0, each byte contains 2 consecutive pixels formatted as follows:

______________________________________________________________________
                      <---- 1  byte ---->
Screen         => [...[pixelX ][ pixelY ]...] (2 pixels, consecutive)
======================================================================
Video Memory   => [...[ X Y X Y X Y X Y ]...] (1  byte, 8 bits)
Pixel X (3210) => [...[ 0 · 2 · 1 · 3 · ]...] (4  bits)
Pixel Y (dcba) => [...[ · a · c · b · d ]...] (4  bits)
----------------------------------------------------------------------
      Scheme 1. Screen pixel format and video memory

This function uses a 16-byte conversion table to get screen formatted values for each one of the two pixels given.  These formatted values are then OR’ed to get the final byte that you may use to draw on screen.

Destroyed Register values

AF, BC, DE, HL

Required memory

C-bindings47 bytes (31 bytes code, 16 bytes colour conversion table)
ASM-bindings42 bytes (26 bytes code, 16 bytes colour conversion table)
NoteColour conversion table is shared with cpct_drawCharM0.  If you use both functions, only one copy of the colour table is loaded into memory.

Time Measures

Case       | microSecs (us) |  CPU Cycles
------------------------------------------
Any        |      40        |     160
------------------------------------------
ASM-saving |     -11        |     -44
------------------------------------------

NC=Number of colours to convert

unsigned char (u8 = unsigned 8-bits, 1 byte )
Transforms 2 pixel colour values [0-15] into a byte value in the video memory pixel format for Mode 0.
Prints a ROM character on a given even-pixel position (byte-aligned) on the screen in Mode 0 (160x200 px, 16 colours).
Close