-
Notifications
You must be signed in to change notification settings - Fork 57
/
IDLIBC.ASM
8172 lines (8171 loc) · 124 KB
/
IDLIBC.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
; Hovertank 3-D Source Code
; Copyright (C) 1993-2014 Flat Rock Software
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License along
; with this program; if not, write to the Free Software Foundation, Inc.,
; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ifndef ??version
?debug macro
endm
publicdll macro name
public name
endm
$comm macro name,dist,size,count
comm dist name:BYTE:count*size
endm
else
$comm macro name,dist,size,count
comm dist name[size]:BYTE:count
endm
endif
?debug S "idlibc.c"
?debug C E92C869D160869646C6962632E63
?debug C E9D03A9E160749444C49422E48
?debug C E9AE10A3160A4752415048484F562E48
?debug C E92592951609534E4453484F562E48
?debug C E900104D1616433A5C42435C494E434C5544455C7374646172672E+
?debug C 68
?debug C E900104D1613433A5C42435C494E434C5544455C646F732E68
?debug C E900104D1613433A5C42435C494E434C5544455C6D656D2E68
?debug C E900104D1618433A5C42435C494E434C5544455C7379735C737461+
?debug C 742E68
?debug C E900104D1615433A5C42435C494E434C5544455C66636E746C2E68
?debug C E900104D1616433A5C42435C494E434C5544455C7374646C69622E+
?debug C 68
?debug C E900104D1615433A5C42435C494E434C5544455C616C6C6F632E68
?debug C E900104D1612433A5C42435C494E434C5544455C696F2E68
_TEXT segment byte public 'CODE'
_TEXT ends
DGROUP group _DATA,_BSS
assume cs:_TEXT,ds:DGROUP
_DATA segment word public 'DATA'
d@ label byte
d@w label word
_DATA ends
_BSS segment word public 'BSS'
b@ label byte
b@w label word
_BSS ends
_TEXT segment byte public 'CODE'
;
; void CalibrateJoy (int joynum)
;
assume cs:_TEXT
_CalibrateJoy proc near
push bp
mov bp,sp
sub sp,42
push si
push di
mov si,word ptr [bp+4]
;
; {
; int stage,dx,dy,xl,yl,xh,yh;
; ControlStruct ctr;
;
; ExpWin (34,11);
;
mov ax,11
push ax
mov ax,34
push ax
call near ptr _ExpWin
pop cx
pop cx
;
;
;
; fontcolor=13;
;
mov word ptr DGROUP:_fontcolor,13
;
; CPPrint("Joystick Configuration\n");
;
mov ax,offset DGROUP:s@
push ax
call near ptr _CPPrint
pop cx
;
; py+=6;
;
add word ptr DGROUP:_py,6
;
; fontcolor=15;
;
mov word ptr DGROUP:_fontcolor,15
;
; PPrint("Hold the joystick in the UPPER LEFT\n");
;
mov ax,offset DGROUP:s@+24
push ax
call near ptr _PPrint
pop cx
;
; PPrint("corner and press a button:");
;
mov ax,offset DGROUP:s@+61
push ax
call near ptr _PPrint
pop cx
;
; stage=15;
;
mov di,15
;
; sx=(px+7)/8;
;
mov ax,word ptr DGROUP:_px
add ax,7
shr ax,1
shr ax,1
shr ax,1
mov word ptr DGROUP:_sx,ax
@1@50:
;
; do // wait for a button press
; {
; DrawChar (sx,py,stage);
;
push di
push word ptr DGROUP:_py
push word ptr DGROUP:_sx
call near ptr _DrawChar
add sp,6
;
; WaitVBL (3);
;
mov ax,3
push ax
call near ptr _WaitVBL
pop cx
;
; if (++stage==23)
;
inc di
mov ax,di
cmp ax,23
jne short @1@98
;
; stage=15;
;
mov di,15
@1@98:
;
; ReadJoystick (joynum,&xl,&yl);
;
lea ax,word ptr [bp-8]
push ax
lea ax,word ptr [bp-6]
push ax
push si
call near ptr _ReadJoystick
add sp,6
;
; ctr = ControlJoystick(joynum);
;
lea ax,word ptr [bp-18]
push ss
push ax
push si
push ss
lea ax,word ptr [bp-24]
push ax
call near ptr _ControlJoystick
add sp,6
lea ax,word ptr [bp-24]
push ss
push ax
mov cx,6
call near ptr N_SCOPY@
;
; if (keydown[1])
;
cmp byte ptr DGROUP:_keydown+1,0
je short @1@146
;
; return;
;
jmp @1@674
@1@146:
;
; } while (ctr.button1!= 1 && ctr.button2!=1);
;
cmp word ptr [bp-16],1
je short @1@194
cmp word ptr [bp-14],1
jne short @1@50
@1@194:
;
; DrawChar(sx,py,BLANKCHAR);
;
mov ax,9
push ax
push word ptr DGROUP:_py
push word ptr DGROUP:_sx
call near ptr _DrawChar
add sp,6
@1@218:
;
; do // wait for the button release
; {
; ctr = ControlJoystick(joynum);
;
lea ax,word ptr [bp-18]
push ss
push ax
push si
push ss
lea ax,word ptr [bp-30]
push ax
call near ptr _ControlJoystick
add sp,6
lea ax,word ptr [bp-30]
push ss
push ax
mov cx,6
call near ptr N_SCOPY@
;
; } while (ctr.button1);
;
cmp word ptr [bp-16],0
jne short @1@218
;
; WaitVBL (4); // so the button can't bounce
;
mov ax,4
push ax
call near ptr _WaitVBL
pop cx
;
;
; py+=6;
;
add word ptr DGROUP:_py,6
;
; PPrint("\nHold the joystick in the LOWER RIGHT\n");
;
mov ax,offset DGROUP:s@+88
push ax
call near ptr _PPrint
pop cx
;
; PPrint("corner and press a button:");
;
mov ax,offset DGROUP:s@+127
push ax
call near ptr _PPrint
pop cx
@1@290:
;
; do // wait for a button press
; {
; DrawChar (sx,py,stage);
;
push di
push word ptr DGROUP:_py
push word ptr DGROUP:_sx
call near ptr _DrawChar
add sp,6
;
; WaitVBL (3);
;
mov ax,3
push ax
call near ptr _WaitVBL
pop cx
;
; if (++stage==23)
;
inc di
mov ax,di
cmp ax,23
jne short @1@338
;
; stage=15;
;
mov di,15
@1@338:
;
; ReadJoystick (joynum,&xh,&yh);
;
lea ax,word ptr [bp-12]
push ax
lea ax,word ptr [bp-10]
push ax
push si
call near ptr _ReadJoystick
add sp,6
;
; ctr = ControlJoystick(joynum);
;
lea ax,word ptr [bp-18]
push ss
push ax
push si
push ss
lea ax,word ptr [bp-36]
push ax
call near ptr _ControlJoystick
add sp,6
lea ax,word ptr [bp-36]
push ss
push ax
mov cx,6
call near ptr N_SCOPY@
;
; if (keydown[1])
;
cmp byte ptr DGROUP:_keydown+1,0
je short @1@386
;
; return;
;
jmp @1@674
@1@386:
;
; } while (ctr.button1!= 1 && ctr.button2!=1);
;
cmp word ptr [bp-16],1
je short @1@434
cmp word ptr [bp-14],1
jne short @1@290
@1@434:
;
; DrawChar (sx,py,BLANKCHAR);
;
mov ax,9
push ax
push word ptr DGROUP:_py
push word ptr DGROUP:_sx
call near ptr _DrawChar
add sp,6
@1@458:
;
; do // wait for the button release
; {
; ctr = ControlJoystick(joynum);
;
lea ax,word ptr [bp-18]
push ss
push ax
push si
push ss
lea ax,word ptr [bp-42]
push ax
call near ptr _ControlJoystick
add sp,6
lea ax,word ptr [bp-42]
push ss
push ax
mov cx,6
call near ptr N_SCOPY@
;
; } while (ctr.button1);
;
cmp word ptr [bp-16],0
jne short @1@458
;
;
; //
; // figure out good boundaries
; //
;
; dx=(xh-xl) / 6;
;
mov ax,word ptr [bp-10]
sub ax,word ptr [bp-6]
mov bx,6
cwd
idiv bx
mov word ptr [bp-2],ax
;
; dy=(yh-yl) / 6;
;
mov ax,word ptr [bp-12]
sub ax,word ptr [bp-8]
mov bx,6
cwd
idiv bx
mov word ptr [bp-4],ax
;
; JoyXlow[joynum]=xl+dx;
;
mov bx,si
shl bx,1
mov ax,word ptr [bp-6]
add ax,word ptr [bp-2]
mov word ptr DGROUP:_JoyXlow[bx],ax
;
; JoyXhigh[joynum]=xh-dx;
;
mov bx,si
shl bx,1
mov ax,word ptr [bp-10]
sub ax,word ptr [bp-2]
mov word ptr DGROUP:_JoyXhigh[bx],ax
;
; JoyYlow[joynum]=yl+dy;
;
mov bx,si
shl bx,1
mov ax,word ptr [bp-8]
add ax,word ptr [bp-4]
mov word ptr DGROUP:_JoyYlow[bx],ax
;
; JoyYhigh[joynum]=yh-dy;
;
mov bx,si
shl bx,1
mov ax,word ptr [bp-12]
sub ax,word ptr [bp-4]
mov word ptr DGROUP:_JoyYhigh[bx],ax
;
; if (joynum==1)
;
cmp si,1
jne short @1@554
;
; playermode[1]=joystick1;
;
mov word ptr DGROUP:_playermode+2,2
jmp short @1@578
@1@554:
;
; else
; playermode[1]=joystick2;
;
mov word ptr DGROUP:_playermode+2,3
@1@578:
;
;
; py+=6;
;
add word ptr DGROUP:_py,6
;
; PPrint ("\n(F)ire or (A)fterburn with B1 ?");
;
mov ax,offset DGROUP:s@+154
push ax
call near ptr _PPrint
pop cx
;
; ch = PGet();
;
call near ptr _PGet
mov byte ptr DGROUP:_ch,al
;
; if ( ch == 'A' || ch == 'a')
;
cmp byte ptr DGROUP:_ch,65
je short @1@626
cmp byte ptr DGROUP:_ch,97
jne short @1@650
@1@626:
;
; buttonflip = 1;
;
mov word ptr DGROUP:_buttonflip,1
jmp short @1@674
@1@650:
;
; else
; buttonflip = 0;
;
mov word ptr DGROUP:_buttonflip,0
@1@674:
;
; }
;
pop di
pop si
mov sp,bp
pop bp
ret
_CalibrateJoy endp
_TEXT ends
_DATA segment word public 'DATA'
db 63
db 63
db 49
db 50
db 51
db 52
db 53
db 54
db 55
db 56
db 57
db 48
db 45
db 43
db 63
db 63
db 81
db 87
db 69
db 82
db 84
db 89
db 85
db 73
db 79
db 80
db 91
db 93
db 124
db 63
db 65
db 83
db 68
db 70
db 71
db 72
db 74
db 75
db 76
db 59
db 34
db 63
db 63
db 63
db 90
db 88
db 67
db 86
db 66
db 78
db 77
db 44
db 46
db 47
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 15
db 63
db 45
db 21
db 53
db 17
db 43
db 63
db 19
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
db 63
_DATA ends
_TEXT segment byte public 'CODE'
;
; void printscan (int sc)
;
assume cs:_TEXT
_printscan proc near
push bp
mov bp,sp
sub sp,4
push si
mov si,word ptr [bp+4]
;
; {
; char static chartable[128] =
; {'?','?','1','2','3','4','5','6','7','8','9','0','-','+','?','?',
; 'Q','W','E','R','T','Y','U','I','O','P','[',']','|','?','A','S',
; 'D','F','G','H','J','K','L',';','"','?','?','?','Z','X','C','V',
; 'B','N','M',',','.','/','?','?','?','?','?','?','?','?','?','?',
; '?','?','?','?','?','?','?','?', 15,'?','-', 21,'5', 17,'+','?',
; 19,'?','?','?','?','?','?','?','?','?','?','?','?','?','?','?',
; '?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?',
; '?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?'};
;
; sc = sc & 0x7f;
;
mov ax,si
and ax,127
mov si,ax
;
;
; if (sc==1)
;
cmp si,1
jne short @2@74
;
; PPrint ("ESC");
;
mov ax,offset DGROUP:s@+187
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@74:
;
; else if (sc==0xe)
;
cmp si,14
jne short @2@122
;
; PPrint ("BKSP");
;
mov ax,offset DGROUP:s@+191
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@122:
;
; else if (sc==0xf)
;
cmp si,15
jne short @2@170
;
; PPrint ("TAB");
;
mov ax,offset DGROUP:s@+196
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@170:
;
; else if (sc==0x1d)
;
cmp si,29
jne short @2@218
;
; PPrint ("CTRL");
;
mov ax,offset DGROUP:s@+200
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@218:
;
; else if (sc==0x2A)
;
cmp si,42
jne short @2@266
;
; PPrint ("LSHIFT");
;
mov ax,offset DGROUP:s@+205
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@266:
;
; else if (sc==0x39)
;
cmp si,57
jne short @2@314
;
; PPrint ("SPACE");
;
mov ax,offset DGROUP:s@+212
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@314:
;
; else if (sc==0x3A)
;
cmp si,58
jne short @2@362
;
; PPrint ("CAPSLK");
;
mov ax,offset DGROUP:s@+218
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@362:
;
; else if (sc>=0x3b && sc<=0x44)
;
cmp si,59
jl short @2@458
cmp si,68
jg short @2@458
;
; {
; char str[3];
; PPrint ("F");
;
mov ax,offset DGROUP:s@+225
push ax
call near ptr _PPrint
pop cx
;
; itoa (sc-0x3a,str,10);
;
mov ax,10
push ax
lea ax,word ptr [bp-4]
push ax
mov ax,si
add ax,65478
push ax
call near ptr _itoa
add sp,6
;
; PPrint (str);
;
lea ax,word ptr [bp-4]
push ax
call near ptr _PPrint
pop cx
;
; }
;
jmp @2@1346
@2@458:
;
; else if (sc==0x57)
;
cmp si,87
jne short @2@506
;
; PPrint ("F11");
;
mov ax,offset DGROUP:s@+227
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@506:
;
; else if (sc==0x59)
;
cmp si,89
jne short @2@554
;
; PPrint ("F12");
;
mov ax,offset DGROUP:s@+231
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@554:
;
; else if (sc==0x46)
;
cmp si,70
jne short @2@602
;
; PPrint ("SCRLLK");
;
mov ax,offset DGROUP:s@+235
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@602:
;
; else if (sc==0x1c)
;
cmp si,28
jne short @2@650
;
; PPrint ("ENTER");
;
mov ax,offset DGROUP:s@+242
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@650:
;
; else if (sc==0x36)
;
cmp si,54
jne short @2@698
;
; PPrint ("RSHIFT");
;
mov ax,offset DGROUP:s@+248
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@698:
;
; else if (sc==0x37)
;
cmp si,55
jne short @2@746
;
; PPrint ("PRTSC");
;
mov ax,offset DGROUP:s@+255
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@746:
;
; else if (sc==0x38)
;
cmp si,56
jne short @2@794
;
; PPrint ("ALT");
;
mov ax,offset DGROUP:s@+261
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@794:
;
; else if (sc==0x47)
;
cmp si,71
jne short @2@842
;
; PPrint ("HOME");
;
mov ax,offset DGROUP:s@+265
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@842:
;
; else if (sc==0x49)
;
cmp si,73
jne short @2@890
;
; PPrint ("PGUP");
;
mov ax,offset DGROUP:s@+270
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@890:
;
; else if (sc==0x4f)
;
cmp si,79
jne short @2@938
;
; PPrint ("END");
;
mov ax,offset DGROUP:s@+275
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@938:
;
; else if (sc==0x51)
;
cmp si,81
jne short @2@986
;
; PPrint ("PGDN");
;
mov ax,offset DGROUP:s@+279
push ax
call near ptr _PPrint
pop cx
jmp @2@1346
@2@986:
;
; else if (sc==0x52)
;
cmp si,82
jne short @2@1034
;
; PPrint ("INS");
;
mov ax,offset DGROUP:s@+284
push ax
call near ptr _PPrint
pop cx
jmp short @2@1346
@2@1034:
;
; else if (sc==0x53)
;
cmp si,83
jne short @2@1082
;
; PPrint ("DEL");
;
mov ax,offset DGROUP:s@+288
push ax
call near ptr _PPrint
pop cx
jmp short @2@1346
@2@1082:
;
; else if (sc==0x45)
;
cmp si,69
jne short @2@1130
;
; PPrint ("NUMLK");
;
mov ax,offset DGROUP:s@+292
push ax
call near ptr _PPrint
pop cx
jmp short @2@1346
@2@1130:
;
; else if (sc==0x48)
;
cmp si,72
jne short @2@1178
;
; PPrint ("UP");
;
mov ax,offset DGROUP:s@+298
push ax
call near ptr _PPrint