-
Notifications
You must be signed in to change notification settings - Fork 1
/
BIOS2.MAC
1237 lines (1197 loc) · 31.4 KB
/
BIOS2.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
;
IF DEBUG
DEBUGADDR EQU 04001h
ENDIF
DEBUGINIT MACRO x
IF DEBUG
ld hl,DEBUGADDR
ld (hl),x
ENDIF
ENDM
DEBUGTRACE MACRO y
IF DEBUG
ld hl,DEBUGADDR
inc (hl)
ENDIF
ENDM
;
;The IOBYTE lives at address 3 (in the Zero Page) and should be changed using
;BDOS calls 7 and 8 (get/set IOBYTE). The value is bitmapped:
;
; Bits Bits 6,7 Bits 4,5 Bits 2,3 Bits 0,1
; Device LIST PUNCH READER CONSOLE
;
; Value
; 00 TTY: TTY: TTY: TTY:
; 01 CRT: PTP: PTR: CRT:
; 10 LPT: UP1: UR1: BAT:
; 11 UL1: UP2: UR2: UC1:
;
;* BAT = batch mode. Use the current Reader for console input, and the current
; List (printer) device as the console output.
;
; * CRT = Standard console (keyboard and terminal screen).
; * LPT = Standard line printer.
; * PTP = Standard Paper Tape Punch.
; * PTR = Standard Paper Tape Reader.
; * TTY = Teletype device, eg a serial port.
; * UC1 = User defined (ie implementation dependent) console device.
; * UL1 = User defined (ie implementation dependent) printer device.
; * UPn = User defined (ie implementation dependent) output device.
; * URn = User defined (ie implementation dependent) input device.
;
;========================= TTY values =======================
;
TTYBEG EQU 0F120h ; IDEBDOS(F100..F11F), MTTY(F120..F13D), MOVEBUF(F162..F1E1)
MTTY EQU TTYBEG
TTYBUF EQU mttyend-mttybeg+TTYBEG ; LOW TTYBUF <= 255-TTYSIZE !!! because
; H=const, L=incrementing -> mod 256 align
TTYSIZE EQU MOVEBUF-TTYBUF ; TTY buffer size <= 126
TTYPTR EQU 0F3F4h ; offset of next free byte in tty buffer = TTYBUF[TTYPTR]
; (=0FFh if no_interrupts=poll mode)
TTYCUR EQU 0F3F3h ; current returned pointer from TTYBUF
;
;
UART_DATA equ 0F764h
UART_CTL equ 0F765h
;
; Îòïðàâêà áàéòà - çàïèñü â ïîðò F764.
; Ïðèåì áàéòà - ÷òåíèå ïîðòà F764.
; Êîíòðîëü ñîñòîÿíèÿ ïåðåäà÷è - ïîðò F765 íà ÷òåíèå:
; D7 - TX_Ready (0 = èäåò îòïðàâêà áàéòà, ïîðò íå ãîòîâ. 1 = ìîæíî çàïèñûâàòü ñëåäóþùèé áàéò äëÿ îòïðàâêè)
; D6 - RX_Status (0 = íåò íîâîãî ïðèíÿòîãî áàéòà. 1 = ïðèíÿò íîâûé áàéò. Ïîñëå ñ÷èòûâàíèÿ áàéòà èç F764 ýòîò áèò ñáðàñûâàåòñÿ â 0).
; Óïðàâëåíèå ðåæèìàìè - ïîðò F765 íà çàïèñü:
; D0, D1 - Ñêîðîñòè UART (0=4800, 1=9600, 2=19200, 3=38400)
; D6 - "1" = ðàçðåøàåò ïðåðûâàíèå ïî ïðèåìó áàéòà. Íà ØÄ ñòàâèòñÿ 0FDh.
;
; Ïåðåäà÷à áàéòà ñ ïðåðûâàíèÿìè íå ñâÿçàíà, è êîíòðîëèðóåòñÿ ñ÷èòûâàíèåì ñ ïîðòà F765 ñèãíàëà TX_Ready
;
; ===========================================================
;
; BDOS wrapper at page 2
;
BDOS: JP DOOR
;
; ×ÅËÔÏÒÁ ÏÛÉÂÏË BDOS
XERR1: DW ERR1 ; bad sector
XERR2: DW ERR2 ; select
XERR3: DW ERR3 ; disk read/only
XERR4: DW ERR4 ; file read/only
BERR1: DB 2
DW MERR1
BERR2: DB 2
DW MERR2
BERR3: DB 2
DW MERR3
BERR4: DB 2
DW MERR4
DOOR: CALL ASKSEG2
LD B,A
LD A,(YBDOS)
LD HL,(YBDOS+1)
CALL BCALL
bit 7, c ; do not process BDOS functions over 128
ret nz
;
; 20100412. Quicker process BDOS direct console functions - do not interbank calls to WORKPAGE
;
ld a,c
cp 11 ; console status
jr z, TDA06 ; CONSTATUS
LD HL, BDOS1
cp 6 ; direct input\output, no echo
jp nz, BCALL_1
;
BDOSF6: LD A,E
INC A
Jr Z, BF6NEXT
INC A
Jr Z, TDA06 ; CONSTATUS
ld c, e
Jr TDA0C ; CONOUT
;
BF6NEXT:CALL TDA06 ; CONSTATUS
OR A
CALL NZ, TDA09 ; CONIN
RET
;
MERR1: LD HL,(XERR1)
JP (HL)
ERR1: LD HL,R_BADS
JR COMMERR
;
MERR2: LD HL,(XERR2)
JP (HL)
ERR2: ld a, DEFAULT_DISK
LD (ACTDSK),A
LD HL,R_SELD
JR COMMERR
;
MERR3: LD HL,(XERR3)
JP (HL)
ERR3: LD HL,R_DSKRO
JR COMMERR
;
MERR4: LD HL,(XERR4)
JP (HL)
ERR4: LD HL,R_FLRO
COMMERR:LD A,WORKPAGE
JP BJMP
;
; BIOS wrapper at page 2
;
BIOS:
TDA00: JP WARMSTART ; ÈÏÌ. ÓÔÁÒÔ
TDA03: JP WARMSTART ; ÔÅÐÌ. ÓÔÁÒÔ
TDA06: JP CONSTATUS ; ÓÔÁÔÕÓ ËÏÎÓÏÌÉ
TDA09: JP CONIN ; ÞÔÅÎÉÅ Ó ËÌÁ×ÉÁÔÕÒÙ
TDA0C: JP CONOUT ; ×Ù×ÏÄ ÎÁ ËÏÎÓÏÌØ
TDA0F: JP LSTOUT ; ×Ù×ÏÄ ÎÁ ÐÒÉÎÔÅÒ
TDA12: JP AUXOUT ; ×Ù×ÏÄ ÎÁ ÕÓÔÒÏÊÓÔ×Ï ×Ù×ÏÄÁ
TDA15: JP AUXIN ; ××ÏÄ Ó ÕÓÔÒÏÊÓÔ×Á ××ÏÄÁ
TDA18: JP SLTR00 ; ÕÓÔÁÎÏ×ËÁ ÄÏÒÏÖËÉ 00
TDA1B: JP SLDSK ; ×ÙÂÒÁÔØ ÄÉÓË
TDA1E: JP SLTRK ; ÕÓÔÁÎÏ×ÉÔØ ÄÏÒÏÖËÕ
TDA21: JP SLSEC ; ÕÓÔÁÎÏ×ÉÔØ ÓÅËÔÏÒ
TDA24: JP SLDMA ; ÕÓÔÁÎÏ×ÉÔØ DMA
TDA27: JP READS ; ÞÔÅÎÉÅ ÓÅËÔÏÒÁ
TDA2A: JP WRITES ; ÚÁÐÉÓØ ÓÅËÔÏÒÁ
TDA2D: JP LSTSTAT ; ÓÔÁÔÕÓ ÐÒÉÎÔÅÒÁ
TDA30: JP TRANSSEC ; ÐÅÒÅËÏÄÉÒÏËÁ ÓÅËÔÏÒÏ×
;
; õÓÔÁÎÏ×ËÁ JUMPÏ× × ÏÂÌÁÓÔÉ Ó×ÑÚÉ CP/M (0-100h)
SETJUMPS:
LD A,0C3H
LD (0),A
LD HL,BIOS+3
LD (1),HL
LD (5),A
LD HL,BDOS
LD (6),HL
RET
WARMSTART:
LD SP,0F3C0H
CALL SETJUMPS ; õÓÔÁÎÏ×ËÁ JUMPÏ× × ÏÂÌÁÓÔÉ
; Ó×ÑÚÉ CP/M (0-100h)
LD BC,80h
CALL SLDMA
; õÓÔ. ÐÏÒÔÏ× FB, FA, F8 ÐÏ ÑÞÅÊËÁÍ ËÏÎÆÉÇÕÒÁÃÉÉ
; F3FB, F3FA, F3F8.
LD A,(sysPFB)
OUT (PFB),A
WARM_S: LD HL,CCPFLUSH ; FLUSH ; ÓÂÒÏÓ ÆÌÁÖËÏ× É ÏÞÉÓÔËÁ
CALL BCALL_1 ; ÂÕÆÅÒÁ ÉÍÅÎ ÀÚÅÒÏ×., C=WARMDISK
CALL SLDSK
LD A,H
OR L
JR Z,WARM_S
; ÎÅÓÕÝÅÓÔÕÀÝÉÊ ÄÉÓË -> ÃÉËÌ ÎÁ Warm_S
JP BEGCCP
;
CONSTATUS:
ld a, (IO_BYTE)
and 3 ; TTY=D1D0=00, CRT=D1D0=01
LD HL, YCONST
jr nz, RETPROC
;
TTYSTATUS: ;
;
; Out: A=0FFH, if next char ready for read
; A=0 if buffer empty / no input char
;
; ×òåíèå ñ êîíñîëè.
; Ïðèçíàê íàëè÷èÿ äàííûõ (CONSTATUS):
; - ðåæèì INT (TTYPTR<>0FFh): TTYPTR<>TTYCUR
; - ðåæèì POLL (TTYPTR=0FFh): PF765.D6=1
;
ld a, (TTYPTR)
ld hl, TTYCUR
inc a
jr z, pollstatus
; INT
dec a
bit 7, a
jr nz, TTYST1
and 7Fh
cp (hl)
jr TTYST1
; POLL
pollstatus:
ld a, (UART_CTL)
and 40h
TTYST1: ld a, 0FFh
ret nz ; D6=1 -> UART ready for read byte
xor a
ret ; D6=0 -> UART not ready
;
LSTSTAT:LD HL,YLSTST
JR RETPROC
;
AUXIN: LD HL,YAUXIN
JR RETPROC
AUXOUT: LD HL,YAUXOUT
JR YPROC
;
LSTOUT: LD HL,YLSTOUT
;
; ÐÁÒÁÍÅÔÒÙ Æ-ÃÉÑÍ ÐÅÒÅÄÁÀÔÓÑ/ÐÏÌÕÞÁÀÔÓÑ × BC, ÕËÁÚÁÔÅÌØ ÎÁ
; ÛÌÀÚ(GATE) - HL, ×ÙÚÙ×ÁÀÝÉÊ ÓÅÇÍÅÎÔ - E
YPROC: LD A,(HL)
INC HL
LD E,(HL)
INC HL
LD H,(HL)
LD L,E
JP BCALL ; ×ÙÚ×ÁÔØ ÃÅÐÏÞËÕ ÛÌÀÚÏ×
;
CONIN: ld a, (IO_BYTE)
and 3 ; TTY=D1D0=00, CRT=D1D0=01
jr z, TTYIN
LD HL, YCONIN
RETPROC:CALL YPROC
LD A,C
RET
;
TTYIN:
;
; Out: A=readed_char. Does infinitive wait for input char if input queue is empty
;
; ×èòàåì áàéò (îæèäàåì äàííûõ â íàëè÷èè):
; - ðåæèì INT: âîçâðàùàåì TTYBUF[TTYCUR], TTYCUR:=(TTYCUR+1) mod TTYSIZE
; åñëè TTYPTR and 80h <> 0 (buf full), òî
; TTYPTR=TTYPTR and 7Fh, äàííûå èç PF764 ïèøåì â TTYBUF[TTYPTR]
; - ðåæèì POLL: âîçâðàùàåì äàííûå ñ ïîðòà PF764
;
call TTYSTATUS ; hl=TTYCUR
jr z, TTYIN ; wait for incoming char
ld a, (TTYPTR)
inc a
jr nz, intread ; if non-interrupt mode
pollread:
ld a, (UART_DATA)
ret
intread:
ld a, (hl) ; A=TTYCUR
push hl
ld hl, TTYBUF
add a, l
ld l, a
ld a, (hl) ; A=TTYBUF[TTYCUR]
pop hl ; hl=TTYCUR
push af
inc (hl)
ld a, TTYSIZE
sub (hl)
jr nz, TTYIN1
ld (hl), a ; TTYCUR:=(TTYCUR+1) mod TTYSIZE
TTYIN1: ld hl, TTYPTR
bit 7, (hl)
jr z, TTYIN2 ; if buffer not full
ld a, (hl)
and 7Fh
ld (hl), a ; buffer not full now because TTYBUF[TTYCUR] readed
ld hl, TTYBUF
add a, l
ld l, a
ld a, (UART_DATA)
ld (hl), a ; TTYBUF[TTYPTR]:=A
TTYIN2: pop af ; A=TTYBUF[TTYCUR]
ret
;
;
CONOUT: ld a, (IO_BYTE)
and 3 ; TTY=D1D0=00, CRT=D1D0=01
LD HL, YCONOUT
jr nz, YPROC
TTYOUT:
;
; Inp: C=char for output. Check (and wait) for queue ready before output the char
;
pollwrite:
ld a, (UART_CTL)
rlc a ; D7=1 -> ready for send data
jr nc, pollwrite ; wait for output queue is empty
ld a, c
ld (UART_DATA), a
ret
;
DRVTAB:
IF BOOTFDD
defb 0 ; Map fdd0 to drive "A"
ELSE
defb 0FFh
ENDIF
defb 0FFh
IF BOOTFDD
defb 0FFh
ELSE
defb 3 ; Map IDE/SD slot 0 to drive "C" (0,1=floppy; 2=vdisk 3,4,5=IDE/SD)
ENDIF
defs 13, 0FFh
;
SLDSK: LD HL,YSELDISK
CALL YPROC
PUSH HL
LD HL,DRVTAB
ld b,0
add hl,bc ; ðåòåëïäéòï÷ëá
ld c, (hl)
POP HL
ld a, c
LD (WDISK),A
CP 0FEH
RET Z
LD HL,SELDISK
JR BCALL_1 ; ÷ùâïò äéóëá
;
SLTR00: LD HL,YHOME
CALL YPROC
LD BC,0
JR SLTRK0
;
SLTRK: LD HL,YSELTRK
CALL YPROC
SLTRK0: LD HL,SELTRK
JR SLSEC0
;
SLSEC: LD HL,YSELSEC
CALL YPROC
LD HL,SELSEC
SLSEC0: ld a,(WDISK)
cp 0FEh
ret z
BCALL_1:LD A, WORKPAGE
JP BCALL
;
SLDMA: LD HL,YSETDMA
CALL YPROC
LD HL,SETDMA
JR BCALL_1
;
READS: CALL ASKSEG2
LD HL,READSEC
push hl
LD HL,YREAD
RDWRCOM:push hl
LD A,(CALBANK)
LD D,A
LD HL,GETBANK ; óÏÏÂÒÁÚÉÔØ, × ËÁËÏÊ ÂÁÎË
CALL BCALL_1 ; ×ÙÄÁÔØ ÄÁÎÎÙÅ
pop hl ; hl=YREAD/YWRITE
CALL YPROC
pop hl ; hl=READSEC/WRITESEC
LD E,A
LD A,(WDISK)
CP 0FEH
LD A,E
RET Z ; ÷îåûîéê äòáê÷åò äéóëá
JR BCALL_1
;
WRITES: CALL ASKSEG2
LD HL,WRITESEC
push hl
LD HL,YWRITE
JR RDWRCOM
TRANSSEC:
LD L,C
LD H,0
INC HL
RET
;
ASKSEG2:ld hl,2
ASKSEGM:add hl,sp ; ðòïðõóë áäòåóá ÷ïú÷òáôá
; éú ð/ð ASKSEGM
PUSH DE ; ïðòåäåìñåí éú ëáëïçï
PUSH BC ; óåçíåîôá ÷ùú÷áîá BDOS
ld e,(hl)
inc hl
ld d,(hl) ; DE = áäòåó ÷ïú÷òáôá
push hl
ld hl,BRET
or a ; ÐÒÏ×ÅÒËÁ: ËÁËÉÍ CALL'ÏÍ
sbc hl,de ; ÂÙÌÁ ×ÙÚ×ÁÎÁ BDOS-ÐÒÏÓÔÙÍ
pop hl ; (BANK=2) ÉÌÉ ÍÅÖÂÁÎËÏ×ÙÍ
ld a,TPAPAGE ; BANK TPA
jp nz,CALLER ; if return <> 0F207h
inc hl
ld a,(hl) ; A=PF9
inc hl
inc hl
ld d,(hl)
inc hl
ld h,(hl)
ld l,d ; hl=stack pointer
inc hl
CALLER: PUSH AF
LD (CALBANK),A
CALL BLDB ; B=óô.â. áäòåóá ÷ùúï÷á
POP AF
LD C,B
LD B,4
CALLER1:RL C
RLA
DJNZ CALLER1
POP BC
POP DE
RET ; A=÷ùúù÷áàýéê óåçíåîô
;
CALBANK:DEFB 2
WDISK: DEFB 0
;
ENDDOSCODE:
;
DPH_A: defw 0 ; XLT ; FLOPPY 0
defs 6h,0 ; WORK
defw DIRBUF ; DIRBUF
defw DPB_A ; DPB
defw CSV_A ; CSV
defw ALV_A ; ALV
defb 54h
defb 54h
defb 0
defb 7
defb 1
defb 3
defb 0
defb 10h
DDAD0: defb 0
DPB_A: defw 38h ; SPT ; FLOPPY 0
defb 4 ; BSH
defb 0fh ; BLM
defb 0 ; EXM
defw 228h ; DSM
defw 7fh ; DRM
defw 0c0h ; AL0,AL1
defw 20h ; CKS ; catalog 128 records
defw 02h ; OFF
DPH_B: defw 0 ; XLT ; FLOPPY 1
defs 6h,0 ; WORK
defw DIRBUF ; DIRBUF
defw DPB_B ; DPB
defw CSV_B ; CSV
defw ALV_B ; ALV
defb 54h
defb 54h
defb 0
defb 7
defb 1
defb 3
defb 0
defb 11h
DDAFC: defb 0
DPB_B: defw 38h ; SPT ; FLOPPY 1
defb 4 ; BSH
defb 0fh ; BLM
defb 0 ; EXM
defw 228h ; DSM
defw 7fh ; DRM
defw 0c0h ; AL0,AL1
defw 20h ; CKS
defw 02h ; OFF
;
; do not recompose PARIDE, DPH, DPB arrays for IDE/SD slots !
;
PARIDE0:defw LBABUF0
defw border0
defw IDEBUF0
defw DPB_C
DPH_C: defw 0 ; XLT ; IDE/SD_0
defs 6h,0 ; WORK
defw DIRBUF ; DIRBUF
defw DPB_C ; DPB
defw CSV_H0 ; CSV
defw ALV_C ; ALV
DPB_C: defw 38h ; SPT ; IDE/SD_0
defb 4 ; BSH
defb 0fh ; BLM
defb 0 ; EXM
defw 228h ; DSM
defw 7fh ; DRM
defw 0c0h ; AL0,AL1
defw 40h ; CKS ; catalog 256 records
defw 2 ; OFF
PARIDE1:defw LBABUF1
defw border1
defw IDEBUF1
defw DPB_D
DPH_D: defw 0 ; XLT ; IDE/SD_1
defs 6h,0 ; WORK
defw DIRBUF ; DIRBUF
defw DPB_D ; DPB
defw CSV_H1 ; CSV
defw ALV_D ; ALV
DPB_D: defw 127 ; SPT ; IDE/SD_1
defb 4 ; BSH
defb 0fh ; BLM
defb 0 ; EXM
defw 253 ; DSM
defw 7fh ; DRM
defw 0c0h ; AL0,AL1
defw 40h ; CKS
defw 2 ; OFF
PARIDE2:defw LBABUF2
defw border2
defw IDEBUF2
defw DPB_X
DPH_X: defw 0 ; XLT ; IDE/SD_2
defs 6h,0 ; WORK
defw DIRBUF ; DIRBUF
defw DPB_X ; DPB
defw CSV_H2 ; CSV
defw ALV_X ; ALV
DPB_X: defw 127 ; SPT ; IDE/SD_1
defb 4 ; BSH
defb 0fh ; BLM
defb 0 ; EXM
defw 253 ; DSM
defw 7fh ; DRM
defw 0c0h ; AL0,AL1
defw 40h ; CKS
defw 2 ; OFF
DPH_E: defw 0 ; XLT ; VDISK (RAMDISK)
defs 6h,0 ; WORK
defw DIRBUF ; DIRBUF
defw DPB_E ; DPB
defw 0 ; CSV
defw ALV_E ; ALV
DPB_E: defw 20H ; SPT ; VDISK (RAMDISK)
defb 3 ; BSH
defb 7 ; BLM
defb 0 ; EXM
defw 255 ; DSM
defw 3fh ; DRM
defw 0C0h ; AL0,AL1
defw 0 ; CKS
defw 1 ; OFF
DPH_R: defw 0 ; XLT ; ROMDISK
defs 6h,0 ; WORK
defw DIRBUF ; DIRBUF
defw DPB_R ; DPB
defw 0 ; CSV
defw ALV_R ; ALV
DPB_R: defw 28H ; SPT ; 40 sectors (5 kb per track)
defb 4 ; BSH
defb 0Fh ; BLM ; 2048 bytes block
defb 0 ; EXM
defw 1D4h ; DSM ; TOTAL=ORDOS+SYSTEM+DIR+DATA=64k+20k+4k+936k=1024k
defw 7fh ; DRM ; catalog=128 records
defw 0C0h ; AL0,AL1 ; catalog=4kb
defw 0 ; CKS
defw 4 ; OFF ; system = 4 tracks = 20kb
ENDBIOS EQU MARKER-3 ; EFFF=(byte)marker, EFFD=(word)stack_int
ALV_C:
ALV_D equ ALV_C ; temporary, will be calculated in CALC_ALV_D
ALV_X equ ALV_C ; temporary, will be calculated in CALC_ALV_D
ALV_B EQU ENDBIOS-64h-3Bh-21h-64h
ALV_E EQU ENDBIOS-64h-3Bh-21h ; LBA-ÎÏÍÅÒ ÐÏÓÌÅÄÎÅÇÏ ÐÒÏÞÉÔÁÎÎÏÇÏ IDE ÓÅËÔÏÒÁ
ALV_R EQU ENDBIOS-64h-3Bh
ALV_A equ ENDBIOS-64h
;
; (ALV_E-ALV_C) recommended value = 800 bytes (100Mb limit for total IDE/SD capacity)
;
; ÒÁÂÏÔÁÅÔ ÐÏÓÌÅ ÚÁÇÒÕÚÞÉËÁ ÉÚ BOOT-SECTOR × 1 ÓÔÒÁÎÉÃÅ
COLDSTART:
CALL COLDINIT
COLDST1:LD HL, COLDINIT
LD (HL),0 ; ,0
LD d, h
ld e, l
inc de
LD BC,ENDBIOS-COLDINIT-1
LDIR ; CLEAR ALV
LD HL,COLD
PUSH HL
LD A,TPAPAGE
LD (RETT+1),A
EXX
EX AF,AF'
POP HL ; HL=COLD
LD BC,COLDSTART-COLD
CALL BLDIRF1 ; LD A,WORKPAGE ðåòEëéîõìé üíõìñôïò BDOS
LD A,TPAPAGE
LD HL, coldbeg
JP BJMP
;
COLDINIT: ; input: DE = IDE/SD port address
DEBUGINIT 0
LD A,80H
LD (sysPFB),A
OUT (PFB),A
xor a
dec a ; A=0FFh
ld (BORDER0+9), a ; c=0/10h=master/slave, 1/3=SDcard, 0FFh=not used (free) - 1 IDE/SD slot (default boot slot)
ld (BORDER1+9), a ; c=0/10h=master/slave, 1/3=SDcard, 0FFh=not used (free) - 2 IDE/SD slot
ld (BORDER2+9), a ; c=0/10h=master/slave, 1/3=SDcard, 0FFh=not used (free) - 3 IDE/SD slot
DEBUGINIT 1
ld a, (12) ; a=drive_sign (D4..D0: 0=IDE8255_Master, 10h=IDE8255_Slave, 57h=IDEPRO_Master, 1=SDC, 3=SDHC, 4=ROM, 5=FDD)
ld hl, ide_8255 ; IDE: source,compiled base address
ld bc, port_tbl ; IDE: hlat table address
and 11101111b
jr z, sport00 ; if IDE mode
cp 4
jr z, COLDROM ; if ROM-disk BOOT
ld hl, SD_ADDR ; SD: source,compiled base address
ld bc, portsd_tbl ; SD: hlat table address
cp 5
jp z, cold_ide ; if FDD boot
IF IDEPRO
cp 47h ; because "57h and 11101111b"
jr nz, sport00 ; if SD boot
ld hl,12
ld (hl),h ; if IDEPRO - it allways master, (12)=0
jr sport1
ENDIF
sport00:ex de, hl
;
; Correct IDE port addresses for PPA (IDE).
; Input: hl=(destination base port address)
; de=(source=compiled base port address)
; bc=hlat table address
;
xor a ; CY=0
sbc hl, de ; hl=(destination port address)-(source/compiled base port address)=offset
ex de, hl ; de=offset
sport0: ld a, (bc)
ld l, a ; hl=address of address to correct
inc bc
ld a, (bc)
ld h ,a
or l
jr z, sport1 ; end of port_tbl table
ld a, (hl) ; low part of value to correct
add a, e
ld (hl), a
inc hl
ld a, (hl) ; high part of value to correct
adc a, d
ld (hl), a
inc bc
jr sport0
;
port_tbl:
IF IDEPRO
DW 0
ELSE
dw @@P0+1, @@P1+1, @@P2+1, @@P3+1, @@P4+1, @@P5+1, @@P6+1
dw @@P14+1,@@P15+1
dw @@P7+1, @@P8+1, @@P9+1, @@P10+1, @@P11+1, @@P12+1, @@P13+1, 0
ENDIF
;
portsd_tbl:
dw @@SD1+1, @@SD2+1, @@SD3+1, @@SD4+1, @@SD5+1, @@SD6+1, @@SD7+1
dw @@SD8+1, @@SD9+1, @@SD10+1, 0
;
COLDROM:IN a,(0BH) ; 08H..0AH ports control register PPA 8255 (Orion-PRO)
inc a
; ld (ORIONPRO),a
jr z,OR128 ; SKIP IF HOST IS ORION-128
ld hl,ySELROM
ld (SELROM+1),hl
ld hl,yGETROM
ld (GETROM+1),hl
OR128: ld a,6 ; Device=ROM
ld (DRVTAB+2),a ; at 3-nd drive letter (drive C = ROM)
ld de, DPB_R
jr coldrom2
sport1:
ld de, DPB_C
coldrom2:
DEBUGINIT 2
push af
ld hl, 10h
ld bc, 15
ldir ; get ide HDD partition DPB where we are booting
ld l, 12 ; h=0
ld de, BORDER0+9
ld bc, 966h
mvcrc: ld a, (hl)
ld (de), a ; get partition offset (first LBA-addressed sector)
add a, c
ld c, a
dec hl
dec de
djnz mvcrc
ld (de), a ; put crc to BORDER0[0]
pop af
;
; ------------------- IDE drive init ---------------------------------
;
; Hard reset on the drive, by pulsing its reset pin.
; this should usually be followed with a call to "ide_init".
;
cold_ide:
DEBUGINIT 3
IF IDEPRO
cp 47h
jr z,LOOPEXT ; allready inited, so skip PRO_INIT
PRO_INIT:
LD A,06H ; sbros (D2), prerywaniq zapre}eny (D1)
OUT (PRO_SYS),A ;
LD BC,0 ; ograni~enie ovidaniq DELAY=0.5s at 5MHz
ILOOP: DEC bC
ld a,b
or c
jr nz,ILOOP ;wremq wy{lo
;
LD A,02H ;konec sbrosa,prerywaniq zapre}eny
OUT (PRO_SYS),A
DLOOP: DEC C
jr Z,LOOPEXT ;wremq wy{lo
WTHD: EX (SP),HL
EX (SP),HL
DJNZ WTHD
IN a,(PRO_STAT) ; D7=Busy, D0=Error
RLA
JR C,DLOOP ; HDD ne gotow
ld a, 0E0h ; 11100000b - LBA mode, Master, head 0
out (PRO_HEAD),a ; ide_head
LOOPEXT:
ELSE
ld a, rd_ide_8255
@@P14: ld (ide_8255_cfg), a ; config 8255 chip, read mode
@@P15: ld hl, ide_8255_ctl
ld (hl), ide_rst_line ; hard reset the disk drive
call delay10 ; de=0
ld (hl), d ; no ide control lines asserted
;
; initialize the ide drive.
;
ld a, (12) ; a=drive_sign (D4..D0: 0=MasverIde, 10h=SlaveIDE, 1=SDC, 3=SDHC, 4=ROM)
and 10h
or 10100000b
ld e, a
ld a, ide_head
call ide_wr_8 ; select the master device
; call ide_wait_ready
ENDIF
;
;-------------------- SD-card cold init ------------------------------
;
cold_sd:
IF INITSD
DEBUGINIT 4
call sd_init
jr z, coldsd2 ; if card present & MSX scheme
ld hl, sd_tab1 ;
ld de, sd_tab0
push de
ld bc, sd_tab2-sd_tab1
ldir ; else switch to N8VEM scheme
call sd_init
pop de
jr nz, coldsd1 ; if sd_init fail
ld hl, sd_tab3
ld de, RDLOOP
ld bc, sd_tab4-sd_tab3
ldir
jr coldsd2
coldsd1:ld hl, sd_tab2 ;
; ld de, sd_tab0
ld bc, sd_tab3-sd_tab2
ldir ; both tests fail -> back to MSX scheme (default scheme)
coldsd2:
ENDIF
DEBUGINIT 5
;
;---------------
;
LD HL,ACPMVEC
ld de,NTAB
push de
ld bc, AVECEND-AVECBEG+EE-EB+2
LDIR
;
LD HL,0F3CFH
LD (HL),0C0H ; screen start at C000
INC HL
LD (HL),30H ; ÛÉÒÉÎÁ ÜËÒÁÎÁ
INC HL
LD (HL),B ; B=0. ÆÏÎÔ ÎÁ F000
INC HL
LD (HL),0F0H
inc hl
ld (hl),B ; B=0. ÏÔËÌ. ÉÎ×ÅÒÓÉÀ
CALL 0F82DH ; ÒÁÓÐÁËÏ×ÁÔØ ÆÏÎÔ
DEBUGINIT 6
pop hl ; HL=NTAB
LD DE,BPROC
LD BC,AVECEND-AVECBEG
LDIR ; íåöâáîëï÷ùê óåò÷éó
push de
ld de,PRCC
ld c,EE-EB
ldir ; óïïâýåîéñ ïâ ïûéâëáè
pop de
;
ld hl, mttybeg
ld c, mttyend-mttybeg
LDIR
;
DEBUGINIT 7
CALL FLUSH ; SET RG.A=0
LD (TIMBUF),A
LD (BATVAR),A
LD (REPLBUF),A
LD (ETRACK0),A
LD HL,0F3F5H
LD (HL),a ; MONOCHROME
INC HL
LD (HL),00010111b
; X,X,X, LPT F600, NO CCP, ECHO ON, PROMPT ON, WIDTH 8
INC HL
LD (HL),a ; "÷ÙÇÒÕÚËÁ" ÄÒÁÊ×ÅÒÁ ËÏÎÓÏÌÉ
INC HL
LD (HL),a ; F3F8 = 0
INC HL
ld (hl),TPAPAGE ; F3F9 = 2
INC HL
LD (HL),a ; F3FA = 0
DEBUGINIT 8
JP MMTEST ; MEMORY TEST
;
sd_tab1:
jp sd_wiggle_n8vem
jp sd_fini_n8vem
jp sd_put_n8vem
jp sd_get_n8vem
sd_tab2:
jp sd_wiggle_msx
jp sd_fini_msx
jp sd_put_msx
jp sd_get_msx
sd_tab3:
;
;RDLOOP:
ex de, hl ; hl:=buffer address
call sd_get ; data
ld (hl), a
inc hl
call sd_get ; data
ex de, hl ; de:=buffer address
jp RDJNZ
sd_tab4:
;
; Áóôåð ïóñò, åñëè TTYCUR=TTYPTR
; Áóôåð çàïîëíåí íà 100%, åñëè TTYCUR=(TTYPTR+1) mod TTYSIZE
;
; Âõîä â ISR.
; - Åñëè áóôåð çàïîëíåí íà 100%, âûõîäèì áåç ïðî÷èòûâàíèÿ ñèìâîëà
; ñ PF764 (îñòàâëÿåì àêòèâíûì ñèãíàë "íåãîòîâ" UART) è ñòàâèì
; TTYPTR=TTYPTR or 80h (D7=1)
; (óñòàíàâëèâàåì äëÿ CONIN ïðèçíàê ïîñëåäóþùåé âû÷èòêè ñèìâîëà -
; ýòî íåîáõîäèìî, ò.ê. ïðåðûâàíèå âûäàåòñÿ òîëüêî îäíàæäû)
; - Èíà÷å (åñëè â áóôåðå åñòü ñâîáîäíîå ìåñòî), ñ÷èòûâàåì áàéò ñ
; PF764, ñîõðàíÿåì åãî â TTYBUF[TTYPTR], TTYPTR:=(TTYPTR+1) mod TTYSIZE
;
mttybeg: ; TTY interrupt processor
di
push af
ld a, (TTYPTR)
inc a
jr z, TTYe ; if TTYPTR=0FFh (POLL mode)
push hl
cp TTYSIZE
jr c, TTY0
xor a
TTY0: ld hl, TTYCUR ; A=(TTYPTR+1) mod TTYSIZE
cp (hl)
jr z, TTYfull ; if buffer full (TTYPTR=TTYCUR-1)
push af
ld a, (TTYPTR)
ld hl, TTYBUF
add a, l
ld l, a
ld a, (UART_DATA)
ld (hl), a
pop af ; A=(TTYPTR+1) mod TTYSIZE
jr TTY1
TTYfull:or 80h ; POLL read flag (buffer full flag)
TTY1: ld (TTYPTR), a
pop hl
TTYe: pop af
ei
reti ; 46 bytes
mttyend:
;
ACPMVEC:
.DEPHASE
.PHASE BPROC
AVECBEG:
;
; ÍÎÏÇÏÓÔÒÁÎÉÞÎÙÊ ÓÅÒ×ÉÓ
;
BLDIR: jp MLDIR ; f201 ÍÅÖÂ. ldir
;
; Ð/Ð ÐÅÒÅÄÁÞÉ ÕÐÒÁ×ÌÅÎÉÑ (ÍÅÖÂÁÎËÏ×ÙÊ JMP).
; ÷ÈÏÄ : <A>&<HL>=<page>&<adress>
;
BJMP: out (PF9),a
jp (hl) ; jp MJMP ; f204 jump
BCALL: jp MCALL ; f207 call
BRET: jp MRET ; f20a ret
BLDB: jp MLDB ; f20d getbyte
BSTB: ; jp MSTB ; f210 setbyte
;
; Ð/Ð ÚÁÐÉÓÉ ÓÏÄÅÒÖÉÍÏÇÏ ÒÅÇ. ÷ × ÑÞÅÊËÕ ÐÏ ÁÄÒÅÓÕ {A+HL}
;
MSTB: call XDI
ld (LASTSP),sp
ld sp,FSP
ld de,(MARKER)
out (PF9),a
ld (HL),b
jr FRET
;
; Ð/Ð ÞÔÅÎÉÑ × ÒÅÇ. ÷ ÉÚ ÑÞÅÊËÉ ÐÏ ÁÄÒÅÓÕ {A+HL}
;
MLDB: call XDI
ld (LASTSP),sp
ld sp,FSP
ld de,(MARKER)
out (PF9),a
ld b,(HL)
jr FRET ; was JP
;
MOVEADR:OUT (0F9H),A
LDIR
ex af, af'
OUT (0F9H),A
RET
;
; Ð/Ð ÐÅÒÅÓÙÌËÉ (ÍÅÖÂÁÎËÏ×ÙÊ LDIR)
; ÷ÈÏÄ: á =ÂÁÎË-ÉÓÔÏÞÎÉË á' =ÂÁÎË-ÐÒÉÅÍÎÉË
; HL=ÁÄÒÅÓ-ÉÓÔÏÞÎÉË HL'=ÁÄÒÅÓ-ÐÒÉÅÍÎÉË
; BC=ËÏÌÉÞÅÓÔ×Ï ÐÅÒÅÓÙÌÁÅÍÙÈ ÂÁÊÔ
;