cpct_drawTileGrayCode2x8_af

Copies a 2x8-byte sprite to video memory (or screen buffer), assuming that the sprite lines are grey-code ordered and the location to be copied is Pixel Line 0 of a character line.

C Definition

void cpct_drawTileGrayCode2x8_af (void* pvideomem, void* sprite) __z88dk_callee;

Input Parameters (4 bytes)

(2B HL) sprite endPointer to the end of the sprite array (Sprite in Gray Code format)
(2B DE) pvideomemPointer (aligned) to the first byte in video memory where the sprite will be copied.

Assembly call (Input parameters on registers)

call cpct_drawTileGrayCode2x8_af_asm

Parameter Restrictions

  • sprite must be a pointer to the last byte of an array containing sprite’s pixels data in screen pixel format, and in graycode line order.  Sprite must be rectangular.  Total amount of bytes in pixel array should be 16.  You may check screen pixel format for mode 0 (cpct_px2byteM0) and mode 1 (cpct_px2byteM1) as for mode 2 is linear (1 bit = 1 pixel).  Line order will be 0-1-3-2-6-7-5-4, meaning that the first 2 bytes will contain the pixel values for screen line 0 and last 2 bytes pixel values for screen line 4.  For clarity, if we consider the 16 bytes of the sprite, their order in the given array must be:
BYTE: [0,1,2,3,6,7,4,5,12,13,14,15,10,11,8,9]
       --- --- --- --- ----- ----- ----- ---
LINE:   0   1   3   2    6     7     5    4
  • memory must be a pointer to the first byte in video memory (or screen buffer) where the sprite will be drawn.  This location must be aligned, meaning that it must be a Pixel Line 0 of a screen character line.  To Know more about pixel lines and character lines on screen, take a look at cpct_drawSprite.  If memory points to a not aligned byte (one pertaining to a Non-0 Pixel Line of a character line), this function will overwrite random parts of the memory, with unexpected results (typically, bad drawing results, erratic program behaviour, hangs and crashes).

Known limitations

  • This function does not do any kind of boundary check or clipping.  If you try to draw sprites on the frontier of your video memory or screen buffer if might potentially overwrite memory locations beyond boundaries.  This could cause your program to behave erratically, hang or crash.  Always take the necessary steps to guarantee that you are drawing inside screen or buffer boundaries.
  • As this function receives a byte-pointer to memory, it can only draw byte-sized and byte-aligned sprites.  This means that the sprite cannot start on non-byte aligned pixels (like odd-pixels, for instance) and their sizes must be a multiple of a byte (2 in mode 0, 4 in mode 1 and 8 in mode 2).

Details

This function does the same as cpct_drawTileAligned2x8_f, but using a Gray Code Line Order for the screen lines (0-1-3-2-6-7-5-4), and getting bytes from memory in pairs, using POP instruction.

Copies a 2x8-byte sprite from an array with 16 screen pixel format bytes, and Grey Code Line Order (0-1-3-2-6-7-5-4) to video memory or a screen buffer.  This function is tagged aligned, meaning that the destination byte must be character aligned.  Being character aligned means that the 8 lines of the sprite will coincide with the 8 lines of a character line in video memory (or in the screen buffer).  For more details about video memory character and pixel lines check table 1 at cpct_drawSprite.

As the 8 lines of the sprite must go to a character line on video memory (or screen buffer), memory destination pointer must point to a the first line (Pixel Line 0) of a character line.  If hardware scrolling has not been used, all pixel lines 0 are contained inside one of these 4 ranges:

[ 0xC000 -- 0xC7FF ]RAM Bank 3 (Default Video Memory Bank)
[ 0x8000 -- 0x87FF ]RAM Bank 2
[ 0x4000 -- 0x47FF ]RAM Bank 1
[ 0x0000 -- 0x07FF ]RAM Bank 0

All of them have 3 bits in common: bits 5, 4 and 3 are always 0 (--000---).  Any address not having all these 3 bits set to 0 does not refer to a Pixel Line 0 and is not considered to be aligned.

This function will just copy bytes, not taking care of colours or transparencies.  If you wanted to copy a sprite without erasing the background just check for masked sprites and <cpct_drawMaskedSprite>.

Destroyed Register values

HL, DE, F

Interrupts

  • Disables interrupts when called.
  • Enables interrupts before returning.
  • Uses SP register and POP to read from memory.

Required memory

C-bindings61 bytes
ASM-bindings58 bytes

Time Measures

   Case    | microSecs (us) | CPU Cycles
------------------------------------------
   Any     |      103       |    412
------------------------------------------
Asm saving |      -12       |    -48
------------------------------------------
Copies a 2x8-byte sprite to video memory (or screen buffer), assuming that the sprite lines are grey-code ordered and the location to be copied is Pixel Line 0 of a character line.
Transforms 2 pixel colour values [0-15] into a byte value in the video memory pixel format for Mode 0.
Transforms 4 pixel colour values [0-3] into a byte value in the video memory pixel format for Mode 1.
Copies a sprite from an array to video memory (or to a screen buffer).
Copies a 2x8-byte sprite to video memory (or screen buffer), assuming that location to be copied is Pixel Line 0 of a character line.
Close