-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkernel.asm
More file actions
1182 lines (780 loc) · 20.6 KB
/
kernel.asm
File metadata and controls
1182 lines (780 loc) · 20.6 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
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
org 0x7e00
jmp 0x0000:start
str_a db "Welcome to CAD! This is your startup screen to help you with the commands.", 13, 10, 0
str_b db 13, 10,"Movements:", 13, 10, 10, "- Down 'x'", 13, 10, "- Up 'w'", 13, 10, "- Right 'd'", 13, 10, "- Left 'a'", 13, 10, "- Down right 'c'", 13, 10, "- Down left 'z'", 13, 10, "- Up right 'r'", 13, 10, "- Up left 'q'", 13, 10, 10, "To paint the pixel at the current position press 's', and to hold the painting while moving, keep 'shift' pressed or active the 'Caps Lock' key. ", 13, 10, 10, "Brush:", 13, 10, 10, "- Incrase speed (pixel per click) '+'", 13, 10, "- Decrease speed (pixel per click) '-'", 13, 10, "- Alternate brush aparence 'p'", 13, 10, 10, "Others: ", 13, 10, 10, "- Reset board '<'", 13, 10, "- Quit 'Esc'", 13, 10, 10, "Press any key to continue...", 13, 10, 0
str_c db "Colors: ", 13, 10, 10, "- Black '1'", 13, 10, "- Blue '2'", 13, 10, "- Green '3'", 13, 10, "- Cyan '4'", 13, 10, "- Red '5'", 13, 10, "- Magenta '6'", 13, 10, "- Brown '7'", 13, 10, "- Light Gray '8'", 13, 10, "- Dark Gray '9'", 13, 10, "- Light Blue '0'", 13, 10, "- Light Green ''''", 13, 10, "- Light Cyan '!'", 13, 10, "- Light Red '@'", 13, 10, "- Light Magenta '#'", 13, 10, "- Yellow '$'", 13, 10, "- White '%'", 13, 10, 10, "Developers:", 13, 10, 10, "Almir Menezes da Cunha Junior - amcj2@cin.ufpe.br", 13, 10, "Daniel Henrique Amorim Correia - dhac@cin.ufpe.br", 13, 10, 10, "Press any key to start...", 13, 10, 0
current_color db "Current color: ", 0
current_speed db "Current speed: ", 0
speed dw 1 ; movement's speed
color db 0x0; color parameter to paint
user_color db 0xf ; user paint color
under_color db 0x0 ; color under the brush
brush_color db 0xf ; brush color
up dw 20 ; max up movement
down dw 479 ; max down movement
right dw 639 ; max right movement
left dw 1 ; max left movement
i dw 0 ; loop's variable
j dw 0 ; loop's variable
temp1 dw 0
temp2 dw 0
start:
xor ax, ax
mov ds, ax
mov ah, 0
mov al, 12h
int 10h
mov cl, 0
mov si, str_a
call print_str ; print string a
mov si, str_b
call print_str ; print string b
mov ah, 0
int 16h
mov ah, 0 ; other page
mov al, 12h
int 10h
mov si, str_c
call print_str ; print string c
mov ah, 0
int 16h
mov ah, 0
mov al, 12h
int 10h
mov cl, 0
mov si, current_color
call print_str
mov ah, 2 ; cursor positioning
mov bh, 0
mov dh, 0
mov dl, 20
int 10h
mov si, current_speed
call print_str
mov dx, 240 ; cursor to middle of screen
mov cx, 320
call color_screen
call speed_screen
jmp control ; start control
speed_screen:
mov word [temp1], dx
mov word [temp2], cx
mov al, byte [speed]
cmp al, 10
jge converter
add al, 48
mov ah, 2
mov bh, 0
mov dh, 0
mov dl, 35
int 10h
mov ah, 0xe
mov bl, 0xf
int 10h
xor al, al
mov ah, 0xe
mov bl, 0xf
int 10h
jmp end_speed_screen
converter:
xor ah, ah
mov bh, 10
div bh
add al, 48
mov cl, ah
add cl, 48
mov ah, 2
mov bh, 0
mov dh, 0
mov dl, 35
int 10h
mov ah, 0xe
mov bl, 0xf
int 10h
mov al, cl
mov ah, 0xe
mov bl, 0xf
int 10h
end_speed_screen:
mov dx, word [temp1]
mov cx, word [temp2]
pop ax
jmp ax
print_str:
lodsb
cmp cl, al
je end_print_str
mov ah, 0xe
mov bl, 0xf
int 10h
jmp print_str
end_print_str:
pop ax
jmp ax
color_screen:
mov word [temp1], dx
mov word [temp2], cx
mov cx, 115
mov dx, 2
mov bx, 10
mov word [j], bx
cc_col:
cmp word [j], 0
je cc_col_end
mov bx, 10
mov word [i], bx
mov cx, 115
cc_row:
cmp word [i], 0
je cc_row_end
mov bl, byte [user_color]
mov byte [color], bl
call paint
inc cx
mov bx, word [i]
dec bx
mov word [i], bx
jmp cc_row
cc_row_end:
inc dx
mov bx, word [j]
dec bx
mov word [j], bx
jmp cc_col
cc_col_end:
mov dx, word [temp1]
mov cx, word [temp2]
pop ax
jmp ax
control:
mov ah, 0
int 16h
mov bx, word [speed]
mov word [i], bx ; the paint loop's index variable receives the speed to paint a sequece of pixels through some vector defined by user's input controller
; paint controllers (to control the cursor while painting);
cmp al, 73h ; "s"
je paint_dot
cmp al, 58h ; 'X'
je paint_down
cmp al, 57h ; 'W'
je paint_up
cmp al, 44h ; 'D'
je paint_right
cmp al, 41h ; 'A'
je paint_left
cmp al, 43h ; 'C'
je paint_down_right
cmp al, 0x5a ; 'Z'
je paint_down_left
cmp al, 45h ; 'E'
je paint_up_right
cmp al, 51h ; 'Q'
je paint_up_left
; end paint controllers ;
; color ;
cmp al, 31h ; '1' Cor = Black
je colorBlack
cmp al, 32h; '2' Cor = Blue
je colorBlue
cmp al, 33h; '3'Cor = Green
je colorGreen
cmp al, 34h; '4'Cor = Cyan
je colorLGreen
cmp al, 35h; '5' Cor = Red
je colorCyan
cmp al, 36h; '6'Cor = Magenta
je colorMagenta
cmp al, 37h; '7'Cor = BRown
je colorBrown
cmp al, 38h; '8'Cor = Light Gray
je colorLGray
cmp al, 39h; '9'Cor = Dark Gray
je colorDGray
cmp al, 30h; '0'Cor = Light Blue
je colorLBlue
cmp al, 22h; '"'Cor = Light Green
je colorLGreen
cmp al, 21h; '!'Cor = Light Cyan
je colorLCyan
cmp al, 40h; '@'Cor = Light REd
je colorRed
cmp al, 23h; '#'Cor = Light MAgenta
je colorLMagenta
cmp al, 24h; '$'Cor = Yellow
je colorYellow
cmp al, 25h; '%'Cor = white
je colorWhite
; end color ;
; movement cursor (to control the cursor without painting);
cmp al, 78h ; 'x'
je move_down
cmp al, 77h ; 'w'
je move_up
cmp al, 64h ; 'd'
je move_right
cmp al, 61h ; 'a'
je move_left
cmp al, 63h ; 'c'
je move_down_right
cmp al, 0x7a ; 'z'
je move_down_left
cmp al, 65h ; 'e'
je move_up_right
cmp al, 71h ; 'q'
je move_up_left
; end moviment cursor ;
; brush color alternate ;
cmp al, 70h ; 'p'
je brush_color_change
; end brush color alternate ;
; change speed ;
cmp al, 0x2b ; '+'
je more_vel
cmp al, 0x2d ; '-'
je less_vel
; end change speed ;
; reset board (to erase all on the board);
cmp al, 0x3c ; '<'
je reset_board
; end reset board ;
; save (to save the project on hda (will be loaded by the kernel on startup));
; end save ;
; help ;
; end help ;
; quit (to quit);
cmp al, 0x1b
je quit
; end quit ;
jmp control ; no key recognized
; paint actions ;
paint_dot:
mov bl, byte [user_color]
mov byte [under_color], bl
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint_down:
cmp dx, word [down] ; vertical down limit to paint
je control
mov bl, byte [under_color]
mov byte [color], bl ; paint dot with original color (under_color)
call paint
inc dx ; movement
mov bl, byte [user_color]
mov byte [color], bl
call paint ; paint pixel and back
mov bl, byte [user_color]
mov byte [under_color], bl
mov bx, word [i]
cmp bx, 1
je paint_down_end ; if loop's reched the max speed, then, end loop
dec bx
mov word [i], bx ; else, decrement the loop's index variable
jmp paint_down
paint_down_end:
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint_up:
cmp dx, word [up]
je control
mov bl, byte [under_color]
mov byte [color], bl ; paint dot with original color (under_color)
call paint
dec dx
mov bl, byte [user_color]
mov byte [color], bl
call paint
mov bl, byte [user_color]
mov byte [under_color], bl
mov bx, word [i]
cmp bx, 1
je paint_up_end
dec bx
mov word [i], bx
jmp paint_up
paint_up_end:
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint_right:
cmp cx, word [right]
je control
mov bl, byte [under_color]
mov byte [color], bl ; paint dot with original color (under_color)
call paint
inc cx
mov bl, byte [user_color]
mov byte [color], bl
call paint
mov bl, byte [user_color]
mov byte [under_color], bl
mov bx, word [i]
cmp bx, 1
je paint_right_end
dec bx
mov word [i], bx
jmp paint_right
paint_right_end:
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint_left:
cmp cx, word [left]
je control
mov bl, byte [under_color]
mov byte [color], bl ; paint dot with original color (under_color)
call paint
dec cx
mov bl, byte [user_color]
mov byte [color], bl
call paint
mov bl, byte [user_color]
mov byte [under_color], bl
mov bx, word [i]
cmp bx, 1
je paint_left_end
dec bx
mov word [i], bx
jmp paint_left
paint_left_end:
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint_down_right:
cmp dx, word [down]
je control
cmp cx, word [right]
je control
mov bl, byte [under_color]
mov byte [color], bl ; paint dot with original color (under_color)
call paint
inc dx
inc cx
mov bl, byte [user_color]
mov byte [color], bl
call paint
mov bl, byte [user_color]
mov byte [under_color], bl
mov bx, word [i]
cmp bx, 1
je paint_down_right_end
dec bx
mov word [i], bx
jmp paint_down_right
paint_down_right_end:
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint_down_left:
cmp dx, word [down]
je control
cmp cx, word [left]
je control
mov bl, byte [under_color]
mov byte [color], bl ; paint dot with original color (under_color)
call paint
inc dx
dec cx
mov bl, byte [user_color]
mov byte [color], bl
call paint
mov bl, byte [user_color]
mov byte [under_color], bl
mov bx, word [i]
cmp bx, 1
je paint_down_left_end
dec bx
mov word [i], bx
jmp paint_down_left
paint_down_left_end:
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint_up_right:
cmp dx, word [up]
je control
cmp cx, word [right]
je control
mov bl, byte [under_color]
mov byte [color], bl ; paint dot with original color (under_color)
call paint
dec dx
inc cx
mov bl, byte [user_color]
mov byte [color], bl
call paint
mov bl, byte [user_color]
mov byte [under_color], bl
mov bx, word [i]
cmp bx, 1
je paint_up_right_end
dec bx
mov word [i], bx
jmp paint_up_right
paint_up_right_end:
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint_up_left:
cmp dx, word [up]
je control
cmp cx, word [left]
je control
mov bl, byte [under_color]
mov byte [color], bl ; paint dot with original color (under_color)
call paint
dec dx
dec cx
mov bl, byte [user_color]
mov byte [color], bl
call paint
mov bl, byte [user_color]
mov byte [under_color], bl
mov bx, word [i]
cmp bx, 1
je paint_up_left_end
dec bx
mov word [i], bx
jmp paint_up_left
paint_up_left_end:
mov bl, byte [brush_color]
mov byte [color], bl
call paint
jmp control
paint:
mov ah, 0xc
mov bh, 0
mov al, byte [color]
int 10h
pop ax
jmp ax
; end paint actions ;
; color actions ;
colorBlack:
mov byte[user_color], 0
call color_screen
jmp control
colorBlue:
mov byte[user_color], 1
call color_screen
jmp control
colorGreen:
mov byte[user_color], 2
call color_screen
jmp control
colorCyan:
mov byte[user_color], 3
call color_screen
jmp control
colorRed:
mov byte[user_color], 4
call color_screen
jmp control
colorMagenta:
mov byte[user_color], 5
call color_screen
jmp control
colorBrown:
mov byte[user_color], 6
call color_screen
jmp control
colorLGray:
mov byte[user_color], 7
call color_screen
jmp control
colorDGray:
mov byte[user_color], 8
call color_screen
jmp control
colorLBlue:
mov byte[user_color], 9
call color_screen
jmp control
colorLGreen:
mov byte[user_color] , 10
call color_screen
jmp control
colorLCyan:
mov byte[user_color], 11
call color_screen
jmp control
colorLRed:
mov byte[user_color], 12
call color_screen
jmp control
colorLMagenta:
mov byte[user_color], 13
call color_screen
jmp control
colorYellow:
mov byte[user_color], 14
call color_screen
jmp control
colorWhite:
mov byte[user_color], 15
call color_screen
jmp control
; end color actions ;
; movement cursor actions ;
move_down:
cmp dx, word [down]
je control
mov bl, byte [under_color]
mov byte [color], bl
call paint
inc dx ; move
mov ah, 0x0d
mov bh, 0
int 10h
mov byte [under_color], al
mov bl, byte [brush_color]
mov byte [color], bl
call paint
mov bx, word [i]
cmp bx, 1
je move_down_end
dec bx
mov word [i], bx
jmp move_down
move_down_end:
jmp control
move_up:
cmp dx, word [up]
je control
mov bl, byte [under_color]
mov byte [color], bl
call paint
dec dx ; move
mov ah, 0x0d
mov bh, 0
int 10h
mov byte [under_color], al
mov bl, byte [brush_color]
mov byte [color], bl
call paint
mov bx, word [i]
cmp bx, 1
je move_up_end
dec bx
mov word [i], bx
jmp move_up
move_up_end:
jmp control
move_right:
cmp cx, word [right]
je control
mov bl, byte [under_color]
mov byte [color], bl
call paint
inc cx ; move
mov ah, 0x0d ; get new under_color
mov bh, 0
int 10h
mov byte [under_color], al
mov bl, byte [brush_color]
mov byte [color], bl
call paint
mov bx, word [i]
cmp bx, 1
je move_right_end
dec bx
mov word [i], bx
jmp move_right
move_right_end:
jmp control
move_left:
cmp cx, word [left]
je control
mov bl, byte [under_color]
mov byte [color], bl
call paint
dec cx ; move
mov ah, 0x0d
mov bh, 0
int 10h
mov byte [under_color], al
mov bl, byte [brush_color]
mov byte [color], bl
call paint
mov bx, word [i]
cmp bx, 1
je move_left_end
dec bx
mov word [i], bx
jmp move_left
move_left_end:
jmp control
move_down_right:
cmp dx, word [down]
je control
cmp cx, word [right]
je control
mov bl, byte [under_color]
mov byte [color], bl
call paint
inc cx
inc dx
mov ah, 0x0d ; get new under_color
mov bh, 0
int 10h
mov byte [under_color], al
mov bl, byte [brush_color]
mov byte [color], bl
call paint
mov bx, word [i]
cmp bx, 1
je move_down_right_end
dec bx
mov word [i], bx
jmp move_down_right
move_down_right_end:
jmp control
move_down_left:
cmp dx, word [down]
je control
cmp cx, word [left]
je control
mov bl, byte [under_color]
mov byte [color], bl
call paint
dec cx
inc dx
mov ah, 0x0d ; get new under_color
mov bh, 0
int 10h
mov byte [under_color], al
mov bl, byte [brush_color]
mov byte [color], bl
call paint
mov bx, word [i]
cmp bx, 1
je move_down_left_end