学习啦 > 学习电脑 > 操作系统 > 操作系统基础知识 > DOS操作系统源码相关资料知识

DOS操作系统源码相关资料知识

时间: 志艺942 分享

DOS操作系统源码相关资料知识

  你还在为不知道DOS操作系统源码相关资料知识而烦恼么?接下来是小编为大家收集的DOS操作系统源码相关资料知识教程,希望能帮到大家。

  DOS操作系统源码相关资料知识

学习啦在线学习网   微软DOS早期源码,现已公开;下了一份,看下其大致结构;

  包括1.1和2.0版本的源码和编译后的结果;

  贴出其1.1版本 MSDOS.ASM 源码;有空研究;

[plain] view plain copy ; 86-DOS High-performance operating system for the 8086 version 1.25

  ; by Tim Paterson

  ; ****************** Revision History *************************

  ; >> EVERY change must noted below!! <<

  ;

  ; 0.34 12/29/80 General release, updating all past customers

  ; 0.42 02/25/81 32-byte directory entries added

学习啦在线学习网   ; 0.56 03/23/81 Variable record and sector sizes

  ; 0.60 03/27/81 Ctrl-C exit changes, including register save on user stack

  ; 0.74 04/15/81 Recognize I/O devices with file names

  ; 0.75 04/17/81 Improve and correct buffer handling

  ; 0.76 04/23/81 Correct directory size when not 2^N entries

  ; 0.80 04/27/81 Add console input without echo, Functions 7 & 8

  ; 1.00 04/28/81 Renumber for general release

  ; 1.01 05/12/81 Fix bug in `STORE'

  ; 1.10 07/21/81 Fatal error trapping, NUL device, hidden files, date & time,

  ; RENAME fix, general cleanup

学习啦在线学习网   ; 1.11 09/03/81 Don't set CURRENT BLOCK to 0 on open; fix SET FILE SIZE

  ; 1.12 10/09/81 Zero high half of CURRENT BLOCK after all (CP/M programs don't)

  ; 1.13 10/29/81 Fix classic "no write-through" error in buffer handling

  ; 1.20 12/31/81 Add time to FCB; separate FAT from DPT; Kill SMALLDIR;

学习啦在线学习网   ; Add FLUSH and MAPDEV calls; allow disk mapping in DSKCHG;

  ; Lots of smaller improvements

  ; 1.21 01/06/82 HIGHMEM switch to run DOS in high memory

学习啦在线学习网   ; 1.22 01/12/82 Add VERIFY system call to enable/disable verify after write

学习啦在线学习网   ; 1.23 02/11/82 Add defaulting to parser; use variable escape character

学习啦在线学习网   ; Don't zero extent field in IBM version (back to 1.01!)

  ; 1.24 03/01/82 Restore fcn. 27 to 1.0 level; add fcn. 28

学习啦在线学习网   ; 1.25 03/03/82 Put marker (00) at end of directory to speed searches

  ;

  ; *************************************************************

学习啦在线学习网   ; Interrupt Entry Points:

  ; INTBASE: ABORT

  ; INTBASE+4: COMMAND

  ; INTBASE+8: BASE EXIT ADDRESS

  ; INTBASE+C: CONTROL-C ABORT

  ; INTBASE+10H: FATAL ERROR ABORT

学习啦在线学习网   ; INTBASE+14H: BIOS DISK READ

  ; INTBASE+18H: BIOS DISK WRITE

  ; INTBASE+40H: Long jump to CALL entry point

  IF IBM

学习啦在线学习网   ESCCH EQU 0

学习啦在线学习网   CANCEL EQU 1BH ;Cancel with ESC

学习啦在线学习网   TOGLINS EQU TRUE ;One key toggles insert mode

  TOGLPRN EQU TRUE ;One key toggles printer echo

学习啦在线学习网   NUMDEV EQU 6 ;Include "COM1" as I/O device name

  ZEROEXT EQU TRUE

  ELSE

  ESCCH EQU 1BH

  CANCEL EQU "X"-"@" ;Cancel with Ctrl-X

  TOGLINS EQU FALSE ;Separate keys for insert mode on and off

  TOGLPRN EQU FALSE ;Separate keys for printer echo on and off

  NUMDEV EQU 5 ;Number of I/O device names

学习啦在线学习网   ZEROEXT EQU FALSE

  ENDIF

  MAXCALL EQU 36

  MAXCOM EQU 46

  INTBASE EQU 80H

学习啦在线学习网   INTTAB EQU 20H

学习啦在线学习网   ENTRYPOINTSEG EQU 0CH

学习啦在线学习网   ENTRYPOINT EQU INTBASE+40H

学习啦在线学习网   CONTC EQU INTTAB+3

学习啦在线学习网   EXIT EQU INTBASE+8

  LONGJUMP EQU 0EAH

  LONGCALL EQU 9AH

  MAXDIF EQU 0FFFH

  SAVEXIT EQU 10

  ; Field definition for FCBs

学习啦在线学习网   FCBLOCK STRUC

  DB 12 DUP (?) ;Drive code and name

  EXTENT DW ?

学习啦在线学习网   RECSIZ DW ? ;Size of record (user settable)

  FILSIZ DW ? ;Size of file in bytes

  DRVBP DW ? ;BP for SEARCH FIRST and SEARCH NEXT

  FDATE DW ? ;Date of last writing

  FTIME DW ? ;Time of last writing

学习啦在线学习网   DEVID DB ? ;Device ID number, bits 0-5

  ;bit 7=0 for file, bit 7=1 for I/O device

  ;If file, bit 6=0 if dirty

学习啦在线学习网   ;If I/O device, bit 6=0 if EOF (input)

  FIRCLUS DW ? ;First cluster of file

  LSTCLUS DW ? ;Last cluster accessed

学习啦在线学习网   CLUSPOS DW ? ;Position of last cluster accessed

  DB ? ;Forces NR to offset 32

  NR DB ? ;Next record

  RR DB 3 DUP (?) ;Random record

  FCBLOCK ENDS

学习啦在线学习网   FILDIRENT = FILSIZ ;Used only by SEARCH FIRST and SEARCH NEXT

学习啦在线学习网   ; Description of 32-byte directory entry (same as returned by SEARCH FIRST

  ; and SEARCH NEXT, functions 17 and 18).

  ;

  ; Location bytes Description

  ;

  ; 0 11 File name and extension ( 0E5H if empty)

  ; 11 1 Attributes. Bits 1 or 2 make file hidden

  ; 12 10 Zero field (for expansion)

  ; 22 2 Time. Bits 0-4=seconds/2, bits 5-10=minute, 11-15=hour

  ; 24 2 Date. Bits 0-4=day, bits 5-8=month, bits 9-15=year-1980

学习啦在线学习网   ; 26 2 First allocation unit ( < 4080 )

  ; 28 4 File size, in bytes (LSB first, 30 bits max.)

  ;

  ; The File Allocation Table uses a 12-bit entry for each allocation unit on

  ; the disk. These entries are packed, two for every three bytes. The contents

学习啦在线学习网   ; of entry number N is found by 1) multiplying N by 1.5; 2) adding the result

学习啦在线学习网   ; to the base address of the Allocation Table; 3) fetching the 16-bit word at

学习啦在线学习网   ; this address; 4) If N was odd (so that N*1.5 was not an integer), shift the

学习啦在线学习网   ; word right four bits; 5) mask to 12 bits (AND with 0FFF hex). Entry number

学习啦在线学习网   ; zero is used as an end-of-file trap in the OS and as a flag for directory

学习啦在线学习网   ; entry size (if SMALLDIR selected). Entry 1 is reserved for future use. The

  ; first available allocation unit is assigned entry number two, and even

  ; though it is the first, is called cluster 2. Entries greater than 0FF8H are

  ; end of file marks; entries of zero are unallocated. Otherwise, the contents

学习啦在线学习网   ; of a FAT entry is the number of the next cluster in the file.

  ; Field definition for Drive Parameter Block

  DPBLOCK STRUC

  DEVNUM DB ? ;I/O driver number

学习啦在线学习网   DRVNUM DB ? ;Physical Unit number

  SECSIZ DW ? ;Size of physical sector in bytes

  CLUSMSK DB ? ;Sectors/cluster - 1

  CLUSSHFT DB ? ;Log2 of sectors/cluster

  FIRFAT DW ? ;Starting record of FATs

学习啦在线学习网   FATCNT DB ? ;Number of FATs for this drive

学习啦在线学习网   MAXENT DW ? ;Number of directory entries

学习啦在线学习网   FIRREC DW ? ;First sector of first cluster

学习啦在线学习网   MAXCLUS DW ? ;Number of clusters on drive + 1

学习啦在线学习网   FATSIZ DB ? ;Number of records occupied by FAT

学习啦在线学习网   FIRDIR DW ? ;Starting record of directory

学习啦在线学习网   FAT DW ? ;Pointer to start of FAT

学习啦在线学习网   DPBLOCK ENDS

  DPBSIZ EQU 20 ;Size of the structure in bytes

  DIRSEC = FIRREC ;Number of dir. sectors (init temporary)

学习啦在线学习网   DSKSIZ = MAXCLUS ;Size of disk (temp used during init only)

  ;The following are all of the segments used

学习啦在线学习网   ;They are declared in the order that they should be placed in the executable

  CODE SEGMENT

学习啦在线学习网   CODE ENDS

  CONSTANTS SEGMENT BYTE

  CONSTANTS ENDS

  DATA SEGMENT WORD

  DATA ENDS

学习啦在线学习网   DOSGROUP GROUP CODE,CONSTANTS,DATA

  SEGBIOS SEGMENT

  SEGBIOS ENDS

  ; BOIS entry point definitions

  IF IBM

  BIOSSEG EQU 60H

  ENDIF

  IF NOT IBM

  BIOSSEG EQU 40H

  ENDIF

  SEGBIOS SEGMENT AT BIOSSEG

  ORG 0

  DB 3 DUP (?) ;Reserve room for jump to init code

学习啦在线学习网   BIOSSTAT DB 3 DUP (?) ;Console input status check

  BIOSIN DB 3 DUP (?) ;Get console character

  BIOSOUT DB 3 DUP (?) ;Output console character

学习啦在线学习网   BIOSPRINT DB 3 DUP (?) ;Output to printer

  BIOSAUXIN DB 3 DUP (?) ;Get byte from auxilliary

学习啦在线学习网   BIOSAUXOUT DB 3 DUP (?) ;Output byte to auxilliary

  BIOSREAD DB 3 DUP (?) ;Disk read

学习啦在线学习网   BIOSWRITE DB 3 DUP (?) ;Disk write

学习啦在线学习网   BIOSDSKCHG DB 3 DUP (?) ;Dsik-change status

  BIOSSETDATE DB 3 DUP (?) ;Set date

  BIOSSETTIME DB 3 DUP (?) ;Set time

  BIOSGETTIME DB 3 DUP (?) ;Get time and date

学习啦在线学习网   BIOSFLUSH DB 3 DUP (?) ;Clear console input buffer

  BIOSMAPDEV DB 3 DUP (?) ;Dynamic disk table mapper

学习啦在线学习网   SEGBIOS ENDS

  ; Location of user registers relative user stack pointer

学习啦在线学习网   STKPTRS STRUC

  AXSAVE DW ?

  BXSAVE DW ?

  CXSAVE DW ?

学习啦在线学习网   DXSAVE DW ?

  SISAVE DW ?

  DISAVE DW ?

学习啦在线学习网   BPSAVE DW ?

  DSSAVE DW ?

学习啦在线学习网   ESSAVE DW ?

学习啦在线学习网   IPSAVE DW ?

学习啦在线学习网   CSSAVE DW ?

  FSAVE DW ?

  STKPTRS ENDS

  ; Start of code

  CODE SEGMENT

  ASSUME CS:DOSGROUP,DS:DOSGROUP,ES:DOSGROUP,SS:DOSGROUP

  ORG 0

学习啦在线学习网   CODSTRT EQU $

学习啦在线学习网   JMP DOSINIT

  ESCCHAR DB ESCCH ;Lead-in character for escape sequences

  ESCTAB:

  IF NOT IBM

学习啦在线学习网   DB "S" ;Copy one char

  DB "V" ;Skip one char

  DB "T" ;Copy to char

学习啦在线学习网   DB "W" ;Skip to char

  DB "U" ;Copy line

  DB "E" ;Kill line (no change in template)

学习啦在线学习网   DB "J" ;Reedit line (new template)

  DB "D" ;Backspace

  DB "P" ;Enter insert mode

  DB "Q" ;Exit insert mode

学习啦在线学习网   DB "R" ;Escape character

  DB "R" ;End of table

  ENDIF

  IF IBM

  DB 64 ;Crtl-Z - F6

  DB 77 ;Copy one char - -->

学习啦在线学习网   DB 59 ;Copy one char - F1

  DB 83 ;Skip one char - DEL

学习啦在线学习网   DB 60 ;Copy to char - F2

学习啦在线学习网   DB 62 ;Skip to char - F4

  DB 61 ;Copy line - F3

  DB 61 ;Kill line (no change to template ) - Not used

学习啦在线学习网   DB 63 ;Reedit line (new template) - F5

学习啦在线学习网   DB 75 ;Backspace - <--

  DB 82 ;Enter insert mode - INS (toggle)

  DB 65 ;Escape character - F7

学习啦在线学习网   DB 65 ;End of table

  ENDIF

  ESCTABLEN EQU $-ESCTAB

学习啦在线学习网   IF NOT IBM

学习啦在线学习网   HEADER DB 13,10,"MS-DOS version 1.25"

学习啦在线学习网   IF HIGHMEM

  DB "H"

  ENDIF

  IF DSKTEST

  DB "D"

  ENDIF

  DB 13,10

  DB "Copyright 1981,82 Microsoft, Inc.",13,10,"$"

  ENDIF

  QUIT:

  MOV AH,0

学习啦在线学习网   JMP SHORT SAVREGS

  COMMAND: ;Interrupt call entry point

  CMP AH,MAXCOM

  JBE SAVREGS

  BADCALL:

学习啦在线学习网   MOV AL,0

  IRET: IRET

  ENTRY: ;System call entry point and dispatcher

学习啦在线学习网   POP AX ;IP from the long call at 5

  POP AX ;Segment from the long call at 5

学习啦在线学习网   POP CS:[TEMP] ;IP from the CALL 5

  PUSHF ;Start re-ordering the stack

  CLI

  PUSH AX ;Save segment

学习啦在线学习网   PUSH CS:[TEMP] ;Stack now ordered as if INT had been used

  CMP CL,MAXCALL ;This entry point doesn't get as many calls

  JA BADCALL

  MOV AH,CL

学习啦在线学习网   SAVREGS:

  PUSH ES

  PUSH DS

  PUSH BP

  PUSH DI

  PUSH SI

  PUSH DX

  PUSH CX

  PUSH BX

  PUSH AX

  IF DSKTEST

  MOV AX,CS:[SPSAVE]

  MOV CS:[NSP],AX

  MOV AX,CS:[SSSAVE]

  MOV CS:[NSS],AX

  POP AX

  PUSH AX

  ENDIF

学习啦在线学习网   MOV CS:[SPSAVE],SP

  MOV CS:[SSSAVE],SS

学习啦在线学习网   MOV SP,CS

  MOV SS,SP

  REDISP:

  MOV SP,OFFSET DOSGROUP:IOSTACK

  STI ;Stack OK now

  MOV BL,AH

学习啦在线学习网   MOV BH,0

  SHL BX,1

  CLD

学习啦在线学习网   CMP AH,12

  JLE SAMSTK

学习啦在线学习网   MOV SP,OFFSET DOSGROUP:DSKSTACK

  SAMSTK:

学习啦在线学习网   CALL CS:[BX+DISPATCH]

  LEAVE:

  CLI

  MOV SP,CS:[SPSAVE]

  MOV SS,CS:[SSSAVE]

学习啦在线学习网   MOV BP,SP

学习啦在线学习网   MOV BYTE PTR [BP.AXSAVE],AL

  IF DSKTEST

  MOV AX,CS:[NSP]

  MOV CS:[SPSAVE],AX

  MOV AX,CS:[NSS]

  MOV CS:[SSSAVE],AX

  ENDIF

  POP AX

  POP BX

  POP CX

  POP DX

  POP SI

  POP DI

  POP BP

  POP DS

  POP ES

  IRET

学习啦在线学习网   ; Standard Functions

学习啦在线学习网   DISPATCH DW ABORT ;0

  DW CONIN

学习啦在线学习网   DW CONOUT

学习啦在线学习网   DW READER

  DW PUNCH

学习啦在线学习网   DW LIST ;5

学习啦在线学习网   DW RAWIO

  DW RAWINP

  DW IN

  DW PRTBUF

  DW BUFIN ;10

  DW CONSTAT

学习啦在线学习网   DW FLUSHKB

  DW DSKRESET

  DW SELDSK

  DW OPEN ;15

学习啦在线学习网   DW CLOSE

  DW SRCHFRST

  DW SRCHNXT

学习啦在线学习网   DW DELETE

学习啦在线学习网   DW SEQRD ;20

  DW SEQWRT

学习啦在线学习网   DW CREATE

学习啦在线学习网   DW RENAME

学习啦在线学习网   DW INUSE

学习啦在线学习网   DW GETDRV ;25

学习啦在线学习网   DW SETDMA

  DW GETFATPT

学习啦在线学习网   DW GETFATPTDL

  DW GETRDONLY

  DW SETATTRIB ;30

学习啦在线学习网   DW GETDSKPT

学习啦在线学习网   DW USERCODE

  DW RNDRD

  DW RNDWRT

  DW FILESIZE ;35

  DW SETRNDREC

学习啦在线学习网   ; Extended Functions

  DW SETVECT

  DW NEWBASE

学习啦在线学习网   DW BLKRD

  DW BLKWRT ;40

  DW MAKEFCB

  DW GETDATE

  DW SETDATE

学习啦在线学习网   DW GETTIME

  DW SETTIME ;45

学习啦在线学习网   DW VERIFY

  INUSE:

  GETIO:

  SETIO:

  GETRDONLY:

学习啦在线学习网   SETATTRIB:

  USERCODE:

学习啦在线学习网   MOV AL,0

  RET

  VERIFY:

  AND AL,1

  MOV CS:VERFLG,AL

  RET

  FLUSHKB:

  PUSH AX

学习啦在线学习网   CALL FAR PTR BIOSFLUSH

  POP AX

  MOV AH,AL

  CMP AL,1

  JZ REDISPJ

学习啦在线学习网   CMP AL,6

学习啦在线学习网   JZ REDISPJ

学习啦在线学习网   CMP AL,7

  JZ REDISPJ

  CMP AL,8

  JZ REDISPJ

  CMP AL,10

  JZ REDISPJ

  MOV AL,0

  RET

  REDISPJ:JMP REDISP

  READER:

  AUXIN:

  CALL STATCHK

学习啦在线学习网   CALL FAR PTR BIOSAUXIN

  RET

  PUNCH:

  MOV AL,DL

  AUXOUT:

  PUSH AX

学习啦在线学习网   CALL STATCHK

  POP AX

  CALL FAR PTR BIOSAUXOUT

  RET

  UNPACK:

学习啦在线学习网   ; Inputs:

  ; DS = CS

学习啦在线学习网   ; BX = Cluster number

学习啦在线学习网   ; BP = Base of drive parameters

学习啦在线学习网   ; SI = Pointer to drive FAT

学习啦在线学习网   ; Outputs:

学习啦在线学习网   ; DI = Contents of FAT for given cluster

  ; Zero set means DI=0 (free cluster)

  ; No other registers affected. Fatal error if cluster too big.

  CMP BX,[BP.MAXCLUS]

  JA HURTFAT

  LEA DI,[SI+BX]

  SHR BX,1

  MOV DI,[DI+BX]

  JNC HAVCLUS

  SHR DI,1

  SHR DI,1

  SHR DI,1

学习啦在线学习网   SHR DI,1

  STC

  HAVCLUS:

  RCL BX,1

  AND DI,0FFFH

  RET

学习啦在线学习网   HURTFAT:

  PUSH AX

  MOV AH,80H ;Signal Bad FAT to INT 24H handler

学习啦在线学习网   MOV DI,0FFFH ;In case INT 24H returns (it shouldn't)

  CALL FATAL

  POP AX ;Try to ignore bad FAT

  RET

  PACK:

  ; Inputs:

学习啦在线学习网   ; DS = CS

  ; BX = Cluster number

  ; DX = Data

  ; SI = Pointer to drive FAT

学习啦在线学习网   ; Outputs:

  ; The data is stored in the FAT at the given cluster.

  ; BX,DX,DI all destroyed

学习啦在线学习网   ; No other registers affected

  MOV DI,BX

  SHR BX,1

  ADD BX,SI

  ADD BX,DI

  SHR DI,1

学习啦在线学习网   MOV DI,[BX]

  JNC ALIGNED

  SHL DX,1

  SHL DX,1

学习啦在线学习网   SHL DX,1

学习啦在线学习网   SHL DX,1

  AND DI,0FH

  JMP SHORT PACKIN

学习啦在线学习网   ALIGNED:

学习啦在线学习网   AND DI,0F000H

  PACKIN:

学习啦在线学习网   OR DI,DX

学习啦在线学习网   MOV [BX],DI

  RET

  DEVNAME:

学习啦在线学习网   MOV SI,OFFSET DOSGROUP:IONAME ;List of I/O devices with file names

  MOV BH,NUMDEV ;BH = number of device names

  LOOKIO:

  MOV DI,OFFSET DOSGROUP:NAME1

  MOV CX,4 ;All devices are 4 letters

  REPE CMPSB ;Check for name in list

  JZ IOCHK ;If first 3 letters OK, check for the rest

学习啦在线学习网   ADD SI,CX ;Point to next device name

  DEC BH

学习啦在线学习网   JNZ LOOKIO

  CRET:

  STC ;Not found

  RET

  IOCHK:

  IF IBM

学习啦在线学习网   CMP BH,NUMDEV ;Is it the first device?

  JNZ NOTCOM1

学习啦在线学习网   MOV BH,2 ;Make it the same as AUX

学习啦在线学习网   NOTCOM1:

  ENDIF

  NEG BH

  MOV CX,2 ;Check rest of name but not extension

学习啦在线学习网   MOV AX,2020H

  REPE SCASW ;Make sure rest of name is blanks

  JNZ CRET

学习啦在线学习网   RET1: RET ;Zero set so CREATE works

  GETFILE:

学习啦在线学习网   ; Same as GETNAME except ES:DI points to FCB on successful return

学习啦在线学习网   CALL MOVNAME

  JC RET1

  PUSH DX

  PUSH DS

  CALL FINDNAME

  POP ES

  POP DI

  RET2: RET

  GETNAME:

  ; Inputs:

学习啦在线学习网   ; DS,DX point to FCB

  ; Function:

  ; Find file name in disk directory. First byte is

  ; drive number (0=current disk). "?" matches any

  ; character.

学习啦在线学习网   ; Outputs:

  ; Carry set if file not found

  ; ELSE

  ; Zero set if attributes match (always except when creating)

学习啦在线学习网   ; BP = Base of drive parameters

学习啦在线学习网   ; DS = CS

学习啦在线学习网   ; ES = CS

学习啦在线学习网   ; BX = Pointer into directory buffer

学习啦在线学习网   ; SI = Pointer to First Cluster field in directory entry

学习啦在线学习网   ; [DIRBUF] has directory record with match

  ; [NAME1] has file name

  ; All other registers destroyed.

  CALL MOVNAME

学习啦在线学习网   JC RET2 ;Bad file name?

  FINDNAME:

  MOV AX,CS

  MOV DS,AX

  CALL DEVNAME

  JNC RET2

学习啦在线学习网   CALL STARTSRCH

学习啦在线学习网   CONTSRCH:

  CALL GETENTRY

  JC RET2

  SRCH:

学习啦在线学习网   MOV AH,BYTE PTR [BX]

  OR AH,AH ;End of directory?

  JZ FREE

  CMP AH,[DELALL] ;Free entry?

  JZ FREE

  MOV SI,BX

  MOV DI,OFFSET DOSGROUP:NAME1

学习啦在线学习网   MOV CX,11

学习啦在线学习网   WILDCRD:

  REPE CMPSB

学习啦在线学习网   JZ FOUND

  CMP BYTE PTR [DI-1],"?"

学习啦在线学习网   JZ WILDCRD

学习啦在线学习网   NEXTENT:

  CALL NEXTENTRY

  JNC SRCH

  RET3: RET

  FREE:

学习啦在线学习网   CMP [ENTFREE],-1 ;Found a free entry before?

学习啦在线学习网   JNZ TSTALL ;If so, ignore this one

学习啦在线学习网   MOV CX,[LASTENT]

  MOV [ENTFREE],CX

  TSTALL:

  CMP AH,[DELALL] ;At end of directory?

学习啦在线学习网   JZ NEXTENT ;No - continue search

  STC ;Report not found

  RET

  FOUND:

学习啦在线学习网   ;Check if attributes allow finding it

  MOV AH,[ATTRIB] ;Attributes of search

  NOT AH

学习啦在线学习网   AND AH,[SI] ;Compare with attributes of file

学习啦在线学习网   ADD SI,15

学习啦在线学习网   AND AH,6 ;Only look at bits 1 and 2

  JZ RET3

学习啦在线学习网   TEST BYTE PTR [CREATING],-1 ;Pass back mismatch if creating

  JZ NEXTENT ;Otherwise continue searching

  RET

学习啦在线学习网   GETENTRY:

  ; Inputs:

  ; [LASTENT] has previously searched directory entry

  ; Function:

  ; Locates next sequential directory entry in preparation for search

  ; Outputs:

  ; Carry set if none

  ; ELSE

  ; AL = Current directory block

  ; BX = Pointer to next directory entry in [DIRBUF]

  ; DX = Pointer to first byte after end of DIRBUF

  ; [LASTENT] = New directory entry number

  MOV AX,[LASTENT]

学习啦在线学习网   INC AX ;Start with next entry

  CMP AX,[BP.MAXENT]

学习啦在线学习网   JAE NONE

  GETENT:

  MOV [LASTENT],AX

学习啦在线学习网   MOV CL,4

  SHL AX,CL

  XOR DX,DX

学习啦在线学习网   SHL AX,1

  RCL DX,1 ;Account for overflow in last shift

学习啦在线学习网   MOV BX,[BP.SECSIZ]

  AND BL,255-31 ;Must be multiple of 32

  DIV BX

  MOV BX,DX ;Position within sector

  MOV AH,[BP.DEVNUM] ;AL=Directory sector no.

  CMP AX,[DIRBUFID]

学习啦在线学习网   JZ HAVDIRBUF

  PUSH BX

学习啦在线学习网   CALL DIRREAD

  POP BX

  HAVDIRBUF:

学习啦在线学习网   MOV DX,OFFSET DOSGROUP:DIRBUF

  ADD BX,DX

  ADD DX,[BP.SECSIZ]

  RET

学习啦在线学习网   NEXTENTRY:

  ; Inputs:

学习啦在线学习网   ; Same as outputs of GETENTRY, above

学习啦在线学习网   ; Function:

  ; Update AL, BX, and [LASTENT] for next directory entry.

  ; Carry set if no more.

  MOV DI,[LASTENT]

  INC DI

学习啦在线学习网   CMP DI,[BP.MAXENT]

  JAE NONE

  MOV [LASTENT],DI

学习啦在线学习网   ADD BX,32

  CMP BX,DX

学习啦在线学习网   JB HAVIT

学习啦在线学习网   INC AL ;Next directory sector

  PUSH DX ;Save limit

  CALL DIRREAD

  POP DX

  MOV BX,OFFSET DOSGROUP:DIRBUF

  HAVIT:

  CLC

  RET

  NONE:

学习啦在线学习网   CALL CHKDIRWRITE

  STC

  RET4: RET

  DELETE: ; System call 19

学习啦在线学习网   CALL MOVNAME

  MOV AL,-1

  JC RET4

  MOV AL,CS:[ATTRIB]

学习啦在线学习网   AND AL,6 ;Look only at hidden bits

学习啦在线学习网   CMP AL,6 ;Both must be set

  JNZ NOTALL

  MOV CX,11

学习啦在线学习网   MOV AL,"?"

学习啦在线学习网   MOV DI,OFFSET DOSGROUP:NAME1

  REPE SCASB ;See if name is *.*

学习啦在线学习网   JNZ NOTALL

  MOV BYTE PTR CS:[DELALL],0 ;DEL *.* - flag deleting all

  NOTALL:

学习啦在线学习网   CALL FINDNAME

  MOV AL,-1

  JC RET4

  OR BH,BH ;Check if device name

  JS RET4 ;Can't delete I/O devices

学习啦在线学习网   DELFILE:

  MOV BYTE PTR [DIRTYDIR],-1

  MOV AH,[DELALL]

学习啦在线学习网   MOV BYTE PTR [BX],AH

学习啦在线学习网   MOV BX,[SI]

学习啦在线学习网   MOV SI,[BP.FAT]

学习啦在线学习网   OR BX,BX

学习啦在线学习网   JZ DELNXT

  CMP BX,[BP.MAXCLUS]

  JA DELNXT

学习啦在线学习网   CALL RELEASE

  DELNXT:

  CALL CONTSRCH

学习啦在线学习网   JNC DELFILE

学习啦在线学习网   CALL FATWRT

学习啦在线学习网   CALL CHKDIRWRITE

学习啦在线学习网   XOR AL,AL

  RET

  RENAME: ;System call 23

  CALL MOVNAME

学习啦在线学习网   JC ERRET

  ADD SI,5

学习啦在线学习网   MOV DI,OFFSET DOSGROUP:NAME2

学习啦在线学习网   CALL LODNAME

  JC ERRET ;Report error if second name invalid

  CALL FINDNAME

  JC ERRET

  OR BH,BH ;Check if I/O device name

  JS ERRET ;If so, can't rename it

学习啦在线学习网   MOV SI,OFFSET DOSGROUP:NAME1

  MOV DI,OFFSET DOSGROUP:NAME3

学习啦在线学习网   MOV CX,6 ;6 words (12 bytes)--include attribute byte

  REP MOVSW ;Copy name to search for

  RENFIL:

  MOV DI,OFFSET DOSGROUP:NAME1

  MOV SI,OFFSET DOSGROUP:NAME2

  MOV CX,11

  NEWNAM:

  LODSB

学习啦在线学习网   CMP AL,"?"

学习啦在线学习网   JNZ NOCHG

  MOV AL,[BX]

  NOCHG:

  STOSB

  INC BX

学习啦在线学习网   LOOP NEWNAM

学习啦在线学习网   MOV BYTE PTR [DI],6 ;Stop duplicates with any attributes

  CALL DEVNAME ;Check if giving it a device name

  JNC RENERR

  PUSH [LASTENT] ;Save position of match

  MOV [LASTENT],-1 ;Search entire directory for duplicate

  CALL CONTSRCH ;See if new name already exists

  POP AX

  JNC RENERR ;Error if found

  CALL GETENT ;Re-read matching entry

  MOV DI,BX

  MOV SI,OFFSET DOSGROUP:NAME1

  MOV CX,5

  MOVSB

学习啦在线学习网   REP MOVSW ;Replace old name with new one

  MOV BYTE PTR [DIRTYDIR],-1 ;Flag change in directory

  MOV SI,OFFSET DOSGROUP:NAME3

学习啦在线学习网   MOV DI,OFFSET DOSGROUP:NAME1

  MOV CX,6 ;Include attribute byte

  REP MOVSW ;Copy name back into search buffer

  CALL CONTSRCH

学习啦在线学习网   JNC RENFIL

学习啦在线学习网   CALL CHKDIRWRITE

  XOR AL,AL

  RET

  RENERR:

  CALL CHKDIRWRITE

  ERRET:

  MOV AL,-1

学习啦在线学习网   RET5: RET

学习啦在线学习网   MOVNAME:

  ; Inputs:

学习啦在线学习网   ; DS, DX point to FCB or extended FCB

  ; Outputs:

学习啦在线学习网   ; DS:DX point to normal FCB

  ; ES = CS

学习啦在线学习网   ; If file name OK:

  ; BP has base of driver parameters

  ; [NAME1] has name in upper case

  ; All registers except DX destroyed

  ; Carry set if bad file name or drive

  MOV CS:WORD PTR [CREATING],0E500H ;Not creating, not DEL *.*

  MOV AX,CS

  MOV ES,AX

学习啦在线学习网   MOV DI,OFFSET DOSGROUP:NAME1

  MOV SI,DX

  LODSB

  MOV CS:[EXTFCB],AL ;Set flag if extended FCB in use

  MOV AH,0 ;Set default attributes

  CMP AL,-1 ;Is it an extended FCB?

  JNZ HAVATTRB

学习啦在线学习网   ADD DX,7 ;Adjust to point to normal FCB

学习啦在线学习网   ADD SI,6 ;Point to drive select byte

学习啦在线学习网   MOV AH,[SI-1] ;Get attribute byte

  LODSB ;Get drive select byte

  HAVATTRB:

学习啦在线学习网   MOV CS:[ATTRIB],AH ;Save attributes

学习啦在线学习网   CALL GETTHISDRV

学习啦在线学习网   LODNAME:

  ; This entry point copies a file name from DS,SI

学习啦在线学习网   ; to ES,DI converting to upper case.

  CMP BYTE PTR [SI]," " ;Don't allow blank as first letter

学习啦在线学习网   STC ;In case of error

  JZ RET5

  MOV CX,11

  MOVCHK:

学习啦在线学习网   CALL GETLET

  JB RET5

  JNZ STOLET ;Is it a delimiter?

  CMP AL," " ;This is the only delimiter allowed

学习啦在线学习网   STC ;In case of error

  JNZ RET5

  STOLET:

  STOSB

  LOOP MOVCHK

  CLC ;Got through whole name - no error

学习啦在线学习网   RET6: RET

  GETTHISDRV:

  CMP CS:[NUMDRV],AL

  JC RET6

  DEC AL

学习啦在线学习网   JNS PHYDRV

学习啦在线学习网   MOV AL,CS:[CURDRV]

  PHYDRV:

  MOV CS:[THISDRV],AL

  RET

学习啦在线学习网   OPEN: ;System call 15

学习啦在线学习网   CALL GETFILE

  DOOPEN:

学习啦在线学习网   ; Enter here to perform OPEN on file already found

  ; in directory. DS=CS, BX points to directory

  ; entry in DIRBUF, SI points to First Cluster field, and

  ; ES:DI point to the FCB to be opened. This entry point

  ; is used by CREATE.

  JC ERRET

  OR BH,BH ;Check if file is I/O device

学习啦在线学习网   JS OPENDEV ;Special handler if so

学习啦在线学习网   MOV AL,[THISDRV]

  INC AX

  STOSB

学习啦在线学习网   XOR AX,AX

  IF ZEROEXT

  ADD DI,11

  STOSW ;Zero low byte of extent field if IBM only

  ENDIF

  IF NOT ZEROEXT

学习啦在线学习网   ADD DI,12 ;Point to high half of CURRENT BLOCK field

学习啦在线学习网   STOSB ;Set it to zero (CP/M programs set low byte)

  ENDIF

  MOV AL,128 ;Default record size

  STOSW ;Set record size

学习啦在线学习网   LODSW ;Get starting cluster

  MOV DX,AX ;Save it for the moment

学习啦在线学习网   MOVSW ;Transfer size to FCB

  MOVSW

  MOV AX,[SI-8] ;Get date

  STOSW ;Save date in FCB

  MOV AX,[SI-10] ;Get time

  STOSW ;Save it in FCB

  MOV AL,[BP.DEVNUM]

学习啦在线学习网   OR AL,40H

  STOSB

  MOV AX,DX ;Restore starting cluster

学习啦在线学习网   STOSW ; first cluster

  STOSW ; last cluster accessed

学习啦在线学习网   XOR AX,AX

  STOSW ; position of last cluster

  RET

  OPENDEV:

学习啦在线学习网   ADD DI,13 ;point to 2nd half of extent field

  XOR AX,AX

  STOSB ;Set it to zero

  MOV AL,128

  STOSW ;Set record size to 128

  XOR AX,AX

  STOSW

  STOSW ;Set current size to zero

学习啦在线学习网   CALL DATE16

  STOSW ;Date is todays

学习啦在线学习网   XCHG AX,DX

  STOSW ;Use current time

学习啦在线学习网   MOV AL,BH ;Get device number

  STOSB

  XOR AL,AL ;No error

  RET

  FATERR:

学习啦在线学习网   XCHG AX,DI ;Put error code in DI

  MOV AH,2 ;While trying to read FAT

  MOV AL,[THISDRV] ;Tell which drive

学习啦在线学习网   CALL FATAL1

学习啦在线学习网   JMP SHORT FATREAD

学习啦在线学习网   STARTSRCH:

  MOV AX,-1

学习啦在线学习网   MOV [LASTENT],AX

学习啦在线学习网   MOV [ENTFREE],AX

  FATREAD:

  ; Inputs:

学习啦在线学习网   ; DS = CS

  ; Function:

  ; If disk may have been changed, FAT is read in and buffers are

学习啦在线学习网   ; flagged invalid. If not, no action is taken.

  ; Outputs:

  ; BP = Base of drive parameters

  ; Carry set if invalid drive returned by MAPDEV

  ; All other registers destroyed

  MOV AL,[THISDRV]

  XOR AH,AH ;Set default response to zero & clear carry

学习啦在线学习网   CALL FAR PTR BIOSDSKCHG ;See what BIOS has to say

  JC FATERR

  CALL GETBP

  MOV AL,[THISDRV] ;Use physical unit number

  MOV SI,[BP.FAT]

学习啦在线学习网   OR AH,[SI-1] ;Dirty byte for FAT

学习啦在线学习网   JS NEWDSK ;If either say new disk, then it's so

  JNZ MAPDRV

  MOV AH,1

学习啦在线学习网   CMP AX,WORD PTR [BUFDRVNO] ;Does buffer have dirty sector of this drive?

  JZ MAPDRV

  NEWDSK:

  CMP AL,[BUFDRVNO] ;See if buffer is for this drive

学习啦在线学习网   JNZ BUFOK ;If not, don't touch it

  MOV [BUFSECNO],0 ;Flag buffers invalid

  MOV WORD PTR [BUFDRVNO],00FFH

  BUFOK:

  MOV [DIRBUFID],-1

学习啦在线学习网   CALL FIGFAT

  NEXTFAT:

  PUSH AX

  CALL DSKREAD

  POP AX

  JC BADFAT

  SUB AL,[BP.FATCNT]

  JZ NEWFAT

学习啦在线学习网   CALL FATWRT

  NEWFAT:

  MOV SI,[BP.FAT]

  MOV AL,[BP.DEVNUM]

  MOV AH,[SI] ;Get first byte of FAT

学习啦在线学习网   OR AH,0F8H ;Put in range

  CALL FAR PTR BIOSMAPDEV

  MOV AH,0

  MOV [SI-2],AX ;Set device no. and reset dirty bit

  MAPDRV:

  MOV AL,[SI-2] ;Get device number

  GETBP:

学习啦在线学习网   MOV BP,[DRVTAB] ;Just in case drive isn't valid

学习啦在线学习网   AND AL,3FH ;Mask out dirty bit

  CMP AL,[NUMIO]

  CMC

  JC RET7

  PUSH AX

  MOV AH,DPBSIZ

  MUL AH

学习啦在线学习网   ADD BP,AX

  POP AX

  RET7: RET

  BADFAT:

学习啦在线学习网   MOV CX,DI

学习啦在线学习网   ADD DX,CX

  DEC AL

  JNZ NEXTFAT

  CALL FIGFAT ;Reset registers

学习啦在线学习网   CALL DREAD ;Try first FAT once more

学习啦在线学习网   JMP SHORT NEWFAT

  OKRET1:

学习啦在线学习网   MOV AL,0

  RET

  CLOSE: ;System call 16

  MOV DI,DX

学习啦在线学习网   CMP BYTE PTR [DI],-1 ;Check for extended FCB

学习啦在线学习网   JNZ NORMFCB3

  ADD DI,7

学习啦在线学习网   NORMFCB3:

  TEST BYTE PTR [DI.DEVID],0C0H ;Allow only dirty files

  JNZ OKRET1 ;can't close if I/O device, or not writen

  MOV AL,[DI] ;Get physical unit number

  DEC AL ;Make zero = drive A

学习啦在线学习网   MOV AH,1 ;Look for dirty buffer

学习啦在线学习网   CMP AX,CS:WORD PTR [BUFDRVNO]

  JNZ FNDDIR

学习啦在线学习网   ;Write back dirty buffer if on same drive

  PUSH DX

  PUSH DS

  PUSH CS

  POP DS

学习啦在线学习网   MOV BYTE PTR [DIRTYBUF],0

  MOV BX,[BUFFER]

  MOV CX,1

  MOV DX,[BUFSECNO]

学习啦在线学习网   MOV BP,[BUFDRVBP]

学习啦在线学习网   CALL DWRITE

  POP DS

  POP DX

  FNDDIR:

  CALL GETFILE

学习啦在线学习网   BADCLOSEJ:

学习啦在线学习网   JC BADCLOSE

  MOV CX,ES:[DI.FIRCLUS]

学习啦在线学习网   MOV [SI],CX

  MOV DX,ES:WORD PTR [DI.FILSIZ]

学习啦在线学习网   MOV [SI+2],DX

学习啦在线学习网   MOV DX,ES:WORD PTR [DI.FILSIZ+2]

学习啦在线学习网   MOV [SI+4],DX

  MOV DX,ES:[DI.FDATE]

  MOV [SI-2],DX

  MOV DX,ES:[DI.FTIME]

学习啦在线学习网   MOV [SI-4],DX

学习啦在线学习网   CALL DIRWRITE

  CHKFATWRT:

学习啦在线学习网   ; Do FATWRT only if FAT is dirty and uses same I/O driver

学习啦在线学习网   MOV SI,[BP.FAT]

学习啦在线学习网   MOV AL,[BP.DEVNUM]

学习啦在线学习网   MOV AH,1

  CMP [SI-2],AX ;See if FAT dirty and uses same driver

学习啦在线学习网   JNZ OKRET

  FATWRT:

  ; Inputs:

学习啦在线学习网   ; DS = CS

  ; BP = Base of drive parameter table

  ; Function:

学习啦在线学习网   ; Write the FAT back to disk and reset FAT

学习啦在线学习网   ; dirty bit.

  ; Outputs:

学习啦在线学习网   ; AL = 0

  ; BP unchanged

学习啦在线学习网   ; All other registers destroyed

  CALL FIGFAT

  MOV BYTE PTR [BX-1],0

学习啦在线学习网   EACHFAT:

  PUSH DX

  PUSH CX

  PUSH BX

  PUSH AX

  CALL DWRITE

  POP AX

  POP BX

  POP CX

  POP DX

  ADD DX,CX

  DEC AL

学习啦在线学习网   JNZ EACHFAT

  OKRET:

  MOV AL,0

  RET

  BADCLOSE:

  MOV SI,[BP.FAT]

  MOV BYTE PTR [SI-1],0

  MOV AL,-1

  RET

  FIGFAT:

  ; Loads registers with values needed to read or

  ; write a FAT.

  MOV AL,[BP.FATCNT]

  MOV BX,[BP.FAT]

  MOV CL,[BP.FATSIZ] ;No. of records occupied by FAT

  MOV CH,0

  MOV DX,[BP.FIRFAT] ;Record number of start of FATs

  RET

  DIRCOMP:

  ; Prepare registers for directory read or write

  CBW

学习啦在线学习网   ADD AX,[BP.FIRDIR]

  MOV DX,AX

  MOV BX,OFFSET DOSGROUP:DIRBUF

  MOV CX,1

  RET

  CREATE: ;System call 22

学习啦在线学习网   CALL MOVNAME

  JC ERRET3

学习啦在线学习网   MOV DI,OFFSET DOSGROUP:NAME1

学习啦在线学习网   MOV CX,11

学习啦在线学习网   MOV AL,"?"

  REPNE SCASB

  JZ ERRET3

  MOV CS:BYTE PTR [CREATING],-1

  PUSH DX

  PUSH DS

  CALL FINDNAME

  JNC EXISTENT

学习啦在线学习网   MOV AX,[ENTFREE] ;First free entry found in FINDNAME

  CMP AX,-1

  JZ ERRPOP

  CALL GETENT ;Point at that free entry

学习啦在线学习网   JMP SHORT FREESPOT

  ERRPOP:

  POP DS

  POP DX

  ERRET3:

  MOV AL,-1

  RET

  EXISTENT:

学习啦在线学习网   JNZ ERRPOP ;Error if attributes don't match

学习啦在线学习网   OR BH,BH ;Check if file is I/O device

学习啦在线学习网   JS OPENJMP ;If so, no action

学习啦在线学习网   MOV CX,[SI] ;Get pointer to clusters

  JCXZ FREESPOT

  CMP CX,[BP.MAXCLUS]

  JA FREESPOT

  PUSH BX

  MOV BX,CX

学习啦在线学习网   MOV SI,[BP.FAT]

学习啦在线学习网   CALL RELEASE ;Free any data already allocated

  CALL FATWRT

  POP BX

学习啦在线学习网   FREESPOT:

学习啦在线学习网   MOV DI,BX

  MOV SI,OFFSET DOSGROUP:NAME1

  MOV CX,5

  MOVSB

  REP MOVSW

  MOV AL,[ATTRIB]

  STOSB

  XOR AX,AX

  MOV CL,5

  REP STOSW

学习啦在线学习网   CALL DATE16

  XCHG AX,DX

  STOSW

学习啦在线学习网   XCHG AX,DX

  STOSW

  XOR AX,AX

  PUSH DI

  MOV CL,6

  SMALLENT:

学习啦在线学习网   REP STOSB

  PUSH BX

  CALL DIRWRITE

  POP BX

  POP SI

  OPENJMP:

学习啦在线学习网   CLC ;Clear carry so OPEN won't fail

  POP ES

  POP DI

  JMP DOOPEN

  DIRREAD:

  ; Inputs:

学习啦在线学习网   ; DS = CS

  ; AL = Directory block number

  ; BP = Base of drive parameters

  ; Function:

  ; Read the directory block into DIRBUF.

学习啦在线学习网   ; Outputs:

学习啦在线学习网   ; AX,BP unchanged

  ; All other registers destroyed.

  PUSH AX

学习啦在线学习网   CALL CHKDIRWRITE

  POP AX

  PUSH AX

学习啦在线学习网   MOV AH,[BP.DEVNUM]

学习啦在线学习网   MOV [DIRBUFID],AX

  CALL DIRCOMP

  CALL DREAD

  POP AX

学习啦在线学习网   RET8: RET

  DREAD:

  ; Inputs:

学习啦在线学习网   ; BX,DS = Transfer address

  ; CX = Number of sectors

学习啦在线学习网   ; DX = Absolute record number

  ; BP = Base of drive parameters

  ; Function:

  ; Calls BIOS to perform disk read. If BIOS reports

学习啦在线学习网   ; errors, will call HARDERR for further action.

学习啦在线学习网   ; BP preserved. All other registers destroyed.

学习啦在线学习网   CALL DSKREAD

  JNC RET8

学习啦在线学习网   MOV CS:BYTE PTR [READOP],0

  CALL HARDERR

  CMP AL,1 ;Check for retry

  JZ DREAD

学习啦在线学习网   RET ;Ignore otherwise

  HARDERR:

学习啦在线学习网   ;Hard disk error handler. Entry conditions:

学习啦在线学习网   ; DS:BX = Original disk transfer address

学习啦在线学习网   ; DX = Original logical sector number

  ; CX = Number of sectors to go (first one gave the error)

学习啦在线学习网   ; AX = Hardware error code

学习啦在线学习网   ; DI = Original sector transfer count

学习啦在线学习网   ; BP = Base of drive parameters

  ; [READOP] = 0 for read, 1 for write

  XCHG AX,DI ;Error code in DI, count in AX

学习啦在线学习网   SUB AX,CX ;Number of sectors successfully transferred

  ADD DX,AX ;First sector number to retry

  PUSH DX

学习啦在线学习网   MUL [BP.SECSIZ] ;Number of bytes transferred

  POP DX

  ADD BX,AX ;First address for retry

  MOV AH,0 ;Flag disk section in error

学习啦在线学习网   CMP DX,[BP.FIRFAT] ;In reserved area?

  JB ERRINT

  INC AH ;Flag for FAT

学习啦在线学习网   CMP DX,[BP.FIRDIR] ;In FAT?

  JB ERRINT

  INC AH

  CMP DX,[BP.FIRREC] ;In directory?

  JB ERRINT

学习啦在线学习网   INC AH ;Must be in data area

  ERRINT:

学习啦在线学习网   SHL AH,1 ;Make room for read/write bit

  OR AH,CS:[READOP]

  FATAL:

学习啦在线学习网   MOV AL,[BP.DRVNUM] ;Get drive number

  FATAL1:

学习啦在线学习网   PUSH BP ;The only thing we preserve

学习啦在线学习网   MOV CS:[CONTSTK],SP

学习啦在线学习网   CLI ;Prepare to play with stack

学习啦在线学习网   MOV SS,CS:[SSSAVE]

  MOV SP,CS:[SPSAVE] ;User stack pointer restored

  INT 24H ;Fatal error interrupt vector

  MOV CS:[SPSAVE],SP

  MOV CS:[SSSAVE],SS

  MOV SP,CS

学习啦在线学习网   MOV SS,SP

学习啦在线学习网   MOV SP,CS:[CONTSTK]

  STI

  POP BP

学习啦在线学习网   CMP AL,2

学习啦在线学习网   JZ ERROR

  RET

  DSKREAD:

  MOV AL,[BP.DEVNUM]

  PUSH BP

  PUSH BX

  PUSH CX

  PUSH DX

学习啦在线学习网   CALL FAR PTR BIOSREAD

  POP DX

  POP DI

  POP BX

  POP BP

  RET9: RET

  CHKDIRWRITE:

  TEST BYTE PTR [DIRTYDIR],-1

  JZ RET9

  DIRWRITE:

  ; Inputs:

学习啦在线学习网   ; DS = CS

学习啦在线学习网   ; AL = Directory block number

  ; BP = Base of drive parameters

  ; Function:

学习啦在线学习网   ; Write the directory block into DIRBUF.

  ; Outputs:

  ; BP unchanged

  ; All other registers destroyed.

  MOV BYTE PTR [DIRTYDIR],0

学习啦在线学习网   MOV AL,BYTE PTR [DIRBUFID]

  CALL DIRCOMP

  DWRITE:

学习啦在线学习网   ; Inputs:

学习啦在线学习网   ; BX,DS = Transfer address

学习啦在线学习网   ; CX = Number of sectors

  ; DX = Absolute record number

学习啦在线学习网   ; BP = Base of drive parameters

  ; Function:

学习啦在线学习网   ; Calls BIOS to perform disk write. If BIOS reports

学习啦在线学习网   ; errors, will call HARDERR for further action.

学习啦在线学习网   ; BP preserved. All other registers destroyed.

学习啦在线学习网   MOV AL,[BP.DEVNUM]

学习啦在线学习网   MOV AH,CS:VERFLG

  PUSH BP

  PUSH BX

  PUSH CX

  PUSH DX

  CALL FAR PTR BIOSWRITE

  POP DX

  POP DI

  POP BX

  POP BP

  JNC RET9

  MOV CS:BYTE PTR [READOP],1

学习啦在线学习网   CALL HARDERR

学习啦在线学习网   CMP AL,1 ;Check for retry

学习啦在线学习网   JZ DWRITE

  RET

  ABORT:

学习啦在线学习网   LDS SI,CS:DWORD PTR [SPSAVE]

  MOV DS,[SI.CSSAVE]

学习啦在线学习网   XOR AX,AX

  MOV ES,AX

  MOV SI,SAVEXIT

  MOV DI,EXIT

  MOVSW

  MOVSW

  MOVSW

  MOVSW

  MOVSW

  MOVSW

  ERROR:

学习啦在线学习网   MOV AX,CS

学习啦在线学习网   MOV DS,AX

  MOV ES,AX

  CALL WRTFATS

学习啦在线学习网   XOR AX,AX

  CLI

  MOV SS,[SSSAVE]

  MOV SP,[SPSAVE]

学习啦在线学习网   MOV DS,AX

  MOV SI,EXIT

  MOV DI,OFFSET DOSGROUP:EXITHOLD

  MOVSW

  MOVSW

  POP AX

  POP BX

  POP CX

  POP DX

  POP SI

  POP DI

  POP BP

  POP DS

  POP ES

学习啦在线学习网   STI ;Stack OK now

  JMP CS:DWORD PTR [EXITHOLD]

学习啦在线学习网   SEQRD: ;System call 20

  CALL GETREC

  CALL LOAD

  JMP SHORT FINSEQ

  SEQWRT: ;System call 21

学习啦在线学习网   CALL GETREC

  CALL STORE

  FINSEQ:

  JCXZ SETNREX

学习啦在线学习网   ADD AX,1

  ADC DX,0

  JMP SHORT SETNREX

学习啦在线学习网   RNDRD: ;System call 33

学习啦在线学习网   CALL GETRRPOS1

学习啦在线学习网   CALL LOAD

学习啦在线学习网   JMP SHORT FINRND

  RNDWRT: ;System call 34

  CALL GETRRPOS1

学习啦在线学习网   CALL STORE

  JMP SHORT FINRND

  BLKRD: ;System call 39

学习啦在线学习网   CALL GETRRPOS

学习啦在线学习网   CALL LOAD

  JMP SHORT FINBLK

学习啦在线学习网   BLKWRT: ;System call 40

  CALL GETRRPOS

  CALL STORE

  FINBLK:

学习啦在线学习网   LDS SI,DWORD PTR [SPSAVE]

  MOV [SI.CXSAVE],CX

  JCXZ FINRND

  ADD AX,1

  ADC DX,0

  FINRND:

学习啦在线学习网   MOV ES:WORD PTR [DI.RR],AX

  MOV ES:[DI.RR+2],DL

  OR DH,DH

  JZ SETNREX

  MOV ES:[DI.RR+3],DH ;Save 4 byte of RECPOS only if significant

  SETNREX:

  MOV CX,AX

  AND AL,7FH

学习啦在线学习网   MOV ES:[DI.NR],AL

学习啦在线学习网   AND CL,80H

  SHL CX,1

  RCL DX,1

  MOV AL,CH

学习啦在线学习网   MOV AH,DL

  MOV ES:[DI.EXTENT],AX

  MOV AL,CS:[DSKERR]

  RET

  GETRRPOS1:

学习啦在线学习网   MOV CX,1

学习啦在线学习网   GETRRPOS:

  MOV DI,DX

  CMP BYTE PTR [DI],-1

学习啦在线学习网   JNZ NORMFCB1

  ADD DI,7

  NORMFCB1:

  MOV AX,WORD PTR [DI.RR]

  MOV DX,WORD PTR [DI.RR+2]

  RET

  NOFILERR:

学习啦在线学习网   XOR CX,CX

学习啦在线学习网   MOV BYTE PTR [DSKERR],4

  POP BX

  RET

  SETUP:

  ; Inputs:

  ; DS:DI point to FCB

  ; DX:AX = Record position in file of disk transfer

  ; CX = Record count

  ; Outputs:

  ; DS = CS

  ; ES:DI point to FCB

  ; BL = DEVID from FCB

学习啦在线学习网   ; CX = No. of bytes to transfer

  ; BP = Base of drive parameters

学习啦在线学习网   ; SI = FAT pointer

学习啦在线学习网   ; [RECCNT] = Record count

学习啦在线学习网   ; [RECPOS] = Record position in file

  ; [FCB] = DI

  ; [NEXTADD] = Displacement of disk transfer within segment

学习啦在线学习网   ; [SECPOS] = Position of first sector

  ; [BYTPOS] = Byte position in file

  ; [BYTSECPOS] = Byte position in first sector

学习啦在线学习网   ; [CLUSNUM] = First cluster

  ; [SECCLUSPOS] = Sector within first cluster

  ; [DSKERR] = 0 (no errors yet)

学习啦在线学习网   ; [TRANS] = 0 (No transfers yet)

  ; [THISDRV] = Physical drive unit number

学习啦在线学习网   ; If SETUP detects no records will be transfered, it returns 1 level up

  ; with CX = 0.

  PUSH AX

  MOV AL,[DI]

  DEC AL

学习啦在线学习网   MOV CS:[THISDRV],AL

学习啦在线学习网   MOV AL,[DI.DEVID]

学习啦在线学习网   MOV SI,[DI.RECSIZ]

学习啦在线学习网   OR SI,SI

  JNZ HAVRECSIZ

学习啦在线学习网   MOV SI,128

学习啦在线学习网   MOV [DI.RECSIZ],SI

  HAVRECSIZ:

  PUSH DS

学习啦在线学习网   POP ES ;Set ES to DS

  PUSH CS

学习啦在线学习网   POP DS ;Set DS to CS

学习啦在线学习网   OR AL,AL ;Is it a device?

学习啦在线学习网   JNS NOTDEVICE

学习啦在线学习网   MOV AL,0 ;Fake in drive 0 so we can get SP

  NOTDEVICE:

学习啦在线学习网   CALL GETBP

  POP AX

学习啦在线学习网   JC NOFILERR

学习啦在线学习网   CMP SI,64 ;Check if highest byte of RECPOS is significant

学习啦在线学习网   JB SMALREC

  MOV DH,0 ;Ignore MSB if record >= 64 bytes

  SMALREC:

学习啦在线学习网   MOV [RECCNT],CX

  MOV WORD PTR [RECPOS],AX

  MOV WORD PTR [RECPOS+2],DX

学习啦在线学习网   MOV [FCB],DI

  MOV BX,[DMAADD]

学习啦在线学习网   MOV [NEXTADD],BX

  MOV BYTE PTR [DSKERR],0

  MOV BYTE PTR [TRANS],0

学习啦在线学习网   MOV BX,DX

  MUL SI

学习啦在线学习网   MOV WORD PTR [BYTPOS],AX

  PUSH DX

  MOV AX,BX

  MUL SI

  POP BX

学习啦在线学习网   ADD AX,BX

学习啦在线学习网   ADC DX,0 ;Ripple carry

学习啦在线学习网   JNZ EOFERR

学习啦在线学习网   MOV WORD PTR [BYTPOS+2],AX

  MOV DX,AX

  MOV AX,WORD PTR [BYTPOS]

  MOV BX,[BP.SECSIZ]

  CMP DX,BX ;See if divide will overflow

  JNC EOFERR

  DIV BX

学习啦在线学习网   MOV [SECPOS],AX

  MOV [BYTSECPOS],DX

  MOV DX,AX

  AND AL,[BP.CLUSMSK]

  MOV [SECCLUSPOS],AL

  MOV AX,CX ;Record count

学习啦在线学习网   MOV CL,[BP.CLUSSHFT]

学习啦在线学习网   SHR DX,CL

  MOV [CLUSNUM],DX

  MUL SI ;Multiply by bytes per record

学习啦在线学习网   MOV CX,AX

  ADD AX,[DMAADD] ;See if it will fit in one segment

  ADC DX,0

  JZ OK ;Must be less than 64K

学习啦在线学习网   MOV AX,[DMAADD]

  NEG AX ;Amount of room left in segment

学习啦在线学习网   JNZ PARTSEG ;All 64K available?

学习啦在线学习网   DEC AX ;If so, reduce by one

  PARTSEG:

  XOR DX,DX

  DIV SI ;How many records will fit?

学习啦在线学习网   MOV [RECCNT],AX

  MUL SI ;Translate that back into bytes

  MOV BYTE PTR [DSKERR],2 ;Flag that trimming took place

  MOV CX,AX

学习啦在线学习网   JCXZ NOROOM

  OK:

学习啦在线学习网   MOV BL,ES:[DI.DEVID]

  MOV SI,[BP.FAT]

  RET

  EOFERR:

  MOV BYTE PTR [DSKERR],1

  XOR CX,CX

  NOROOM:

  POP BX ;Kill return address

  RET

  BREAKDOWN:

学习啦在线学习网   ;Inputs:

  ; DS = CS

  ; CX = Length of disk transfer in bytes

  ; BP = Base of drive parameters

  ; [BYTSECPOS] = Byte position witin first sector

  ;Outputs:

  ; [BYTCNT1] = Bytes to transfer in first sector

  ; [SECCNT] = No. of whole sectors to transfer

学习啦在线学习网   ; [BYTCNT2] = Bytes to transfer in last sector

学习啦在线学习网   ;AX, BX, DX destroyed. No other registers affected.

  MOV AX,[BYTSECPOS]

学习啦在线学习网   MOV BX,CX

  OR AX,AX

学习啦在线学习网   JZ SAVFIR ;Partial first sector?

  SUB AX,[BP.SECSIZ]

  NEG AX ;Max number of bytes left in first sector

学习啦在线学习网   SUB BX,AX ;Subtract from total length

  JAE SAVFIR

  ADD AX,BX ;Don't use all of the rest of the sector

  XOR BX,BX ;And no bytes are left

  SAVFIR:

  MOV [BYTCNT1],AX

  MOV AX,BX

  XOR DX,DX

  DIV [BP.SECSIZ] ;How many whole sectors?

学习啦在线学习网   MOV [SECCNT],AX

  MOV [BYTCNT2],DX ;Bytes remaining for last sector

  RET10: RET

  FNDCLUS:

  ; Inputs:

学习啦在线学习网   ; DS = CS

学习啦在线学习网   ; CX = No. of clusters to skip

  ; BP = Base of drive parameters

  ; SI = FAT pointer

  ; ES:DI point to FCB

学习啦在线学习网   ; Outputs:

  ; BX = Last cluster skipped to

  ; CX = No. of clusters remaining (0 unless EOF)

学习啦在线学习网   ; DX = Position of last cluster

  ; DI destroyed. No other registers affected.

  MOV BX,ES:[DI.LSTCLUS]

学习啦在线学习网   MOV DX,ES:[DI.CLUSPOS]

学习啦在线学习网   OR BX,BX

  JZ NOCLUS

  SUB CX,DX

  JNB FINDIT

  ADD CX,DX

  XOR DX,DX

  MOV BX,ES:[DI.FIRCLUS]

  FINDIT:

学习啦在线学习网   JCXZ RET10

  SKPCLP:

  CALL UNPACK

  CMP DI,0FF8H

学习啦在线学习网   JAE RET10

学习啦在线学习网   XCHG BX,DI

  INC DX

学习啦在线学习网   LOOP SKPCLP

  RET

  NOCLUS:

  INC CX

  DEC DX

  RET

  BUFSEC:

  ; Inputs:

  ; AL = 0 if buffer must be read, 1 if no pre-read needed

  ; BP = Base of drive parameters

  ; [CLUSNUM] = Physical cluster number

  ; [SECCLUSPOS] = Sector position of transfer within cluster

  ; [BYTCNT1] = Size of transfer

  ; Function:

  ; Insure specified sector is in buffer, flushing buffer before

  ; read if necessary.

学习啦在线学习网   ; Outputs:

  ; SI = Pointer to buffer

学习啦在线学习网   ; DI = Pointer to transfer address

  ; CX = Number of bytes

  ; [NEXTADD] updated

学习啦在线学习网   ; [TRANS] set to indicate a transfer will occur

  MOV DX,[CLUSNUM]

  MOV BL,[SECCLUSPOS]

  CALL FIGREC

学习啦在线学习网   MOV [PREREAD],AL

学习啦在线学习网   CMP DX,[BUFSECNO]

  JNZ GETSEC

学习啦在线学习网   MOV AL,[BUFDRVNO]

学习啦在线学习网   CMP AL,[THISDRV]

  JZ FINBUF ;Already have it?

  GETSEC:

  XOR AL,AL

  XCHG [DIRTYBUF],AL ;Read dirty flag and reset it

  OR AL,AL

学习啦在线学习网   JZ RDSEC

  PUSH DX

  PUSH BP

  MOV BP,[BUFDRVBP]

  MOV BX,[BUFFER]

学习啦在线学习网   MOV CX,1

学习啦在线学习网   MOV DX,[BUFSECNO]

  CALL DWRITE

  POP BP

  POP DX

  RDSEC:

学习啦在线学习网   TEST BYTE PTR [PREREAD],-1

  JNZ SETBUF

学习啦在线学习网   XOR AX,AX

学习啦在线学习网   MOV [BUFSECNO],AX ;Set buffer valid in case of disk error

  DEC AX

学习啦在线学习网   MOV [BUFDRVNO],AL

  MOV BX,[BUFFER]

  MOV CX,1

  PUSH DX

  CALL DREAD

  POP DX

  SETBUF:

  MOV [BUFSECNO],DX

学习啦在线学习网   MOV AL,[THISDRV]

  MOV [BUFDRVNO],AL

  MOV [BUFDRVBP],BP

  FINBUF:

学习啦在线学习网   MOV BYTE PTR [TRANS],1 ;A transfer is taking place

学习啦在线学习网   MOV DI,[NEXTADD]

  MOV SI,DI

  MOV CX,[BYTCNT1]

  ADD SI,CX

学习啦在线学习网   MOV [NEXTADD],SI

  MOV SI,[BUFFER]

  ADD SI,[BYTSECPOS]

  RET

  BUFRD:

  XOR AL,AL ;Pre-read necessary

  CALL BUFSEC

  PUSH ES

  MOV ES,[DMAADD+2]

  SHR CX,1

学习啦在线学习网   JNC EVENRD

  MOVSB

  EVENRD:

学习啦在线学习网   REP MOVSW

  POP ES

  RET

  BUFWRT:

  MOV AX,[SECPOS]

学习啦在线学习网   INC AX ;Set for next sector

  MOV [SECPOS],AX

学习啦在线学习网   CMP AX,[VALSEC] ;Has sector been written before?

学习啦在线学习网   MOV AL,1

  JA NOREAD ;Skip preread if SECPOS>VALSEC

  MOV AL,0

  NOREAD:

  CALL BUFSEC

  XCHG DI,SI

  PUSH DS

  PUSH ES

  PUSH CS

  POP ES

  MOV DS,[DMAADD+2]

学习啦在线学习网   SHR CX,1

  JNC EVENWRT

  MOVSB

学习啦在线学习网   EVENWRT:

  REP MOVSW

  POP ES

  POP DS

  MOV BYTE PTR [DIRTYBUF],1

  RET

  NEXTSEC:

学习啦在线学习网   TEST BYTE PTR [TRANS],-1

学习啦在线学习网   JZ CLRET

学习啦在线学习网   MOV AL,[SECCLUSPOS]

  INC AL

  CMP AL,[BP.CLUSMSK]

  JBE SAVPOS

学习啦在线学习网   MOV BX,[CLUSNUM]

  CMP BX,0FF8H

  JAE NONEXT

  MOV SI,[BP.FAT]

学习啦在线学习网   CALL UNPACK

学习啦在线学习网   MOV [CLUSNUM],DI

  INC [LASTPOS]

  MOV AL,0

  SAVPOS:

学习啦在线学习网   MOV [SECCLUSPOS],AL

  CLRET:

  CLC

  RET

  NONEXT:

  STC

  RET

学习啦在线学习网   TRANBUF:

  LODSB

  STOSB

学习啦在线学习网   CMP AL,13 ;Check for carriage return

  JNZ NORMCH

学习啦在线学习网   MOV BYTE PTR [SI],10

  NORMCH:

  CMP AL,10

学习啦在线学习网   LOOPNZ TRANBUF

  JNZ ENDRDCON

  CALL OUT ;Transmit linefeed

  XOR SI,SI

学习啦在线学习网   OR CX,CX

  JNZ GETBUF

  OR AL,1 ;Clear zero flag--not end of file

  ENDRDCON:

学习啦在线学习网   MOV [CONTPOS],SI

学习啦在线学习网   ENDRDDEV:

学习啦在线学习网   MOV [NEXTADD],DI

  POP ES

学习啦在线学习网   JNZ SETFCBJ ;Zero set if Ctrl-Z found in input

学习啦在线学习网   MOV DI,[FCB]

  AND ES:BYTE PTR [DI.DEVID],0FFH-40H ;Mark as no more data available

  SETFCBJ:

  JMP SETFCB

  READDEV:

  PUSH ES

  LES DI,DWORD PTR [DMAADD]

  INC BL

  JZ READCON

  INC BL

学习啦在线学习网   JNZ ENDRDDEV

学习啦在线学习网   READAUX:

  CALL AUXIN

  STOSB

  CMP AL,1AH

学习啦在线学习网   LOOPNZ READAUX

  JMP SHORT ENDRDDEV

学习啦在线学习网   READCON:

  PUSH CS

  POP DS

  MOV SI,[CONTPOS]

  OR SI,SI

  JNZ TRANBUF

学习啦在线学习网   CMP BYTE PTR [CONBUF],128

学习啦在线学习网   JZ GETBUF

  MOV WORD PTR [CONBUF],0FF80H ;Set up 128-byte buffer with no template

  GETBUF:

  PUSH CX

  PUSH ES

  PUSH DI

  MOV DX,OFFSET DOSGROUP:CONBUF

  CALL BUFIN ;Get input buffer

  POP DI

  POP ES

  POP CX

学习啦在线学习网   MOV SI,2 + OFFSET DOSGROUP:CONBUF

  CMP BYTE PTR [SI],1AH ;Check for Ctrl-Z in first character

  JNZ TRANBUF

学习啦在线学习网   MOV AL,1AH

  STOSB

  MOV AL,10

  CALL OUT ;Send linefeed

  XOR SI,SI

  JMP SHORT ENDRDCON

  RDERR:

  XOR CX,CX

  JMP WRTERR

  RDLASTJ:JMP RDLAST

  LOAD:

学习啦在线学习网   ; Inputs:

  ; DS:DI point to FCB

学习啦在线学习网   ; DX:AX = Position in file to read

  ; CX = No. of records to read

  ; Outputs:

  ; DX:AX = Position of last record read

  ; CX = No. of bytes read

  ; ES:DI point to FCB

学习啦在线学习网   ; LSTCLUS, CLUSPOS fields in FCB set

  CALL SETUP

学习啦在线学习网   OR BL,BL ;Check for named device I/O

  JS READDEV

  MOV AX,ES:WORD PTR [DI.FILSIZ]

学习啦在线学习网   MOV BX,ES:WORD PTR [DI.FILSIZ+2]

学习啦在线学习网   SUB AX,WORD PTR [BYTPOS]

学习啦在线学习网   SBB BX,WORD PTR [BYTPOS+2]

  JB RDERR

  JNZ ENUF

  OR AX,AX

  JZ RDERR

  CMP AX,CX

学习啦在线学习网   JAE ENUF

学习啦在线学习网   MOV CX,AX

  ENUF:

  CALL BREAKDOWN

  MOV CX,[CLUSNUM]

学习啦在线学习网   CALL FNDCLUS

  OR CX,CX

  JNZ RDERR

  MOV [LASTPOS],DX

学习啦在线学习网   MOV [CLUSNUM],BX

学习啦在线学习网   CMP [BYTCNT1],0

  JZ RDMID

学习啦在线学习网   CALL BUFRD

  RDMID:

学习啦在线学习网   CMP [SECCNT],0

学习啦在线学习网   JZ RDLASTJ

学习啦在线学习网   CALL NEXTSEC

  JC SETFCB

  MOV BYTE PTR [TRANS],1 ;A transfer is taking place

  ONSEC:

学习啦在线学习网   MOV DL,[SECCLUSPOS]

  MOV CX,[SECCNT]

  MOV BX,[CLUSNUM]

  RDLP:

  CALL OPTIMIZE

  PUSH DI

  PUSH AX

  PUSH DS

  MOV DS,[DMAADD+2]

  PUSH DX

  PUSH BX

  PUSHF ;Save carry flag

  CALL DREAD

学习啦在线学习网   POPF ;Restore carry flag

  POP DI ;Initial transfer address

学习啦在线学习网   POP AX ;First sector transfered

  POP DS

  JC NOTBUFFED ;Was one of those sectors in the buffer?

  CMP BYTE PTR [DIRTYBUF],0 ;Is buffer dirty?

学习啦在线学习网   JZ NOTBUFFED ;If not no problem

  ;We have transfered in a sector from disk when a dirty copy of it is in the buffer.

学习啦在线学习网   ;We must transfer the sector from the buffer to correct memory address

  SUB AX,[BUFSECNO] ;How many sectors into the transfer?

  NEG AX

  MOV CX,[BP.SECSIZ]

学习啦在线学习网   MUL CX ;How many bytes into the transfer?

  ADD DI,AX

  MOV SI,[BUFFER]

  PUSH ES

学习啦在线学习网   MOV ES,[DMAADD+2] ;Get disk transfer segment

学习啦在线学习网   SHR CX,1

学习啦在线学习网   REP MOVSW

  JNC EVENMOV

  MOVSB

学习啦在线学习网   EVENMOV:

  POP ES

  NOTBUFFED:

  POP CX

  POP BX

  JCXZ RDLAST

  CMP BX,0FF8H

  JAE SETFCB

  MOV DL,0

学习啦在线学习网   INC [LASTPOS] ;We'll be using next cluster

  JMP SHORT RDLP

  SETFCB:

  MOV SI,[FCB]

  MOV AX,[NEXTADD]

  MOV DI,AX

学习啦在线学习网   SUB AX,[DMAADD] ;Number of bytes transfered

学习啦在线学习网   XOR DX,DX

  MOV CX,ES:[SI.RECSIZ]

学习啦在线学习网   DIV CX ;Number of records

  CMP AX,[RECCNT] ;Check if all records transferred

学习啦在线学习网   JZ FULLREC

学习啦在线学习网   MOV BYTE PTR [DSKERR],1

  OR DX,DX

学习啦在线学习网   JZ FULLREC ;If remainder 0, then full record transfered

  MOV BYTE PTR [DSKERR],3 ;Flag partial last record

  SUB CX,DX ;Bytes left in last record

  PUSH ES

  MOV ES,[DMAADD+2]

  XCHG AX,BX ;Save the record count temporarily

学习啦在线学习网   XOR AX,AX ;Fill with zeros

  SHR CX,1

  JNC EVENFIL

  STOSB

  EVENFIL:

  REP STOSW

学习啦在线学习网   XCHG AX,BX ;Restore record count to AX

  POP ES

  INC AX ;Add last (partial) record to total

学习啦在线学习网   FULLREC:

学习啦在线学习网   MOV CX,AX

学习啦在线学习网   MOV DI,SI ;ES:DI point to FCB

  SETCLUS:

  MOV AX,[CLUSNUM]

  MOV ES:[DI.LSTCLUS],AX

学习啦在线学习网   MOV AX,[LASTPOS]

  MOV ES:[DI.CLUSPOS],AX

  ADDREC:

  MOV AX,WORD PTR [RECPOS]

  MOV DX,WORD PTR [RECPOS+2]

  JCXZ RET28 ;If no records read, don't change position

  DEC CX

  ADD AX,CX ;Update current record position

  ADC DX,0

  INC CX

  RET28: RET

  RDLAST:

学习啦在线学习网   MOV AX,[BYTCNT2]

学习啦在线学习网   OR AX,AX

学习啦在线学习网   JZ SETFCB

  MOV [BYTCNT1],AX

学习啦在线学习网   CALL NEXTSEC

  JC SETFCB

学习啦在线学习网   MOV [BYTSECPOS],0

  CALL BUFRD

学习啦在线学习网   JMP SHORT SETFCB

  WRTDEV:

  PUSH DS

  LDS SI,DWORD PTR [DMAADD]

  OR BL,40H

  INC BL

学习啦在线学习网   JZ WRTCON

  INC BL

  JZ WRTAUX

  INC BL

学习啦在线学习网   JZ ENDWRDEV ;Done if device is NUL

  WRTLST:

  LODSB

  CMP AL,1AH

  JZ ENDWRDEV

  CALL LISTOUT

  LOOP WRTLST

  JMP SHORT ENDWRDEV

  WRTAUX:

  LODSB

  CALL AUXOUT

学习啦在线学习网   CMP AL,1AH

  LOOPNZ WRTAUX

  JMP SHORT ENDWRDEV

  WRTCON:

  LODSB

学习啦在线学习网   CMP AL,1AH

  JZ ENDWRDEV

学习啦在线学习网   CALL OUT

学习啦在线学习网   LOOP WRTCON

  ENDWRDEV:

  POP DS

  MOV CX,[RECCNT]

  MOV DI,[FCB]

  JMP SHORT ADDREC

学习啦在线学习网   HAVSTART:

学习啦在线学习网   MOV CX,AX

  CALL SKPCLP

  JCXZ DOWRTJ

  CALL ALLOCATE

学习啦在线学习网   JNC DOWRTJ

  WRTERR:

学习啦在线学习网   MOV BYTE PTR [DSKERR],1

  LVDSK:

学习啦在线学习网   MOV AX,WORD PTR [RECPOS]

  MOV DX,WORD PTR [RECPOS+2]

  MOV DI,[FCB]

  RET

  DOWRTJ: JMP DOWRT

  WRTEOFJ:

  JMP WRTEOF

  STORE:

  ; Inputs:

  ; DS:DI point to FCB

  ; DX:AX = Position in file of disk transfer

  ; CX = Record count

学习啦在线学习网   ; Outputs:

  ; DX:AX = Position of last record written

  ; CX = No. of records written

学习啦在线学习网   ; ES:DI point to FCB

学习啦在线学习网   ; LSTCLUS, CLUSPOS fields in FCB set

学习啦在线学习网   CALL SETUP

  CALL DATE16

  MOV ES:[DI.FDATE],AX

学习啦在线学习网   MOV ES:[DI.FTIME],DX

  OR BL,BL

学习啦在线学习网   JS WRTDEV

学习啦在线学习网   AND BL,3FH ;Mark file as dirty

  MOV ES:[DI.DEVID],BL

  CALL BREAKDOWN

学习啦在线学习网   MOV AX,WORD PTR [BYTPOS]

  MOV DX,WORD PTR [BYTPOS+2]

  JCXZ WRTEOFJ

  DEC CX

  ADD AX,CX

  ADC DX,0 ;AX:DX=last byte accessed

学习啦在线学习网   DIV [BP.SECSIZ] ;AX=last sector accessed

  MOV CL,[BP.CLUSSHFT]

学习啦在线学习网   SHR AX,CL ;Last cluster to be accessed

  PUSH AX

  MOV AX,ES:WORD PTR [DI.FILSIZ]

  MOV DX,ES:WORD PTR [DI.FILSIZ+2]

  DIV [BP.SECSIZ]

学习啦在线学习网   OR DX,DX

学习啦在线学习网   JZ NORNDUP

  INC AX ;Round up if any remainder

学习啦在线学习网   NORNDUP:

学习啦在线学习网   MOV [VALSEC],AX ;Number of sectors that have been written

  POP AX

学习啦在线学习网   MOV CX,[CLUSNUM] ;First cluster accessed

  CALL FNDCLUS

  MOV [CLUSNUM],BX

学习啦在线学习网   MOV [LASTPOS],DX

  SUB AX,DX ;Last cluster minus current cluster

  JZ DOWRT ;If we have last clus, we must have first

  JCXZ HAVSTART ;See if no more data

  PUSH CX ;No. of clusters short of first

  MOV CX,AX

  CALL ALLOCATE

  POP AX

  JC WRTERR

  MOV CX,AX

  MOV DX,[LASTPOS]

  INC DX

  DEC CX

学习啦在线学习网   JZ NOSKIP

学习啦在线学习网   CALL SKPCLP

  NOSKIP:

学习啦在线学习网   MOV [CLUSNUM],BX

  MOV [LASTPOS],DX

  DOWRT:

  CMP [BYTCNT1],0

学习啦在线学习网   JZ WRTMID

  MOV BX,[CLUSNUM]

学习啦在线学习网   CALL BUFWRT

  WRTMID:

  MOV AX,[SECCNT]

  OR AX,AX

学习啦在线学习网   JZ WRTLAST

  ADD [SECPOS],AX

  CALL NEXTSEC

学习啦在线学习网   MOV BYTE PTR [TRANS],1 ;A transfer is taking place

学习啦在线学习网   MOV DL,[SECCLUSPOS]

学习啦在线学习网   MOV BX,[CLUSNUM]

  MOV CX,[SECCNT]

  WRTLP:

学习啦在线学习网   CALL OPTIMIZE

学习啦在线学习网   JC NOTINBUF ;Is one of the sectors buffered?

  MOV [BUFSECNO],0 ;If so, invalidate the buffer since we're

  MOV WORD PTR [BUFDRVNO],0FFH ; completely rewritting it

学习啦在线学习网   NOTINBUF:

  PUSH DI

  PUSH AX

  PUSH DS

  MOV DS,[DMAADD+2]

  CALL DWRITE

  POP DS

  POP CX

  POP BX

学习啦在线学习网   JCXZ WRTLAST

  MOV DL,0

  INC [LASTPOS] ;We'll be using next cluster

  JMP SHORT WRTLP

  WRTLAST:

学习啦在线学习网   MOV AX,[BYTCNT2]

  OR AX,AX

学习啦在线学习网   JZ FINWRT

  MOV [BYTCNT1],AX

  CALL NEXTSEC

学习啦在线学习网   MOV [BYTSECPOS],0

学习啦在线学习网   CALL BUFWRT

  FINWRT:

学习啦在线学习网   MOV AX,[NEXTADD]

学习啦在线学习网   SUB AX,[DMAADD]

  ADD AX,WORD PTR [BYTPOS]

学习啦在线学习网   MOV DX,WORD PTR [BYTPOS+2]

学习啦在线学习网   ADC DX,0

学习啦在线学习网   MOV CX,DX

  MOV DI,[FCB]

学习啦在线学习网   CMP AX,ES:WORD PTR [DI.FILSIZ]

学习啦在线学习网   SBB CX,ES:WORD PTR [DI.FILSIZ+2]

  JB SAMSIZ

学习啦在线学习网   MOV ES:WORD PTR [DI.FILSIZ],AX

学习啦在线学习网   MOV ES:WORD PTR [DI.FILSIZ+2],DX

  SAMSIZ:

  MOV CX,[RECCNT]

  JMP SETCLUS

  WRTERRJ:JMP WRTERR

  WRTEOF:

学习啦在线学习网   MOV CX,AX

学习啦在线学习网   OR CX,DX

  JZ KILLFIL

  SUB AX,1

  SBB DX,0

  DIV [BP.SECSIZ]

  MOV CL,[BP.CLUSSHFT]

学习啦在线学习网   SHR AX,CL

  MOV CX,AX

  CALL FNDCLUS

  JCXZ RELFILE

  CALL ALLOCATE

学习啦在线学习网   JC WRTERRJ

  UPDATE:

  MOV DI,[FCB]

  MOV AX,WORD PTR [BYTPOS]

  MOV ES:WORD PTR [DI.FILSIZ],AX

学习啦在线学习网   MOV AX,WORD PTR [BYTPOS+2]

学习啦在线学习网   MOV ES:WORD PTR [DI.FILSIZ+2],AX

学习啦在线学习网   XOR CX,CX

  JMP ADDREC

学习啦在线学习网   RELFILE:

学习啦在线学习网   MOV DX,0FFFH

学习啦在线学习网   CALL RELBLKS

  SETDIRT:

  MOV BYTE PTR [SI-1],1

  JMP SHORT UPDATE

学习啦在线学习网   KILLFIL:

学习啦在线学习网   XOR BX,BX

学习啦在线学习网   XCHG BX,ES:[DI.FIRCLUS]

学习啦在线学习网   OR BX,BX

  JZ UPDATE

学习啦在线学习网   CALL RELEASE

学习啦在线学习网   JMP SHORT SETDIRT

  OPTIMIZE:

  ; Inputs:

  ; DS = CS

学习啦在线学习网   ; BX = Physical cluster

学习啦在线学习网   ; CX = No. of records

  ; DL = sector within cluster

  ; BP = Base of drives parameters

  ; [NEXTADD] = transfer address

  ; Outputs:

学习啦在线学习网   ; AX = No. of records remaining

学习啦在线学习网   ; BX = Transfer address

学习啦在线学习网   ; CX = No. or records to be transferred

  ; DX = Physical sector address

  ; DI = Next cluster

  ; Carry clear if a sector to transfer is in the buffer

  ; Carry set otherwise

  ; [CLUSNUM] = Last cluster accessed

学习啦在线学习网   ; [NEXTADD] updated

学习啦在线学习网   ; BP unchanged. Note that segment of transfer not set.

  PUSH DX

  PUSH BX

  MOV AL,[BP.CLUSMSK]

  INC AL ;Number of sectors per cluster

  MOV AH,AL

  SUB AL,DL ;AL = Number of sectors left in first cluster

学习啦在线学习网   MOV DX,CX

学习啦在线学习网   MOV SI,[BP.FAT]

  MOV CX,0

学习啦在线学习网   OPTCLUS:

  ;AL has number of sectors available in current cluster

  ;AH has number of sectors available in next cluster

学习啦在线学习网   ;BX has current physical cluster

学习啦在线学习网   ;CX has number of sequential sectors found so far

  ;DX has number of sectors left to transfer

  ;SI has FAT pointer

  CALL UNPACK

  ADD CL,AL

  ADC CH,0

学习啦在线学习网   CMP CX,DX

学习啦在线学习网   JAE BLKDON

  MOV AL,AH

  INC BX

  CMP DI,BX

  JZ OPTCLUS

  DEC BX

学习啦在线学习网   FINCLUS:

  MOV [CLUSNUM],BX ;Last cluster accessed

  SUB DX,CX ;Number of sectors still needed

  PUSH DX

  MOV AX,CX

  MUL [BP.SECSIZ] ;Number of sectors times sector size

  MOV SI,[NEXTADD]

  ADD AX,SI ;Adjust by size of transfer

  MOV [NEXTADD],AX

  POP AX ;Number of sectors still needed

  POP DX ;Starting cluster

学习啦在线学习网   SUB BX,DX ;Number of new clusters accessed

  ADD [LASTPOS],BX

学习啦在线学习网   POP BX ;BL = sector postion within cluster

  CALL FIGREC

  MOV BX,SI

学习啦在线学习网   ;Now let's see if any of these sectors are already in the buffer

学习啦在线学习网   CMP [BUFSECNO],DX

学习啦在线学习网   JC RET100 ;If DX > [BUFSECNO] then not in buffer

学习啦在线学习网   MOV SI,DX

学习啦在线学习网   ADD SI,CX ;Last sector + 1

  CMP [BUFSECNO],SI

  CMC

  JC RET100 ;If SI <= [BUFSECNO] then not in buffer

  PUSH AX

学习啦在线学习网   MOV AL,[BP.DEVNUM]

  CMP AL,[BUFDRVNO] ;Is buffer for this drive?

  POP AX

学习啦在线学习网   JZ RET100 ;If so, then we match

学习啦在线学习网   STC ;No match

学习啦在线学习网   RET100: RET

  BLKDON:

学习啦在线学习网   SUB CX,DX ;Number of sectors in cluster we don't want

  SUB AH,CL ;Number of sectors in cluster we accepted

学习啦在线学习网   DEC AH ;Adjust to mean position within cluster

  MOV [SECCLUSPOS],AH

  MOV CX,DX ;Anyway, make the total equal to the request

  JMP SHORT FINCLUS

  FIGREC:

  ;Inputs:

  ; DX = Physical cluster number

  ; BL = Sector postion within cluster

  ; BP = Base of drive parameters

学习啦在线学习网   ;Outputs:

  ; DX = physical sector number

学习啦在线学习网   ;No other registers affected.

  PUSH CX

学习啦在线学习网   MOV CL,[BP.CLUSSHFT]

  DEC DX

  DEC DX

  SHL DX,CL

  OR DL,BL

学习啦在线学习网   ADD DX,[BP.FIRREC]

  POP CX

  RET

  GETREC:

  ; Inputs:

学习啦在线学习网   ; DS:DX point to FCB

学习啦在线学习网   ; Outputs:

  ; CX = 1

学习啦在线学习网   ; DX:AX = Record number determined by EXTENT and NR fields

  ; DS:DI point to FCB

学习啦在线学习网   ; No other registers affected.

学习啦在线学习网   MOV DI,DX

学习啦在线学习网   CMP BYTE PTR [DI],-1 ;Check for extended FCB

  JNZ NORMFCB2

  ADD DI,7

  NORMFCB2:

  MOV CX,1

  MOV AL,[DI.NR]

  MOV DX,[DI.EXTENT]

  SHL AL,1

  SHR DX,1

学习啦在线学习网   RCR AL,1

  MOV AH,DL

  MOV DL,DH

学习啦在线学习网   MOV DH,0

  RET

  ALLOCATE:

  ; Inputs:

  ; DS = CS

  ; ES = Segment of FCB

学习啦在线学习网   ; BX = Last cluster of file (0 if null file)

  ; CX = No. of clusters to allocate

  ; DX = Position of cluster BX

学习啦在线学习网   ; BP = Base of drive parameters

  ; SI = FAT pointer

  ; [FCB] = Displacement of FCB within segment

  ; Outputs:

  ; IF insufficient space

  ; THEN

  ; Carry set

  ; CX = max. no. of records that could be added to file

  ; ELSE

  ; Carry clear

学习啦在线学习网   ; BX = First cluster allocated

  ; FAT is fully updated including dirty bit

学习啦在线学习网   ; FIRCLUS field of FCB set if file was null

学习啦在线学习网   ; SI,BP unchanged. All other registers destroyed.

学习啦在线学习网   PUSH [SI]

  PUSH DX

  PUSH CX

  PUSH BX

  MOV AX,BX

  ALLOC:

学习啦在线学习网   MOV DX,BX

  FINDFRE:

  INC BX

  CMP BX,[BP.MAXCLUS]

学习啦在线学习网   JLE TRYOUT

学习啦在线学习网   CMP AX,1

学习啦在线学习网   JG TRYIN

  POP BX

  MOV DX,0FFFH

学习啦在线学习网   CALL RELBLKS

  POP AX ;No. of clusters requested

  SUB AX,CX ;AX=No. of clusters allocated

  POP DX

学习啦在线学习网   POP [SI]

  INC DX ;Position of first cluster allocated

  ADD AX,DX ;AX=max no. of cluster in file

  MOV DL,[BP.CLUSMSK]

  MOV DH,0

  INC DX ;DX=records/cluster

  MUL DX ;AX=max no. of records in file

  MOV CX,AX

学习啦在线学习网   SUB CX,WORD PTR [RECPOS] ;CX=max no. of records that could be written

学习啦在线学习网   JA MAXREC

学习啦在线学习网   XOR CX,CX ;If CX was negative, zero it

  MAXREC:

  STC

  RET11: RET

  TRYOUT:

  CALL UNPACK

学习啦在线学习网   JZ HAVFRE

  TRYIN:

  DEC AX

学习啦在线学习网   JLE FINDFRE

学习啦在线学习网   XCHG AX,BX

  CALL UNPACK

  JZ HAVFRE

学习啦在线学习网   XCHG AX,BX

学习啦在线学习网   JMP SHORT FINDFRE

  HAVFRE:

  XCHG BX,DX

学习啦在线学习网   MOV AX,DX

学习啦在线学习网   CALL PACK

  MOV BX,AX

  LOOP ALLOC

学习啦在线学习网   MOV DX,0FFFH

  CALL PACK

  MOV BYTE PTR [SI-1],1

  POP BX

  POP CX ;Don't need this stuff since we're successful

  POP DX

  CALL UNPACK

  POP [SI]

学习啦在线学习网   XCHG BX,DI

  OR DI,DI

  JNZ RET11

  MOV DI,[FCB]

  MOV ES:[DI.FIRCLUS],BX

  RET12: RET

学习啦在线学习网   RELEASE:

  ; Inputs:

学习啦在线学习网   ; DS = CS

学习啦在线学习网   ; BX = Cluster in file

学习啦在线学习网   ; SI = FAT pointer

学习啦在线学习网   ; BP = Base of drive parameters

  ; Function:

  ; Frees cluster chain starting with [BX]

学习啦在线学习网   ; AX,BX,DX,DI all destroyed. Other registers unchanged.

  XOR DX,DX

  RELBLKS:

  ; Enter here with DX=0FFFH to put an end-of-file mark

  ; in the first cluster and free the rest in the chain.

  CALL UNPACK

学习啦在线学习网   JZ RET12

  MOV AX,DI

  CALL PACK

  CMP AX,0FF8H

  MOV BX,AX

  JB RELEASE

  RET13: RET

  GETEOF:

  ; Inputs:

学习啦在线学习网   ; BX = Cluster in a file

  ; SI = Base of drive FAT

学习啦在线学习网   ; DS = CS

  ; Outputs:

  ; BX = Last cluster in the file

  ; DI destroyed. No other registers affected.

  CALL UNPACK

学习啦在线学习网   CMP DI,0FF8H

  JAE RET13

  MOV BX,DI

  JMP SHORT GETEOF

  SRCHFRST: ;System call 17

  CALL GETFILE

学习啦在线学习网   SAVPLCE:

  ; Search-for-next enters here to save place and report

学习啦在线学习网   ; findings.

  JC KILLSRCH

  OR BH,BH

学习啦在线学习网   JS SRCHDEV

  MOV AX,[LASTENT]

学习啦在线学习网   MOV ES:[DI.FILDIRENT],AX

  MOV ES:[DI.DRVBP],BP

  ;Information in directory entry must be copied into the first

学习啦在线学习网   ; 33 bytes starting at the disk transfer address.

学习啦在线学习网   MOV SI,BX

学习啦在线学习网   LES DI,DWORD PTR [DMAADD]

  MOV AX,00FFH

  CMP AL,[EXTFCB]

学习啦在线学习网   JNZ NORMFCB

  STOSW

  INC AL

  STOSW

  STOSW

  MOV AL,[ATTRIB]

  STOSB

学习啦在线学习网   NORMFCB:

  MOV AL,[THISDRV]

  INC AL

  STOSB ;Set drive number

学习啦在线学习网   MOV CX,16

学习啦在线学习网   REP MOVSW ;Copy remaining 10 characters of name

学习啦在线学习网   XOR AL,AL

  RET

学习啦在线学习网   KILLSRCH:

  KILLSRCH1 EQU KILLSRCH+1

学习啦在线学习网   ;The purpose of the KILLSRCH1 label is to provide a jump label to the following

学习啦在线学习网   ; instruction which leaves out the segment override.

  MOV WORD PTR ES:[DI.FILDIRENT],-1

学习啦在线学习网   MOV AL,-1

  RET

学习啦在线学习网   SRCHDEV:

  MOV ES:[DI.FILDIRENT],BX

学习啦在线学习网   LES DI,DWORD PTR [DMAADD]

  XOR AX,AX

学习啦在线学习网   STOSB ;Zero drive byte

学习啦在线学习网   SUB SI,4 ;Point to device name

  MOVSW

  MOVSW

  MOV AX,2020H

  STOSB

  STOSW

  STOSW

  STOSW ;Fill with 8 blanks

学习啦在线学习网   XOR AX,AX

  MOV CX,10

学习啦在线学习网   REP STOSW

  STOSB

  RET14: RET

学习啦在线学习网   SRCHNXT: ;System call 18

  CALL MOVNAME

学习啦在线学习网   MOV DI,DX

  JC NEAR PTR KILLSRCH1

  MOV BP,[DI.DRVBP]

学习啦在线学习网   MOV AX,[DI.FILDIRENT]

学习啦在线学习网   OR AX,AX

学习啦在线学习网   JS NEAR PTR KILLSRCH1

  PUSH DX

  PUSH DS

  PUSH CS

  POP DS

  MOV [LASTENT],AX

  CALL CONTSRCH

  POP ES

  POP DI

  JMP SAVPLCE

  FILESIZE: ;System call 35

  CALL GETFILE

  MOV AL,-1

学习啦在线学习网   JC RET14

  ADD DI,33 ;Write size in RR field

  MOV CX,ES:[DI.RECSIZ-33]

  OR CX,CX

学习啦在线学习网   JNZ RECOK

  MOV CX,128

  RECOK:

  XOR AX,AX

学习啦在线学习网   XOR DX,DX ;Intialize size to zero

  OR BH,BH ;Check for named I/O device

学习啦在线学习网   JS DEVSIZ

  INC SI

  INC SI ;Point to length field

  MOV AX,[SI+2] ;Get high word of size

  DIV CX

  PUSH AX ;Save high part of result

  LODSW ;Get low word of size

  DIV CX

  OR DX,DX ;Check for zero remainder

  POP DX

  JZ DEVSIZ

学习啦在线学习网   INC AX ;Round up for partial record

  JNZ DEVSIZ ;Propagate carry?

  INC DX

  DEVSIZ:

  STOSW

学习啦在线学习网   MOV AX,DX

  STOSB

  MOV AL,0

  CMP CX,64

  JAE RET14 ;Only 3-byte field if RECSIZ >= 64

学习啦在线学习网   MOV ES:[DI],AH

  RET

  SETDMA: ;System call 26

学习啦在线学习网   MOV CS:[DMAADD],DX

  MOV CS:[DMAADD+2],DS

  RET

  NOSUCHDRV:

学习啦在线学习网   MOV AL,-1

  RET

  GETFATPT: ;System call 27

  MOV DL,0 ;Use default drive

  GETFATPTDL: ;System call 28

  PUSH CS

  POP DS

  MOV AL,DL

  CALL GETTHISDRV

学习啦在线学习网   JC NOSUCHDRV

  CALL FATREAD

学习啦在线学习网   MOV BX,[BP.FAT]

  MOV AL,[BP.CLUSMSK]

  INC AL

学习啦在线学习网   MOV DX,[BP.MAXCLUS]

  DEC DX

  MOV CX,[BP.SECSIZ]

  LDS SI,DWORD PTR [SPSAVE]

  MOV [SI.BXSAVE],BX

  MOV [SI.DXSAVE],DX

学习啦在线学习网   MOV [SI.CXSAVE],CX

学习啦在线学习网   MOV [SI.DSSAVE],CS

  RET

学习啦在线学习网   GETDSKPT: ;System call 31

  PUSH CS

  POP DS

  MOV AL,[CURDRV]

  MOV [THISDRV],AL

  CALL FATREAD

学习啦在线学习网   LDS SI,DWORD PTR [SPSAVE]

学习啦在线学习网   MOV [SI.BXSAVE],BP

学习啦在线学习网   MOV [SI.DSSAVE],CS

  RET

学习啦在线学习网   DSKRESET: ;System call 13

  PUSH CS

  POP DS

  WRTFATS:

学习啦在线学习网   ; DS=CS. Writes back all dirty FATs. All registers destroyed.

学习啦在线学习网   XOR AL,AL

学习啦在线学习网   XCHG AL,[DIRTYBUF]

学习啦在线学习网   OR AL,AL

学习啦在线学习网   JZ NOBUF

  MOV BP,[BUFDRVBP]

学习啦在线学习网   MOV DX,[BUFSECNO]

  MOV BX,[BUFFER]

  MOV CX,1

  CALL DWRITE

  NOBUF:

学习啦在线学习网   MOV CL,[NUMIO]

  MOV CH,0

学习啦在线学习网   MOV BP,[DRVTAB]

  WRTFAT:

  PUSH CX

  CALL CHKFATWRT

  POP CX

  ADD BP,DPBSIZ

  LOOP WRTFAT

  RET

学习啦在线学习网   GETDRV: ;System call 25

  MOV AL,CS:[CURDRV]

学习啦在线学习网   RET15: RET

学习啦在线学习网   SETRNDREC: ;System call 36

  CALL GETREC

  MOV [DI+33],AX

学习啦在线学习网   MOV [DI+35],DL

  CMP [DI.RECSIZ],64

学习啦在线学习网   JAE RET15

  MOV [DI+36],DH ;Set 4th byte only if record size < 64

  RET16: RET

学习啦在线学习网   SELDSK: ;System call 14

  MOV AL,CS:[NUMDRV]

  CMP DL,AL

学习啦在线学习网   JNB RET17

学习啦在线学习网   MOV CS:[CURDRV],DL

学习啦在线学习网   RET17: RET

学习啦在线学习网   BUFIN: ;System call 10

  MOV AX,CS

  MOV ES,AX

学习啦在线学习网   MOV SI,DX

  MOV CH,0

  LODSW

  OR AL,AL

学习啦在线学习网   JZ RET17

学习啦在线学习网   MOV BL,AH

  MOV BH,CH

学习啦在线学习网   CMP AL,BL

  JBE NOEDIT

  CMP BYTE PTR [BX+SI],0DH

  JZ EDITON

  NOEDIT:

学习啦在线学习网   MOV BL,CH

  EDITON:

学习啦在线学习网   MOV DL,AL

  DEC DX

  NEWLIN:

  MOV AL,CS:[CARPOS]

  MOV CS:[STARTPOS],AL

  PUSH SI

  MOV DI,OFFSET DOSGROUP:INBUF

  MOV AH,CH

学习啦在线学习网   MOV BH,CH

  MOV DH,CH

  GETCH:

  CALL IN

  CMP AL,"F"-"@" ;Ignore ^F

学习啦在线学习网   JZ GETCH

  CMP AL,CS:ESCCHAR

  JZ ESC

学习啦在线学习网   CMP AL,7FH

  JZ BACKSP

  CMP AL,8

  JZ BACKSP

  CMP AL,13

  JZ ENDLIN

  CMP AL,10

  JZ PHYCRLF

  CMP AL,CANCEL

  JZ KILNEW

  SAVCH:

  CMP DH,DL

学习啦在线学习网   JAE BUFFUL

  STOSB

  INC DH

学习啦在线学习网   CALL BUFOUT

  OR AH,AH

学习啦在线学习网   JNZ GETCH

  CMP BH,BL

  JAE GETCH

  INC SI

  INC BH

学习啦在线学习网   JMP SHORT GETCH

  BUFFUL:

  MOV AL,7

  CALL OUT

  JMP SHORT GETCH

  ESC:

  CALL IN

  MOV CL,ESCTABLEN

  PUSH DI

  MOV DI,OFFSET DOSGROUP:ESCTAB

学习啦在线学习网   REPNE SCASB

  POP DI

  SHL CX,1

学习啦在线学习网   MOV BP,CX

学习啦在线学习网   JMP [BP+OFFSET DOSGROUP:ESCFUNC]

  ENDLIN:

  STOSB

  CALL OUT

  POP DI

学习啦在线学习网   MOV [DI-1],DH

  INC DH

学习啦在线学习网   COPYNEW:

  MOV BP,ES

学习啦在线学习网   MOV BX,DS

  MOV ES,BX

  MOV DS,BP

  MOV SI,OFFSET DOSGROUP:INBUF

  MOV CL,DH

学习啦在线学习网   REP MOVSB

  RET

  CRLF:

  MOV AL,13

  CALL OUT

学习啦在线学习网   MOV AL,10

  JMP OUT

  PHYCRLF:

  CALL CRLF

学习啦在线学习网   JMP SHORT GETCH

  KILNEW:

学习啦在线学习网   MOV AL,"\"

学习啦在线学习网   CALL OUT

  POP SI

  PUTNEW:

学习啦在线学习网   CALL CRLF

  MOV AL,CS:[STARTPOS]

  CALL TAB

  JMP NEWLIN

  BACKSP:

  OR DH,DH

  JZ OLDBAK

  CALL BACKUP

学习啦在线学习网   MOV AL,ES:[DI]

  CMP AL," "

学习啦在线学习网   JAE OLDBAK

学习啦在线学习网   CMP AL,9

学习啦在线学习网   JZ BAKTAB

  CALL BACKMES

  OLDBAK:

学习啦在线学习网   OR AH,AH

  JNZ GETCH1

  OR BH,BH

学习啦在线学习网   JZ GETCH1

  DEC BH

  DEC SI

  GETCH1:

学习啦在线学习网   JMP GETCH

  BAKTAB:

  PUSH DI

  DEC DI

  STD

学习啦在线学习网   MOV CL,DH

学习啦在线学习网   MOV AL," "

  PUSH BX

学习啦在线学习网   MOV BL,7

学习啦在线学习网   JCXZ FIGTAB

  FNDPOS:

  SCASB

学习啦在线学习网   JNA CHKCNT

  CMP ES:BYTE PTR [DI+1],9

  JZ HAVTAB

  DEC BL

  CHKCNT:

学习啦在线学习网   LOOP FNDPOS

  FIGTAB:

学习啦在线学习网   SUB BL,CS:[STARTPOS]

  HAVTAB:

学习啦在线学习网   SUB BL,DH

  ADD CL,BL

  AND CL,7

  CLD

  POP BX

  POP DI

学习啦在线学习网   JZ OLDBAK

  TABBAK:

  CALL BACKMES

  LOOP TABBAK

学习啦在线学习网   JMP SHORT OLDBAK

  BACKUP:

  DEC DH

  DEC DI

  BACKMES:

  MOV AL,8

学习啦在线学习网   CALL OUT

  MOV AL," "

  CALL OUT

  MOV AL,8

  JMP OUT

  TWOESC:

  MOV AL,ESCCH

学习啦在线学习网   JMP SAVCH

  COPYLIN:

  MOV CL,BL

  SUB CL,BH

学习啦在线学习网   JMP SHORT COPYEACH

学习啦在线学习网   COPYSTR:

学习啦在线学习网   CALL FINDOLD

  JMP SHORT COPYEACH

  COPYONE:

  MOV CL,1

  COPYEACH:

  MOV AH,0

学习啦在线学习网   CMP DH,DL

  JZ GETCH2

学习啦在线学习网   CMP BH,BL

  JZ GETCH2

  LODSB

  STOSB

  CALL BUFOUT

  INC BH

  INC DH

  LOOP COPYEACH

  GETCH2:

  JMP GETCH

  SKIPONE:

  CMP BH,BL

  JZ GETCH2

  INC BH

  INC SI

  JMP GETCH

  SKIPSTR:

学习啦在线学习网   CALL FINDOLD

学习啦在线学习网   ADD SI,CX

学习啦在线学习网   ADD BH,CL

学习啦在线学习网   JMP GETCH

学习啦在线学习网   FINDOLD:

  CALL IN

  MOV CL,BL

  SUB CL,BH

学习啦在线学习网   JZ NOTFND

  DEC CX

  JZ NOTFND

  PUSH ES

  PUSH DS

  POP ES

  PUSH DI

学习啦在线学习网   MOV DI,SI

  INC DI

学习啦在线学习网   REPNE SCASB

  POP DI

  POP ES

  JNZ NOTFND

  NOT CL

学习啦在线学习网   ADD CL,BL

  SUB CL,BH

  RET30: RET

  NOTFND:

  POP BP

学习啦在线学习网   JMP GETCH

  REEDIT:

学习啦在线学习网   MOV AL,"@"

学习啦在线学习网   CALL OUT

  POP DI

  PUSH DI

  PUSH ES

  PUSH DS

学习啦在线学习网   CALL COPYNEW

  POP DS

  POP ES

  POP SI

学习啦在线学习网   MOV BL,DH

  JMP PUTNEW

  ENTERINS:

学习啦在线学习网   IF TOGLINS

  NOT AH

  JMP GETCH

  ENDIF

  IF NOT TOGLINS

学习啦在线学习网   MOV AH,-1

  JMP GETCH

学习啦在线学习网   EXITINS:

  MOV AH,0

学习啦在线学习网   JMP GETCH

  ENDIF

学习啦在线学习网   ESCFUNC DW GETCH

  DW TWOESC

学习啦在线学习网   IF NOT TOGLINS

  DW EXITINS

  ENDIF

  DW ENTERINS

学习啦在线学习网   DW BACKSP

  DW REEDIT

  DW KILNEW

学习啦在线学习网   DW COPYLIN

  DW SKIPSTR

学习啦在线学习网   DW COPYSTR

学习啦在线学习网   DW SKIPONE

  DW COPYONE

  IF IBM

  DW COPYONE

  DW CTRLZ

  CTRLZ:

  MOV AL,"Z"-"@"

  JMP SAVCH

  ENDIF

  BUFOUT:

学习啦在线学习网   CMP AL," "

  JAE OUT

  CMP AL,9

  JZ OUT

  PUSH AX

学习啦在线学习网   MOV AL,"^"

  CALL OUT

  POP AX

学习啦在线学习网   OR AL,40H

学习啦在线学习网   JMP SHORT OUT

  NOSTOP:

  CMP AL,"P"-"@"

学习啦在线学习网   JZ INCHK

学习啦在线学习网   IF NOT TOGLPRN

学习啦在线学习网   CMP AL,"N"-"@"

学习啦在线学习网   JZ INCHK

  ENDIF

学习啦在线学习网   CMP AL,"C"-"@"

  JZ INCHK

  RET

  CONOUT: ;System call 2

学习啦在线学习网   MOV AL,DL

  OUT:

学习啦在线学习网   CMP AL,20H

学习啦在线学习网   JB CTRLOUT

学习啦在线学习网   CMP AL,7FH

  JZ OUTCH

  INC CS:BYTE PTR [CARPOS]

  OUTCH:

  PUSH AX

  CALL STATCHK

  POP AX

  CALL FAR PTR BIOSOUT

  TEST CS:BYTE PTR [PFLAG],-1

学习啦在线学习网   JZ RET18

学习啦在线学习网   CALL FAR PTR BIOSPRINT

  RET18: RET

学习啦在线学习网   STATCHK:

  CALL FAR PTR BIOSSTAT

  JZ RET18

  CMP AL,'S'-'@'

  JNZ NOSTOP

学习啦在线学习网   CALL FAR PTR BIOSIN ;Eat Cntrl-S

  INCHK:

学习啦在线学习网   CALL FAR PTR BIOSIN

学习啦在线学习网   CMP AL,'P'-'@'

学习啦在线学习网   JZ PRINTON

  IF NOT TOGLPRN

学习啦在线学习网   CMP AL,'N'-'@'

  JZ PRINTOFF

  ENDIF

  CMP AL,'C'-'@'

  JNZ RET18

学习啦在线学习网   ; Ctrl-C handler.

  ; "^C" and CR/LF is printed. Then the user registers are restored and the

  ; user CTRL-C handler is executed. At this point the top of the stack has

  ; 1) the interrupt return address should the user CTRL-C handler wish to

  ; allow processing to continue; 2) the original interrupt return address

学习啦在线学习网   ; to the code that performed the function call in the first place. If the

  ; user CTRL-C handler wishes to continue, it must leave all registers

  ; unchanged and IRET. The function that was interrupted will simply be

学习啦在线学习网   ; repeated.

  MOV AL,3 ;Display "^C"

  CALL BUFOUT

  CALL CRLF

  CLI ;Prepare to play with stack

学习啦在线学习网   MOV SS,CS:[SSSAVE]

  MOV SP,CS:[SPSAVE] ;User stack now restored

  POP AX

  POP BX

  POP CX

  POP DX

  POP SI

  POP DI

  POP BP

  POP DS

学习啦在线学习网   POP ES ;User registers now restored

学习啦在线学习网   INT CONTC ;Execute user Ctrl-C handler

学习啦在线学习网   JMP COMMAND ;Repeat command otherwise

学习啦在线学习网   PRINTON:

学习啦在线学习网   IF TOGLPRN

学习啦在线学习网   NOT CS:BYTE PTR [PFLAG]

  RET

  ENDIF

学习啦在线学习网   IF NOT TOGLPRN

  MOV CS:BYTE PTR [PFLAG],1

  RET

  PRINTOFF:

学习啦在线学习网   MOV CS:BYTE PTR [PFLAG],0

  RET

  ENDIF

  CTRLOUT:

学习啦在线学习网   CMP AL,13

  JZ ZERPOS

  CMP AL,8

学习啦在线学习网   JZ BACKPOS

学习啦在线学习网   CMP AL,9

  JNZ OUTCHJ

学习啦在线学习网   MOV AL,CS:[CARPOS]

  OR AL,0F8H

  NEG AL

  TAB:

  PUSH CX

学习啦在线学习网   MOV CL,AL

学习啦在线学习网   MOV CH,0

  JCXZ POPTAB

  TABLP:

学习啦在线学习网   MOV AL," "

  CALL OUT

  LOOP TABLP

  POPTAB:

  POP CX

学习啦在线学习网   RET19: RET

  ZERPOS:

学习啦在线学习网   MOV CS:BYTE PTR [CARPOS],0

学习啦在线学习网   OUTCHJ: JMP OUTCH

  BACKPOS:

  DEC CS:BYTE PTR [CARPOS]

  JMP OUTCH

  CONSTAT: ;System call 11

  CALL STATCHK

  MOV AL,0

  JZ RET19

  OR AL,-1

  RET

  CONIN: ;System call 1

  CALL IN

  PUSH AX

  CALL OUT

  POP AX

  RET

  IN: ;System call 8

  CALL INCHK

  JZ IN

  RET29: RET

学习啦在线学习网   RAWIO: ;System call 6

学习啦在线学习网   MOV AL,DL

学习啦在线学习网   CMP AL,-1

  JNZ RAWOUT

  LDS SI,DWORD PTR CS:[SPSAVE] ;Get pointer to register save area

  CALL FAR PTR BIOSSTAT

学习啦在线学习网   JNZ RESFLG

  OR BYTE PTR [SI.FSAVE],40H ;Set user's zero flag

学习啦在线学习网   XOR AL,AL

  RET

  RESFLG:

学习啦在线学习网   AND BYTE PTR [SI.FSAVE],0FFH-40H ;Reset user's zero flag

  RAWINP: ;System call 7

  CALL FAR PTR BIOSIN

  RET

  RAWOUT:

学习啦在线学习网   CALL FAR PTR BIOSOUT

  RET

  LIST: ;System call 5

学习啦在线学习网   MOV AL,DL

学习啦在线学习网   LISTOUT:

  PUSH AX

  CALL STATCHK

  POP AX

  CALL FAR PTR BIOSPRINT

学习啦在线学习网   RET20: RET

学习啦在线学习网   PRTBUF: ;System call 9

  MOV SI,DX

  OUTSTR:

  LODSB

  CMP AL,"$"

  JZ RET20

学习啦在线学习网   CALL OUT

学习啦在线学习网   JMP SHORT OUTSTR

  OUTMES: ;String output for internal messages

  LODS CS:BYTE PTR [SI]

  CMP AL,"$"

学习啦在线学习网   JZ RET20

  CALL OUT

学习啦在线学习网   JMP SHORT OUTMES

  MAKEFCB: ;Interrupt call 41

学习啦在线学习网   DRVBIT EQU 2

  NAMBIT EQU 4

  EXTBIT EQU 8

  MOV DL,0 ;Flag--not ambiguous file name

  TEST AL,DRVBIT ;Use current drive field if default?

学习啦在线学习网   JNZ DEFDRV

  MOV BYTE PTR ES:[DI],0 ;No - use default drive

  DEFDRV:

  INC DI

学习啦在线学习网   MOV CX,8

学习啦在线学习网   TEST AL,NAMBIT ;Use current name fiels as defualt?

学习啦在线学习网   XCHG AX,BX ;Save bits in BX

学习啦在线学习网   MOV AL," "

  JZ FILLB ;If not, go fill with blanks

学习啦在线学习网   ADD DI,CX

  XOR CX,CX ;Don't fill any

  FILLB:

  REP STOSB

  MOV CL,3

  TEST BL,EXTBIT ;Use current extension as default

学习啦在线学习网   JZ FILLB2

  ADD DI,CX

  XOR CX,CX

  FILLB2:

  REP STOSB

学习啦在线学习网   XCHG AX,CX ;Put zero in AX

  STOSW

学习啦在线学习网   STOSW ;Initialize two words after to zero

  SUB DI,16 ;Point back at start

学习啦在线学习网   TEST BL,1 ;Scan off separators if not zero

学习啦在线学习网   JZ SKPSPC

学习啦在线学习网   CALL SCANB ;Peel off blanks and tabs

  CALL DELIM ;Is it a one-time-only delimiter?

学习啦在线学习网   JNZ NOSCAN

  INC SI ;Skip over the delimiter

  SKPSPC:

学习啦在线学习网   CALL SCANB ;Always kill preceding blanks and tabs

  NOSCAN:

学习啦在线学习网   CALL GETLET

  JBE NODRV ;Quit if termination character

  CMP BYTE PTR[SI],":" ;Check for potential drive specifier

  JNZ NODRV

学习啦在线学习网   INC SI ;Skip over colon

  SUB AL,"@" ;Convert drive letter to binary drive number

  JBE BADDRV ;Valid drive numbers are 1-15

学习啦在线学习网   CMP AL,CS:[NUMDRV]

  JBE HAVDRV

  BADDRV:

  MOV DL,-1

  HAVDRV:

  STOSB ;Put drive specifier in first byte

  INC SI

  DEC DI ;Counteract next two instructions

  NODRV:

  DEC SI ;Back up

  INC DI ;Skip drive byte

学习啦在线学习网   MOV CX,8

  CALL GETWORD ;Get 8-letter file name

  CMP BYTE PTR [SI],"."

  JNZ NODOT

学习啦在线学习网   INC SI ;Skip over dot if present

  MOV CX,3 ;Get 3-letter extension

学习啦在线学习网   CALL MUSTGETWORD

  NODOT:

  LDS BX,CS:DWORD PTR [SPSAVE]

  MOV [BX.SISAVE],SI

  MOV AL,DL

  RET

  NONAM:

学习啦在线学习网   ADD DI,CX

  DEC SI

  RET

学习啦在线学习网   GETWORD:

  CALL GETLET

  JBE NONAM ;Exit if invalid character

  DEC SI

  MUSTGETWORD:

学习啦在线学习网   CALL GETLET

  JBE FILLNAM

学习啦在线学习网   JCXZ MUSTGETWORD

  DEC CX

  CMP AL,"*" ;Check for ambiguous file specifier

学习啦在线学习网   JNZ NOSTAR

  MOV AL,"?"

学习啦在线学习网   REP STOSB

  NOSTAR:

  STOSB

  CMP AL,"?"

学习啦在线学习网   JNZ MUSTGETWORD

学习啦在线学习网   OR DL,1 ;Flag ambiguous file name

学习啦在线学习网   JMP MUSTGETWORD

  FILLNAM:

  MOV AL," "

学习啦在线学习网   REP STOSB

  DEC SI

  RET21: RET

  SCANB:

  LODSB

  CALL SPCHK

  JZ SCANB

  DEC SI

  RET

  GETLET:

  ;Get a byte from [SI], convert it to upper case, and compare for delimiter.

学习啦在线学习网   ;ZF set if a delimiter, CY set if a control character (other than TAB).

  LODSB

  AND AL,7FH

  CMP AL,"a"

  JB CHK

学习啦在线学习网   CMP AL,"z"

  JA CHK

  SUB AL,20H ;Convert to upper case

  CHK:

  CMP AL,"."

学习啦在线学习网   JZ RET21

  CMP AL,'"'

  JZ RET21

学习啦在线学习网   CMP AL,"/"

  JZ RET21

学习啦在线学习网   CMP AL,"["

  JZ RET21

学习啦在线学习网   CMP AL,"]"

  JZ RET21

  IF IBM

  DELIM:

  ENDIF

  CMP AL,":" ;Allow ":" as separator in IBM version

  JZ RET21

  IF NOT IBM

  DELIM:

  ENDIF

学习啦在线学习网   CMP AL,"+"

  JZ RET101

  CMP AL,"="

  JZ RET101

  CMP AL,";"

学习啦在线学习网   JZ RET101

  CMP AL,","

  JZ RET101

  SPCHK:

  CMP AL,9 ;Filter out tabs too

  JZ RET101

学习啦在线学习网   ;WARNING! " " MUST be the last compare

学习啦在线学习网   CMP AL," "

学习啦在线学习网   RET101: RET

  SETVECT: ; Interrupt call 37

  XOR BX,BX

学习啦在线学习网   MOV ES,BX

学习啦在线学习网   MOV BL,AL

  SHL BX,1

  SHL BX,1

  MOV ES:[BX],DX

  MOV ES:[BX+2],DS

  RET

学习啦在线学习网   NEWBASE: ; Interrupt call 38

学习啦在线学习网   MOV ES,DX

  LDS SI,CS:DWORD PTR [SPSAVE]

  MOV DS,[SI.CSSAVE]

学习啦在线学习网   XOR SI,SI

学习啦在线学习网   MOV DI,SI

  MOV AX,DS:[2]

学习啦在线学习网   MOV CX,80H

学习啦在线学习网   REP MOVSW

  SETMEM:

  ; Inputs:

学习啦在线学习网   ; AX = Size of memory in paragraphs

  ; DX = Segment

  ; Function:

  ; Completely prepares a program base at the

  ; specified segment.

  ; Outputs:

  ; DS = DX

学习啦在线学习网   ; ES = DX

学习啦在线学习网   ; [0] has INT 20H

  ; [2] = First unavailable segment ([ENDMEM])

  ; [5] to [9] form a long call to the entry point

  ; [10] to [13] have exit address (from INT 22H)

  ; [14] to [17] have ctrl-C exit address (from INT 23H)

学习啦在线学习网   ; [18] to [21] have fatal error address (from INT 24H)

  ; DX,BP unchanged. All other registers destroyed.

学习啦在线学习网   XOR CX,CX

学习啦在线学习网   MOV DS,CX

学习啦在线学习网   MOV ES,DX

  MOV SI,EXIT

学习啦在线学习网   MOV DI,SAVEXIT

  MOVSW

  MOVSW

  MOVSW

  MOVSW

  MOVSW

  MOVSW

学习啦在线学习网   MOV ES:[2],AX

学习啦在线学习网   SUB AX,DX

  CMP AX,MAXDIF

  JBE HAVDIF

  MOV AX,MAXDIF

  HAVDIF:

学习啦在线学习网   MOV BX,ENTRYPOINTSEG

  SUB BX,AX

学习啦在线学习网   SHL AX,1

学习啦在线学习网   SHL AX,1

  SHL AX,1

学习啦在线学习网   SHL AX,1

学习啦在线学习网   MOV DS,DX

学习啦在线学习网   MOV DS:[6],AX

  MOV DS:[8],BX

  MOV DS:[0],20CDH ;"INT INTTAB"

  MOV DS:(BYTE PTR [5]),LONGCALL

  RET

  DATE16:

  PUSH CX

  CALL READTIME

  SHL CL,1 ;Minutes to left part of byte

  SHL CL,1

  SHL CX,1 ;Push hours and minutes to left end

  SHL CX,1

  SHL CX,1

  SHR DH,1 ;Count every two seconds

  OR CL,DH ;Combine seconds with hours and minutes

  MOV DX,CX

  POP CX

学习啦在线学习网   MOV AX,WORD PTR [MONTH] ;Fetch month and year

  SHL AL,1 ;Push month to left to make room for day

学习啦在线学习网   SHL AL,1

  SHL AL,1

学习啦在线学习网   SHL AL,1

学习啦在线学习网   SHL AX,1

学习啦在线学习网   OR AL,[DAY]

学习啦在线学习网   RET22: RET

  FOURYEARS EQU 3*365+366

学习啦在线学习网   READTIME:

学习啦在线学习网   ;Gets time in CX:DX. Figures new date if it has changed.

  ;Uses AX, CX, DX.

  CALL FAR PTR BIOSGETTIME

学习啦在线学习网   CMP AX,[DAYCNT] ;See if day count is the same

学习啦在线学习网   JZ RET22

  CMP AX,FOURYEARS*30 ;Number of days in 120 years

学习啦在线学习网   JAE RET22 ;Ignore if too large

  MOV [DAYCNT],AX

  PUSH SI

  PUSH CX

  PUSH DX ;Save time

学习啦在线学习网   XOR DX,DX

  MOV CX,FOURYEARS ;Number of days in 4 years

学习啦在线学习网   DIV CX ;Compute number of 4-year units

学习啦在线学习网   SHL AX,1

  SHL AX,1

学习啦在线学习网   SHL AX,1 ;Multiply by 8 (no. of half-years)

学习啦在线学习网   MOV CX,AX ;<240 implies AH=0

学习啦在线学习网   MOV SI,OFFSET DOSGROUP:YRTAB ;Table of days in each year

  CALL DSLIDE ;Find out which of four years we're in

  SHR CX,1 ;Convert half-years to whole years

学习啦在线学习网   JNC SK ;Extra half-year?

  ADD DX,200

  SK:

  CALL SETYEAR

学习啦在线学习网   MOV CL,1 ;At least at first month in year

  MOV SI,OFFSET DOSGROUP:MONTAB ;Table of days in each month

  CALL DSLIDE ;Find out which month we're in

学习啦在线学习网   MOV [MONTH],CL

  INC DX ;Remainder is day of month (start with one)

学习啦在线学习网   MOV [DAY],DL

学习啦在线学习网   CALL WKDAY ;Set day of week

  POP DX

  POP CX

  POP SI

学习啦在线学习网   RET23: RET

  DSLIDE:

学习啦在线学习网   MOV AH,0

  DSLIDE1:

  LODSB ;Get count of days

  CMP DX,AX ;See if it will fit

学习啦在线学习网   JB RET23 ;If not, done

  SUB DX,AX

学习啦在线学习网   INC CX ;Count one more month/year

  JMP SHORT DSLIDE1

学习啦在线学习网   SETYEAR:

学习啦在线学习网   ;Set year with value in CX. Adjust length of February for this year.

学习啦在线学习网   MOV BYTE PTR [YEAR],CL

  CHKYR:

学习啦在线学习网   TEST CL,3 ;Check for leap year

  MOV AL,28

  JNZ SAVFEB ;28 days if no leap year

  INC AL ;Add leap day

  SAVFEB:

  MOV [MONTAB+1],AL ;Store for February

  RET

学习啦在线学习网   ;Days in year

学习啦在线学习网   YRTAB DB 200,166 ;Leap year

学习啦在线学习网   DB 200,165

学习啦在线学习网   DB 200,165

  DB 200,165

  ;Days of each month

  MONTAB DB 31 ;January

  DB 28 ;February--reset each time year changes

  DB 31 ;March

学习啦在线学习网   DB 30 ;April

学习啦在线学习网   DB 31 ;May

学习啦在线学习网   DB 30 ;June

学习啦在线学习网   DB 31 ;July

  DB 31 ;August

  DB 30 ;September

学习啦在线学习网   DB 31 ;October

  DB 30 ;November

学习啦在线学习网   DB 31 ;December

  GETDATE: ;Function call 42

  PUSH CS

  POP DS

  CALL READTIME ;Check for rollover to next day

  MOV AX,[YEAR]

  MOV BX,WORD PTR [DAY]

学习啦在线学习网   LDS SI,DWORD PTR [SPSAVE] ;Get pointer to user registers

  MOV [SI.DXSAVE],BX ;DH=month, DL=day

  ADD AX,1980 ;Put bias back

  MOV [SI.CXSAVE],AX ;CX=year

  MOV AL,CS:[WEEKDAY]

  RET24: RET

  SETDATE: ;Function call 43

  MOV AL,-1 ;Be ready to flag error

  SUB CX,1980 ;Fix bias in year

学习啦在线学习网   JC RET24 ;Error if not big enough

  CMP CX,119 ;Year must be less than 2100

  JA RET24

学习啦在线学习网   OR DH,DH

学习啦在线学习网   JZ RET24

学习啦在线学习网   OR DL,DL

  JZ RET24 ;Error if either month or day is 0

  CMP DH,12 ;Check against max. month

  JA RET24

  PUSH CS

  POP DS

  CALL CHKYR ;Set Feb. up for new year

学习啦在线学习网   MOV AL,DH

学习啦在线学习网   MOV BX,OFFSET DOSGROUP:MONTAB-1

  XLAT ;Look up days in month

学习啦在线学习网   CMP AL,DL

学习啦在线学习网   MOV AL,-1 ;Restore error flag, just in case

学习啦在线学习网   JB RET24 ;Error if too many days

  CALL SETYEAR

学习啦在线学习网   MOV WORD PTR [DAY],DX ;Set both day and month

  SHR CX,1

  SHR CX,1

学习啦在线学习网   MOV AX,FOURYEARS

学习啦在线学习网   MOV BX,DX

  MUL CX

学习啦在线学习网   MOV CL,BYTE PTR [YEAR]

学习啦在线学习网   AND CL,3

  MOV SI,OFFSET DOSGROUP:YRTAB

学习啦在线学习网   MOV DX,AX

  SHL CX,1 ;Two entries per year, so double count

学习啦在线学习网   CALL DSUM ;Add up the days in each year

  MOV CL,BH ;Month of year

学习啦在线学习网   MOV SI,OFFSET DOSGROUP:MONTAB

  DEC CX ;Account for months starting with one

  CALL DSUM ;Add up days in each month

  MOV CL,BL ;Day of month

  DEC CX ;Account for days starting with one

  ADD DX,CX ;Add in to day total

  XCHG AX,DX ;Get day count in AX

  MOV [DAYCNT],AX

学习啦在线学习网   CALL FAR PTR BIOSSETDATE

  WKDAY:

  MOV AX,[DAYCNT]

  XOR DX,DX

  MOV CX,7

  INC AX

  INC AX ;First day was Tuesday

  DIV CX ;Compute day of week

  MOV [WEEKDAY],DL

学习啦在线学习网   XOR AL,AL ;Flag OK

  RET25: RET

  DSUM:

  MOV AH,0

  JCXZ RET25

  DSUM1:

  LODSB

学习啦在线学习网   ADD DX,AX

学习啦在线学习网   LOOP DSUM1

  RET

  GETTIME: ;Function call 44

  PUSH CS

  POP DS

  CALL READTIME

学习啦在线学习网   LDS SI,DWORD PTR [SPSAVE] ;Get pointer to user registers

  MOV [SI.DXSAVE],DX

  MOV [SI.CXSAVE],CX

学习啦在线学习网   XOR AL,AL

  RET26: RET

  SETTIME: ;Function call 45

  ;Time is in CX:DX in hours, minutes, seconds, 1/100 sec.

  MOV AL,-1 ;Flag in case of error

  CMP CH,24 ;Check hours

  JAE RET26

  CMP CL,60 ;Check minutes

  JAE RET26

学习啦在线学习网   CMP DH,60 ;Check seconds

学习啦在线学习网   JAE RET26

  CMP DL,100 ;Check 1/100's

学习啦在线学习网   JAE RET26

  CALL FAR PTR BIOSSETTIME

学习啦在线学习网   XOR AL,AL

  RET

学习啦在线学习网   ; Default handler for division overflow trap

  DIVOV:

  PUSH SI

  PUSH AX

学习啦在线学习网   MOV SI,OFFSET DOSGROUP:DIVMES

  CALL OUTMES

  POP AX

  POP SI

  INT 23H ;Use Ctrl-C abort on divide overflow

  IRET

学习啦在线学习网   CODSIZ EQU $-CODSTRT ;Size of code segment

学习啦在线学习网   CODE ENDS

  ;***** DATA AREA *****

  CONSTANTS SEGMENT BYTE

  ORG 0

学习啦在线学习网   CONSTRT EQU $ ;Start of constants segment

  IONAME:

学习啦在线学习网   IF NOT IBM

学习啦在线学习网   DB "PRN ","LST ","NUL ","AUX ","CON "

  ENDIF

  IF IBM

学习啦在线学习网   DB "COM1","PRN ","LPT1","NUL ","AUX ","CON "

  ENDIF

  DIVMES DB 13,10,"Divide overflow",13,10,"$"

  CARPOS DB 0

学习啦在线学习网   STARTPOS DB 0

  PFLAG DB 0

学习啦在线学习网   DIRTYDIR DB 0 ;Dirty buffer flag

  NUMDRV DB 0 ;Number of drives

  NUMIO DB ? ;Number of disk tables

学习啦在线学习网   VERFLG DB 0 ;Initialize with verify off

  CONTPOS DW 0

  DMAADD DW 80H ;User's disk transfer address (disp/seg)

  DW ?

学习啦在线学习网   ENDMEM DW ?

  MAXSEC DW 0

  BUFFER DW ?

学习啦在线学习网   BUFSECNO DW 0

学习啦在线学习网   BUFDRVNO DB -1

  DIRTYBUF DB 0

学习啦在线学习网   BUFDRVBP DW ?

  DIRBUFID DW -1

  DAY DB 0

学习啦在线学习网   MONTH DB 0

  YEAR DW 0

学习啦在线学习网   DAYCNT DW -1

  WEEKDAY DB 0

  CURDRV DB 0 ;Default to drive A

学习啦在线学习网   DRVTAB DW 0 ;Address of start of DPBs

学习啦在线学习网   DOSLEN EQU CODSIZ+($-CONSTRT) ;Size of CODE + CONSTANTS segments

  CONSTANTS ENDS

  DATA SEGMENT WORD

学习啦在线学习网   ; Init code overlaps with data area below

  ORG 0

  INBUF DB 128 DUP (?)

  CONBUF DB 131 DUP (?) ;The rest of INBUF and console buffer

  LASTENT DW ?

  EXITHOLD DB 4 DUP (?)

  FATBASE DW ?

学习啦在线学习网   NAME1 DB 11 DUP (?) ;File name buffer

  ATTRIB DB ?

  NAME2 DB 11 DUP (?)

学习啦在线学习网   NAME3 DB 12 DUP (?)

  EXTFCB DB ?

  ;WARNING - the following two items are accessed as a word

学习啦在线学习网   CREATING DB ?

  DELALL DB ?

学习啦在线学习网   TEMP LABEL WORD

  SPSAVE DW ?

  SSSAVE DW ?

  CONTSTK DW ?

  SECCLUSPOS DB ? ;Position of first sector within cluster

  DSKERR DB ?

  TRANS DB ?

  PREREAD DB ? ;0 means preread; 1 means optional

学习啦在线学习网   READOP DB ?

  THISDRV DB ?

  EVEN

  FCB DW ? ;Address of user FCB

  NEXTADD DW ?

学习啦在线学习网   RECPOS DB 4 DUP (?)

学习啦在线学习网   RECCNT DW ?

  LASTPOS DW ?

  CLUSNUM DW ?

  SECPOS DW ? ;Position of first sector accessed

  VALSEC DW ? ;Number of valid (previously written) sectors

  BYTSECPOS DW ? ;Position of first byte within sector

学习啦在线学习网   BYTPOS DB 4 DUP (?) ;Byte position in file of access

  BYTCNT1 DW ? ;No. of bytes in first sector

学习啦在线学习网   BYTCNT2 DW ? ;No. of bytes in last sector

学习啦在线学习网   SECCNT DW ? ;No. of whole sectors

  ENTFREE DW ?

  DB 80H DUP (?) ;Stack space

学习啦在线学习网   IOSTACK LABEL BYTE

  DB 80H DUP (?)

  DSKSTACK LABEL BYTE

学习啦在线学习网   IF DSKTEST

学习啦在线学习网   NSS DW ?

  NSP DW ?

  ENDIF

学习啦在线学习网   DIRBUF LABEL WORD

学习啦在线学习网   ;Init code below overlaps with data area above

  ORG 0

  MOVFAT:

  ;This section of code is safe from being overwritten by block move

学习啦在线学习网   REP MOVS BYTE PTR [DI],[SI]

  CLD

学习啦在线学习网   MOV ES:[DMAADD+2],DX

  MOV SI,[DRVTAB] ;Address of first DPB

  MOV AL,-1

学习啦在线学习网   MOV CL,[NUMIO] ;Number of DPBs

  FLGFAT:

  MOV DI,ES:[SI.FAT] ;get pointer to FAT

  DEC DI ;Point to dirty byte

学习啦在线学习网   STOSB ;Flag as unused

  ADD SI,DPBSIZ ;Point to next DPB

  LOOP FLGFAT

学习啦在线学习网   MOV AX,[ENDMEM]

学习啦在线学习网   CALL SETMEM ;Set up segment

  XXX PROC FAR

  RET

  XXX ENDP

  DOSINIT:

  CLI

  CLD

  PUSH CS

  POP ES

  MOV ES:[ENDMEM],DX

  LODSB ;Get no. of drives & no. of I/O drivers

  MOV ES:[NUMIO],AL

  MOV DI,OFFSET DOSGROUP:MEMSTRT

  PERDRV:

  MOV BP,DI

  MOV AL,ES:[DRVCNT]

  STOSB ;DEVNUM

学习啦在线学习网   LODSB ;Physical unit no.

学习啦在线学习网   STOSB ;DRVNUM

  CMP AL,15

学习啦在线学习网   JA BADINIT

学习啦在线学习网   CBW ;Index into FAT size table

学习啦在线学习网   SHL AX,1

学习啦在线学习网   ADD AX,OFFSET DOSGROUP:FATSIZTAB

学习啦在线学习网   XCHG BX,AX

学习啦在线学习网   LODSW ;Pointer to DPT

  PUSH SI

  MOV SI,AX

  LODSW

  STOSW ;SECSIZ

学习啦在线学习网   MOV DX,AX

学习啦在线学习网   CMP AX,ES:[MAXSEC]

  JBE NOTMAX

学习啦在线学习网   MOV ES:[MAXSEC],AX

  NOTMAX:

  LODSB

  DEC AL

  STOSB ;CLUSMSK

  JZ HAVSHFT

  CBW

学习啦在线学习网   FIGSHFT:

  INC AH

学习啦在线学习网   SAR AL,1

  JNZ FIGSHFT

  MOV AL,AH

学习啦在线学习网   HAVSHFT:

学习啦在线学习网   STOSB ;CLUSSHFT

  MOVSW ;FIRFAT (= number of reserved sectors)

  MOVSB ;FATCNT

  MOVSW ;MAXENT

  MOV AX,DX ;SECSIZ again

  MOV CL,5

  SHR AX,CL

  MOV CX,AX ;Directory entries per sector

  DEC AX

  ADD AX,ES:[BP.MAXENT]

  XOR DX,DX

  DIV CX

  STOSW ;DIRSEC (temporarily)

  MOVSW ;DSKSIZ (temporarily)

  FNDFATSIZ:

学习啦在线学习网   MOV AL,1

  MOV DX,1

学习啦在线学习网   GETFATSIZ:

  PUSH DX

学习啦在线学习网   CALL FIGFATSIZ

  POP DX

  CMP AL,DL ;Compare newly computed FAT size with trial

  JZ HAVFATSIZ ;Has sequence converged?

  CMP AL,DH ;Compare with previous trial

学习啦在线学习网   MOV DH,DL

学习啦在线学习网   MOV DL,AL ;Shuffle trials

学习啦在线学习网   JNZ GETFATSIZ ;Continue iterations if not oscillating

  DEC WORD PTR ES:[BP.DSKSIZ] ;Damp those oscillations

  JMP SHORT FNDFATSIZ ;Try again

  BADINIT:

  MOV SI,OFFSET DOSGROUP:BADMES

  CALL OUTMES

  STI

  HLT

  HAVFATSIZ:

学习啦在线学习网   STOSB ;FATSIZ

学习啦在线学习网   MUL ES:BYTE PTR[BP.FATCNT] ;Space occupied by all FATs

学习啦在线学习网   ADD AX,ES:[BP.FIRFAT]

学习啦在线学习网   STOSW ;FIRDIR

  ADD AX,ES:[BP.DIRSEC]

学习啦在线学习网   MOV ES:[BP.FIRREC],AX ;Destroys DIRSEC

  CALL FIGMAX

学习啦在线学习网   MOV ES:[BP.MAXCLUS],CX

  MOV AX,BX ;Pointer into FAT size table

  STOSW ;Allocate space for FAT pointer

  MOV AL,ES:[BP.FATSIZ]

  XOR AH,AH

  MUL ES:[BP.SECSIZ]

学习啦在线学习网   CMP AX,ES:[BX] ;Bigger than already allocated

学习啦在线学习网   JBE SMFAT

学习啦在线学习网   MOV ES:[BX],AX

  SMFAT:

学习啦在线学习网   POP SI ;Restore pointer to init. table

  MOV AL,ES:[DRVCNT]

  INC AL

  MOV ES:[DRVCNT],AL

学习啦在线学习网   CMP AL,ES:[NUMIO]

  JAE CONTINIT

  JMP PERDRV

  BADINITJ:

  JMP BADINIT

学习啦在线学习网   CONTINIT:

  PUSH CS

  POP DS

学习啦在线学习网   ;Calculate true address of buffers, FATs, free space

学习啦在线学习网   MOV BP,[MAXSEC]

学习啦在线学习网   MOV AX,OFFSET DOSGROUP:DIRBUF

  ADD AX,BP

  MOV [BUFFER],AX ;Start of buffer

学习啦在线学习网   ADD AX,BP

学习啦在线学习网   MOV [DRVTAB],AX ;Start of DPBs

  SHL BP,1 ;Two sectors - directory and buffer

学习啦在线学习网   ADD BP,DI ;Allocate buffer space

学习啦在线学习网   ADD BP,ADJFAC ;True address of FATs

  PUSH BP

学习啦在线学习网   MOV SI,OFFSET DOSGROUP:FATSIZTAB

  MOV DI,SI

学习啦在线学习网   MOV CX,16

  TOTFATSIZ:

  INC BP ;Add one for Dirty byte

学习啦在线学习网   INC BP ;Add one for I/O device number

  LODSW ;Get size of this FAT

  XCHG AX,BP

  STOSW ;Save address of this FAT

  ADD BP,AX ;Compute size of next FAT

  CMP AX,BP ;If size was zero done

  LOOPNZ TOTFATSIZ

  MOV AL,15

学习啦在线学习网   SUB AL,CL ;Compute number of FATs used

  MOV [NUMDRV],AL

学习啦在线学习网   XOR AX,AX ;Set zero flag

学习啦在线学习网   REPZ SCASW ;Make sure all other entries are zero

学习啦在线学习网   JNZ BADINITJ

  ADD BP,15 ;True start of free space

学习啦在线学习网   MOV CL,4

  SHR BP,CL ;First free segment

学习啦在线学习网   MOV DX,CS

  ADD DX,BP

  MOV BX,0FH

  MOV CX,[ENDMEM]

学习啦在线学习网   CMP CX,1 ;Use memory scan?

  JNZ SETEND

学习啦在线学习网   MOV CX,DX ;Start scanning just after DOS

学习啦在线学习网   MEMSCAN:

  INC CX

学习啦在线学习网   JZ SETEND

  MOV DS,CX

  MOV AL,[BX]

  NOT AL

学习啦在线学习网   MOV [BX],AL

  CMP AL,[BX]

  NOT AL

  MOV [BX],AL

  JZ MEMSCAN

  SETEND:

  IF HIGHMEM

学习啦在线学习网   SUB CX,BP

学习啦在线学习网   MOV BP,CX ;Segment of DOS

学习啦在线学习网   MOV DX,CS ;Program segment

  ENDIF

  IF NOT HIGHMEM

  MOV BP,CS

  ENDIF

  ; BP has segment of DOS (whether to load high or run in place)

  ; DX has program segment (whether after DOS or overlaying DOS)

  ; CX has size of memory in paragraphs (reduced by DOS size if HIGHMEM)

  MOV CS:[ENDMEM],CX

  IF HIGHMEM

  MOV ES,BP

  XOR SI,SI

  MOV DI,SI

  MOV CX,(DOSLEN+1)/2

  PUSH CS

  POP DS

  REP MOVSW ;Move DOS to high memory

  ENDIF

  XOR AX,AX

  MOV DS,AX

学习啦在线学习网   MOV ES,AX

  MOV DI,INTBASE

  MOV AX,OFFSET DOSGROUP:QUIT

  STOSW ;Set abort address--displacement

学习啦在线学习网   MOV AX,BP

  MOV BYTE PTR DS:[ENTRYPOINT],LONGJUMP

  MOV WORD PTR DS:[ENTRYPOINT+1],OFFSET DOSGROUP:ENTRY

  MOV WORD PTR DS:[ENTRYPOINT+3],AX

  MOV WORD PTR DS:[0],OFFSET DOSGROUP:DIVOV ;Set default divide trap address

学习啦在线学习网   MOV DS:[2],AX

学习啦在线学习网   MOV CX,9

  REP STOSW ;Set 5 segments (skip 2 between each)

学习啦在线学习网   MOV WORD PTR DS:[INTBASE+4],OFFSET DOSGROUP:COMMAND

学习啦在线学习网   MOV WORD PTR DS:[INTBASE+12],OFFSET DOSGROUP:IRET ;Ctrl-C exit

  MOV WORD PTR DS:[INTBASE+16],OFFSET DOSGROUP:IRET ;Fatal error exit

  MOV AX,OFFSET BIOSREAD

  STOSW

学习啦在线学习网   MOV AX,BIOSSEG

  STOSW

学习啦在线学习网   STOSW ;Add 2 to DI

  STOSW

  MOV WORD PTR DS:[INTBASE+18H],OFFSET BIOSWRITE

  MOV WORD PTR DS:[EXIT],100H

  MOV WORD PTR DS:[EXIT+2],DX

  IF NOT IBM

学习啦在线学习网   MOV SI,OFFSET DOSGROUP:HEADER

学习啦在线学习网   CALL OUTMES

  ENDIF

  PUSH CS

  POP DS

  PUSH CS

  POP ES

  ;Move the FATs into position

  MOV AL,[NUMIO]

  CBW

  XCHG AX,CX

学习啦在线学习网   MOV DI,OFFSET DOSGROUP:MEMSTRT.FAT

  FATPOINT:

  MOV SI,WORD PTR [DI] ;Get address within FAT address table

  MOVSW ;Set address of this FAT

学习啦在线学习网   ADD DI,DPBSIZ-2 ;Point to next DPB

  LOOP FATPOINT

学习啦在线学习网   POP CX ;True address of first FAT

学习啦在线学习网   MOV SI,OFFSET DOSGROUP:MEMSTRT ;Place to move DPBs from

学习啦在线学习网   MOV DI,[DRVTAB] ;Place to move DPBs to

  SUB CX,DI ;Total length of DPBs

  CMP DI,SI

  JBE MOVJMP ;Are we moving to higher or lower memory?

学习啦在线学习网   DEC CX ;Move backwards to higher memory

  ADD DI,CX

  ADD SI,CX

  INC CX

  STD

  MOVJMP:

学习啦在线学习网   MOV ES,BP

学习啦在线学习网   JMP MOVFAT

学习啦在线学习网   FIGFATSIZ:

  MUL ES:BYTE PTR[BP.FATCNT]

学习啦在线学习网   ADD AX,ES:[BP.FIRFAT]

学习啦在线学习网   ADD AX,ES:[BP.DIRSEC]

  FIGMAX:

学习啦在线学习网   ;AX has equivalent of FIRREC

  SUB AX,ES:[BP.DSKSIZ]

  NEG AX

  MOV CL,ES:[BP.CLUSSHFT]

  SHR AX,CL

  INC AX

  MOV CX,AX ;MAXCLUS

  INC AX

  MOV DX,AX

  SHR DX,1

  ADC AX,DX ;Size of FAT in bytes

学习啦在线学习网   MOV SI,ES:[BP.SECSIZ]

学习啦在线学习网   ADD AX,SI

  DEC AX

  XOR DX,DX

  DIV SI

  RET

  BADMES:

  DB 13,10,"INIT TABLE BAD",13,10,"$"

  FATSIZTAB:

学习啦在线学习网   DW 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

  DRVCNT DB 0

  MEMSTRT LABEL WORD

  ADJFAC EQU DIRBUF-MEMSTRT

  DATA ENDS

  END

  

学习啦在线学习网 看了“DOS操作系统源码相关资料知识”还想看:

1.计算机的DOS操作系统详解

2.dos操作系统介绍

3.DOS操作系统历史知识

4.电脑操作系统介绍与发展历程

5.操作系统发展简史

2779956