Video.inc
[ Return to Browse Source Page ]
; Video.inc:
; A 32-bit Console-Mode Video Driver
; Copyright 1999, Ed Pizzi
;
; To do: Make all of this accessible through interrupts.
; Either rewrite these procs into interrupts, or
; just write interrupt 'shell' for these functions.
Video_Init:
mov ax,0900h
call set_cursor
mov al,07
mov gs:[PDA_StdStyle],al
; print video mode brag string
mov esi,offset video_init_str
mov ax,fs
mov ds,ax
call Print
ret
; Print:
; Typical string output.
; Prints a null-terminated string in DS:[SI] to the screen.
;Print:
;pushad
;push ds
; push PDA
; pop ds
; mov cl,ds:[PDA_StdStyle]
; pop ds
; Print_loop:
; lodsb
; or al,al
; jz End_Print
; call Print_char2
; jmp Print_loop
; End_Print:
;popad
;ret
Print:
pushad
push es
push fs
mov ax,OS_Vram
mov bx,PDA
mov fs,ax
mov es,bx
xor eax,eax
Print_restorecolor:
xor ecx,ecx
mov ah,es:[PDA_StdStyle]
Print_loop:
mov al,[esi]
inc esi
test al,al
jz End_Print
cmp al,0FFh
jz Print_ColorChange
cmp al,01h
jz Print_RLE
call Print_Char_Internal
jmp Print_loop
End_Print:
pop fs
pop es
popad
ret
Print_char_internal:
test al,al
jz print_char_i_end
cmp al,0Dh
jz do_crlf
cmp al,08h
jz do_backspace
cmp al,0Ah
jz print_char_i_end
mov edx,eax
call getcursorpos
call text_make_linear
mov fs:[ebx],dx
call advance_cursor
mov eax,edx
print_char_i_end:
ret
Print_ColorChange:
mov al,[esi]
inc esi
cmp al,0FFh
jz Print_restorecolor
mov ah,al
jmp Print_loop
Print_RLE:
xor edx,edx
mov dl,[esi]
inc esi
cmp dl,01
jz Print_CRLF2
cmp dl,0FFh
jz Print_Allign
mov ebp,edx
mov al,[esi]
inc esi
Print_RLE_loop:
call Print_char_internal
dec ebp
jnz Print_RLE_loop
jmp Print_loop
Print_CRLF2:
call do_crlf
Print_Allign:
call message_allign
jmp Print_loop
;print_char:
;push ecx
;push ds
;push PDA
;pop ds
;mov cl,ds:[PDA_StdStyle]
;call Print_char2
;pop ds
;pop ecx
;ret
; Print_char:
; Prints the char in al to the screen.
; Like the BIOS function "write text in teletype mode".
; Control Characters:
; 00h = (treated as a NOP. this makes things easier, such as
; printing numbers, and certain loops.)
; 08h = Backspace (destructive)
; 0Ah = (treated as a NOP for compatibility with BIOS strings)
; 0Dh = Carriage Return / Line Feed
Print_char:
pushad
push es
push fs
mov cx,OS_Vram
mov bx,PDA
mov fs,cx
mov es,bx
mov ah,es:[PDA_StdStyle]
call print_char_internal
pop fs
pop es
popad
ret
Print_char_keyctrl:
push eax
cmp al,01
jz print_char_keyctrl_bs
cmp al,03
jz print_char_keyctrl_enter
cmp al,019h
jz print_char_keyctrl_bs
cmp al,01Ah
jnz print_char_keyctrl_ret
; print_char_keyctrl_space:
mov al,020h
print_char_keyctrl_print:
call print_char
print_char_keyctrl_ret:
pop eax
ret
print_char_keyctrl_bs:
add esp,4 ; get rid of eax on the stack
jmp do_backspace
print_char_keyctrl_enter:
mov al,0Dh
add esp,4 ; get rid of eax on the stack
jmp print_char_keyctrl_print
advance_cursor:
do_space:
push eax
call getcursorpos
inc al
cmp al,80
jb advance_cursor_no_clip
call do_crlf
jmp advance_cursor_clip_end
advance_cursor_no_clip:
call set_cursor
advance_cursor_clip_end:
pop eax
ret
getcursorpos:
push ds
push PDA
pop ds
mov ax,ds:[PDA_CursorPos]
movzx eax,ax
pop ds
ret
text_make_linear:
push eax
mov ebx,eax ; x
shr eax,3 ; >> 8 * << 5
and ebx,0FFh
and eax,01111111100000b ; y
lea eax,[eax+eax*4]
lea ebx,[eax+ebx*2]
pop eax
ret
set_cursor:
push ds
push PDA
pop ds
mov ds:[PDA_CursorPos],ax
pop ds
push eax
push edx
push ebx
mov ebx,eax
call text_make_linear
shr ebx,1
mov al,0Fh
mov dx,03D4h
out dx,al
mov al,bl
inc dl
out dx,al
mov al,0Eh
dec dl
out dx,al
inc dl
mov al,bh
out dx,al
pop ebx
pop edx
pop eax
ret
do_crlf:
push ecx
push eax
call getcursorpos
inc ah
cmp ah,25
jnz do_crlf_noscroll
dec ah
call scroll_line
do_crlf_noscroll:
xor al,al
call set_cursor
pop eax
pop ecx
ret
do_backspace:
push ebx
push eax
push ds
mov ax,OS_Vram
mov ds,ax
call getcursorpos
sub al,1
jnc do_backspace_1
mov al,79
sub ah,1
jnc do_backspace_1
xor eax,eax
do_backspace_1:
call text_make_linear
mov byte ptr [ebx],020h
call set_cursor
pop ds
pop eax
pop ebx
ret
scroll_line:
push eax
push edi
push esi
push ds
push es
mov ax,OS_Vram
mov es,ax
mov ds,ax
xor edi,edi
lea esi,[edi+(80*2)]
mov ecx,(((80*2)*24)/4)
rep movsd
mov cl,80
push PDA
pop ds
mov ah,ds:[PDA_StdStyle]
mov al,020h
rep stosw
pop es
pop ds
pop esi
pop edi
pop eax
ret
vret:
push eax
push edx
mov edx,03DAh
vret_screenactive:
in al,dx ;crtc status
test al,8
jnz vret_screenactive
vret_vretactive:
in al,dx
test al,8
jz vret_vretactive
pop eax
pop edx
ret
Download this file.
[ Return to Browse Source Page ]
Copyright 2000, Ed Pizzi