-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisk.asm
2906 lines (2408 loc) · 86.6 KB
/
Disk.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
;----------------------------------------------------------------------------
;---------------------- Program Starting ... --------------------------------
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;Defination Starting...
;----------------------------------------------------------------------------
A_BUF = 0400H
UP = 0
escape = 011bh
enter = 1c0dh
c_pgup = 8400h
c_pgdw = 7600h
home = 4700h
ende = 4f00h
pageup = 4900h
pagedw = 5100h
cleft = 4b00h
cup = 4800h
cright = 4d00h
cdown = 5000h
digit0 = 48
digit9 = 57
hex_au = 65
hex_fu = 70
hex_ad = 97
hex_fd = 102
lfrg = 0c4h
updw = 0b3h
uplf = 0dah
uprg = 0bfh
dwlf = 0c0h
dwrg = 0d9h
d_wild = 74
d_row = 03
d_col = 02
d_hex = d_col+10
d_text = d_col+59
d_para = d_col+04
d_drive = d_para+02
d_cyls = d_para+09
d_head = d_para+18
d_sect = d_para+28
d_ldrive = d_para+39
d_lclust = d_para+46
d_lsect = d_para+56
d_up = d_para+64
w_msub = 10
c_mbar = 7
tbar_c = 07h
pbar_c = 70h
tmnu_c = 70h
pmnu_c = 07h
thed_c = 26h
phed_c = 2eh
bord_c = 2ah
text_c = 3eh
stat1_c = 3ch
stat2_c = 39h
stat3_c = 3ah
stat4_c = 3bh
ldisk_w = 18
;Defination End...
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;Macro Starting...
;----------------------------------------------------------------------------
Add_Row macro ;Use SI=>Get Row
mov ax,si
mov [row],al
add [row],d_row+1
call SCursor
endm
Add_Col macro ;Use DI=>Get Col
mov ax,di
mov dl,3
mul dl
add al,d_hex ;Disp2hex=>Col
mov [col],al
call SCursor
endm
;Macro End...
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;CODE Segment Starting...
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Code segment para public
org 100h
assume cs:Code,ds:Data,es:Data,ss:Code
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Main Proc Far
;----------------------------------------------------------------------------
START:
mov ax,Data ;MOV AX,OFFSET CLAST
;INC AX
;MOV BX,AX
;MOV CL,4
;SHR AX,CL
;MOV DX,AX
;SHL DX,CL
;CMP DX,BX
;JZ NEXT
;INC AX
;NEXT:
;MOV BX,CS
;ADD AX,BX
mov ds,ax
mov es,ax
call Disk
call Display
call Cls
;----------------------------------------------------------------------------
Main Endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Exit proc near
;----------------------------------------------------------------------------
mov ah,4ch
int 21h
Exit endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Error proc near
;----------------------------------------------------------------------------
call NewLine
mov dx,offset version
call DispText
call NewLine
call NewLine
mov dx,offset error_m
call DispText
call NewLine
call Exit
Error endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Invalid proc near
;----------------------------------------------------------------------------
mov al,[y]
push ax
mov [x1],8
mov [y1],20
mov [x],5
mov [y],41
call MSave
call MBox
mov [row],9
mov [col],35
call SCursor
mov dx,offset err_m1
call DispText
mov [row],11
mov [col],22
call SCursor
mov dx,offset err_m2
call DispText
mov [col],28
call SCursor
mov bl,[ldrive]
add bl,hex_au
call DispChar
mov [row],13
mov [col],28
call SCursor
mov dx,offset err_m3
call DispText
call GetKey
call Mstore
pop ax
mov [y],al
ret
Invalid endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
WBox proc near
;----------------------------------------------------------------------------
mov bh,stat1_c
mov cx,1800h
mov dx,1802h
call Box
mov bh,stat2_c
mov cx,1803h
mov dx,1810h
call Box
mov bh,stat3_c
mov cx,1810h
mov dx,1840h
call Box
mov bh,stat4_c
mov cx,1840h
mov dx,184fh
call Box
mov [row],18h
call SCursor
mov dx,offset status
call DispText ;Display Version
mov bh,tbar_c
call Dsp_Bar
mov bh,11h
mov cx,0100h
mov dx,174fh
call Box ;Clear Text Screen
mov ah,[color]
mov al,[y]
push ax
mov [x1],d_row
mov [y1],d_col-1
mov [x],16
mov [y],d_wild+1
mov [color],bord_c
call MBox ;Text Box Border
pop ax
mov [color],ah
mov [y],al
mov bh,text_c
mov ch,d_row+1
mov cl,d_col
mov dh,d_row+16
mov dl,d_col+d_wild
call Box ;Text Box
mov bh,thed_c
mov ch,d_row
mov cl,d_para+1
mov dh,ch
mov dl,d_up+1
call Box ;Parameter Box
mov [row],d_row
mov [col],d_para
call SCursor
mov dx,offset titles
call DispText ;Display Disk Parameter
mov bh,phed_c
mov ch,d_row
mov cl,d_cyls
mov dh,ch
mov dl,d_cyls+3
call Box ;Cylinder
mov bh,phed_c
mov ch,d_row
mov cl,d_head
mov dh,ch
mov dl,d_head+1
call Box ;Head
mov bh,phed_c
mov ch,d_row
mov cl,d_sect
mov dh,ch
mov dl,d_sect+1
call Box ;Sector
mov bh,phed_c
mov ch,d_row
mov cl,d_ldrive
mov dh,ch
mov dl,d_ldrive
call Box ;Logical Drive
mov bh,phed_c
mov ch,d_row
mov cl,d_lclust
mov dh,ch
mov dl,d_lclust+3
call Box ;Logical Clust
mov bh,phed_c
mov ch,d_row
mov cl,d_lsect
mov dh,ch
mov dl,d_lsect+1
call Box ;Logical Sector
mov bh,phed_c
mov ch,d_row
mov cl,d_up
mov dh,ch
mov dl,d_up
call Box ;page UP/DOWN
ret
WBox endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Dsp_Bar proc near
;----------------------------------------------------------------------------
mov cx,0000h
mov dx,004fh
call Box ;Menu Bar Box
mov [row],0
mov [col],0
call SCursor
mov dx,offset menubar
call DispText ;Display Menubar
ret
Dsp_Bar endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Disk proc near
;----------------------------------------------------------------------------
mov [drive],80h
call XDisk
or ax,ax
jz disk1
call Error
disk1:
call Cls
call ECursor
call WBox
call DispPage
mov [ldrive],2
mov [dlast],0
mov bp,sp
sub bp,6
disk2:
mov di,[buffer]
disk3:
push di
push [cyls]
mov ah,[head]
mov al,[sect]
push ax
call Read
jc disk5
mov al,[di+01c2h]
cmp al,06h ;No Branch
jnz disk4
mov ch,[di+01c1h]
mov dh,[di+01bfh]
mov cl,[di+01c0h]
call PPPP
mov [ncyls],ax
mov [nhead],dh
mov [nsect],cl
call LDisk
cmp ax,0
jnz disk5
call PushDisk
inc [ldrive]
inc [dlast]
pop ax
mov [head],ah
mov [sect],al
pop [cyls]
pop di
add di,10h
jmp disk3
disk4:
cmp al,05h ;Have Branch
jnz disk5 ;AL==0:End
mov ch,[di+01c1h]
mov dh,[di+01bfh]
mov cl,[di+01c0h]
call PPPP
mov [cyls],ax
mov [head],dh
mov [sect],cl
jmp disk2
disk5:
mov di,sp
mov di,ss:[di+4]
sub di,[buffer]
cmp di,40h
jb disk6
cmp bp,sp
jz diskx
add sp,6
disk6:
pop ax
mov [head],ah
mov [sect],al
pop [cyls]
pop di
add di,10h
jmp disk3
diskx:
add sp,6
mov [ldrive],2
call PopDisk
ret
Disk endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
XDisk proc near ;AX ?= 0
;----------------------------------------------------------------------------
mov ah,8
mov dl,[drive]
int 13h
jnc xdisk1
xdiskx:
mov ax,0ffffh
ret
xdisk1:
mov ax,Data ;MOV AX,DS
mov es,ax
add ch,[Extra_Cylinder]
call PPPP
mov [xcyls],ax
mov [xhead],dh
mov [xsect],cl
mov [cyls],0
mov [head],0
mov [sect],1
call Read
jc xdiskx
xor ax,ax
ret
XDisk endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
PPPP proc near ;CH,CL=>AX,CL
;----------------------------------------------------------------------------
mov al,cl
shl cl,1
shl cl,1
shr cl,1
shr cl,1
push cx
mov cl,6
shr al,cl
mov ah,al
mov al,ch
pop cx
ret
PPPP endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
LDisk proc near ;AX ?= 0
;----------------------------------------------------------------------------
mov [ls_h],0
mov [ls_l],0
call LRead
jc ldiskx
mov si,[buffer]
jmp ldisk0
ldiskx:
call Invalid
mov ax,0ffffh
ret
ldisk0:
mov ax,[si+1feh]
cmp ax,0aa55h
jnz ldiskx
mov ax,[si+0bh] ;0BH:Bytes/Sector
cmp ax,0
jz ldiskx
mov cl,[si+0dh] ;0DH:sectors/clust
cmp cl,0
jz ldiskx
dec cl
mov [xlsect],cl
inc cl
mov al,[drive]
cmp al,80h
jnz ldisk1
mov dx,[si+22h] ;20H:Max LSector
mov ax,[si+20h] ;IF DL==80
jmp ldisk2
ldisk1:
xor dx,dx ;13H:Max Sector
mov ax,[si+13h] ;IF DL==00/01
ldisk2:
mov [xls_h],dx
mov [xls_l],ax
call Divide
cmp ax,0
jz ldiskx
mov [xlclust],ax
mov cl,[si+10h] ;10H:fats
cmp cl,0
jz ldiskx
xor ch,ch
dec cx
mov ax,[si+16h] ;16H:sectors/fat
cmp ax,0
jz ldiskx
mov bx,ax
inc ax
mov [fat],ax
ldisk3:
add ax,bx
loop ldisk3
mov [root],ax
mov bx,[si+11h] ;11H:root items
cmp bx,0
jz ldiskx
mov cl,4
shr bx,cl
add ax,bx
mov [d1st],ax
xor ax,ax
ret
LDisk endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
DiskP proc near
;----------------------------------------------------------------------------
mov al,[sectors] ;AL=Sectors.
mov bx,[buffer] ;BX=Buffer,
;ES=Segment.
mov dx,[cyls]
mov cl,6
shl dh,cl
mov cl,[sect] ;CL=Sector,
add cl,dh
mov dh,[head] ;DH=Head,
mov ch,dl ;CH=Cylinder,
mov dl,[drive] ;DL=Drive.
int 13h
ret
DiskP endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Read proc near
;----------------------------------------------------------------------------
mov ah,02 ;AH=Function.
call DiskP
jc readx
call ResetUp
readx:
ret
Read endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Write proc near
;----------------------------------------------------------------------------
mov ah,03 ;AH=Function.
call DiskP
ret
Write endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
LRead proc near
;----------------------------------------------------------------------------
call LtoP
call Read
ret
LRead endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
PushDisk proc near
;----------------------------------------------------------------------------
mov si,offset dlast
push [xcyls]
pop [si+1]
mov al,[xhead]
mov [si+3],al
mov al,[xsect]
mov [si+4],al
add si,4
mov al,[ldrive]
dec al
dec al
mov cl,ldisk_w
mul cl
add si,ax
mov al,[ldrive]
mov [si+1],al
push [ncyls]
pop [si+2]
mov al,[nhead]
mov [si+4],al
mov al,[nsect]
mov [si+5],al
push [xls_h]
pop [si+6]
push [xls_l]
pop [si+8]
push [xlclust]
pop [si+10]
mov al,[xlsect]
mov [si+12],al
push [fat]
pop [si+13]
push [root]
pop [si+15]
push [d1st]
pop [si+17]
ret
PushDisk endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
PopDisk proc near
;----------------------------------------------------------------------------
mov si,offset dlast
push [si+1]
pop [xcyls]
mov al,[si+3]
mov [xhead],al
mov al,[si+4]
mov [xsect],al
add si,4
mov al,[ldrive]
dec al
dec al
mov cl,ldisk_w
mul cl
add si,ax
mov al,[si+1]
mov [ldrive],al
push [si+2]
pop [ncyls]
mov al,[si+4]
mov [nhead],al
mov al,[si+5]
mov [nsect],al
push [si+6]
pop [xls_h]
push [si+8]
pop [xls_l]
push [si+10]
pop [xlclust]
mov al,[si+12]
mov [xlsect],al
push [si+13]
pop [fat]
push [si+15]
pop [root]
push [si+17]
pop [d1st]
mov [ls_h],0
mov [ls_l],0
call StoC
call LRead
ret
PopDisk endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
PtoL proc near
;----------------------------------------------------------------------------
mov ax,[cyls]
sub ax,[ncyls]
jc ptolx
mov cl,[xhead]
inc cl
xor dx,dx
call Multiply
mov cl,[head]
add ax,cx
jnc ptol1
inc dx
ptol1:
mov cl,[nhead]
sub ax,cx
jnc ptol2
sub dx,1
jc ptolx
ptol2:
mov cl,[xsect]
call Multiply
mov cl,[sect]
add ax,cx
jnc ptol3
inc dx
ptol3:
mov cl,[nsect]
sub ax,cx
jnc ptol4
sub dx,1
jc ptolx
ptol4:
cmp dx,[xls_h]
ja ptolx
jnz ptol5
cmp ax,[xls_l]
ja ptolx
ptol5:
mov [ls_h],dx
mov [ls_l],ax
call StoC
ptolx:
ret
PtoL endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
LtoP proc near
;----------------------------------------------------------------------------
mov dx,[ls_h]
mov ax,[ls_l]
xor ch,ch
mov cl,[nsect]
dec cl
add ax,cx
jnc ltop1
inc dx
ltop1:
mov cl,[xsect]
call Divide
inc cl
mov [sect],cl
mov cl,[nhead]
add ax,cx
jnc ltop2
inc dx
ltop2:
mov cl,[xhead]
inc cl
call Divide
mov [head],cl
mov cx,[ncyls]
add ax,cx
mov [cyls],ax
ret
LtoP endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Divide proc near ;DX_AX/CL(<>0)=>DX_AX,CL
;----------------------------------------------------------------------------
push ax
xor ah,ah
mov al,dh
div cl
mov dh,al ;=>DH
mov al,dl
div cl
mov dl,al ;=>DL
pop bx
mov al,bh
div cl
mov bh,al ;=>AH
mov al,bl
div cl
mov bl,al ;=>AL
mov cl,ah ;=>CL
mov ax,bx ;=>AX
ret
Divide endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Multiply proc near ;DX_AX*CL=>DX_AX
;----------------------------------------------------------------------------
push ax
xor ch,ch
mov ax,dx
mul cx
mov bx,ax
pop ax
mul cx
add dx,bx
ret
Multiply endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
iCyls proc near
;----------------------------------------------------------------------------
mov cx,[xcyls]
cmp [cyls],cx
jz icylsx
inc [cyls]
call PtoL
icylsx:
ret
iCyls endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
dCyls proc near
;----------------------------------------------------------------------------
cmp [cyls],0
jz dcylsx
dec [cyls]
call PtoL
dcylsx:
ret
dCyls endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
iHead proc near
;----------------------------------------------------------------------------
mov cl,[xhead]
cmp [head],cl
jz ihead1
inc [head]
call PtoL
jmp iheadx
ihead1:
mov [head],0
call iCyls
iheadx:
ret
iHead endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
dHead proc near
;----------------------------------------------------------------------------
cmp [head],0
jz dhead1
dec [head]
call PtoL
jmp dheadx
dhead1:
mov al,[xhead]
mov [head],al
call dCyls
dheadx:
ret
dHead endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
iSect proc near
;----------------------------------------------------------------------------
mov cl,[xsect]
cmp [sect],cl
jz isect1
inc [sect]
call PtoL
jmp isectx
isect1:
mov [sect],1
call iHead
isectx:
ret
iSect endp
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
dSect proc near
;----------------------------------------------------------------------------
cmp [sect],1
jz dsect1
dec [sect]
call PtoL
jmp dsectx
dsect1:
mov al,[xsect]
mov [sect],al
call dHead
dsectx:
ret
dSect endp
;----------------------------------------------------------------------------