summaryrefslogtreecommitdiff
path: root/v2.0/source/RECOVER.ASM
blob: 05d27f91fa10dd5ea39cbe68dbeb8740120a06f2 (plain) (blame)
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
TITLE   RECOVER MS-DOS File/Disk Recovery Utility
;----------------------------------------------------------
;
;       Recover - Program to rebuild an ms.dos directory
;
;       Copyright 1982 by Microsoft Corporation
;       Written by Chris Peters, April 1982
;
;-----------------------------------------------------------
;
;REV 1.5 added header message ARR
;

FALSE   EQU     0
TRUE    EQU     NOT FALSE


IBMVER  EQU     true
KANJI   EQU     FALSE

bdos    equ     21h
boot    equ     20h
aread   equ     25h
awrite  equ     26h

        INCLUDE DOSSYM.ASM

;
cr      equ     0dh
lf      equ     0ah
;
fcb     equ     5ch

code    segment public
code    ends

const   segment public byte
const   ends

data    segment public byte
data    ends


dg      group   code,const,data

code    segment public
        assume  cs:dg,ds:dg,es:dg,ss:dg

        PUBLIC  PCRLF,PRINT,INT_23,convert
        EXTRN   dskwrt:NEAR,dskrd:NEAR,DSKERR:NEAR,report:NEAR

        org     100h

recover:jmp     rec_start

HEADER  DB      "Vers 1.50"

;-----------------------------------------------------------------------;
hardch  dd      ?

the_root db     0                       ;root directory flag

fudge   db      0                       ;directory changed flag
user_drive      db      0
drive   db      0


dirchar db      "/",0


userdir db      "/",0
        db      (dirstrlen) dup(0)

fname_buffer db 128 dup(0)
;-----------------------------------------------------------------------;

pcrlf:  mov     dx,offset dg: crlf
print:  mov     ah,STD_CON_STRING_OUTPUT
        int     bdos
pret:   ret
;
convert:push    bx
        xor     ax,ax
        mov     bx,ax
        mov     bp,ax
        mov     cx,32
convlp: shl     si,1
        rcl     di,1
        xchg    ax,bp
        call    convwrd
        xchg    ax,bp
        xchg    ax,bx
        call    convwrd
        xchg    ax,bx
        adc     al,0
        loop    convlp

        mov     cx,1810h
        xchg    dx,ax
        call    digit
        xchg    ax,bx
        call    outword
        mov     ax,bp
        call    outword
        pop     dx
        call    print
ret2:   ret
;
outword:push    ax
        mov     dl,ah
        call    outbyte
        pop     dx
outbyte:mov     dh,dl
        shr     dl,1
        shr     dl,1
        shr     dl,1
        shr     dl,1
        call    digit
        mov     dl,dh
digit:  and     dl,0fh
        jz      blankzer
        xor     cl,cl
blankzer:
        dec     ch
        and     cl,ch
        or      dl,30h
        sub     dl,cl
        cmp     dl,30h
        jl      ret2
        mov     ah,STD_CON_OUTPUT
        int     bdos
        ret
;
convwrd:adc     al,al
        daa
        xchg    al,ah
        adc     al,al
        daa
        xchg    al,ah
        ret
;
;       bx = fat[ax]
;
getfat: mov     bx,offset dg: fattbl
        push    ax
        mov     si,ax
        sar     ax,1
        pushf
        add     si,ax
        mov     bx,word ptr [bx][si]
        popf
        jnc     getfat1
        mov     cl,4
        shr     bx,cl
getfat1:and     bh,00001111b
        pop     ax
        mov     cx,secsiz
        ret
;
;       fat[ax] = dx
;
setfat: mov     bx,offset dg: fattbl
        push    ax
        push    dx
        mov     si,ax
        sar     ax,1
        pushf
        add     si,ax
        mov     ax,word ptr [bx][si]
        popf
        jnc     setfat2
        and     ax,000fh
        mov     cl,4
        shl     dx,cl
