/
mfrsd.asm
2197 lines (1821 loc) · 42.8 KB
/
mfrsd.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
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
;-----------------------------------------------------------------------------
;
; MegaFlashROM SCC+ SD disk driver for Nextor
; By Manuel Pazos 14/12/2012
;
; 24/07/2018 - v1.3 Implement DRV_CONFIG routine (Nextor 2.0.5)
;-----------------------------------------------------------------------------
DRIVER_VERSION equ 1
DRIVER_SUBVERSION equ 3
.RELAB
;---------------------------------------------------------------------------
; MACROS
;---------------------------------------------------------------------------
ADD_HL_A macro
add a, l ; 4
ld l, a ; 4
adc a, h ; 4
sub l ; 4
ld h, a ; 4
ENDM
ADD_DE_A macro
add a, e ; 4
ld e, a ; 4
adc a, d ; 4
sub e ; 4
ld d, a ; 4
ENDM
;-----------------------------------------------------------------------------
; Constants
;-----------------------------------------------------------------------------
WORK_AREA_SIZE equ 0 ; RAM needed by the driver
;The NUM_SLOTS constant (SD card slots available) must be defined externally
ifndef NUM_SLOTS
.fatal NUM_SLOTS constant required with a value of 1 or 2
else
if (NUM_SLOTS NE 1) and (NUM_SLOTS NE 2)
.fatal The value of NUM_SLOTS must be either 1 or 2, got {NUM_SLOTS}
endif
endif
; Work area offsets
STATUS equ 0 ; Offset in work area to status byte
BIT_SDHC equ 0 ; 0 = SDSC, 1 = SDHC
BIT_SD_CHG equ 1 ; 0 = Not changed, 1 = Changed
BIT_ROM_DSK equ 2 ; 0 = Not available, 1 = Available
;CARD_TYPE equ 31
; Cards types
CARD_MMC equ 0
CARD_SD1X equ 1
CARD_SD2X equ 2
CARD_SDHC equ 3
;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 0F2EDh
; BIOS
ENASLT: equ #24
CHGET equ #9f
CHPUT equ #A2 ;Character output
RSLREG: equ #138
EXPTBL: equ #FCC1
SLTWRK: equ #FD09
; SD
DATA_TOKEN equ #FE
MUL_DAT_TKN_STA equ #FC
MUL_DAT_TKN_END equ #FD
;Driver type:
DRV_TYPE equ 1 ; 0 for drive-based, 1 for device-based
;Driver version
VER_MAIN equ 1
VER_SEC equ 3
VER_REV equ 0
; Error codes for DEV_RW
IF DRV_TYPE = 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
;-----------------------------------------------------------------------------
; Start
;-----------------------------------------------------------------------------
org #4000
ds 256,0 ; Dummy bytes. Will be overwriten by Page 0 code
DRV_START:
;-----------------------------------------------------------------------------
;
; 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 1: 1 for hot-plug devices supported (device-based drivers only)
; bit 2: 1 if the driver provides configuration
; (implements the DRV_CONFIG routine)
;-----------------------------------------------------------------------------
IF DRV_TYPE = 0
db 0
ENDIF
IF DRV_TYPE = 1
db %00000111
ENDIF
;-----------------------------------------------------------------------------
;
; Reserved byte
;
;-----------------------------------------------------------------------------
db 0
;-----------------------------------------------------------------------------
;
; Driver name
;
;-----------------------------------------------------------------------------
DRV_NAME:
db "MegaFlashROM SCC+ SD"
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 = 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 = 1
; These routines are mandatory for device-based drivers
jp DEV_RW
jp DEV_INFO
jp DEV_STATUS
jp LUN_INFO
jp DEV_FORMAT
jp DEV_CMD
ENDIF
;=====
;===== END of data that must be at fixed addresses
;=====
;-----------------------------------------------------------------------------
;
; 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
;include "expcall.asm"
ret
;-----------------------------------------------------------------------------
; Dejamos libre el area usada por los puertos del MegaSD #4000-#5FFF
;-----------------------------------------------------------------------------
ds #6000-$
;-----------------------------------------------------------------------------
; 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:
or a
jr nz,.secondExe ; Second execution
ld hl,WORK_AREA_SIZE
;ld a,NUM_DRIVES
ret ;Note that Cy is 0 (no interrupt hooking needed)
.secondExe:
ld de,TXT_INFO
call PRINT ; Driver info
ld c,0
call RomDiskCheck
jr nz,.notFound ; ROM disk not found
ld de,TXT_ROMDSKOK
call PRINT ; Print "Rom disk found"
ld c,1 ; Flag ROM disk found
.notFound:
ld b,NUM_SLOTS
.loop:
push bc
di
ld a,NUM_SLOTS
sub b
call GETWRK
dec c
jr nz,.notRomDisk
set BIT_ROM_DSK,(ix+0) ; ROM disk available
.notRomDisk:
call SD_ON
ld a,NUM_SLOTS
sub b
ld c,a
push bc
ld (#5800),a ; Select SD slot
call InitSD ; Init SD card
call SD_OFF
pop bc ; C = SD slot
ei
.COMMENT *
push af
ld a,e
and #f
add a,"0"
call CHPUT ; Error code
pop af
;*
jr c,.notCard
jr nz,.notCard
ld b,e ; Card type
ld de,TXT_INIT
call PRINT ; Card init text
ld a,c ; SD slot
add a,'1'
call CHPUT
ld a,':'
call CHPUT
ld a,b ; Card type
rlca
ld hl,IDX_TYPE
ADD_HL_A
ld e,(hl)
inc hl
ld d,(hl)
call PRINT ; Shows card type
.notCard:
pop bc
djnz .loop
ld de,TXT_EMPTY
call PRINT
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 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 7450h, 7453h, 7456h, 7459h and 745Ch
; 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
;
; 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:
dec a
jr z,.GetNumDrives
dec a
jr z,.GetRelDrvNum
.error:
ld a,1 ; Unknown configuration index
ret
.GetNumDrives:
bit 5,c ;Single drive per driver requested?
ld b,1
ld a,0
ret nz
call RomDiskCheck
ld b,NUM_SLOTS+1 ; Three drives: ROM disk, SD 1 and SD 2
jr z,.GetNumDrives2
dec b ; ROM Disk not available
.GetNumDrives2:
xor a
ret
.GetRelDrvNum:
ld b,c
inc b
call RomDiskCheck
jr z,.ok
inc b
.ok:
ld c,1
xor a
ret
;=====
;===== BEGIN of DRIVE-BASED specific routines
;=====
IF DRV_TYPE = 0
include "drivebased.asm"
ENDIF
;=====
;===== END of DRIVE-BASED specific routines
;=====
;=====
;===== BEGIN of DEVICE-BASED specific routines
;=====
IF DRV_TYPE = 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:
push af
dec a
jp z,.romdisk ; ROM disk device
dec a
cp NUM_SLOTS ; Device number
jp nc,.error
dec c ; LUN
jp nz,.error
di
call SD_ON
ld (#5800),a ; SD slot select
call GETWRK
pop af ; Cy=0 to read, 1 to write
jr c,.write ; Write
; Read
;push af
;ld a,#f6
;call Color
;pop af
.COMMENT *
;Count read sectors ----------------------------
push hl
push af
ld a,b
ld hl,(#f9f0)
add a, l ; 4
ld l, a ; 4
adc a, h ; 4
sub l ; 4
ld h, a ; 4
ld (#f9f0),hl
pop af
pop hl
;----------------------------
;*
call ReadSD
;push af
;ld a,#f0
;call Color
;pop af
;ld hl,(#f9f0)
;inc hl
;ld (#f9f0),hl ; Count reads
call SD_OFF
ei
jr nc,.ok
ld b,0
;ld a,DISK ; General unknown disk error
ret
.ok:
;A successful device access must reset the "device changed" flag
res BIT_SD_CHG,(ix+STATUS)
xor a ; Ok
ret
.write:
; Write
call WriteSD
call SD_OFF
ei
jr nc,.ok ; Ok
.COMMENT *
; DEBUG: Print error number in A
ld c,"0"
add a,c
ld ix,#a2
ld iy,(#fcc1-1)
call #1c
;*
.writeError:
ld b,0
ld a,WRERR ; Write error
ret ; Error
.error:
pop af
ld b,0
ld a,IDEVL ; Invalid device or LUN
ret
;----------
; ROM disk
;----------
.romdisk:
dec c ; LUN
jp nz,.error
pop af
jr c,.writeError ; Can't write in ROM
jp RomDiskRead
;-----------------------------------------------------------------------------
;
; 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 Alpha 2b.
;
; 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:
dec a
jp z,RomDiskInfo ; ROM disk
dec a
cp NUM_SLOTS
jp nc,.DEV_INFO_ERROR
call GETWRK
push ix
pop de
di
call SD_ON
ld (#5800),a ; SD slot select
push bc
push hl
call GetCID
pop de ; DE = Buffer in RAM, HL = SD registers
pop bc
jp c,.DEV_INFO_ERROR
djnz .DEV_INFO2
; 1: Manufacturer name string
ld a,(hl) ; ID
push af
ld b,15 + 2
call SkipBytes
call GetManufacName
ld b,0
ldir ; Copy manufacturer name to buffer
pop bc
; Add [id] to the manufacturer name
ld a,"["
ld (de),a
inc de
ld a,b
call Num2Hex.Num1
ld a,b
call Num2Hex.Num2
ld a,"]"
ld (de),a
inc de
jr .DEV_END
.DEV_INFO2:
djnz .DEV_INFO3
; 2: Device name string
ld a,(hl) ; MID
ld a,(hl) ; OID byte 1
ld a,(hl) ; OID byte 2
ld bc,5
ldir
ld b,8 + 2
call SkipBytes
jr .DEV_END
.DEV_INFO3:
djnz .DEV_INFO0
; 3: Serial number string
;ex de,hl
ld b,9
call SkipBytes
call .num
call .num
ld b,3 + 2
call SkipBytes
jr .DEV_END
.num:
ld a,(hl)
ld l,(hl)
ld h,a
call Num2Hex
ld h,#40
ret
.DEV_INFO0:
; 0: Basic information
ld b,16 + 2
call SkipBytes
ex de,hl
ld (hl),1 ; Number of logical units
inc hl
ld (hl),0 ; Flags: always zero in Alpha 2b.
jr .DEV_END2
;xor a
;ret
.DEV_END:
xor a
ld (de),a
.DEV_END2:
call SD_OFF
ei
xor a
ret
.DEV_INFO_ERROR:
call SD_OFF
ei
ld a,1
ret
;------------------------------------------------------------------------------
; Input: HL = number to convert, DE = location of ASCII string
; Output: ASCII string at (DE)
;------------------------------------------------------------------------------
Num2Hex:
ld a,h
call .Num1
ld a,h
call .Num2
ld a,l
call .Num1
ld a,l
jr .Num2
.Num1:
rra
rra
rra
rra
.Num2:
or #F0
daa
add a,#A0
adc a,#40
ld (de),a
inc de
ret
;-----------------------------------------------------------------------------
; Get manufacturer name
; In: A = ID
; Out: HL = String
; BC = String length
;-----------------------------------------------------------------------------
GetManufacName:
ld c,a
ld hl,Manufacturers
.loop:
ld a,(hl)
inc hl
cp c
jr z,.found
or a
jr z,.found ; No more names in the list
push bc
call .found
add hl,bc
inc hl
pop bc
jr .loop
.found:
ld c,0
push hl
ld a,"$"
.cont:
inc c
inc hl
cp (hl)
jr nz,.cont
.end:
pop hl
ld b,0
ret
Manufacturers:
db #01,"Panasonic$"
db #02,"Toshiba$"
db #03,"SanDisk$"
db #04,"(SMI-S?)"
db #06,"Renesas$"
db #11,"Dane-Elec$"
db #15,"Samsumg$"
db #18,"Infineon$"
db #13,"(KingMax?)$"
db #1a,"(PQI?)$"
db #1b,"(Sony?)$"
db #1c,"(Transcend?)$"
db #1d,"(A-DATA?)$"
db #27,"Verbatim$"
db #37,"(KINGMAX?)$"
db #41,"OKI$"
db #73,"SilverHT$"
db #aa,"openMSX$"
db #00,"Unknown$"
;-----------------------------------------------------------------------------
;
; 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.
;-----------------------------------------------------------------------------
DEV_STATUS:
dec a
jp z,RomDiskStatus ; ROM disk
dec a
cp NUM_SLOTS
jp nc,DEV_STAT1
ld c,a
ld a,b
cp 2
jp nc,DEV_STAT1