Code: Select all
SETUP_SECTS equ 4 ; default nr of setup-sectors
KERNEL_SECTS equ 128 ; default nr of kernel-sectors
SETUP_SEG equ 9000h ; setup start segment
SYS_SEG equ 1000h ; system begins with this segment
END_SEG equ 2000h ; end of system segment
org 07c00h
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov ax, 7c00h
mov sp, ax
call print_sth
call load_setup
call load_kernel
jmp $
; call kill_motor
jmp SETUP_SEG:0 ; SETUP_SEG = 0x9000
print_sth:
; print 'welcome to sparrow world!'
mov ax, msg_welm
mov bp, ax ; ES:BP = base of string
mov cx, 25 ; CX = length
mov ax, 01301h ; AH = 13, AL = 01h
mov bx, 000ch ; page 0(BH = 0) red word with black background (BL = 0Ch,high light)
mov dl, 25 ; line
int 10h
; int 10h: ah=3(read cursor pos), ah=A(print char in cursor pos), ah=13h(print string)
; read current cursor position
mov ah, 03h ; read cursor pos
xor bh, bh ; bh = page no.
int 10h ; return values in ch/cl, dh/dl
; print 'loading'
mov cx, 9 ; length of string
mov bx, 0007h ; page 0, attribute 7 (normal)
mov bp, msg_ld
mov ax, 1301h ; write string, cursor follows(al=1)
int 10h
ret
; INT 13h AH=02h: Read Sectors From Drive
; AH 02h
; DH Head
; DL Drive
; ES:BX Buffer Address Pointer
load_setup:
mov ah, 02h
mov al, SETUP_SECTS ; AL Sectors To Read Count
mov cx, 0002h ; CX Track + Sector
mov dx, 0000h
mov bx, SETUP_SEG
mov es, bx
sub bx, bx
int 13h
ret
load_kernel:
; There are actually four types of floppy disks classified by
; their capability, including 360KB, 720KB, 1.2MB, 1.44MB and 2.88MB.
; In the other way, they are classified into four types according to number of
; sectors per track, which are listed as follows:
; 2.88MB disks: Sectors/Track = 36
; 1.44MB disks: Sectors/Track = 18
; 1.2MB disks: Sectors/Track = 15
; 720KB/360KB disks: Sectors/Track = 9
check_sectors:
xor dx, dx ; drive 0, head 0
mov cx, 24h ; sector 36, track 0
mov bx, 7c00h + 200h ; address after boot (es = cs)
mov ax, 0201h ; service 2, 1 sector
int 13h
jnc got_sectors
mov cl, 12h ; sector 18
mov ax, 0201h ; service 2, 1 sector
int 13h
jnc got_sectors
mov cl, 0fh ; sector 15
mov ax, 0201h ; service 2, 1 sector
int 13h
jnc got_sectors
mov cl, 09h
got_sectors:
mov [sects_per_trk], cl
start_read2:
mov ax, SYS_SEG
mov es, ax
sub bx, bx
rp_read:
mov ax, [sects_per_trk]
sub ax, [sects]
mov cx, ax
shl cx, 9
add cx, bx
jnc read_remin
je read_remin
xor ax, ax
sub ax, bx
shr ax, 9
read_remin:
mov dx, [track]
mov cx, [sects]
inc cx
mov ch, dl
mov dx, [head]
mov dh, dl
mov dl, 0
and dx, 0100h
mov ah, 2
pushad
mov ah, 0eh
mov al, 2eh
mov bx, 7
int 10h
popad
int 13h
mov cl, al
mov ah, 0
add ax, [sects]
cmp ax, [sects_per_trk]
jne adjust_seg
mov dx, 1
sub dx, [head]
jnz org_head
inc byte [track]
org_head:
mov [head], dx
sub ax, ax
adjust_seg:
mov [sects], ax
mov ch, 0
shl cx, 9
add cx, bx
jnc rp_read
mov ax, es
add ax, 1000h
mov es, ax
sub bx, bx
cmp ax, END_SEG
jb rp_read
jmp $
ret
kill_motor:
push dx
mov dx, 03f2h
xor al, al
out dx, al
pop dx
ret
msg_welm: db "Welcome to sparrow world!"
msg_ld:
db 13
db 10
db "Loading"
sects_per_trk: dw 0
sects: dw 1 + SETUP_SECTS ; sectors that have been read already
head: dw 0 ; current head
track: dw 0 ; current track
times 510-($-$$) db 0