setfat1:or      ax,dx
        mov     word ptr [bx][si],ax
        pop     dx
        pop     ax
        ret

setfat2:and     ax,0f000h
        jmp     setfat1

load:   mov     dx,firfat
        mov     al,byte ptr fatnum
        mov     byte ptr fatcnt,al
        mov     al,byte ptr drive
        mov     cx,fatsiz
        mov     bx,offset dg: fattbl
ret66:  ret

readft: call    load
readit: call    dskrd
        cmp     [fndfat],0      ;save location of readable fat sector
        jnz     fdfat
        mov     [fndfat],dx
fdfat:  cmp     word ptr [bx+1],-1
        jz      ret66

        add     dx,cx           ;try to read the other fats
        dec     byte ptr fatcnt
        jnz     readit

        mov     dx,[fndfat]     ;see if any readable at all
        or      dx,dx
        jz      readft          ;if not disk is blown, keep trying
        call    dskrd
        ret

wrtfat: call    load
wrtit:  push    ax
        push    bx
        push    cx
        push    dx
        call    dskwrt
        pop     dx
        pop     cx
        pop     bx
        pop     ax

wrtok:  add     dx,cx
        dec     byte ptr fatcnt
        jnz     wrtit
        ret

printerr:
        call    print
        jmp     rabort


rec_start:

;Code to print header
;       PUSH    AX
;       MOV     DX,OFFSET DG:HEADER
;       CALL    print
;       POP     AX

DOSVER_HIGH     EQU  0200H   ;2.00 in hex
        PUSH    AX              ;Save DRIVE validity info
        MOV     AH,GET_VERSION
        INT     21H
        XCHG    AH,AL           ;Turn it around to AH.AL
        CMP     AX,DOSVER_HIGH
        JAE     OKDOS
GOTBADDOS:
        MOV     DX,OFFSET DG:BADVER
        CALL    PRINT
        INT     20H

OKDOS:  POP     AX

        cmp     al,0ffH
        JZ      BADDRVSPECJ
        mov     si,80h
        lodsb
        or      al,al
        jz      noparm
look:   lodsb
        cmp     al," "
        jz      look
        cmp     al,9
        jz      look
        cmp     al,13
        jnz     gotparm
noparm:
        jmp     noname

BADDRVSPECJ: JMP BADDRVSPEC

gotparm:
        mov     ah,DISK_RESET
        int     bdos                    ;empty buffer queue

        mov     ah,get_default_drive    ;save current drive
        int     21h
        mov     [user_drive],al

        mov     bx,fcb                  ;determine input command
        mov     al,[bx]
        dec     al
        cmp     al,-1
        jnz     drvok1
        mov     al,[user_drive]
drvok1:
        mov     [drive],al
        add     [drvlet],al
        add     [drvlet1],al
        mov     dx,offset dg: askmsg
        call    print
        mov     ah,STD_CON_INPUT_FLUSH
        mov     al,1                    ;wait for a key
        int     bdos

        cmp     al,17h
        jnz     drvok2
        mov     dx,offset dg: egomes
        jmp     printerr
egomes: db      "Chris Peters helped with the new dos!",cr,lf
        db      "Microsoft rules ok$"

drvok2:
        IF      IBMVER
        MOV     AL,DRIVE                ;This is for ibm's single drive sys
        PUSH    DS
        MOV     BX,50H
        MOV     DS,BX
        MOV     DS:(BYTE PTR 4),AL              ;Indicate drive changed
        POP     DS
        ENDIF

;----- Process Pathnames -----------------------------------------------;
        mov     ax,(char_oper shl 8)    ;get switch character
        int     21h
        cmp     dl,"/"
        jnz     slashok                 ;if not / , then not PC
        mov     [dirchar],"\"           ;in PC, dir separator = \
        mov     [userdir],"\"

