cpct_setVideoMemoryOffset

Sets the 8 Least Significant bits (the offset) of the memory address where video memory starts.

C Definition

void cpct_setVideoMemoryOffset (u8 offset)

Input Parameters (4 bytes)

(1B L) offsetNew starting offset for Video Memory (8 Least Significant bits)

Assembly call (Input parameters on registers)

call cpct_setVideoMemoryOffset_asm

Parameter Restrictions

  • offset could be any 8-bit value, and should contain video memory offset value.  Its 8-bits will become the 8 Least Significant bits (LSb) of the programmable Video Memory Start Address (VMSA), as the 2 least significant bits of the address are always set to 0 (see figure 1).  For instance, an offset value of 10101011 will set the VMSA to xxxxxx1010101100, being xxxxxx the previous value of VMSA page.  Consult cpct_setVideoMemoryPage for more details on this.

Details

Changes part of the address where video memory starts (Video Memory Start Address, VMSA).  Video memory starts at an address that can be defined in binary as follows:

--------------------------------------------------------
           VMSA = [ ppppppoooooooo00 ]
--------------------------------------------------------
Figure 1 - Video Memory Start Address (VMSA) composition

where you have 6 bits that define the Page (p-bits), and 8 bits that define the offset (o-bits).  The 2 Least Significant Bits (LSb) are always set to 0.

This function changes the 8 bits that define the offset (the o-bits).  These 8 bits are controlled by Register R13 from the CRTC.  If you wanted to change the 6 Most Significant bits (the page), you should use cpct_setVideoMemoryPage

Changing the offset effectively changes the place where your video memory starts in your system RAM, immediately changing what is displayed on screen.  This could be used to produce scrolling effects or to make a fine grained control of double / triple buffers by hardware.

To better explain this, lets show an example,

1You want your VMSA at 0xC0A0, instead of 0xC000
20xC0A0 corresponds to page = 0x30, offset = 0xA0 (check Figure 1)
3Page 0x30 is set by default (memory address starts at 0xC000 at power on)
4You only have to call cpct_setVideoMemoryOffset(0xA0)

Another example, requiring page and offset to be set, could be the next one.  Imagine you have a double buffer starting at memory address 0x801A and you wanted to make it visible on screen.  Your code to do that could be like this:

...
cpct_setVideoMemoryPage(cpct_page80);  // Set page   0x80
cpct_setVideoMemoryOffset(0x1A);       // Set offset 0x1A
...

When creating hardware back buffers, always take into account that video memory is never considered linear by Gate Array.  This means that, wherever you put your VMSA, it will be considered the start of a Video Memory made of 8-pixel-line characters.  Consult cpct_drawSprite for more details on how video memory is distributed at its default place (it will be distributed similarly at every place it were located).

Destroyed Register values

F, BC, HL

Required memory

9 bytes

Time Measures

   Case    | microSecs (us) | CPU Cycles
-----------------------------------------
    Any    |     15         |    60
-----------------------------------------
Sets the 8 Least Significant bits (the offset) of the memory address where video memory starts.
unsigned char (u8 = unsigned 8-bits, 1 byte )
Sets the 6 most significant bits (the page) of the memory address where video memory starts.
Copies a sprite from an array to video memory (or to a screen buffer).
Close