1;
2;	ZX IF1 & Microdrive functions
3;
4;	int if1_init_file (int drive, int name, struct M_CHAN buffer);
5;
6;	This is the original BASIC structure with no added values/flags.
7;
8;
9;	Open a file for writing
10;
11;	$Id: if1_init_file.asm,v 1.3 2016-07-01 22:08:20 dom Exp $
12;
13
14		SECTION code_clib
15		PUBLIC 	if1_init_file
16		PUBLIC 	_if1_init_file
17
18		EXTERN	if1_setname
19
20
21if1_init_file:
22_if1_init_file:
23		rst	8
24		defb 	31h		; Create Interface 1 system vars if required
25
26		pop	af
27		pop	hl	;buffer
28		pop	de	;filename
29		pop	bc	;driveno
30		push	bc
31		push	de
32		push	hl
33		push	af
34		push	ix	;save callers
35
36		push	hl
37
38		ld	a,c
39		ld	($5cd6),a
40
41		push	de
42		ld	hl,filename	; filename location
43		push	hl
44		call	if1_setname
45		ld	($5cda),hl	; length
46		pop	hl
47		ld	($5cdc),hl	; pointer to filename
48		pop	de
49
50		;rst	8		; Erase if file exists ?
51		;defb	24h
52
53		rst	8
54		defb	22h		; Open temporary 'M' channel (touch)
55
56		; Now IX points to the newly created channel
57		push 	ix
58		pop	hl
59
60		;ld	a,h
61		;or	l
62		;and	a
63
64		;ld	de,4		; Experimentally corrected
65		;add	hl,de		; with this offset
66
67		pop	de		; buffer
68		ld	bc,253h
69		;ld	bc,37h
70		ldir			; take a copy of the file buffer header
71
72		xor	a
73		rst	8
74		defb	21h		; stop microdrive motor
75
76		rst	8
77		defb	2Ch		; Reclaim the channel
78					; ..I need the initialized buffer only
79
80		; here we could check for free space
81		; and eventually give the "microdrive full" error
82		ld	hl,0
83		pop	ix		;restore callers
84		ret
85
86		SECTION bss_clib
87filename:	defs	10
88