⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textmode.inc

📁 TestOS - 带简单GUI的DOS扩展OS// 源代码// ASM// 英文
💻 INC
字号:
;=========================================================;
; TextMode                                       11/12/03 ;
;---------------------------------------------------------;
; DOS EXTREME OS V0.01                                    ;
; by Craig Bamford.                                       ;
;                                                         ;
; Text mode functions for uses in programs.               ;                          
;=========================================================;

 ;----------------------------------------------------;
 ; Sets the text pos                                  ;
 ;----------------------------------------------------;

set_text_pos:
	mov   [screen_x],al
	mov   [screen_y],ah
	ret

 ;'''''''''''''''''''''''''''''''''''''''''''''''''''';
 ; Prints char               ; print's a char from al ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;  Input:                                            ;
 ;      Al Ascii character to write.                  ;
 ;                                                    ;
 ; Output:                                            ;
 ;      None.                                         ;
 ;....................................................;

print_char:
	                                        
	push  edi
        cli
       
       	mov   edi,0xb8000
	call  get_scr_pointer
       
        ;mov   ah,3
	mov   [es:edi], al 
	call  inc_scr_pointer

        sti
        pop   edi
       	ret

 ;'''''''''''''''''''''''''''''''''''''''''''''''''''';
 ; Prints string      ; does what it say's on the box ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;  Input:                                            ;
 ;      es:esi points to asciiz string to write.      ;
 ;                                                    ;
 ; Output:                                            ;
 ;      None.                                         ;
 ;....................................................;

print_string:
         pushad                                   
	;push  eax
	;push  esi
aloop:
	mov   al,[esi]
	cmp   al,0				           ; 0x00 = end of string
	je    gend
	cmp   al,0x0D				           ; 0x0d = CR ( = \n )
	jne   no_cr
	call  carriage_return
	jmp   a1
no_cr:

	call  print_char
a1:	inc   esi
      	jmp   aloop
gend:
        call  set_cursor_pos
	;pop   esi
	;pop   eax
        popad
	ret

 ;----------------------------------------------------;
 ; write hex 32        ;prints a hex number from eax. ;
 ;----------------------------------------------------;

write_hex32:
	
	pushad

	mov ebx, eax
loop1:
	rol eax, 8		                           ; get leftmost byte on right side
	call write_hex16
	cmp eax, ebx		                           ; loop until eax has rotated 360 degrees :)
	jne loop1

	popad
	ret

 ;----------------------------------------------------;
 ; write hex 16        ;prints a hex number from  al. ;
 ;----------------------------------------------------;

write_hex16:
	

	push eax
	push eax

	shr al, 4		                           ; get left nybble
	call hexget		                           ; al = 1st ascii
	call print_char

	pop eax

	call hexget		                           ; al = 2nd ascii
	call print_char

	pop eax
	ret



 ;----------------------------------------------------;
 ; Carriage return                       ; next line  ;
 ;----------------------------------------------------;

carriage_return:
	push  eax
	mov   [screen_x], byte 0
	mov   ah,[screen_y]     
	cmp   ah,24                 
	jb    no_scroll

	call  scroll
	jmp   cend
no_scroll:
	inc   ah    
	mov   [screen_y],ah     

cend:	pop   eax
	ret

 ;----------------------------------------------------;
 ; Scroll                      ; scroll's screen up 1 ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          none.                                     ;
 ;  Output:                                           ;
 ;          none.                                     ;
 ;....................................................;

scroll:
	push  eax
	push  ecx
	push  esi
	push  edi
        push  gs

        mov   ax,linear_sel
	mov   gs,ax
       	mov   al,0
	mov   ah,24
        call  set_text_pos
	cli
	mov   edi,0xb8000
	mov   esi,0xb8000+(80*2)
	mov   ecx,80*2*25/4

mloop:	mov   eax,[gs:esi]
	add   esi,4
	mov   [gs:edi],eax			
	add   edi,4
	dec   ecx
	jnz   mloop
        
        sti
        pop   gs
	pop   edi
	pop   esi
	pop   ecx
	pop   eax
	ret

 ;----------------------------------------------------;
 ; cls_text                     ; clear's text screen ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;   Input:                                           ;
 ;          none.                                     ;
 ;  Output:                                           ;
 ;          none.                                     ;
 ;....................................................;

