Transforms 4 pixel colour values [0-3] into a byte value in the video memory pixel format for Mode 1.
u8 cpct_px2byteM1 (u8 px0, u8 px1, u8 px2, u8 px3);
(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] |
u8 | byte with px0, px1, px2 and px3 colour information in screen pixel format. |
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 ;;
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.
AF, BC, DE, HL
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. |
Case | microSecs (us) | CPU Cycles ------------------------------------ Any | 96 | 384 ------------------------------------