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$
|
|
|
|
;
|
|
|
|
|
2001-04-15 05:21:50 +02:00
|
|
|
%ifndef SYS
|
2003-06-15 13:46:51 +02:00
|
|
|
%include "../kernel/segs.inc"
|
2003-03-12 23:43:53 +01:00
|
|
|
segment HMA_TEXT
|
2001-04-15 05:21:50 +02:00
|
|
|
%else
|
2001-04-22 03:19:34 +02:00
|
|
|
segment _TEXT class=CODE
|
|
|
|
%endif
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
|
|
|
;
|
|
|
|
; Reset both the diskette and hard disk system
|
|
|
|
;
|
|
|
|
; BOOL fl_reset(WORD drive)
|
|
|
|
;
|
|
|
|
; returns TRUE if successful
|
|
|
|
;
|
|
|
|
|
|
|
|
global _fl_reset
|
|
|
|
_fl_reset:
|
2003-09-15 12:53:09 +02:00
|
|
|
pop ax ; return address
|
|
|
|
pop dx ; drive
|
|
|
|
push dx ; restore stack
|
|
|
|
push ax ;
|
|
|
|
mov ah,0 ; BIOS reset diskette & fixed disk
|
2000-05-06 21:34:20 +02:00
|
|
|
int 13h
|
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
sbb ax,ax ; cy==1 is error
|
|
|
|
inc ax ; TRUE on success, FALSE on failure
|
2000-05-06 21:34:20 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
;
|
|
|
|
; Read disk change line status
|
|
|
|
;
|
|
|
|
; COUNT fl_diskchanged(WORD drive)
|
|
|
|
;
|
2003-09-15 12:53:09 +02:00
|
|
|
; returns 1 if disk has changed, 0 if not, 0xFFFF if error
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
global _fl_diskchanged
|
|
|
|
_fl_diskchanged:
|
2003-09-15 12:53:09 +02:00
|
|
|
pop ax ; return address
|
|
|
|
pop dx ; get the drive number
|
|
|
|
push dx ; restore stack
|
|
|
|
push ax ;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
mov ah,16h ; read change status type
|
|
|
|
int 13h
|
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
mov al,1
|
|
|
|
jnc fl_dc_ret1 ; cy==1 is error or disk has changed
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
cmp ah,6 ; ah=6: disk has changed
|
|
|
|
je fl_dc_ret
|
|
|
|
dec ax ; 0xFF on error
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
fl_dc_ret1: dec ax
|
|
|
|
fl_dc_ret: cbw
|
2000-05-06 21:34:20 +02:00
|
|
|
ret
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
;
|
|
|
|
; Format Sectors
|
|
|
|
;
|
|
|
|
; COUNT fl_format(WORD drive, WORD head, WORD track, WORD sector, WORD count, BYTE FAR *buffer);
|
|
|
|
;
|
|
|
|
; Formats one or more tracks, sector should be 0.
|
|
|
|
;
|
|
|
|
; Returns 0 if successful, error code otherwise.
|
|
|
|
global _fl_format
|
|
|
|
_fl_format:
|
|
|
|
mov ah, 5
|
|
|
|
jmp short fl_common
|
2000-05-06 21:34:20 +02:00
|
|
|
;
|
|
|
|
; Read Sectors
|
|
|
|
;
|
|
|
|
; COUNT fl_read(WORD drive, WORD head, WORD track, WORD sector, WORD count, BYTE FAR *buffer);
|
|
|
|
;
|
|
|
|
; Reads one or more sectors.
|
|
|
|
;
|
|
|
|
; Returns 0 if successful, error code otherwise.
|
|
|
|
;
|
|
|
|
;
|
|
|
|
; Write Sectors
|
|
|
|
;
|
|
|
|
; COUNT fl_write(WORD drive, WORD head, WORD track, WORD sector, WORD count, BYTE FAR *buffer);
|
|
|
|
;
|
|
|
|
; Writes one or more sectors.
|
|
|
|
;
|
|
|
|
; Returns 0 if successful, error code otherwise.
|
|
|
|
;
|
2001-03-21 03:56:26 +01:00
|
|
|
global _fl_read
|
|
|
|
_fl_read:
|
|
|
|
mov ah,2 ; cmd READ
|
|
|
|
jmp short fl_common
|
|
|
|
|
|
|
|
global _fl_verify
|
|
|
|
_fl_verify:
|
|
|
|
mov ah,4 ; cmd verify
|
|
|
|
jmp short fl_common
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
global _fl_write
|
|
|
|
_fl_write:
|
2001-03-21 03:56:26 +01:00
|
|
|
mov ah,3 ; cmd WRITE
|
|
|
|
|
|
|
|
fl_common:
|
2000-05-06 21:34:20 +02:00
|
|
|
push bp ; C entry
|
|
|
|
mov bp,sp
|
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
mov cx,[bp+8] ; cylinder number (lo only if hard)
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
mov al,1 ; this should be an error code
|
2003-09-15 12:53:09 +02:00
|
|
|
cmp ch,3 ; this code can't write above 3ff=1023
|
2001-03-21 03:56:26 +01:00
|
|
|
ja fl_error
|
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
xchg ch,cl ; ch=low 8 bits of cyl number
|
|
|
|
ror cl,1 ; extract bits 8+9 to cl
|
|
|
|
ror cl,1
|
|
|
|
or cl,[bp+0Ah] ; or in the sector number (bits 0-5)
|
2001-03-21 03:56:26 +01:00
|
|
|
|
|
|
|
mov al,[bp+0Ch] ; count to read/write
|
2000-05-06 21:34:20 +02:00
|
|
|
les bx,[bp+0Eh] ; Load 32 bit buffer ptr
|
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
mov dl,[bp+4] ; get the drive (if or'ed 80h its
|
|
|
|
; hard drive.
|
|
|
|
mov dh,[bp+6] ; get the head number
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
int 13h ; write sectors from mem es:bx
|
|
|
|
|
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
|
|
|
|
; (Zero transfer count)
|
2001-03-21 03:56:26 +01:00
|
|
|
fl_error:
|
2003-09-15 12:53:09 +02:00
|
|
|
mov ah,0 ; force into < 255 count
|
2000-05-06 21:34:20 +02:00
|
|
|
pop bp
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
; COUNT fl_lba_ReadWrite(BYTE drive, UWORD mode, VOID FAR *dap_p)
|
|
|
|
;
|
|
|
|
; Returns 0 if successful, error code otherwise.
|
|
|
|
;
|
|
|
|
global _fl_lba_ReadWrite
|
|
|
|
_fl_lba_ReadWrite:
|
|
|
|
push bp ; C entry
|
|
|
|
mov bp,sp
|
|
|
|
|
|
|
|
push ds
|
|
|
|
push si ; wasn't in kernel < KE2024Bo6!!
|
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
mov dl,[bp+4] ; get the drive (if ored 80h harddrive)
|
2001-07-10 00:19:33 +02:00
|
|
|
mov ax,[bp+6] ; get the command
|
|
|
|
lds si,[bp+8] ; get far dap pointer
|
|
|
|
int 13h ; read from/write to drive
|
|
|
|
|
|
|
|
pop si
|
|
|
|
pop ds
|
2003-09-15 12:53:09 +02:00
|
|
|
|
2001-07-10 00:19:33 +02:00
|
|
|
pop bp
|
2003-09-15 12:53:09 +02:00
|
|
|
ret_AH:
|
|
|
|
mov al,ah ; place any error code into al
|
|
|
|
mov ah,0 ; zero out ah
|
2001-07-10 00:19:33 +02:00
|
|
|
ret
|
2001-09-23 22:39:44 +02:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
;
|
|
|
|
; void fl_readkey (void);
|
|
|
|
;
|
|
|
|
|
2001-09-23 22:39:44 +02:00
|
|
|
global _fl_readkey
|
|
|
|
_fl_readkey: xor ah, ah
|
|
|
|
int 16h
|
|
|
|
ret
|
2001-11-04 20:47:39 +01:00
|
|
|
|
|
|
|
global _fl_setdisktype
|
|
|
|
_fl_setdisktype:
|
2003-09-15 12:53:09 +02:00
|
|
|
pop bx ; return address
|
|
|
|
pop dx ; drive number (dl)
|
|
|
|
pop ax ; disk type (al)
|
|
|
|
push ax ; restore stack
|
|
|
|
push dx
|
|
|
|
push bx
|
2001-11-04 20:47:39 +01:00
|
|
|
mov ah,17h
|
|
|
|
int 13h
|
2003-09-15 12:53:09 +02:00
|
|
|
jmp short ret_AH
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
;
|
|
|
|
; COUNT fl_setmediatype (WORD drive, WORD tracks, WORD sectors);
|
|
|
|
;
|
2001-11-04 20:47:39 +01:00
|
|
|
global _fl_setmediatype
|
|
|
|
_fl_setmediatype:
|
2003-09-15 12:53:09 +02:00
|
|
|
pop ax ; return address
|
|
|
|
pop dx ; drive number
|
|
|
|
pop cx ; number of tracks
|
|
|
|
pop bx ; sectors/track
|
|
|
|
push bx ; restore stack
|
|
|
|
push cx
|
|
|
|
push dx
|
|
|
|
push ax
|
2001-11-04 20:47:39 +01:00
|
|
|
push di
|
2003-09-15 12:53:09 +02:00
|
|
|
|
|
|
|
dec cx ; should be highest track
|
|
|
|
xchg ch,cl ; low 8 bits of cyl number
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2003-09-15 12:53:09 +02:00
|
|
|
ror cl,1 ; extract bits 8+9 to cl bit 6+7
|
|
|
|
ror cl,1
|
2001-11-04 20:47:39 +01:00
|
|
|
|
|
|
|
or cl,bl ; or in bits 7-6
|
|
|
|
|
|
|
|
mov ah,18h
|
|
|
|
int 13h
|
|
|
|
jc skipint1e
|
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
|
|
|
|