mov ax, 0x07C0
mov ds, ax
mov es, ax

start:
	mov si, begin	;Start message
	call print

	mov si, floppy	;Tell user FDC is being reset
	call print

	call reset	;Reset FDC

	mov si, sectors	;Tell user sectors are being read
	call print

	call read	;Read sector(s) into memory

	mov si, memjump	;Tell user about to jump to program
	call print

	jmp 0x1000	;Jump to address

	
	mov si, halt	;In case, for some reason, it ever
	call print	;gets this far, which it probably won't
	hlt

print:
	lodsb
	
	or al, al
	jz. done

	mov ah, 0x0E
	int 10
	
	jmp print

.done:
	ret


reset:
	mov dl, 0x0	;Function
	mov dl, 0x0	;Drive number

	int 0x13
	jc reset	;Error, try again

	mov si, done	;Tell user it has finished
	call print

	ret

read:
	mov ax, 0x1000	;Load sectors to this address

	mov es, ax	;Not really sure what these are for
	xor bx, bx	

	mov ah, 0x02	;Function 2
	mov al, 5	;Number of sectors to load
	mov ch, 1	;Cyclinder number
	mov cl, 1	;Sector 2
	mov dh, 0	;Head 0
	mov dl, 0	;Drive 0
	int 0x13	;Interrupt

	jc read		;Error, try again

	mov si, done	;Tell user it has finished
	call print
	
	ret

;Text data

begin db 'Bootloader', 0x0D, 0x0A, 0x0D, 0x0A, 0	;2 lines
floppy db 'Resetting FDC...', 0
sectors db 'Reading sector(s) into memory @ 0x1000...', 0
done db 'Done!', 0x0D, 0x0A, 0
halt db 'Processor Halted!', 0
memjump db 'Jumping to program @ 0x1000', 0x0D, 0x0A, 0