Category : HD Utilities
Archive   : BOOT11.ZIP
Filename : BOOT.ASM

 
Output of file : BOOT.ASM contained in archive : BOOT11.ZIP
PAGE 60,132
NAME BootSave
; [ - condensed Toshiba P351
TITLE BootSave BootRest BootChk Resuce Master boot sector
Comment |
Version 1.0 1991 Sept 23 Roedy Green
works with MASM 6.0 and Optasm

See Boot.TXT for details on use.

USAGE:

Examples:
*********

BootSave A:\MyBoot.Sav

BootRest A:\MyBoot.Sav

BootChk A:\ByBoot.Sav

Syntax errors or missing file trouble generates an ERRORLEVEL 4.
BootChk generates an ERRORLEVEL 1 if the Boot record has changed
since the BootSave was done.

Version History
***************

Version 1.1
- released to BIX 91/09/23
- simpler use, parallels CMOSSave

Version 1.0
- released to BIX 90/11/19

How to Assemble
***************

Manually set the GENERATING equate, then:

to assemble with MASM 6.0 use:
ML.EXE /AT /c /Fl /VM /Zf /Zm BOOT.Asm
LINK.EXE /TINY /MAP BOOT.Obj,BOOT.com,BOOT.map;

to assemble with OPTASM use:
Optasm BOOT.Asm,BOOT.Obj,BOOT.Lst/L/N/G/S
OLINK BOOT.Obj,BOOT.COM,/MAP/TINY;

| ; end of comment


; E Q U A T E S

BootSAVE EQU 1
BootREST EQU 2
BootCHK EQU 3

; use /DGenerating#BootSAVE
; /DGenerating#BootREST
; /DGenerating#BootCHK
; on the assembler command line to select which version
; of the code to assemble.
; Or add code following of the form:

GENERATING EQU BootSave


If Generating eq BootSave
%OUT Generating BootSave.Com
Endif

If Generating eq BootRest
%OUT Generating BootRest.Com
endif

If Generating eq BootChk
%OUT Generating BootChk.Com
endif
;==============================================================


stack segment stack ; keep MS link happy by providing null stack
stack ends

CODE SEGMENT PARA ; start off in code.

;==============================================================

data segment byte ; provide a separate DATA segment
; actually all come after the code

;==============================================================

; V A R I A B L E S


If Generating eq BootSave

BannerMsg DB '°±²Û BootSave 1.1 Û²±°',13d,10d
DB 13d,10d
DB 'Saves contents of hard disk master boot sector to a file on hard disk or floppy.',13,10
DB 'Copyright (c) 1991 Roedy Green Canadian Mind Products',13,10
DB 'May be freely distributed and used for any purpose except military.',13,10
DB 13,10
db '$'

UsageMsg DB '°±²Û Error Û²±°',7,13,10
DB 'Insert a formatted diskette.',13,10
DB 'then try:',13,10
DB 'BootSav A:\Boot.Sav',13,10
DB 'or if want to save on hard disk try:',13,10
DB 'BootSav C:\Boot.Sav',13,10
DB 'Read Boot.Txt to find how to use it properly.',13,10
db '$'

FileTroubleMsg DB '°±²Û Error Û²±°',7,13,10
DB 'Cannot create the disk file.',13,10
db '$'

HardMsg DB '°±²Û Error Û²±°',13,10
DB 'Hard disk failed.',13,10
db '$'


WorkedMsg DB 'Hard disk master boot sector successfully saved.',13,10
db '$'

EndIf


If Generating eq BootRest

BannerMsg DB '°±²Û BootRest 1.1 Û²±°',13d,10d
DB 13d,10d
DB 'Restores hard disk master boot sector from a BootSave file on hard disk or floppy.',13,10
DB 'Copyright (c) 1991 Roedy Green Canadian Mind Products',13,10
DB 'May be freely distributed and used for any purpose except military.',13,10
DB 13,10
db '$'

UsageMsg DB '°±²Û Error Û²±°',13,10
DB 'Insert the diskette you used for BootSave.',13,10
DB 'then try:',13,10
DB 'BootRest A:\Boot.Sav',13,10
DB 'or if the file is on hard disk try:',13,10
DB 'BootRest C:\Boot.Sav',13,10
DB 'Read Boot.Txt to find how to use it properly.',13,10
db '$'

GeomMsg DB '°±²Û Error Û²±°',13,10
DB 'The Boot.Sav file does not match the geometry of this hard disk.',13,10
DB 'Either you have a BootSave file from a different computer,',13,10
DB 'or you have changed the disk drive since you did the BootSave,',13,10
DB 'or your CMOS disk configuration is corrupted.',13,10
DB 'Your hard disk boot sector has been left as is.',13,10
DB '$'

FileTroubleMsg DB '°±²Û Error Û²±°',7,13,10
DB 'Cannot find/read the disk file.',13,10
db '$'

HardMsg DB '°±²Û Error Û²±°',13,10
DB 'Hard disk failed.',13,10
db '$'

WorkedMsg DB 'Hard disk master boot sector successfully restored',13,10
db '$'

EndIf

If Generating eq BootChk

BannerMsg DB '°±²Û BootChk 1.1 Û²±°',13d,10d
DB 13d,10d
DB 'Ensures hard disk master boot sector not corrupted or changed.',13,10
DB 'Copyright (c) 1991 Roedy Green Canadian Mind Products',13,10
DB 'May be freely distributed and used for any purpose except military.',13,10
DB 13,10
db '$'

UsageMsg DB '°±²Û Error Û²±°',7,13,10
DB 'Insert the diskette you used for BootSave.',13,10
DB 'then try:',13,10
DB 'BootChk A:\Boot.Sav',13,10
DB 'or if you have the file on hard disk try:',13,10
DB 'BootChk C:\Boot.Sav',13,10
DB 'Read Boot.TXT to find how to use it properly.',13,10
db '$'

FileTroubleMsg DB '°±²Û Error Û²±°',7,13,10
DB 'Cannot find/read the disk file.',13,10
db '$'

HardMsg DB '°±²Û Error Û²±°',13,10
DB 'Hard disk failed.',13,10
db '$'

GeomMsg DB '°±²Û Error Û²±°',13,10
DB 'The Boot.Sav file does not match the geometry of this hard disk.',13,10
DB 'Either you have a BootSave file from a different computer,',13,10
DB 'or you have changed the disk drive since you did the BootSave,',13,10
DB 'or your CMOS disk configuration is corrupted.',13,10
DB 'Try using CMOSREST to fix your CMOS.',13,10
DB '$'

MatchTroubleMsg DB '°±²Û Error Û²±°',7,13,10
DB 'Hard disk master boot sector has been corrupted!',13,10
db '$'

WorkedMsg DB 'Hard disk master boot sector is OK, i.e. unchanged since the last BootSave.',13,10
db '$'

EndIf


FilenamePtr DW 0
; pointer to filename in command line

CXSave DW 0 ; disk geometry from INT 13/08
DXSave DW 0 ; will be saved along with boot record

Buffer dw 0 ; dynamic buffer will grow to 512
; it hangs out past the end of the program

Buffer2 equ Buffer+512
; used to compare two versions of sector

data ends

com group code,data ; force data segment to go at the end

ASSUME CS:com,DS:com,ES:com,SS:com
; seg regs cover everything
ORG 100H ; in Code segment

;==========================

Main proc far

; M A I N L I N E R O U T I N E
Start:
lea dx,BannerMsg ; display the banner
Call Say
Call Parse ; get filename from command line

If Generating eq BootSave
call GetBoot ; fetch Boot to buffer
call SaveGeom ; save disk geometry as well
call WriteBoot ; write Boot contents to file
EndIf

If Generating eq BootRest
call ReadBoot ; read Boot contents from file
call CheckGeom ; make sure disk geometry matches
; safety check we have the right file.
call PutBoot ; store buffer to Boot
EndIf

If Generating eq BootChk
call ReadBoot ; read Boot contents from file
call CheckGeom ; make sure disk geometry matches
; safety check we have the right file.
call Duplicate ; make copy in Buffer2
call GetBoot ; get current boot into Buffer
call CompareBoot ; compare buffer with Buffer2
EndIf

lea dx,WorkedMsg ; crow about success
Call Say
Done:
mov ax,4c00h
int 21h ;normal termination

Main EndP

;===============================================================

Trouble proc near

FileTrouble:
Lea dx,FileTroubleMsg ; display file trouble
Call Say
Jmp Abort

SyntaxTrouble:
lea dx,UsageMsg ; display usage message
Call Say
Jmp Abort

HardTrouble:
lea dx,HardMsg ; display hard disk not responding
Call Say
Jmp Abort

If Generating ne BootSave

GeomTrouble:
Lea dx,GeomMsg ; display geometry trouble
Call Say
Jmp Abort

EndIf

If Generating eq BootChk

MatchTrouble:
lea dx,MatchTroubleMsg ; display Boot mismatch
call Say
mov ax, 4c01h ; ERRORLEVEL = 1
int 21h ; DIE

EndIf

abort:
; error exit
mov ax, 4c04h ; ERRORLEVEL = 4
int 21h ; DIE

Trouble endp

;===============================================================

MLeading PROC Near

; Remove leading blanks
; on entry BX is addr of string, CX its length
; trims off any leading blanks, leaving result in BX CX
; length may also be 0 or 1, but not -ve
; If the entire string is blank the result is the null string
mov di,bx
mov al,20H ; AL = blank -- the search char
jcxz mleading2 ; jump if null string
repe scasb ; scan ES:DI forwards till hit non blank
; DI points just after it (wrap ok)
; cx IS ONE TOO SMALL, OR 0 IF NONE FOUND
je mleading1 ; jump if entire string was blank
inc cx ; CX is length of remainder of string
mleading1:
dec di ; DI points to non-blank
mleading2:
mov bx,di ; put address back
ret

MLeading ENDP

;========================================

MTrailing PROC Near

; Remove trailing blanks.
; on entry BX is addr of string, CX its length
; trims off any trailing blanks, leaving result in BX CX
; length may also be 0 or 1, but not -ve
; If the entire string is blank the result is the null string
mov di,bx
add di,cx ; calc addr last char in string
dec di
mov al,20H ; AL = blank -- the search char
jcxz mtrailing1 ; jump if null string
std
repe scasb ; scan ES:DI backwards till hit non blank
; DI points just ahead of it (wrap ok)
; CX is one too small, or 0 if none found
cld
je mtrailing1 ; jump if whole string was blank
inc cx
mtrailing1:
ret

MTrailing ENDP

;========================================

Parse PROC NEAR
; Parse the command line to remove lead/trail blanks from
; the single drive parameter and terminate it by 2 nulls.
; sample inputs
; BootRest A:\MyBoot.SAV
; BootRest B:\MySub\MyBoot.SAV
;
; When Done DS:BX points to start of string.
; String will be terminated by 2 nulls
; CX counts bytes in string exclusive of nulls
; counted string at HEX 80 PSP
; contains command line.
; Preceeded by unwanted spaces.
; possibly followed by unwanted spaces.
; currently missing a trailing null.
xor ch,ch
mov cl,ds:80H
mov bx,81H
call Mleading ; get rid of leading blanks
call MTrailing ; get rid of trailing blanks
mov di,bx ; calc addr of byte just past end
add di,cx
mov word ptr [di],0 ; plop in pair of nulls after string
mov FileNamePtr,bx ; remember where filename was
jcxz SyntaxTrouble ; missing parm.
ret

Parse ENDP

;======================================

Say Proc

; on entry DX points to a string to display

MOV AH,9
Int 21h
ret

Say EndP

;======================================

If Generating ne BootRest

GetBoot Proc Near

; Read first sector, the boot block of hard disk C:

mov ah,02 ; function 2 read
mov dl,080h ; C:= 080h
mov dh,0 ; head 0
mov ch,0 ; cyl 0
mov cl,1 ; sector 1 is first
mov al,1 ; just 1 sector
lea bx,Buffer ; ES:BX is buffer
int 13h
jc HardTrouble
ret

GetBoot EndP

EndIf

;===============================================================

If Generating eq BootSave

SaveGeom Proc Near

; Save disk geometry (heads, cyls)
; We can later ensure we are restoring to a suitable disk

mov dx,0080h ; get drv parms for disk c:
mov ax,0800h ; ah 08 = get disk parameters
int 13h ; into CX/DX
mov CXSave,CX
mov DXSave,DX
ret

SaveGeom EndP

EndIf

;===============================================================

If Generating eq BootRest

PutBoot Proc Near

; Write first sector, the boot block of hard disk C:

mov ah,03 ; function 3 write
mov dl,080h ; 80h = C:
mov dh,0 ; head 0
mov ch,0 ; cyl 0
mov cl,1 ; sector 1 is first
mov al,1 ; just 1 sector
lea bx,Buffer ; ES:BX is buffer
int 13h
jc HardTrouble
ret

PutBoot EndP

EndIf

;===============================================================

If Generating eq BootChk

Duplicate Proc Near

; Make a duplicate copy of Buffer in Buffer2

lea si,Buffer
lea di,Buffer2
mov cx,512/2
rep movsw
ret

Duplicate EndP

EndIf

;===============================================================

If Generating eq BootChk

CompareBoot proc Near

; compares buffer version of Boot with contents of actual Boot
; Aborts if finds a mismatch

lea si,Buffer
lea di,Buffer2
mov cx,512/2
rep cmpsw
jne MatchTrouble
ret

CompareBoot EndP

EndIf

;===============================================================

If Generating ne BootSave

ReadBoot Proc Near

; Open a file read the Boot into a buffer

mov dx,FileNamePtr ; DS:DX point to file
xor al,al ; AL=0 is attribute read/only
mov ah,03Dh ; DOS open function
int 21h
jc FileTrouble
mov bx,ax ; save handle
mov cx,512+4 ; read CX DX + 1 sector
lea dx,CXSave ; buffer address
mov ah,3fH ; DOS read
int 21h
jc FileTrouble
cmp ax,512+4
jne FileTrouble
mov ah,3eh ; DOS close
int 21h
jc FileTrouble
ret

ReadBoot EndP

EndIf

;===============================================================

If Generating ne BootSave

CheckGeom Proc Near

; Check disk geometry (heads, cyls)
; Ensure we are restoring to a suitable disk

mov dx,0080h ; drive no. for c:
mov ax,0800h ; ah 08 = get disk parameters
int 13h ; into CX/DX
cmp CX,CXSave
jne GeomTrouble
cmp DX,DXSave
jne GeomTrouble
ret

CheckGeom EndP

EndIf

;===============================================================

if Generating eq BootSave

WriteBoot Proc Near

; Create a file write Boot to it

mov dx,FileNamePtr ; DS:DX point to file
xor cx,cx ; CX=0 is attribute
mov ah,03ch ; DOS create function
int 21h
jc FileTrouble
mov bx,ax ; save handle
mov cx,512+4 ; write CX/DXSave + 1 sector buffer
lea dx,CXSave ; buffer address
mov ah,40h ; DOS write
int 21h
jc FileTrouble
cmp ax,512+4
jne FileTrouble
mov ah,3eh ; DOS close
int 21h
jc FileTrouble
ret

WriteBoot EndP

EndIf

;===============================================================

CODE ends ; end of code segment
end Start


  3 Responses to “Category : HD Utilities
Archive   : BOOT11.ZIP
Filename : BOOT.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/