
.286c

bootstart equ     7C00h

data_3e         equ     7D96h                   
data_4e         equ     7DA1h                   
data_5e         equ     7DFBh                   
data_6e         equ     7DFCh                   
data_7e         equ     7DFDh                   

hddboot         segment byte public
                assume cs:hddboot , ds:hddboot
                jmp  short hddcode
                nop

hddcode:
		xor	cx,cx			; Zero register
		mov	ss,cx
		mov	sp,7BF0h
		mov	ds,cx
		mov	ax,2000h
		mov	es,ax
		cld				; Clear direction
                mov     bp,bootstart
		cmp	[bp+24h],cl
		jge	loc_4			; Jump if > or =
		mov	ax,cx
		cwd				; Word to double word
		call	sub_2
		jc	loc_4			; Jump if carry Set
		sub	bx,3Ah
		db	 66h,0A1h, 1Ch, 7Ch
loc_2:
		db	 26h, 66h, 3Bh, 07h, 26h, 8Ah
		db	 57h,0FCh, 75h, 06h, 80h,0CAh
		db	 02h, 88h, 56h, 02h
		db	 80h,0C3h, 10h, 73h,0EBh
loc_4:
		xor	cx,cx			; Zero register
		mov	al,[bp+10h]
		cbw				; Convrt byte to word
		mul	word ptr [bp+16h]	; ax = data * ax
		add	ax,[bp+1Ch]
		adc	dx,[bp+1Eh]
		add	ax,[bp+0Eh]
		adc	dx,cx
		mov	si,[bp+11h]
		pusha				; Save all regs
		mov	[bp-4],ax
		mov	[bp-2],dx
		mov	ax,20h
		mul	si			; dx:ax = reg * ax
		mov	bx,[bp+0Bh]
		add	ax,bx
		dec	ax
		div	bx			; ax,dx rem=dx:ax/reg
		add	[bp-4],ax
		adc	[bp-2],cx
		popa				; Restore all regs
loc_5:
		mov	di,0
		call	sub_2
		jc	loc_11			; Jump if carry Set
loc_6:
		cmp	es:[di],ch
		je	loc_7			; Jump if equal
		pusha				; Save all regs
		mov	cl,0Bh
		mov	si,data_4e
		repe	cmpsb			; Rep zf=1+cx >0 Cmp [si] to es:[di]
		popa				; Restore all regs
		jz	loc_13			; Jump if zero
		dec	si
		jz	loc_7			; Jump if zero
		add	di,20h
		cmp	di,bx
		jb	loc_6			; Jump if below
		jmp	short loc_5
loc_7:
		mov	al,ds:data_5e
loc_8:
		mov	ah,7Dh			; '}'
		mov	si,ax
loc_9:
		lodsb				; String [si] to al
		cbw				; Convrt byte to word
		inc	ax
		jz	loc_10			; Jump if zero
		dec	ax
		jz	loc_12			; Jump if zero
		mov	ah,0Eh
		mov	bx,7
		int	10h			; Video display   ah=functn 0Eh
						;  write char al, teletype mode
		jmp	short loc_9
loc_10:
		mov	al,ds:data_7e
		jmp	short loc_8
loc_11:
		mov	al,ds:data_6e
		jmp	short loc_8
loc_12:
		int	16h			; ??INT Non-standard interrupt
		int	19h			; Bootstrap loader
loc_13:
		mov	dx,es:[di+1Ah]
		push	dx
		mov	al,1
		mov	bx,0
		call	sub_1
		jc	loc_11			; Jump if carry Set
		pop	bx
		mov	dl,[bp+24h]
		mov	si,7C0Bh
		mov	di,sp
		mov	word ptr [bp-10h],7D3Dh
		mov	word ptr [bp-0Ch],7D29h
		mov	cx,ds
		mov	[bp-0Eh],cx
		mov	[bp-0Ah],cx
		mov	byte ptr ds:data_3e,0CBh
              jmp     far ptr loc_1           
		db	0EAh, 03h, 00h, 00h, 20h
		db	 0Fh,0B6h,0C8h, 66h, 8Bh, 46h
		db	0F8h, 66h, 03h, 46h, 1Ch, 66h
		db	 8Bh,0D0h, 66h,0C1h,0EAh, 10h
		db	0EBh
		db	5Eh

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

sub_1		proc	near
		db	 0Fh,0B6h,0C8h, 4Ah, 4Ah, 8Ah
		db	 46h, 0Dh, 32h,0E4h,0F7h,0E2h
		db	 03h, 46h,0FCh, 13h, 56h,0FEh
		db	0EBh
		db	4Ah
		db	 52h, 50h, 06h, 53h, 6Ah, 01h
		db	 6Ah, 10h, 91h, 8Bh, 46h, 18h
		db	 96h, 92h, 33h,0D2h,0F7h,0F6h
		db	 91h,0F7h,0F6h, 42h, 87h,0CAh
		db	0F7h, 76h, 1Ah, 8Ah,0F2h, 8Ah
		db	0E8h,0C0h,0CCh, 02h, 0Ah,0CCh
		db	0B8h, 01h, 02h, 80h, 7Eh, 02h
		db	 0Eh, 75h, 04h,0B4h, 42h, 8Bh
		db	0F4h
loc_15:
		mov	dl,[bp+24h]
		int	13h			; Disk  dl=drive ?  ah=func 0Eh
						;  read sector buffer into es:bx
		popa				; Restore all regs
		popa				; Restore all regs
		jc	loc_ret_17		; Jump if carry Set
		inc	ax
		jnz	loc_16			; Jump if not zero
		inc	dx
loc_16:
		add	bx,[bp+0Bh]
		dec	cx
		jnz	$+8			; Jump if not zero
		clc				; Clear carry flag

loc_ret_17:
		retn
sub_1		endp


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

sub_2		proc	near
		inc	cx
		mov	bx,0
		pusha				; Save all regs
                db 66h, 6Ah, 00h, 0EBh, 0B0h
                db 'NXBIO   SYS', 0Dh, 0Ah
                db 'NXBIO is missing'
		db	0FFh
                db 0Dh, 0Ah, 'Disk error'
		db	0FFh
                db 0Dh, 0Ah, 'Press any key to restart', 0Dh, 0Ah
		db	0
		db	18 dup (0)
                db      0ACh,0BFh,0CCh

ROMID db 55h, 0AAh, 00h
sub_2		endp


hddboot           ends



		end
