]> wirehaze git hosting - BOS.git/blob - kernel/vga/text.asm

wirehaze git hosting

Update shell.asm
[BOS.git] / kernel / vga / text.asm
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2003-2005. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; Textmode screen functions. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9 ;-----------------;
10 ; variables ;
11 ;-----------------;
12 screen_rows db 25 ; all comments assume
13 screen_cols db 80 ; that this is 25 & 80
14 cursor_pos dw 0
15
16
17 ;--------------------------------------;
18 ; change cursor attribs ;
19 ; in: bx = cursor attribs ;
20 ;--------------------------------------;
21 changecursor:
22 push ax
23 push dx
24
25 mov dx, 0x3D4
26 mov al, 0x0A
27 mov ah, bh
28 out dx, ax
29 inc ax
30 mov ah, bl
31 out dx, ax
32
33 pop dx
34 pop ax
35 ret
36
37
38 ;----------------------;
39 ; clear the screen ;
40 ;----------------------;
41 cls:
42 push bx
43 push cx
44
45 movzx cx, [screen_rows]
46 .loop:
47 call _scroll_up
48 loop .loop
49
50 mov bx, 0
51 call setcursor
52
53 pop cx
54 pop bx
55 ret
56
57
58 ;-----------------------------------;
59 ; get the cursor pos ;
60 ; out: bh = x bl = y ;
61 ;-----------------------------------;
62 getcursorxy:
63 push ax
64
65 call getcursor
66 mov ax, bx
67 mov bl, [screen_cols]
68 div bl
69 mov bl, al
70 mov bh, ah
71
72 pop ax
73 ret
74
75
76 ;-------------------------------;
77 ; get the cursor pos ;
78 ; out: bx = offset ;
79 ;-------------------------------;
80 getcursor:
81 push ax
82 push dx
83
84 mov dx, 0x3D4
85 mov al, 0x0E
86 out dx, al
87 inc dx
88 in al, dx
89 mov bh, al
90 mov al, 0x0F
91 dec dx
92 out dx, al
93 inc dx
94 in al, dx
95 mov bl, al
96
97 pop dx
98 pop ax
99 ret
100
101
102 ;------------------------------;
103 ; set the cursor to: ;
104 ; bh = x bl = y ;
105 ;------------------------------;
106 setcursorxy:
107 push ax
108 push bx
109
110 xor ax, ax
111 mov al, [screen_cols]
112 mul bl ; bl * al = ax
113 movzx bx, bh
114 add bx, ax
115 call setcursor
116
117 pop bx
118 pop ax
119 ret
120
121
122 ;--------------------------;
123 ; set the cursor to: ;
124 ; bx = offset ;
125 ;--------------------------;
126 setcursor:
127 push ax
128 push bx
129 push dx
130
131 mov al, 0x0E
132 mov ah, bh
133 mov dx, 0x3D4
134 out dx, ax
135 inc ax
136 mov ah, bl
137 out dx, ax
138
139 pop dx
140 pop bx
141 pop ax
142 ret
143
144
145 ;-----------------------;
146 ; cursor position +1 ;
147 ;-----------------------;
148 inccursor:
149 push ax
150 push bx
151
152 mov al, [screen_cols]
153 mov bl, [screen_rows]
154 mul bl
155 dec ax
156
157 call getcursor
158 cmp bx, ax ; 0x7CF = (80*25)-1
159 jne .cont
160 call scroll_up
161 jmp .end
162
163 .cont:
164 inc bx
165 call setcursor
166
167 .end:
168 pop bx
169 pop ax
170 ret
171
172
173 ;-----------------------;
174 ; cursor position -1 ;
175 ;-----------------------;
176 deccursor:
177 push bx
178
179 call getcursor
180 cmp bx, 0
181 je .end
182
183 dec bx
184 call setcursor
185
186 .end:
187 pop bx
188 ret
189
190
191
192 ;---------------------------------------;
193 ; backspace - delete last typed char ;
194 ;---------------------------------------;
195 backspace:
196 push bx
197
198 call getcursor
199 cmp bx, 0
200 je .end
201
202 call deccursor
203
204 mov bh, 0x07
205 mov bl, 0
206 call print_char
207
208 call deccursor
209
210 .end:
211 pop bx
212 ret
213
214
215
216 ;-----------------------------------------;
217 ; print char ;
218 ; in: bl = char, bh = attrib ;
219 ;-----------------------------------------;
220 print_char:
221 push eax
222 push bx
223
224 cmp bl, 13
225 jne .cont
226 call new_line
227 jmp .done
228
229 .cont:
230 cmp bl, 10 ; ignore
231 je .done
232
233 push bx
234 call getcursor
235 movzx eax, bx
236 pop bx
237
238 mov [es:(eax*2 + 0xB8000)], bx
239
240 call inccursor
241 .done:
242 pop bx
243 pop eax
244 ret
245
246
247
248 ;------------------------------------------;
249 ; print 32-bit hex value ;
250 ; in: ebx = value, cl = color ;
251 ;------------------------------------------;
252 print_hex32:
253 push eax
254 push ebx
255 push ecx
256 push edx
257
258 mov eax, ebx ; quick & dirty fix so
259 mov bh, cl ; input reg != eax
260 mov ecx, 8
261
262 .print_it:
263 rol eax, 4
264 movzx edx, al
265 and edx, 0x0F
266 or edx, 0x30
267 cmp edx, 0x39
268 jna .cont
269 add edx, 7
270 .cont:
271 mov bl, dl
272 call print_char
273 loop .print_it
274
275 pop edx
276 pop ecx
277 pop ebx
278 pop eax
279 ret
280
281
282
283 ;-------------------------------------------------;
284 ; display a asciiz message on the screen ;
285 ; in: esi = message, bl = color ;
286 ;-------------------------------------------------;
287 print:
288 push eax
289 push bx
290
291 mov ah, bl
292 call getcursor
293 mov [cursor_pos], bx
294
295 .displaychar:
296 lodsb
297 or al, al
298 jz .done
299
300 cmp al, 13
301 jne .cont
302 mov bx, [cursor_pos]
303 call setcursor
304 call new_line
305 call getcursor
306 mov [cursor_pos], bx
307 jmp .displaychar
308
309 .cont:
310 cmp al, 10 ; ignore
311 je .displaychar
312 movzx ebx, [cursor_pos]
313 mov [es:(ebx*2 + 0xB8000)], ax
314 inc [cursor_pos]
315 jmp .displaychar
316
317 .done:
318 mov bx, [cursor_pos]
319 call setcursor ; update cursor on screen
320
321 pop bx
322 pop eax
323 ret
324
325
326
327 ;-----------------------------;
328 ; make a new line (CR, LF) ;
329 ;-----------------------------;
330 new_line:
331 push bx
332
333 call getcursorxy
334 mov bh, [screen_rows]
335 dec bh
336 cmp bl, bh ; 24
337 jb .newline
338
339 call scroll_up
340 jmp .done
341
342 .newline:
343 call getcursorxy
344 mov bh, 0
345 inc bl
346 call setcursorxy
347
348 .done:
349 pop bx
350 ret
351
352
353
354 ;----------------;
355 ; scrolling.. ;
356 ;----------------;
357 scroll_up:
358 call _scroll_up
359
360 .mv_curs:
361 push ax
362 push bx
363
364 xor ax, ax
365 mov al, [screen_rows] ; mov bx, 80*24
366 mov bl, [screen_cols]
367 dec al
368 mul bl
369 mov bx, ax
370 call setcursor
371
372 pop bx
373 pop ax
374 ret
375
376 _scroll_up:
377 push eax
378 push ecx
379 push edi
380 push esi
381
382 mov edi, 0xB8000
383 movzx esi, [screen_cols]
384 shl esi, 1 ; 80*2 = 160
385 mov cl, [screen_rows]
386 dec cl
387 mov eax, esi
388 mul cl
389 shr ax, 2 ; ax = (160*24)/4
390 movzx ecx, ax ; ecx = - || -
391 add esi, 0xB8000 ; esi = 0xB8000+160
392
393 rep movsd
394
395 mov cl, [screen_cols]
396 shl cl, 1 ; 80*2 = 160
397 mov al, [screen_rows]
398 dec al ; al = 24
399 mul cl
400 movzx edi, ax
401 add edi, 0xB8000 ; edi = 0xB8000+160*24
402 movzx ecx, [screen_cols]
403 shr ecx, 1 ; 80/2
404 mov eax, 0x07000700 ; fill with zeros
405 rep stosd
406
407 pop esi
408 pop edi
409 pop ecx
410 pop eax
411 ret