-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathdrv.mac
1107 lines (906 loc) · 19.1 KB
/
drv.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
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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.z80
name('drv')
title MSX-DOS 2 ROM Copyright (1986) IS Systems Ltd.
subttl Substitute for the dummy disk driver module
; In MSX-DOS 2.3x, this was a dummy disk driver module that simply returned errors when called.
; Now this contains code that redirects calls to the driver bank.
;-----------------------------------------------------------------------------
;
INCLUDE macros.inc
INCLUDE const.inc
;
;-----------------------------------------------------------------------------
;
SCANKEYS equ 41EFh-3 ;As defined in init.mac
PRINTL macro NAME,VALUE
if2
.PRINTX % Size of NAME = VALUE bytes %
endif
endm
ALIGN macro ADDR
if $-START gt ADDR-ORIGIN
error <Code overwraps at ADDR>
PRINTL <wrap at ADDR>,%($-START)-(ADDR-ORIGIN)
org ADDR-ORIGIN
else
PRINTL <hole at ADDR>,%(ADDR-ORIGIN)-($-START)
defs (ADDR-ORIGIN)-($-START),0
endif
endm
ORIGIN equ 7700h
ALIGN 7700h
;
; External Routines.
;
; extrn PROMPT,SETINT,PRVINT,GETSLOT,GETWRK,DIV16,ENASLT,XFER
;
; External Variables.
;
; extrn $SECBUF,RAMAD0,RAMAD1,RAMAD2,RAMAD3,RAWFLG
;
; Public Values.
;
public DEFDPB
;
;-----------------------------------------------------------------------------
;This routine is invoked in disk emulation mode prior to any disk access.
;If checks if a valid file change key is being pressed, and if so,
;reloads the emulation data file and updates the information in DVB_TABLE.
;If no suitable key is being pressed, or if change is performed ok, returns Z.
;If there is an error reading the emulation data file, returns NZ and A=Error code.
CHGFILE:
push hl
push de
push bc
push ix
push iy
call CHGF2
pop iy
pop ix
pop bc
pop de
pop hl
ret
CHGF2:
ld ix,(DVB_TABLE##)
call GETCURKEY
or a
ret z
cp 0FFh
jr nz,CHGF3
call CAPSON
call WAIT_KEY_RELEASE ;GRAPH pressed: wait for other keys to release...
CHGWA2:
call GETCURKEY ;...then to be pressed again.
or a
jr z,CHGWA2
cp 0FFh ;User changed his mind and pressed GRAPH
jr nz,CHGF3
call WAIT_KEY_RELEASE
ret
CHGF3:
ld c,a
call CAPSON
;--- The key with index C is pressed
;> Do nothing if chosen file is the same currently in use
ld a,(ix+DSK_CURRENT_FILE_INDEX##)
and 3Fh
cp c
call z,CAPSOFF
ret z
;> Read emulation data file
push bc
ld a,(ix+EMU_DEV_AND_LUN##) ;data file dev index + 16 * LUN index
ld d,a
rrca
rrca
rrca
rrca
and 111b
ld b,a ;LUN
ld a,d
and 111b ;Device
ld l,(ix+EMU_FILE_FIRST_SECTOR##)
ld h,(ix+EMU_FILE_FIRST_SECTOR##+1)
ld (TMP_SEC##),hl
ld l,(ix+EMU_FILE_FIRST_SECTOR##+2)
ld h,(ix+EMU_FILE_FIRST_SECTOR##+3)
ld (TMP_SEC##+2),hl
ld iy,(0F348h-1) ;Master controller slot
ld hl,DEV_RW##
ld (BK4_ADD##),hl
ld c,b
ld b,1
ld hl,($SECBUF##)
ld de,TMP_SEC##
or a
push ix
ld ix,CALDRV##
call CALSLT## ;Call DEV_RW
pop ix
pop bc
call CAPSOFF
or a
ret nz
;> Set the new file data in work area
ld a,(ix+DSK_CURRENT_FILE_INDEX##)
and 11000000b ;In emulation mode flag + Russian keyboard flag
ld b,a
ld a,c
or b
ld (ix+DSK_CURRENT_FILE_INDEX##),a
set 7,(ix+EMU_DEV_AND_LUN##) ;File changed flag
dec a
add a,a ;Each entry is 8 bytes
add a,a
add a,a
ld l,a
ld h,0
ld bc,24
add hl,bc
ld de,($SECBUF##)
add hl,de ;HL = Pointer to boot file data
push ix
pop de
inc de
inc de ;DE must point to DSK_CURRENT_FILE_DEVICE_INDEX in work area
ld bc,8
ldir
ld a,(ix+DSK_CURRENT_FILE_DEVICE_INDEX##) ;set DSK_CURRENT_FILE_DEVICE_INDEX and DSK_CURRENT_FILE_LUN_INDEX as same of data file if 0
or a
jr nz,CHGF4
ld a,(ix+EMU_DEV_AND_LUN##)
ld b,a
and 00000111b
ld (ix+DSK_CURRENT_FILE_DEVICE_INDEX##),a
ld a,b
rrca
rrca
rrca
rrca
and 00000111b
ld (ix+DSK_CURRENT_FILE_LUN_INDEX##),a
CHGF4:
xor a
ret
WAIT_KEY_RELEASE:
call GETCURKEY
or a
jr nz,WAIT_KEY_RELEASE
ret
;Return in A the index of currently pressed key, 0 if none, FFh is GRAPH
;Input: IX = Pointer to emulation data area
GETCURKEY:
ex af,af'
ld a,(ix+DSK_CURRENT_FILE_INDEX##)
rlca
rlca
rlca
and 1 ;Russian keyboard?
ex af,af'
push ix
ld ix,SCANKEYS
xor a
call CALBNK##
pop ix
bit 6,h
ld a,0FFh
ret nz
ld c,b
ld b,(ix+DSK_EMULATED_FILES_COUNT##)
ld a,1
;HLDEC = key statuses
;B = Keys left to check
;A = Current key index
;We do an initial rotation because we want to start at key 1.
CHGLOOP:
sra c
rr e
rr d
rr l
rr h
bit 0,c
ret nz
inc a
djnz CHGLOOP
xor a
ret
CAPSON:
in a,(0AAh)
and 10111111b
out (0AAh),a
ret
CAPSOFF:
push af
in a,(0AAh)
or 01000000b
out (0AAh),a
pop af
ret
ALIGN 781Fh
;-----------------------------------------------------------------------------
;
; Null message. The address of this message can be returned by
; the CHOICE routine in the disk driver when the device can't be formatted.
null_message:
db 0
; "Single side/double side" message, can be used when driving
; a legacy MSX disk drive
db "1 - Single side",13,10
db "2 - Double side",13,10
db 0
; Moved here due to space constraints
DO_DIRCALL:
pop ix
push bc
ld bc,DV_D0##-DIRCALL-3
add ix,bc
pop bc
jp DO_CALBNK
;-----------------------------------------------------------------------------
;
; Entries for direct calls.
; Calls to these addresses will be translated to calls to the DV_DIRECTx
; entry points in the driver bank.
ALIGN 7850h
DIRCALL:
call DO_DIRCALL
call DO_DIRCALL
call DO_DIRCALL
call DO_DIRCALL
call DO_DIRCALL
; Process the output of DSKIO so that Cy is set
; if an error has been returned.
DIO_SET_ERR_FLAG::
push af
ld a,(KSLOT##)
or a
jr z,DIO_SET_ERR_FLAG_END
;Device-based: set Cy if error code is not 0
pop af
or a
ret z
scf
ret
;Drive-based driver: result will already have Cy set on error
DIO_SET_ERR_FLAG_END:
pop af
ret
;-----------------------------------------------------------------------------
;
; Entry for disk routine DSKIO. It is somewhat complex:
; if transfer involves page 1, then 1-sector transfers are done
; by using XFER and SECBUF.
;
DIO_ENTRY::
push af
call IS_DVB
jp nc,DIO_ENTRY_DO
ld a,(iy+UD1_DEVICE_INDEX##)
or a
jp z,DISKERR
call IS_EMU
jp c,DIOEN_ISEMU
;>>> NOT in disk emulation mode
DIOEN_NOEMU:
call HAS_PARTITION
call nz,ASSIGN_PARTITION
jp nz,POP_CONV_ERR
jr DIOEN3
;>>> In disk emulation mode
DIOEN_ISEMU:
pop af
push af
or a
jp nz,DISKERR ;Drive number must be 0
call CHGFILE
jr z,DIOCHGFOK
pop bc
ld b,0
ret
DIOCHGFOK:
; Moan if sector number + sector count > dsk file size
push hl
push de
ld ix,(DVB_TABLE##)
ld e,(ix+DSK_CURRENT_FILE_SECTORS_COUNT##)
ld d,(ix+DSK_CURRENT_FILE_SECTORS_COUNT##+1) ;DE = dsk size in sectors
pop hl
push hl
push bc
ld c,b
ld b,0
add hl,bc ;HL = Sector num + count
pop bc
dec hl
call COMP16
pop de
pop hl
jp nc,DIO_RNF
; Wait for VDP interrupt.
; This introduces a small delay that is required by some games.
di
ld a,2
out (99h),a
ld a,8fh
out (99h),a
WVDP:
in a,(99h)
and 81h
dec a
jr z,WVDP
xor a
out (99h),a
ld a,8fh
out (99h),a
call CAPSON
pop af
call DIOEN2
call CAPSOFF
ret
DIOEN2:
push af
ld iy,(DVB_TABLE)
DIOEN3:
; In this point one of these is true:
;
; - We are in disk emulation mode, and IY points to the beginning
; of the work area for emulation mode.
;
; - We are in normal DOS 1 mode, and IY points to the entry
; for the drive in DVB_TABLE.
;
; The following code is common to both cases, that's why
; device index, LUN index and first sector number must be stored
; at the same offset in both the DVB_TABLE entries (UD1_*)
; and the disk emulation work area (DSK_*).
ld a,1
ld (KSLOT##),a ;KSLOT=1 -> device-based
push hl
ld l,(iy+UD1_FIRST_ABSOLUTE_SECTOR##)
ld h,(iy+UD1_FIRST_ABSOLUTE_SECTOR##+1)
add hl,de
ld ix,TMP_SEC##
ld (ix),l ;Calculate absolute sector number
ld (ix+1),h
ld l,(iy+UD1_FIRST_ABSOLUTE_SECTOR##+2)
ld h,(iy+UD1_FIRST_ABSOLUTE_SECTOR##+3)
ld de,0
adc hl,de
ld (ix+2),l
ld (ix+3),h
pop hl ;Restore transfer address
ld de,TMP_SEC##
ld c,(iy+UD1_LUN_INDEX##) ;Set LUN index
pop af ;From here Cy must be kept untouched
ld a,(iy+UD1_DEVICE_INDEX##) ;Set device index
jr DIO_ENTRY_DO_2
;From here, the processing is almost the same for device-based drivers
;and for drive-based drivers, since the relevant parameters are almost the same
;(B for the sector count, HL for the transfer address, A and C are not touched).
;The only thing to take in account, is that for drive-based, DE contains
;the sector number; and for device-based, DE is a pointer to a 32 bit sector number.
;We use KSLOT to handle this difference.
DIO_ENTRY_DO:
xor a
ld (KSLOT##),a ;KSLOT=0 -> drive-based
pop af
DIO_ENTRY_DO_2:
; If the transfer starts and ends in page 0,
; ir of it starts in page 2 or 3,
; do all the transfer with a simple call to the driver
push af
bit 7,h
jp nz,DIO_NOP1 ;Transfer starts in page 2 or 3?
push hl
push bc
sla b
ld c,0 ;Now BC = number of bytes to read
add hl,bc
dec hl ;Now HL = last read or written address
ld a,h
and 11000000b ;Last accessed address in page 0?
pop bc
pop hl
jp z,DIO_NOP1
pop af
jp c,DIO_WR_LOOP
; Loop for reading to page 1
DIO_RD_LOOP:
push af
bit 7,h
jp nz,DIO_NOP1 ;If not in page 0/1 anymore,
push bc ;do the remaining transfer
push de ;with a simple call to the driver
push hl
or a
call DIO_DO_CALDRV
jr nc,DIO_RD_OK
pop hl ;On disk error, just return
pop de
pop bc
pop bc ;Not POP AF, to preserve error info
jp CONV_ERR
DIO_RD_OK:
ld hl,($SECBUF##)
pop de ;Was PUSH HL
push de
ld bc,512
call XFER##
pop hl
pop de
pop bc
inc h
inc h ;Increase destination address by 512
call DIO_INC_DE
pop af
djnz DIO_RD_LOOP
xor a
ret
; Loop for writing from page 1
DIO_WR_LOOP:
push af
bit 7,h
jr nz,DIO_NOP1 ;If not in page 0/1 anymore,
push hl ;do the remaining transfer
push bc ;with a simple call to the driver
push de
ld de,($SECBUF##)
ld bc,512
call XFER## ;Preserves AF
pop de
pop bc
push bc
push de
scf
call DIO_DO_CALDRV
jr nc,DIO_WR_OK
pop de ;On disk error, just return
pop bc
pop hl
pop hl ;Not POP AF, to preserve error info
ret
DIO_WR_OK:
pop de
pop bc
pop hl
inc h
inc h ;Increase destination address by 512
call DIO_INC_DE
pop af
djnz DIO_WR_LOOP
xor a
ret
DIO_DO_CALDRV:
ld hl,($SECBUF##)
ld b,1
ld ix,DV_DSKIO##
ex af,af'
ld a,DV_BANK##
call CALBNK##
jp DIO_SET_ERR_FLAG
; Jump here when the transfer can be done in a single step
; (no page 1 involved)
DIO_NOP1:
pop af
ld ix,DV_DSKIO##
call DO_CALBNK
jp CONV_ERR
;This subroutine increases the sector number by one.
;Corrupts AF, IX.
DIO_INC_DE:
ld a,(KSLOT##)
or a
jr nz,DIO_INC_DE_DVB
;Drive-based: simply increment DE.
;Note that C can't hold sector number,
;since this will be called in DOS 1 mode only,
;and DOS 1 does not support FAT16,
;so sector numbers are always 16 bit.
inc de
ret
;Device-based: increment the 32 bit number pointed by DE
DIO_INC_DE_DVB:
push hl
push de
pop ix
ld l,(ix)
ld h,(ix+1)
inc hl
ld (ix),l
ld (ix+1),h
ld a,h
or l
jr nz,DIO_INC_DE_DVB_END
ld l,(ix+2)
ld h,(ix+3)
inc hl
ld (ix+2),l
ld (ix+3),h
DIO_INC_DE_DVB_END:
pop hl
ret
;-----------------------------------------------------------------------------
;
; General disk routines entry
;--- Check disk change status
CHG_ENTRY::
call IS_DVB
ld ix,DV_CHGDSK##
jp nc,DO_CALBNK
ld d,a
ld a,(iy+UD1_DEVICE_INDEX##)
or a
jp z,DISKERR
call IS_EMU
jp nc,CHGEN_NOEMU
;>>> In disk emulation mode
ld a,d
or a
jp nz,DISKERR ;Drive number must be 0
call CHGFILE
ret nz
xor a
ld ix,(DVB_TABLE##)
bit 7,(ix+EMU_DEV_AND_LUN##)
res 7,(ix+EMU_DEV_AND_LUN##)
ld b,1
ret z
ld a,d
jp DPBEN2
;>>> NOT in disk emulation mode
CHGEN_NOEMU:
;Drive-based mapping:
;Return "changed" if partition has changed, "unchanged" otherwise
ld a,(iy+UD1_RELATIVE_DRIVE##)
ld c,a
res 7,(iy+UD1_RELATIVE_DRIVE##)
and 10000000b ;Check partition changed flag
ld b,-1
ld a,c
jr nz,DO_MKDPB ;"Changed" if partition has changed
xor a
ld b,1 ;"Unchanged" if partition has not changed
ret
;--- Obtain DPB, input: IY=Entry in DVB_TABLE, HL=Address for DPB
DPB_ENTRY::
call IS_DVB
ld ix,DV_GETDPB##
jp nc,DO_CALBNK
call IS_EMU
jr nc,DO_MKDPB
;>>> In disk emulation mode
;or a
;jp nz,DISKERR ;Drive number must be 0
call CHGFILE
ret nz
jr DPBEN2
;>>> NOT in disk emulation mode
DO_MKDPB:
call HAS_PARTITION
call nz,ASSIGN_PARTITION
jp nz,CONV_ERR
DPBEN2:
push hl
ld a,(iy+UD1_FIRST_ABSOLUTE_SECTOR##)
ld (TMP_SEC##),a
ld a,(iy+UD1_FIRST_ABSOLUTE_SECTOR##+1)
ld (TMP_SEC##+1),a
ld a,(iy+UD1_FIRST_ABSOLUTE_SECTOR##+2)
ld (TMP_SEC##+2),a
ld a,(iy+UD1_FIRST_ABSOLUTE_SECTOR##+3)
ld (TMP_SEC##+3),a
ld a,(iy+UD1_DEVICE_INDEX##)
ld b,1
ld c,(iy+UD1_LUN_INDEX##)
ld de,TMP_SEC##
ld hl,($SECBUF##)
or a
ld ix,DEV_RW##
call DO_CALBNK
pop de
inc de
or a
jp nz,CONV_ERR
ld hl,($SECBUF##)
ld bc,MKDPB##
ld (BK4_ADD##),bc
call C4PBK##
if 0
spfat::
ld a,(DOS_VER##)
or a
jr nz,MKDPB_OK_SECPERFAT
ld ix,($SECBUF##)
ld a,(ix+17h)
or a
jp nz,DISKERR
ld a,(ix+16h)
cp 4
jp nc,DISKERR
MKDPB_OK_SECPERFAT:
endif
xor a
ret
;--- Format choice
CHO_ENTRY::
call IS_DVB
ld ix,DV_CHOICE##
jp nc,DO_CALBNK
ld hl,781fh ;Formatting is no supported yet for device-based drivers
ret
;--- Format device
FMT_ENTRY::
call IS_DVB
ld ix,DV_CHOICE##
jp nc,DO_CALBNK
ld a,16 ;Formatting is no supported yet for device-based drivers
scf
ret
;--- Motor off
MOF_ENTRY::
call IS_DVB
ld ix,DV_MTOFF##
jp nc,DO_CALBNK
ret
DO_CALBNK:
ex af,af'
ld a,DV_BANK##
jp CALBNK##
;--- Jump here when an operation is requested
; on an existing, but empty, entry in DVB_TABLE
DISKERR:
ld a,12
scf
ret
DIO_RNF:
pop af
ld a,8
ld b,0
scf
ret
;-----------------------------------------------------------------------------
;
; Check if the relative drive pointer by A refers to a device-based driver
; and we are in DOS 1 mode. If so, returns Cy=1 and IY=pointer to the
; table entry in DVB_TABLE. Otherwise returns Cy=0.
; Corrupts IY, F.
IS_DVB:
push af
ld a,(DOS_VER##)
or a
jr nz,IS_NOT_DVB
ld iy,(DVB_TABLE##)
ld a,iyh
or iyl
jr z,IS_NOT_DVB
ld a,(iy)
and 80h
jr z,IS_DVB_NOEMU
pop af ;In emulation mode: return Cy=1 only if drive is 0
or a
scf
ret z
ccf
ret
IS_DVB_NOEMU:
pop af
push af
push bc
ld c,a ;C = Drive number
ld b,(iy) ;B = num of entries in DVB_TABLE
inc iy
IS_DVB_LOOP:
push bc
ld a,(KSLOT##)
ld b,(iy+UD1_SLOT##)
res 6,b
cp b
pop bc
jr nz,DIO_NEXT
ld a,(iy+UD1_RELATIVE_DRIVE##)
and 01111111b ;Ignore partition changed flag
cp c
jr nz,DIO_NEXT
DIO_OK:
pop bc ;Found, return Cy=1
pop af
scf
ret
DIO_NEXT:
push bc
ld bc,8
add iy,bc
pop bc
djnz IS_DVB_LOOP
pop bc
IS_NOT_DVB:
pop af
scf
ccf
ret
;--------------
;
; Check if we are in disk emulation mode
; Assumes IS_DVB has returned Cy=1 (that is, in DOS 1 mode and DVB_TABLE exists)
; Returns Cy=1 if in emulation mode, Cy=0 if not
; Corruputs: F
IS_EMU:
push iy
ld iy,(DVB_TABLE##)
bit 7,(iy)
pop iy
scf
ret nz
ccf
ret
;-----------------------------------------------------------------------------
;
; Check if the entry of DVB_TABLE pointed by IY has a partition assigned.
; Return A=0, Z if partition assigned; A<>0, NZ if NO partition assigned.
HAS_PARTITION:
ld a,(iy+UD1_FIRST_ABSOLUTE_SECTOR##) ;No partition assigned
and (iy+UD1_FIRST_ABSOLUTE_SECTOR##+1) ;if sector number is -1
and (iy+UD1_FIRST_ABSOLUTE_SECTOR##+2)
and (iy+UD1_FIRST_ABSOLUTE_SECTOR##+3)
inc a
jr z,RET_NZ
xor a
ret
RET_NZ:
inc a
ret
;-----------------------------------------------------------------------------
;
; Assign the first available FAT12 primary partition to
; the device whose entry of DVB_TABLE pointed by IY.
; Returns disk error code in A, with Z appropriately set.
; Corrupts: AF, IX.
MBR_PSTART equ 01BEh ;Start of partition table in MBR
MBR_PSIZE equ 16 ;Size of partition table entry
POFF_TYPE equ 4 ;Offset of partition type in p. table entry
POFF_PSTART equ 8 ;Offset of partition start in p. table entry
POFF_PSIZE equ 12 ;Offset of partition size in p. table entry
PT_FAT12 equ 1 ;Partition type code for FAT12
ASSIGN_PARTITION:
push bc
push de
push hl
push iy
pop hl
push hl
ld b,(iy+UD1_DEVICE_INDEX##)
ld c,(iy+UD1_LUN_INDEX##)
ld a,4
ld d,0
ld ix,AUTO_ASPART##
call CALBNK##
pop iy
pop hl
pop de
pop bc
or a
ret z
ld a,12
ret
;-----------------------------------------------------------------------------
;
; Read the MBR of the device whose entry in DVB_TABLE
; is pointed by IY. Returns the disk error in A.
; Corrupts AF, BC, DE, HL, IX, IY.
READ_BOOT:
ld de,0
ld (TMP_SEC##),de
ld (TMP_SEC##+2),de
ld a,(iy+UD1_DEVICE_INDEX##)
ld b,1
ld c,(iy+UD1_LUN_INDEX##)
ld de,TMP_SEC##
ld hl,($SECBUF##)
or a
ld ix,DEV_RW##
jp DO_CALBNK
;-----------------------------------------------------------------------------
;
; Convert the disk error returned by a device-based routine,
; into its drive-based equivalent
POP_CONV_ERR:
inc sp
inc sp
CONV_ERR:
or a
ret z