                .286c

boot            segment byte public
                assume  cs:boot, ds:boot


		org	0

mswin41         proc    far

start:
                jmp     short abbootcode
		db	90h

_MSWIN41 EQU 1

include \nxdos\src\boot\metakern.bpb

abbootcode:

	cli
	xor  cx, cx
	mov  ss, cx
	mov  sp, offset BOOT ; 7bf8
	mov  es, cx
	; DISk param block
	mov  bp, 0078
	lds  si, [bp+00]
	push ds
	push si
	push ss
	push bp
	mov  di, 0522h
	mov  [bp+00], di
	mov  [bp+02], cx
	mov  cl, 0bh
	cld
	repz movsb
	
	mov  ds, cx
	mov  bp, 7c00h
	mov  byte ptr [di-02], 0fh
	mov  ax, [bp+18h]
	mov  [di-07], al
	cmp  [bp+40h], cl
	jge  H7cb5
	mov  ax, cx
	cwd
	mov  bx, 0700h
	call readmbr    ; 7d30
	jb   H7cb5      ; or jc 
	sub  bx, 3ah
	; mov  eax, ds:7c1c
H7ca2:
	; cmp  eax, [bx]
	mov  dl, [bx-04] ; MOV     DL,0E	
	jnz  H7cb0  ; the boot code is forced to always use Extended INT 13 
	or   dl, 02
	mov  [bp+02], dl ; ([7C00+2] -> 02h) This FLAG indicate EXT. INT 13                 
H7cb0:
	add  bl, 10h
	jnb  H7ca2	
H7cb5:
	mov  di, 0002
	cmp  word ptr [bp+16], 0
        jnz  reboot    ; 7d03
       
	
KEYB:   
        int  16h
REBOOT: 
        int  19h

READMBR proc 
	inc  cx ; CX = 1 (sector) for MBR
READDISK proc 
bcrdisk:
	push si
        push 0000
        push 0000 ; dword ptr 0
	push dx
	push ax
	push es
	push bx
	push 1
	push 10
	mov  si, sp
	pusha
	cmp  byte ptr [bp+02], 0eh
	jnz  bcrdsk     ; 7d4a ;  jne -> jump if not equal
        mov  ah, 42h
	jmp  bcint13    ; 7d67
bcrdsk: 
        xchg cx, ax
	xchg dx, ax
	xor  dx, dx
	div  word ptr [bp+18h]     
	xchg cx, ax
	div  word ptr [bp+18h]
	inc  dx
	xchg cx, dx
	div  word ptr [bp+1ah]
      	mov  dh, dl             ; DH = Head Number,
	mov  ch, al             ; CH = Cylinder  
	ror  ah, 02             ; rotate right 2 bits 
	or   cl, ah             ; cl = sector
	mov  ax, 0201h
bcint13:	
	mov  dx, [bp+40h]       ; DL = Drive
	int  13h                ; Read sector(s) into memory at ES:BX 
	
	popa
	lea  sp, [si+10h]
	pop  si
	jb   bcrd_x
	inc  ax
	jnz  bc7d77
	inc  dx
bc7d77:
	add  bx, [bp+0bh]
	dec  cx
	jnz  bcrdisk
bcrd_x:	ret
READDISK endp

READMBR endp

BOOTDATA:
        db 13h, 18h, 01h, 27h
Invalid_sysdisk_msg	db 'Invalid system disk',0ffh,0dh,0ah
Disk_IO_error_msg       db 'Disk I/O error',0ffh,0dh,0ah
Replace_disk_msg        db 'Replace the disk, and then press any key...',0ffh,0dh,0ah
			dw 0
IO_SYS                  db 'IO      SYS'
MSDOS_SYS               db 'MSDOS   SYS'
                        db 7eh, 01h, 0
WINBOOT_SYS             db 'WINBOOT SYS',0,0

CodeSize        EQU $-start          ; org boot+200h-2
padding         db (512-CodeSize-2) dup(0)
bootsignature   db 55h,0aah

MSWIN41 endp

boot           ends



		end	start
