-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawscreen.s
449 lines (409 loc) · 10.8 KB
/
drawscreen.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
.include "header.s"
.global drawscreen
#drawscreen function that clears the screen everytime and redraws all the characters from the memory
drawscreen:
#save all callee save registers on the stack
subi sp,sp,32
stw r15,(sp)
stw r16,4(sp)
stw r17,8(sp)
stw r18,12(sp)
stw r19,16(sp)
stw r20,20(sp)
stw r21,24(sp)
stw ra,28(sp)
#load the address for the pre, post & buffer pointer from memory
movia r7,pre
ldh r18,(r7)
movia r7,post
ldh r19,(r7)
movia r4,buffer
#pre and post hold the index past buffer they are in, however making them the address itself by adding them to buffer
add r5,r18,r4
add r6,r19,r4
movia r7,ADDR_CHAR
movi r19,128
movi r18,60
movi r16,-1
#goes through all the char buffer and sets them all to space(clearing it)
cleartext:
#outerloop to go through while y<60 reset the x
outsideloop:
beq r16,r18,text
addi r16,r16,1
movi r17,0
innerloop:
#increment x until its 80
beq r17,r19,outsideloop
#memory address= x+128y+base
muli r21,r16,128
add r20,r17,r21
add r20,r20,r7
#set them all to space
movi r21,' '
sthio r21,0(r20)
addi r17,r17,1
br innerloop
#begin writing from memory
text:
movi r17,0
movi r18,80
movi r19,0
movi r20,10
movia r21,ADDR_CHAR
#loop while the index is less than pre(the beggining of the buffer)
loop:
beq r4,r5,preskip
bne r19,r18,here
movi r19,0 #current position in the x
addi r21,r21,48
here:
#load from the index
ldb r16,(r4)
addi r19,r19,1
#check if you have an enter
bne r20,r16,next
#skip a full line of display by subtracting your current position from 128 to know what to add to get to the next line
subi r19,r19,129 # -1 extra
muli r19,r19,-1
mov r15,r19
add r21,r21,r19
movi r19,0
next:
#r17 holds which character number you are form the start of memory
#position is the location of each of the 4 cursors from the start of memory
#this section determines whether to draw a cursor or not
movia r7,position
ldh r22,(r7)
beq r17,r22,cursor
ldh r22,2(r7)
beq r17,r22,cursor
## for cursors 3 and 4
## ldh r22,4(r7)
## beq r17,r22,cursor
## ldh r22,6(r7)
## beq r17,r22,cursor
#check if its an enter
beq r16,r20,next11
#this is a normal character draw it onto the screen and increment the location in the char buffer
stbio r16,0(r21)
addi r21,r21,1
#increment buffer pointer
#increment the Nth character from memory
next11: addi r4,r4,1
addi r17,r17,1
br loop
#drawing a cursor based on blinking every half second
cursor:
movia r7,blink
ldb r7,(r7)
beq r7,r0,dtdraw
movi r28, 127
beq r16,r20,specialcase
stbio r28,0(r21)
addi r21,r21,1
br next11
specialcase:
sub r21,r21,r15
stbio r28,0(r21)
## addi r21,r21,1
add r21,r21,r15
br next11
#draw what should be drawn there not the cursor
dtdraw: beq r16,r20,next11
stbio r16,0(r21)
addi r21,r21,1
br next11
#check if the cursor is at pre and draw it if need be
preskip:
movia r7,blink
ldb r7,(r7)
beq r7,r0,skip
movi r28, 127
stbio r28,0(r21)
#same procedure as above however this time dealing with post buffer memory until you read a null/zero char
skip:
ldb r16,(r6)
addi r19,r19,1
beq r0,r16,end
bne r20,r16,next2
subi r19,r19,129
muli r19,r19,-1
add r21,r21,r19
movi r19,0
br next22
#check if the current position is where a cursor is
next2: movia r7,position
ldh r22,(r7)
beq r17,r22,cursor2
ldh r22,2(r7)
beq r17,r22,cursor2
stbio r16,0(r21)
## for cursors 3 and 4
## ldh r22,4(r7)
## beq r17,r22,cursor2
## ldh r22,6(r7)
## beq r17,r22,cursor2
addi r21,r21,1
next22: addi r6,r6,1
addi r17,r17,1
movia r7,position
ldh r22,(r7)
beq r17,r22,endcursor
ldh r22,2(r7)
beq r17,r22,endcursor
## cursors 3 and 4
## ldh r22,4(r7)
## beq r17,r22,endcursor
## ldh r22,6(r7)
## beq r17,r22,endcursor
br skip
#animation of cursor every 1 second
cursor2:
movia r7,blink
ldb r7,(r7)
beq r7,r0,dtTdraw
movi r28,127
stbio r28,0(r21)
addi r21,r21,1
br next22
dtTdraw: stbio r16,0(r21)
addi r21,r21,1
br next22
endcursor:
movia r7,blink
ldb r7,(r7)
beq r7,r0,skip
movi r28,127
stbio r28,0(r21)
br skip
end:
ldw r15,(sp)
ldw r16,4(sp)
ldw r17,8(sp)
ldw r18,12(sp)
ldw r19,16(sp)
ldw r20,20(sp)
ldw r21,24(sp)
ldw ra,28(sp)
addi sp,sp,32
ret
## functiont to clear screen by pixels
.global clearscreen
clearscreen:
subi sp,sp,28
stw r16,(sp)
stw r17,4(sp)
stw r18,8(sp)
stw r19,12(sp)
stw r20,16(sp)
stw r21,20(sp)
stw ra,24(sp)
movia r7,ADDR_VGA
movi r19,320
movi r18,239
movi r16,-1
#go through nested loop while y<320
outsideloop_s:
beq r16,r18,done_clrscr
addi r16,r16,1
movi r17,0
#while x<240
innerloop_s:
beq r17,r19,outsideloop_s
#memory address = 2x+1024y+base
muli r20,r17,2
muli r21,r16,1024
add r20,r20,r21
add r20,r20,r7
sthio r0,0(r20)
addi r17,r17,1
br innerloop_s
done_clrscr:
ldw r16,(sp)
ldw r17,4(sp)
ldw r18,8(sp)
ldw r19,12(sp)
ldw r20,16(sp)
ldw r21,20(sp)
ldw ra,24(sp)
addi sp,sp,28
ret
## .include "header.s"
## .global drawscreen
## drawscreen:
## subi sp,sp,28
## stw r16,(sp)
## stw r17,4(sp)
## stw r18,8(sp)
## stw r19,12(sp)
## stw r20,16(sp)
## stw r21,20(sp)
## stw ra,24(sp)
## movia r7,pre
## ldh r18,(r7)
## movia r7,post
## ldh r19,(r7)
## movia r4,buffer
## add r5,r18,r4
## add r6,r19,r4
## movia r7,ADDR_CHAR
## movi r19,128
## movi r18,60
## movi r16,-1
## cleartext:
## outsideloop:
## beq r16,r18,text
## addi r16,r16,1
## movi r17,0
## innerloop:
## beq r17,r19,outsideloop
## muli r21,r16,128
## add r20,r17,r21
## add r20,r20,r7
## movi r21,' '
## sthio r21,0(r20)
## addi r17,r17,1
## br innerloop
## text:
## movi r17,0
## movi r18,80
## movi r19,0
## movi r20,10
## movia r21,ADDR_CHAR
## loop:
## beq r4,r5,preskip
## bne r19,r18,here
## movi r19,0
## addi r21,r21,48
## here:
## ldb r16,(r4)
## addi r19,r19,1
## bne r20,r16,next
## subi r19,r19,129 # -1 extra
## muli r19,r19,-1
## add r21,r21,r19
## movi r19,0
## ## br next11
## next:
## movia r7,position
## ldh r22,(r7)
## beq r17,r22,cursor
## ldh r22,2(r7)
## beq r17,r22,cursor
## beq r16,r20,next11
## stbio r16,0(r21)
## addi r21,r21,1
## next11: addi r4,r4,1
## addi r17,r17,1
## br loop
## cursor:
## movia r7,blink
## ldb r7,(r7)
## beq r7,r0,dtdraw
## movi r28, 127
## stbio r28,0(r21)
## addi r21,r21,1
## br next11
## dtdraw: beq r16,r20,next11
## stbio r16,0(r21)
## addi r21,r21,1
## br next11
## preskip:
## movia r7,blink
## ldb r7,(r7)
## beq r7,r0,skip
## movi r28, 127
## stbio r28,0(r21)
## br skip
## skip:
## ldb r16,(r6)
## addi r19,r19,1
## beq r0,r16,end
## bne r20,r16,next2
## subi r19,r19,129
## muli r19,r19,-1
## add r21,r21,r19
## movi r19,0
## br next22
## next2: movia r7,position
## ldh r22,(r7)
## beq r17,r22,cursor2
## ldh r22,2(r7)
## beq r17,r22,cursor2
## stbio r16,0(r21)
## addi r21,r21,1
## next22: addi r6,r6,1
## addi r17,r17,1
## movia r7,position
## ldh r22,(r7)
## beq r17,r22,endcursor
## ldh r22,2(r7)
## beq r17,r22,endcursor
## br skip
## cursor2:
## movia r7,blink
## ldb r7,(r7)
## beq r7,r0,dtTdraw
## movi r28,127
## stbio r28,0(r21)
## addi r21,r21,1
## br next22
## dtTdraw: stbio r16,0(r21)
## addi r21,r21,1
## br next22
## endcursor:
## movia r7,blink
## ldb r7,(r7)
## beq r7,r0,skip
## movi r28,127
## stbio r28,0(r21)
## br skip
## end:
## ldw r16,(sp)
## ldw r17,4(sp)
## ldw r18,8(sp)
## ldw r19,12(sp)
## ldw r20,16(sp)
## ldw r21,20(sp)
## ldw ra,24(sp)
## addi sp,sp,28
## ret
## ## functiont to clear screen by pixels
## .global clearscreen
## clearscreen:
## subi sp,sp,28
## stw r16,(sp)
## stw r17,4(sp)
## stw r18,8(sp)
## stw r19,12(sp)
## stw r20,16(sp)
## stw r21,20(sp)
## stw ra,24(sp)
## movia r7,ADDR_VGA
## movi r19,320
## movi r18,239
## movi r16,-1
## outsideloop_s:
## beq r16,r18,done_clrscr
## addi r16,r16,1
## movi r17,0
## innerloop_s:
## beq r17,r19,outsideloop_s
## muli r20,r17,2
## muli r21,r16,1024
## add r20,r20,r21
## add r20,r20,r7
## sthio r0,0(r20)
## addi r17,r17,1
## br innerloop_s
## done_clrscr:
## ldw r16,(sp)
## ldw r17,4(sp)
## ldw r18,8(sp)
## ldw r19,12(sp)
## ldw r20,16(sp)
## ldw r21,20(sp)
## ldw ra,24(sp)
## addi sp,sp,28
## ret