-
Notifications
You must be signed in to change notification settings - Fork 0
Screen Buffer
BuildScreenBuffer
This function serves to allocate in the heap (part of memory out of code and data segment), a virtual video memory, the screen buffer. Each time we need to display something, we write in this screen buffer, as if it were the video memory, and once all the modification of the loop are done , we update the real display by copying quickly the screen buffer into the video memory, for each frame.
This function needs to define a bss variable ('ScreenBufferSegment resw 1') to store the adress' segment of the screen buffer. This function needs to include the Heap Library. After this function had beeen executed, at the very beginning, the segment new destination to display something is not 0xA000 anymore, but '[ScreenBufferSegment]'.
This function doesn't return anything. Even if this function overwrite ax and bx, as it is called at the very beginning, it doesn't matter at all.
An example were we display something (black color on all the screen)
ClearScreen:
;clear the screen by filling it with a unique color (stored in al)
;set the source 'al'
mov al, 0x00 ; color to fill the screen
;set the destination 'es:di' :
push word [ScreenBufferSegment] ; segment destination
pop es
mov di, 0 ; begin the offset (pixel position) at 0
mov cx, SCREEN_WIDTH*SCREEN_HEIGHT
rep stosb
ret
And then, to update the screen, you just call the function 'UpdateScreen'
Call this function once , before dispalying anything.
None
call SetVideoMode call BuildScreenBuffer call ClearScreen -> modify the value of 'al' to have a special color call UpdateScreen
if you see the screen filed by this special color : you used well the screen buffer, which had been well built.
None
@benoitdekeyn , developper