  
PAGE  59,132
  
;==========================================================================
;==								         ==
;==			        BF				         ==
;==								         ==
;==      Created:   20-Mar-94					         ==
;==      Code type: zero start					         ==
;==      Passes:    5	       Analysis Flags on: HIK		         ==
;==								         ==
;==========================================================================
  
  
seg_a		segment
		assume	cs:seg_a, ds:seg_a, es:seg_a, ss:seg_a

		org	7C00h

;==========================================================================
;
;			External Entry Point
;
;==========================================================================
  
Entry_point:
		jmp	short main
		db	90h			; (nop)
OEM_ID		db	'MSDOS5.0'
Bytes_per_sect	dw	200h
Sects_per_clu	db	1
Reserved_sects	dw	1
Number_FATs	db	2
Rootdir_entries	dw	0E0h
Tot_num_sect	dw	0B40h
Media_descr	db	0F0h
Sects_per_FAT	dw	9
Sects_per_Track	dw	12h
Number_Heads	dw	2
N_Hidden_Sects	dd	00000h
D_T_Num_Sects	dd	00000h
data_7C24	db	0
data_7C25	db	0
		db	29h, 1Eh, 10h, 38h, 1Ch
		db	'NO NAME    FAT12   '
main:
		cli				; Disable interrupts
		xor	ax,ax			; Zero register
		mov	ss,ax
		mov	sp,7C00h
		push	ss
		pop	es
		mov	bx,78h			; interrupt vector 1Eh
		lds	si,dword ptr ss:[bx]	; contains the BPB address
		push	ds
		push	si
		push	ss
		push	bx
		mov	di,7C3Eh		;
		mov	cx,0Bh			; move 13 bytes
		cld				; direction upward
		rep	movsb			; Rep cx times [si] to es:[di]
		push	es
		pop	ds
		mov	byte ptr [di-2],0Fh
		mov	cx,Sects_per_Track	; (6B40:7C18=12h)
		mov	[di-7],cl
		mov	[bx+2],ax
		mov	word ptr [bx],7C3Eh
		sti				; Enable interrupts
		int	13h			; Disk  dl=drive #: ah=func a0h
						;  reset disk, al=return status
		jc	Error			; Jump if carry Set
		xor	ax,ax			; Zero register
		cmp	Tot_num_sect,ax		; (6B40:7C13=0B40h)
		je	loc_7C84		; Jump if equal
		mov	cx,Tot_num_sect		; (6B40:7C13=0B40h)
		mov	word ptr D_T_Num_Sects,cx	; (6B40:7C20=0)
loc_7C84:
		mov	al,Number_FATs		; (6B40:7C10=2)
		mul	Sects_per_FAT		; (6B40:7C16=9) ax = data * ax
		add	ax,word ptr N_Hidden_Sects	; (6B40:7C1C=0)
		adc	dx,word ptr N_Hidden_Sects+2	; (6B40:7C1E=0)
		add	ax,Reserved_sects	; (6B40:7C0E=1)
		adc	dx,0
		mov	word ptr ds:[7C50h],ax	; (=5316h)
		mov	word ptr ds:[7C52h],dx	; (=3EBFh)
		mov	word ptr ds:[7C49h],ax	; (=78h)
		mov	word ptr ds:[7C4Bh],dx	; (=0C536h)
		mov	ax,20h
		mul	Rootdir_entries		; (6B40:7C11=0E0h) ax = data * ax
		mov	bx,Bytes_per_sect	; (6B40:7C0B=200h)
		add	ax,bx
		dec	ax
		div	bx			; ax,dx rem=dx:ax/reg
		add	word ptr ds:[7C49h],ax	; (=78h)
		adc	word ptr ds:[7C4Bh],0	; (=0C536h)
		mov	bx,500h
		mov	dx,word ptr ds:[7C52h]	; (=3EBFh)
		mov	ax,word ptr ds:[7C50h]	; (=5316h)
		call	sub_7D60
		jc	Error			; Jump if carry Set
		mov	al,1
		call	sub_7D81
		jc	Error			; Jump if carry Set
		mov	di,bx
		mov	cx,0Bh
		mov	si,7DE0h
		repe	cmpsb			; Rep zf=1+cx >0 Cmp [si] to es:[di]
		jnz	Error			; Jump if not zero
		lea	di,[bx+20h]		; Load effective addr
		mov	cx,0Bh
		repe	cmpsb			; Rep zf=1+cx >0 Cmp [si] to es:[di]
		jz	loc_7D05		; Jump if zero
