2019-03-25 09:51:37 +01:00
|
|
|
org 0x7C00
|
|
|
|
|
2019-03-27 23:05:00 +01:00
|
|
|
fdc: ; FDC Descriptor as per ECMA-107
|
|
|
|
jmp _startup
|
|
|
|
times (0x03 - ($-$$)) nop
|
2019-03-25 09:51:37 +01:00
|
|
|
.oem:
|
2019-03-27 23:05:00 +01:00
|
|
|
db "2B" ; creating system identifier
|
|
|
|
times (0x0B - ($-$$)) db " " ; space-padded
|
|
|
|
.ss:
|
|
|
|
dw 0x200 ; sector size
|
|
|
|
.sc:
|
|
|
|
db 0 ; sectors per cluster
|
|
|
|
.rsc:
|
|
|
|
dw 2 ; reserved sector count
|
|
|
|
.fn:
|
|
|
|
db 0 ; number of file allocation tables
|
|
|
|
.rde:
|
|
|
|
dw 0 ; number of root directory entries
|
|
|
|
.ts_old:
|
|
|
|
dw 0 ; legacy: total number of sectors
|
|
|
|
.mi: ; medium identifier
|
2019-03-25 09:51:37 +01:00
|
|
|
db 0xFD ; 5.25-inch Double sided, 40 tracks per side, 9 sectors per track (360 KB)
|
2019-03-27 23:05:00 +01:00
|
|
|
.sf: ; sectors per fat
|
2019-03-25 09:51:37 +01:00
|
|
|
dw 0
|
|
|
|
.spt:
|
|
|
|
dw 9 ; sectors per track
|
2019-03-27 23:05:00 +01:00
|
|
|
.nos:
|
|
|
|
dw 2 ; number of sides (heads)
|
|
|
|
.po:
|
|
|
|
dd 0 ; partition offset (in LBA blocks)
|
|
|
|
.ts:
|
|
|
|
dw 720
|
|
|
|
.drv:
|
2019-03-26 21:46:40 +01:00
|
|
|
db 0 ; drive number
|
|
|
|
db 0
|
2019-03-27 23:05:00 +01:00
|
|
|
db 0x29 ; efdc signature
|
|
|
|
.vid:
|
|
|
|
dd 0 ; volume id
|
|
|
|
.vlabel:
|
|
|
|
db "2B"
|
|
|
|
times (54 - ($-$$)) db " "
|
|
|
|
.fstype:
|
|
|
|
db "FAT12"
|
|
|
|
times (62 - ($-$$)) db " "
|
2019-03-25 09:51:37 +01:00
|
|
|
|
|
|
|
_startup:
|
2019-03-27 23:05:00 +01:00
|
|
|
mov [fdc.drv], dl ; backup driver number
|
|
|
|
mov ah, 0x08
|
|
|
|
int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15
|
|
|
|
jc .noadjust ; skip if function does not exist
|
|
|
|
inc dh
|
|
|
|
mov [fdc.nos], dh
|
|
|
|
mov ax, cx
|
|
|
|
and ax, 0x003F
|
|
|
|
mov [fdc.spt], ax ; no adjustment because sectors are 1-indexed
|
|
|
|
mov ax, cx
|
|
|
|
xchg al, ah
|
|
|
|
mov cl,6
|
|
|
|
shr ah,cl
|
|
|
|
inc ax ; convert from maximum number (0-based) to total number (1-based) of cylinders
|
|
|
|
mul word [fdc.nos] ; number of tracks = number of cylinders * heads
|
|
|
|
mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track
|
|
|
|
mov [fdc.ts], ax
|
|
|
|
.noadjust:
|
2019-03-26 21:46:40 +01:00
|
|
|
mov ax, 0x0500
|
|
|
|
mov es, ax
|
2019-03-27 23:05:00 +01:00
|
|
|
mov bx, 0x0000
|
|
|
|
mov ax, 1
|
2019-03-26 21:46:40 +01:00
|
|
|
call loadblk
|
|
|
|
call dump
|
2019-03-27 23:05:00 +01:00
|
|
|
|
|
|
|
mov al, [fdc.sc]
|
|
|
|
call print8
|
2019-03-26 21:46:40 +01:00
|
|
|
.end:
|
|
|
|
hlt
|
|
|
|
jmp .end
|
|
|
|
|
2019-03-27 23:05:00 +01:00
|
|
|
; Load a cluster from cluster offset
|
|
|
|
loadcluster:
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Load a single cluster into memory
|
|
|
|
; in ax sector number
|
|
|
|
; es:bx buffer
|
|
|
|
; out al error code,
|
|
|
|
; carry set if error
|
|
|
|
loadblk:
|
|
|
|
xor dx, dx
|
|
|
|
div word [fdc.spt] ; ax:temp = (lba / spt)
|
|
|
|
inc dx ; dx:sector = (lba % spt) + 1
|
|
|
|
mov cl, dl ; sector number
|
|
|
|
xor dx, dx
|
|
|
|
div word [fdc.nos] ; ax:cylinder = (tmp / heads)
|
|
|
|
; dx:head = (tmp % heads)
|
|
|
|
mov ch, al ; cylinder number
|
|
|
|
mov dh, dl ; head number
|
|
|
|
mov dl, [fdc.drv] ; driver number
|
|
|
|
mov ax, 0x0201 ; ah=0x02 al=0x01
|
|
|
|
int 0x13
|
|
|
|
ret
|
|
|
|
|
2019-03-26 21:46:40 +01:00
|
|
|
dump:
|
|
|
|
mov si, 0x0000
|
|
|
|
mov cx, 0x10
|
|
|
|
.nextline:
|
|
|
|
mov ax, si
|
|
|
|
call print16
|
|
|
|
mov al, 0x3A
|
|
|
|
call printc
|
|
|
|
mov al, 0x20
|
|
|
|
call printc
|
|
|
|
|
|
|
|
push cx
|
|
|
|
mov cx, 0x0020
|
|
|
|
.words:
|
|
|
|
es lodsb
|
|
|
|
call print8
|
|
|
|
loop .words
|
|
|
|
pop cx
|
|
|
|
|
|
|
|
mov al, 0x0A
|
|
|
|
call printc
|
|
|
|
mov al, 0x0D
|
|
|
|
call printc
|
|
|
|
|
|
|
|
loop .nextline
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2019-03-25 09:51:37 +01:00
|
|
|
%include "print.asm"
|
|
|
|
|
|
|
|
times (0x1FE - ($-$$)) nop
|
|
|
|
dw 0xAA55
|