slashok:
        mov     si,81h                  ;point to cammand line
        mov     di,offset dg: fname_buffer
        xor     cx,cx                   ;zero pathname length

kill_bl:
        lodsb                           ;get rid of blanks
        cmp     al,9
        je      kill_bl
        cmp     al,' '
        je      kill_bl
        cmp     al,13                   ;A carriage return?
        jne     next_char
        jmp     noname                  ;yes, file name missing

next_char:
        stosb                           ;put patname in buffer
        inc     cx
        lodsb
        cmp     al,' '
        je      name_copied
        cmp     al,9
        je      name_copied
        cmp     al,13                   ; a CR ?
        jne     next_char

name_copied:
        mov     byte ptr [di],0         ;nul terminate the pathname
        dec     di                      ;adjust to the end of the pathname

;----- Scan for directory ----------------------------------------------;

        IF      KANJI
        mov     dx,offset dg: [fname_buffer]
        PUSH    DX
        PUSH    DI
        MOV     BX,DI
        MOV     DI,DX
DELLOOP:
        CMP     DI,BX
        JZ      GOTDELE
        MOV     AL,[DI]
        INC     DI
        CALL    TESTKANJ
        JZ      NOTKANJ11
        INC     DI
        JMP     DELLOOP

NOTKANJ11:
        cmp     al,[dirchar]
        JNZ     DELLOOP
        MOV     DX,DI           ;Point to char after '/'
        DEC     DX
        DEC     DX              ;Point to char before '/'
        JMP     DELLOOP

GOTDELE:
        MOV     DI,DX
        POP     AX              ;Initial DI
        POP     DX
        SUB     AX,DI           ;Distance moved
        SUB     CX,AX           ;Set correct CX
        CMP     DX,DI
        JB      sja             ;Found a pathsep
        JA      sjb             ;Started with a pathsep, root
        MOV     AX,[DI]
        CALL    TESTKANJ
        JNZ     same_dirj
        XCHG    AH,AL
        cmp     al,[dirchar]
        jz      sja             ;One character directory
same_dirj:
        ELSE
        mov     al,[dirchar]            ;get directory separator character
        std                             ;scan backwards
        repnz   scasb                   ;(cx has the pathname length)
        cld                             ;reset direction, just in case
        jz      sja
        ENDIF

        jmp     same_dir                ;no dir separator char. found, the
                                        ; file is in the current directory
                                        ; of the corresponding drive. Ergo,
                                        ; the FCB contains the data already.

sja:
        jcxz    sjb                     ;no more chars left, it refers to root
        cmp     byte ptr [di],':'       ;is the prvious character a disk def?
        jne     not_root
sjb:
        mov     [the_root],01h          ;file is in the root
not_root:
        inc     di                      ;point to dir separator char.
        mov     al,0
        stosb                           ;nul terminate directory name
        pop     ax
        push    di                      ;save pointer to file name
        mov     [fudge],01h             ;remember that the current directory
                                        ; has been changed.

;----- Save current directory for exit ---------------------------------;
        mov     dl,byte ptr ds:[fcb]    ;get specified drive if any
        or      dl,dl                   ;default disk?
        jz      same_drive
        dec     dl                      ;adjust to real drive (a=0,b=1,...)
        mov     ah,set_default_drive    ;change disks
        int     21h
        cmp     al,-1                   ;error?
        jne     same_drive
BADDRVSPEC:
        mov     dx,offset dg: baddrv
        jmp     printerr

same_drive:
        mov     ah,get_default_dpb
        int     21h

assume  ds:nothing

        cmp     al,-1                   ;bad drive? (should always be ok)
        jne     drvisok
        mov     dx,offset dg: baddrv
        jmp     printerr

drvisok:
        cmp     [bx.dpb_current_dir],0
        je      curr_is_root
        mov     si,bx
        add     si,dpb_dir_text
        mov     di,offset dg: userdir + 1

dir_save_loop:
        lodsb
        stosb
        or      al,al
        jnz     dir_save_loop

