-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMARKHACK.ASM
637 lines (493 loc) · 11.3 KB
/
MARKHACK.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
.386C
IDEAL
MODEL MEDIUM,C
SC_INDEX = 03C4h
SC_RESET = 0
SC_CLOCK = 1
SC_MAPMASK = 2
CRTC_INDEX = 03D4h
SCREENBWIDE= 80
SCREENSEG = 0a000h
MISC_OUTPUT= 03c2h
MASK_COLOR = 254
DATASEG
EXTRN viewwidth:WORD
EXTRN viewheight:WORD
EXTRN bufferofs:WORD
EXTRN ylookup:WORD
EXTRN centery:WORD
EXTRN postsource:DWORD
EXTRN bufx:WORD
EXTRN postheight:WORD
EXTRN shadingtable:DWORD
CODESEG
;----------------------------------------------------------------------------
;
; DrawPost - Draws an unmasked post centered in the viewport
;
; ecx - height to scale post to
; esi - source pointer to proper column (x offsetted)
; edi - destination pointer to proper screen column (xoffsetted)
;
;----------------------------------------------------------------------------
;ALIGN 16
PROC DrawPost
PUBLIC DrawPost
; ECX - loop variable (height and counter)
; EDI - top offset + bufferofs
; EDX - destination offset
; EBX - high word contains bottom offset, low word contains source data
; EBP - fraction
push si
push di
push bp
mov ax,[WORD postsource + 2]
mov gs,ax
mov si,[WORD postsource]
mov ecx,0
mov cx,[postheight]
SETFLAG cx,cx
jz donedraw
mov edx,0
mov eax,32*65536
idiv ecx
mov edx,eax
; edx holds fractional step
mov [DWORD PTR cs:patch1+3],edx ; JTR Self modifing cod
shr edx,1
mov ax,SCREENSEG
mov es,ax
mov di,OFFSET ylookup
mov ax,[centery]
shl ax,1
add di,ax
mov di,[di]
add di,[bufferofs]
add di,[bufx]
mov bp,SCREENBWIDE
sub di,SCREENBWIDE
shr ax,1
cmp cx,ax
jle heightok
mov cx,ax
heightok: ; height is ok.. < viewheigth
drawloop:
mov eax,edx
shr eax,16
mov ebx,31
patch1:
add edx,12345678h ; JTR Self Modifing Code
sub ebx,eax
mov bl,[BYTE PTR gs:si+bx]
mov [es:di],bl
mov ebx,32
add ebx,eax
mov bl,[BYTE PTR gs:si+bx]
mov [es:di+bp],bl
sub di,SCREENBWIDE
add bp,SCREENBWIDE*2
dec cx
jnz drawloop
donedraw:
pop bp
pop di
pop si
ret
ENDP DrawPost
;----------------------------------------------------------------------------
;
; DrawLSPost - Draws an unmasked light sourced post centered in the viewport
;
; ecx - height to scale post to
; esi - source pointer to proper column (x offsetted)
; edi - destination pointer to proper screen column (xoffsetted)
;
;----------------------------------------------------------------------------
;ALIGN 16
PROC DrawLSPost
PUBLIC DrawLSPost
; ECX - loop variable (height and counter)
; EDI - top offset + bufferofs
; EDX - destination offset
; EBX - high word contains bottom offset, low word contains source data
; EBP - fraction
push si
push di
push bp
mov ax,[WORD postsource + 2]
mov gs,ax
mov si,[WORD postsource]
mov ecx,0
mov ax,[WORD shadingtable + 2]
mov fs,ax
mov cx,[postheight]
SETFLAG cx,cx
jz donedraw
mov edx,0
mov eax,32*65536
idiv ecx
mov edx,eax
; edx holds fractional step
mov [DWORD PTR cs:patch1ls+3],edx ; JTR: Self Modifing Code!
shr edx,1
mov ax,SCREENSEG
mov es,ax
mov di,OFFSET ylookup
mov ax,[centery]
shl ax,1
add di,ax
mov di,[di]
add di,[bufferofs]
add di,[bufx]
mov bp,SCREENBWIDE
sub di,SCREENBWIDE
shr ax,1
cmp cx,ax
jle heightokls
mov cx,ax
heightokls: ; height is ok.. < viewheigth
drawloopls:
mov eax,edx
shr eax,16
mov ebx,31
patch1ls:
add edx,12345678h ; JTR This value 1234... will change to contain the frac inc value.
sub ebx,eax
shl eax,16
mov al,[BYTE PTR gs:si+bx]
mov bx,[WORD shadingtable]
mov bl,al
mov al,[fs:bx]
mov [es:di],al
mov ebx,32
shr eax,16
add ebx,eax
mov al,[BYTE PTR gs:si+bx]
mov bx,[WORD shadingtable]
mov bl,al
mov al,[fs:bx]
mov [es:di+bp],al
sub di,SCREENBWIDE
add bp,SCREENBWIDE*2
dec cx
jnz drawloopls
donedrawls:
pop bp
pop di
pop si
ret
ENDP DrawLSPost
IF 0 ; JIM Add line
;----------------------------------------------------------------------------
;
; DrawMPost - Draws an masked post centered in the viewport
;
; ecx - height to scale post to
; esi - source pointer to proper column (x offsetted)
; edi - destination pointer to proper screen column (xoffsetted)
;
;----------------------------------------------------------------------------
;ALIGN 16
PROC DrawMPost
PUBLIC DrawMPost
; ECX - loop variable (height and counter)
; EDI - top offset + bufferofs
; EDX - destination offset
; EBX - high word contains bottom offset, low word contains source data
; EBP - fraction
push si
push di
push bp
;
; 'postsource' is a ptr to the source image.
;
; Setup ptr to source image
; GS:SI will be address of veritacal post to draw.
;
mov ax,[WORD postsource + 2]
mov gs,ax
mov si,[WORD postsource]
;
; Clear out our high word of our loop counter
;
mov ecx,0
;
; Store height and test for 0
;
mov cx,[postheight]
SETFLAG cx,cx
jz donedrawm
;
; Calc fractional step values to be stored in EDX
;
; (Height/Max_View??)
;
;
mov edx,0
mov eax,32*65536
idiv ecx
mov edx,eax
;
; Self modify the asm code to use the fractional step
; value. Stored at patch1mls+3
;
mov [DWORD PTR cs:patch1m+3],edx ; Self modifing code
;
; Compute position on screen to draw pixel
;
shr edx,1
mov ax,SCREENSEG
mov es,ax
mov di,OFFSET ylookup
mov ax,[centery]
shl ax,1
add di,ax
mov di,[di]
add di,[bufferofs]
add di,[bufx]
mov bp,SCREENBWIDE
sub di,SCREENBWIDE
shr ax,1
cmp cx,ax
jle heightokm
mov cx,ax
heightokm: ; height is ok.. < viewheigth
;
; Get ready to draw post
;
drawloopm:
mov eax,edx
shr eax,16 ; restore contents of AX from high word
mov ebx,31
patch1m:
add edx,12345678h ; Self Modifing Code
sub ebx,eax
;
; move source pixel into BL
;
mov bl,[BYTE PTR gs:si+bx]
;
; BL now contains our source pixel to draw
;
; Test for mask color
;
cmp bl,MASK_COLOR
je skip1_maskcolor
;
; Draw source pixel to screen
;
mov [es:di],bl
skip1_maskcolor:
mov ebx,32
add ebx,eax
;
; Get pixel from source image.
;
mov bl,[BYTE PTR gs:si+bx]
;
; Test for mask color
;
cmp bl,MASK_COLOR
je skip2_maskcolor
;
; Draw Pixel
;
mov [es:di+bp],bl
skip2_maskcolor:
sub di,SCREENBWIDE
add bp,SCREENBWIDE*2
dec cx
jnz drawloopm
donedrawm:
pop bp
pop di
pop si
ret
ENDP DrawMPost
;----------------------------------------------------------------------------
;
; DrawMLSPost - Draws a masked light sourced post centered in the viewport
;
; ecx - height to scale post to
; esi - source pointer to proper column (x offsetted)
; edi - destination pointer to proper screen column (xoffsetted)
;
;----------------------------------------------------------------------------
;ALIGN 16
PROC DrawMLSPost
PUBLIC DrawMLSPost
; ECX - loop variable (height and counter)
; EDI - top offset + bufferofs
; EDX - destination offset
; EBX - high word contains bottom offset, low word contains source data
; EBP - fraction
push si
push di
push bp
;
; Setup ptr to source image
; GS:SI will be address of veritacal post to draw.
;
mov ax,[WORD postsource + 2]
mov gs,ax
mov si,[WORD postsource]
;
; Clear out our high word of our loop counter
;
mov ecx,0
;
; Init FS to hold SEGMENT for the shading table
;
; (shading table is on WORD boundries?)
;
mov ax,[WORD shadingtable + 2]
mov fs,ax ; FS - Holds SEG to Far shading table
;
; Store height and test for 0
;
mov cx,[postheight]
SETFLAG cx,cx
jz donedrawmls ; Nothing to draw...Exit this mofo.
;
; Calc fractional step values to be stored in EDX
;
; (Height/Max_View??)
;
;
mov edx,0
mov eax,32*65536
idiv ecx
mov edx,eax
;
; Self modify the asm code to use the fractional step
; value. Stored at patch1mls+3
;
mov [DWORD PTR cs:patch1mls+3],edx
;
; Divide the fractional step in half
;
shr edx,1
;
; Calc screen position to draw vert post
;
; ES:DI - dest Screen ptr
;
mov ax,SCREENSEG
mov es,ax
mov di,OFFSET ylookup
mov ax,[centery]
shl ax,1
add di,ax
mov di,[di]
add di,[bufferofs]
add di,[bufx]
mov bp,SCREENBWIDE
sub di,SCREENBWIDE
;
; Test boundries of drawing....?
;
shr ax,1
cmp cx,ax
jle heightokmls
mov cx,ax
heightokmls: ; height is ok.. < viewheigth
;
; Get ready to draw this Mofo!
;
;
drawloopmls:
mov eax,edx
shr eax,16
mov ebx,31
;
; NOTE: The value 12345678 will be Modified to hold the
; fractional inc value.
;
patch1mls:
add edx,12345678h
sub ebx,eax
shl eax,16 ; Store AX into the high word of EAX
;
; AL will contain the source pixel to draw
;
mov al,[BYTE PTR gs:si+bx]
;
; Now test AL for a mask color, if so, lets skip it.
;
cmp al,MASK_COLOR
je skip1_ls_maskcolor
;
; Nope, Not the mask color....
;
; Get the offset to the shading table
;
; BX = offset to shading table
;
;
mov bx,[WORD shadingtable] ; Get offset for shading table
;
; Adjust the offset into the shading table to index
; using the source pixel color (currently being held in
; AL.
;
mov bl,al
;
; FS:BX points to the shaded color
;
; Move into AL
;
mov al,[fs:bx]
;
; Draw the shaded pixel to the screen.
;
mov [es:di],al
;
; Do some adjustments for ??????????
;
;
skip1_ls_maskcolor:
mov ebx,32
shr eax,16 ; Restore the Old AX which was stored in the hi word
add ebx,eax
;
; Move the source pixel into AL
;
;
mov al,[BYTE PTR gs:si+bx]
;
; Test AL for a mask color
;
cmp al,MASK_COLOR
je skip2_ls_maskcolor
;
; Get the offset for the Shading table ... again
;
; BX = Offset into shading table
;
mov bx,[WORD shadingtable]
;
; Adjust BX to index with the source pixel color to
; get the shaded pixel color.
;
mov bl,al
mov al,[fs:bx]
;
; AL now contains the shaded pixel... Draw that mofo!
;
mov [es:di+bp],al
;
; Move to next pixel(s)
;
skip2_ls_maskcolor:
sub di,SCREENBWIDE
add bp,SCREENBWIDE*2
dec cx
jnz drawloopmls
donedrawmls:
pop bp
pop di
pop si
ret
ENDP DrawMLSPost
ENDIF ; JIM Add line
END