-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClickomania.asm
1954 lines (1658 loc) · 31.5 KB
/
Clickomania.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
.386
.586
.model flat, stdcall
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;includem biblioteci, si declaram ce functii vrem sa importam
includelib msvcrt.lib
extern exit: proc
extern malloc: proc
extern memset: proc
extern exit: proc
extern fclose: proc
extern fscanf: proc
extern fopen: proc
extern fprintf: proc
extern printf: proc
extern fgets: proc
extern rand: proc
extern srand: proc
extern time: proc
includelib canvas.lib
extern BeginDrawing: proc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;declaram simbolul start ca public - de acolo incepe executia
public start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;sectiunile programului, date, respectiv cod
.data
;aici declaram date
contor_nickname DD 0
mode_read DB "r", 0
mode_write DB "w", 0
mode_append DB "a", 0
file_name DB "scores.txt", 0
pointer_file_name DD 0
file_name_old DB "scores_old.txt", 0
pointer_file_name_old DD 0
started DB 0
nickname_score_format DB "%s %d",0ah,0
hexa_format DB "%x", 0ah, 0
decimal_format DB "%d", 0ah, 0
string_format DB "%s", 0ah, 0
decimal_formatx2 DB "%d %d", 0ah, 0
window_title DB "LaurCrush",0
area_width EQU 600;640
area_height EQU 1000;480
game_color DD 0
cluster_size DD 100
actual_score DD 0
inceput_linii_orizontale DD 200
contor_linii_orizontale DD 199
inceput_linii_verticale DD 0
contor_linii_verticale DD 0
inceput_matrice_x DD 0
inceput_matrice_y DD 200
contor_matrice_x DD 0
contor_matrice_x1 DD 0
contor_matrice_y DD 200
contor_matrice_y1 DD 200
colors DD 0f21111h,01149f2h,0ba04b1h,038ed24h,0fffc4ah
area DD 0
areav DD 0
areas DD 0
clickcolor DD 0
pixel1color DD 0
pixel2color DD 0
redc dd 0f21111h
bluec dd 01149f2h
violetc dd 0ba04b1h
greenc dd 038ed24h
yellowc dd 0fffc4ah
counter DD 0 ; numara evenimentele de tip timer
arg1 EQU 8
arg2 EQU 12
arg3 EQU 16
arg4 EQU 20
symbol_width EQU 10
symbol_height EQU 20
high_score DD 0
nickname DB 50 dup(0)
nickname_de_aruncat DB 50 dup(0)
scor_de_aruncat DD 0
game_over DD 1
coordx DD 0
coordy DD 0
game_over_size DD 0
disable_click DD 0
disable_timer DD 0
include digits.inc
include letters.inc
.code
; procedura make_text afiseaza o litera sau o cifra la coordonatele date
; arg1 - simbolul de afisat (litera sau cifra)
; arg2 - pointer la vectorul de pixeli
; arg3 - pos_x
; arg4 - pos_y
update_highscore proc
push ebp
mov ebp, esp
pusha
; mov ecx,actual_score
; cmp ecx,high_score
; jbe nimic
;mov high_score,ecx
push offset mode_write
push offset file_name_old
call fopen
add esp,8
mov pointer_file_name_old,eax
push offset mode_read
push offset file_name
call fopen
add esp,8
mov pointer_file_name,eax
mov edi,1
bucla_citire_pana_la_final:
push offset scor_de_aruncat
push offset nickname_de_aruncat
push offset nickname_score_format
mov eax,pointer_file_name
push eax
call fscanf
add esp,16
mov eax,scor_de_aruncat
cmp eax,actual_score
ja skip_scriere_actual
cmp edi,1
jne skip_scriere_actual
mov eax,actual_score
push eax
push offset nickname
push offset nickname_score_format
mov eax,pointer_file_name_old
push eax
call fprintf
add esp,16
dec edi
skip_scriere_actual:
mov eax,scor_de_aruncat
push eax
push offset nickname_de_aruncat
push offset nickname_score_format
mov eax,pointer_file_name_old
push eax
call fprintf
add esp,16
cmp scor_de_aruncat,0
jne bucla_citire_pana_la_final
mov eax,pointer_file_name
push eax
call fclose
add esp,4
mov eax,pointer_file_name_old
push eax
call fclose
add esp,4
push offset mode_read
push offset file_name_old
call fopen
add esp,8
mov pointer_file_name_old,eax
push offset mode_write
push offset file_name
call fopen
add esp,8
mov pointer_file_name,eax
bucla_scriere_pana_la_final:
push offset scor_de_aruncat
push offset nickname_de_aruncat
push offset nickname_score_format
mov eax,pointer_file_name_old
push eax
call fscanf
add esp,16
mov eax,scor_de_aruncat
push eax
push offset nickname_de_aruncat
push offset nickname_score_format
mov eax,pointer_file_name
push eax
call fprintf
add esp,16
cmp scor_de_aruncat,0
jne bucla_scriere_pana_la_final
mov eax,pointer_file_name
push eax
call fclose
add esp,4
mov eax,pointer_file_name_old
push eax
call fclose
add esp,4
nimic:
popa
mov esp, ebp
pop ebp
ret
update_highscore endp
get_highscore proc
push ebp
mov ebp, esp
pusha
push offset mode_read
push offset file_name
call fopen
add esp,8
push eax
push offset high_score
push offset nickname_de_aruncat
push offset nickname_score_format
push eax
call fscanf
add esp,16
pop eax
push eax
call fclose
add esp,4
popa
mov esp, ebp
pop ebp
ret
get_highscore endp
last_col_grey_macro macro
local bucla_linie,bucla_verticala,bucla_jos_sus,nimic,inceput,bucla_stanga_dreapta
mov eax,200
mov ebx,area_width
mul ebx
add eax,area_width-40
shl eax,2
add eax,area
mov contor_matrice_y,200
bucla_verticala:
mov contor_matrice_x,560
bucla_orizontala:
mov dword ptr[eax],0c2c2c2c2h
add eax,4
inc contor_matrice_x
cmp contor_matrice_x,area_width
jne bucla_orizontala
add eax,4*area_width
sub eax,160
inc contor_matrice_y
cmp contor_matrice_y,area_height
jne bucla_verticala
endm
last_col_grey_proc proc
push ebp
mov ebp, esp
pusha
last_col_grey_macro
popa
mov esp, ebp
pop ebp
ret
last_col_grey_proc endp
go_left_macro macro
local bucla_linie,bucla_verticala,bucla_jos_sus,nimic,inceput,bucla_stanga_dreapta
mov eax,area_height
mov ebx,area_width
mul ebx
add eax,area_width
shl eax,2
sub eax,8*area_width
add eax,area
mov contor_matrice_x,0
mov contor_matrice_y,area_height
bucla_linie:
cmp dword ptr [eax],0c2c2c2c2h
jne nimic
cmp dword ptr [eax+160],0c2c2c2c2h
je nimic
inceput:
push eax
mov contor_matrice_y,area_height
bucla_jos_sus:
mov ecx,contor_matrice_x
mov contor_matrice_x1,ecx
push eax
bucla_stanga_dreapta:
mov ecx,dword ptr [eax+4]
mov dword ptr [eax],ecx
; pusha
; push 2
; push offset decimal_format
; call printf
; add esp,8
; popa
add eax,4
inc contor_matrice_x1
cmp contor_matrice_x1,area_width-40
jne bucla_stanga_dreapta
pop eax
sub eax,4*area_width
dec contor_matrice_y
cmp contor_matrice_y,200
jae bucla_jos_sus
pop eax
cmp dword ptr [eax],0c2c2c2c2h
je inceput
call last_col_grey_proc
nimic:
add eax,4
inc contor_matrice_x
cmp contor_matrice_x,area_width-41
jbe bucla_linie
endm
go_left_proc proc
push ebp
mov ebp, esp
pusha
go_left_macro
popa
mov esp, ebp
pop ebp
ret
go_left_proc endp
update_lines_macro macro
local bucla_orizontala,bucla_verticala,nimic,if1,if2,if3
xor edx,edx
xor eax,eax
add edx, area
add eax, areas
mov ebx, area_height
dec ebx
bucla_verticala:
mov contor_matrice_x,area_width
bucla_orizontala:
; cmp dword ptr [edx],0c2c2c2h
; jne if1
; mov dword ptr [eax],0c2c2c2h
; if1:
; cmp dword ptr [edx],0c2c2c2c2h
; jne if2
; mov dword ptr [eax],0c2c2c2h
if2:
mov ecx,dword ptr [eax]
cmp ecx,dword ptr [eax+4]
je if3
mov dword ptr [eax],0
if3:
cmp ecx,dword ptr [eax+4*area_width]
je nimic
mov dword ptr [eax],0
nimic:
add eax,4
add edx,4
dec contor_matrice_x
jnz bucla_orizontala
dec ebx
jnz bucla_verticala
endm
update_lines_proc proc
push ebp
mov ebp, esp
pusha
update_lines_macro
popa
mov esp, ebp
pop ebp
ret
update_lines_proc endp
update_area_macro macro
local bucla_orizontala,bucla_verticala
xor edx,edx
xor eax,eax
add edx, area
add eax, areas
mov ebx, area_height
bucla_verticala:
mov contor_matrice_x,area_width
bucla_orizontala:
mov ecx,dword ptr[eax]
mov dword ptr[edx],ecx
add eax,4
add edx,4
dec contor_matrice_x
jnz bucla_orizontala
dec ebx
jnz bucla_verticala
endm
update_area_proc proc
push ebp
mov ebp, esp
pusha
update_area_macro
popa
mov esp, ebp
pop ebp
ret
update_area_proc endp
color_macrov macro x, y, color
local coloreaza,nimic,final
mov ecx,x
cmp ecx,area_width
jae nimic
mov ecx,y
cmp ecx,area_height
jae nimic
mov ecx,y
cmp ecx,199
jb nimic
mov ecx,x
cmp ecx,0
jb nimic
mov eax,y
mov ebx, area_width
mul ebx
add eax,x
shl eax, 2
add eax, areav
mov ecx,dword ptr [eax]
cmp ecx,0c2c2c2h
je nimic
cmp ecx,0c2c2c2c2h
je nimic
cmp ecx,0
je nimic
cmp ecx,0ffffffh
je nimic
cmp ecx,clickcolor
je coloreaza
; cmp ecx,0
; je coloreaza
jmp nimic
coloreaza:
mov dword ptr [eax],0c2c2c2h
mov eax,-1
jmp final
coloreaza_alb:
mov dword ptr [eax],0c2c2c2h
mov eax,-1
jmp final
nimic:
mov eax,0
final:
endm
color_procv proc
push ebp
mov ebp, esp
pusha
; push [ebp+arg2]
; push [ebp+arg1]
; push offset decimal_formatx2
; call printf
; add esp,12
color_macrov [ebp+arg1], [ebp+arg2],clickcolor
cmp eax,0
je return
;
; add dword ptr [ebp+arg1],1
; push [ebp+arg2]
; push [ebp+arg1]
; call color_proc
; add esp,12
sub dword ptr [ebp+arg1],1
push [ebp+arg2]
push [ebp+arg1]
call color_procv
add esp,8
add dword ptr [ebp+arg1],1
add dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call color_procv
add esp,8
add dword ptr [ebp+arg1],1
sub dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call color_procv
add esp,8
sub dword ptr [ebp+arg1],1
sub dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call color_procv
add esp,8
return:
popa
mov esp, ebp
pop ebp
ret
color_procv endp
go_down_macro macro
local bucla_orizontala,bucla_verticala,bucla_jos_sus,nimic,inceput
mov eax,area_height
mov ebx,area_width
mul ebx
add eax,area_width
shl eax,2
add eax,area
sub eax,8*area_width
mov contor_matrice_y,area_height
bucla_verticala:
mov contor_matrice_x,area_width
add eax,4*area_width
bucla_orizontala:
cmp dword ptr [eax],0c2c2c2h
jne nimic
cmp dword ptr [eax-4*area_width],0c2c2c2h
jne nimic
inceput:
push eax
mov ecx,contor_matrice_y
mov contor_matrice_y1,ecx
bucla_jos_sus:
mov ecx,dword ptr [eax-4*area_width]
mov dword ptr [eax],ecx
sub eax,4*area_width
dec contor_matrice_y1
cmp contor_matrice_y1,200
jne bucla_jos_sus
pop eax
cmp dword ptr [eax],0c2c2c2h
je inceput
nimic:
sub eax,4
dec contor_matrice_x
cmp contor_matrice_x,-1
jne bucla_orizontala
sub eax,4*area_width
dec contor_matrice_y
cmp contor_matrice_y,200
jne bucla_verticala
; mov contor_matrice_y,area_height
; bucla_verticala:
; mov dword ptr [eax],0
; push eax
; push contor_matrice_y
; push offset decimal_format
; call printf
; add esp,8
; pop eax
; sub eax,4*area_width
; dec contor_matrice_y
; cmp contor_matrice_y,200
; jne bucla_verticala
endm
go_down_proc proc
push ebp
mov ebp, esp
pusha
go_down_macro
popa
mov esp, ebp
pop ebp
ret
go_down_proc endp
is_valid_macro macro x, y, color
local coloreaza,nimic,final
mov ecx,x
cmp ecx,area_width
jae nimic
mov ecx,y
cmp ecx,area_height
jae nimic
mov ecx,y
cmp ecx,199
jb nimic
mov ecx,x
cmp ecx,0
jb nimic
mov eax,y
mov ebx, area_width
mul ebx
add eax,x
shl eax, 2
add eax, areav
mov ecx,dword ptr [eax]
cmp ecx,0c2c2c2h
je nimic
cmp ecx,0c2c2c2c2h
je nimic
cmp ecx,0
je nimic
cmp ecx,0ffffffh
je nimic
cmp ecx,clickcolor
je coloreaza
; cmp ecx,0
; je coloreaza
jmp nimic
coloreaza:
mov dword ptr [eax],0c2c2c2h
inc cluster_size
mov eax,-1
jmp final
coloreaza_alb:
mov dword ptr [eax],0ffffffh
mov eax,-1
jmp final
nimic:
mov eax,0
final:
endm
is_valid_proc proc
push ebp
mov ebp, esp
pusha
; push [ebp+arg2]
; push [ebp+arg1]
; push offset decimal_formatx2
; call printf
; add esp,12
is_valid_macro [ebp+arg1], [ebp+arg2],clickcolor
; pusha
; push esp
; push offset hexa_format
; call printf
; add esp,8
; popa
cmp eax,0
je return
;
; add dword ptr [ebp+arg1],1
; push [ebp+arg2]
; push [ebp+arg1]
; call is_valid_proc
; add esp,12
sub dword ptr [ebp+arg1],1
push [ebp+arg2]
push [ebp+arg1]
call is_valid_proc
add esp,8
add dword ptr [ebp+arg1],1
add dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call is_valid_proc
add esp,8
add dword ptr [ebp+arg1],1
sub dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call is_valid_proc
add esp,8
sub dword ptr [ebp+arg1],1
sub dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call is_valid_proc
add esp,8
return:
popa
mov esp, ebp
pop ebp
ret
is_valid_proc endp
update_areas_macro macro
local bucla_orizontala,bucla_verticala
xor edx,edx
xor eax,eax
add edx, areas
add eax, area
mov ebx, area_height
bucla_verticala:
mov contor_matrice_x,area_width
bucla_orizontala:
mov ecx,dword ptr[eax]
mov dword ptr[edx],ecx
add eax,4
add edx,4
dec contor_matrice_x
jnz bucla_orizontala
dec ebx
jnz bucla_verticala
endm
update_areas_proc proc
push ebp
mov ebp, esp
pusha
update_areas_macro
popa
mov esp, ebp
pop ebp
ret
update_areas_proc endp
update_areav_macro macro
local bucla_orizontala,bucla_verticala
xor edx,edx
xor eax,eax
add edx, areav
add eax, area
mov ebx, area_height
bucla_verticala:
mov contor_matrice_x,area_width
bucla_orizontala:
mov ecx,dword ptr[eax]
mov dword ptr[edx],ecx
add eax,4
add edx,4
dec contor_matrice_x
jnz bucla_orizontala
dec ebx
jnz bucla_verticala
endm
update_areav_proc proc
push ebp
mov ebp, esp
pusha
update_areav_macro
popa
mov esp, ebp
pop ebp
ret
update_areav_proc endp
color_macro macro x, y, color
local coloreaza,nimic,final
mov ecx,x
cmp ecx,area_width
jae nimic
mov ecx,y
cmp ecx,area_height
jae nimic
mov ecx,y
cmp ecx,199
jb nimic
mov ecx,x
cmp ecx,0
jb nimic
mov eax,y
mov ebx, area_width
mul ebx
add eax,x
shl eax, 2
add eax, area
mov ecx,dword ptr [eax]
cmp ecx,0c2c2c2h
je nimic
cmp ecx,0c2c2c2c2h
je nimic
cmp ecx,0
je nimic
cmp ecx,0ffffffh
je nimic
cmp ecx,clickcolor
je coloreaza
; cmp ecx,0
; je coloreaza
jmp nimic
coloreaza:
mov dword ptr [eax],0c2c2c2h
mov eax,-1
jmp final
coloreaza_alb:
mov dword ptr [eax],0c2c2c2h
mov eax,-1
jmp final
nimic:
mov eax,0
final:
endm
color_proc proc
push ebp
mov ebp, esp
pusha
; push [ebp+arg2]
; push [ebp+arg1]
; push offset decimal_formatx2
; call printf
; add esp,12
color_macro [ebp+arg1], [ebp+arg2],clickcolor
cmp eax,0
je return
;
; add dword ptr [ebp+arg1],1
; push [ebp+arg2]
; push [ebp+arg1]
; call color_proc
; add esp,12
sub dword ptr [ebp+arg1],1
push [ebp+arg2]
push [ebp+arg1]
call color_proc
add esp,8
add dword ptr [ebp+arg1],1
add dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call color_proc
add esp,8
add dword ptr [ebp+arg1],1
sub dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call color_proc
add esp,8
sub dword ptr [ebp+arg1],1
sub dword ptr [ebp+arg2],1
push [ebp+arg2]
push [ebp+arg1]
call color_proc
add esp,8
return:
popa
mov esp, ebp
pop ebp
ret
color_proc endp
get_color macro x, y, color
mov eax,y
mov ebx, area_width
mul ebx
add eax,x
shl eax, 2
add eax, areas
mov eax,dword ptr [eax]
mov color,eax
endm
randomNumberGen proc
push EBP
mov EBP, ESP