curr_is_root:
        push    cs
        pop     ds

assume  ds:dg


;----- Change directories ----------------------------------------------;
        cmp     [the_root],01h
        mov     dx,offset dg: [dirchar]            ;assume the root
        je      sj1
        mov     dx,offset dg: [fname_buffer]
sj1:
        mov     ah,chdir                        ;change directory
        int     21h
        mov     dx,offset dg: baddrv
        jnc     no_errors
        jmp     printerr
no_errors:

;----- Set Up int 24 intercept -----------------------------------------;

        mov     ax,(get_interrupt_vector shl 8) or 24h
        int     21h
        mov     word ptr [hardch],bx
        mov     word ptr [hardch+2],es
        mov     ax,(set_interrupt_vector shl 8) or 23h
        mov     dx,offset dg: int_23
        int     21h
        mov     ax,(set_interrupt_vector shl 8) or 24h
        mov     dx,offset dg: int_24
        int     21h
        push    cs
        pop     es

;----- Parse filename to FCB -------------------------------------------;
        pop     si
        mov     di,fcb
        mov     ax,(parse_file_descriptor shl 8) or 1
        int     21h
        push    ax
;-----------------------------------------------------------------------;
same_dir:
        pop     ax

        mov     bx,fcb
        cmp     byte ptr [bx+1],' '     ;must specify file name
        jnz     drvok
        cmp     byte ptr [bx],0         ;or drive specifier
        jnz     drvok
noname: mov     dx,offset dg: drverr
        call    print
        jmp     int_23

drvok:  push    ds
        mov     dl,drive
        inc     dl
        mov     ah,GET_DPB
        int     bdos
        mov     ax,word ptr [bx+2]      ;get physical sector size
        mov     cl,byte ptr [bx+4]      ;get sectors/cluster - 1
        xor     ch,ch
        inc     cx
        mov     cs:secall,cx            ;save sectors per cluster
        mul     cx                      ;ax = bytes per cluster
        mov     bp,word ptr [bx+11]     ;get record of first sector
        mov     dx,word ptr [bx+16]     ;get record of first directory entry
        mov     si,word ptr [bx+6]      ;get record of first fat
        mov     cl,byte ptr [bx+15]     ;get size of fat
        mov     di,word ptr [bx+13]     ;get number of clusters
        mov     ch,byte ptr [bx+8]      ;get number of fats on drive
        mov     bx,word ptr [bx+9]      ;get max number of dir entries
        pop     ds

        mov     maxent,bx
        mov     firfat,si
        mov     firrec,bp
        mov     firdir,dx
        mov     byte ptr fatsiz,cl
        mov     lastfat,di              ;number of fat entries
        mov     byte ptr fatnum,ch      ;save number of fats on disk

        mov     secsiz,ax

        mov     di,table                ;di points into constructed directory
        mov     ax,0e5e5h               ;deleted file magic number
        shl     bx,1                    ;16 words in a dir entry
        shl     bx,1
        shl     bx,1
        shl     bx,1
        mov     cx,bx
        rep     stosw

        call    readft
        mov     bx,fcb
        cmp     byte ptr [bx+1],' '
        jz      recdsk
        jmp     recfil

recdsk: mov     di,table
        mov     fatptr,2
        mov     ax,fatptr
step1:  call    getfat
        cmp     bx,0fffh
        jz      step1a
        jmp     step6
step1a: mov     filsiz,0
        mov     word ptr filsiz+2,0
        mov     dx,lastfat
        mov     target,ax
step2:  mov     ax,2
        add     filsiz,cx
        adc     word ptr filsiz+2,0
step3:  call    getfat
        cmp     bx,target
        jne     step4
        mov     target,ax
        jmp     step2
step4:  inc     ax
        cmp     ax,dx
        jle     step3
;
;       at this point target = head of list, filsiz = file size
;
        inc     filcnt                  ;increment file count
        mov     ax,maxent
        cmp     filcnt,ax               ;compare with max number of entries
        ja      direrr

        mov     si,(offset dg: dirent)+7
