-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
DRIVER.ASM
687 lines (550 loc) · 17.5 KB
/
DRIVER.ASM
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
; Dummy disk driver for Nextor 2.0
; By Konamiman, 8/2018
;
; This code can be used as the basis for developing
; a real disk driver: just set DRV_TYPE appropriately,
; change the driver name and version at DRV_NAME and VER_*, and
; implement the required routines depending on the driver type.
;
; See the Nextor driver development guide for more details.
;org 4100h
DRV_START:
;-----------------------------------------------------------------------------
;
; Miscellaneous constants
;
;This is a 2 byte buffer to store the address of code to be executed.
;It is used by some of the kernel page 0 routines.
CODE_ADD: equ 0F84Ch
;-----------------------------------------------------------------------------
;
; Driver configuration constants
;
;Driver type:
; 0 for drive-based
; 1 for device-based
DRV_TYPE equ 0
;Driver version
VER_MAIN equ 1
VER_SEC equ 0
VER_REV equ 0
;-----------------------------------------------------------------------------
;
; Error codes for DEV_RW
;
if DRV_TYPE eq 1
.NCOMP equ 0FFh
.WRERR equ 0FEh
.DISK equ 0FDh
.NRDY equ 0FCh
.DATA equ 0FAh
.RNF equ 0F9h
.WPROT equ 0F8h
.UFORM equ 0F7h
.SEEK equ 0F3h
.IFORM equ 0F0h
.IDEVL equ 0B5h
.IPARM equ 08Bh
endif
;-----------------------------------------------------------------------------
;
; Routines and information available on kernel page 0
;
;* Get in A the current slot for page 1. Corrupts F.
; Must be called by using CALBNK to bank 0:
; xor a
; ld ix,GSLOT1
; call CALBNK
GSLOT1 equ 402Dh
;* This routine reads a byte from another bank.
; Must be called by using CALBNK to the desired bank,
; passing the address to be read in HL:
; ld a,<bank number>
; ld hl,<byte address>
; ld ix,RDBANK
; call CALBNK
RDBANK equ 403Ch
;* This routine temporarily switches kernel main bank
; (usually bank 0, but will be 3 when running in MSX-DOS 1 mode),
; then invokes the routine whose address is at (CODE_ADD).
; It is necessary to use this routine to invoke CALBAS
; (so that kernel bank is correct in case of BASIC error)
; and to invoke DOS functions via F37Dh hook.
;
; Input: Address of code to invoke in (CODE_ADD).
; AF, BC, DE, HL, IX, IY passed to the called routine.
; Output: AF, BC, DE, HL, IX, IY returned from the called routine.
CALLB0 equ 403Fh
;* Call a routine in another bank.
; Must be used if the driver spawns across more than one bank.
;
; Input: A = bank number
; IX = routine address
; AF' = AF for the routine
; HL' = Ix for the routine
; BC, DE, HL, IY = input for the routine
; Output: AF, BC, DE, HL, IX, IY returned from the called routine.
CALBNK equ 4042h
;* Get in IX the address of the SLTWRK entry for the slot passed in A,
; which will in turn contain a pointer to the allocated page 3
; work area for that slot (0 if no work area was allocated).
; If A=0, then it uses the slot currently switched in page 1.
; Returns A=current slot for page 1, if A=0 was passed.
; Corrupts F.
; Must be called by using CALBNK to bank 0:
; ld a,<slot number> (xor a for current page 1 slot)
; ex af,af'
; xor a
; ld ix,GWORK
; call CALBNK
GWORK equ 4045h
;* This address contains one byte that tells how many banks
; form the Nextor kernel (or alternatively, the first bank
; number of the driver).
K_SIZE equ 40FEh
;* This address contains one byte with the current bank number.
CUR_BANK equ 40FFh
;-----------------------------------------------------------------------------
;
; Built-in format choice strings
;
NULL_MSG equ 781Fh ;Null string (disk can't be formatted)
SING_DBL equ 7820h ;"1-Single side / 2-Double side"
;-----------------------------------------------------------------------------
;
; Driver signature
;
db "NEXTOR_DRIVER",0
;-----------------------------------------------------------------------------
;
; Driver flags:
; bit 0: 0 for drive-based, 1 for device-based
; bit 2: 1 if the driver implements the DRV_CONFIG routine
; (used by Nextor from v2.0.5)
if DRV_TYPE eq 0
db 0+4
endif
if DRV_TYPE eq 1
db 1+4
endif
;-----------------------------------------------------------------------------
;
; Reserved byte
;
db 0
;-----------------------------------------------------------------------------
;
; Driver name
;
DRV_NAME:
db "Dummy driver"
ds 32-($-DRV_NAME)," "
;-----------------------------------------------------------------------------
;
; Jump table for the driver public routines
;
; These routines are mandatory for all drivers
; (but probably you need to implement only DRV_INIT)
jp DRV_TIMI
jp DRV_VERSION
jp DRV_INIT
jp DRV_BASSTAT
jp DRV_BASDEV
jp DRV_EXTBIO
jp DRV_DIRECT0
jp DRV_DIRECT1
jp DRV_DIRECT2
jp DRV_DIRECT3
jp DRV_DIRECT4
jp DRV_CONFIG
ds 12
if DRV_TYPE eq 0
; These routines are mandatory for drive-based drivers
jp DRV_DSKIO
jp DRV_DSKCHG
jp DRV_GETDPB
jp DRV_CHOICE
jp DRV_DSKFMT
jp DRV_MTOFF
endif
if DRV_TYPE eq 1
; These routines are mandatory for device-based drivers
jp DEV_RW
jp DEV_INFO
jp DEV_STATUS
jp LUN_INFO
endif
;=====
;===== END of data that must be at fixed addresses
;=====
;-----------------------------------------------------------------------------
;
; Timer interrupt routine, it will be called on each timer interrupt
; (at 50 or 60Hz), but only if DRV_INIT returns Cy=1 on its first execution.
DRV_TIMI:
ret
;-----------------------------------------------------------------------------
;
; Driver initialization routine, it is called twice:
;
; 1) First execution, for information gathering.
; Input:
; A = 0
; B = number of available drives
; HL = maximum size of allocatable work area in page 3
; Output:
; A = number of required drives (for drive-based driver only)
; HL = size of required work area in page 3
; Cy = 1 if DRV_TIMI must be hooked to the timer interrupt, 0 otherwise
;
; 2) Second execution, for work area and hardware initialization.
; Input:
; A = 1
; B = number of allocated drives for this controller
;
; The work area address can be obtained by using GWORK.
;
; If first execution requests more work area than available,
; second execution will not be done and DRV_TIMI will not be hooked
; to the timer interrupt.
;
; If first execution requests more drives than available,
; as many drives as possible will be allocated, and the initialization
; procedure will continue the normal way
; (for drive-based drivers only. Device-based drivers always
; get two allocated drives.)
DRV_INIT:
xor a
ld hl,0
ret
;-----------------------------------------------------------------------------
;
; Obtain driver version
;
; Input: -
; Output: A = Main version number
; B = Secondary version number
; C = Revision number
DRV_VERSION:
ld a,VER_MAIN
ld b,VER_SEC
ld c,VER_REV
ret
;-----------------------------------------------------------------------------
;
; BASIC expanded statement ("CALL") handler.
; Works the expected way, except that if invoking CALBAS is needed,
; it must be done via the CALLB0 routine in kernel page 0.
DRV_BASSTAT:
scf
ret
;-----------------------------------------------------------------------------
;
; BASIC expanded device handler.
; Works the expected way, except that if invoking CALBAS is needed,
; it must be done via the CALLB0 routine in kernel page 0.
DRV_BASDEV:
scf
ret
;-----------------------------------------------------------------------------
;
; Extended BIOS hook.
; Works the expected way, except that it must return
; D'=1 if the old hook must be called, D'=0 otherwise.
; It is entered with D'=1.
DRV_EXTBIO:
ret
;-----------------------------------------------------------------------------
;
; Direct calls entry points.
; Calls to addresses 7850h, 7853h, 7856h, 7859h and 785Ch
; in kernel banks 0 and 3 will be redirected
; to DIRECT0/1/2/3/4 respectively.
; Receives all register data from the caller except IX and AF'.
DRV_DIRECT0:
DRV_DIRECT1:
DRV_DIRECT2:
DRV_DIRECT3:
DRV_DIRECT4:
ret
;-----------------------------------------------------------------------------
;
; Get driver configuration
; (bit 2 of driver flags must be set if this routine is implemented)
;
; Input:
; A = Configuration index
; BC, DE, HL = Depends on the configuration
;
; Output:
; A = 0: Ok
; 1: Configuration not available for the supplied index
; BC, DE, HL = Depends on the configuration
;
; * Get number of drives at boot time (for device-based drivers only):
; Input:
; A = 1
; B = 0 for DOS 2 mode, 1 for DOS 1 mode
; Output:
; B = number of drives
;
; * Get default configuration for drive
; Input:
; A = 2
; B = 0 for DOS 2 mode, 1 for DOS 1 mode
; C = Relative drive number at boot time
; Output:
; B = Device index
; C = LUN index
DRV_CONFIG:
ld a,1
ret
;=====
;===== BEGIN of DRIVE-BASED specific routines
;=====
if DRV_TYPE eq 0
;-----------------------------------------------------------------------------
;
; Read/write disk sectors
;
;Input: A = Drive number, starting at 0
; Cy = 0 for reading sectors, 1 for writing sectors
; B = Number of sectors to read/write
; C = First sector number to read/write (bits 22-16) if bit 7 = 0
; Media ID if bit 7 = 1
; DE = First sector number to read/write (bits 15-0)
; HL = source/destination address for the transfer
;Output: Cy = 0 on success, 1 on error
; A = Error code (on error only):
; 0 Write protected
; 2 Not ready
; 4 Data (CRC) error
; 6 Seek error
; 8 Record not found
; 10 Write fault
; 12 Other errors
; B = Number of sectors actually read (in case of error only)
DRV_DSKIO:
ld a,12
scf
ret
;-----------------------------------------------------------------------------
;
; Get disk change status
;
;Input: A = Drive number, starting at 0
; B = C = Media descriptor
; HL = Base address for DPB -1
;Output: Cy = 0 on success, 1 on error
; A = Error code (on error only)
; Same codes as DRV_DSKIO
; B = Disk status (on success only)
; 1 Disk not changed
; 0 Unknown
; -1 Disk changed
DRV_DSKCHG:
ld a,12
scf
ret
;-----------------------------------------------------------------------------
;
; Get DPB for disk
;
;Input: A = Drive number, starting at 0
; B = C = Media descriptor
; HL = Base address for DPB -1
;Output: -
DRV_GETDPB:
ld a,12
scf
ret
;-----------------------------------------------------------------------------
;
; Return format choice string
;
;Input: -
;Output: HL = Address of the choice string in the kernel slot
DRV_CHOICE:
ld hl,NULL_MSG
ret
;-----------------------------------------------------------------------------
;
; Format a disk
;
;Input: A = Formatting choice, from 1 to 9 (see DRV_CHOICE).
; D = Drive number, starting at 0
; HL = Address of work area in memory
; DE = Size of work area
;Output: Cy = 0 on success, 1 on error
; A = Error code (on error only):
; 0 Write protected
; 2 Not ready
; 4 Data (CRC) error
; 6 Seek error
; 8 Record not found
; 10 Write fault
; 12 Bad parameter
; 14 Insufficient memory
; 16 Other errors
DRV_DSKFMT:
ld a,16
scf
ret
;-----------------------------------------------------------------------------
;
; Turn off the floppy disk drive motor
;
;Input: -
;Output: -
DRV_MTOFF:
ret
endif
;=====
;===== END of DRIVE-BASED specific routines
;=====
;=====
;===== BEGIN of DEVICE-BASED specific routines
;=====
if DRV_TYPE eq 1
;-----------------------------------------------------------------------------
;
; Read or write logical sectors from/to a logical unit
;
;Input: Cy=0 to read, 1 to write
; A = Device number, 1 to 7
; B = Number of sectors to read or write
; C = Logical unit number, 1 to 7
; HL = Source or destination memory address for the transfer
; DE = Address where the 4 byte sector number is stored.
;Output: A = Error code (the same codes of MSX-DOS are used):
; 0: Ok
; .IDEVL: Invalid device or LUN
; .NRDY: Not ready
; .DISK: General unknown disk error
; .DATA: CRC error when reading
; .RNF: Sector not found
; .UFORM: Unformatted disk
; .WPROT: Write protected media, or read-only logical unit
; .WRERR: Write error
; .NCOMP: Incompatible disk.
; .SEEK: Seek error.
B = Number of sectors actually read (in case of error only)
DEV_RW:
ld a,.NRDY
ld b,0
ret
;-----------------------------------------------------------------------------
;
; Device information gathering
;
;Input: A = Device index, 1 to 7
; B = Information to return:
; 0: Basic information
; 1: Manufacturer name string
; 2: Device name string
; 3: Serial number string
; HL = Pointer to a buffer in RAM
;Output: A = Error code:
; 0: Ok
; 1: Device not available or invalid device index
; 2: Information not available, or invalid information index
; When basic information is requested,
; buffer filled with the following information:
;
;+0 (1): Numer of logical units, from 1 to 7. 1 if the device has no logical
; units (which is functionally equivalent to having only one).
;+1 (1): Device flags, always zero in Beta 2.
;
; The strings must be printable ASCII string (ASCII codes 32 to 126),
; left justified and padded with spaces. All the strings are optional,
; if not available, an error must be returned.
; If a string is provided by the device in binary format, it must be reported
; as an hexadecimal, upper-cased string, preceded by the prefix "0x".
; The maximum length for a string is 64 characters;
; if the string is actually longer, the leftmost 64 characters
; should be provided.
;
; In the case of the serial number string, the same rules for the strings
; apply, except that it must be provided right-justified,
; and if it is too long, the rightmost characters must be
; provided, not the leftmost.
DEV_INFO:
ld a,1
ret
;-----------------------------------------------------------------------------
;
; Obtain device status
;
;Input: A = Device index, 1 to 7
; B = Logical unit number, 1 to 7
; 0 to return the status of the device itself.
;Output: A = Status for the specified logical unit,
; or for the whole device if 0 was specified:
; 0: The device or logical unit is not available, or the
; device or logical unit number supplied is invalid.
; 1: The device or logical unit is available and has not
; changed since the last status request.
; 2: The device or logical unit is available and has changed
; since the last status request
; (for devices, the device has been unplugged and a
; different device has been plugged which has been
; assigned the same device index; for logical units,
; the media has been changed).
; 3: The device or logical unit is available, but it is not
; possible to determine whether it has been changed
; or not since the last status request.
;
; Devices not supporting hot-plugging must always return status value 1.
; Non removable logical units may return values 0 and 1.
;
; The returned status is always relative to the previous invokation of
; DEV_STATUS itself. Please read the Driver Developer Guide for more info.
DEV_STATUS:
xor a
ret
;-----------------------------------------------------------------------------
;
; Obtain logical unit information
;
;Input: A = Device index, 1 to 7
; B = Logical unit number, 1 to 7
; HL = Pointer to buffer in RAM.
;Output: A = 0: Ok, buffer filled with information.
; 1: Error, device or logical unit not available,
; or device index or logical unit number invalid.
; On success, buffer filled with the following information:
;
;+0 (1): Medium type:
; 0: Block device
; 1: CD or DVD reader or recorder
; 2-254: Unused. Additional codes may be defined in the future.
; 255: Other
;+1 (2): Sector size, 0 if this information does not apply or is
; not available.
;+3 (4): Total number of available sectors.
; 0 if this information does not apply or is not available.
;+7 (1): Flags:
; bit 0: 1 if the medium is removable.
; bit 1: 1 if the medium is read only. A medium that can dinamically
; be write protected or write enabled is not considered
; to be read-only.
; bit 2: 1 if the LUN is a floppy disk drive.
;+8 (2): Number of cylinders
;+10 (1): Number of heads
;+11 (1): Number of sectors per track
;
; Number of cylinders, heads and sectors apply to hard disks only.
; For other types of device, these fields must be zero.
LUN_INFO:
ld a,1
ret
endif
;=====
;===== END of DEVICE-BASED specific routines
;=====
;-----------------------------------------------------------------------------
;
; End of the driver code
DRV_END:
;ds 3FD0h-(DRV_END-DRV_START)
end