2000-05-06 21:34:20 +02:00
|
|
|
;
|
|
|
|
; File:
|
|
|
|
; floppy.asm
|
|
|
|
; Description:
|
|
|
|
; floppy disk driver primitives
|
|
|
|
;
|
|
|
|
; Copyright (c) 1995
|
|
|
|
; Pasquale J. Villani
|
|
|
|
; All Rights Reserved
|
|
|
|
;
|
|
|
|
; This file is part of DOS-C.
|
|
|
|
;
|
|
|
|
; DOS-C is free software; you can redistribute it and/or
|
|
|
|
; modify it under the terms of the GNU General Public License
|
|
|
|
; as published by the Free Software Foundation; either version
|
|
|
|
; 2, or (at your option) any later version.
|
|
|
|
;
|
|
|
|
; DOS-C is distributed in the hope that it will be useful, but
|
|
|
|
; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
|
|
|
; the GNU General Public License for more details.
|
|
|
|
;
|
|
|
|
; You should have received a copy of the GNU General Public
|
|
|
|
; License along with DOS-C; see the file COPYING. If not,
|
|
|
|
; write to the Free Software Foundation, 675 Mass Ave,
|
|
|
|
; Cambridge, MA 02139, USA.
|
|
|
|
;
|
|
|
|
; $Id$
|
|
|
|
;
|
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
%include "../kernel/segs.inc"
|
|
|
|
segment HMA_TEXT
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
; BOOL ASMPASCAL fl_reset(WORD drive);
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
; Reset both the diskette and hard disk system.
|
|
|
|
; returns TRUE if successful.
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
|
|
|
|
2004-04-09 15:11:25 +02:00
|
|
|
global FL_RESET
|
|
|
|
FL_RESET:
|
2003-09-15 12:53:09 +02:00
|
|
|
pop ax ; return address
|
2004-06-19 21:41:47 +02:00
|
|
|
pop dx ; drive (DL only)
|
2004-04-09 15:11:25 +02:00
|
|
|
push ax ; restore address
|
2004-06-18 08:57:33 +02:00
|
|
|
mov ah,0 ; BIOS reset diskette & fixed disk
|
|
|
|
int 13h
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
sbb ax,ax ; carry set indicates error, AX=-CF={-1,0}
|
|
|
|
inc ax ; ...return TRUE (1) on success,
|
|
|
|
ret ; else FALSE (0) on failure
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
; COUNT ASMPASCAL fl_diskchanged(WORD drive);
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
; Read disk change line status.
|
|
|
|
; returns 1 if disk has changed, 0 if not, 0xFFFF if error.
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
|
|
|
|
2004-04-09 15:11:25 +02:00
|
|
|
global FL_DISKCHANGED
|
|
|
|
FL_DISKCHANGED:
|
2003-09-15 12:53:09 +02:00
|
|
|
pop ax ; return address
|
2004-06-18 08:57:33 +02:00
|
|
|
pop dx ; drive (DL only, 00h-7Fh)
|
2004-04-09 15:11:25 +02:00
|
|
|
push ax ; restore stack
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
push si ; preserve value
|
|
|
|
mov ah,16h ; read change status type
|
2004-04-09 15:11:25 +02:00
|
|
|
xor si,si ; RBIL: avoid crash on AT&T 6300
|
2004-06-18 08:57:33 +02:00
|
|
|
int 13h
|
|
|
|
pop si ; restore
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
sbb al,al ; AL=-CF={-1,0} where 0==no change
|
|
|
|
jnc fl_dc ; carry set on error or disk change
|
|
|
|
cmp ah,6 ; if AH==6 then disk change, else error
|
|
|
|
jne fl_dc ; if error, return -1
|
|
|
|
mov al, 1 ; set change occurred
|
2004-06-19 21:41:47 +02:00
|
|
|
fl_dc: cbw ; extend AL into AX, AX={1,0,-1}
|
2004-06-18 08:57:33 +02:00
|
|
|
ret ; note: AH=0 on no change, AL set above
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
; Format tracks (sector should be 0).
|
|
|
|
; COUNT ASMPASCAL fl_format(WORD drive, WORD head, WORD track, WORD sector, WORD count, UBYTE FAR *buffer);
|
2000-05-06 21:34:20 +02:00
|
|
|
; Reads one or more sectors.
|
2004-06-18 08:57:33 +02:00
|
|
|
; COUNT ASMPASCAL fl_read (WORD drive, WORD head, WORD track, WORD sector, WORD count, UBYTE FAR *buffer);
|
2000-05-06 21:34:20 +02:00
|
|
|
; Writes one or more sectors.
|
2004-06-18 08:57:33 +02:00
|
|
|
; COUNT ASMPASCAL fl_write (WORD drive, WORD head, WORD track, WORD sector, WORD count, UBYTE FAR *buffer);
|
|
|
|
; COUNT ASMPASCAL fl_verify(WORD drive, WORD head, WORD track, WORD sector, WORD count, UBYTE FAR *buffer);
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
|
|
|
; Returns 0 if successful, error code otherwise.
|
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
|
|
|
|
global FL_FORMAT
|
|
|
|
FL_FORMAT:
|
|
|
|
mov ah,5 ; format track
|
|
|
|
jmp short fl_common
|
|
|
|
|
2004-04-09 15:11:25 +02:00
|
|
|
global FL_READ
|
|
|
|
FL_READ:
|
2004-06-18 08:57:33 +02:00
|
|
|
mov ah,2 ; read sector(s)
|
2001-03-21 03:56:26 +01:00
|
|
|
jmp short fl_common
|
|
|
|
|
2004-04-09 15:11:25 +02:00
|
|
|
global FL_VERIFY
|
|
|
|
FL_VERIFY:
|
2004-06-18 08:57:33 +02:00
|
|
|
mov ah,4 ; verify sector(s)
|
2001-03-21 03:56:26 +01:00
|
|
|
jmp short fl_common
|
|
|
|
|
2004-04-09 15:11:25 +02:00
|
|
|
global FL_WRITE
|
|
|
|
FL_WRITE:
|
2004-06-18 08:57:33 +02:00
|
|
|
mov ah,3 ; write sector(s)
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
fl_common:
|
2004-06-18 08:57:33 +02:00
|
|
|
push bp ; setup stack frame
|
2000-05-06 21:34:20 +02:00
|
|
|
mov bp,sp
|
|
|
|
|
2004-06-19 21:41:47 +02:00
|
|
|
mov cx,[bp+0Ch] ; cylinder number
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
mov al,1 ; this should be an error code
|
2004-06-18 08:57:33 +02:00
|
|
|
cmp ch,3 ; this code can't write above 3FFh=1023
|
2004-06-19 21:41:47 +02:00
|
|
|
ja fl_error ; as cylinder # is limited to 10 bits.
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
xchg ch,cl ; ch=low 8 bits of cyl number
|
2004-06-18 08:57:33 +02:00
|
|
|
ror cl,1 ; bits 8-9 of cylinder number...
|
|
|
|
ror cl,1 ; ...to bits 6-7 in CL
|
2003-09-15 12:53:09 +02:00
|
|
|
or cl,[bp+0Ah] ; or in the sector number (bits 0-5)
|
2001-03-21 03:56:26 +01:00
|
|
|
|
2004-06-19 21:41:47 +02:00
|
|
|
mov al,[bp+08h] ; count of sectors to read/write/...
|
2004-06-18 08:57:33 +02:00
|
|
|
les bx,[bp+04h] ; Load 32 bit buffer ptr into ES:BX
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
mov dl,[bp+10h] ; drive (if or'ed 80h its a hard drive)
|
2004-04-09 15:11:25 +02:00
|
|
|
mov dh,[bp+0Eh] ; get the head number
|
2003-09-15 12:53:09 +02:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
int 13h ; process sectors
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
sbb al,al ; carry: al=ff, else al=0
|
|
|
|
and al,ah ; carry: error code, else 0
|
2001-03-21 03:56:26 +01:00
|
|
|
fl_error:
|
2004-06-19 21:41:47 +02:00
|
|
|
mov ah,0 ; extend AL into AX without sign extension
|
2000-05-06 21:34:20 +02:00
|
|
|
pop bp
|
2004-04-09 15:11:25 +02:00
|
|
|
ret 14
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
;
|
|
|
|
; COUNT ASMPASCAL fl_lba_ReadWrite(BYTE drive, WORD mode, void FAR * dap_p);
|
2001-07-10 00:19:33 +02:00
|
|
|
;
|
|
|
|
; Returns 0 if successful, error code otherwise.
|
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
|
2004-04-09 15:11:25 +02:00
|
|
|
global FL_LBA_READWRITE
|
|
|
|
FL_LBA_READWRITE:
|
2004-06-18 08:57:33 +02:00
|
|
|
push bp ; setup stack frame
|
2001-07-10 00:19:33 +02:00
|
|
|
mov bp,sp
|
|
|
|
|
|
|
|
push ds
|
|
|
|
push si ; wasn't in kernel < KE2024Bo6!!
|
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
mov dl,[bp+10] ; drive (if or'ed with 80h a hard drive)
|
2004-04-09 15:11:25 +02:00
|
|
|
mov ax,[bp+8] ; get the command
|
|
|
|
lds si,[bp+4] ; get far dap pointer
|
2001-07-10 00:19:33 +02:00
|
|
|
int 13h ; read from/write to drive
|
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
pop si
|
2001-07-10 00:19:33 +02:00
|
|
|
pop ds
|
2003-09-15 12:53:09 +02:00
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
pop bp
|
2004-06-18 08:57:33 +02:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
mov al,ah ; place any error code into al
|
|
|
|
mov ah,0 ; zero out ah
|
2004-04-09 15:11:25 +02:00
|
|
|
ret 8
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
; void ASMPASCAL fl_readkey (void);
|
2003-09-15 12:53:09 +02:00
|
|
|
;
|
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
global FL_READKEY
|
2004-04-09 15:11:25 +02:00
|
|
|
FL_READKEY: xor ah, ah
|
2001-09-23 22:39:44 +02:00
|
|
|
int 16h
|
|
|
|
ret
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
;
|
|
|
|
; COUNT ASMPASCAL fl_setdisktype (WORD drive, WORD type);
|
|
|
|
;
|
|
|
|
|
|
|
|
global FL_SETDISKTYPE
|
2004-04-09 15:11:25 +02:00
|
|
|
FL_SETDISKTYPE:
|
2003-09-15 12:53:09 +02:00
|
|
|
pop bx ; return address
|
2004-06-18 08:57:33 +02:00
|
|
|
pop ax ; disk format type (al)
|
2004-04-09 15:11:25 +02:00
|
|
|
pop dx ; drive number (dl)
|
|
|
|
push bx ; restore stack
|
2004-06-18 08:57:33 +02:00
|
|
|
mov ah,17h ; floppy set disk type for format
|
|
|
|
int 13h
|
|
|
|
ret_AH:
|
|
|
|
mov al,ah ; place any error code into al
|
|
|
|
mov ah,0 ; zero out ah
|
|
|
|
ret
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
; COUNT ASMPASCAL fl_setmediatype (WORD drive, WORD tracks, WORD sectors);
|
2003-09-15 12:53:09 +02:00
|
|
|
;
|
2004-06-18 08:57:33 +02:00
|
|
|
global FL_SETMEDIATYPE
|
2004-04-09 15:11:25 +02:00
|
|
|
FL_SETMEDIATYPE:
|
2003-09-15 12:53:09 +02:00
|
|
|
pop ax ; return address
|
2004-06-18 08:57:33 +02:00
|
|
|
pop bx ; sectors/track
|
2004-04-09 15:11:25 +02:00
|
|
|
pop cx ; number of tracks
|
|
|
|
pop dx ; drive number
|
|
|
|
push ax ; restore stack
|
2004-06-18 08:57:33 +02:00
|
|
|
push di
|
2003-09-15 12:53:09 +02:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
dec cx ; number of cylinders - 1 (last cyl number)
|
|
|
|
xchg ch,cl ; CH=low 8 bits of last cyl number
|
|
|
|
|
|
|
|
ror cl,1 ; extract bits 8-9 of cylinder number...
|
|
|
|
ror cl,1 ; ...into cl bit 6-7
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
or cl,bl ; sectors/track (bits 0-5) or'd with high cyl bits 7-6
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2004-06-18 08:57:33 +02:00
|
|
|
mov ah,18h ; disk set media type for format
|
|
|
|
int 13h
|
2001-11-04 20:47:39 +01:00
|
|
|
jc skipint1e
|
2004-06-18 08:57:33 +02:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
push es
|
2001-11-04 20:47:39 +01:00
|
|
|
xor dx,dx
|
|
|
|
mov es,dx
|
|
|
|
cli
|
2003-09-15 12:53:09 +02:00
|
|
|
pop word [es:0x1e*4+2] ; set int 0x1e table to es:di
|
2001-11-04 20:47:39 +01:00
|
|
|
mov [es:0x1e*4 ], di
|
|
|
|
sti
|
|
|
|
skipint1e:
|
|
|
|
pop di
|
2003-09-15 12:53:09 +02:00
|
|
|
jmp short ret_AH
|
2001-11-04 20:47:39 +01:00
|
|
|
|