汇编杂谈-光标设置

调整 CRT 阴极射线管控制器光标位置

调整光标位置

 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
CRT_ADDR_REG equ 0x3d4
CRT_DATA_REG equ 0x3d5
CRT_CURSOR_HIGH equ 0xe
CRT_CURSOR_LOW equ 0xf

; 每行80个字符,跳转到15行需要设置15*80
mov ax, 15 * 80 
call set_cursor

set_cursor:
	; ax 传递参数
	push bx
	push dx
	mov bx, ax

	mov dx, CRT_ADDR_REG
	mov al, CRT_CURSOR_LOW
	out dx, al

	mov dx, CRT_DATA_REG
	mov al, bl
	out dx, al

	mov dx, CRT_ADDR_REG
	mov al, CRT_CURSOR_HIGH
	out dx, al

	mov dx, CRT_DATA_REG
	mov al, bh
	out dx, al

	pop dx
	pop bx
	ret

获取光标位置

 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
get_cursor:
	; ax 传递参数
	push bx
	push dx

	mov dx, CRT_ADDR_REG
	mov al, CRT_CURSOR_LOW
	out dx, al

	mov dx, CRT_DATA_REG
	in al, dx
	mov bl, al

	mov dx, CRT_ADDR_REG
	mov al, CRT_CURSOR_HIGH
	out dx, al

	mov dx, CRT_DATA_REG
	in al, dx
	mov bh, al

	mov ax, bx
	pop dx
	pop bx
	ret
0%