Error:
		mov	si,7D9Eh
		call	sub_7D52
		xor	ax,ax			; Zero register
		int	16h			; Keyboard i/o  ah=function 00h
						;  get keybd char in al, ah=scan
		pop	si
		pop	ds
		pop	word ptr [si]
		pop	word ptr [si+2]
		int	19h			; Bootstrap loader
loc_7D00:
		pop	ax
		pop	ax
		pop	ax
		jmp	short Error
loc_7D05:
		mov	ax,[bx+1Ah]
		dec	ax
		dec	ax
		mov	bl,Sects_per_clu	; (6B40:7C0D=1)
		xor	bh,bh			; Zero register
		mul	bx			; dx:ax = reg * ax
		add	ax,word ptr ds:[7C49h]	; (=78h)
		adc	dx,word ptr ds:[7C4Bh]	; (=0C536h)
		mov	bx,700h
		mov	cx,3
  
locloop_7D20:
		push	ax
		push	dx
		push	cx
		call	sub_7D60
		jc	loc_7D00		; Jump if carry Set
		mov	al,1
		call	sub_7D81
		pop	cx
		pop	dx
		pop	ax
		jc	Error			; Jump if carry Set
		add	ax,1
		adc	dx,0
		add	bx,Bytes_per_sect	; (6B40:7C0B=200h)
		loop	locloop_7D20		; Loop if cx > 0
  
		mov	ch,Media_descr		; (6B40:7C15=0F0h)
		mov	dl,data_7C24		; (=0)
		mov	bx,word ptr ds:[7C49h]	; (=78h)
		mov	ax,word ptr ds:[7C4Bh]	; (=0C536h)
;*		jmp	far ptr l_0070_0000	;*
		db	0EAh, 0, 0, 70h, 0
  
;==========================================================================
;			       SUBROUTINE
;==========================================================================
  
sub_7D52	proc	near
loc_7D52:
		lodsb				; String [si] to al
		or	al,al			; Zero ?
		jz	loc_ret_7D80		; Jump if zero
		mov	ah,0Eh
		mov	bx,7
		int	10h			; Video display   ah=functn 0Eh
						;  write char al, teletype mode
		jmp	short loc_7D52

;==== External Entry into Subroutine ======================================

sub_7D60:
		cmp	dx,Sects_per_Track	; (6B40:7C18=12h)
		jae	loc_7D7F		; Jump if above or =
		div	Sects_per_Track		; (6B40:7C18=12h) ax,dxrem=dx:ax/data
		inc	dl
		mov	byte ptr ds:[7C4Fh],dl	; (=56h)
		xor	dx,dx			; Zero register
		div	Number_Heads		; (6B40:7C1A=2) ax,dxrem=dx:ax/data
		mov	data_7C25,dl		; (=0)
		mov	word ptr ds:[7C4Dh],ax	; (=1E37h)
		clc				; Clear carry flag
		retn
loc_7D7F:
		stc				; Set carry flag

loc_ret_7D80:
		retn
sub_7D52	endp


;==========================================================================
;			       SUBROUTINE
;==========================================================================

sub_7D81	proc	near
		mov	ah,2
		mov	dx,word ptr ds:[7C4Dh]	; (=1E37h)
		mov	cl,6
		shl	dh,cl			; Shift w/zeros fill
		or	dh,byte ptr ds:[7C4Fh]	; (=56h)
		mov	cx,dx
		xchg	ch,cl
		mov	dl,data_7C24		; (=0)
		mov	dh,data_7C25		; (=0)
		int	13h			; Disk  dl=drive #: ah=func a2h
						;  read sectors to memory es:bx
		retn
sub_7D81	endp
  		db	0Dh, 0Ah, 'Disque non-syst',8Ah,'me/erreur disque'
		db	0Dh, 0Ah, 'Remplacez et pressez touche', 0Dh, 0Ah
		db	0
		db	'IO      SYS'
		db	'MSDOS   SYS'
		db	8 dup(0)
		db	55h, 0AAh	; Boot sector Signature.

seg_a		ends

		end
