-
Notifications
You must be signed in to change notification settings - Fork 0
Background Buffer
BackgroundBufferSegment
This function uses heap memory allocation which enables the creation of a background buffer. This background buffer can be assimilated to a virtual video memory. (The heap is a part of memory out of code and data segment which is on top of the stack). The background buffer stores an editable copy of the background.
The background contains:
- The maze layout
- The pellets & power pellets which can be dynamically updated and removed
This can be considered as a sub-layer of the screen buffer. Each time we need to restore the background after the passage of a ghost, we read in this buffer to overwrite the ghost with the right background.
This function needs to define a bss variable ('BackgroundBufferSegment resw 1') to store the adress' segment of the background buffer. This function needs to include the heap library.
This function doesn't return anything. Even if this function overwrite ax and bx, as it is called at the very beginning, just after the building of the screen buffer, it doesn't matter at all.
An example where we clear a ghost , reading the background buffer
;need to define the y position in ax, and x position in bx
ClearSprite:
; calculate the adress (offset) of the first pixel
mov cx, SCREEN_WIDTH
mul cx
add bx, ax
;set the destination 'es:di' as SreenBuffer:offsetOfTheFirstPixel
push word [ScreenBufferSegment]
pop es
mov di, bx
;set the source 'ds:si' as BackgroundBuffer:offsetOfTheFirstPixel
push word [BackgroundBufferSegment]; load the effective adress (L.E.A.) of the backup in the destination offset
pop ds
mov si, di
;using source and destination, copy the data on a 8x8 bits square :
mov dx, SPRITE_SIZE
.eachLine:
mov cx, SPRITE_SIZE
rep movsb
add di, SCREEN_WIDTH - SPRITE_SIZE
dec dx ; decrementatin de dx, when it reach 0, the flag is 0 too cause of the dec propreties
jnz .eachLine ; while the flag != 0, it continues
;restore the value of 'ds' to don't disturb the rest of the code
push cs
pop ds
ret
You only need to call this function once at the beginning of the program. This function is also needed to clear the ghosts in the rest of the program.
call SetVideoMode call BuildScreenBuffer call BuildBackgroundBuffer call FirstDispalyPacMan call UpdateScreen mov word [x_PinkyPosition], 45 -> change this value to test mov word [y_PinkyPosition], 23 -> change this value to test mov word [frameOf_Pinky], PINKY_1 mov word [frameOf_Pinky_eyes], EYES_RIGHT call Display_Pinky mov ax, [y_PinkyPosition] mov bx, [x_PinkyPosition] call ClearSprite
If there is no Pinky on the screen : you used well the background buffer (so, well built) to restore the background on Pinky.
Benoît DE KEYN