Sets the 6 most significant bits (the page) of the memory address where video memory starts.
void cpct_setVideoMemoryPage (u8 page_6LSb);
(1B L) page_6LSb | New starting page for Video Memory (Only 6 Least Significant bits are used) |
call cpct_setVideoMemoryPage_asm
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,
1 | You want your Video Memory to start at 0x8000, instead of 0xC000 |
2 | Then, you should set Video Memory Page to 0x80 (10000000) |
3 | You call this routine with 0x20 as parameter (00100000) |
4 | Note 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 ...
F, BC, HL
9 bytes
Case | microSecs (us) | CPU Cycles ------------------------------------------- Any | 15 | 60 -------------------------------------------