forked from Konamiman/Nextor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAPDRV.MAC
483 lines (405 loc) · 8.29 KB
/
MAPDRV.MAC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
.z80
;include MACROS.INC
ld_a_iyl macro
db 0FDh
ld a,l
endm
FIB equ 3000h
jp START
; -------------------------------------------------------------------------------
db 13
db "MAPDRV - map a drive to a driver, device, LUN and partition,",13,10
db " or mount a file on a drive"
db 13,10
db "Usage:",13,10
db 13,10
db "MAPDRV [/L] <drive>: <partition>|d|u [<device>[-<LUN>] [<slot>[-<subslot>]|0]]",13,10
db "MAPDRV <drive>: [/]<filename> [/ro]",13,10
db 13,10
db "Maps the drive to the specified partition of the specified device and LUN",13,10
db "of the driver in the specified slot (must be a device-based driver).",13,10
db 13,10
db "/L locks the drive immediately after doing the mapping.",13,10
db 13,10
db "<partition> can be any number starting at 1, or 0 to map the drive directly",13,10
db "to the device (needed for partitionless devices such as floppy disks).",13,10
db "Partition numbers 2 to 4 refer to extended partitions 2-1 to 2-4 if partition",13,10
db "2 of the device is extended, otherwise they refer to primary partitions.",13,10
db 13,10
db "<device> and <LUN> must be a number from 1 to 7 each one. If <device> is",13,10
db "specifided but <LUN> is omitted, value 1 is assumed for <LUN>.",13,10
db 13,10
db "<slot> and <subslot> must be a number from 0 to 3. If 0 is specified instead,",13,10
db "the primary disk controller slot is assumed.",13,10
db 13,10
db "If device information is provided but slot is omitted, the drive is mapped to",13,10
db "the specified partition of the specified device in the driver already",13,10
db "controlling the drive (this works only if the drive is currently mapped",13,10
db "to a device-based driver).",13,10
db 13,10
db "If both device and slot information are omitted, the drive is mapped to the",13,10
db "specified partition of the device it is already mapped to (this works only if",13,10
db "the drive is currently mapped to a device-based driver).",13,10
db 13,10
db "'d' will revert the drive to its default mapping (the mapping at boot time).",13,10
db "'u' will leave the drive unmapped. Other parameters are ignored in both cases.",13,10
db 13,10
db "If a valid filename is supplied after <drive>, the specified file will be",13,10
db "mapped to the drive. A file cannot be mapped to its own drive, or to a drive",13,10
db "that contains a file that has been mapped. Prepend the filename with '/'",13,10
db "if the first character of his name is a digit.",13,10
db 1Ah
USAGE_S:
db "MAPDRV - map a drive to a driver, device, LUN and partition",13,10
db " or mount a file on a drive",13,10
db 13,10
db "MAPDRV [/L] <drive>: <partition>|d|u [<device>[-<LUN>] [<slot>[-<subslot>]|0]]",13,10
db "MAPDRV <drive>: [/]<filename> [/ro]",13,10
db 13,10
db "TYPE MAPDRV.COM for more details.",13,10
db 0
START:
call CHK250##
ld de,BUF
ld a,1
call EXTPAR##
jr nz,FOUND_PARAMS
ld de,USAGE_S
ld c,_ZSTROUT##
call 5
ld b,a
ld c,_TERM##
jp 5
FOUND_PARAMS:
;--- Get parameters
;* Check for /L
ld iy,2
ld a,(BUF)
cp '/'
jr nz,NO_LOCK
inc hl
ld a,(BUF+1)
or 32
cp 'l'
jr nz,NO_LOCK
ld a,-1
ld (DO_LOCK),a
ld de,buf
ld a,2
call EXTPAR##
ld b,.NOPAR##
ld c,_TERM##
jp c,5
inc iy
NO_LOCK:
;* Drive letter
ld hl,BUF
call CHKLET##
dec a
ld (DRIVE),a
;* Partition number, or "d", "u", or file name
ld de,BUF
ld_a_iyl
inc iy
call EXTPAR##
ld b,.NOPAR##
ld c,_TERM##
jp c,5
ld a,(de)
cp "/"
inc de
jp z,IS_FILE_DE
ld hl,BUF ;Try to get first parameter as a number
call EXT8##
jr nc,IS_PART
ld a,(BUF+1)
or a
jp nz,IS_FILE
ld a,(BUF) ;Check fo special values "d" and "u"
or 20h
cp "d"
ld b,1
jp z,DO_MAP_DU
cp "u"
ld b,0
jp z,DO_MAP_DU
jp IS_FILE
IS_PART:
ld (PARTITION),a
;* Device, LUN
ld de,BUF
ld_a_iyl
inc iy
call EXTPAR##
jp c,DO_MAP
ld a,(BUF)
cp "1"
jp c,IPARM_TERM
cp "8"
jp nc,IPARM_TERM
sub "0"
ld (DEVICE),a
ld a,(BUF+1)
or a
jr z,OK_DEVLUN
cp "-"
jp nz,IPARM_TERM
ld a,(BUF+2)
cp "1"
jp c,IPARM_TERM
cp "8"
jp nc,IPARM_TERM
sub "0"
ld (LUN),a
OK_DEVLUN:
;* Slot, subslot, segment
ld de,BUF
ld_a_iyl
inc iy
call EXTPAR##
jp c,DO_MAP
ld hl,BUF
call GETSLOT##
or a
jr nz,NO_MAIN
ld a,(0F348h)
NO_MAIN:
ld (SLOT),a
ld a,b
ld (SEGMENT),a
jr DO_MAP
;--- Do the mapping to default value, or unmap the drive
; Input: B=0 to unmap, B=1 to map to default value
DO_MAP_DU:
ld a,(DRIVE)
ld c,_MAPDRV##
call 5
ld b,a
ld c,_TERM##
jp 5
;--- Do the mapping to partition and device
DO_MAP:
;* If no slot specified, get the current drive mapping
ld a,(SLOT)
inc a
jr nz,OK_GETCURMAP
ld a,(DRIVE)
ld hl,BUF_LETTER
ld c,_GDLI##
call 5
ld b,a
ld c,_TERM##
jp nz,5
ld a,(BUF_LETTER)
cp 1
ld b,.IDRV##
ld c,_TERM##
jp nz,5 ;Error if not assigned to a block device
ld a,(DEVICE)
or a
jr nz,OK_DEVICE
ld a,(BUF_LETTER+4)
ld (DEVICE),a
ld a,(BUF_LETTER+5)
ld (LUN),a
OK_DEVICE:
xor a
inc hl
ld d,(hl)
inc hl
ld e,(hl)
ld hl,BUF_DRIVER
ld c,_GDRVR##
call 5
ld b,a
ld c,_TERM##
jp nz,5
ld a,(BUF_DRIVER+4)
and 1
ld b,.IDRVR##
ld c,_TERM##
jp z,5 ;Error if not assigned to a device-based driver
ld a,(BUF_DRIVER)
ld (SLOT),a
ld a,(BUF_DRIVER+1)
ld (SEGMENT),a
OK_GETCURMAP:
;* Convert partition to primary or extended as appropriate
ld a,(PARTITION)
or a
jp z,OK_ADJUST_PARTITION
cp 1
jr z,IS_PRIM_PART
cp 5
jr nc,IS_EXT_PART
ld hl,0
ld de,0
ld ix,DRIVE
ld a,(ix+3) ;Slot
ld b,(ix+4) ;Segment
ld d,(ix+5) ;Device
ld e,(ix+6) ;LUN
ld h,2 ;Primary partition
ld l,0 ;Extended partition
ld c,_GPART##
call 5
ld h,b
ld b,a
ld c,_TERM##
jp nz,5
ld a,h
cp 5 ;Is extended?
jr z,IS_EXT_PART
IS_PRIM_PART:
ld a,(PARTITION)
ld (PRIMARY),a
xor a
ld (EXTENDED),a
jr OK_ADJUST_PARTITION
IS_EXT_PART:
ld a,2
ld (PRIMARY),a
ld a,(PARTITION)
dec a
ld (EXTENDED),a
OK_ADJUST_PARTITION::
;* Obtain the partition information
ld hl,0
ld de,0
ld a,(PRIMARY)
or a
jr z,OK_PARTINFO
ld ix,DRIVE
ld a,(ix+3) ;Slot
ld b,(ix+4) ;Segment
ld d,(ix+5) ;Device
ld e,(ix+6) ;LUN
ld h,(ix+1) ;Primary partition
ld l,(ix+2) ;Extended partition
ld c,_GPART##
call 5
ld b,a
ld c,_TERM##
jp nz,5
OK_PARTINFO:
;* Finally, do the actual mapping and lock if necessary
ld (SLOT+4),de
ld (SLOT+6),hl
ld a,(DRIVE)
ld b,2
ld hl,SLOT ;Information is already in the right order for _MAPDRV
ld c,_MAPDRV##
call 5
ld b,a
or a
jr nz,DO_LOCK_OK
ld a,(DO_LOCK)
or a
jr z,DO_LOCK_OK
ld a,(DRIVE)
ld e,a
ld a,1
ld b,0FFh
ld c,_LOCK##
call 5
ld b,a
DO_LOCK_OK:
ld c,_TERM##
jp 5
;--- Do the mapping to a file.
; FIB is appropriately filled already.
IS_FILE:
ld de,BUF
IS_FILE_DE:
ld b,10110b ;Include directories, hidden and system files
ld c,_FFIRST##
ld ix,FIB
call 5
jp nz,DO_TERM
call CHKNEX21
; * First, extract "/ro" parameter if present
ld de,FIB+64
ld a,3
call EXTPAR##
ld d,0
jp c,DO_FILE
ld a,(FIB+64)
cp '/'
jp nz,IPARM_TERM
ld a,(FIB+65)
or 32
cp 'r'
jp nz,IPARM_TERM
ld a,(FIB+66)
or 32
cp 'o'
jp nz,IPARM_TERM
ld a,(FIB+67)
or a
jp nz,IPARM_TERM
ld d,1
DO_FILE:
ld a,(DRIVE)
ld bc,_MAPDRV##+3*256
ld hl,FIB
call 5
DO_TERM:
ld b,a
ld c,_TERM##
jp 5
EXTNUM_TERM:
call EXT8##
ret nc
IPARM_TERM:
ld b,.IPARM##
ld c,_TERM##
jp 5
NOPARM_TERM:
ld b,.NOPAR##
ld c,_TERM##
jp 5
CHKNEX21:
ld b,05Ah
ld hl,01234h
ld de,0ABCDh
ld c,_DOSVER##
ld ix,0
call 5
ld a,b
cp 2
jr c,CHK21_ERR
push ix
pop bc
ld a,b
cp 1 ;NEXTOR_ID
jr nz,CHK21_ERR
ld a,c
cp 2
jr c,CHK21_ERR
push iy
pop bc
ld a,b
or a
ret nz
CHK21_ERR:
ld de,BADKER21_MSG
ld c,_STROUT##
call 5
ld c,_TERM0##
jp 5
BADKER21_MSG:
db "*** File mounting requires Nextor 2.1 or later",13,10,"$"
PARTITION: db 0
DO_LOCK: db 0
DRIVE: db 0
PRIMARY: db 0
EXTENDED: db 0
SLOT: db -1
SEGMENT: db 255
DEVICE: db 0
LUN: db 1
FILE_FLAGS: db 0
BUF:
BUF_DRIVER:
BUF_LETTER:
end