# cpct_px2byteM1

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

#### C Definition

u8 cpct_px2byteM1 (u8 px0, u8 px1, u8 px2, u8 px3);

#### Input Parameters (2 Bytes)

(1B _) px0 | Firmware colour value for left pixel (pixel 0) [0-3]
(1B _) px1 | Firmware colour value for center-left pixel (pixel 1) [0-3]
(1B _) px2 | Firmware colour value for center-right pixel (pixel 2) [0-3]
(1B _) px3 | Firmware colour value for right pixel (pixel 3) [0-3]

#### Returns

u8 | byte with px0, px1, px2 and px3 colour information in screen pixel format.

#### Assembly call

This function does not have assembly entry point. You should use C entry point and put parameters on the stack, this way:

>     ld   bc, #0x0103      ;; B = *px1* = 1, C = *px0* = 3 (Firmware colours)
>     ld   de, #0x0200      ;; D = *px3* = 2, E = *px2* = 0 (Firmware colours)
>     push de               ;; Put parameters on the stack (in reverse order, always)
>     push bc               ;;
>     call _cpct_px2byteM1  ;; Call the function on the C entry point
>     pop  bc               ;; Recover parameters from stack to leave it at its previous state
>     pop  de               ;;

#### Parameter Restrictions

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

#### Details

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

>     ___________________________________________________________________________________
>                           <----------- 1 byte ----------->
>     Screen         => [...[pixelA][pixelB][pixelC][pixelD]...] (4 pixels, consecutive)
>     ===================================================================================
>     Video Memory   => [...[  A   B  C  D   A  B  C   D   ]...] (1  byte, 8 bits)
>     Pixel A   (10) => [...[  0   ·  ·  ·   1  ·  ·   ·   ]...] (2  bits)
>     Pixel B   (32) => [...[  ·   2  ·  ·   ·  3  ·   ·   ]...] (2  bits)
>     Pixel C   (54) => [...[  ·   ·  4  ·   ·  ·  5   ·   ]...] (2  bits)
>     Pixel D   (76) => [...[  ·   ·  ·  6   ·  ·  ·   7   ]...] (2  bits)
>     -----------------------------------------------------------------------------------
>                 Scheme 1. Screen pixel format and video memory

This function uses a 4-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

29 bytes (25 bytes code, 4 bytes colour conversion table)

Note | Colour conversion table is shared with cpct_drawCharM1. If you use both functions, only one copy of the colour table is loaded into memory.

#### Time Measures

>     Case  | microSecs (us) | CPU Cycles
>     ------------------------------------
>     Any   |      96        |   384
>     ------------------------------------

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