Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.msdos.programmer > #96

Re: Overriding the Critical Handler

From pete@nospam.demon.co.uk
Newsgroups comp.os.msdos.programmer
Subject Re: Overriding the Critical Handler
Date 2011-06-03 05:36 +0000
Organization PDL
Message-ID <1307079395snz@nospam.demon.co.uk> (permalink)
References <6VVFp.26962$ar1.4099@newsfe08.iad>

Show all headers | View raw


In article <6VVFp.26962$ar1.4099@newsfe08.iad>
           aaa97@hotSPAM.com "Brian Dude" writes:

> Hello, I'm not well versed with interrupt coding. (Mostly my straight C
> handles things for me.) My first task was to suppress the default error
> message when a disk is not ready:
> 
> Not ready reading drive X:
> Abort, Retry, Fail?
> 
> And I found out that I had to override the Critical Error Handler
> (0x24). So I basically did that. But now I'm not sure what to about
> regaining control. If I make my own custom message it still seems like
> the system tries to access the hardware, and fails, leaving my program
> hanging. I've been checking the RBIL but I'm not sure what to call to
> just get it to ignore and continue.
> 
> TIA,
> Brian Dude

Overriding the Critical Error handler is exactly what you need to do.  
Here's a quick/dirty implementation of same:

------- ISDISKIN.ASM --------

        ; Assemble using: masm /mx isdiskin;

_TEXT	SEGMENT BYTE	PUBLIC	'CODE'
	ASSUME	CS:_TEXT

	PUBLIC	_isdiskavl

_isdiskavl	proc	near	;small model

	push	bp
	mov	bp, sp
	push	ds		;save our DS
	mov	ax, 3524h	;get critical error vector
	int	21h		;
	push	bx		;save it on stack
	push	es		;

	mov	ax, cs
	mov	ds, ax
	lea	dx, handler	;install our own crit err handler
	mov	ax, 2524h
	int	21h

	mov	word ptr cs:[diskready], 1 ;assume the best
        mov     dx, 4[bp]       ;get drive number (6[bp] for large model)
	mov	ah, 36h 	;DOS "get disk free" service
	int	21h

	pop	ds		;reset original handler
	pop	dx
	mov	ax, 2524h
	int	21h
	pop	ds		;restore DS
	pop	bp
	mov	ax, cs:[diskready] ;set return value in AX
	ret

_isdiskavl	endp

handler proc	far

	xor	ax, ax			;ignore error
	mov	cs:[diskready], ax	;set FALSE
	iret

handler endp

diskready dw ?  ;keep in CS for now

_TEXT	ENDS

	END

------- ISDISKIN.ASM --------

And here's a harness to test it: 

#include <stdio.h>

int isdiskavl (char drv);

int main (int argc, char *argv[])
{
    if (argc < 2)
        printf ("No drive specified\n");
    else
    {
	unsigned char drive;
	// convert to lower case
	drive = (unsigned char) (*argv[1] | ('a' - 'A'));
        if (drive < 'a' || drive > 'z')
            printf ("Invalid drive '%c'\n", drive);
        else
        {
	    int result = isdiskavl (drive - 'a' + 1);
	    printf ("isdiskavl() returned %s\n",
				result ? "TRUE" : "FALSE");
	}
    }
    return 0;
}


It works here -- have fun!

Pete
-- 
   "We have not inherited the earth from our ancestors,
    we have borrowed it from our descendants."

Back to comp.os.msdos.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Overriding the Critical Handler Brian Dude <aaa97@hotSPAM.com> - 2011-06-02 20:28 -0400
  Re: Overriding the Critical Handler pete@nospam.demon.co.uk - 2011-06-03 05:36 +0000
    Re: Overriding the Critical Handler pete@nospam.demon.co.uk - 2011-06-04 07:29 +0000
      Re: Overriding the Critical Handler Brian Dude <aaa97@hotSPAM.com> - 2011-06-07 14:28 -0400
        Re: Overriding the Critical Handler pete@nospam.demon.co.uk - 2011-06-08 04:59 +0000
          Re: Overriding the Critical Handler Brian Dude <aaa97@hotSPAM.com> - 2011-06-15 20:18 -0400
        Re: Overriding the Critical Handler Ross Ridge <rridge@csclub.uwaterloo.ca> - 2011-06-10 11:08 -0400
          Re: Overriding the Critical Handler Brian Dude <aaa97@hotSPAM.com> - 2011-06-15 20:22 -0400
            Re: Overriding the Critical Handler Ross Ridge <rridge@csclub.uwaterloo.ca> - 2011-06-15 20:41 -0400
              Re: Overriding the Critical Handler Brian Dude <aaa97@hotSPAM.com> - 2011-06-16 05:10 -0400
                Re: Overriding the Critical Handler Ross Ridge <rridge@csclub.uwaterloo.ca> - 2011-06-16 11:45 -0400
                Re: Overriding the Critical Handler Brian Dude <aaa97@hotSPAM.com> - 2011-06-16 20:44 -0400

csiph-web