-
Notifications
You must be signed in to change notification settings - Fork 0
/
DISC_MONITOR_V43.A99
1698 lines (1651 loc) · 41.6 KB
/
DISC_MONITOR_V43.A99
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
;
;-----------------------------------------------------------------------
; MONITOR AND FDC INTERFACE ROUTINES for the TI99000 SBC
;
; Written by Alex Cameron
;
; The monitor routines are called from a DOS or other
; programme to perform Console I/O and Disc I/O similar
; to a BIOS.
;
; Version 2.1 14th May 2020 - The year of the Corona Virus
; Version 2.2 3rd February, 2024 -
; Combined partial set of TIBUG commands into Monitor
; and targeted for the SBC ROM.
; RAM ADDRESS: EC00H-EFFFH;
; ROM ADDRESS: F000H-FFFFH
; VERSION 3.0 9th June, 2024
; Support added to allows for a IDE/SATA interface using LBA sectors.
; VERSION 4.1 29th July, 2024
; Support segmented memory model and removal of Floppy Disc Code
; VERSION 4.21 7th September, 2024
; Support segmented memory model extension of a PSEL SET AND CLEAR
;
;---------------------------------------------------------------------
;
R0 EQU 0
R1 EQU 1
R2 EQU 2
R3 EQU 3
R4 EQU 4
R5 EQU 5
R6 EQU 6
R7 EQU 7
R8 EQU 8
R9 EQU 9 ;Use to index workspace pointer not stack overflow
;SL EQU R9 ;STACK LIMIT
R10 EQU 10
SP EQU R10 ;STACK POINTER
R11 EQU 11
R12 EQU 12
PORT EQU R12 ;IO BASE
R13 EQU 13
R14 EQU 14
R15 EQU 15
ST EQU 15
;
;***************************************************
;
; DEFINE SOME XOP'S.
; ALL PROGRAMMES USE THESE XOPS
;
;****************************************************
;
DXOP BDOS,0
DXOP RETF,1
DXOP SETPAGE,2 ;SET PAGE/SEGMENT REGISTER
DXOP SWBANK,3
DXOP PUSHREG,4 ;PUSH RANGE OF REGISTERS TO STACH
DXOP POPREG,5
DXOP CALL,6
DXOP RET,7
DXOP PUSH,8 ;PUSH SINGLE REGISTER
DXOP POP,9
DXOP WHEX,10 ;WRITE OUT A 16 BIT HEX VALUE
DXOP RHEX,11 ;READ IN A 16 BIT HEX VALUE
DXOP WRITE,12 ;WRITE CHAR IN MSB
DXOP READ,13 ;READ CHAR IN MSB
DXOP MESG,14 ;OUTPUT NULL TERMINATED MESSAGE
DXOP DEBUG,15 ;DEBUG CURRENT LOCATION & STORE INTO DEBUG_BUFFER
;
; SOME EQUATES. NOTE WORKSP MUST BE IN COMMON MEMORY
;
MONORG: EQU 0F000H ;ORIGIN FOR THIS MONITOR
INTVEC: EQU 0000H ;START AT THE TOP
XOPVEC: EQU 0040H
INTWP: EQU 00B0H ;;7 INT AND 16 XOPS WORKSPACES OF 16 BYTES EACH
XOPWP: EQU 0130H ;XOP WORKSPACE ALLOCATION FOR ALL XOPS
WORKSP: EQU 0230H ;USE AREA BELOW XOP WORKSPACES - 32 BYTES
STACKP: EQU 0500H ;COMMON STACK USED BY ALL PROGRAMMES
MON_PTR: EQU 0088H ;MONITOR VECTOR. PROGRAMMES CAN USE THIS
TPA: EQU 0500H ;PROGRAME LOAD AREA
;
; THIS IS WHERE THE LBA (TWO WORDS) ARE STORED SO IT CAN BE LOADED
;
LBA: EQU 0A8H ;TWO WORDS (4 BYTES)
BDOSV: EQU 086H ;VECTOR SUPPLIED BY SHELL. SHELL AND BDOS MUST BE LOADED BEFORE CALLING THIS
;
; DECLARE VARIABLES THAT NEED RAM
;
BUFFER: EQU MONORG-0300H ;THIS IS A TEMPORARY BUFFER USED BY BOOT
LOCAL_RAM: EQU MONORG-0100H
AORG LOCAL_RAM
BSS 32
;
; NOTE THIS IS USED BY DEBUG TO STORE MULTIPLE DEBUG POINTERS TO
; PROGRAMMES CALLING DEBUG
;
DEBUG_NAME: BSS 10 ;;NAME OF MODULE 8 CHARS LONG NULL TERMINATED
DEBUG_BUFFER: BSS 20 ;DEBUG TRACE LIST
;
;-- RAM BASED IO PARAMETER BLOCK - NOT USED WITH IDE
;
EVEN
DISC_PARAM: EQU $ + 0
FDCSTATUS: WORD 0 ;OPERATION STATUS
TIMEOUT: WORD 1 ;N * 16MS DURATION
DISC_INUSE: WORD 0
RAM_SIZE: EQU $ - DISC_PARAM
; AORG 0400H
; SETO R9 ;CLEAR SEGEMENT AND SELECT PAGE 0
; LI PORT,MEMBASE
; LDCR R9,BYTEWIDE ;GET PAGE VALUE FROM STEP ABOVE
; BLWP @INIT_MONITOR
;
;;-----TESTING CODE
; AORG 0500H
; BLWP @TEMP
;TEMP: WORD WORKSP
; WORD INITIAL
;----- END TESTING CODE
;
; LOCATE THE MONITOR IN MEMORY
;
AORG MONORG
;
; INITIALISATION
;
;
;************************************************************************************
;
; USE BLWP @MONITOR TO INITIALISE MONITOR VECTORS AND INTERRUPTS
;
; NOTE ALL PROGRAMMES OR MODULES MUST SET THEIR WORSPACE
; POINTERS AND STACKS BEFORE CALLING, e.g.
;
; AORG 0100H
; LWPI WORKSP
; BLWP @INIT_MONITOR
; <INITIALISED MONITOR WILL RETURN HERE>
;
;
;*************************************************************************************
;
INIT_MONITOR:
WORD WORKSP ;THIS IS MONITOR WORKSAPCE
WORD INITIAL ;INITIALISE ALL XOP, INTERRUPT AND ENTRY VECTORS
BOOT_ADDR: B @BOOT ;PERFORM A COLD BOOT - POS IN TABLE HELPS DEBUGGING
B @CIN ;CHAR IN
B @COUT ;CHAR OUT
B @SELDSK ;SELECT A DISK DRIVE
B @RECAL ;RECALIBRATE DRIVES
B @SEEK ;SEEK THE TRACK IN R3
B @RDREC ;READ SELECTED SECTOR
B @WRREC ;WRITE SELECTED SECTOR
B @RDID ;READ TRACK ID ADDRESS
B @WBOOT ;PERFORM A WARM BOOT
B @RDTRK ;READ A TRACK OF DATA
B @WRTRK ;WRITE A TRACK OF DATA
;
;**********************************************************
;
; DMA PARAMETER BLOCK DEFINITIONS
; INDEXED DEPENDING ON READ(0), OR WRITE(1) COMMAND
;
;************************************************************
;
CMDTBL: STCR *R8+,BYTEWIDE ;BYTE WIDE FDC DATA READ
LDCR *R8+,BYTEWIDE ;BYTE WIDE FDC DATA WRITE
;
;--REGISTERS IN INTERRUPT 3 WORKSPACE
;
DMACMD SET 2*R9+INTWP2 ;CURRENT COMMAND
DMAADDR SET 2*R8+INTWP2 ;REGISTER HOLDING SOURCE ADDRESS
DMAPORT SET 2*R12+INTWP2 ;IO BASE REG I.E. DATAREG
CRLF BYTE 0DH,0AH,0
EVEN
;
;--FDC 1797 IO REG LOCATIONS. SET BY ADDRESS BITS A13,A14 HENCE 2, 4 6
;
FDC1797: EQU 8000H ;IO BASE REGISTER- BYTE TRANSFER WITH MSB SET
STSREG: EQU FDC1797+0 ;MAIN STATUS REG
;CMDREG: EQU FDC1797+0 ;COMMAND REGISTER
;TRKREG: EQU FDC1797+2 ;TRACK REGISTER
;SECREG: EQU FDC1797+4 ;SECTOR REGISTER
;DATREG: EQU FDC1797+6 ;DATA REGISTER
;
; BANK SWITCHING PORT
;
MEMBASE: EQU 80C0H ;BASE MEMORY BANK SWITCH PORT
LDS: EQU 0780H ; Long Distance Source instruction operand.
LDD: EQU 07C0H ; Long Distance Destination instruction operand.
;
;
;--PORTS ETC.
;
SELMUX: EQU 0 ;SELECT CONTROL PORT (R12 CRU PORT)
;TYPMUX: EQU SELMUX + 2*5 ;START AT BIT 5
BYTEWIDE: EQU 2 ;PARALLEL I/O DONE IN BYTES (UNIQUE TO 99105)
;
;
; THESE ARE THE TIBUG BASIC COMMANDS, SUCH AS:
; QBOOT, ADDR G(O), ADDR O(UTPUT), W(ORKSPACE), R(EGISTERS), ADDRESS O(PEN).
;
; TIBUG WILL BE THE DEFAULT ENTRY POINT.
; BOOTING IS EFFECTED BY ISSUING THE Q(QBOOT) COMMAND
;
;TIBUG_ENTRY: AND WE CAN NOW ENABLE INTERRUPTS
;
BANNER LIMI 7 ;ENABLE INTERRUPTS
MESG @MESS00 ;_PRINT ">> TMS9900 TIBUG <<"
PROMPT MESG @MESS01 ;PRINT PROMPTER
BL @HEXIN ;OBTAIN ADDRESS IN R2 AND INSTRUCTION IN R1
LI R4,20 ;20 POSSIBLE INSTRUCTIONS
MON01 CB @INTAB(R4),R1 ;SEARCH INTAB
JEQ MON03
DEC R4
JOC MON01
MON02 MESG @MESS02 ;PRINT " ??"
JMP PROMPT
MON03 SLA R4,1 ;BRANCH TO APPROPRIATEE ROUTINE
MOV @SUBTAB(R4),R4 ;
MOV R3,R3 ;TEST HEXIN FLAG
B *R4
;
; TIBUG INSTRUCTION TABLE
;
HEXTAB TEXT '0123456789ABCDEF'
NUMTAB TEXT '0 1 2 3 4 5 6 7 8 9 101112131415'
INTAB BYTE 1AH ;CONTROL Z(CLEARS SCREEN) AND VERSION
TEXT '//QUVGMZOWRPXLHST/. '
EVEN
SUBTAB WORD BANNER,0,0,QBOOT,HEXLOAD,HEXLOAD2,GO,MOVE,FIND,OUTPUT,WP,PRINT_REGS,PRINT
WORD XCUTE,LOWW,SETBP,SSTEP,TRACE,CHAR,INSTANT,OPEN
;
; COMMANDS IMPLEMENTED IN DISC_MONITOR
; REGIST, OPEN, GO AND QBOOT.
;
;MASK32 WORD 001FH
MASK15 WORD 000FH
;MASK8 WORD 0007H
MASK3 WORD 0003H
;
; DUMMY LIST
;
SSTEP: JMP PROMPT; NULL COMMAND
SETBP: JMP PROMPT; NULL COMMAND
TRACE: JMP PROMPT; NULL COMMAND
CHAR: JMP PROMPT; NULL COMMAND
MOVE: JMP PROMPT; NULL COMMAND
FIND: JMP PROMPT; NULL COMMAND
XCUTE: JMP PROMPT; NULL COMMAND
LOWW: JMP PROMPT; NULL COMMAND
INSTANT: JMP PROMPT; NULL COMMAND
PRINT: JMP PROMPT; NULL COMMAND
;
;ONLY THESE ONES HAVE BEEN IMPLEMENT WITHIN THE DISC_MONITOR ROM. AS
;THE ADDRESS SPACE HAS BEEN TAKEN UP WITH THE DISC-IO AND THE OTHER FUNCTIONS
;CAN BE EASILY IMPLEMENTED WITH DISC BASED PROGRAMMES.
;
;QBOOT: JMP PROMPT; NULL COMMAND
;GO: JMP PROMPT; NULL COMMAND
;OUTPUT: JMP PROMPT; NULL COMMAND
;WP: JMP PROMPT; NULL COMMAND
;PRINT_REGS: JMP PROMPT; NULL COMMAND
;OPEN: JMP PROMPT; NULL COMMAND
;
; MESSGES AND OTHER EQUATES
;
MESS00 BYTE CR,LF
TEXT '<TMS9900 DISC MONITOR V4.3>'
; BYTE 0
MESS01 BYTE CR,LF
TEXT '>'
BYTE 0
MESS02 TEXT '??'
BYTE 0
MESS03 BYTE LF,CR,LF
TEXT ' '
BYTE 0
MESS04 TEXT ' = '
BYTE 0
;
CR: EQU 0DH ;CARRIAGE RETURN
LF: EQU 0AH ;LINE FEED
EVEN
;
;*********************************
; SUPPORT ROUTINES FOR INPUT AND OUTPUT
;**********************************
;
;
; SUBROUTINE HEXIN
; INPUTS A HEX NO. INTO R2
; AND INSTRUCTION INTO R1
; (INSTRUCTION ' ' INSERT AND MOVE TO NEXT ADDRESS
; (INSTRUCTION '-' INSERT AND MOVE TO PREVIOUS ADDRESS
; THE HEX INDEX USES THE TRANSLATE TABLE HEXTAB TO IDENTIFY THE HEX DIGIT.
; THE LAST CHARACTER, EITHER SPACE OR - BREAKS THE CYCLE AS THEY ARE NOT IN THE HEXTABLE
;
; USES R1,R2,R3,R4
;
HEXIN: CLR R1
CLR R2
SETO R3 ;SET FLAG
HEXIN0 READ R1 ;GET CHARACTER
WRITE R1 ;PRINT CHARACTER
LI R4,15
HEXIN1 CB @HEXTAB(R4),R1
JNE HEXIN2
CLR R3 ;CLEARS FLAG
SLA R2,4 ;SHIFTS HEX DIGIT INTO R2
SOC R4,R2
JMP HEXIN0
HEXIN2 DEC R4
JOC HEXIN1 ;SUBTRACTING 1 FROM 0 DOES NOT RESULT IN CARRY
MOV R3,R3 ;TEST HEXIN FLAG
RT ;RETURN FROM BL
;
; SUBROUTINE HEXOUT ;OUTPUT CONTENTS OF R2
; USES R0,R1,R2,R3
;
;HEXOUT WRITE @MESS03+7 ;PRINTS " "
;HEXOUT0 PUSHREG R3 ;SAVE R0-R3
;HEXOUTX CLR R0
; LI R3,4
;HEXOUT1 SRC R2,12
; MOV R2,R1
; ANDI R1,000FH
; MOVB @HEXTAB(R1),R0
; WRITE R0
; DEC R3
; JNE HEXOUT1
; POPREG R3 ;RESTORE R3-R0
; RT
;
DOT: BYTE '.',0
PLUS BYTE '+',0
LOADERR: TEXT 'LOAD ERROR'
BYTE 0
EVEN
;
;**********************************************
; XOP WP ENTRY POINTS
;**********************************************
;
XOPTAB: WORD XOPWP0,XOP0,XOPWP1,XOP1,XOPWP2,XOP2,XOPWP3,XOP3
WORD XOPWP4,XOP4,XOPWP5,XOP5,XOPWP6,XOP6,XOPWP7,XOP7,XOPWP8,XOP8
WORD XOPWP9,XOP9,XOPWP10,XOP10,XOPWP11,XOP11
WORD XOPWP12,XOP12,XOPWP13,XOP13,XOPWP14,XOP14,XOPWP15,XOP15
;
INTTAB: WORD WORKSP,INITIAL,INTWP1,INT1,INTWP2,FDC_RWINT, INTWP3,FDC_DRQ ;FDC1797 INTERUPT VECTORS
WORD INTWP4,INTTIMER,INTWP5,IDE_IRQ, INTWP6, IDE_DMARQ, INTWP7,INT7 ;TIMER INTERRUPT
;
INT1: ;LI R0,1
;WHEX R0
RTWP
INT7: ;LI R0,7
;WHEX R0
RTWP
;
; NOTE. APPLICATIONS MUST CALL WITH THEIR WP POINTERS SET
; THIS CALL IS USED TO SET UP MONITOR AND IS CALLED USING BL
; CALLED USING BLWP @MONITOR
;
INIT_VECTORS: RSET ;CLEAR INTERRUPT MASK
; LWPI WORKSP ;USE MONITOR LOCAL WORKSPACE
; LI SP,STACKP ;STACK FOR LOCAL MONITOR USE
;
; LI R0,MON_PTR ;SET UP THE MONITOR POINTER
; LI R1,MONORG
; MOV *R1+,*R0+ ;MOVE WORKSPACE POINTER
; MOV *R1+,*R0+ ;MOVE MONITOR INITIALISATION ADDRESS
;
;************************************************************
;
; SWTICH TO MONITOR XOP VECTORS RATHER THAN TIMON ROM
; THIS MEANS THAT ALL PROGRAMMES THAT USE XOP WILL USE THE
; THE XOP IMPLEMENTATIONS DEFINED IN MONITOR THAT IS HERE!
;
;************************************************************
LI R0,INTVEC ;SET UP INTERRUPT VECTORS
LI R1,INTTAB ;ONLY INT 0 TO 7
INIT1: MOV *R1+,*R0+
MOV *R1+,*R0+
CI R0,INTVEC+8*4 ;8 INTERRUPT VECTORS
JNE INIT1
;
;ZERO UNUSED INTERRUPT WORDS AND OTHER INITIALISATION AREAS UP TO TPA
;
LI R0,INTWP0
LI R1,TPA
INIT2: ;CLR *R0+
;C R0,R1
;JNE INIT2
;
;INITIALISE XOP-START AT XOP0, INTO MEMORY LOCATION AT 40H
;
LI R0,XOPVEC
LI R1,XOPTAB
INIT3: MOV *R1+,*R0+
MOV *R1+,*R0+
CI R0,80H ;FINISHED?
JNE INIT3 ;NO
;
;Now initialise DISC and OTHER RAM. FIRST ZERO THEN COMPY PRESETS
;
LI R0,RAM_SIZE
LI R1,DISC_PARAM
CLR R2
INIT_RAM MOVB R2,*R1+
DEC R0
JNE INIT_RAM
;
; NOW MOVE PRESETS
;
SETO R0
INC @TIMEOUT ;THIS JUST SETS TIMEOUT TO 1 AS IT IS ALREAY 0
RT
;
;************************************************************
;
; WARM BOOT ASSUMES A COLD BOOT HAS ALREADY OCCURED
; AND DISC IS JUST BEING CALIBRATED TO A KNOWN STATE
;
;************************************************************
;
WBOOT: JMP BOOT
;
;*********************************************************
;
; BOOT ASSUMES MONITOR HAS BEEN INITIALISED AND SO
; THE FDC AND INTERRUPT VECTORS ARE IN VALID
;
;***********************************************************
;
BOOT: MESG @BMSG2
CLR R2
CALL @IDE_READY
;
;BOOT SECTOR IS LBA = 0
;
CLR R3 ;BOOT LBA SECTOR
LI R4,BUFFER ;USE THIS AREA TO BOOT
CALL @READ_SECTOR
JNE BOOT2
;
; GET THE LOAD ADDRESS WHICH IS LOCATED AT THE LAST 2 BYTES OF THE LOADER BUFFER
;
MOV @BUFFER+510,R4
MOV R4,R0
LI R1,BUFFER
LI R2,512
BOOT1 MOV *R1+,*R4+
DECT R2
JNE BOOT1
LWPI WORKSP ;RESET USE MONITOR LOCAL WORKSPACE
LI SP,STACKP
B *R0 ;LET THERE BE LIFE - LOAD THE SYSTEM
;
; --BOOT ERROR
;
BOOT2 MOV R1,@FDCSTATUS
MESG @BMSG1
B @PROMPT
;
BMSG1 TEXT '--Boot error'
BYTE 0DH,0AH,0
EVEN
BMSG2 TEXT '--Booting....'
BYTE 0DH,0AH,0
PAGE TEXT "PAGE: "
BYTE 0
EVEN
;
;****************************
;
; CHAR IN (MSB OF R1)
;
;*****************************
CIN READ R1 ;GET CHAR
RET
;*******************************
;
; CHAR OUT (MSB OF R2)
;
;********************************
;
COUT CLR R1
MOVB R2,R1 ;COPY CHAR TO R1
WRITE R1 ;OUTPUT IT
RET
;
;************************************************
;
; SELECT THE DRIVE IN R2
;
;************************************************
;
SELDSK: B @IDE_READY
;
;*****************************
;
;--RECAL IS JUST SEEK TO TRK ZERO (RECAL IS HANDLED THERE)
;
;*****************************
;
RECAL: RET
;*******************************
;
;READ ID FIELDS
;
;******************************
;
RDID RET
;****************************
;
;READ A RECORD
; R3 HOLDS SECTOR
; R4 HOLDS BUFFER POINTER
;
;*****************************
;
RDREC: B @READ_SECTOR
;****************************
;
;READ A TRACK
; R3 NOT REQUIRED
; R4 HOLDS BUFFER POINTER
;
;*****************************
;
RDTRK RET
;
;
;****************************
;
;WRITE A TRACK
; R3 NOT REQUIRED
; R4 HOLDS BUFFER POINTER
;
;*****************************
;
WRTRK RET
;******************************
;
;WRITE A RECORD
; R3 HOLDS SECTOR/LBA
; R4 HOLDS BUFFER POINTER
;
;*****************************
;
WRREC B @WRITE_SECTOR
;
;=========START OF IDE INTERFACE ROUTINES====================
;
;
; IDE REGISTERS - REFERENCE SEE THE SEAGATE REFERENCE MANUAL
;
; IDE I/O ports
IDE_BASE_PORT: EQU 8040H ;PARALLEL OUTPUT ADDRESS WITH MSB SET THIS IS CS0
IDE_COMMAND: EQU IDE_BASE_PORT+7*2
IDE_STATUS: EQU IDE_BASE_PORT+7*2
IDE_CONTROL: EQU IDE_BASE_PORT+6*2
IDE_DATA: EQU IDE_BASE_PORT
IDE_HEAD: EQU IDE_BASE_PORT + 6*2
IDE_CYL_LSB: EQU IDE_BASE_PORT + 4*2
IDE_CYL_MSB: EQU IDE_BASE_PORT + 5*2
IDE_SECTOR: EQU IDE_BASE_PORT + 3*2
IDE_SEC_CNT: EQU IDE_BASE_PORT + 2*2
IDE_ERROR: EQU IDE_BASE_PORT + 1*2
;
; IDE STATUS REGISTER AND BIT DEFINTIONS
;
IDE_BSY: EQU 10000000B ;80H
IDE_DRDY: EQU 01000000B ;40H
IDE_ERR: EQU 00000001B ;01H
IDE_DWF: EQU 00100000B ;20H DRIVE WRITE FAULT
IDE_DSC: EQU 00010000B ;01H DRIVE SEEK COMPLETE
IDE_DRQ: EQU 000010000B ;01H DATA REQUEST BIT
;
; IDE COMMANDS - NOTE COMMAND IS IN THE MOST SIGNIFICANT BYTE
;
IDE_CMD_READ: EQU 02000H
IDE_CMD_WRITE: EQU 03000H ;R = 0 FOR NO RETRY
IDE_CMD_RECAL: EQU 01000H ;R = 0 FOR NO RETRY
IDE_CMD_INIT: EQU 09100H
IDE_CMD_ID: EQU 0EC00H ;GET THE DRIVE PROPERTIES
IDE_CMD_SDOWN: EQU 0E000H ;R = 0 FOR NO RETRY
IDE_CMD_SUP: EQU 0E100H ;R = 0 FOR NO RETRY
BYTSEC: EQU 512
;
; CHECK THE IDE READY BIT.
;
IDE_READY: LI PORT, IDE_HEAD ;DEVICE HEAD REGISTER
LI R1, 10100000B*256 ;SPECIFY LBA MODE
LDCR R1,BYTEWIDE ;WRITE THE COMMAND
LI PORT,IDE_STATUS ;STATUS
BSY1: STCR R1,BYTEWIDE ;GET STATUS REGISTER
ANDI R1,10000000B * 256 ;IF BUSY, THEN WAIT
JNE BSY1
LI PORT,IDE_STATUS ;STATUS
RDY1: STCR R1,BYTEWIDE ;GET STATUS REGISTER
ANDI R1,01000000B * 256 ;WAIT FOR RDY TO BE SET
JEQ RDY1
RET
;
; TEMPORARY INTERRUPT HANDLERS
;
IDE_IRQ: ;LI R0,5
;WHEX R0
LI PORT,IDE_STATUS ;STATUS
STCR R0,BYTEWIDE
RTWP
;
; TEMPORARY INTERRUPT HANDLERS
;
IDE_DMARQ: ;LI R0,6
;WHEX R0
LI PORT,IDE_STATUS ;STATUS
STCR R0,BYTEWIDE
RTWP
;
; CALL THE DRIVE ID. THIS IS NOT OF MUCH PRACTICAL USE, BUT A GOOD TEST.
;
DRIVE_ID: CALL @IDE_READY
LI PORT, IDE_COMMAND ;COMMAND REGISTER6
LI R1, IDE_CMD_ID ; READ BUFFER
LDCR R1,BYTEWIDE
CALL @IDE_WAIT_DRQ
JEQ IDE_GET_ERROR
CALL @IDE_READ_DATA
RET
;
;when an error occurs, we get acc.0 set from a call to ide_drq
;or ide_wait_not_busy (which read the drive's status register). If
;that error bit is set, we should jump here to read the drive's
;explaination of the error, to be returned to the user. If for
;some reason the error code is zero (shouldn't happen), we'll
;return 255, so that the main program can always depend on a
;return of zero to indicate success.
;
IDE_GET_ERROR: LI PORT, IDE_ERROR
CLR R1
STCR R1,BYTEWIDE
MOVB R1,R1
JEQ IGE_X ;RETURN ERROR IN MSB OF R1
MESG @IDE_MSG1
WHEX R1
IGE_X RET
IDE_MSG1: TEXT "IDE ERROR: "
WORD 0DH,0AH,0
EVEN
;
; READ_SECTOR
; R3 HOLDS THE LSB OF THE LBA VALUE FOR THE SECTOR WE WANT TO READ
; R4 HOLDS THE BUFFER ADDRESS
;
READ_SECTOR: MOV R3,R5 ;SAVE THE LBA
CALL @IDE_NOT_BUSY
CALL @IDE_WR_LBA
LI PORT, IDE_COMMAND ;COMMAND REGISTER6
LI R1, IDE_CMD_READ ; READ BUFFER
LDCR R1,BYTEWIDE
;
CALL @IDE_WAIT_DRQ
JEQ IDE_GET_ERROR
CALL @IDE_READ_DATA
RET
;
; WRITE SECTOR
; R3 HOLDS THE LSB OF THE LBA VALUE FOR THE SECTOR WE WANT TO READ
; R4 HOLDS THE BUFFER ADDRESS
;
;
WRITE_SECTOR: MOV R3,R5
CALL @IDE_NOT_BUSY
CALL @IDE_WR_LBA
LI PORT, IDE_COMMAND ;COMMAND REGISTER6
LI R1, IDE_CMD_WRITE ; WRITE BUFFER
LDCR R1,BYTEWIDE
;
CALL @IDE_WAIT_DRQ
CALL @IDE_WRITE_DATA
RET
;
; WAIT FOR THE IDE DRIVE TO NOT BE BUSY
;
IDE_NOT_BUSY: LI PORT,IDE_COMMAND ;STATUS
BSY2 STCR R1,BYTEWIDE ;GET STATUS REGISTER
ANDI R1,10000000B * 256 ;IF BUSY, THEN WAIT
JNE BSY2
RET
;
; WAIT FOR DRQ BEFORE READ DATA. 0 STATUS, ERROR
;
IDE_WAIT_DRQ: SETO R0 ;VERY CRUDE TIMEOUT
LI PORT,IDE_COMMAND
CLR R1
DRQ1 DEC R0
JEQ DRQ_X
STCR R1,BYTEWIDE
ANDI R1,00001000B * 256 ;WAUT FOR DRQ READT, THEN WAIT
JEQ DRQ1
DRQ_X RET
;
; IDE Status Register:
; bit 7: Busy 1=busy, 0=not busy
; bit 6: Ready 1=ready for command, 0=not ready yet
; bit 5: DF 1=fault occured inside drive
; bit 4: DSC 1=seek complete
; bit 3: DRQ 1=data request ready, 0=not ready to xfer yet
; bit 2: CORR 1=correctable error occured
; bit 1: IDX vendor specific
; bit 0: ERR 1=error occured
;;------------------------------------------------------------------
;
; BECAUSE IDE TRANSFERS ARE IN 16 BIT WORDS AND WE ONLY HAVE ACCESS TO 8 BIT
; TRANSFERS, 256 BYTES REPRESENTS AN LBA AND TWO LBA A SECTOR. SO TWO LBAS ARE READ
;
; WE ENTER WITH R4 -> BUFFER
;
IDE_READ_DATA: LI R0,BYTSEC
LI PORT,IDE_DATA ;DATA REG
RL11: STCR R1,BYTEWIDE ;
MOVB R1,*R4+
DEC R0
JNE RL11
MOV R0,R1
RET
;
; BECAUSE IDE TRANSFERS ARE IN 16 BIT WORDS AND WE ONLY HAVE ACCESS TO 8 BIT
; TRANSFERS, 256 BYTES REPRESENTS AN LBA AND TWO LBA A SECTOR.
;
; WE ENTER WITH R4 -> BUFFER
IDE_WRITE_DATA: LI R0,BYTSEC
LI PORT,IDE_DATA ;DATA REG
WL11: MOVB *R4+,R1
LDCR R1,BYTEWIDE ;
DEC R0
JNE WL11
MOV R0,R1
RET
;
; WRITE THE LOGICAL BLOCK ADDRESS TO THE DRIVE'S REGISTERS
; ORGANISED AS:
; LBA WORD 0,0
;
; LBA + 3 = HEAD (MSB)
; LBA + 2 = CYL MSB
; LBA + 1 = CYL LSB
; LBA + 0 = SECTOR (LSB )
;
; R5 HOLDS THE LSB OF THE LBA, MSB WILL BE ZEROED FOR TIME BEING
;
IDE_WR_LBA: CLR @LBA
MOV R5,@LBA + 2
MOVB @LBA+0,R1 ;GET THE FIRST MSB BYTE
ANDI R1,0FH*256
ORI R1,0E0H*256 ; 0EH IS JUST THE 1110 CODE FOR HEAD REGISTER
LI PORT,IDE_HEAD ; IDE HEAD
LDCR R1,BYTEWIDE
;
MOVB @LBA+1,R1
LI PORT,IDE_CYL_MSB ;CYLINDER MSB
LDCR R1,BYTEWIDE
MOVB @LBA+2,R1
LI PORT,IDE_CYL_LSB ;CYLINDER LSB
LDCR R1,BYTEWIDE
MOVB @LBA+3,R1
LI PORT,IDE_SECTOR ;CYLINDER LSB
LDCR R1,BYTEWIDE
;
; WE NEED TO READ TWO SECTORS TO GET 512 BYTES DUE TO THE FACT THAT WE CAN'T DO 16 BIT READS/WRITES
; SO TWO LBAS REPRESENT A VIRTUAL SECTOR OF 512
;
LI R1,2*256 ;
LI PORT,IDE_SEC_CNT ;CYLINDER LSB
LDCR R1,BYTEWIDE
RET
;======================= END IDE INTERFACE ROUTINES ==============
;
;
;********************************
;
;INTIALISE INT.VECTORS ETC
;
;*******************************
;
INTSYS RET
;
;********************************
;
;RESET FDC
;
;********************************
;
RSET RET
;
;
;*******************************************
;
; SET THE TIME OUT TIMER
;
SETTIMER: WORD INTWP4,SETTIMER+4
LI PORT,0080H
SBZ 20 ;RESET INTERRUPT
LI R8,200 ; 200 X 16MS = 7.0SEC
MOV R8,@TIMEOUT
SBZ 14
SBO 13 ;LOAD INTERVAL TIMER ONLY
LDCR @INTLV2,8
SBO 20 ;ENABLE INTERRUPT
RTWP
;
INTLV2: BYTE 255 ;16.0 MILLISECONDS
EVEN
;
;;*******************************************
;
; SEEK TO THE TRACK NUMBER HELD IN R3
;
; DRIVE # IS IN DRIVE
;
;********************************************
;
SEEK: CALL @IDE_READY
RET
;
;******************************
;
; MAIN INTERRUPT ROUTINES
;
;********************************
;
FDC_DRQ ;LI R0,3 ;SHOW WHERE THE INTERRUPT CAME FROM
;WHEX R0
LI PORT,STSREG
STCR R8 ;READ THE PORT AND CLEAR THE INTERRUPT
RTWP
;
;***********************************
;
; THIS INTERRUPT SIMULATES DMA CONTROL
; ORGANISED AS FOLLOWS:
;
; R9 HOLDS CURRENT COMMAND I.E. STCR OR LDCR
; R8 HOLDS THE CURRENT DMA ADDRESS.
; R12 HOLDS THE CURRENT IO PORT - GENERALLY DATREG
;
FDC_RWINT ;LI R0,2 ;SHOW WHERE THE INTERRUPT CAME FROM
;WHEX R0
;X R9 ;EXECUTE THE COMMAND SPECIFIED BY RDWRT
RTWP
;
;*********************************************************************
;
; THIS INTERRUPT IS CONTROLED BY THE TIMER ON THE TMS9902
;
;**********************************************************************
;
INTTIMER: LI PORT,CRUBASE
TB 25
JNE TIME2
SBO 20 ;RESET INTERRUPT
DEC @TIMEOUT
JNE TIME2
INC @TIMEOUT
SBZ 20 ;DISABLE TIMER
LI PORT,SELMUX
CLR R8
LDCR R8,5 ;CLEAR DISKS
TIME2 RTWP
;
;***********************************************************************
;
; MESSAGES
;
;************************************************************************
;
ERRMSG BYTE 0DH,0AH,20H
TEXT 'FDC error type: '
BYTE 0
;STKMSG BYTE 0DH,0AH,20H
; TEXT 'Stack overflow at: '
; BYTE 0
DRVMSG TEXT ' Drive: '
BYTE 0
TRKMSG TEXT ' Track: '
BYTE 0
SECTMSG TEXT ' Sector: '
BYTE 0
;
;***************************************************************************
;
; ALL XOP's AND WORKSPACES ARE DEFINED IN THIS SECTION AND ARE USED BY ALL PROGRAMMES
; THAT INTERACT WITH THE MONITOR ROUTINES
;
; NOTES.
; 1. ALL INTWP'S AND XOPWP'S OVERLAP AND SO ANY INT OR XOP
; FUNCTION CODE MAY ONLY USE REGISTERS R8-R10. REGISTERS R11
; TO R15 ARE RESERVED FOR XOP & INT LINKAGES.
;
; 2. THE XOP WORKSPACES ARE JUST FOR MANAGING THE STACK AND CONTEXT
; CALLS THE ORIGINAL WP IS PRESERVED AFTER THE CALL, WHICH MEANS
; THAT CALLING ROUTINES SHARE THE SAME REGISTERS.
;
; 3. EVEN THOUGH R9 & R10 ARE GENERALLY USED AS STACK REGISTERS
; THIS DOES NOT APPLY IN INTERRUPT WORKSPACE WHERE THEY CAN'T
; BE USED FOR THAT PURPOSE - SIMPLY BECAUSE THE STACK POINTER
; IS NOT PASSED TO THE NEW WORKSPACE. THEY CAN BE COPIED USING
; THE R13 INDEX IF NEEDED AS R13 POINTS TO THE CALLING ROUTINE'S WORKSPACE
;
;*****************************************************************************
;
; EVEN
INTWP0 EQU INTWP ;INTERRUPT WORKSPACE
INTWP1 EQU INTWP0+16 ;ONLY 7 ALLOWED
INTWP2 EQU INTWP1+16
INTWP3 EQU INTWP2+16
INTWP4 EQU INTWP3+16
INTWP5 EQU INTWP4+16
INTWP6 EQU INTWP5+16
INTWP7 EQU INTWP6+16
;
; NOW XOP'S
;
XOPWP0 EQU XOPWP
XOPWP1 EQU XOPWP0+16
XOPWP2 EQU XOPWP1+16
XOPWP3 EQU XOPWP2+16
XOPWP4 EQU XOPWP3+16
XOPWP5 EQU XOPWP4+16
XOPWP6 EQU XOPWP5+16
XOPWP7 EQU XOPWP6+16
XOPWP8 EQU XOPWP7+16
XOPWP9 EQU XOPWP8+16
XOPWP10 EQU XOPWP9+16
XOPWP11 EQU XOPWP10+16
XOPWP12 EQU XOPWP11+16
XOPWP13 EQU XOPWP12+16
XOPWP14 EQU XOPWP13+16
XOPWP15 EQU XOPWP14+16
XOPWP16 EQU XOPWP15+16
;
; AORG XOPWP15+32
;
;
; DEFINE ALL THE XOP ROUTINES
;
;================================================
;
; DOS EMULATOR - THIS IS NEEDED WHEN CODE IN MEMORY SEGMENTS NEED TO ACCESS BDOS
; CALLING METHOD: BDOS
; REGISTERS: R2 AND R3 CONTAIN FUNCTION NUMBER AND ARGUMENT
;
; IT WORKS BECAUSE THE TMS99105A WILL CLEAR THE PSEL BIT AND FORCE THE SIGNAL HIGH THUS SELECTING PAGE 0
; OR COMMON MEMORY. RTWP, AND R15 WILL RETURN IT TO ITS ORIGINAL VALUE.
;
;================================================
;
XOP0: MOV @2*R2(R13),R2 ;GET FUNCTION
MOV @2*R3(R13),R3 ;GET PARAMETER
MOV @BDOSV,R8
CALL *R8
RTWP