-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdblbuf.asm
149 lines (131 loc) · 3.92 KB
/
dblbuf.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
;===================================================================================================
; Double Buffering
;
; Written By: Oded Cnaan (oded.8bit@gmail.com)
; Site: http://odedc.net
; Licence: GPLv3 (see LICENSE file)
; Package: GrLib
;
; Description:
; Double buffering implementation
;===================================================================================================
LOCALS @@
DATASEG
_DblBufferSeg dw 0
_IsDblBuffer db FALSE
CODESEG
;------------------------------------------------------------------------
; MACRO Description: Sets whether we use double buffering
;
; Input:
; state - TRUE or FALSE
;------------------------------------------------------------------------
MACRO SetDoubleBuffering state
mov [_IsDblBuffer], state
ENDM
;------------------------------------------------------------------------
; MACRO Description: saves double buffering segment
;
; Input:
; seg - the segment
;------------------------------------------------------------------------
MACRO SetDoubleBufferSeg seg
mov [_DblBufferSeg], seg
ENDM
;------------------------------------------------------------------------
; MACRO Description: Gets double buffering segment into a register
;
; Input:
; reg - register
;------------------------------------------------------------------------
MACRO GetDblBufferSeg reg
push [_DblBufferSeg]
pop reg
ENDM
;------------------------------------------------------------------------
; MACRO Description: Is using double buffering
;
; Input:
; jmpIfTrue - label to jump to in case NOT using double buffering
;------------------------------------------------------------------------
MACRO IsDblBuffering jmpIfFalse
cmp [_IsDblBuffer], FALSE
je jmpIfFalse
ENDM
;------------------------------------------------------------------------
; PROC Description: Allocate double buffer for VGA mode 320x200x256
; and clears the buffer (black)
;
; Assuming FreeProgramMem was already called
;------------------------------------------------------------------------
PROC AllocateDblBuffer
store_sp_bp
push ax bx
mov bx, VGA_SCREEN_WIDTH * VGA_SCREEN_HEIGHT
shr bx,4 ; bx/16
push bx
call malloc
cmp ax, 0
jz @@end
SetDoubleBufferSeg ax
SetDoubleBuffering TRUE
call ClearDblBuffer
@@end:
pop bx ax
restore_sp_bp
ret
ENDP AllocateDblBuffer
;------------------------------------------------------------------------
; PROC Description: Releases the buffer and stops double buffering
;------------------------------------------------------------------------
PROC ReleaseDblBuffer
store_sp_bp
push ax es
IsDblBuffering @@end
SetDoubleBuffering FALSE
GetDblBufferSeg ax
push ax
call mfree
@@end:
pop es ax
restore_sp_bp
ret
ENDP ReleaseDblBuffer
;------------------------------------------------------------------------
; PROC Description: clears entire double buffer
;------------------------------------------------------------------------
PROC ClearDblBuffer
store_sp_bp
push ax es di cx
IsDblBuffering @@end
GetDblBufferSeg es
xor di,di
xor ax,ax
mov ax,0
mov cx,VGA_SCREEN_WIDTH * VGA_SCREEN_HEIGHT
rep stosb ; Store AL at address ES:DI
@@end:
pop cx di es ax
restore_sp_bp
ret
ENDP ClearDblBuffer
;------------------------------------------------------------------------
; PROC Description: Copy double buffer to video memory (VGA)
;------------------------------------------------------------------------
PROC CopyDblBufToVideo
store_sp_bp
push si di cx es ds
IsDblBuffering @@end
mov cx, [GR_START_ADDR]
mov es, cx
GetDblBufferSeg ds
xor si,si
xor di,di
mov cx, VGA_SCREEN_WIDTH * VGA_SCREEN_HEIGHT
;DS:SI to address ES:DI
rep movsb
@@end:
pop ds es cx di si
restore_sp_bp
ret
ENDP CopyDblBufToVideo