; ==================================
;; 文件: pnt.asm
;; 作用: 需要调用的显示部分子程序
;; 创建日期:2006/04/30 flyback
;; 修改日期:2006/05/07 flyback
;; http://blog.youkuaiyun.com/flyback
;; fly-back@163.com
; ==================================
[bits 16]
[global _pntchr]
[global _cls]
[global _NextLine]
[global _Num2Str]
[global _ShowAddress]
[global _NextCursor]
segment .data
_row dw 0
_col dw 0
[section .text]
_pntchr:
push ebx
push eax
push si
push di
push cx
push es
mov ax, 0xb800
mov es, ax
push si
lea si, [dword _row]
mov ax, [si]
mov bx, 80 * 2
mul bx
lea si, [dword _col]
add ax, [si]
mov di, ax
pop si
.pnt:
mov al, byte[ds:si]
test al, 0xff
jz .endpntchr
mov byte[es:di], al
inc di
mov byte[es:di], 0x7
inc di
inc si
call _NextCursor
jmp .pnt ;
.endpntchr: ;
pop es
pop cx
pop di
pop si
pop eax
pop ebx
ret ; 返回
; =======
; 清屏幕
; =======
_cls:
push ax
push es
push di
push ecx
push si
; push fs
mov ax, 0xb800
mov es, ax
mov ax, 0
mov di, ax
mov ecx, 25 * 80
mov ah, 0x7
mov al, ' '
rep stosw
mov ax, 0
mov es, ax
lea si, [dword _row]
mov [si], ax
lea si, [dword _col]
mov [si], ax
; pop fs
pop si
pop ecx
pop di
pop es
pop ax
ret
; =============
; 跳到下一行
; =============
_NextLine:
push si
lea si, [dword _row]
inc word[si]
lea si, [dword _col]
mov word [si], 0
pop si
ret
; =================
; 设置光标的下一个位置
; =================
_NextCursor:
push si
lea si, [dword _col]
inc word[si]
inc word[si]
cmp word [si], 80 * 2
jne .addcol
mov word [si], 0
lea si, [dword _row]
inc word[si]
.addcol:
pop si
ret
; ===================
; 显示指定位置的地址内容
; 入口参数:
; si = 有效地址
; cx = 内容个数
; ===================
_ShowAddress:
push eax
.lod
lodsb
or cx,cx
jz .end
push si
call _Num2Str
call _pntchr
; call _NextLine
pop si
loop .lod
.end
pop eax
ret
; ===========
; 把al的数按16
; 进制显示出来
; al = num
; ===========
_Num2Str:
push bx
push eax
jmp .handle
.show db ' '
.dath db 0
.datl db 0,0
.tab db '0123456789ABCDEF'
.handle:
and ax, 0xff
push ax
and ax, 0x0f
lea si, [dword .tab]
add si, ax
mov al, byte[si]
lea si, [dword .datl]
mov [si], al
pop ax
shr ax, 4
and ax, 0x0f
lea si, [dword .tab]
add si, ax
mov al, byte[si]
lea si, [dword .dath]
mov [si], al
lea si, [dword .show]
pop eax
pop bx
ret