cpct_setVideoMemoryPage

Sets the 6 most significant bits (the page) of the memory address where video memory starts.

C Definition

void cpct_setVideoMemoryPage (u8 page_6LSb);

Input Parameters (4 bytes)

(1B L) page_6LSbNew starting page for Video Memory (Only 6 Least Significant bits are used)

Assembly call (Input parameters on registers)

call cpct_setVideoMemoryPage_asm

Parameter Restrictions

  • page_6LSb should contain video memory page value encoded in its 6 Least Significant bits (LSb).  This parameter must be in the range [0-63] as only its 6 LSb must be used.  These 6 bits will become the 6 Most significant bits (MSb) of the video memory start address (its page).  So, for instance, if page_6LSb = 00101000, then video memory will start at address 101000xxxxxxxx00, being xxxxxx = the offset (consult cpct_setVideoMemoryOffset for more details).

Details

Changes the place where the video memory starts.  Concretely, it changes de Video Memory Page, which corresponds to the 6 Most significant bits (MSb) of the memory address where video memory starts.  By doing this, you are effectively changing what part of the 64K of RAM will be used as Video Memory and, therefore, what is to be displayed on screen.  With this you can affectively implement and triple buffer using hardware instead of software (i.e. copying bytes).

This routine achieves this by changing Register R12 from CRTC.  This register is the responsible for holding the 6 MSb of the place where Video Memory starts (its page).  However, this register stores this 6 bits as its 6 LSb (--bbbbbb).  We have to take this into account to correctly set the page we want.

To better explain this, lets show an example,

1You want your Video Memory to start at 0x8000, instead of 0xC000
2Then, you should set Video Memory Page to 0x80 (10000000)
3You call this routine with 0x20 as parameter (00100000)
4Note that 0x20 (00100000) is 0x80 (10000000) shifted twice to the right.  Your 6 MSb are to be passed as the 6 LSb of the page parameter.

In order to make this process easier, you may use predefined constants to set the most typical video memory pages:

      Page | Memory Start | constant to use | value
     ------------------------------------------------
      0xC0 |    0xC000    |  cpct_pageC0    |  0x30
      0x80 |    0x8000    |  cpct_page80    |  0x20
      0x40 |    0x4000    |  cpct_page40    |  0x10
      0x00 |    0x0000    |  cpct_page00    |  0x00
     ------------------------------------------------
Table 1. Useful constants for setting video memory pages

If you wanted to set a more specific video memory page, you can calculate it by hand, or use cpct_memPage6 macro.  With this macro, you specify the page you want, and you get the page_6LSb parameter you should pass to this function.  For instance, imagine you want to use 0x84 as your video memory page (and 0x8400 will be the starting point of video memory), you could do it this way:

...
i8 page = cpct_memPage6(0x84);   // Transform page into 6LSb parameter
cpct_setVideoMemoryPage(page);   // ... and use it to set the Video Memory page
...

Destroyed Register values

F, BC, HL

Required memory

9 bytes

Time Measures

   Case    |  microSecs (us) | CPU Cycles
-------------------------------------------
    Any    |   15            |    60
-------------------------------------------
Sets the 6 most significant bits (the page) of the memory address where video memory starts.
unsigned char (u8 = unsigned 8-bits, 1 byte )
Sets the 8 Least Significant bits (the offset) of the memory address where video memory starts.
Macro that encodes a video memory page in the 6 Least Significant bits (LSb) of a byte, required as parameter for cpct_setVideoMemoryPage
Close