nam0:   inc     byte ptr [si]           ;increment file name
        cmp     byte ptr [si],'9'
        jle     nam1
        mov     byte ptr [si],'0'
        dec     si
        jmp     nam0

nam1:   mov     ah,GET_DATE
        int     bdos                    ;set the date
        sub     cx,1980
        add     dh,dh
        add     dh,dh
        add     dh,dh
        add     dh,dh
        add     dh,dh
        rcl     cl,1
        or      dh,dl
        mov     byte ptr dirent+24,dh
        mov     byte ptr dirent+25,cl
        mov     ah,GET_TIME
        int     bdos                    ;set the time
        shr     dh,1
        add     cl,cl
        add     cl,cl
        add     cl,cl
        rcl     ch,1
        add     cl,cl
        rcl     ch,1
        add     cl,cl
        rcl     ch,1
        or      dh,cl
        mov     byte ptr dirent+22,dh
        mov     byte ptr dirent+23,ch

        mov     ax,filsiz                       ;set file size
        mov     word ptr dirent+28,ax
        mov     ax,word ptr filsiz+2
        mov     word ptr dirent+30,ax
        mov     ax,target                       ;set first cluster location
        mov     word ptr dirent+26,ax

        mov     si,offset dg: dirent                ;copy in new dir entry
        mov     cx,32
        rep     movsb

step6:  inc     fatptr                          ;keep looking for eof's
        mov     ax,fatptr
        cmp     ax,lastfat
        jg      step7
        jmp     step1

direrr: dec     filcnt
        mov     dx,offset dg: dirmsg
        call    print

step7:
        mov     al,drive
        mov     dx,firdir               ;write out constructed directory
        mov     cx,firrec
        sub     cx,dx
        mov     bx,table
        call    dskwrt
        call    pcrlf
        mov     dx,offset dg: recmsg_pre
        call    print
        mov     bx,offset dg: recmsg_post
        mov     si,filcnt
        xor     di,di                   ;output number of files created
        call    convert
        jmp     rexit
recfil: mov     dx,fcb
        mov     ah,FCB_OPEN
        int     bdos
        inc     al
        jnz     recfil0
        mov     dx,offset dg: opnerr
        call    print
        jmp     rexit

recfil0:mov     lastfat,1               ;indicate location of list head
        mov     di,fcb
        mov     ax,[di+16]              ;get file size
        mov     filsiz,ax
        mov     siztmp,ax
        mov     ax,[di+18]
        mov     filsiz+2,ax
        mov     siztmp+2,ax
        mov     ax,[di+25]              ;get list head
        or      ax,ax
        mov     fatptr,ax
        jnz     recfil1
recvec: jmp     recfil6

recfil1:cmp     fatptr,0fffh
        jz      recvec                  ;terminate loop at e-o-f

        mov     cx,secall
        mov     ax,fatptr
        dec     ax
        dec     ax
        mul     cx
        add     ax,firrec
        mov     dx,ax
        mov     bx,table
        mov     al,drive
        int     aread
        pop     di                      ;restore stack pointer
        mov     di,fcb                  ;restore pointer to fcb
        jnc     recfil4                 ;if no error continue reading

        mov     ax,fatptr
        call    getfat
        cmp     lastfat,1
        jnz     recfil2

        cmp     bx,0fffh
        jnz     noteof
        xor     bx,bx
noteof: mov     word ptr [di+25],bx
        jmp     recfil3

recfil2:mov     dx,bx                   ;jump around bad sector
        mov     ax,lastfat
        call    setfat

recfil3:mov     ax,fatptr               ;mark sector bad
        mov     dx,0ff7h
        call    setfat
        mov     ax,secsiz               ;prepare to dec filsiz by secsiz
        cmp     siztmp+2,0
        jnz     recfilx
        cmp     siztmp,ax
        ja      recfilx
        mov     ax,siztmp

