;   coredisk.inc, Copyright (c) 1997-1998 by Lukas Ruf,
;   Swiss Federal Institute of Technology,
;   Computer Engineering and Networks Laboratory.
;
;   TOPSY -- A Teachable Operating System.
;            Implementation of a tiny and simple
;            micro kernel for teaching purposes.
;
;   For further information, please visit http://www.tik.ee.ethz.ch/~topsy
;
;   This software is provided under the terms of the GNU General Public Licence.
;   A full copy of the GNU GPL is provided in the file COPYING found in the 
;   development root of Topsy.
;
;       This copyright notice supercedes all originally or previously used 
;       copyrights being used within the source code.
;       
;       Author: Lukas Ruf, lr@lpr.ch


;Topsy i386                                                Lukas Ruf, August 1997
;--------------------------------------------------------------------------------

;--------------------------------------------------------------------------------
; Disk Access Routines: Low Level, only BIOS INT 13h
;--------------------------------------------------------------------------------


; ResetDisk():
;ResetDisk PROC NEAR
ResetDisk:
        PUSH AX
        PUSH CX
        PUSH DX
        MOV CX,#0x0005

   ResetTry:
        PUSH CX
        MOV AH,#0x00
        MOV DL,#0x00
        INT 0x13
        POP CX
        JNC ResetSuccess
        LOOP ResetTry

   ResetSuccess:
        POP DX
        POP CX
        POP AX
        RET
;ResetDisk ENDP

; word16b ReadTrackAtOnce(char *buffer, char Head, char Track)
;       Stack:  Segment(buffer)
;               Offset (buffer)
;               Head            (low  Byte = Head)
;               Track           (low  Byte = Track)
;               returnaddr      <- SP
; Return: CF = 1 : Failure

;ReadTrackAtOnce PROC NEAR
ReadTrackAtOnce:
        PUSH    BP
        MOV     BP,SP
        PUSH    AX
        PUSH    BX
        PUSH    CX
        PUSH    DX
        PUSH    ES
        MOV     CX,#0x0005
 ReadTry:
        PUSH    CX
        ; MOV     CX,SS:[BP+04]           ; Track (0-based) (CH)
        seg ss
        MOV     CX,[BP+04]           ; Track (0-based) (CH)
        MOV     CH,CL                   ;       (0-based)
        MOV     CL,#0x1                  ;       (1-based)
        seg ss
        MOV     DX,[BP+06]           ; Head  (0-based) (DH)
        MOV     DH,DL                   ;       (0-based)
        MOV     DL,#0x0                  ; Drive (0-based for floppys)
        seg ss
        MOV     BX,[BP+08]           ; BX of ES:BX
        seg ss
        MOV     AX,[BP+10]           ; ES of ES:BX
        MOV     ES,AX                   ; ES:BX

        MOV     AH,#0x02                 ; Read
        MOV     AL,#18                   ; No. of Sectors

        INT     0x13
        POP     CX
        JNC     ReadSuccess
        CALL    ResetDisk
        LOOP    ReadTry
        STC
 ReadSuccess:
        POP     ES
        POP     DX
        POP     CX
        POP     BX
        POP     AX
        POP     BP
        RET     8
;ReadTrackAtOnce ENDP

