1;
2;       ZX IF1 & Microdrive functions
3;
4;       Get Microdrive status
5;
6;       int if1_mdv_status (int drive);
7;
8;       Returns:
9;       0: Microdrive Ready, cartridge inserted, no write protection
10;       1: Cartridge is write protected
11;       2: Microdrive not present
12;
13;       $Id: if1_mdv_status.asm,v 1.3 2016-07-01 22:08:20 dom Exp $
14;
15
16		SECTION   code_clib
17                PUBLIC    if1_mdv_status
18                PUBLIC    _if1_mdv_status
19
20                EXTERN     if1_rommap
21                EXTERN    MOTOR
22
23
24if1_mdv_status:
25_if1_mdv_status:
26
27                pop	hl
28                pop	bc
29                push	bc
30                push	hl
31
32                ld      a,c
33                ld      hl,-1
34                and     a               ; drive no. = 0 ?
35                ret     z               ; yes, return -1
36                dec     a
37                cp      8               ; drive no. >8 ?
38                ret     nc              ; yes, return -1
39                inc     a
40
41		push	af
42                call    if1_rommap
43                pop	af
44
45		call    MOTOR           ; select drive motor
46		ld	hl,retcode+1
47		ld	a,2
48		ld	(hl),a
49		jr	nz,estatus	; microdrive not present
50
51		in	a,($ef)
52		and	1		; test the write-protect tab
53		;;ret	z		; drive 'write' protected
54		xor	1		; invert result (now 1=protected)
55		ld	(hl),a
56
57estatus:
58		xor	a
59		call	MOTOR		; Switch microdrive motor off (a=0)
60                call    1               ; unpage
61                ei
62
63retcode:	ld	hl,0
64		ret
65