recfilx:sub     word ptr [di+16],ax
        sbb     word ptr [di+18],0
        sub     siztmp,ax
        sbb     siztmp,0

        and     byte ptr [di+24],10111111b      ;mark file dirty

        mov     ax,lastfat                      ;point to next sector to check
        jmp     recfil5

recfil4:
        mov     ax,secsiz               ;set bytes remaining to be read
        sub     siztmp,ax
        sbb     siztmp+2,0
        jnc     recok
        xor     ax,ax                   ;if < 0, then set to zero
        mov     siztmp,ax
        mov     siztmp+2,ax

recok:  mov     ax,fatptr               ;get next sector to test
        mov     lastfat,ax
recfil5:call    getfat
        mov     fatptr,bx
        jmp     recfil1

recfil6:                                ;all done
        mov     dx,fcb
        mov     ah,FCB_CLOSE
        int     bdos            ;close the file
        call    pcrlf
        call    report

;
rexit:  mov     ah,DISK_RESET
        int     bdos
        call    wrtfat          ;save the fat
int_23: call    rest_dir
rabort: int     boot            ;home, james...

;----- Restore INT 24 vector and old current directory -----------------;
rest_dir:
        cmp     [fudge],0
        je      no_fudge

        mov     ax,(set_interrupt_vector shl 8) or 24h
        lds     dx,[hardch]
        int     21h
        push    cs
        pop     ds

        mov     dx,offset dg: userdir               ;restore directory
        mov     ah,chdir
        int     21h
        mov     dl,[user_drive]                 ;restore old current drive
        mov     ah,set_default_drive
        int     21h

no_fudge:
        ret

;----- INT 24 Processing -----------------------------------------------;

int_24_retaddr dw       int_24_back

int_24  proc    far
assume  ds:nothing,es:nothing,ss:nothing

        pushf
        push    cs
        push    [int_24_retaddr]
        push    word ptr [hardch+2]
        push    word ptr [hardch]
        ret
int_24  endp

int_24_back:
        cmp     al,2            ;abort?
        jnz     ireti
        push    cs
        pop     ds

assume  ds:dg

        call    rest_dir
        int     20h
ireti:
        iret

        IF      KANJI
TESTKANJ:
        CMP     AL,81H
        JB      NOTLEAD
        CMP     AL,9FH
        JBE     ISLEAD
        CMP     AL,0E0H
        JB      NOTLEAD
        CMP     AL,0FCH
        JBE     ISLEAD
NOTLEAD:
        PUSH    AX
        XOR     AX,AX           ;Set zero
        POP     AX
        RET

ISLEAD:
        PUSH    AX
        XOR     AX,AX           ;Set zero
        INC     AX              ;Reset zero
        POP     AX
        RET
        ENDIF

code  ends

const   segment public byte

        EXTRN   BADVER:BYTE,askmsg:BYTE,drvlet:BYTE,dirmsg:BYTE
        EXTRN   recmsg_pre:BYTE,DRVLET1:BYTE,recmsg_post:BYTE
        EXTRN   crlf:BYTE,drverr:BYTE,baddrv:BYTE,opnerr:BYTE

const   ends

data    segment byte

        PUBLIC  filsiz

dirent  db      'FILE0000REC'
        db      21 dup (00)

fndfat  dw      0000                    ;sector of first good fat
filcnt  dw      0000
fatcnt  db      00
fatnum  db      00
fatsiz  dw      0000
firfat  dw      0000
fatptr  dw      0000
secall  dw      0000                    ;sectors per cluster
target  dw      0000
maxent  dw      0000
firrec  dw      0000
firdir  dw      0000
secsiz  dw      0000
siztmp  dw      0000
        dw      0000
filsiz  dw      0000
        dw      0000
lastfat dw      0000
;
table   dw      offset dg:fattbl + 6 * 1024
fattbl  db      0

data    ends

        end     recover