-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterm.s
More file actions
150 lines (129 loc) · 2.92 KB
/
Copy pathterm.s
File metadata and controls
150 lines (129 loc) · 2.92 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
.include "sys_call-inl.s"
.extern term_fd
.global last_char # variable
.global getchar
.global putchar
.global clear_screen
.global hide_cursor
.global show_cursor
.global set_cursor_pos
.global set_color_red
.global set_color_green
.global set_color_blue
.data
#=======================
code_clear_screen: .ascii "\033[2J"
.equiv code_clear_screen_len, . - code_clear_screen
code_hide_cursor: .ascii "\033[?25l"
.equiv code_hide_cursor_len, . - code_hide_cursor
code_show_cursor: .ascii "\033[?25h"
.equiv code_show_cursor_len, . - code_show_cursor
.equiv code_color_len, 5
code_color_red: .ascii "\033[31m"
code_color_green: .ascii "\033[32m"
code_color_blue: .ascii "\033[33m"
last_char: .byte '?'
.text
#=======================
#-----------------------
# func getchar()
# -> %al(0: get nothing, others: get a char)
.type getchar, @function
getchar:
read term_fd, $last_char, $1
cmpl $0, %eax
jle getchar_fail
# succ
mov last_char, %al
jmp getchar_end
getchar_fail:
mov $0, %al
getchar_end:
ret
#-----------------------
# func putchar
# row/y(%ax), col/x(%bx)
# char to put(%cl)
.type putchar, @function
.bss
.lcomm putchar_buf, 1
.text
putchar:
pushw %cx
call set_cursor_pos
popw %cx
movb %cl, putchar_buf
write term_fd, $putchar_buf, $1
ret
#-----------------------
# func clear_screen
.type clear_screen, @function
clear_screen:
write term_fd, $code_clear_screen, $code_clear_screen_len
ret
#-----------------------
# func hide_cursor
.type hide_cursor, @function
hide_cursor:
write term_fd, $code_hide_cursor, $code_hide_cursor_len
ret
#-----------------------
# func show_cursor
.type show_cursor, @function
show_cursor:
write term_fd, $code_show_cursor, $code_show_cursor_len
ret
#-----------------------
# func set_color_red
.type set_color_red, @function
set_color_red:
write term_fd, $code_color_red, $code_color_len
ret
#-----------------------
# func set_color_green
.type set_color_green, @function
set_color_green:
write term_fd, $code_color_green, $code_color_len
ret
#-----------------------
# func set_color_blue
.type set_color_blue, @function
set_color_blue:
write term_fd, $code_color_blue, $code_color_len
ret
#-----------------------
# func set_cursor_pos
# row/y(%ax), col/x=%bx
.type set_cursor_pos, @function
.bss
.lcomm set_cursor_pos_buf, 20
.text
set_cursor_pos:
# \033
movb $0x1B, set_cursor_pos_buf
# [
movb $'[', set_cursor_pos_buf + 1 # [
# y
movl $(set_cursor_pos_buf + 2), %edi
pushw %bx
pushl %edi
call itoa
popl %edi
popw %bx
addl %ecx, %edi
# ;
movb $';', (%edi)
incl %edi
# x
movw %bx, %ax
pushl %edi
call itoa
popl %edi
addl %ecx, %edi
# H
movb $'H', (%edi)
incl %edi
# edi as len
subl $set_cursor_pos_buf, %edi
write term_fd, $set_cursor_pos_buf, %edi
ret