-
Notifications
You must be signed in to change notification settings - Fork 0
Screen Buffer
BuildScreenBuffer
This function uses heap memory allocation which enables the creation of a screen buffer. This screen buffer can be assimilated to a virtual video memory copy. (The heap is a part of memory out of code and data segment which is on top of the stack).
This is used as a pre-version of the video memory, we write all the data in the screen buffer. Once all the data has been included in the screen buffer, we copy its content to the video memory. This content copy is done once for each frame.
The data opbjects contained in the screen buffer are the following:
- Background buffer content
- Maze layout
- Pellets
- Ghosts and Pac-Man
- Score, Lives & Non-related gameplay elements
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. This function needs to be executed at the very beginning. After its execution, the new destination to display something is no more at the adress segment 0xA000, but instead is now at the '[ScreenBufferSegment]'.
This function doesn't return anything. Even if this function overwrites 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.
call SetVideoMode call BuildScreenBuffer call ClearScreen -> modify the value of 'al' to have a special color call UpdateScreen
If you see the screen filled by the provided color, you used well the screen buffer and there are no bugs.
Benoît DE KEYN