-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibcursor.asm
145 lines (127 loc) · 1.9 KB
/
libcursor.asm
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
get_int10h_cursor_coordinates:
push ax
push bx
push cx
mov ah, 03h ; get cursor position
mov bh, 00h ; page 0
int 10h
pop cx
pop bx
pop ax
ret ; DH = row, DL = column
store_cursor_coordinates:
push dx
call get_int10h_cursor_coordinates
mov [cursor_row], dh
mov [cursor_column], dl
pop dx
ret
get_cursor_coordinates:
mov dh, [cursor_row]
mov dl, [cursor_column]
ret ; DH = row, DL = column
set_cursor_coordinates: ; DH = row, DL = column
push ax
push bx
mov ah, 02h
mov bh, 00h ; page
mov [cursor_row], dh
mov [cursor_column], dl
int 10h
pop bx
pop ax
ret
scroll_up:
push ax
push bx
push cx
push dx
mov ah, 06h
mov al, 1
mov bh, 0Fh ; 0 - black, F - white
mov ch, 0
mov cl, 0
mov dh, 24
mov dl, 79
int 10h
pop dx
pop cx
pop bx
pop ax
ret
scroll_down:
push ax
push bx
push cx
push dx
mov ah, 07h
mov al, 1
mov bh, 0Fh ; 0 - black, F - white
mov ch, 0
mov cl, 0
mov dh, 24
mov dl, 79
int 10h
mov dx, [code_offset] ; if we are gone off-borders, load the buffer
cmp dx, 1999 ; 24*80+79
jl .end
push es
push bp
; write string
mov dh, 0
mov dl, 0
mov bx, [code_offset]
sub bx, 1999
mov bp, bx
mov ax, 840h
mov es, ax
mov ah, 13h ; Write string
mov al, 00000000b ; Write mode
mov bh, 0 ; page 0
mov bl, 0Fh ; black und white
mov cx, 80 ; length of string
int 10h
pop bp
pop es
.end:
pop dx
pop cx
pop bx
pop ax
ret
push_cursor_left:
push dx
call get_cursor_coordinates
cmp dl, 0
jnz .not_equal
mov dl, 79
call set_cursor_coordinates
call scroll_down
pop dx
ret
.not_equal: dec dl
call set_cursor_coordinates
pop dx
ret
push_cursor_right:
push dx
call get_cursor_coordinates
cmp dl, 79
jnz .not_equal
mov dl, 0
call set_cursor_coordinates
call scroll_up
pop dx
ret
.not_equal: inc dl
call set_cursor_coordinates
pop dx
ret
newline:
push dx
mov dh, 24
mov dl, 0
call set_cursor_coordinates
call scroll_up
pop dx
ret