-
Notifications
You must be signed in to change notification settings - Fork 3
/
Drawer.asm
290 lines (252 loc) · 4.3 KB
/
Drawer.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
SCREEN_SIZE equ 2000
SCREEN_WIDTH equ 80
SCREEN_HEIGH equ 25
VIDEO_ADDRESS equ 0xB800
BLANK equ 0x0720
section .text
; 清空屏幕并保存原屏幕信息
ScreenInit:
push ax
push cx
mov ax, VIDEO_ADDRESS
mov es, ax
mov ax, 0
mov di, ax
mov cx, SCREEN_SIZE
ScreenInit.save:
mov ax, word [es:di]
mov word [old_screen+di], ax
add di,2
loop ScreenInit.save
call ClearScreen
call HideCursor
pop cx
pop ax
ret
ClearScreen:
push ax
push cx
mov ax, VIDEO_ADDRESS
mov es, ax
mov ax, 0
mov di, ax
mov cx, SCREEN_SIZE
mov ax,BLANK
ClearScreen.clear:
mov word [es:di],ax
add di,2
loop ClearScreen.clear
pop cx
pop ax
ret
Quit:
push ax
push cx
call DisplayCursor
call QuitMouse
mov ax, VIDEO_ADDRESS
mov es, ax
mov ax, 0
mov di, ax
mov cx, SCREEN_SIZE
Quit.return:
mov ax, word [old_screen+di]
mov word [es:di], ax
add di,2
loop Quit.return
;call DeleteAllPtr
pop cx
pop ax
mov ax,4ch
int 21h
ret
; 绘制一条线
; void DrawLine(u16 x,u16 y,u16 x_len ,u16 y_len, u16 charactor)
DrawLine:
push bp
mov bp,sp
push ax
push cx
push word [bp+12]
push word [bp+10]
call GetDisplayLocation
pop cx
pop cx
mov cx,word [bp+8]
DrawLine.draw_y:
push cx
mov cx,word [bp+6]
mov ax,word [bp+4]
push di
DrawLine.draw_x:
mov word [es:di], ax
add di,2
loop DrawLine.draw_x
pop di
add di, SCREEN_WIDTH*2
pop cx
loop DrawLine.draw_y
pop cx
pop ax
mov sp,bp
pop bp
ret
; void GetDisplayLocation(u16 x,u16 y)
GetDisplayLocation:
push bp
mov bp,sp
push ax
push cx
mov ax, VIDEO_ADDRESS
mov es, ax
mov ax,word [bp+6]
mov cl, SCREEN_WIDTH*2
mul cl
add ax,word [bp+4]
add ax,word [bp+4]
mov di, ax
pop cx
pop ax
mov sp,bp
pop bp
ret
; u16 GetLocValue(u16 x,u16 y)
GetLocValue:
push bp
mov bp,sp
push word [bp+6]
push word [bp+4]
call GetDisplayLocation
mov ax,di
mov sp,bp
pop bp
ret
WALL_COLOR equ 0x4000
WALL_HORIZONTAL_WIDTH equ 1
WALL_VERTICAL_WIDTH equ 2
; void DrawHorizontalWall(u16 x,u16 y,u16 len)
DrawHorizontalWall:
push bp
mov bp,sp
push word [bp+8]
push word [bp+6]
push word WALL_HORIZONTAL_WIDTH
push word [bp+4]
push word WALL_COLOR
call DrawLine
mov sp,bp
pop bp
ret
; DrawVerticalWall(u16 x,u16 y,u16 len)
DrawVerticalWall:
push bp
mov bp,sp
push word [bp+8]
push word [bp+6]
push word [bp+4]
push word WALL_VERTICAL_WIDTH
push word WALL_COLOR
call DrawLine
mov sp, bp
pop bp
ret
WHITE equ 1
DrawHorizontalWhiteLine:
push bp
mov bp,sp
push word [bp+8]
push word [bp+6]
push word WALL_HORIZONTAL_WIDTH
push word [bp+4]
push word WALL_COLOR
call DrawLine
mov sp,bp
pop bp
ret
DrawVerticalWhiteLine:
push bp
mov bp,sp
push word [bp+8]
push word [bp+6]
push word [bp+4]
push word WALL_VERTICAL_WIDTH
push word WALL_COLOR
call DrawLine
mov sp, bp
pop bp
ret
DrawSquare:
push bp
mov bp,sp
push ax
mov ax, VIDEO_ADDRESS
mov es,ax
mov ax,word [bp+6]
mov di,ax
mov ax,word [bp+4]
mov word [es:di],ax
add di,2
mov word [es:di],ax
pop ax
mov sp, bp
pop bp
ret
HideCursor:
push dx
push bx
push ax
mov dx, 03d4h
; 保存原光标位置
mov al, 0eh
out dx, al
inc dx
in al,dx
mov bh,al
dec dx
mov al, 0fh
out dx, al
inc dx
in al,dx
mov bl,al
mov word [old_cursor],bx
dec dx
; 隐藏光标
mov bx, 25*80+1
mov al, 0eh
out dx, al
inc dx
mov al,bh
out dx,al
dec dx
mov al, 0fh
out dx, al
inc dx
mov al,bl
out dx,al
pop ax
pop bx
pop dx
ret
DisplayCursor:
push dx
push bx
push ax
mov bx, word [old_cursor]
mov al, 0eh
out dx, al
inc dx
mov al,bh
out dx,al
dec dx
mov al, 0fh
out dx, al
inc dx
mov al,bl
out dx,al
pop ax
pop bx
pop dx
ret
section .data
old_cursor dw 0
old_screen: times SCREEN_SIZE dw 0x0