-
Notifications
You must be signed in to change notification settings - Fork 0
/
cursor.s
285 lines (236 loc) · 3.49 KB
/
cursor.s
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
.include "system_calls.s"
.data
hide:
.byte 27
.ascii "[?25l"
show:
.byte 27
.ascii "[?25h"
fore:
.byte 27
.ascii "[30m"
back:
.byte 27
.ascii "[40m"
home:
.byte 27
.ascii "[H"
position:
.byte 27
.ascii "[0000;0000H"
clear_l:
.byte 27
.ascii "[2K"
clear_s:
.byte 27
.ascii "[2J"
bold:
.byte 27
.ascii "[1m"
dim:
.byte 27
.ascii "[2m"
reset:
.byte 27
.ascii "[0m"
color_red:
.byte 27
.ascii "[34m"
.balign 4
.text
.global cursor_show
cursor_show:
mov r7, #WRITE
mov r0, #STDOUT
ldr r1, =show
mov r2, #6
svc #0
bx lr
.global cursor_hide
cursor_hide:
mov r7, #WRITE
mov r0, #STDOUT
ldr r1, =hide
mov r2, #6
svc #0
bx lr
.global fore_color
fore_color:
cmp r0, #10
bxpl lr
// Inject the color number into the string
add r0, r0, #48
ldr r1, =fore
strb r0, [r1, #3]
mov r7, #WRITE
mov r0, #STDOUT
mov r2, #5
svc #0
bx lr
.global spider_color
spider_color:
push {r0, r1}
cmp r0, #10
bxpl lr
// Inject the color number into the string
add r0, r0, #48
ldr r1, =color_red
strb r0, [r1, #3]
mov r7, #WRITE
mov r0, #STDOUT
mov r2, #5
svc #0
pop {r0, r1}
bx lr
.global back_color
back_color:
cmp r0, #10
bxpl lr
// Inject the color number into the string
add r0, r0, #48
ldr r1, =back
strb r0, [r1, #3]
mov r7, #WRITE
mov r0, #STDOUT
mov r2, #5
svc #0
bx lr
.global cursor_home
cursor_home:
mov r7, #WRITE
mov r0, #STDOUT
ldr r1, =home
mov r2, #3
svc #0
bx lr
.global locate
locate:
cmp r0, #1000
bxpl lr
cmp r1, #1000
bxpl lr
push {r4-r8, lr} // Uneven Stack without r8
ldr r12, =position
mov r7, #10
mov r6, #0 // Which coordiate are we working on? 0 = x, 1 = y
locate_loop:
mov r3, #0 // Counter and shifter
mov r2, #0 // Set this to zeroes
coordinate_loop:
udiv r4, r0, r7 // Get x / 10
mls r5, r4, r7, r0 // Get x % 10
add r5, r5, #48 // Convert digit to ascii
mov r2, r2, LSL #8
add r2, r2, r5 // Put digit in the appropriate byte of r2
mov r0, r4
cmp r3, #24
addne r3, r3, #8
bne coordinate_loop
cmp r6, #0
moveq r0, r1
moveq r1, r2
addeq r6, r6, #1
beq locate_loop
str r1, [r12, #2] // Put x in string
str r2, [r12, #7] // Put y in string
mov r7, #WRITE
mov r0, #STDOUT
mov r1, r12
mov r2, #12
svc #0
pop {r4-r8, pc}
.global clear_line
clear_line:
mov r7, #WRITE
mov r0, #STDOUT
ldr r1, =clear_l
mov r2, #4
svc #0
bx lr
.global clear_screen
clear_screen:
mov r7, #WRITE
mov r0, #STDOUT
ldr r1, =clear_s
mov r2, #4
svc #0
bx lr
.global bold_text
bold_text:
mov r7, #WRITE
mov r0, #STDOUT
ldr r1, =bold
mov r2, #4
svc #0
bx lr
.global dim_text
dim_text:
mov r7, #WRITE
mov r0, #STDOUT
ldr r1, =dim
mov r2, #4
svc #0
bx lr
.global reset_text
reset_text:
mov r7, #WRITE
mov r0, #STDOUT
ldr r1, =reset
mov r2, #4
svc #0
bx lr
// Test code that should be commented out
/*.global _start
_start:
bl ask
bl cursor_hide
bl ask
bl cursor_show
bl ask
mov r0, #5
bl fore_color
bl ask
mov r0, #9
bl fore_color
bl ask
mov r0, #5
bl back_color
bl ask
mov r0, #9
bl back_color
bl ask
bl cursor_home
bl ask
mov r0, #50
mov r1, #50
bl locate
bl ask
bl clear_line
bl ask
bl clear_screen
bl ask
bl bold_text
bl ask
bl dim_text
bl ask
bl reset_text
bl ask
mov r7, #1
svc #0
ask:
sub sp, sp, #16
mov r7, #WRITE
mov r0, #STDOUT
adr r1, prompt
mov r2, #1
svc #0
mov r7, #READ
mov r0, #STDIN
mov r1, sp
mov r2, #16
svc #0
add sp, sp, #16
bx lr
prompt:
.ascii ">"
*/