-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFillFields.asm
More file actions
555 lines (394 loc) · 9.94 KB
/
FillFields.asm
File metadata and controls
555 lines (394 loc) · 9.94 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
.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\Advapi32.inc
;include \masm32\include\masm32rt.inc
include \masm32\include\winmm.inc
includelib \masm32\lib\winmm.lib
include \masm32\include\dialogs.inc ; macro file for dialogs
include \masm32\macros\macros.asm ; masm32 macro file
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\ole32.lib
includelib \masm32\lib\msvcrt.lib
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc
include \masm32\include\Advapi32.inc
include \masm32\include\masm32rt.inc
include \masm32\include\winmm.inc
includelib \masm32\lib\winmm.lib
.const
VEL_X equ 3
VEL_Y equ 3
RECT_WIDTH_BACKUP equ 30
RECT_HEIGHT_BACKUP equ 20
WINDOW_WIDTH equ 900
WINDOW_HEIGHT equ 600
RIGHT equ 1
DOWN equ 2
LEFT equ 3
UP equ 4
MAIN_TIMER_ID equ 0
.data
RECT_WIDTH DB 30
RECT_HEIGHT DB 20
PlayerX DWORD 0
PlayerY DWORD 5
;Facing DWORD LEFT ;1 - Right, 2 -Down, 3 - Left, 4 - Up
ClassName DB "TheClass",0
windowTitle DB "A Game!",0
JumpState DWORD 0
StartY DWORD 400
scoreText DB "score: ",0
maze DWORD 1, 569 dup (0)
;maze DWORD 00000001,29 dup (1), 100 dup (0), 30 dup (0)
counter DWORD 0
yellow DWORD 0
counter2 DWORD 0
speed DWORD 0
PlayerX2 DWORD 0
PlayerY2 DWORD 0
.code
BUILDRECT PROC, x:DWORD, y:DWORD, h:DWORD, w:DWORD, hdc:HDC, brush:HBRUSH
LOCAL rectangle:RECT
mov eax, x
mov rectangle.left, eax
add eax, w
mov rectangle.right, eax
mov eax, y
mov rectangle.top, eax
add eax, h
mov rectangle.bottom, eax
invoke FillRect, hdc, addr rectangle, brush
ret
BUILDRECT ENDP
FillFields PROC, index:DWORD
xor ecx, ecx
mov esi, offset maze
mov edx, LENGTHOF maze
mov ecx, index
mov ebx, [esi + ecx * 4]
.if(ebx == 3 || ebx == 2)
jmp enddd
.endif
mov eax, 2
mov [esi + ecx * 4], eax
push eax
push ecx
push ebx
push ecx
push ecx
push ecx
push ecx
mov eax, PlayerX ; eax, end result eax / ebx
mov ebx, 30
sub edx, edx ;set edx to zero
div ebx
pop ecx
.if (edx > 0)
dec ecx
invoke FillFields , ecx
.endif
pop ecx
.if (edx < 19)
inc ecx
invoke FillFields , ecx
.endif
pop ecx
.if (eax > 0)
sub ecx, 30
invoke FillFields , ecx
.endif
pop ecx
.if (eax < 29)
add ecx, 30
invoke FillFields , ecx
.endif
pop ebx
pop ecx
pop eax
endd:
enddd:
ret
FillFields ENDP
CheckBounds PROC
ret
CheckBounds ENDP
DoChangesInPainting PROC, index:LONG
xor ecx, ecx
mov esi, offset maze
mov ecx, LENGTHOF maze
L122:
push ecx ; Push ecx to the stack
mov edx, [esi + ecx * 4]
cmp edx, 1
jne dntChange
push ecx
change:
push ecx
mov ebx, [esi + ecx * 4]
.if (ebx == 3 || ebx == 3)
jmp continue
.endif
mov eax, 2
mov [esi + ecx * 4], eax
pop ecx
sub ecx, 30
mov edx, [esi + ecx * 4]
.if (edx == 1) ; Every one (1), sWING IT
mov eax, 3
mov [esi + ecx * 4], eax
.endif
cmp edx, 1
jne change
continue:
pop ecx
dntChange:
enddraw:
pop ecx
sub ecx, 1
cmp ecx, 0
jne L122
ret
DoChangesInPainting ENDP
ProjectWndProc PROC, hWnd:HWND, message:UINT, wParam:WPARAM, lParam:LPARAM
local paint:PAINTSTRUCT
local hdc:HDC
local brushcolouring:HBRUSH
;local counter:LONG
invoke GetAsyncKeyState, VK_LEFT
cmp eax, 0
jne moveleft
invoke GetAsyncKeyState, VK_RIGHT
cmp eax, 0
jne moveright
checkupdown:
invoke GetAsyncKeyState, VK_UP
cmp eax, 0
jne moveup
invoke GetAsyncKeyState, VK_DOWN
cmp eax, 0
jne movedown
jmp endmovement
moveleft:
;invoke Sleep, 50
mov speed, -1
jmp checkupdown
moveright:
mov speed, 1
jmp checkupdown
movedown:
mov speed, 30
jmp endmovement
moveup:
mov speed, -30
jmp endmovement
endmovement:
cmp message, WM_PAINT
je painting
cmp message, WM_CLOSE
je closing
;cmp message, WM_KEYDOWN
;je movement
;cmp message, WM_KEYUP
;je stopmovement
cmp message, WM_TIMER
je timing
jmp OtherInstances
closing:
invoke ExitProcess, 0
painting:
add counter2, 1
.if(counter2 >= 5)
mov ecx, 1
.while(ecx)
push ecx
mov eax, PlayerX ; get current index at the maze, add the speed to it
add eax, speed
mov PlayerX, eax
mov esi, offset maze ; take addr of maze array
mov eax, PlayerX
mov ecx, 1
mov [esi + eax * 4], ecx ; Change index in maze to one 1 - > Black
mov eax, PlayerX ; eax, end result eax / ebx
mov ebx, 30
sub edx, edx ;set edx to zero
div ebx ; calulate col ------> index / numberOfRows
; add eax, 1
imul eax, 30
;mov PlayerX2, eax
mov PlayerY2, eax
mov eax, PlayerX ; eax, end result eax / ebx
mov ebx, 30
sub edx, edx ;set edx to zero
div ebx ; calulate row ------> index / numberOfRows
;sun edx, 1
imul edx, 30
mov PlayerX2, edx
.if (speed == -1)
mov ecx, PlayerX
add ecx, -1
.elseif (speed == 1)
mov ecx, PlayerX
add ecx, 1
.elseif (speed == 30)
mov ecx, PlayerX
add ecx, 30
.elseif (speed == -30)
mov ecx, PlayerX
add ecx, -30
.endif
mov eax, [esi + ecx * 4]
.if(eax == 3) || eax == 2
invoke DoChangesInPainting, 1
.endif
mov counter2, 0
pop ecx
dec ecx
.endw
.endif
.if(counter2 >= 180)
mov counter, 0
.endif
invoke BeginPaint, hWnd, addr paint
mov hdc, eax
invoke GetStockObject, DC_BRUSH
mov brushcolouring, eax
invoke SelectObject, hdc,brushcolouring
invoke SetDCBrushColor, hdc, 00000027ae60h
mov yellow, eax
xor ecx, ecx
mov esi, offset maze
L122:
push ecx ; Push ecx to the stack
push ecx
mov eax, ecx ; eax, end result eax / ebx
mov ebx, 30
sub edx, edx ;set edx to zero
div ebx ; calulate row
add eax, 1
imul eax, 30
push eax
mov eax, ecx ; eax, end result eax / ebx
mov ebx, 30
sub edx, edx ;set edx to zero
div ebx
mov ecx, edx
imul ecx, 30
pop eax
sub eax, 30
pop edx
cmp ecx, 0
jne con1
mov ebx, 3 ; Blue
mov [esi + edx * 4], ebx
con1:
cmp ecx, 870
jne con2
mov ebx, 3 ; Blue
mov [esi + edx * 4], ebx
con2:
cmp eax, 0
jne con3
mov ebx, 3 ; Blue
mov [esi + edx * 4], ebx
con3:
cmp eax, 540
jne dntChange
mov ebx, 3 ; Blue
mov [esi + edx * 4], ebx
dntChange:
mov ebx, [esi + edx * 4] ; Check if state one
cmp ebx, 1
je drawGreen
mov ebx, [esi + edx * 4] ; Check if state one
cmp ebx, 3
je drawBlue
mov ebx, [esi + edx * 4] ; Check if state one
cmp ebx, 2
je drawBlue
push eax
push ecx
push edx
invoke SetDCBrushColor, hdc, 000000ffffffh
mov brushcolouring, eax
pop edx
pop ecx
pop eax
invoke BUILDRECT, ecx , eax , 28, 28, hdc, brushcolouring
jmp enddraw
drawBlue:
push eax
push ecx
push edx
invoke SetDCBrushColor, hdc, 000000f00000h
mov brushcolouring, eax
pop edx
pop ecx
pop eax
invoke BUILDRECT, ecx , eax , 28, 28, hdc, brushcolouring
JMP enddraw
drawGreen:
push eax
push ecx
push edx
invoke SetDCBrushColor, hdc, 0000000f0000h
mov brushcolouring, eax
pop edx
pop ecx
pop eax
invoke BUILDRECT, ecx , eax , 28, 28, hdc, brushcolouring
enddraw:
pop ecx
add ecx, 1
cmp ecx, LENGTHOF maze
jne L122
invoke BUILDRECT, PlayerX2 , PlayerY2 , 28, 28, hdc, 3
invoke crt__itoa, counter, addr scoreText + 7, 10 ; Convert integer to string
invoke crt_strlen, addr scoreText ;Get the length of the scoreText string
invoke TextOutA, hdc, 10, 10, addr scoreText, eax ;Print the score
; jmp endhere
invoke EndPaint, hWnd, addr paint
ret
timing:
invoke InvalidateRect, hWnd, NULL, TRUE
ret
OtherInstances:
invoke DefWindowProc, hWnd, message, wParam, lParam
ret
ProjectWndProc ENDP
main PROC
LOCAL wndcls:WNDCLASSA ; Class struct for the window
LOCAL hWnd:HWND ;Handle to the window
LOCAL msg:MSG
invoke RtlZeroMemory, addr wndcls, SIZEOF wndcls ;Empty the window class
mov eax, offset ClassName
mov wndcls.lpszClassName, eax ;Set the class name
invoke GetStockObject, BLACK_BRUSH
mov wndcls.hbrBackground, (HBRUSH)(9) ;Set the background color as black
mov eax, ProjectWndProc
mov wndcls.lpfnWndProc, eax ;Set the procedure that handles the window messages
invoke RegisterClassA, addr wndcls ;Register the class
invoke CreateWindowExA, WS_EX_COMPOSITED, addr ClassName, addr windowTitle, WS_SYSMENU, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0 ;Create the window
mov hWnd, eax ;Save the handle
invoke ShowWindow, eax, SW_SHOW ;Show it
invoke SetTimer, hWnd, MAIN_TIMER_ID, 20, NULL ;Set the repaint timer
msgLoop:
; PeekMessage
invoke GetMessage, addr msg, hWnd, 0, 0 ;Retrieve the messages from the window
mov eax, 55
invoke DispatchMessage, addr msg ;Dispatches a message to the window procedure
jmp msgLoop
invoke ExitProcess, 1
main ENDP
end main