-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asm
1301 lines (1104 loc) · 32.3 KB
/
main.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
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
TITLE Nome: Giovani Bellini dos Santos, RA: 22007263 | Nome: Joao Victor Rokemback Tapparo, RA:22003236
.model small
.stack 100h
;------------------------------------data------------------------------------
.data
horizontal_mouse_position dw ?
vertical_mouse_position dw ?
variable_a db ?
variable_b db ?
variable_c db ?
length_second_number db ?
length_first_number db ?
variable_d db ?
array_first_number db 40 dup (?)
array_second_number db 40 dup (?)
flag db ?
operator db ?
registered_character db ?
pixel_pointer db ?
input_value dw ?
output_value dw ?
;----------------------------------------------------------------------------
;---data initialization---
mov ax, @data
mov ds, ax
;---return to dos---
returning_dos macro
mov ah,4ch
int 21h
endm
;---cleaning the registers---
cleaning_registers macro
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
endm
;---set video mode---
setmode macro
mov ah,0
mov al,13h
int 10h
endm
;-----------------------------------lines------------------------------------
;to design the calculator as a general rule, macros were created to create
;modelable lines, so that you can make the design you want just by
;informing basic variables such as the size, its x, y and its color.
;---make a horizontal line---
horizontal_line_printer macro x,y,z,c
local l1 ;In the first directive, within a macro, LOCAL defines
;labels that are unique to each instance of the macro.
mov cx,x
mov dx,z
l1:
mov ah,0ch ;
mov al,c
int 10h
inc cx
cmp cx,y
jnz l1
endm
;---make a vertical line---
vertical_line_printer macro x,y,z,c
local l2
mov cx,z
mov dx,x
l2:
mov ah,0ch
mov al,c
int 10h
inc dx
cmp dx,y
jnz l2
endm
;---make a diagonal line---
diagonal_line_printer macro x,y,z,c
local l2
mov cx,z
mov dx,x
l2:
mov ah,0ch
mov al,c
int 10h
inc dx
inc cx
cmp dx,y
jnz l2
endm
;---make a inverted diagonal line---
inverted_diagonal_line_printer macro x,y,z,c
local l2
mov cx,z
mov dx,y
l2:
mov ah,0ch
mov al,c
int 10h
dec dx
inc cx
cmp dx,x
jnz l2
endm
;----------------------------------------------------------------------------
;------------------------------calculator edge-------------------------------
drawouter macro
;this macro has the function of creating and managing the edge of
;the calculator, being it the part that would imitate the housing
;of a real calculator
;---first border---
cleaning_registers
horizontal_line_printer 4,254,4,7
cleaning_registers
horizontal_line_printer 4,255,194,7
cleaning_registers
vertical_line_printer 4,194,4,7
cleaning_registers
vertical_line_printer 4,194,254,7
cleaning_registers
;---second border---
cleaning_registers
horizontal_line_printer 4,256,196,8
cleaning_registers
vertical_line_printer 4,197,256,8
endm
;----------------------------------------------------------------------------
;-----------------------------calculator display-----------------------------
calculator_display macro
;this part that shapes the look of the calculator display, that
;is, that rectangular border that surrounds the input and
;the output of the calculator
;---first border---
cleaning_registers
horizontal_line_printer 9,249,9,7
cleaning_registers
horizontal_line_printer 9,250,69,7
cleaning_registers
vertical_line_printer 9,69,9,7
cleaning_registers
vertical_line_printer 9,69,249,7
cleaning_registers
;-second border---
cleaning_registers
horizontal_line_printer 11,248,67,8
cleaning_registers
vertical_line_printer 11,67,11,8
endm
;----------------------------------------------------------------------------
;-----------------------------all buttons border-----------------------------
;here macros are made to create all the keycaps present in the calculator
;the macros are made to draw the border of the keycaps
default_button_border_printer macro x, y, c
cleaning_registers
horizontal_line_printer y,(y+39),x,c
cleaning_registers
horizontal_line_printer y,(y+39),(x+24),c
cleaning_registers
vertical_line_printer x,(x+24),y,c
cleaning_registers
vertical_line_printer x,(x+25),(y+39),c
cleaning_registers
endm
zero_button_border_printer macro x, y, c
cleaning_registers
horizontal_line_printer y,(y+39+40+60),x,c
cleaning_registers
horizontal_line_printer y,(y+39+40+60),(x+24),c
cleaning_registers
vertical_line_printer x,(x+25),y,c
cleaning_registers
vertical_line_printer x,(x+25),(y+39+40+60),c
cleaning_registers
endm
;----------------------------------------------------------------------------
;---------------------------button border printer----------------------------
button_border_printer macro
;this section of the code is entirely dedicated to creating borders
;around symbols and numerals working as if they were keycaps
;of a real calculator
;---default button border---
default_button_border_printer 74,9,3
default_button_border_printer 104,9,3
default_button_border_printer 134,9,3
default_button_border_printer 164,9,3
default_button_border_printer 74,59,15
default_button_border_printer 104,59,15
default_button_border_printer 134,59,15
default_button_border_printer 74,109,15
default_button_border_printer 104,109,15
default_button_border_printer 134,109,15
default_button_border_printer 74,159,15
default_button_border_printer 104,159,15
default_button_border_printer 134,159,15
default_button_border_printer 164,209,3
default_button_border_printer 74,209,3
default_button_border_printer 104,209,3
default_button_border_printer 134,209,3
;---zero button border---
zero_button_border_printer 164,59,15
endm
;----------------------------------------------------------------------------
;--------------------------print imput and output----------------------------
print_imput_output macro
;---print "imput:"---
character_printer 'i',2,2,11
character_printer 'n',2,3,11
character_printer 'p',2,4,11
character_printer 'u',2,5,11
character_printer 't',2,6,11
character_printer ':',2,7,11
;---print "output:"---
character_printer 'o',4+1,2,11
character_printer 'u',4+1,3,11
character_printer 't',4+1,4,11
character_printer 'p',4+1,5,11
character_printer 'u',4+1,6,11
character_printer 't',4+1,7,11
character_printer ':',4+1,8,11
endm
;----------------------------------------------------------------------------
;-------------------------numeral symbols from 1 to 9------------------------
;this part of the code is several macros that will create the design of
;the digits that will appear on the calculator keyboard, and each one
;will be in its proper square (key)
number_0_printer macro x,y
horizontal_line_printer (y-4),(y+4),x-8,15
horizontal_line_printer (y-4),(y+4),x+8,15
vertical_line_printer (x-8),(x+8),(y-4),15
vertical_line_printer (x-8),(x+9),(y+4),15
endm
number_1_printer macro x,y
vertical_line_printer (x-8),(x+8),(y+4),15
endm
number_2_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,15
horizontal_line_printer (y-4),(y+5),x-8,15
horizontal_line_printer (y-4),(y+4),x+8,15
vertical_line_printer (x),(x+9),(y-4),15
vertical_line_printer (x-8),(x+1),(y+4),15
endm
number_3_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,15
horizontal_line_printer (y-4),(y+4),x-8,15
horizontal_line_printer (y-4),(y+4),x+8,15
vertical_line_printer (x-8),(x+9),(y+4),15
endm
number_4_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,15
vertical_line_printer (x-8),(x),(y-4),15
vertical_line_printer (x-8),(x+8),(y+4),15
endm
number_5_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,15
horizontal_line_printer (y-4),(y+4),x-8,15
horizontal_line_printer (y-4),(y+5),x+8,15
vertical_line_printer (x-8),(x),(y-4),15
vertical_line_printer (x),(x+8),(y+4),15
endm
number_6_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,15
horizontal_line_printer (y-4),(y+4),x-8,15
horizontal_line_printer (y-4),(y+5),x+8,15
vertical_line_printer (x-8),(x+8),(y-4),15
vertical_line_printer x,(x+8),(y+4),15
endm
number_7_printer macro x,y
horizontal_line_printer (y-4),(y+4),x-8,15
vertical_line_printer (x-8),(x+8),(y+4),15
endm
number_8_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,15
horizontal_line_printer (y-4),(y+4),x-8,15
horizontal_line_printer (y-4),(y+5),x+8,15
vertical_line_printer (x-8),(x+8),(y-4),15
vertical_line_printer (x-8),(x+8),(y+4),15
endm
number_9_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,15
horizontal_line_printer (y-4),(y+4),x-8,15
horizontal_line_printer (y-4),(y+4),x+8,15
vertical_line_printer (x-8),(x),(y-4),15
vertical_line_printer (x-8),(x+9),(y+4),15
endm
;----------------------------------------------------------------------------
;------------------plus, minus, multiply and divide symbols------------------
;this part of the code is several macros that will create the design of the
;plus, minus, multiplication and division symbols that will appears on the
;calculator keyboard, and each will be in its appropriate square (key)
plus_symbol_printer macro x,y
horizontal_line_printer (y-4),(y+4+1),x,3
vertical_line_printer (x-4),(x+4+1),(y),3
endm
minus_symbol_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,3
endm
multiply_symbol_printer macro
diagonal_line_printer 110+3,118+4,14+11,3
diagonal_line_printer 110+3,118+4,14+10,3
diagonal_line_printer 110+3,118+4,14+9,3
inverted_diagonal_line_printer 110+2,118+3,14+11,3
inverted_diagonal_line_printer 110+2,118+3,14+10,3
inverted_diagonal_line_printer 110+2,118+3,14+9,3
endm
divide_symbol_printer macro x,y
horizontal_line_printer (y-4),(y+4),x,3
horizontal_line_printer (y-1),(y+1),x-3,3
horizontal_line_printer (y-1),(y+1),x-4,3
horizontal_line_printer (y-1),(y+1),x+3,3
horizontal_line_printer (y-1),(y+1),x+4,3
endm
;----------------------------------------------------------------------------
;--------------------------function buttons symbols--------------------------
;this part of the code is several macros that will create the drawing
;of the AC and equal symbols appears on the calculator keyboard, and
; each will be in its appropriate square (key)
ac_symbol_printer macro x,y
horizontal_line_printer (y-4+6),(y+4+6),x-8,3
horizontal_line_printer (y-4+6),(y+4+6),x+8,3
vertical_line_printer (x-8),(x+8),(y-4+6),3
horizontal_line_printer (y-4-6),(y+4-6),x,3
horizontal_line_printer (y-4-6),(y+4-6),x-8,3
vertical_line_printer (x-8),(x+8+1),(y-4-6),3
vertical_line_printer (x-8),(x+8+1),(y+4-6),3
endm
equal_symbol_printer macro x,y
horizontal_line_printer (y-6),(y+6),x-2,3
horizontal_line_printer (y-6),(y+6),x+1,3
horizontal_line_printer (y-6),(y+6),x-3,3
horizontal_line_printer (y-6),(y+6),x+0,3
endm
;----------------------------------------------------------------------------
;----------------------------------symbols----------------------------------
symbols_printer macro
;this part of the code is responsible for printing all
;the drawings that will be on the calculator keyboard
;---number 0---
number_0_printer (164+12),(59+69)
number_0_printer (164+12),(59+70)
number_0_printer (164+12),(59+71)
;---number 1---
number_1_printer (134+12),(59+19)
number_1_printer (134+12),(59+20)
number_1_printer (134+12),(59+21)
;---number 2---
number_2_printer (134+12),(109+19)
number_2_printer (134+12),(109+20)
number_2_printer (134+12),(109+21)
;---number 3---
number_3_printer (134+12),(159+19)
number_3_printer (134+12),(159+20)
number_3_printer (134+12),(159+21)
;---number 4---
number_4_printer (104+12),(59+19)
number_4_printer (104+12),(59+20)
number_4_printer (104+12),(59+21)
;---number 5---
number_5_printer (104+12),(109+19)
number_5_printer (104+12),(109+20)
number_5_printer (104+12),(109+21)
;---number 6---
number_6_printer (104+12),(159+19)
number_6_printer (104+12),(159+20)
number_6_printer (104+12),(159+21)
;---number 7---
number_7_printer (74+12),(59+19)
number_7_printer (74+12),(59+20)
number_7_printer (74+12),(59+21)
;---number 8---
number_8_printer (74+12),(109+19)
number_8_printer (74+12),(109+20)
number_8_printer (74+12),(109+21)
;---number 9---
number_9_printer (74+12),(159+19)
number_9_printer (74+12),(159+20)
number_9_printer (74+12),(159+21)
;---off---
character_printer 'o',22,27,3
character_printer 'f',22,28,3
character_printer 'f',22,29,3
;---plus---
plus_symbol_printer (164+12),(9+19)
plus_symbol_printer(164+12),(9+20)
plus_symbol_printer(164+12),(9+21)
plus_symbol_printer(164+11),(9+20)
plus_symbol_printer(164+13),(9+20)
;---minus---
minus_symbol_printer (134+12),(9+19)
minus_symbol_printer(134+12),(9+20)
minus_symbol_printer(134+12),(9+21)
minus_symbol_printer(134+11),(9+20)
minus_symbol_printer(134+13),(9+20)
;---multiply---
multiply_symbol_printer(104+12),(9+20)
;---divide---
divide_symbol_printer (74+12),(9+19)
divide_symbol_printer(74+12),(9+20)
divide_symbol_printer(74+12),(9+21)
divide_symbol_printer(74+11),(9+20)
divide_symbol_printer(74+13),(9+20)
;---AC---
ac_symbol_printer (104+12),(209+21)
ac_symbol_printer(104+12),(209+20)
ac_symbol_printer(104+12),(209+19)
;---dell---
character_printer 'd',11,27,3
character_printer 'e',11,28,3
character_printer 'l',11,29,3
character_printer 'l',11,30,3
;---equal---
equal_symbol_printer(134+16),(209+20)
endm
;----------------------------------------------------------------------------
;---------------------------printing a character-----------------------------
character_printer macro character,r,c,col
;character_printer is a macro created to facilitate writing on the
;screen, whenever you need to print a character just use
;character_printer 'c',row,column,color
;---set background/border color---
mov ah,0bh
mov bh,0h ;if bh were equal to 01h he would set palette
mov bl,3
int 10h
;---set cursor position---
mov ah,2
mov bh,0
mov dh,r
mov dl,c
int 10h
;---write character and attribute at cursor position---
mov ah,9
mov al, character
mov bl,col
mov cx,1
int 10h
endm
;----------------------------------------------------------------------------
;-----------------------------------mouse------------------------------------
initialize_mouse_cursor macro
xor ax, ax
int 33h ;mouse reset/get mouse installed flag
mov ax,1 ;show mouse cursor
int 33h
endm
;----------------------------------------------------------------------------
;-------------------------------mouse position-------------------------------
;this part of the code serves to inform the position where the mouse
;is, to be able, for example, to click on a button
mouse_position macro vertical,horizontal
local greater_than_horizontal,greater_than_vertical,cc3,less_than_horizontal,less_than_vertical,end_mouse_position_comparison
mov ax,horizontal_mouse_position
mov bx,vertical_mouse_position
xor cx, cx
cmp ax,horizontal
jge greater_than_horizontal
jmp end_mouse_position_comparison
greater_than_horizontal: ;if horizontal_mouse_position is
;greater than horizontal
sub ax,horizontal
cmp ax,40
jle less_than_horizontal
jmp end_mouse_position_comparison
less_than_horizontal: ;if horizontal_mouse_position is less
;than horizontal
inc cx
cmp bx,vertical
jge greater_than_vertical
jmp end_mouse_position_comparison
greater_than_vertical: ;if vertical_mouse_position is
;greater than vertical
sub bx,vertical
cmp bx,25
jle less_than_vertical
jmp end_mouse_position_comparison
less_than_vertical: ;if vertical_mouse_position is
;less than vertical
inc cx
jmp end_mouse_position_comparison
end_mouse_position_comparison:
endm
;----------------------------------------------------------------------------
;-----------------------------pressed character------------------------------
pressed_character macro
local end_pressed_character
local register_equal,register_ac,register_dell,register_off
local register_0,register_1,register_2,register_3,register_4,register_5,register_6,register_7,register_8,register_9
local register_plus,register_minus,register_multiply,register_divide
local mouse_on_ac_button,mouse_on_dell_button,mouse_on_off_button
local mouse_on_0_button,mouse_on_1_button,mouse_on_2_button,mouse_on_3_button,mouse_on_4_button,mouse_on_5_button,mouse_on_6_button,mouse_on_7_button,mouse_on_8_button,mouse_on_9_button
local mouse_on_plus_button,mouse_on_minus_button,mouse_on_multiply_button,mouse_on_divide_button
;whenever you use the local directive it cannot contain spaces
;because otherwise it will give an error
;local directive order
;---local end---
;---local registers functions---
;---local registers numbers---
;---local registers operations---
;---local mouse position functions---
;---local mouse position numbers---
;---local mouse position operations---
mouse_on_equal_button:
mouse_position 134,209 ;if the mouse is on the equal button
cmp cx,2
je register_equal ;if cx is equal to 2, then the mouse is on the equal button
cmp cx,2
jne mouse_on_ac_button ;if the mouse is not on the equal button
register_equal:
mov cl, '=' ;if the mouse is on the equal button, then cl will be equal to '='
mov registered_character,cl
mouse_on_ac_button:
mouse_position 104,209
cmp cx,2
je register_ac
cmp cx,2
jne mouse_on_dell_button
register_ac:
mov cl, 'a'
mov registered_character,cl
mouse_on_dell_button:
mouse_position 74,209
cmp cx,2
je register_dell
cmp cx,2
jne mouse_on_off_button
register_dell:
mov cl, 'c'
mov registered_character,cl
mouse_on_off_button:
mouse_position 164,209
cmp cx,2
je register_off
cmp cx,2
jne mouse_on_0_button
register_off:
mov cl, '*'
mov registered_character,cl
mouse_on_0_button:
mouse_position 164,120
cmp cx,2
je register_0
cmp cx,2
jne mouse_on_1_button
register_0:
mov cl, '0'
mov registered_character,cl
mouse_on_1_button:
mouse_position 134,59
cmp cx,2
je register_1
cmp cx,2
jne mouse_on_2_button
register_1:
mov cl, '1'
mov registered_character,cl
mouse_on_2_button:
mouse_position 134,109
cmp cx,2
je register_2
cmp cx,2
jne mouse_on_3_button
register_2:
mov cl, '2'
mov registered_character,cl
mouse_on_3_button:
mouse_position 134,159
cmp cx,2
je register_3
cmp cx,2
jne mouse_on_4_button
register_3:
mov cl, '3'
mov registered_character,cl
mouse_on_4_button:
mouse_position 104,59
cmp cx,2
je register_4
cmp cx,2
jne mouse_on_5_button
register_4:
mov cl, '4'
mov registered_character,cl
mouse_on_5_button:
mouse_position 104,109
cmp cx,2
je register_5
cmp cx,2
jne mouse_on_6_button
register_5:
mov cl, '5'
mov registered_character,cl
mouse_on_6_button:
mouse_position 104,159
cmp cx,2
je register_6
cmp cx,2
jne mouse_on_7_button
register_6:
mov cl, '6'
mov registered_character,cl
mouse_on_7_button:
mouse_position 74,59
cmp cx,2
je register_7
cmp cx,2
jne mouse_on_8_button
register_7:
mov cl, '7'
mov registered_character,cl
mouse_on_8_button:
mouse_position 74,109
cmp cx,2
je register_8
cmp cx,2
jne mouse_on_9_button
register_8:
mov cl, '8'
mov registered_character,cl
mouse_on_9_button:
mouse_position 74,159
cmp cx,2
je register_9
cmp cx,2
jne mouse_on_plus_button
register_9:
mov cl, '9'
mov registered_character,cl
mouse_on_plus_button:
mouse_position 164,9
cmp cx,2
je register_plus
cmp cx,2
jne mouse_on_minus_button
register_plus:
mov cl, '+'
mov registered_character,cl
mouse_on_minus_button:
mouse_position 134,9
cmp cx,2
je register_minus
cmp cx,2
jne mouse_on_multiply_button
register_minus:
mov cl, '-'
mov registered_character,cl
mouse_on_multiply_button:
mouse_position 104,9
cmp cx,2
je register_multiply
cmp cx,2
jne mouse_on_divide_button
register_multiply:
mov cl, 'x'
mov registered_character,cl
mouse_on_divide_button:
mouse_position 74,9
cmp cx,2
je register_divide
cmp cx,2
jne end_pressed_character
register_divide:
mov cl, '/'
mov registered_character,cl
jmp end_pressed_character
end_pressed_character:
endm
;----------------------------------------------------------------------------
;-------------------------------mouse pressed--------------------------------
mouse_pressed macro
local jump_ac,jump_off
local jump_plus,jump_minus,jump_multiply,jump_divide
local plus,multiply,minus,divide,check
local number_1,number_2,final,not_number,proceed
;if the mouse is pressed, then the mouse will be registered
pressed_character
;---dell---
mov cl,'c'
cmp registered_character,cl
jne jump_ac
xor dl,dl
cmp length_first_number,dl
je jump_ac
dec length_first_number
dec pixel_pointer
character_printer ' ',3,pixel_pointer,0 ;dell the last character
;---ac---
jump_ac:
mov cl,'a'
cmp registered_character,cl
jne jump_off
initializing_variables
cleaning_screen
;---off---
jump_off:
mov cl,'*'
cmp registered_character,cl
jne jump_plus
returning_dos
;---plus---
jump_plus:
mov cl,'+'
cmp registered_character,cl
jne jump_minus
mov operator,cl
character_printer '+',2,28,11 ;print the operator on the screen
mov dl,1
cmp flag,dl
je plus
cmp flag,dl
jne jump_minus
plus:
mov bl,2
mov flag,bl
mov pixel_pointer,bl
call clear
;---minus---
jump_minus:
mov cl,'-'
cmp registered_character,cl
jne jump_multiply
mov operator,cl
character_printer '-',2,28,11 ;print the operator on the screen
mov dl,1
cmp flag,dl
je minus
cmp flag,dl
jne jump_multiply
minus:
mov bl,2
mov flag,bl
mov pixel_pointer,bl
call clear
;---multiply---
jump_multiply:
mov cl,'x'
cmp registered_character,cl
jne jump_divide
mov operator,cl
character_printer 'x',2,28,11 ;print the operator on the screen
mov dl,1
cmp flag,dl
je multiply
cmp flag,dl
jne jump_divide
multiply:
mov bl,2
mov flag,bl
mov pixel_pointer,bl
call clear
;---divide---
jump_divide:
mov cl,'/'
cmp registered_character,cl
jne check
mov operator,cl
character_printer '/',2,28,11 ;print the operator on the screen
mov dl,1
cmp flag,dl
je divide
cmp flag,dl
jne check
divide: ;
mov bl,2
mov flag,bl
mov pixel_pointer,bl
call clear
;---check---
check:
mov cl,registered_character ;if the character is a number, then
;it will be printed
cmp cl,'0'
jl not_number ;if the character is not a number, then
;it will not be printed
cmp cl,'9'
jg not_number
mov cl,1
cmp flag,cl ;if the character is a number, then
;it will be printed
je number_1 ;number_1 is the first number
mov cl,2
cmp flag,cl ;flag is 2, then it will be printed in
;the second number
je number_2
not_number:
jmp final
number_1:
first_number_entered
jmp final
number_2:
second_number_entered
jmp final
final:
mov cl,'='
cmp registered_character,cl ;if the character is =, then the
;result will be printed
jne proceed
call mathematical_resolution
proceed:
endm
;----------------------------------------------------------------------------
;----------------------------first number entered----------------------------
first_number_entered macro
;this part of the server code to get the first number pressed and
;display it on the calculator display
xor cx,cx
mov cl,length_first_number ;length_first_number is the number of
;characters in the first number
mov si,cx ;si is the number of characters in the first number
mov cl,registered_character ;cl is the character pressed
mov array_first_number[si],cl ;array_first_number is the array that
;contains the first number
inc length_first_number
;---display the first number---
character_printer registered_character,3,pixel_pointer,15
;---increment the pixel pointer---
inc pixel_pointer ;it is necessary to increment 1 pixel on
;the display because if not, whenever a
;composite number was typed, for example
;12, after pressing 1 and then 2, the
;number 2 would overlap 1
endm
;----------------------------------------------------------------------------
;---------------------------second number entered----------------------------
second_number_entered macro
;this part of the server code to get the second number pressed and
;display it on the calculator display
xor cx,cx
mov cl,length_second_number ;length_second_number is the length of the
;second number
mov si,cx
mov cl,registered_character
mov array_second_number[si],cl ;array_second_number is the array that
;stores the second number
inc length_second_number
;---display the second number---
character_printer registered_character,3,pixel_pointer,15
;---increment the pixel pointer---
inc pixel_pointer
endm
;----------------------------------------------------------------------------
;----------------------------cleaning the screen-----------------------------
cleaning_screen macro
local cleaning_loop
;without that part of code every time you type some operation the program
;would keep the old digits, for example if i wanted to perform an
;operation: 50 x 2 = 100 when typing the 2 keep the 0 of the 50 because
;it didn't clear the screen, it just put 2 in front of the 5, making
;it equal to 50 x 20 = 100
mov cl,2
mov variable_a,cl
cleaning_loop:
character_printer ' ',3,variable_a,0
character_printer ' ',6,variable_a,0
inc variable_a