cls_text:
	push  eax
	push  ecx
	push  esi
	push  edi
        push  gs

        mov   ax,linear_sel
	mov   gs,ax
     
	cli

	mov   ecx,80*24
	mov   edi,0B8000h

	mov   al," "		; space ascii char
	mov   bl,0Fh		; text color atribute

cls_loop:
	mov   byte [gs:edi],al
	inc   edi
	mov   byte [gs:edi],bl
	inc   edi
	dec   ecx
	jnz   cls_loop

	mov   [screen_x],byte 0
	mov   [screen_y],byte 0

        sti
        pop   gs
	pop   edi
	pop   esi
	pop   ecx
	pop   eax
	ret

 ;----------------------------------------------------;
 ; Inc screen pointer                                 ;
 ;----------------------------------------------------;

inc_scr_pointer:
	push  eax
	cld

	mov   al,[screen_x]
	cmp   al,80
	jb    no_incy

	call  carriage_return
	jmp   dend

no_incy:
	inc   al
	mov   [screen_x],al

dend:	pop   eax
	ret

 ;----------------------------------------------------;
 ; Gets screen pointer                                ;
 ;----------------------------------------------------;

get_scr_pointer:                                     
	
	push  eax                                          ; edi += screen_x * 2 + screen_y * 160
	push  ebx
	;xor   ebx,ebx
        xor   ebx,ebx
	mov   bl,[screen_x]
	shl   ebx,1
	add   edi, ebx
	mov   bl,[screen_y]
	mov   eax,0xa0
	mul   bx
	add   edi,eax
    	pop   ebx
	pop   eax
       
	ret

 ;'''''''''''''''''''''''''''''''''''''''''''''''''''';
 ; Sets cursor pos                                    ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;  Input:                                            ;
 ;     [screen_x]    points to X                      ;
 ;                                                    ;
 ;     [screen_Y]    points to Y                      ;
 ;                                                    ;
 ; Output:                                            ;
 ;      None.                                         ;
 ;....................................................;

set_cursor_pos:
	                                                     ; al = x, ah = y
	push  eax
	push  ebx
	push  ecx
	push  edx

	xor   ebx,ebx
	mov   bl,[screen_x]                                   ; al
	mov   ecx,ebx
	mov   bl,[screen_y]                                   ; ah
	mov   eax,80
	mul   bx
	add   eax,ecx			                     ; calculate offset for the crtc
	                                                     ; eax = ax = y * 25 + x	
        mov   edx,0x3D4
	mov   ecx,eax
	mov   al,0x0F
	out   dx,al
	mov   eax,ecx
	inc   edx
	out   dx,al
	mov   al,0x0E
	dec   edx
	out   dx,al
	mov   eax,ecx
	mov   al,ah
	inc   edx
	out   dx,al			                     ; send the offset to crtc

	pop   edx
	pop   ecx
	pop   ebx
	pop   eax
	ret

 ;----------------------------------------------------;
 ; Compear_String                                     ;
 ;----------------------------------------------------;

Compear_String:
        pushad
        push  es
        mov   ax,sys_data                                   ; Move how data base,into ax
        mov   es,ax                                         ; move ax into es
        mov   edi,TmpFileName1
        mov   esi,FileName
        mov   cx,9       ;11
FindNameCycle:
        cmp   byte [es:edi],ch
        je    FindNameFailed          
        pusha
        repe  cmpsb
        popa
        je    FindNameFound
FindNameFailed:
        stc
FindNameFound:
        pop   es
        popad
        ret

 ;----------------------------------------------------;
 ; hexget         convers from ASCII to hexadecimal.  ;
 ;----------------------------------------------------;

hexget:
	

	and eax, 0x0000000F
	or eax,  0x00000030
	cmp eax, 0x39
	ja add7
	ret
add7:	add eax, 7		
	ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -