-
Notifications
You must be signed in to change notification settings - Fork 1
/
bdos.a86
4152 lines (4146 loc) · 77.3 KB
/
bdos.a86
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
; BASIC DISK OPERATING SYSTEM OF CP/M 86
;
; 1983.8.16.
;
; EQUATIONS OF FUNCTION
;
CLIST EQU 5 ;LIST OUT
CRTVNO EQU 12 ;RETURN VERION NUMBER
CREADS EQU 20 ;READ SEQUENTIAL
CSTDMA EQU 26 ;SET DMA OFFSET
CSTDMS EQU 51 ;SET DMA SEGMENT
CGTMXM EQU 53 ;GET MAXIMUM MEMORY
CGTAMX EQU 54 ;GET ABSOLUTE MAXIMUM MEOMRY
CALMEM EQU 55 ;ALLOCATE MEMORY
CALAME EQU 56 ;ALLOCATE ABSOLUTE MEMORY
;
; EQUATIONS OF DATA
;
BS EQU 8 ;BACK SPACE
HT EQU 9 ;HORIZONTAL TAB
LF EQU 0AH ;LINE FEED
CR EQU 0DH ;CARRIAGE RETURN
ITBDOS EQU 0E0H ;BDOS INTERRUPT VECTOR
DELCOD EQU 0E5H ;DELETED FILE DIRECTORY CODE
;
; EQUATIONS OF DATA
;
COMBUF EQU 9 ;COMMAND BUFFER OF CCP
MDSUBE EQU 0805H ;SUBMIT MODE
;
; EQUATIONS OF BIOS VECTOR
;
VBIOS EQU 2500H ;BIOS JUMP VECTOR TOP
VINIT EQU VBIOS+00H ;INITIALIZE COLD START
VWBOOT EQU VBIOS+03H ;WARM START
VCONST EQU VBIOS+06H ;CONSOLE STATUS
VCONIN EQU VBIOS+09H ;CONSOLE INPUT
VCONOT EQU VBIOS+0CH ;CONSOLE OUTPUT
VLIST EQU VBIOS+0FH ;LIST OUT
VPUNCH EQU VBIOS+12H ;PUNCH OUT
VREADR EQU VBIOS+15H ;READER IN
VHOME EQU VBIOS+18H ;HOME
VSLDSK EQU VBIOS+1BH ;SELECT DISK
VSTTRK EQU VBIOS+1EH ;SET TRACK
VSTSEC EQU VBIOS+21H ;SET SECTOR
VSTDMA EQU VBIOS+24H ;SET DMA OFFSET
VDREAD EQU VBIOS+27H ;READ ONE SECTOR
VDWRIT EQU VBIOS+2AH ;WRITE ONE SECTOR
VSCTRN EQU VBIOS+30H ;SECTOR TRANSLATE
VSTDMS EQU VBIOS+33H ;SET DMA SEGMENT
VGTMRT EQU VBIOS+36H ;GET MEMORY REGION TABLE
VGTIOB EQU VBIOS+39H ;GET I/O BYTE
VSTIOB EQU VBIOS+3CH ;SET I/ BYTE
;
;
CSEG
ORG 0
TOP: ;DUMMY FOR TAGGED LABEL
; TS: START PATCH 13
ORG 0A00H
PATCH13:
MOV CS:FLINSD, 01
PUSH AX
MOV AH, CS:AFWFCB
MOV AL, CS:FLOMOD
PUSH AX
INT ITBDOS
POP AX
MOV CS:FLOMOD, AL
MOV CS:AFWFCB, AH
POP AX
RET
NOP
; TS: END PATCH 13
;
ORG 0A20H
;
; PATCH AREA
;
; FOR LOAD PROGRAM
;
MLOADK: ;OK END
MOV INSTOF,AX ;RESTORE ENTRY STACK & END FOR LOAD PROGRAM
POP ES
RET
;
ORG 0A30H
;
MLOADQ: ;ERROR END OF LOAD PROGRAM
MOV AX,FCBSEG
MOV INDSEG,AX
MOV OTPARA,-1
JMP MLOADE
;
ORG 0A50H
;
; FOR BDOS BODY
; CHECK BDOS FUNCTION CODE RANGE
;
BDOSBC:
JC BDOSBI ;IN RANGE
MOV OTPARA,-1 ;OVER END
RET
;
BDOSBI: ;IN RANGE
JMP BDOSBS
;
;
ORG 0A60H
; TS: START PATCH 15
; DB '12 january 82'
PATCH15:
CMP WORD PTR 03[SI],0
JZ PATCH15_AX
PUSH AX
MOV AX, WORD PTR 03[SI]
MOV DGBASE,AX
POP AX
JMPS END_PATCH15
PATCH15_AX:
MOV DGBASE,AX
END_PATCH15:
JMP STLDBD
; TS: END PATCH 15
;
; TS: START IBM VINIT
;CSEG
;ORG 0A00H
;PATCH_VINIT:
;ADD BX, VINIT
;JMP BIOSCL
; TS: END PATCH IBM VINIT
ORG 0A80H
;
; BDOS FUNCTION INDEX
;
IXMAIN:
DW MSYRST ; 0 SYSTEM RESET
DW MCONIN ; 1 CONSOLE INPUT
DW CONOUT ; 2 CONSOLE OUTPUT
DW MREDER ; 3 READER INPUT
DW VPUNCH ; 4 PUNCHER UTPUT
DW BLIST ; 5 LIST OUTPUT
DW MDCNIO ; 6 DIRECT CONSOLE I/O
DW MGTIOB ; 7 GET I/O BYTE
DW MSTIOB ; 8 SET I/O BYTE
DW MBUFPR ; 9 PRINT STRING
DW MRDCBF ;10 READ CONSOLE BUFFER
DW MCONST ;11 CONSOLE STATUS
DW MRTVNO ;12 RETURN VERSION NUMBER
DW MRSDSY ;13 RESET DISK SYSTEM
DW MSELDK ;14 SELECT DISK
DW MOPEN ;15 OPEN FILE
DW MCLOSE ;16 CLOSE FILE
DW MSRCHF ;17 SEARCH FOR FIRST
DW MSRCHN ;18 SEARCH FOR NEXT
DW MDELET ;19 DELETE FILE
DW MREADS ;20 READ SEQUENTIAL
DW MWRITS ;21 WRITE SEQUENTIAL
DW MMAKE ;22 MAKE FILE
DW MRENAM ;23 RENAME FILE
DW MRTLIV ;24 RETURN LOGIN VECTOR
DW MRTCDK ;25 RETURN CURRENT DISK
DW MSTDMO ;26 SET DMA OFFSET
DW MGTALM ;27 GET ALLOCATION MAP ADDRESS
DW MWPDSK ;28 WRITE PROTECT DISK
DW MGTROV ;29 GET READ/ONLY VECTOR
DW MSTFAT ;30 SET FILE ATTRIBUTE
DW MGDPBA ;31 GET DISK PARAMETER BLOCK ADDRESS
DW MSTUCD ;32 SET/GET USER CODE
DW MREADR ;33 READ RANDOM
DW MWRITR ;34 WRITE RANDOM
DW MCMPFS ;35 COMPUTE FILE SIZE
DW MSTRRC ;36 SET RANDOM RECORD
DW MRSTDV ;37 RESET DRIVE
DW NOPROC ;38 ACCESS DRIVE
DW NOPROC ;39 FREE DRIVE
DW MWRITZ ;40 WRITE RANDOM WITH ZERO FILL
DW MCHAIN ;47 CHAIN TO PROGRAM
DW MFLUSH ;48 FLUSH BUFFERS
DW MGTSAD ;49 GET SYSTEM ADDRESS
DW MDBIOS ;50 DIRECT BIOS CALL
DW MSTDMS ;51 SET DMA SEGMENT
DW MGTDMS ;52 GET DMA ADDRESS
DW MGTMXM ;53 GET MAXIMUM MEMORY
DW MGTAMX ;54 GET ABSOLUTE MAXIMUM MEMORY
DW MALMEM ;55 ALLOCATE MEMORY SEGMENT
DW MALAME ;56 ALLOCATE ABSOLUTE MEMORY SEGMENT
DW MFRMEM ;57 FREE SPECIFIED MEMORY SEGMENT
DW MFRALM ;58 FREE ALL MEMORY
DW MLOADP ;59 PROGRAM LOAD
;
; 12:RETURN VERSION NUMBER
;
MRTVNO:
MOV AL,022H ;2.2 IS VERSION NUMBER
;TS: START FIX WRONG ARCH
;MOV AX,01022h ;return 8086 instead of 8080
;TS: END FIX
JMP BTPRST ;H=0 SIMPLE CP/M
;
; 49:GET SYSTEM ADDRESS
;
MGTSAD:
MOV BX,OFFSET DMAADD ;SYSTEM DATA AREA TOP
JMP WDPRST
;
; BDOS NORMAL TOP
;
ORG 0B00H
;
; USER ID CODE OF BDOS
;
;TS: START PATCH ALIGN ON REF VERSION
;DB 1 ;OEM CODE
;DB 10 ;VERSION NUMBER
;DB 0
;DB 0,0,0 ;USER ID
DB 0 ;OEM CODE
DB 0Ah ;VERSION NUMBER
DB 0
DB 0,9,9Ah ;USER ID
;TS: END PATCH ALIGN ON REF VERSION
;
; BDOS ENTRY
;
BDOSEN:
PUSH DS
MOV AX,CS
MOV DS,AX
POP INDSEG ;SAVE ENTRY DATA SEGMENT
CMP CL,CLIST
JZ BDOSEC
CMP CL,CRTVNO+1
JC BDOSES ;SIMPLE BDOS CALL
BDOSEC: ;COMPLICATED I/O FUNCTION
MOV MDCONF,-1 ;SET COMPLICATED I/O MODE
BDOSES:
MOV INSTSG,SS
MOV INSTOF,SP ;SAVE ENTRY STACK
CMP FLINSD,1
JZ BDOSEI ;FROM INSIDE
MOV AX,CS
MOV SS,AX
MOV SP,OFFSET STACK ;SET SYSTEM STACK
BDOSEI:
MOV BX,INSTOF
MOV ES,INSTSG
MOV BX,ES:4[BX]
AND BX,200H ;GET INTERRUPT FALG
JZ $+3 ;DI
STI ;EI
MOV AX,DS
PUSH BP
PUSH DI
PUSH SI
PUSH CS
POP ES
MOV CURSEG,ES ;SAVE CURRENT SEGMENT
CALL BDOSB ;CALL BDOS BODY
POP SI
POP DI
POP BP
MOV ES,CURSEG
CLI
MOV SS,INSTSG ;RESTORE STACK
MOV SP,INSTOF
MOV MDCONF,0 ;CLEAR COMPLICATED I/O MODE
MOV DS,INDSEG
IRET
;
; BDOS BODY
;
BDOSB:
MOV INPARA,DX
MOV INPARB,DL
XOR AX,AX
MOV OTPARA,AX ;CLEAR OUTPUT PARAMETER
MOV AFWFCB,AL
MOV ENTTYP,AL
MOV FLOMOD,AL
MOV BX,OFFSET ENDPRC
PUSH BX ;SET RETURN ADDRESS
CMP CL,41
JC BDOSBS ;0 TO 40
SUB CL,6
CMP CL,60-6 ;47 TO 59
JMP BDOSBC ;CHECK OVER
;
BDOSBS:
MOV BL,CL
MOV BH,0
MOV CL,DL ;SET BYTE PARAMETER
ADD BX,BX
JMP WORD PTR IXMAIN[BX] ;TO EACH ROUTINE
;
; ERROR ROUTINES
;
; BAD SECTOR ERROR
;
EBADSC:
MOV BX,OFFSET CBADSC ;BAD SECTOR
CALL ERPROC
CMP AL,'C'-40H
JNZ STWFCE ;CONTINUE
JMPS EROFIE ;ABORT
;
; SELECT ERROR
;
ESELCT:
MOV BX,OFFSET CSELCT
JMPS EROFIS
;
; R/O DISK
;
ERODSK:
MOV BX,OFFSET CRODSK
JMPS EROFIS
;
; R/O FILE
;
EROFIL:
MOV BX,OFFSET CROFIL
EROFIS:
CALL ERPROC ;OUT COMMENT & WAIT RESPONSE
EROFIE:
JMP MSYRSA
;
; ERROR TRAP PROCESS
; INPUT
; BX:COMMENT POINT
;
ERPROC:
PUSH BX ;SAVE EACH COMMNET POINT
CALL CRLF
MOV AL,CURDSK
ADD AL,'A'
MOV CERRDK,AL ;SET DRIVE NAME
MOV CX,OFFSET CERROR
CALL BUFPRN ;BDOS ERROR ON X:
POP CX
CALL BUFPRN ;OUT EACH COMMENT
JMP CONINC ;RESPONSE WAIT
;
; SET INPUT DATA TO WORK FCB OR MCB
; INPUT
; CL:COPY COUNT
;
STWFCB:
PUSH DS
PUSH AX
PUSH CX
MOV AFWFCB,0FFH
MOV CNFCBC,CL ;SAVE COPY LENGTH
XOR CH,CH
MOV SI,INPARA ;OFFSET OF INPUT PARAMETER
MOV PTUFCB,SI
MOV DI,OFFSET WKFCB ;OFFSET OF WORK
MOV INPARA,DI
MOV DS,INDSEG ;SEGMENT OF INPUT PARAMETER
CLD
REP MOVSB ;GET DATA
POP CX
POP AX
POP DS
STWFCE:
RET
;
; SET SEQUENTIAL FCB
;
STWFCS:
PUSH CX
MOV CL,33 ;SEQUENTIAL FCB LENGTH IS 33
JMPS STWFCC
;
; SET RANDOM FCB
;
STWFCR:
PUSH CX
MOV CL,36 ;RANDOM FCB LENGTH IS 36
STWFCC:
CALL STWFCB
POP CX
RET
;
; RESTORE FCB DATA
;
RSTFCB:
PUSH ES
PUSH AX
PUSH CX
MOV CL,CNFCBC ;GET LENGTH
XOR CH,CH
MOV ES,INDSEG ;SEGMENT OF INPUT PARAMETER
MOV SI,OFFSET WKFCB
MOV DI,PTUFCB ;OFFSET OF ORIGINAL
MOV INPARA,DI
CLD
REP MOVSB ;RESTORE FCB DATA
POP CX
POP AX
POP ES
RET
;
; READ BY FAR ADDRESS FCB
;
READFR:
MOV CL,CREADS
MOV DX,UFCBOF ;USER FCB OFFSET
MOV DS,FCBSEG ;USER FCB SEGMENT
CALL BDOSIS ;READ SEQUENTIAL
MOV AX,CS
MOV DS,AX ;RESTORE SEGMENT
RET
;
; BDOS CALL FROM INSIDE OF BDOS
;
; MUST BE SAVE STACK SAVE AREA
; & CLEAR INSIDE FLAG AT END ???
;
BDOSIS:
; TS: START PATCH 13
; MOV CS:FLINSD,1 ;SET INSIDE FLAG
; INT ITBDOS
; RET
JMP PATCH13
NOP
NOP
NOP
NOP
NOP
NOP
; TS: END PATCH 13
;
; INTERNAL BDOS CALL FOR MEMORY MANAGEMENT
; INPUT
; CL:FUNCTION CODE
;
BDOSMM:
PUSH BX
MOV DX,OFFSET SYSMCB
CALL BDOSIS
POP BX
RET
;
; MEMORY MANAGEMENT UTILITY
;
; COMPARE MEMORY REQUEST BETWEEN MAX-MIN
; INPUT
; SI:GROUP DESCRIPTOR TOP
; DI:GROUP DESCRIPTOR TOP
; OUTPUT
; SI:SMALLER GD
; DI:LARGER GD
;
CMPMRQ:
PUSH AX
PUSH BX
MOV BX,7[SI]
SUB BX,5[SI] ;GET MAX-MIN
MOV AX,7[DI]
SUB AX,5[DI]
CMP BX,AX
JBE $+4 ;(DI) > (SI)
XCHG SI,DI
POP BX
POP AX
RET
;
; ALLOCATE MEMORY FOR LOAD PROGRAM
; OUTPUT
; AL:0 OK -1 CANNOT ALLOCATE
;
ALMEMR:
SUB BX,BX ;CLEAR MIN SIZE
SUB DX,DX ;CLEAR MAX SIZE
MOV FMODEL,0FFH ;SET 8080 MODEL FLAG
MOV CX,8 ;COUNT OF GROUP DESCRIPTOR
MOV SI,OFFSET BFGRDC ;BUFFER TOP
ALMEML: ;LOOP OF ONE GROUP DESCRIPTOR
CMP BYTE PTR [SI],0
JZ ALMEMN ;NOT ACTIVE DESCRIPTOR
CMP BYTE PTR [SI],2
JNZ ALMEMD ;NOT DATA GROUP
MOV FMODEL,0 ;DATA GROUP SO NOT 8080 MODEL
ALMEMD:
CMP WORD PTR 3[SI],0
JZ ALMEMG ;RELOCATABLE
MOV AX,3[SI] ;ABSOLUTE
MOV SYSMCB,AX ;SET ABSOLUTE BASE
CMP WORD PTR 7[SI],0
MOV AX,5[SI] ;MIN
JZ $+5 ;NO MAX SO DO BY MIN
MOV AX,7[SI] ;WITH MAX SO DO BY MAX
MOV SYSMCB+2,AX ;SET LENGTH
PUSH CX
MOV CL,CALAME
PUSH DX
CALL BDOSMM ;ALLOCATE ABSOLUTE MEMORY SEGMENT
POP DX
POP CX
CMP OTPARB,0
JZ ALMEMN ;OK ALLOCATED
PUSH CX ;NOT ALLOCATED
MOV CL,CGTAMX
CALL BDOSMM ;GET AVAILABLE MAXIMUM SIZE
POP CX
MOV AX,SYSMCB+2
CMP 5[SI],AX
JNC ALMEME ;SMALLER THAN MIN SO ERROR END
MOV 7[SI],AX ;SET AVAILABLE MAX AS LENGTH
MOV CL,CALAME
CALL BDOSMM ;ALLOCATE
JMPS ALMEMN ;TO NEXT
;
ALMEMG: ;RELOCATABLE GROUP
ADD BX,5[SI] ;GET TOTAL BY MIN
CMP WORD PTR 7[SI],0
JZ ALMEMM ;NO MAX SO DO BY MIN
ADD DX,7[SI] ;GET TOTAL MAX
JNC ALMEMN ;NOT OVER
MOV DX,0FFF0H ;OVER SO DO BY ABSOLUTE MAX VALUE
JMPS ALMEMN
;
ALMEME: ;ERROR
JMPS SRTGFF
;
ALMEMM: ;NO MAX SPECIFIED SO MIN USED AS MAX
ADD DX,5[SI] ;GET MAX TOTAL
ALMEMN: ;END OF ONE GROUP DESCRIPTOR
ADD SI,9
LOOP ALMEML ;TO NEXT GD
OR DX,DX
JZ ALMEMF ;NO RELOCATABLE LENGTH
MOV SYSMCB+2,DX ;SET MAX LENGTH
MOV CL,CALMEM
CALL BDOSMM ;ALLOCATE RELOCATABLE MEMORY
CMP OTPARB,0
JZ ALMEMF ;OK ALLOCATED
MOV CL,CGTMXM
CALL BDOSMM ;GET MAX SIZE
CMP BX,SYSMCB+2
JA ALMEME ;SMALLER THAN MIN SO ERROR END
MOV CL,CALMEM
CALL BDOSMM ;ALLOCATE BY MAXIMUM AVAILABLE SIZE
MOV DX,SYSMCB+2
SUB DX,BX ;GET SPACE BETWEEN AVAIL TO MIN
CALL STMXGD ;SET AVAILABLE MAX TO GD
ALMEMF:
MOV DI,PNUMCB
MOV AX,FCBSEG
MOV CX,CS
CMP AX,CX
JNZ ALMEMS ;NOT SYSTEM
MOV BYTE PTR 4[DI],1 ;SYSTEM
INC CNUMCB
ALMEMS:
JMPS SRTGFG
;
; SEARCH TARGET GROUP FORM
; INPUT
; AL:TARGET GROUP FORM
; OUTPUT
; SI:GD TOP
; AL:0 OK -1 NOT FOUND
;
SRTGFM:
MOV SI,OFFSET BFGRDC
MOV CX,8
SRTGFL:
CMP [SI],AL
JZ SRTGFG ;GET MATCHED GD
ADD SI,9
LOOP SRTGFL ;TO NEXT
SRTGFF: ;FAIL END
MOV AL,0FFH
RET
;
SRTGFG: ;OK END
MOV AL,0
RET
;
; SETUP MAXIMUM VALUE OF GROUP DESCRIPTOR
; INPUT
; DX:EXTRA SPACE
;
STMXGD:
CMP FMODEL,0FFH
JNZ STMXGN ;NOT 8080 MODEL
MOV BX,BFGRDC+5 ;8080 MODEL
ADD BX,DX
MOV BFGRDC+7,BX ;SO SET IN TOP GD
RET
;
STMXGN: ;NOT 8080 MODEL
MOV AL,2
CALL SRTGFM ;SEARCH DATA GROUP
CMP WORD PTR 7[SI],0
JZ STMXGX ;NO REQUEST OF MAX
MOV DI,SI
MOV AX,3
CALL SRTGFM ;SEARCH EXTRA GROUP
CMP WORD PTR 7[SI],0
JZ STMXGS ;NO REQUEST OF MAX
CALL CMPMRQ ;GET LARGER REQUESTED GROUP
SHR DX,1 ;GET HALF SPACE
MOV BX,DX
ADD BX,5[SI]
CMP BX,7[SI]
JBE STMXGR ;REQUESTED IS LARGER THAN AVAIL HALF
SUB BX,7[SI] ;REQUESTED IS SMALLER
ADD DX,BX ;SO GET LEFT AVAIL SPACE
JMPS STMXGS
;
STMXGR: ;REQUESTED IS LARGER
MOV 7[SI],BX ;SET HALF SPACE
STMXGS:
ADD DX,5[DI]
MOV 7[DI],DX ;SET LEFT SPACE
RET
;
STMXGX: ;DATA GROUP HAS NO REQUEST
MOV AL,3
CALL SRTGFM ;SEARCH EXTRA GROUP
ADD DX,5[SI]
MOV 7[SI],DX ;SET LEFT SPACE
RET
;
; ADD GROUP LENGTH
; INPUT
; SI:GD POINT
; AX:TOTAL
; OUTPUT
; AX:TOTAL
;
ADDGLN:
CMP WORD PTR 7[SI],0
JZ ADDGLS ;NO MAX SO DO BY MIN
ADD AX,7[SI] ;ADD MAX
RET
;
ADDGLS: ;DO BY MIN
ADD AX,5[SI] ;ADD MIN
RET
;
; SETUP LOADING BASE
;
STLDBS:
MOV MODE80,0
MOV AX,SYSMCB ;GET LOADING BASE OF RELOCATABLE
CMP FMODEL,0FFH
JNZ STLDBM ;NOT 8080 MODEL
MOV MODE80,1 ;8080 MODEL
MOV BFGRDC+3,AX ;SET BASE OF TOP GD
MOV DGBASE,AX ;SET SAME BASE TO DATA SEGMENT BASE
JMPS STLDBF
;
STLDBM: ;NOT 8080 MODEL
MOV SI,OFFSET BFGRDC
MOV CX,8
STLDBL: ;ONE GD LOOP
CMP BYTE PTR [SI],0
JZ STLDBA ;NOT ACTIVE
CMP BYTE PTR [SI],2
JNZ STLDBD ;NO DATA GROUP
; TS: START PATCH 15
; MOV DGBASE,AX ;SAVE DATA SEGMENT BASE
JMP PATCH15
; TS: END PATCH 15
STLDBD:
CMP WORD PTR 3[SI],0
JNZ STLDBN ;ABSOULTE
MOV 3[SI],AX ;RELOCATABLE SO SET BASE
CMP BYTE PTR [SI],9
JNZ STLDBA
MOV BYTE PTR [SI],1 ;SHARED CODE GROUP SO TO CODE GROUP
STLDBA:
CALL ADDGLN ;ADD GROUP LENGTH
STLDBN:
ADD SI,9
LOOP STLDBL ;TO NEXT GD
STLDBF:
RET
;
; GET ONE PARAGRAPH DATA
; INPUT
; BP:COUNT
; OUTPUT
; SI:DATA POINT
;
GOPGDT:
CMP BP,16*7
JNZ GOPGDS ;NOT END
PUSH BX ;END OF ONE SECTOR SO GET NEXT SECTOR
PUSH ES
CALL READFR ;GET ONE SECTOR
POP ES
POP BX
MOV BP,0 ;CLEAR COUNT
MOV SI,OFFSET BFLDPR ;SET DATA TOP POINT
RET
;
GOPGDS: ;NOT END
ADD BP,16 ;UP COUNT
RET
;
; MAKE LENGTH BY BYTE
; INPUT
; AX:LENGTH BY PARAGRAPH
; OUTPUT
; AH,BX:BYTE LENGTH
;
MKBTLG:
MOV BX,AX
AND AX,0F000H
MOV CL,4
SHR AH,CL ;GET HIGHER 4 BITS
MOV CL,4
SHL BX,CL
SUB BX,1
JNC $+4
DEC AH
RET
;
; 59:LOAD PROGRAM
;
MLOADP:
MOV AX,INDSEG
MOV FCBSEG,AX ;SET FCB SEGMENT
PUSH ES
NOP
MOV UFCBOF,DX ;SET FCB OFFSET
MOV AX,INSTSG
MOV LPSTSG,AX
MOV AX,INSTOF
MOV LPSTOF,AX ;SAVE ENTRY STACK POINTER
MOV DX,CS
MOV CL,CSTDMS
CALL BDOSIS ;SET DATA SEGMENT
MOV DX,OFFSET BFGRDC
MOV CL,CSTDMA
CALL BDOSIS ;SET DMA OFFSET TO GD WORK
CALL READFR ;GET GROUP DESCRIPTOR
CMP OTPARB,0
JZ MLOADS ;OK
MLOADM: ;ERROR END
JMP MLOADR
;
MLOADS:
CALL ALMEMR ;ALLOCATE REQUESTED MEMORY
TEST AL,AL
JNZ MLOADM ;CANNOT ALLOCATE
CALL STLDBS ;SETUP LOADING BASE OF EACH GD
MOV DX,OFFSET BFLDPR
MOV CL,CSTDMA
CALL BDOSIS ;SET DMA OFFSET TO READ WORK
MOV BP,16*7
MOV CX,8
MOV BX,OFFSET BFGRDC
MLOADL: ;ONE GD LOOP
PUSH CX
CMP BYTE PTR [BX],0
JZ MLOADN ;NOT ACTIVE GD
MOV ES,3[BX] ;GET BASE
MOV DI,0
MOV CX,1[BX] ;GET PARAGRAPH LENGTH
JCXZ MLOADN ;NO LENGTH
MLOADG: ;ONE PARAGRAPH LOADING LOOP
PUSH CX
CALL GOPGDT ;GET DATA
MOV CX,8
CLD
REP MOVSW ;MOVE TO TARGET
CMP DI,0
JNZ MLOADB ;NOT 64K BAUNDARY
MOV DX,ES ;UP SEGMENT
ADD DH,010H
MOV ES,DX
MLOADB:
POP CX
LOOP MLOADG ;TO NEXT
MLOADN:
POP CX
ADD BX,9
LOOP MLOADL ;TO NEXT GD
MOV ES,DGBASE ;GET DATA GROUP SEGMENT
MOV OTPARA,ES
MOV DI,0
MOV CX,48
MOV AL,0
CLD
REP STOSB ;CLEAR BASE PAGE
MOV DI,0
MOV AL,MODE80
MOV ES:5[DI],AL ;SET 8080 MODEL MODE
MOV DL,1 ;CODE GROUP FORM
MLOADF: ;ONE FORM TYPE PARAMETER SETUP LOOP
MOV SI,OFFSET BFGRDC
MOV CX,8
MLOADC: ;GD SEARCH LOOP
CMP [SI],DL
JZ MLOADT ;GET TARGET GD
ADD SI,9
LOOP MLOADC ;TO NEXT GD
JMPS MLOADX ;NOT MATCH SO TO NEXT FORM
;
MLOADT: ;GET TARGET GD
MOV AX,3[SI]
MOV ES:3[DI],AX ;SET BASE PARAGRAPH ADDRESS
MOV AX,5[SI]
CMP WORD PTR 7[SI],0
JZ $+5 ;NO MAX SO BY MIN
MOV AX,7[SI] ;GET MAX SIZE
CALL MKBTLG ;TO BYTE LENGTH
MOV ES:2[DI],AH ;SET HIGHER 4 BITS
MOV ES:[DI],BX ;SET LOWER 16 BITS
CMP FMODEL,0FFH
JNZ MLOADX ;NOT 8080 MODEL
ADD DI,6 ;8080 MODEL
MOV ES:2[DI],AH ;SET ALSO IN DATA SEGMENT PARAMETER
MOV ES:[DI],BX
JMPS MLOADE
;
MLOADX: ;TO NEXT FORM
INC DL
ADD DI,6
CMP DL,8
JBE MLOADF ;TO NEXT FORM
MLOADE: ;END OF LOADING
MOV AX,UFCBOF
MOV INPARA,AX
MOV FLINSD,0 ;CLEAR INSIDE MODE
MOV AX,LPSTSG
MOV INSTSG,AX ;RESTORE ENTRY STACK
MOV AX,LPSTOF
JMP MLOADK ;TO RETSTORE & END
;
NOP
;
MLOADR: ;ERROR END
JMP MLOADQ
;
; NOT USED BY PATCH
;
DB 24H,0FFH,0FFH
JMPS MLOADE
;
; 0:SYSTEM RESET
; INPUT PARAMETER:ABORT CODE BYTE
;
MSYRST:
MOV AL,INPARB ;GET ABORT MODE
CMP AL,1
JZ MSYRSR ;MEMORY REMAINING ABORT
MSYRSA:
MOV BYTE PTR .COMBUF+1,0
MSYRSF:
CMP CNUMCB,001H
JA MSYRSC ;SOME MEMORY AREA ACTIVE
CALL MFRALM ;FREE ALL MEMORY
JMPS MSYRSR
;
MSYRSC: ;FREE CURRENT MEMORY
CALL FRCRAR
MOV BX,PNUMCB ;GET USED MCB BUFFER POINT
CALL FREMEM ;FREE LAST MEMORY AREA
DEC CNUMCB ;DOWN USED MCB COUNT
MSYRSR:
MOV FLINSD,0 ;CLEAR BDOS INSIDE MODE
MOV BX,VWBOOT
JMP BIOSCL ;WARM BOOT
;
; 50:DIRECT BIOS CALL
;
MDBIOS:
PUSH DS
MOV DS,INDSEG
MOV BX,DX
MOV AL,[BX] ;GET FUNCTION NUMBER
MOV CX,1[BX] ;GET CX
MOV DX,3[BX] ;GET DX
POP DS
POP BX ;CANCEL END PROCESS DIRECT RETURN TO BDOS MAIN
XOR BX,BX
MOV BL,AL
ADD AL,AL
ADD BL,AL ;*3
ADD BX,VINIT ;GET VECTOR
JMP BX ;TO BIOS ROUTINE
;
; 51:SET DMA SEGMNET
;
MSTDMS:
MOV DMASEG,DX ;SAVE SEGMENT
MOV CX,DX
CALL TOP+VSTDMS ;SET IN BIOS
RET
;
; 52:GET DMA SEGMENT
;
MGTDMS:
MOV BX,DMASEG ;GET SEGMENT
MOV CURSEG,BX ;SAVE SEGMENT
MOV BX,DMAADD ;GET OFFSET
JMP WDPRST
;
; SAVE MCB DATA TO BUFFER
; INPUT
; BX:MCB POINT
;
SVMCBD:
SUB PNUMCB,5 ;DOWN USED MCB BUFFER POINTER
MOV DI,PNUMCB
MOV AX,[BX] ;GET BASE
MOV [DI],AX
MOV AX,2[BX] ;GET LENGTH
MOV 2[DI],AX
MOV BYTE PTR 4[DI],0 ;SET AS CURRENT MODE
ADD CNTREG,1 ;UP COUNT
RET
;
; 53:GET MAXIMUM AVAILABLE MEMORY
;
MGTMXM:
CALL CGBSPR ;CHECK & GET BASE
JNZ MGTMXS ;NO SPACE
CMP SIZREG,0
JZ MALAMR ;NO REGION DATA
CALL GMXRTP ;GET MAXIMUM REGION POINT
MGTMXS:
JNZ MALAMR ;NO SPACE
MOV AX,2[SI]
CMP 2[BX],AX
JC $+5 ;ENOUGH LENGTH
MOV 2[BX],AX ;SHORT SO SET LENGTH
MOV AX,[SI]
MOV [BX],AX ;SET BASE
JMPS MALAMS
;
; 54:GET ABSOLUTE MAXIMUM ADDRESS
;
MGTAMX:
CALL CGBSPR ;CHECK & GET BASE
JNZ MALAMR ;NO SPACE
MGTAML: ;CHECK LOOP
ADD SI,4
INC CL
CMP CL,SIZREG
JNC MALAMR ;ALL OVER
CALL CKABAR ;CHECK REQUESTED AREA WITH TABLE
JNZ MGTAML ;NOT MATCH TO NEXT
MOV AX,2[SI] ;GET MATCHED AREA
ADD AX,[SI] ;GET MAXIMUM ADDRESS
SUB AX,[BX]
CMP 2[BX],AX
JC MGTAME ;ENOUGH LENGTH
MOV 2[BX],AX ;SET LENGTH
MGTAME:
JMPS MALAMS
;
; 55:ALLOCATE MEMORY AREA
;
MALMEM:
CALL CGBSPR ;CHECK & GET BASE
JNZ MALAMR ;NO SPACE
CALL SRSTRG ;SEARCH SUITABLE REGION
JNZ MALAMR ;NO SPACE
CALL GSREGN ;GET & SET REGION
CALL SVMCBD ;SAVE IN USED MCB BUFFER
JMPS MALAMS
;
; 56:ALLOCATE ABSOLUTE MEMORY AREA
;
MALAME:
CALL CGBSPR ;CHECK & GET BASE
JNZ MALAMR ;NO SPACE
MALAML: ;CHECK LOOP
ADD SI,4
INC CL
CMP CL,SIZREG
JNC MALAMR ;ALL OVER
CALL CKABAR ;CHECK REQUESTED AREA WITH TABLE
JNZ MALAML ;NOT MATCH TO NEXT
CALL SRTAAL ;SETUP REGION TABLE
CALL SVMCBD ;SAVE IN USED MCB BUFFER
MALAMS:
MOV AL,SIZREG
MOV 4[BX],AL ;SET REGION NUMBER
XOR AL,AL
JMPS MALAMN ;OK END
;
MALAMR: ;ERROR END
MOV AL,0FFH
MALAMN: