Hello.
muazzam wrote:I had implemented scroll down it was very slow I tried double buffering but nothing significant happened (even get worse). Now I have implemented SSE, It gives reasonable performance in other emulators except Bochs. It improves the performance a little bit in Bochs. Now what should I do?
2. Should I use function 7 of VBE?
Yes, i think to set the display start address and writing new lines into the hidden buffer outside the visible view is faster than to copy the lines from and to inside the visible view.
vbe3.pdf (vesa.org)
Page 50 VBE CORE FUNCTIONS VERSION 3.0
Function 07h - Set/Get Display Start
Input: AX = 4F07h VBE Set/Get Display Start Control
(16-bit) BH = 00h Reserved and must be 00h
BL = 00h Set Display Start
= 01h Get Display Start
= 02h Schedule Display Start (Alternate)
= 03h Schedule Stereoscopic Display Start
= 04h Get Scheduled Display Start Status
= 05h Enable Stereoscopic Mode
= 06h Disable Stereoscopic Mode
= 80h Set Display Start during Vertical Retrace
= 82h Set Display Start during Vertical Retrace (Alternate)
= 83h Set Stereoscopic Display Start during Vertical Retrace
ECX = If BL=02h/82h Display Start Address in bytes
If BL=03h/83h Left Image Start Address in bytes
EDX = If BL=03h/83h Right Image Start Address in bytes
CX = If BL=00h/80h First Displayed Pixel In Scan Line
DX = If BL=00h/80h First Displayed Scan Line
Output: AX = VBE Return Status
BH = If BL=01h Reserved and will be 0
CX = If BL=01h First Displayed Pixel In Scan Line
If BL=04h 0 if flip has not occurred, not 0 if it has
DX = If BL=01h First Displayed Scan Line
Input: BH = 00h Reserved and must be 00h
(32-bit) BL = 00h Set Display Start
= 80h Set Display Start during Vertical Retrace
CX = Bits 0-15 of display start address
DX = Bits 16-31 of display start address
ES = Selector for memory mapped registers
This required function selects the pixel to be displayed in the upper left corner of the
display. This function can be used to pan and scroll around logical screens that are larger than the
displayed screen. This function can also be used to rapidly switch between two different
displayed screens for double buffered animation effects.
For the VBE 2.0 32-bit protected mode version, the value passed in DX:CX is the 32
bit offset in display memory, aligned to a plane boundary. For planar modes this means the value
is the byte offset in memory, but in 8+ bits per pixel modes this is the offset from the start of
memory divided by 4. Hence the value passed in is identical to the value that would be programmed
into the standard VGA CRTC start address register.
Note that it is up to the protected mode application to keep track of the color depth and scan line length to calculate the new start address. If a value that is out of range is programmed, unpredictable results will occur. For VBE 3.0 the
application.VBE Function Reference VBE CORE FUNCTIONS VERSION 3.0 Page 51
program may optionally pass the missing two bits of information in the top two bits of DX, to allow for pixel perfect horizontal panning.
For example (32-bit protected mode interface only): in planar modes:
CX[15:0] = SA[15:0]
DX[15:0] = SA[31:16]
in 8bpp and greater modes:
CX[15:0] = SA[17:2]
DX[13:0] = SA[31:18]
DX[15:14] = SA[1:0]
VBE 3.0 defines seven new subfunctions (02h, 03h, 04h, 05h, 06h, 82h, 83h) to
support hardware triple buffering and stereoscopic LC shutter glasses. Functions 02h and 03h schedule
a display start address change to occur during the next vertical retrace, and returns immediately.
Function 04h can then be used by the application to determine if the scheduled flip has
occurred or not, which can be used for hardware triple buffering to avoid writing to the page being
displayed by the CRT controller. Functions 04h and 05h are used to enable and disable free running
hardware stereoscopic mode. Functions 82h and 83h schedule the display start address change
to occur, and then wait until the address has changed before returning.
Note that functions 02h, 03h, 82h and 83h take the display start address as a byte
offset in video memory, whereas the VBE 1.2 compatible functions 00h and 80h take an (x,y) pixel
coordinate as the starting address in the frame buffer. Functions 02h and 82h are preferable because
they allow for correct page flipping operation in all color depths. Functions 00h and 80h have
problems in 24bpp modes where each pixel is represented as three bytes, since there are some
combinations of (x,y) starting addresses that may not map
For stereoscopic LC shutter glasses support, the hardware must provide support for
free running stereoscopic display with the left and right images located consecutively in video
memory, or provide support for dual display start addresses that will be swapped on every vertical
retrace interval. On all VBE 3.0 implementation that support hardware stereoscopic display,
applications can enable free running stereoscopic display by calling function 05h and the hardware
will remain in free running stereoscopic display until the application calls function 06h. When
function 05h is called, free running stereoscopic display is enabled with the left buffer located first in
video memory and the right buffer located immediately following the left buffer in video
memory and the hardware will swap between the two images at each vertical retrace in a sequential
fashion (ie:left, right, left, right etc). By default when a mode is initialized, free running
stereoscopic display is turned off.
For VBE implementations that support dual display start address hardware (VBE
mode information ModeAttributes bit 12 is set), the VBE implementation should enable the
stereoscopic display start addressing when the application calls either function 03h or
function 83h and it will remain in free running stereoscopic display until the application calls
function 06h.VBE Overview Page 52 VBE CORE FUNCTIONS VERSION 3.0
to disable stereoscopic display. The main difference with this method of stereoscopic
display is that the application has complete control over where the buffers are located in video
memory, and two display starting addresses are passed into functions 03h/83h for the complete
change.
Note also that the Display Start Address passed for subfunctions 02h, 03h, 82h and
83h are defined as a byte address in video memory rather than as a pixel coordinate. This is in
contrast to the values passed to the 32-bit version which is a byte address divided by 4, and
allows for controllers that can perform hardware scrolling to a byte boundary for pixel perfect
horizontal scrolling.
VBE Implementation Note: If the hardware does not support free running
stereoscopic page flipping, the VBE implementation should fail functions 03h, 05h, 06h and 83h. If the
hardware does not support dual display start addressing, but does support hardware stereoscopic
display with consecutive images in video memory, the implementation should fail functions
03h and 83h but support 05h and 06h. If the hardware does not support the returning of status
information for the scheduled display start address swap, the VBE implementation should fail
function 04h, however it should still implement functions 02h, 03h, 82h and 83h to provide support
for pixel perfect smooth scrolling.
Note: In VBE 2.0 and later implementations the 32-bit version returns no Return
Status information to the application. Also note that the ES selector only needs to be passed
if the memory location in the Ports and Memory table returned by function 4F0Ah is not
defined.
Note: This function is also valid in text modes. To use this function in text mode, the
application should convert the character coordinates to pixel coordinates by using XCharSize and
YCharSize returned in the ModeInfoBlock. If the requested Display Start coordinates
do not allow for a full page of video memory or the hardware does not support memory
wrapping, the Function call should fail and no changes should be made. As a general
case, if a requested Display Start is not available, fail the Function call and make no
changes.
Note: CX and DX, for both input and output values are zero-based.
Note: Subfunction 01h (Get Display Start) is not supported via the VBE 3.0 protected
mode entry point, and the results are undefined if it is called..VBE Function Reference
3. Should I use triple buffer (I think not)?
I think it is more usefull for to move large objects across the screen for to prevent flickering.
VBE CORE FUNCTIONS VERSION 3.0 Page 9
Using Hardware Triple Buffering
Hardware triple buffering is supported in the VBE/Core specification by allowing the
application to schedule a display start address change, and then providing a function that can be
called to determine the status of the last scheduled display start address change. VBE Function
4F07h is used for this, along with subfunctions 02h and 04h. To implement hardware triple
buffering you would use the following steps:
1. Display from the first visible buffer, and render to the second hidden buffer.
2. Schedule a display start address change for the second hidden buffer that you just
finished rendering (4F07h, 02h), and start rendering immediately to the third hidden
buffer. CRT controller is currently displaying from the first buffer.
3. Before scheduling the display start address change for the third hidden buffer, wait
until the last scheduled change has occurred (4F07h, 04h returns not 0). Schedule
display start address change for the third hidden buffer and immediately begin
rendering to the first hidden buffer. CRT controller is currently displaying from the
second buffer.
4. Repeat step 3 over and over cycling though each of the buffers.
Although the above method does require a spin loop polling on Function 4F07h/04h,
in most cases when this function is called the display start address change will already have
occurred and the spin loop will time out immediately. The only time that this cannot occur is if the
application is rendering at a frame rate in excess of the current hardware refresh rate (i.e.: in excess
of 60-70 frames per second), and the resulting frame rate for the application will be pegged at
the hardware refresh rate.
Dirk