-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk.asm
549 lines (471 loc) · 10.4 KB
/
k.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
; "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
; Ken Silverman's official web site: "http://www.advsys.net/ken"
; See the included license file "BUILDLIC.TXT" for license info.
; This file has been modified from Ken Silverman's original release
.386P
EXTRN _kdmasm1 : dword
EXTRN _kdmasm2 : dword
EXTRN _kdmasm3 : dword
EXTRN _kdmasm4 : dword
EXTRN _chainbackcnt : dword
EXTRN _chainbackstart : dword
EXTRN _pcsndptr : dword
EXTRN _samplecount : dword
EXTRN _pcsndbufsiz : dword
EXTRN _oldpctimerhandler : far
EXTRN _bufferside : byte
EXTRN _qualookup : near
EXTRN _pcsndlookup : near
EXTRN _chain_intr_ : near
EXTRN __GETDS : near
EXTRN preparesndbuf_ : near
_DATA SEGMENT BYTE PUBLIC USE32 'DATA'
_DATA ENDS
DGROUP GROUP _DATA
CODE SEGMENT BYTE PUBLIC USE32 'CODE'
ASSUME cs:CODE
PUBLIC monolocomb_
monolocomb_:
;eax=temp2,ebx=temp1,ecx=cnt,edx=dat,esi=dasplc,edi=stemp,ebp=dasoff
push ebp
mov dword ptr ds:[mach1lm+3], ebx ;voloffs1
mov ebx, _kdmasm4
mov dword ptr ds:[mach5lm+2], ebx
mov ebx, edx
shl ebx, 32-12
sar edx, 12
mov dword ptr ds:[mach3lm+2], ebx ;dasinc
mov dword ptr ds:[mach4lm+2], edx ;dasinc
mov ebp, esi
shl ebp, 32-12
sar esi, 12
xor edx, edx
jmp begitlm
prebegitlm:
cmp _kdmasm1, 0
jz enditlm
mov ebx, _kdmasm2
mov dword ptr ds:[mach5lm+2], ebx
mov _kdmasm4, ebx
mov ebx, _kdmasm3
mov eax, ebx
shl ebx, 32-12
sar eax, 12
sub ebp, ebx
sbb esi, eax
test ecx, ecx
jz enditlm
begitlm:
;dl = [(eax>>12)+dasoff]; (QUICK NO MULTIPLY METHOD)
mach5lm: mov dl, byte ptr [esi+88888888h] ;dasoff
mov ebx, dword ptr [edi]
add edi, 4
mach1lm: add ebx, dword ptr [edx*4+88888888h] ;voloffs1
mach3lm: add ebp, 88888888h ;dasinc
mach4lm: adc esi, 88888888h ;dasinc
mov dword ptr [edi-4], ebx
dec ecx
ja begitlm ;jump if (no carry (add)) and (not zero (dec))!
jc prebegitlm
enditlm:
shl esi, 12
shr ebp, 32-12
lea eax, [esi+ebp]
pop ebp
ret
PUBLIC monohicomb_
monohicomb_:
;eax=temp2,ebx=temp1,ecx=cnt,edx=dat,esi=dasplc,edi=stemp,ebp=dasoff
push ebp
mov ebp, ecx
mov dword ptr ds:[mach1hm+3], ebx ;voloffs1
mov ebx, _kdmasm4
mov dword ptr ds:[mach5hm+3], ebx
mov ebx, edx
shl ebx, 32-12
sar edx, 12
mov dword ptr ds:[mach4hm+2], edx ;dasinc
;mov edx, ebx ;Fake 4-bit counter to save shift
;shr edx, 20 ;
;mov bx, dx ;
mov dword ptr ds:[mach3hm+2], ebx ;dasinc
mov ecx, esi
shl ecx, 32-12
sar esi, 12
;mov edx, ecx ;Fake 4-bit counter to save shift
;shr edx, 20 ;
;mov cx, dx ;
xor edx, edx
sub edi, 4
jmp begithm
prebegithm:
cmp _kdmasm1, 0
jz endithm
mov ebx, _kdmasm2
mov dword ptr ds:[mach5hm+3], ebx
mov _kdmasm4, ebx
mov ebx, _kdmasm3
mov eax, ebx
shl ebx, 32-12
sar eax, 12
sub ecx, ebx
sbb esi, eax
test ebp, ebp
jz endithm
begithm:
;edx = _qualookup[((ebp>>19)&0x00001e00)+(bh-bl)]+bl
mach5hm: mov bx, word ptr [esi+88888888h]
mov eax, ecx
shr eax, 20
add edi, 4
mov dl, bl
mov al, bl
sub al, bh
adc ah, ah
add dl, byte ptr _qualookup[eax]
mov ebx, dword ptr [edi]
mach1hm: add ebx, dword ptr [edx*4+88888888h] ;voloffs1
mach3hm: add ecx, 88888888h ;dasinc
mach4hm: adc esi, 88888888h ;dasinc
dec ebp
mov dword ptr [edi], ebx
ja begithm ;jump if (no carry (add)) and (not zero (dec))!
jc prebegithm
endithm:
shl esi, 12
shr ecx, 32-12
lea eax, [esi+ecx]
pop ebp
ret
PUBLIC stereolocomb_
stereolocomb_:
;eax=temp2,ebx=temp1,ecx=cnt,edx=dat,esi=dasplc,edi=stemp,ebp=dasoff
push ebp
mov dword ptr ds:[mach1ls+3], ebx ;voloffs1
add ebx, 4
mov dword ptr ds:[mach2ls+3], ebx ;voloffs2
mov ebx, _kdmasm4
mov dword ptr ds:[mach5ls+2], ebx
mov ebx, edx
shl ebx, 32-12
sar edx, 12
mov dword ptr ds:[mach3ls+2], ebx ;dasinc
mov dword ptr ds:[mach4ls+2], edx ;dasinc
mov ebp, esi
shl ebp, 32-12
sar esi, 12
xor edx, edx
sub edi, 8
jmp begitls
prebegitls:
cmp _kdmasm1, 0
jz enditls
mov ebx, _kdmasm2
mov dword ptr ds:[mach5ls+2], ebx
mov _kdmasm4, ebx
mov ebx, _kdmasm3
mov eax, ebx
shl ebx, 32-12
sar eax, 12
sub ebp, ebx
sbb esi, eax
test ecx, ecx
jz enditls
jmp begitls
begitls:
add edi, 8
;dl = [(eax>>12)+dasoff]; (QUICK NO MULTIPLY METHOD)
mach5ls: mov dl, byte ptr [esi+88888888h] ;dasoff
mov ebx, dword ptr [edi]
mov eax, dword ptr [edi+4]
mach1ls: add ebx, dword ptr [edx*8+88888888h] ;voloffs1
mach2ls: add eax, dword ptr [edx*8+88888888h] ;voloffs2
mach3ls: add ebp, 88888888h ;dasinc
mov dword ptr [edi], ebx
mach4ls: adc esi, 88888888h ;dasinc
dec ecx
mov dword ptr [edi+4], eax
ja begitls ;jump if (no carry (add)) and (not zero (dec))!
jc prebegitls
enditls:
shl esi, 12
shr ebp, 32-12
lea eax, [esi+ebp]
pop ebp
ret
PUBLIC stereohicomb_
stereohicomb_:
;eax=temp2,ebx=temp1,ecx=cnt,edx=dat,esi=dasplc,edi=stemp,ebp=dasoff
push ebp
mov ebp, ecx
mov dword ptr ds:[mach1hs+3], ebx ;voloffs1
add ebx, 4
mov dword ptr ds:[mach2hs+3], ebx ;voloffs2
mov ebx, _kdmasm4
mov dword ptr ds:[mach5hs+3], ebx
mov ebx, edx
shl ebx, 32-12
sar edx, 12
mov dword ptr ds:[mach4hs+2], edx ;dasinc
;mov edx, ebx ;Fake 4-bit counter to save shift
;shr edx, 20 ;
;mov bx, dx ;
mov dword ptr ds:[mach3hs+2], ebx ;dasinc
mov ecx, esi
shl ecx, 32-12
sar esi, 12
;mov edx, ecx ;Fake 4-bit counter to save shift
;shr edx, 20 ;
;mov cx, dx ;
xor edx, edx
sub edi, 8
jmp begiths
prebegiths:
cmp _kdmasm1, 0
jz endiths
mov ebx, _kdmasm2
mov dword ptr ds:[mach5hs+3], ebx
mov _kdmasm4, ebx
mov ebx, _kdmasm3
mov eax, ebx
shl ebx, 32-12
sar eax, 12
sub ecx, ebx
sbb esi, eax
test ebp, ebp
jz endiths
begiths:
;edx = _qualookup[((ebp>>19)&0x00001e00)+(bh-bl)]+bl
mach5hs: mov bx, word ptr [esi+88888888h]
mov eax, ecx
shr eax, 20
add edi, 8
mov dl, bl
mov al, bl
sub al, bh
adc ah, ah
add dl, byte ptr _qualookup[eax]
mov eax, dword ptr [edi]
mach1hs: mov ebx, dword ptr [edx*8+88888888h] ;voloffs1
add ebx, eax
mov eax, dword ptr [edi+4]
mov dword ptr [edi], ebx
mach2hs: mov ebx, dword ptr [edx*8+88888888h] ;voloffs2
add eax, ebx
mach3hs: add ecx, 88888888h ;dasinc
mach4hs: adc esi, 88888888h ;dasinc
dec ebp
mov dword ptr [edi+4], eax
ja begiths ;jump if (no carry (add)) and (not zero (dec))!
jc prebegiths
endiths:
shl esi, 12
shr ecx, 32-12
lea eax, [esi+ecx]
pop ebp
ret
PUBLIC setuppctimerhandler_
setuppctimerhandler_:
mov dword ptr ds:[pcmach3+2], eax
cmp ebx, 65000d
jl short skipsetuppc1
mov word ptr ds:[pcmach1+0], 0c381h ;81c300000000 = add ebx, 00000000h
mov dword ptr ds:[pcmach1+2], 00000000h
mov word ptr ds:[pcmach2+0], 0c98bh ;8bc9 = mov ecx, ecx
skipsetuppc1:
ret
PUBLIC pctimerhandler_
pctimerhandler_:
push eax
mov ax, DGROUP
push ds
mov ds, ax
push edx
mov edx, dword ptr _pcsndptr
mov al, byte ptr [edx]
out 42h, al
inc edx
mov dword ptr _pcsndptr, edx
pcmach1: dec _chainbackcnt ;samplediv
pcmach2: jz short pc3
mov al, 20h
out 20h, al
pcmach3: cmp edx, 88888888h ;pcsndptrend
jge short pc1
pop edx
pop ds
pop eax
iretd
pc1: xor byte ptr _bufferside, 1
mov eax, _pcsndbufsiz
mov edx, _pcsndptr
jnz short pc2
sub edx, eax
sub edx, eax
mov _pcsndptr, edx
pc2: add eax, edx
mov dword ptr ds:[pcmach3+2], eax
sti
call preparesndbuf_
pop edx
pop ds
pop eax
iretd
pc3: sti
cmp edx, dword ptr ds:[pcmach3+2]
jl short pc5
xor byte ptr _bufferside, 1
mov eax, _pcsndbufsiz
mov edx, _pcsndptr
jnz short pc4
sub edx, eax
sub edx, eax
mov _pcsndptr, edx
pc4: add eax, edx
mov dword ptr ds:[pcmach3+2], eax
sti
call preparesndbuf_
pc5:
mov eax, _chainbackstart
mov _chainbackcnt, eax
pop edx
pop ds
pop eax
;Must start interrupt handler like watcom c
pushad
push ds
push es
push fs
push gs
mov ebp, esp
cld
call __GETDS
mov dx, word ptr [_oldpctimerhandler+4]
mov eax, dword ptr [_oldpctimerhandler]
call _chain_intr_
PUBLIC pcbound2char_
pcbound2char_:
push ebp
add ecx, ecx
lea eax, [ecx+edi]
mov dword ptr ds:[pcmachchar+3], eax
xor edi, edi
sub edi, ecx
xor ecx, ecx
xor edx, edx
mov ebp, 0ffff0000h
startpcbound2char:
mov ebx, dword ptr [esi]
mov eax, dword ptr [esi+4]
test ebx, ebp
jnz short pcboundit1
pcboundit1back:
mov dl, bh
mov dword ptr [esi], 32768
test eax, ebp
mov al, byte ptr _pcsndlookup[edx]
jnz short pcboundit2
pcboundit2back:
mov dl, ah
mov dword ptr [esi+4], 32768
mov ah, byte ptr _pcsndlookup[edx]
add esi, 8
pcmachchar: mov word ptr [edi+88888888h], ax
add edi, 2
jnc short startpcbound2char
pop ebp
ret
pcboundit1:
cmp ebx, 80000000h
sbb bh, bh
jmp short pcboundit1back
pcboundit2:
cmp eax, 80000000h
sbb ah, ah
jmp short pcboundit2back
;for(i=0;i<bytespertic;i++)
;{
; j = (stemp[i]>>8);
; if (j < 0) j = 0;
; if (j > 255) j = 255;
; *charptr++ = (char)j;
;}
PUBLIC bound2char_
bound2char_:
add ecx, ecx
lea eax, [ecx+edi]
mov dword ptr ds:[machchar+3], eax
xor edi, edi
sub edi, ecx
xor ecx, ecx
mov edx, 0ffff0000h
startbound2char:
mov ebx, dword ptr [esi]
mov eax, dword ptr [esi+4]
test ebx, edx
jnz short boundchar1
boundchar1back:
mov dword ptr [esi], 32768
test eax, edx
jnz short boundchar2
boundchar2back:
mov dword ptr [esi+4], 32768
mov al, bh
add esi, 8
machchar: mov word ptr [edi+88888888h], ax
add edi, 2
jnc short startbound2char
ret
boundchar1:
cmp ebx, 80000000h
sbb bh, bh
jmp short boundchar1back
boundchar2:
cmp eax, 80000000h
sbb ah, ah
jmp short boundchar2back
;for(i=0;i<bytespertic;i++)
;{
; j = stemp[i];
; if (j < 0) j = 0;
; if (j > 65535) j = 65535;
; *shortptr++ = (short)(j^8000h);
;}
PUBLIC bound2short_
bound2short_:
shl ecx, 2
lea eax, [ecx+edi]
mov dword ptr ds:[machshort+2], eax
xor edi, edi
sub edi, ecx
xor ecx, ecx
mov edx, 0ffff0000h
startbound2short:
mov ebx, dword ptr [esi]
mov eax, dword ptr [esi+4]
test ebx, edx
jnz short boundshort1
boundshort1back:
mov dword ptr [esi], 32768
test eax, edx
jnz short boundshort2
boundshort2back:
shl eax, 16
mov dword ptr [esi+4], 32768
mov ax, bx
add esi, 8
xor eax, 80008000h
machshort: mov dword ptr [edi+88888888h], eax
add edi, 4
jnc short startbound2short
ret
boundshort1:
cmp ebx, 80000000h
sbb ebx, ebx
jmp short boundshort1back
boundshort2:
cmp eax, 80000000h
sbb eax, eax
jmp short boundshort2back
CODE ENDS
END