1//
2// 2001 STanda
3//
4// The basic file layout was taken from Julian Reschke's Cookies
5//
6
7	.globl	_init
8
9	.globl	_sys_d_free, _sys_f_sfirst, _sys_f_snext, _sys_f_open
10	.globl	_sys_f_close, _sys_d_atime, _sys_f_write, _sys_f_read
11	.globl	_sys_f_attrib, _sys_f_create, _sys_f_seek, _sys_f_cntl
12	.globl  _sys_d_create, _sys_d_delete, _sys_f_rename
13	.globl  _sys_d_getpath, _sys_d_dsetpath
14	.globl	_sys_d_pathconf, _sys_f_xattr, _sys_d_opendir, _sys_d_readdir
15	.globl	_sys_d_closedir, _sys_d_xreaddir, _sys_d_rewinddir
16	.globl	_sys_d_readlabel, _sys_d_delete
17
18	.globl	_DriverName, _ShowBanner, _InitDevice
19
20
21.macro PRINT value
22//	nf_call( nf_get_id(NF_STDERR), value);
23#if 0
24	move.l  #s_stderr,-(sp)
25	move.l  #0,-(sp)
26        dc.w    0x7300
27        lea	8(sp),sp
28
29	move.l  \value,-(sp)
30	move.l  #s_frm,-(sp)
31	move.l  d0,-(sp)
32	move.l  #0,-(sp)
33        dc.w    0x7301
34        lea	16(sp),sp
35#endif
36.endm PRINT
37
38
39#if 1
40#define	SREGS	movem.l	a0-a6/d1-d7,-(sp)
41#define	RREGS	movem.l (sp)+,a0-a6/d1-d7
42#else
43#define	SREGS
44#define	RREGS
45#endif
46
47.macro SSTCK framereg
48	move.l	sp,temp			// store the old stack to the new one (do not touch regs)
49	move.l	#stack,sp
50
51	move.l	temp,-(sp)
52	SREGS
53
54	move.l	temp,\framereg
55.endm SSTCK
56
57.macro RSTCK
58	RREGS
59	move.l	(sp),sp
60.endm RSTCK
61
62//
63// Call to the MetaDOS C function implementation macro
64//
65.macro MDBSR framereg,label
66	move.w	4(\framereg),-(sp)
67	move.l	(\framereg),-(sp)
68	move.l	a5,-(sp)
69	move.l	a4,-(sp)
70	move.l	a3,-(sp)
71	bsr	\label
72	lea	18(sp),sp
73.endm MDBSR
74
75
76	.text
77
78_init:
79	bsr	_ShowBanner
80	move.l	#functionTable+12,d0
81	move.l	#_DriverName,d1
82	rts
83
84
85initfun:
86	movem.l	a0-a6/d1-d7,-(sp)
87	PRINT	#1
88	move.l	d1,-(sp)		// BetaDOS's dosDevID + some weird word / MetaDOS pure crap
89	move.w	d0,-(sp)		// bosDevID 16bit
90	move.w	#0,-(sp)		// pad for gcc (long)
91	bsr	_InitDevice
92	addq	#8,sp
93	movem.l	(sp)+,a0-a6/d1-d7
94// d1: filename conversion
95// Bit 0: 0 = force upper case
96// Bit 1: 0 = fully expand
97// Bit 2: 0 = critical error handler reports EWRPRO
98	moveq	#5,d1
99	rts
100
101
102
103functionTable:
104	dc.l	0x4d414749		// 'MAGI'
105	dc.l	0x434d4554		// 'CMET'
106	dc.l	349
107	dc.l	initfun
108	dc.l	-1, -1, -1, -1, -1
109	dc.l	-1, -1, -1, -1, -1
110	dc.l	-1, -1, -1, -1, -1
111	dc.l	-1, -1, -1, -1, -1
112	dc.l	-1, -1, -1, -1, -1
113	dc.l	-1, -1, -1, -1, -1
114	dc.l	-1, -1, -1, -1, -1
115	dc.l	-1, -1, -1, -1, -1
116	dc.l	-1, -1, -1, -1, -1
117	dc.l	-1, -1, -1, -1, -1	// 49
118	dc.l	-1, -1, -1, -1
119	dc.l	wrap_dfree		// 54
120	dc.l	-1
121	dc.l	-1
122	dc.l	wrap_dcreate		// 57
123	dc.l	wrap_ddelete		// 58
124	dc.l	-1			// 59	// wrap_dsetpath
125	dc.l	wrap_fcreate		// 60
126	dc.l	wrap_fopen		// 61
127	dc.l	wrap_fclose		// 62
128	dc.l	wrap_fread		// 63
129	dc.l	wrap_fwrite		// 64
130	dc.l	wrap_fdelete		// 65
131	dc.l	wrap_fseek		// 66
132	dc.l	wrap_fattrib		// 67
133	dc.l	-1
134	dc.l	-1			// 69
135	dc.l	-1
136	dc.l	-1			// 71	// Dgetpath
137	dc.l	-1, -1, -1		// 74
138	dc.l	-1, -1, -1
139	dc.l	wrap_fsfirst		// 78
140	dc.l	wrap_fsnext		// 79
141	dc.l	-1, -1, -1, -1, -1	// 84
142	dc.l	-1
143	dc.l	wrap_frename		// 86
144	dc.l	wrap_fdatime		// 87
145	dc.l	-1, -1			// 89
146	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 99
147	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 109
148	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 119
149	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 129
150	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 139
151	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 149
152	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 159
153	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 169
154	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 179
155	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 189
156	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 199
157	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 209
158	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 219
159	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 229
160	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 239
161	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 249
162	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 259
163	dc.l	-1			// 260	// wrap_fcntl
164	dc.l	-1, -1, -1, -1		// 264
165	dc.l	-1, -1, -1, -1, -1	// 269
166	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 279
167	dc.l	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1	// 289
168	dc.l	-1, -1
169	dc.l	wrap_dpathconf		// 292
170	dc.l	-1, -1			// 294
171	dc.l	-1
172	dc.l	wrap_dopendir		// 296
173	dc.l	wrap_dreaddir		// 297
174	dc.l	wrap_drewinddir		// 298
175	dc.l	wrap_dclosedir		// 299
176	dc.l	wrap_fxattr		// 300
177	dc.l	-1, -1, -1, -1		// 304
178	dc.l	-1, -1, -1, -1, -1	// 309
179	dc.l	-1, -1, -1, -1, -1	// 314
180	dc.l	-1, -1, -1, -1, -1	// 319
181	dc.l	-1, -1
182	dc.l	wrap_dxreaddir		// 322
183	dc.l	-1, -1
184	dc.l	-1, -1, -1, -1, -1	// 329
185	dc.l	-1, -1, -1, -1, -1 	// 334
186	dc.l	-1, -1, -1
187	dc.l	wrap_dreadlabel		// 338
188	dc.l	-1			// 339
189	dc.l	-1, -1, -1, -1, -1 	// 344
190	dc.l	-1, -1, -1, -1, -1 	// 349
191
192
193wrap_dfree:
194	PRINT	#54
195	SSTCK	a0
196
197	move.w	10(a0),-(sp)	// drive #
198	move.l	6(a0),-(sp)	// diskinfo *
199	MDBSR	a0,_sys_d_free
200	lea	6(sp),sp
201
202	RSTCK
203	rts
204
205wrap_dcreate:
206	PRINT	#57
207	SSTCK	a0
208
209	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
210	MDBSR	a0,_sys_d_create
211	lea	4(sp),sp
212
213	RSTCK
214	rts
215
216wrap_ddelete:
217	PRINT	#58
218	SSTCK	a0
219
220	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
221	MDBSR	a0,_sys_d_delete
222	lea	4(sp),sp
223
224	RSTCK
225	rts
226
227wrap_dsetpath:
228	PRINT	#59
229	SSTCK	a0
230
231	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
232//REM	MDBSR	a0,_sys_d_dsetpath
233	lea	4(sp),sp
234
235	RSTCK
236	rts
237
238wrap_fcreate:
239	PRINT	#60
240	SSTCK	a0
241
242	move.w	10(a0),-(sp)	// attr
243	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
244	MDBSR	a0,_sys_f_create
245	lea	6(sp),sp
246
247	RSTCK
248	rts
249
250wrap_fopen:
251	PRINT	#61
252	SSTCK	a0
253
254	move.w	10(a0),-(sp)	// mode
255	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
256	MDBSR	a0,_sys_f_open
257	lea	6(sp),sp
258
259	RSTCK
260
261	cmp.l	#0,d0
262	bmi	fopen_error
263	move.l	#0,d0		// reset the fs to 0 (MetaDOS requires this)
264fopen_error:
265	rts
266
267wrap_fclose:
268	PRINT	#62
269	SSTCK	a0
270
271	move.w	6(a0),-(sp)	// handle
272	MDBSR	a0,_sys_f_close
273	lea	2(sp),sp
274
275	RSTCK
276	rts
277
278wrap_fread:
279	PRINT	#63
280	SSTCK	a0
281
282	move.l	12(a0),-(sp)	// buffer
283	move.l	8(a0),-(sp)	// count
284	move.w	6(a0),-(sp)	// handle
285	MDBSR	a0,_sys_f_read
286	lea	10(sp),sp
287
288	RSTCK
289	rts
290
291wrap_fwrite:
292	PRINT	#64
293	SSTCK	a0
294
295	move.l	12(a0),-(sp)	// buffer
296	move.l	8(a0),-(sp)	// count
297	move.w	6(a0),-(sp)	// handle
298	MDBSR	a0,_sys_f_write
299	lea	10(sp),sp
300
301	RSTCK
302	rts
303
304wrap_fdelete:
305	PRINT	#65
306	SSTCK	a0
307
308	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
309	MDBSR	a0,_sys_f_delete
310	lea	4(sp),sp
311
312	RSTCK
313	rts
314
315wrap_fseek:
316	PRINT	#66
317	SSTCK	a0
318
319	move.w	12(a0),-(sp)	// mode
320	move.w	10(a0),-(sp)	// handle
321	move.l	6(a0),-(sp)	// count
322	MDBSR	a0,_sys_f_seek
323	lea	8(sp),sp
324
325	RSTCK
326	rts
327
328wrap_fattrib:
329	PRINT	#67
330	SSTCK	a0
331
332	move.w	12(a0),-(sp)	// attrib
333	move.w	10(a0),-(sp)	// flag
334	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
335	MDBSR	a0,_sys_f_attrib
336	lea	8(sp),sp
337
338	RSTCK
339	rts
340
341wrap_fsfirst:
342	PRINT	#78
343	SSTCK	a0
344
345	move.w	10(a0),-(sp)	// flags
346	move.l	a4,-(sp)	// name/mask - 6(a0) or a4 MD
347	MDBSR	a0,_sys_f_sfirst
348	lea	6(sp),sp
349
350	RSTCK
351	rts
352
353wrap_fsnext:
354	PRINT	#79
355	SSTCK	a0
356	MDBSR	a0,_sys_f_snext
357
358	RSTCK
359	rts
360
361wrap_frename:
362	PRINT	#86
363	SSTCK	a0
364
365	move.l	12(a0),-(sp)	// newname
366	move.l	a4,-(sp)	// oldname - 8(a0) or a4 MD (yes 8(a0)!!!)
367	move.w	6(a0),-(sp)	// reserved
368	MDBSR	a0,_sys_f_rename
369	lea	10(sp),sp
370
371	RSTCK
372	rts
373
374wrap_fdatime:
375	PRINT	#87
376	SSTCK	a0
377
378	move.w	12(a0),-(sp)	// flag
379	move.w	10(a0),-(sp)	// handle
380	move.l	6(a0),-(sp)	// timeptr	MDBSR	a0,_sys_f_datime
381	MDBSR	a0,_sys_f_datime
382	lea	8(sp),sp
383
384	RSTCK
385	rts
386
387wrap_fcntl:
388	PRINT	#260
389	SSTCK	a0
390
391	move.w	12(a0),-(sp)	// cmd
392	move.l	8(a0),-(sp)	// argument
393	move.w	6(a0),-(sp)	// handle
394//REM	MDBSR	a0,_sys_f_cntl
395	lea	8(sp),sp
396
397	RSTCK
398	rts
399
400wrap_dpathconf:
401	PRINT	#292
402	SSTCK	a0
403
404	move.w	10(a0),-(sp)	// mode
405	move.l	a4,-(sp)	// name - 6(a0) or a4 MD
406	MDBSR	a0,_sys_d_pathconf
407	lea	6(sp),sp
408
409	RSTCK
410	rts
411
412wrap_dopendir:
413	PRINT	#296
414	SSTCK	a0
415
416	move.w	10(a0),-(sp)	// flag
417	move.l	a4,-(sp)	// name 6(a0) or a4 MD
418	MDBSR	a0,_sys_d_opendir
419	lea	6(sp),sp
420
421	RSTCK
422	rts
423
424wrap_dreaddir:
425	PRINT	#297
426	SSTCK	a0
427
428	move.l	12(a0),-(sp)	// buffer
429	move.l	8(a0),-(sp)	// dirhandle
430	move.w	6(a0),-(sp)	// len
431	MDBSR	a0,_sys_d_readdir
432	lea	10(sp),sp
433
434	RSTCK
435	rts
436
437wrap_drewinddir:
438	PRINT	#298
439	SSTCK	a0
440
441	move.l	6(a0),-(sp)	// dirhandle
442	MDBSR	a0,_sys_d_rewind
443	lea	4(sp),sp
444
445	RSTCK
446	rts
447
448wrap_dclosedir:
449	PRINT	#299
450	SSTCK	a0
451
452	move.l	6(a0),-(sp)	// dirhandle
453	MDBSR	a0,_sys_d_closedir
454	lea	4(sp),sp
455
456	RSTCK
457	rts
458
459wrap_fxattr:
460	PRINT	#300
461	SSTCK	a0
462
463	move.l	12(a0),-(sp)	// xattr*
464	move.l	a4,-(sp)	// name 8(a0) or a4 MD
465	move.w	6(a0),-(sp)	// flag
466	MDBSR	a0,_sys_f_xattr
467	lea	10(sp),sp
468
469	RSTCK
470	rts
471
472wrap_dxreaddir:
473	PRINT	#322
474	SSTCK	a0
475
476	move.l	20(a0),-(sp)	// xret*
477	move.l	16(a0),-(sp)	// xattr*
478	move.l	12(a0),-(sp)	// buffer
479	move.l	8(a0),-(sp)	// dirhandle
480	move.w	6(a0),-(sp)	// len
481	MDBSR	a0,_sys_d_xreaddir
482	lea	18(sp),sp
483
484	RSTCK
485	rts
486
487wrap_dreadlabel:
488	PRINT	#338
489	SSTCK	a0
490
491	move.w	14(a0),-(sp)	// len
492	move.l	10(a0),-(sp)	// buffer
493	move.l	a4,-(sp)	// pathname 6(a0) or a4 MD
494	MDBSR	a0,_sys_d_readlabel
495	lea	10(sp),sp
496
497	RSTCK
498	rts
499
500
501s_frm:
502	.ascii	"DEV: %ld\n\0"
503s_stderr:
504	.ascii	"DEBUGPRINTF\0"
505
506	.bss
507temp:
508	ds.l	1
509
510	ds.b	8192
511stack:
512
513
514