-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfx.inc
executable file
·538 lines (475 loc) · 15 KB
/
gfx.inc
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
_random PROTO :DWORD
initstars PROTO
MoveStars PROTO :DWORD
ScanLines PROTO :BYTE
BlitEffect PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
BlitImg PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
DrawStar PROTO :DWORD, :DWORD
movmm MACRO dest, src
mov eax, src
mov dest, eax
EndM
clreg MACRO ; Clear ALL Registers
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
EndM
STAR Struct
color dd ?
xpos dd ?
ypos dd ?
speed dd ?
STAR ends
RGBGrad STRUCT
RFlag db ?
GFlag db ?
BFlag db ?
RGBGrad EndS
.const
ScreenWidth equ 672 ; screenwidth
ScreenHeight equ 480 ; height
DialogAlign equ 600
NUM_STARS equ 100
starlen equ 10
PixelsN equ ScreenWidth*ScreenHeight
.data?
stardata STAR NUM_STARS dup(<?>)
.data
RandSeed dd 0A2F59C2Eh
dd 05B2A10E9h
GradientColor dd 00001Fe01h
GradientSt RGBGrad <0>
.code
ScanLines PROC SubVal:BYTE
; adds scanlines by dimming every 2nd
; row of pixels
LOCAL pixels:DWORD
LOCAL total:DWORD
LOCAL row :DWORD
LOCAL counter :DWORD
mov total, PixelsN*4
pushad
mov esi, [cBuffer]
mov row, 0
mov counter, 0
beginsub:
mov ecx, counter
mov al, byte ptr [esi+ecx]
mov byte ptr [esi+ecx], al
inc ecx
mov al, byte ptr [esi+ecx]
.if al > SubVal
sub al, SubVal
.elseif al < SubVal
mov al, 22
.endif
mov byte ptr [esi+ecx], al
inc ecx
mov al, byte ptr [esi+ecx]
.if al > SubVal
sub al, SubVal
.elseif al < SubVal
mov al, 22
.endif
mov byte ptr [esi+ecx], al
mov counter, ecx
add row, 2
cmp ecx, total
ja endall
je endall
cmp row, ScreenWidth*4
je skiprow
jmp beginsub
skiprow:
mov row, 0
add counter, ScreenWidth*4
jmp beginsub
endall:
popad
mov eax, 1
Ret
ScanLines EndP
DecrunchFX PROC
; gives a decrunch thingy
LOCAL color:DWORD
LOCAL yPos :DWORD
LOCAL count:DWORD
mov count, 0
invoke _random, 0FFFFFFh
invoke BlitEffect, 0, 0, eax, ScreenWidth, ScreenHeight
starts:
invoke _random, 0FFFFFFh
mov color, eax
invoke _random,ScreenHeight-24
mov yPos, eax
invoke BlitEffect, 0, yPos, color, ScreenWidth-2, 24
inc count
cmp count, 100
jnz starts
Ret
DecrunchFX EndP
BlitImg proc xPos:DWORD, yPos:DWORD, hPal:DWORD, hImg:DWORD, wid:DWORD, len:DWORD, tColor:DWORD
LOCAL gfx_yindex :DWORD
LOCAL sm_picturewidth :DWORD
LOCAL sm_pictureleng :DWORD
LOCAL x_position :DWORD
LOCAL y_position :DWORD
pushad
mov eax, xPos
mov x_position,eax
mov eax, yPos
mov y_position,eax
mov gfx_yindex,0
mov eax,y_position
imul eax,sWidth*4
add edi,eax
mov eax,x_position
shl eax,2
add edi,eax
mov eax, wid
mov sm_picturewidth,eax
mov eax, len
mov sm_pictureleng,eax
mov esi,hImg
incY_line:
xor ecx,ecx
incX_line:
movzx eax,byte ptr [esi+ecx]
mov edx,hPal
mov eax,[edx+eax*4]
plot_to_screen:
cmp eax, tColor
je clip_pixel
mov [edi],eax
add edi,4
inc ecx
cmp ecx,sm_picturewidth
jnz incX_line
mov eax,sm_picturewidth
mov ecx,sWidth
sub ecx,eax
shl ecx,2
add edi,ecx
add esi,sm_picturewidth
inc gfx_yindex
mov eax,sm_pictureleng
cmp gfx_yindex,eax
jnz incY_line
endit:
popad
ret
clip_pixel:
add edi,4
jmp clip_pixel_return
clip_pixel_return:
inc ecx
cmp ecx, sm_picturewidth
jnz incX_line
mov eax, sm_picturewidth
mov ecx,sWidth
sub ecx, eax
shl ecx,2
add edi, ecx
add esi, sm_picturewidth
inc gfx_yindex
mov eax, sm_pictureleng
cmp gfx_yindex, eax
jnz incY_line
jmp endit
BlitImg endp
BlitEffect proc xpos:DWORD, ypos:DWORD, color:DWORD, w:DWORD, l:DWORD
; for this example, i'm just using a modified procedure
; from Sheep's DIB Tutorial 1 for simplicity,
; this should be pretty easy to understand if you've read
; Sheep's DibTut #1
LOCAL gfx_yindex :DWORD
LOCAL sm_picturewidth :DWORD
LOCAL sm_pictureleng :DWORD
LOCAL x_position :DWORD
LOCAL y_position :DWORD
pushad
mov eax, xpos
mov x_position,eax
mov eax, ypos
mov y_position,eax
mov gfx_yindex,0
mov eax,y_position
imul eax,ScreenWidth*4
add edi,eax
mov eax,x_position
shl eax,2
add edi,eax
mov eax, w
mov sm_picturewidth,eax
mov eax, l
mov sm_pictureleng,eax
incY_line:
xor ecx,ecx
incX_line:
mov eax,color
plot_to_screen:
mov [edi],eax
add edi,4
inc ecx
cmp ecx,sm_picturewidth
jnz incX_line
mov eax,sm_picturewidth
mov ecx,ScreenWidth
sub ecx,eax
shl ecx,2
add edi,ecx
add esi,sm_picturewidth
inc gfx_yindex
mov eax,sm_pictureleng
cmp gfx_yindex,eax
jnz incY_line
popad
ret
BlitEffect endp
_random PROC USES EDI ESI EBX ECX Range:DWORD
; this function not by me....
; I found this online. If anyone
; recognizes this as their own, feel
; free to contact me, and i'll credit
; you for this.
mov ecx,Range
mov eax,dWord ptr [RandSeed+4]
mov ebx,dWord ptr [RandSeed]
mov esi,eax
mov edi,ebx
mov dl,ah
mov ah,al
mov al,bh
mov bh,bl
xor bl,bl
rcr dl,1
rcr eax,1
rcr ebx,1
add ebx,edi
adc eax,esi
add ebx,03b1c62e9h
adc eax,04d8f3619h
mov dword ptr [RandSeed],ebx
mov dword ptr [RandSeed+4],eax
xor edx,edx
div ecx
mov eax,edx
jnz _quit
inc eax
_quit:
ret
_random EndP
initstars PROC ; this fills the stardata array
LOCAL color:DWORD ; with initialization random variables (x, y, color)
local xpos:DWORD ; xposition
local ypos:DWORD ; yposition
local speed:DWORD ; speed
local counter:DWORD ; counter
local dwords:DWORD ; number_of_dwords done
mov counter, 0
mov dwords, 0
startinit:
; invoke _random, 0FFFFFFh ; disabled
; mov eax, 099999999h ; this is totally useless, ignore this
; mov color, eax ; same
invoke _random, ScreenWidth-30 ; generate random x plane position
mov xpos, eax ; save value
invoke _random, ScreenHeight-1 ; generate randome y plane position
mov ypos, eax ; save value
invoke _random, 8 ; generate random speed
add eax, 2 ; add 2 in order to make sure
mov speed, eax ; no stars have speed of 0,
; which would mean they won't move
mov edx, dwords ; edx == offset from base of star data
; mov eax, color
mov dword ptr [offset stardata+edx], eax ; save color (disabled)
add edx, 4 ; next
mov eax, xpos ; eax == x pos
mov dword ptr [offset stardata+edx], eax ; save into array
add edx, 4 ; next
mov eax, ypos ; eax == y pos
mov dword ptr [offset stardata+edx], eax ; save into array
add edx, 4 ; etc....
mov eax, speed
mov dword ptr [offset stardata+edx], eax
add edx, 4
mov dwords, edx ; save offset
inc counter ; increment counter (stars done)
cmp counter, NUM_STARS ; done yet?
je AllDone ; if we are, exit
jmp startinit ; else, start again
AllDone: ; done!
mov eax, 1 ; return 1
Ret
initstars EndP
MoveStars PROC STwidth:DWORD
LOCAL color:DWORD
LOCAL xpos :DWORD
LOCAL ypos :DWORD
LOCAL speed:DWORD
LOCAL dwords :DWORD
LOCAL counter:DWORD
; this procedure will MOVE stars
mov counter, 0
mov dwords, 0
mov color, 0
mov xpos, 0
mov ypos, 0
startmove:
mov edx, dwords ; load offset
mov eax, dword ptr [offset stardata+edx] ; load color (unused)
mov color, eax ; save
add edx, 4 ; next
mov eax,dword ptr [offset stardata+edx] ; load x position from array
mov xpos ,eax ; save
add edx, 4 ; next
mov eax,dword ptr [offset stardata+edx] ; load y position from array
mov ypos, eax ; save
add edx, 4 ; next
mov eax, dword ptr [offset stardata+edx] ; load speed from array
mov speed, eax ; save
add edx, 4 ; next
mov eax, speed ; load speed
add xpos, eax ; add speed to x-position (moves star)
mov ecx, ScreenWidth ; ecx == width_screen
sub ecx, STwidth ; subtract star width
cmp xpos, ecx ; has the star scrolled across screen?
mov dwords, edx ; save edx
je reseed ; if we have, reseed
ja reseed ; same as above
mov edx, dwords ; load into edx, dwords (offset)
sub edx, 16 ; sub edx, 16 (back one)
mov eax, color ; eax = color (unused)
mov dword ptr [offset stardata+edx], eax ; saving into array
add edx, 4 ; next
mov eax, xpos ; xpos
mov dword ptr [offset stardata+edx], eax ; etc, etc....
add edx ,4
mov eax, ypos
mov dword ptr [offset stardata+edx], eax
add edx, 4
mov eax, speed
mov dword ptr [offset stardata+edx], eax
add edx, 4
mov dwords, edx
inc counter ; one more star done
cmp counter, NUM_STARS ; done yet?
je alldone ; done?
jmp startmove ; nope.
alldone:
mov dwords, 0
mov counter, 0
StartBlt:
mov edx, dwords ; load edx
mov eax, dword ptr [offset stardata+edx] ; get color
mov color, eax ; save
add edx, 4 ; next
mov eax, dword ptr [offset stardata+edx] ; xpos
mov xpos, eax
add edx, 4
mov eax, dword ptr [offset stardata+edx] ; ypos
mov ypos, eax
add edx, 4
mov eax, dword ptr [offset stardata+edx] ; speed
mov speed, eax
add edx, 4
mov dwords, edx
invoke DrawStar, xpos, ypos ; call drawstar to draw a star at this position
inc counter
cmp counter, NUM_STARS
je EndAlls
jmp StartBlt
EndAlls:
mov eax, 1
Ret
reseed:
mov eax, 099999999h
mov color, eax
invoke _random, ScreenHeight-1 ; random y-pos
mov ypos, eax
invoke _random, 8 ; random speed
add eax, 2
mov speed, eax
mov xpos, 0
sub dwords, 16
mov edx, dwords
mov eax, color
mov dword ptr [offset stardata+edx], eax ; saving values
add edx, 4
mov eax, xpos
mov dword ptr [offset stardata+edx], eax
add edx ,4
mov eax, ypos
mov dword ptr [offset stardata+edx], eax
add edx, 4
mov eax, speed
mov dword ptr [offset stardata+edx], eax
add edx, 4
sub edx, 16
mov dwords, edx
jmp startmove
MoveStars endp
DrawStar PROC xP:DWORD, yP:DWORD
pushad
xor edx, edx
mov ecx, 0888888h
startdraw:
invoke BlitEffect, xP, yP, ecx, 2, 2
inc xP
inc edx
cmp edx, 02
ja enddraw
add ecx, 05050505h
jmp startdraw
enddraw:
popad
Ret
DrawStar EndP
Noise PROC xP:DWORD, yP:DWORD, rx:DWORD, ry:DWORD, pix2steal:DWORD
LOCAL hRegion:DWORD
LOCAL count:DWORD
mov count, 0
pushad
mov edi, [cBuffer]
mov eax, yP
imul eax, ScreenWidth*4
add edi, eax
mov eax, xP
shl eax, 2
add edi, eax
mov hRegion, edi
; now we're here
starts:
invoke _random, 112
mov edx, eax
invoke _random, 112
mov ecx, eax
imul ecx, ScreenWidth*4
shl edx, 2
add edx, ecx
add edi, edx
; stealing pixels
mov eax, dword ptr [edi]
mov edi, hRegion
push eax
invoke _random, rx
mov ecx, eax
invoke _random, ry
mov edx, eax
imul edx, ScreenWidth*4
shl ecx, 2
add edx, ecx
add edi, edx
pop eax
mov dword ptr [edi], eax
inc count
mov ecx, count
cmp ecx, pix2steal
ja done
mov edi, hRegion
jmp starts
done:
popad
Ret
Noise EndP