home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.update.uu.se
/
ftp.update.uu.se.2014.03.zip
/
ftp.update.uu.se
/
pub
/
rainbow
/
msdos
/
latrobe
/
b
/
biodif.arc
/
MSBOOT.DIF
< prev
next >
Wrap
Text File
|
1987-06-23
|
25KB
|
725 lines
************
File MSBOOT.OLD;1
44 ;
******
File MSBOOT.ASM;1
44 ; RGT 16 Jan 1986 Modify it to use hard disk information
45 ; when booting from hard disk.
46 ;
************
************
File MSBOOT.OLD;1
119 F_MAX_FAT_SECTORS EQU 3 ;Assume 3 sectors per FAT
120 F_MAX_NUM_FATS EQU 2 ;2 FATs on disk
121 F_SECTOR_SIZE EQU 512 ;Sector size
122 F_CLUSTER_SIZE EQU 1 ;Cluster size
123 F_MAX_SECT_PER_TRACK EQU 10 ;Normal sectors
124 F_MAX_SURFACES EQU 1 ;Number of surfaces
125 ;
******
File MSBOOT.ASM;1
121 F_NUM_FAT_SECTORS EQU 3 ;Assume 3 sectors per FAT
122 F_NUM_FATS EQU 2 ;2 FATs on disk
123 F_SECTOR_SIZE EQU 512 ;Sector size
124 F_CLUSTER_SIZE EQU 1 ;Cluster size
125 F_SECT_PER_TRACK EQU 10 ;Normal sectors
126 F_NUM_SURFACES EQU 1 ;Number of surfaces
127 F_NUM_RESERVED_SECTORS EQU 20 ;Number of reserved sectors
128 F_NUM_DIR_SECTORS EQU 6 ;Number of directory sectors
129 F_DENSITY_TYPE EQU FDISK_RAINB ;Disk density code
130 ;
131 ; Define some sizes for the double-sided floppy disks
132 ;
133 F2_NUM_FAT_SECTORS EQU 5 ;Assume 5 sectors per FAT
134 F2_NUM_FATS EQU 2 ;2 FATs on disk
135 F2_SECTOR_SIZE EQU 512 ;Sector size
136 F2_CLUSTER_SIZE EQU 1 ;Cluster size
137 F2_SECT_PER_TRACK EQU 10 ;Normal sectors
138 F2_NUM_SURFACES EQU 2 ;Number of surfaces
139 F2_NUM_RESERVED_SECTORS EQU 20 ;Number of reserved sectors
140 F2_NUM_DIR_SECTORS EQU 7 ;Number of directory sectors
141 F2_DENSITY_TYPE EQU FDISK_RAINB+FDISK_DSIDE ;Disk density code
142 ;
************
************
File MSBOOT.OLD;1
128 H_MAX_FAT_SECTORS EQU 6 ;Assume 3 sectors per FAT
129 H_MAX_NUM_FATS EQU 2 ;2 FATs on disk
130 H_SECTOR_SIZE EQU 512 ;Sector size
131 H_CLUSTER_SIZE EQU 4 ;Cluster size
132 H_MAX_SECT_PER_TRACK EQU 16 ;Normal sectors
133 H_MAX_SURFACES EQU 8 ;Number of surfaces
134 H_NUM_RESERVED_SECTORS EQU 48 ;Number of reserved sectors
135 H_PRECOMP_VALUE EQU 50 ;Precomp value
136 ;
******
File MSBOOT.ASM;1
145 H_NUM_FAT_SECTORS EQU 12 ;Assume 12 sectors per FAT
146 H_NUM_FATS EQU 2 ;2 FATs on disk
147 H_SECTOR_SIZE EQU 512 ;Sector size
148 H_CLUSTER_SIZE EQU 4 ;Cluster size
149 H_SECT_PER_TRACK EQU 16 ;Normal sectors
150 H_NUM_SURFACES EQU 8 ;Number of surfaces
151 H_NUM_RESERVED_SECTORS EQU 32 ;Number of reserved sectors
152 H_NUM_DIR_SECTORS EQU 16 ;Number of directory sectors
153 H_PRECOMP_VALUE EQU 50 ;Precomp value
154 ;
155 ; Define the maximum sector size for allocating buffers
156 ;
157 MAX_SECTOR_SIZE EQU 512
158 ;
************
************
File MSBOOT.OLD;1
158 ;
******
File MSBOOT.ASM;1
180
181 ;
************
************
File MSBOOT.OLD;1
167 ; The FORMAT command looks for the following instructions on
******
File MSBOOT.ASM;1
190 ;
191 ; The hard disk bootstrap looks at the first byte
192 ; of the MS-DOS boot code.
193 ; If it is not a JMP instruction, it will not boot.
194 ;
195 ; The FORMAT command looks for the following instructions on
************
************
File MSBOOT.OLD;1
180 ;
181 JMP START ;And jump to start code
182 NOP ;NOP for space for CLI instruction
183 ;
******
File MSBOOT.ASM;1
208 ; Since this will first be written to the floppy, set up for floppy.
209 ;
210 CLI ;Disable interrupts
211 JMP START ;And jump to start code
212 ;
************
************
File MSBOOT.OLD;1
233 READ_AREA DB H_SECTOR_SIZE DUP(0)
234 ;
******
File MSBOOT.ASM;1
262 READ_AREA DB MAX_SECTOR_SIZE DUP(0)
263 ;
************
************
File MSBOOT.OLD;1
247 DISK_CMD_DENSITY DB 0 ;Disk density (Not used)
248 DISK_CMD_GAPLEN DB 0 ;Gap length (Not used)
******
File MSBOOT.ASM;1
276 DISK_CMD_DENSITY DB F_DENSITY_TYPE ;Disk density code
277 DISK_CMD_GAPLEN DB 0 ;Gap length (Not used)
************
************
File MSBOOT.OLD;1
251 DISK_CMD_SECSIZ DW H_SECTOR_SIZE ;Sector size (word)
252 DISK_CMD_DMAOFF DW OFFSET READ_AREA ;DMA offset (word)
******
File MSBOOT.ASM;1
280 DISK_CMD_SECSIZ DW F_SECTOR_SIZE ;Sector size (word)
281 DISK_CMD_DMAOFF DW OFFSET READ_AREA ;DMA offset (word)
************
************
File MSBOOT.OLD;1
257 ; Define the count of sectors to be read
******
File MSBOOT.ASM;1
286 ; Store a flag in case booting from floppy disk.
287 ; This will tell if it is double-sided or not.
288 ;
289 FLOPPY_DSIDED DB 0
290 ;
291 ; Define the count of sectors to be read
************
************
File MSBOOT.OLD;1
261 ; Define the track number of the hard disk to be read
262 ;
******
File MSBOOT.ASM;1
295 ; Store the track number of the hard disk directory
296 ;
297 DIR_TRACK DW 0
298 ;
299 ; Store the sector number of the hard disk directory
300 ;
301 DIR_SECTOR DB 0
302 ;
303 ; Store the track number of the hard disk to be read
304 ;
************
************
File MSBOOT.OLD;1
265 ; Define the sector number of the hard disk to be read
266 ;
******
File MSBOOT.ASM;1
307 ; Store the sector number of the hard disk to be read
308 ;
************
************
File MSBOOT.OLD;1
269 ; Define the track number of the first DPD block
******
File MSBOOT.ASM;1
311 ; Store the information for this disk
312 ;
313 NUM_FAT_SECTORS DB 0 ;Number of FAT sectors
314 NUM_FATS DB 0 ;Number of FATs on disk
315 SECTOR_SIZE DW 0 ;Sector size
316 CLUSTER_SIZE DW 0 ;Cluster size
317 SECT_PER_TRACK DW 0 ;Number of sectors per track
318 NUM_SURFACES DB 0 ;Number of surfaces
319 NUM_RESERVED_SECTORS DW 0 ;Number of reserved sectors
320 NUM_DIR_SECTORS DW 0 ;Number of directory sectors
321 ;
322 ; Define the track number of the first DPD block
************
************
File MSBOOT.OLD;1
281 ; Define the flag that a hard disk interrupt occured
******
File MSBOOT.ASM;1
334 ; Define the first track number of the partition
335 ;
336 FIRST_PARTITION_TRACK DW 0
337 ;
338 ; Define the flag that a hard disk interrupt occured
************
************
File MSBOOT.OLD;1
300 ;
******
File MSBOOT.ASM;1
357 ; Since sector numbers always start at 1,
358 ; add an extra byte for the proper offset.
359 ;
************
************
File MSBOOT.OLD;1
311 MS_DOS_LOADING_MSG DB 'MS-DOS (8) loading . .'
312 ;
******
File MSBOOT.ASM;1
370 MS_DOS_LOADING_MSG DB 'MS-DOS (RGT) loading . .'
371 ;
************
************
File MSBOOT.OLD;1
326 ; Define the message for disk not MS-DOS system disk
******
File MSBOOT.ASM;1
385 ; Define the message for an error reading directory on the disk
386 ;
387 READ_DIR_ERROR_MSG DB 'Error reading disk directory',0
388 ;
389 ; Define the message for disk not MS-DOS system disk
************
************
File MSBOOT.OLD;1
334
******
File MSBOOT.ASM;1
397 ; Define message for types of disks found
398 ;
399 DSIDE_DISK_MSG DB CR,LF,'Floppy disk is double-sided',CR,LF,LF,0
400 SSIDE_DISK_MSG DB CR,LF,'Floppy disk is single-sided',CR,LF,LF,0
401 ;
402
************
************
File MSBOOT.OLD;1
348 MOV DISK_CMD_DRIVE,AL ;Store disk device in memory
349 MOV CX,8 ;Set count to 8 bytes
******
File MSBOOT.ASM;1
416 MOV AH,AL ;Copy into reg AH
417 AND AL,07FH ;Mask out double-sided bit
418 MOV DISK_CMD_DRIVE,AL ;Store disk device in memory
419 AND AH,080H ;Mask out all but double-sided bit
420 MOV FLOPPY_DSIDED,AH ;Store in memory
421 MOV CX,8 ;Set count to 8 bytes
************
************
File MSBOOT.OLD;1
361 ; Restart vector for another attempt to load MS-DOS operating system
362 ;
******
File MSBOOT.ASM;1
433 ; Restart address for another attempt to load MS-DOS operating system
434 ;
************
************
File MSBOOT.OLD;1
383 JL READ_IO_SYSTEM ;If not hard disk, read I/O system
384 CALL HDISK_INIT ;Otherwise, initialize hard disk
385 ;
******
File MSBOOT.ASM;1
455 JL FDISK_INIT ;If not hard disk, check type of disk
456 CALL HDISK_INIT ;Otherwise, initialize hard disk
457 JMP READ_IO_SYSTEM ;And go read I/O system
458 ;
459 ; Disk is floppy disk -- find out if disk is single- or double-sided disk
460 ;
461 FDISK_INIT:
462 MOV AL,FLOPPY_DSIDED ;Get flag for double-sided floppy
463 ;
464 ; Found valid disk type -- store disk type found and print it for user
465 ;
466 OR AL,AL ;Check if single-sided disk
467 JNZ FDISK_INIT_010 ;If not, print other message
468 ;
469 ; Disk is a single-sided disk -- store disk parameters and print message
470 ;
471 MOV DISK_CMD_DENSITY,F_DENSITY_TYPE ;Set disk density code
472 MOV NUM_FAT_SECTORS,F_NUM_FAT_SECTORS
473 MOV NUM_FATS,F_NUM_FATS
474 MOV SECTOR_SIZE,F_SECTOR_SIZE
475 MOV CLUSTER_SIZE,F_CLUSTER_SIZE
476 MOV SECT_PER_TRACK,F_SECT_PER_TRACK
477 MOV NUM_SURFACES,F_NUM_SURFACES
478 MOV NUM_RESERVED_SECTORS,F_NUM_RESERVED_SECTORS
479 MOV NUM_DIR_SECTORS,F_NUM_DIR_SECTORS
480 MOV DIR_TRACK,2 ;Set track of directory
481 MOV DIR_SECTOR,7 ;Set sector of directory
482 MOV SI,OFFSET SSIDE_DISK_MSG ;Get message for single-sided disk
483 JMP SHORT FDISK_INIT_020 ;And print it out
484 ;
485 ; Disk is a double-sided disk -- store disk information and print message
486 ;
487 FDISK_INIT_010:
488 MOV DISK_CMD_DENSITY,F2_DENSITY_TYPE ;Set disk density code
489 MOV NUM_FAT_SECTORS,F2_NUM_FAT_SECTORS
490 MOV NUM_FATS,F2_NUM_FATS
491 MOV SECTOR_SIZE,F2_SECTOR_SIZE
492 MOV CLUSTER_SIZE,F2_CLUSTER_SIZE
493 MOV SECT_PER_TRACK,F2_SECT_PER_TRACK
494 MOV NUM_SURFACES,F2_NUM_SURFACES
495 MOV NUM_RESERVED_SECTORS,F2_NUM_RESERVED_SECTORS
496 MOV NUM_DIR_SECTORS,F2_NUM_DIR_SECTORS
497 MOV DIR_TRACK,3 ;Set track of directory
498 MOV DIR_SECTOR,1 ;Set sector of directory
499 MOV SI,OFFSET DSIDE_DISK_MSG ;Get message for double-sided disk
500 ;
501 ; Print out the type of disk found
502 ;
503 FDISK_INIT_020:
504 CALL PRINT_MESSAGE ;And print it out
505 ;
************
************
File MSBOOT.OLD;1
390 MOV DISK_CMD_DMASEG_OFF[BX],CS ;Store segment of destination
391 MOV CX,24 ;Get count of segments
392 MOV AX,IO_SYS_SEG ;Get segment for loading I/O system
******
File MSBOOT.ASM;1
510 MOV AL,0FFH ;Set reg AL to 0FFH
511 MOV DISK_CMD_CURTRK_OFF[BX],AL ;And set current track to this value
512 MOV DISK_CMD_DMASEG_OFF[BX],CS ;Store segment of destination
513 CALL GET_IO_POSITION ;Get IO.SYS position and size
514 MOV BX,OFFSET DISK_CMD_CMD ;Get address of command block
515 MOV READ_TRACK,AX ;Store track to read for hard disk
516 MOV READ_SECTOR,DL ;Store sector to read for hard disk
517 MOV DISK_CMD_TRACK_OFF[BX],AL ;Set track to read for floppy
518 MOV DISK_CMD_SECTOR_OFF[BX],DL ;Set sector to read for floppy
519 MOV AX,IO_SYS_SEG ;Get segment for loading I/O system
************
************
File MSBOOT.OLD;1
395 MOV AL,3 ;Set AL to 3
396 MOV DISK_CMD_TRACK_OFF[BX],AL ;And set to track to read
397 MOV DISK_CMD_SECTOR_OFF[BX],AL ;Also set to sector to read
398 MOV AL,0FFH ;Set reg AL to 0FFH
399 MOV DISK_CMD_CURTRK_OFF[BX],AL ;And set current track to this value
400 CALL READ_SECTORS ;Call routine to read the logical device
******
File MSBOOT.ASM;1
522 CALL READ_SECTORS ;Call routine to read the logical device
************
************
File MSBOOT.OLD;1
410 MOV CX,36 ;Get number of sectors for MS-DOS code
411 MOV AX,MS_DOS_SEG ;Get segment for loading that code
******
File MSBOOT.ASM;1
532 CALL GET_MSDOS_POSITION ;Get MSDOS.SYS position and size
533 MOV BX,OFFSET DISK_CMD_CMD ;Get address of command block
534 MOV READ_TRACK,AX ;Store track to read for hard disk
535 MOV READ_SECTOR,DL ;Store sector to read for hard disk
536 MOV DISK_CMD_TRACK_OFF[BX],AL ;Set track to read for floppy
537 MOV DISK_CMD_SECTOR_OFF[BX],DL ;Set sector to read for floppy
538 MOV DISK_CMD_DMASEG_OFF[BX],CS ;Store segment of destination
539 MOV AX,MS_DOS_SEG ;Get segment for loading that code
************
************
File MSBOOT.OLD;1
420 MOV CL,DISK_CMD_DRIVE ;Get logical device being booted
******
File MSBOOT.ASM;1
548 ;
549 ; I/O system is loaded, and MS-DOS is loaded.
550 ; Jump to IO.SYS to initiate system.
551 ;
552 MOV CL,DISK_CMD_DRIVE ;Get logical device being booted
************
************
File MSBOOT.OLD;1
455 ; Reg BX -- Offset to string to be printed.
456 ; Reg CX -- Count of number of sectors to be read
457 ;
******
File MSBOOT.ASM;1
587 ; Reg BX -- Offset of command buffer to be used for read of floppy
588 ; Reg CX -- Count of number of sectors to be read
589 ; Reg ES:DI -- Address of buffer for storing data
590 ;
591 ; For floppy disks, track and sector must be stored in command buffer
592 ; For hard disks, track is in READ_TRACK, and sector is in READ_SECTOR
593 ;
************
************
File MSBOOT.OLD;1
460 ; None
461 ;
******
File MSBOOT.ASM;1
596 ; Carry set if read failed.
597 ; Carry clear if read succeeded.
598 ;
************
************
File MSBOOT.OLD;1
470 ; Device being booted is a floppy disk
471 ;
******
File MSBOOT.ASM;1
607 ; Device being booted is a floppy disk.
608 ;
************
************
File MSBOOT.OLD;1
476 CALL DECDISK ;Read sectors of floppy disk
******
File MSBOOT.ASM;1
613 ;
614 ; If this is a double-sided disk, then set the density to double-sided.
615 ;
616 MOV BYTE PTR DISK_CMD_DENSITY_OFF[BX],FDISK_RAINB
617 ;Set to single-density Rainbow
618 CMP NUM_SURFACES,1 ;See if double-sided disk
619 JZ FLOPPY_DISK_LOOP_READ ;If not, then just read disk
620 ;
621 ; This is a double-sided floppy disk.
622 ; Set the density.
623 ;
624 OR BYTE PTR DISK_CMD_DENSITY_OFF[BX],FDISK_DSIDE
625 ;Set double-sided density bit
626 ;
627 ; Now read the disk sectors
628 ;
629 FLOPPY_DISK_LOOP_READ:
630 CALL DECDISK ;Read sectors of floppy disk
************
************
File MSBOOT.OLD;1
516 ADD DI,H_SECTOR_SIZE ;Increment destination by sector size
517 CALL HD_NEXT_SECTOR ;Increment to next sector on disk
******
File MSBOOT.ASM;1
670 ADD DI,SECTOR_SIZE ;Increment destination by sector size
671 CALL HD_NEXT_SECTOR ;Increment to next sector on disk
************
************
File MSBOOT.OLD;1
559 ; Initialize the disk controller (software initialization)
******
File MSBOOT.ASM;1
713 ; Initialize known disk parameters
714 ;
715 MOV NUM_FAT_SECTORS,H_NUM_FAT_SECTORS
716 MOV NUM_FATS,H_NUM_FATS
717 MOV SECTOR_SIZE,H_SECTOR_SIZE
718 MOV CLUSTER_SIZE,H_CLUSTER_SIZE
719 MOV SECT_PER_TRACK,H_SECT_PER_TRACK
720 MOV NUM_SURFACES,H_NUM_SURFACES
721 MOV NUM_RESERVED_SECTORS,H_NUM_RESERVED_SECTORS
722 MOV NUM_DIR_SECTORS,H_NUM_DIR_SECTORS
723 ;
724 ; Initialize the disk controller (software initialization)
************
************
File MSBOOT.OLD;1
597 MOV AX,ES:HOM_DPDTRACK[BX] ;Get track of DPD block
******
File MSBOOT.ASM;1
762 XOR AX,AX ;Clear reg AX
763 MOV AL,ES:HOM_NOSURFACE[BX] ;Get number of surfaces on disk
764 MOV NUM_SURFACES,AL ;Store in memory
765 MOV AL,ES:HOM_SECPERTRK[BX] ;Get number of sectors on disk track
766 MOV SECT_PER_TRACK,AX ;Store in memory
767 MOV AX,ES:HOM_DPDTRACK[BX] ;Get track of DPD block
************
************
File MSBOOT.OLD;1
681 INC BYTE PTR DPD_SECTOR ;Increment to next DPD sector
682 JMP SHORT READ_DPD_BLOCK ;And read in that sector
******
File MSBOOT.ASM;1
851 INC DPD_SECTOR ;Increment to next DPD sector
852 JMP SHORT READ_DPD_BLOCK ;And read in that sector
************
************
File MSBOOT.OLD;1
687 MOV CX,DPD_PART_LTRACK[BX+SI] ;Get last track of partition
688 MOV BX,DPD_PART_FTRACK[BX+SI] ;Get last track of partition
689 CALL CALCULATE_NUMBER_OF_FAT_SECTORS ;And find number of FAT sectors
690 ;for this partition
691 ADD AX,48 ;Add number of reserved sectors
692 ;and sectors for directory
693 XOR DX,DX ;Clear upper word
694 MOV CX,H_MAX_SECT_PER_TRACK ;Get number of sectors per track
695 DIV CX ;Divide to get track and sector
696 INC DX ;Sectors start at 1, so increment sector
697 MOV READ_SECTOR,DL ;Store as sector number to read
698 ADD AX,BX ;Add first track to track number
699 MOV READ_TRACK,AX ;Store as track number to read
700 RET ;And return to caller
******
File MSBOOT.ASM;1
857 MOV CLUSTER_SIZE,H_CLUSTER_SIZE ;Set to number of sectors per cluster
858 MOV CX,DPD_PART_LTRACK[BX+SI] ;Get last track of partition
859 MOV BX,DPD_PART_FTRACK[BX+SI] ;Get first track of partition
860 MOV FIRST_PARTITION_TRACK,BX ;Save first partition track
861 CALL CALCULATE_NUMBER_OF_FAT_SECTORS ;And find number of FAT sectors
862 ;for this partition
863 PUSH AX ;Save number of FAT sectors found
864 SHR AX,1 ;Since there are 2 copies of the FAT,
865 ;divide to get no. of sectors per FAT
866 MOV NUM_FAT_SECTORS,AL ;Store number of FAT sectors found
867 POP AX ;Restore total number found
868
869 ADD AX,NUM_RESERVED_SECTORS ;Add number of reserved sectors
870 XOR DX,DX ;Clear upper word
871 DIV SECT_PER_TRACK ;Divide by number of sectors per track
872 ;to get track and sector
873 INC DX ;Sectors start at 1, so increment sector
874 MOV DIR_SECTOR,DL ;Store as sector number of directory
875 ADD AX,BX ;Add first track to track number
876 MOV DIR_TRACK,AX ;Store as track number of directory
877 RET ;And return to caller
************
************
File MSBOOT.OLD;1
722 ; Registers Changed: ALL except CS
723 ;
******
File MSBOOT.ASM;1
899 ; Registers Changed: AX, CX, DX, BP
900 ;
************
************
File MSBOOT.OLD;1
729 SHL CX,1 ;Multiply by number of sectors per track
730 SHL CX,1
731 SHL CX,1
732 SHL CX,1
733 MOV BP,2 ;Assume 2 FAT sectors
******
File MSBOOT.ASM;1
906 MOV AX,CX ;Move to reg AX
907 MUL SECT_PER_TRACK ;Multiply by number of sectors per track
908 MOV CX,AX ;Put back in reg CX
909 MOV BP,2 ;Assume 2 FAT sectors
************
************
File MSBOOT.OLD;1
739 SUB AX,H_NUM_RESERVED_SECTORS ;Subtract reserved sectors
740 SUB AX,BP ;Subtract number of FAT sectors
741 SHR AX,1 ;Divide by number of sectors per cluster
742 SHR AX,1
743 MOV BX,AX ;Store in reg BX
******
File MSBOOT.ASM;1
915 SUB AX,NUM_RESERVED_SECTORS ;Subtract reserved sectors
916 SUB AX,NUM_DIR_SECTORS ;Subtract directory sectors
917 SUB AX,BP ;Subtract number of FAT sectors
918 XOR DX,DX ;Clear upper word of double word
919 DIV CLUSTER_SIZE ;Divide by number of sectors per cluster
920 MOV BX,AX ;Store in reg BX
************
************
File MSBOOT.OLD;1
749 MOV BX,H_SECTOR_SIZE ;Get sector size of disk
750 XOR DX,DX ;Clear upper word of double word
******
File MSBOOT.ASM;1
926 MOV BX,SECTOR_SIZE ;Get sector size of disk
927 XOR DX,DX ;Clear upper word of double word
************
;
; Function: GET_IO_POSITION
;
; Abstract:
;
; Read the directory of the disk and find the starting track,
; starting sector, and number of sectors used by IO.SYS.
;
; Entry Parameters:
;
; DIR_TRACK -- Track number of first sector of directory
; DIR_SECTOR -- Sector number of first sector of directory
;
; Exit Parameters:
;
; Reg AX -- Track number of first sector of IO.SYS
; Reg CX -- Number of sectors in IO.SYS
; Reg DL -- Sector number of first sector of IO.SYS
;
; Registers Changed: All, except ES, DI
;
; Side Effects: Reads first sector of directory into READ_AREA
;
GET_IO_POSITION PROC NEAR
XOR AX,AX ;Set to no offset of directory
CALL GET_FILE_POSITION ;Read first sector of directory
RET ;And return to caller
;
GET_IO_POSITION ENDP ;End of procedure
;
;
; Function: GET_MSDOS_POSITION
;
; Abstract:
;
; Read the directory of the disk and find the starting track,
; starting sector, and number of sectors used by MSDOS.SYS.
;
; Entry Parameters:
;
; DIR_TRACK -- Track number of first sector of directory
; DIR_SECTOR -- Sector number of first sector of directory
;
; Exit Parameters:
;
; Reg AX -- Track number of first sector of MSDOS.SYS
; Reg CX -- Number of sectors in MSDOS.SYS
; Reg DL -- Sector number of first sector of MSDOS.SYS
;
; Registers Changed: All, except ES, DI
;
; Side Effects: Reads first sector of directory into READ_AREA
;
GET_MSDOS_POSITION PROC NEAR
MOV AX,32 ;Set to offset of second file
CALL GET_FILE_POSITION ;Read first sector of directory
ADD CX,2 ;Add 2 sectors just to be safe
RET ;And return to caller
;
GET_MSDOS_POSITION ENDP ;End of procedure
;
;
; Function: GET_FILE_POSITION
;
; Abstract:
;
; Read the first sector of the directory of the disk.
;
; Entry Parameters:
;
; Reg AX -- Offset to directory entry of interest in dir
; DIR_TRACK -- Track number of first sector of directory
; DIR_SECTOR -- Sector number of first sector of directory
;
; Exit Parameters:
;
; Reg AX -- Track number of first sector of file.
; Reg CX -- Number of sectors in file.
; Reg DL -- Sector number of first sector of file.
;
; Registers Changed: All, except ES, DI
;
; Side Effects:
;
; Save offset to directory entry
;
GET_FILE_POSITION PROC NEAR
PUSH ES ;Save reg ES
PUSH AX ;Save offset to directory entry
;
; Read the directory sector from disk
;
MOV DI,OFFSET READ_AREA ;Get address of buffer
MOV AX,CS ;Copy CS segment to ES
MOV ES,AX
MOV BX,OFFSET DISK_CMD_CMD ;Get address of command block
MOV AL,DIR_SECTOR ;Get sector number to directory
MOV DISK_CMD_SECTOR_OFF[BX],AL ;Store it in command block
MOV READ_SECTOR,AL ;Store in READ_SECTOR for hard disk
MOV AX,DIR_TRACK ;Get track of directory
MOV DISK_CMD_TRACK_OFF[BX],AL ;Store it in command block
MOV READ_TRACK,AX ;Store in READ_TRACK for hard disk
MOV CX,1 ;Set count to 1 sector
CALL READ_SECTORS ;Read sector of floppy disk
MOV SI,OFFSET READ_DIR_ERROR_MSG ;Get address of read error message
JNC GET_FILE_POSITION_110 ;If successful, continue
JMP PRINT_ERROR ;If error, print it and try again
;
; Have sector of directory -- get size and cluster of start of file
;
GET_FILE_POSITION_110:
MOV BX,OFFSET READ_AREA ;Get offset to first entry
;This should be IO.SYS
POP AX ;Restore offset to directory entry
ADD BX,AX ;Add offset to directory entry
MOV DX,[BX+30] ;Get upper word of size of file
MOV AX,[BX+28] ;Get lower word of size of file
DIV SECTOR_SIZE ;Divide by sector size
OR DX,DX ;See if any remainder
JZ GET_FILE_POSITION_130 ;If not, continue
INC AX ;Otherwise, increment to next sector
GET_FILE_POSITION_130:
MOV CX,AX ;Move number of sectors to reg CX
MOV AX,[BX+26] ;Get cluster number of entry
SUB AX,2 ;Subtract 2 since first data cluster
;is actually cluster 2
MUL CLUSTER_SIZE ;Multiply by cluster size to get sectors
ADD AX,NUM_RESERVED_SECTORS ;Add number of reserved sectors
ADD AX,NUM_DIR_SECTORS ;Add number of directory sectors
XOR DX,DX ;Clear reg DX
MOV DL,NUM_FAT_SECTORS ;Get the number of FAT sectors
ADD DX,DX ;Double it for 2 FATs
ADD AX,DX ;And add to get sector of file
;
; Now reg AX contains logical sector number of first sector of file.
; Convert this to sector and track number.
;
XOR DX,DX ;Clear upper word
DIV SECT_PER_TRACK ;Divide by number of sectors per track
INC DX ;Increment sector number to base at zero
ADD AX,FIRST_PARTITION_TRACK ;Add the track number of the
;first track of the partition
;
; That is all -- return to caller
;
POP ES ;Restore extra segment
RET ;Return to caller
;
GET_FILE_POSITION ENDP ;End of procedure