OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [trunk/] [src/] [sys09bug/] [sys09ide.asm] - Blame information for rev 131

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 59 davidgb
*
2
** SYS09BUG MONITOR EXTENSIONS
3
*
4
* FOR SYS09BUG ON THE XESS XSA-3S100 / XST-3.0
5
* WITH I/O MAPPED AT $XE000
6
* 16 BIT IDE MAPPED AT $E100
7
* AND ROM MAPPED AT $XF000
8
*
9
*
10
 PAGE
11
*
12
***************************************************
13
* Serial PROM register
14
***************************************************
15
*
16
** CONFIGURATION PROM DEFINITIONS
17
*
18
PROMREG EQU MONIO+$C0
19
PCLKHI  EQU $01     Toggle PROM Clock High
20
PCLKLO  EQU $00     Toggle PROM Clock Low
21
PRSTHI  EQU $02     Toggle PROM Reset High
22
PRSTLO  EQU $00     Toggle PROM Reset Low
23
SYNCHI  EQU $AA55   Synch Pattern High Word
24
SYNCLO  EQU $FF00   Synch Pattern Low Word
25
*
26
*
27
***************************************************
28
*   START OF ROM                                  *
29
***************************************************
30
*
31
MONITV EQU MONROM+0  FDB MONITOR
32
NXTCMV EQU MONROM+2  FDB NEXTCMD
33
INCHV  EQU MONROM+4  FDB INCH
34
INCHEV EQU MONROM+6  FDB INCHE
35
INCHKV EQU MONROM+8  FDB INCHEK
36
OUTCHV EQU MONROM+10 FDB OUTCH
37
PDATAV EQU MONROM+12 FDB PDATA
38
PCRLFV EQU MONROM+14 FDB PCRLF
39
PSTRGV EQU MONROM+16 FDB PSTRNG
40
LRAV   EQU MONROM+18 FDB LRA
41
*
42
* Condition code flags
43
*
44
CFLAG   EQU $01     CARRY FLAG
45
VFLAG   EQU $02     OVERFLOW FLAG
46
ZFLAG   EQU $04     ZERO FLAG
47
NFLAG   EQU $08     NEGATIVE FLAG
48
IFLAG   EQU $10     IRQ MASK CC
49
HFLAG   EQU $20     HALF CARRY
50
FFLAG   EQU $40     FIRQ MASK CC
51
EFLAG   EQU $80     ENTIRE FLAG
52
*
53
* Serial Port
54
*
55
ACIAC1  EQU ACIAS
56
ACIAD1  EQU ACIAS+1
57
DELCON  EQU 1250    Delay (Processor clock in MHz * 50)
58
*
59
* XMODEM Control characters
60
*
61
SOH     EQU $01
62
EOT     EQU $04
63
ACK     EQU $06
64
NAK     EQU $15
65
CAN     EQU $18
66
*
67
* Some Disk Constants
68
*
69
RMAXTRK EQU 256
70
RMAXSEC EQU 255
71
RTOTSEC EQU RMAXTRK*RMAXSEC-RMAXSEC
72
*
73
* RAM SPACE
74
*
75
* PUT THIS DOWN THE BOTTOM OF MEMORY
76
*
77
        ORG  $0100
78
DRVNUM  RMB 1
79
TRACK   RMB 1
80
SECTOR  RMB 1
81
CHKSUM  RMB 1
82
BLKNUM  RMB 1 Xmodem block number
83
BYTCNT  RMB 1 Xmodem byte count
84
XSTATE  RMB 2 Xmodem State Vector
85
DELCNT  RMB 3  $00,$00,$00 Xmodem Poll timer
86
MAXTRK  RMB 1
87
MAXSEC  RMB 1
88
        ORG  $0200
89
*
90
* SECTOR BUFFER
91
*
92
BUFFER  RMB  256
93
*
94
****************************************
95
*
96
* START OF EXTENSION COMMANDS
97
*
98
****************************************
99
*
100
        ORG MONEXT
101
        FDB NEXTEXT   Jump to next extended command
102
*
103
***** NEXTCMD *****
104
*
105
NEXTEXT JSR [INCHEV]  GET ONE CHAR. FROM TERMINAL
106
        ANDA #$7F STRIP PARITY FROM CHAR.
107
        TFR  A,B
108
        LDA  #$20
109
        JSR [OUTCHV] PRNT SPACE
110
        CMPB #$60
111
        BLE NXTEX0
112
        SUBB #$20
113
*
114
***** DO TABLE LOOKUP *****
115
*   FOR COMMAND FUNCTIONS
116
*
117
NXTEX0  LDX #EXTTAB    POINT TO JUMP TABLE
118
NXTEX1  CMPB ,X+       DOES COMMAND MATCH TABLE ENTRY ?
119
        BEQ  JMPEXT    BRANCH IF MATCH FOUND
120
        LEAX 2,X       POINT TO NEXT ENTRY IN TABLE
121
        CMPX #EXTEND   REACHED END OF TABLE YET ?
122
        BNE  NXTEX1    IF NOT END, CHECK NEXT ENTRY
123
        LDX  #MSGWHAT  POINT TO MSG "WHAT?"
124
        LBRA PDATA1    PRINT MSG AND RETURN
125
JMPEXT  JMP  [,X]      JUMP TO COMMAND ROUTINE
126
*
127
* EXTENDED COMMAND JUMP TABLE
128
*
129
EXTTAB EQU *
130
       FCC 'B'   BOOT FLEX
131
       FDB UBSUB
132
       FCC 'F'   FORMAT IDE DISK
133
       FDB UFSUB
134
       FCC 'X'   XMODEM ROM DISK UPLOAD
135
       FDB UXSUB
136
*
137
EXTEND EQU *
138
*
139
MSGWHAT FCC "WHAT ?"
140
        FCB $0A,$0D,$04
141
*
142
* GO TO FLEX RESIDENT IN MEMORY
143
*
144
UBSUB   LDX #$CD00
145
        STX 10,U
146
        TFR  U,S
147
        RTI
148
*
149
* recieve char from remote drive.
150
* timeout if no response for approx 1s.
151
* Entry: no parameters
152
* Exit:  (A) = recieved char, (C)=1 if valid char, (C)=0 if timeout.
153
*
154
RCHAR   PSHS    X,Y
155
*
156
        LDX     #1000         1000x inner loop
157
RCHAR1  LDY     #DELCON       delay constant for inner loop (approx 1ms).
158
RCHAR2  LDA     ACIAC1        test for recieved char
159
        ASRA
160
        BCS     RCHAR3        get character
161
        LEAY    -1,Y          else, continue to count delay
162
        BNE     RCHAR2
163
        LEAX    -1,X
164
        BNE     RCHAR1
165
        PULS    X,Y,PC        return with error if timed out
166
*
167
RCHAR3  LDA     ACIAD1        return data (carry bit still set)
168
        PULS    X,Y,PC
169
*
170
*
171
* transmit char to remote drive.
172
* timeout if no response for approx 1s. (allows for use of hardware flow control)
173
* Entry: (A) = char to transmit
174
* Exit:  (A) = recieved char, (C)=1 if valid char, (C)=0 if timeout.
175
*
176
SCHAR   PSHS    X,Y
177
        PSHS    A
178
*
179
        LDX     #1000         1000x inner loop
180
SCHAR1  LDY     #DELCON       delay constant for inner loop (approx 1ms).
181
SCHAR2  LDA     ACIAC1        test for space in transmit FIFO
182
        ASRA
183
        ASRA
184
        BCS     SCHAR3        send character
185
        LEAY    -1,Y          else, continue to count delay
186
        BNE     SCHAR2
187
        LEAX    -1,X
188
        BNE     SCHAR1
189
        PULS    A
190
        PULS    X,Y,PC        return with error if timed out
191
*
192
SCHAR3  PULS    A
193
        STA     ACIAD1        send data (carry bit still set)
194
        PULS    X,Y,PC
195
*
196
** 'UF' Format IDE Drive to FLEX standard.
197
*
198
DISFOS  FCB $0A,$0D
199
        FCC 'Formating IDE disk... '
200
        FCB $0A,$0D
201
        FCC 'Drive Number ?'
202
        FCB 4
203
MESS6   FCB $0A,$0D,4
204
        FCC 'IDE drive not allocated! '
205
        FCB 4
206
UFMSG1  FCB $0A,$0D
207
        FCC 'Format Complete'
208
        FCB 4
209
VOLMSG  FCC 'IDEDISK '
210
        FCB 4
211
*
212
UFSUB   JSR  INITDR
213
        LDX #DISFOS
214
        JSR PDATA1
215
UFSUB1  LBSR RCHAR
216
        BCC  UFSUB1
217
        LBSR SCHAR
218
        CMPA #'0'
219
        LBLO UFEXIT
220
        CMPA #'3'
221
        LBHI  UFEXIT
222
        SUBA #'0'
223
        TFR  A,B
224
        STB DRVNUM
225
        LDX #DRVNUM-3
226
        JSR DRVSEL
227
*
228
* set up free chain
229
*
230
        LDX #BUFFER clear out buffer
231
        CLRA
232
        CLRB
233
DFL1    STA 0,X+
234
        DECB
235
        BNE DFL1
236
*
237
        CLR TRACK
238
        LDA #1
239
        STA SECTOR
240
DFL2    LDX #BUFFER
241
        LDA TRACK
242
        STA 0,X
243
        LDA SECTOR
244
        INCA
245
        CMPA #RMAXSEC+1 last sector on track?
246
        BNE DFL3
247
        INC 0,X
248
        LDA #1
249
DFL3    STA 1,X
250
        LDA TRACK
251
        LDB SECTOR
252
        JSR WRITSC
253
        INC SECTOR
254
        LDA SECTOR
255
        CMPA #RMAXSEC+1
256
        BNE DFL2
257
        LDA #1
258
        STA  SECTOR
259
        INC TRACK
260
        LDA TRACK
261
        CMPA #RMAXTRK
262
        BNE DFL2
263
* break free chain at last track/sector
264
        LDX  #BUFFER
265
        LDA  #RMAXTRK-1
266
        LDB  #RMAXSEC
267
        JSR  READSC
268
        LDX  #BUFFER
269
        CLR  0,X
270
        CLR  1,X
271
        LDA  #RMAXTRK-1
272
        LDB  #RMAXSEC
273
        JSR  WRITSC
274
* set up sector structure, SIR, directory etc
275
        LDX  #BUFFER
276
        CLRA
277
        LDB  #RMAXSEC
278
        JSR  READSC
279
        LDX  #BUFFER
280
        CLR  0,X break end of directory chain
281
        CLR  1,X
282
        CLRA
283
        LDB  #RMAXSEC
284
        JSR  WRITSC
285
*
286
        LDX  #BUFFER
287
        CLRA
288
        LDB  #3 set up SIR
289
        JSR  READSC
290
        LDX  #BUFFER
291
        CLR  0,X break forward link
292
        CLR  1,X
293
*
294
        PSHS Y
295
        LDY  #VOLMSG
296
        LDB  #16
297
DFL4    LDA  ,Y+
298
        STA  B,X
299
        INCB
300
        CMPB #24
301
        BNE  DFL4
302
        PULS Y
303
*
304
        CLRA
305
        LDB  DRVNUM volume number
306
        STD  27,X
307
*
308
        LDD  #$0101 first trk/sec  01-01
309
        STD  29,X
310
        LDA  #RMAXTRK-1
311
        LDB  #RMAXSEC
312
        STD  31,X
313
        STD  38,X
314
        LDD  #RTOTSEC total DATA sectors (2912-14)
315
        STD  33,X
316
*
317
        LDA #01 month   set default creation date (SYS09's birthday!)
318
        STA 35,X
319
        LDA #07 day
320
        STA 36,X
321
        LDA #07 year
322
        STA 37,X
323
*
324
RF3     CLRA
325
        LDB  #3
326
        JSR  WRITSC
327
*
328
* Not sure what this is about
329
* put bootstrap on track 0 sector 1
330
*
331
*        LDX #BUFFER
332
*        CLRA
333
*        LDB #1
334
*        JSR READSC
335
*        LDX #BUFFER
336
*        LDA #$AA set the init flag
337
*        STA 0,X
338
*        LDA  #$55
339
*        STA 1,X
340
*        CLRA
341
*        LDB #1
342
*        JSR WRITSC
343
*
344
*  Write Boot sector
345
*
346
        LDX  #BOOT
347
        CLRA         TRACK 0
348
        LDB  #$01    SECTOR 1
349
        STA  TRACK
350
        STB  SECTOR
351
        LBSR WRITSC
352
*
353
UFEXIT  LDX #UFMSG1
354
        JMP PDATA1
355
*
356
* ACIA INPUT TEST
357
*
358
INTEST  LDA ACIAC1
359
        BITA #$01
360
        RTS
361
*
362
* RESET ACIA
363
*
364
ACIRST  LDA #$03 master reset
365
        STA  ACIAC1
366
        LDA #$11
367
        STA ACIAC1
368
        RTS
369
*
370
* ACIA INPUT
371
*
372
INTER   LDA  #16
373
        STA  DELCNT+0
374
        CLR  DELCNT+1
375
        CLR  DELCNT+2
376
INTER0  LDA  ACIAC1
377
        BITA #$01
378
        BNE  INTER1
379
        BITA #$78
380
        BEQ  INTER2
381
        BSR  ACIRST
382
        BRA  INTER
383
*
384
INTER1  LDA  ACIAD1
385
        ANDCC #$FF-VFLAG
386
        RTS
387
*
388
INTER2  DEC  DELCNT+2
389
        BNE  INTER0
390
        DEC  DELCNT+1
391
        BNE  INTER0
392
        DEC  DELCNT+0
393
        BNE  INTER0
394
        CLRA
395
        ORCC #VFLAG
396
        RTS
397
*
398
* ACIA OUTPUT
399
*
400
OUTTER  PSHS A
401
*
402
OUTTE1  LDA ACIAC1
403
        BITA #$02
404
        BNE  OUTTE2
405
        BITA #$78
406
        BEQ  OUTTE1
407
        BSR  ACIRST
408
        BRA  OUTTE1
409
*
410
OUTTE2  PULS A
411
        STA ACIAD1
412
        RTS
413
*
414
* Print Data
415
*
416
PDATA0  BSR  OUTTER
417
PDATA1  LDA  ,X+
418
        CMPA #$04
419
        BNE  PDATA0
420
        RTS
421
*
422
*
423
** 'UX' Xmodem IDE Disk upload
424
*
425
UXMES0  FCB $0D,$0A
426
        FCC 'Xmodem IDE Disk Upload'
427
        FCB 4
428
UXMES1  FCB $0D,$0A
429
        FCC 'Upload Complete'
430
        FCB 4
431
UXMES2  FCB $0D,$0A
432
        FCC 'Upload Error'
433
        FCB 4
434
UXMSG3  FCB $0D,$0A
435
        FCC 'Drive Number :'
436
        FCB 4
437
UXMSG4  FCB $0D,$0A
438
        FCC 'Are You Sure ? (Y/N)'
439
        FCB 4
440
*
441
* Print Banner
442
*
443
UXSUB   LDX #UXMES0
444
        LBSR PDATA1
445
*
446
* Prompt for Disk drive number (0 to 3)
447
*
448
        LDX #UXMSG3
449
        LBSR PDATA1
450
UXSUB1  LBSR INTER
451
        BVS  UXSUB1
452
        LBSR OUTTER
453
        CMPA #'0
454
        LBLO UXEXIT
455
        CMPA #'3
456
        LBHI UXEXIT
457
        SUBA #'0
458
        STA  DRVNUM
459
*
460
* Report selected drive
461
*
462
        LDX #UXMSG3
463
        LBSR PDATA1
464
        LDA  DRVNUM
465
        ADDA #'0
466
        LBSR OUTTER
467
*
468
* Ask for confirmation (Y/N)
469
*
470
        LDX #UXMSG4
471
        LBSR PDATA1
472
UXSUB2  LBSR INTER
473
        BVS  UXSUB2
474
        LBSR OUTTER
475
        ANDA #$5F
476
        CMPA #'N
477
        LBEQ UXEXIT
478
        CMPA #'Y
479
        BNE  UXSUB
480
*
481
* We have confirmation ... now load the disk image
482
*
483
        LBSR INITDR
484
        LDU  #XSTST
485
        STU  XSTATE
486
        LDA  #1
487
        STA  BLKNUM
488
*
489
* Sector1
490
*
491
        LDX  #BUFFER
492
*
493
        CLRA         TRACK 0
494
        LDB  #$01    SECTOR 1
495
        STA  TRACK
496
        STB  SECTOR
497
*
498
        LBSR XREAD
499
        LBCS UXERR
500
        LBSR XACK
501
        LBSR XREAD
502
        LBCS UXERR
503
*
504
        LDX  #BUFFER
505
        LDA  TRACK
506
        LDB  SECTOR
507
        LBSR WRITSC
508
        LBSR XACK
509
*
510
* Sector 2
511
*
512
        LDX  #BUFFER
513
*
514
        LDA  TRACK
515
        LDB  SECTOR
516
        INCB
517
        STA  TRACK
518
        STB  SECTOR
519
*
520
        LBSR XREAD
521
        LBCS UXERR
522
        LBSR XACK
523
        LBSR XREAD
524
        LBCS UXERR
525
*
526
        LDX  #BUFFER
527
        LDA  TRACK
528
        LDB  SECTOR
529
        LBSR WRITSC
530
*
531
        LBSR XACK
532
*
533
* Sector 3 - SIR
534
*
535
        LDX  #BUFFER
536
*
537
        LDA  TRACK
538
        LDB  SECTOR
539
        INCB
540
        STA  TRACK
541
        STB  SECTOR
542
*
543
        LBSR XREAD
544
        LBCS UXERR
545
        LBSR XACK
546
        LBSR XREAD
547
        LBCS UXERR
548
*
549
        LDX  #BUFFER
550
        LDA  38,X
551
        INCA
552
        STA  MAXTRK
553
        LDB  39,X
554
        INCB
555
        STB  MAXSEC
556
        LDA  TRACK
557
        LDB  SECTOR
558
        LBSR WRITSC
559
*
560
        LBSR XACK
561
*
562
* Sector 4 to Last Track & Sector
563
*
564
*
565
        LDA  TRACK
566
        LDB  SECTOR
567
        INCB
568
*
569
UXLOOP  LDX  #BUFFER
570
        STA  TRACK
571
        STB  SECTOR
572
*
573
        LBSR XREAD
574
        LBCS UXERR
575
        LBSR XACK
576
        LBSR XREAD
577
        LBCS UXERR
578
*
579
        LDX  #BUFFER
580
        LDA  TRACK
581
        LDB  SECTOR
582
        LBSR WRITSC
583
        LBSR XACK
584
*
585
        LDA  TRACK
586
        LDB  SECTOR
587
        INCB
588
        CMPB MAXSEC
589
        BNE  UXLOOP
590
        LDB  #1
591
        INCA
592
        CMPA MAXTRK
593
        BNE  UXLOOP
594
*
595
*
596
*  Write Boot sector
597
*
598
        LDX  #BOOT
599
        CLRA         TRACK 0
600
        LDB  #$01    SECTOR 1
601
        STA  TRACK
602
        STB  SECTOR
603
        LBSR WRITSC
604
*
605
UXEXIT  LDX  #UXMES1
606
        JMP  PDATA1
607
*
608
UXERR   LDX  #UXMES2
609
        LBRA PDATA1
610
*
611
* Get a Byte using XModem protocol
612
* Carry clear => no errors
613
* Carry set   => errors
614
*
615
XREAD   PSHS U
616
        LDU  XSTATE
617
*
618
XBYTE0  LBSR INTER
619
        BVC  XBYTE1
620
        LDA  #NAK
621
        LBSR OUTTER
622
        LDU  #XSTST
623
        BRA  XBYTE0
624
*
625
XBYTE1  JSR  ,U
626
        BNE  XBYTE0
627
        STU  XSTATE
628
        PULS U,PC
629
*
630
* START - LOOK FOR SOH (START OF HEADER) = $01
631
*
632
XSTST   CMPA #SOH
633
        BNE  XSTST1
634
        LDU  #XSTBL
635
        ANDCC #$FF-CFLAG-ZFLAG No abort, no valid data (no exit)
636
        RTS
637
*
638
XSTST1  CMPA #EOT
639
        BNE  XSTST2
640
        LDA  #ACK
641
        LBSR OUTTER
642
        ORCC  #CFLAG+ZFLAG  Set (c)=1 abort & exit
643
        RTS
644
*
645
XSTST2  CMPA #CAN
646
        BNE  XSTST3
647
        ORCC  #CFLAG+ZFLAG  Set (c)=1 abort & exit
648
        RTS
649
*
650
XSTST3  ANDCC #$FF-CFLAG-ZFLAG
651
        RTS
652
*
653
* Got SOH
654
* Now get block number
655
*
656
XSTBL   CMPA BLKNUM
657
        BNE  XSTBLE
658
        LDU  #XSTCOM
659
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
660
        RTS
661
*
662
* Error in block number
663
*
664
XSTBLE  LDA  #NAK
665
        LBSR OUTTER
666
        LDU  #XSTST
667
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
668
        RTS
669
*
670
* Get complement of block number
671
*
672
XSTCOM  COMA
673
        CMPA BLKNUM
674
        BNE  XSTBLE
675
        CLR  CHKSUM
676
        LDA  #128
677
        STA  BYTCNT
678
        LDU  #XSTDA
679
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
680
        RTS
681
*
682
* Get data bytes
683
*
684
XSTDA   PSHS A
685
        ADDA CHKSUM
686
        STA  CHKSUM
687
        PULS A
688
        DEC  BYTCNT
689
        BNE  XSTDA1
690
        LDU  #XSTCK
691
XSTDA1  STA  ,X+
692
        ANDCC #$FF-CFLAG-ZFLAG No abort, no valid data (no exit)
693
        RTS
694
*
695
* Byte count reached zero
696
* Check checksum byte
697
*
698
XSTCK   CMPA CHKSUM
699
        BNE  XSTCK1 retry if wrong checksum
700
*
701
* Checksum OK ...
702
* increment block number
703
* Don't send ACK until data written to CF
704
*
705
        INC  BLKNUM
706
        LDU  #XSTST
707
        ANDCC #$FF-CFLAG No abort
708
        ORCC #ZFLAG      Valid data (exit)
709
        RTS
710
*
711
* Checksum Error detected ...
712
* Reset Sector counter in ACCB to last 128 byte boundary
713
* and send NAK
714
*
715
XSTCK1  PSHS B
716
        TFR  X,D
717
        DECB
718
        ANDB #128
719
        TFR  D,X
720
        PULS B
721
        LDA  #NAK
722
XSTCK2  LBSR OUTTER
723
        LDU  #XSTST
724
        ANDCC #$FF-CFLAG-ZFLAG No abort, no valid data (no exit)
725
        RTS
726
*
727
* Acknowledge Data Received
728
*
729
XACK    PSHS A
730
        LDA  #ACK
731
        LBSR OUTTER
732
        PULS A,PC
733
*
734
*
735
** FLEX 9 IDE DISK DRIVERS
736
*
737
* FOR SYS09BUG 1.2 ON THE XSA-3S1000
738
* WITH I/O MAPPED AT $XE000
739
* AND ROM MAPPED AT $XF000
740
*
741
*
742
* INITIALIZE CF CARD FOR 8 BIT LBA MODE
743
*
744
INITDR LDD #AUXRESET
745
       STD CF_AUX
746
       LDD #AUXRSTREL
747
       STD CF_AUX
748
       LDD  #HEADLBA
749
       STD  CF_HEAD
750
       LBRA WTRDY
751
*
752
* RESTORE DISK DRIVER (SEEK TRACK 00)
753
*
754
RESTR1 BSR   DRVSEL
755
       CLRA           ; Track 0
756
       LDB   #$01     ; Sector 1
757
*
758
* Seek track and sector
759
* A holds track number (0 - ??)
760
* B holds sector number (1 - ??)
761
* Sector numbers starts from 1
762
* subtract 1 to start from sector 0 on CF
763
*
764
SEEKTS PSHS A
765
       CLRA
766
       DECB
767
       STD  CF_SECNUM
768
       LDB ,S
769
       STD  CF_CYLLO
770
       LDB  DRVNUM
771
       STD  CF_CYLHI
772
       LDB  #$01
773
       STD  CF_SECCNT
774
       CLRB
775
       PULS A,PC
776
*
777
* READ SECTORS FROM CF
778
*
779
*
780
READSC BSR  SEEKTS
781
       LDD  #CMDREAD ; IDE READ MULTIPLE
782
       STD  CF_COMAND
783
       LBSR  WTRDY
784
*
785
* READ LOOP
786
*
787
       PSHS Y
788
       LDY #256
789
RDLP1  LBSR  WTDRQ
790
       LDD  CF_DATA
791
       STB  ,X+
792
       LEAY -1,Y
793
       BNE  RDLP1
794
       PULS Y
795
*
796
       LBSR  WTRDY
797
       CLRB
798
       RTS
799
*
800
* WRITE SECTOR TO CF
801
*
802
WRITSC BSR  SEEKTS   ; SEEK TRACK & SECTOR
803
       LDD  #CMDWRITE ; IDE WRITE MULTIPLE
804
       STD  CF_COMAND
805
       LBSR  WTRDY
806
*
807
* WRITE LOOP
808
*
809
       PSHS Y
810
       LDY #256
811
       CLRA
812
WRTLP1 LBSR  WTDRQ
813
       LDB  ,X+
814
       STD  CF_DATA
815
       LEAY -1,Y
816
       BNE  WRTLP1
817
       PULS Y
818
*
819
       LBSR  WTRDY
820
       CLRB
821
       RTS
822
*
823
* DRIVE SELECT DISK DRIVER
824
*
825
DRVSEL LDA   3,X       GET DRIVE # FROM FCB
826
       CMPA  #3
827
       BLS   DRVS2     IF > 3, SET IT TO 0
828
       CLRA
829
DRVS2  STA   DRVNUM
830
       CLRB            ; SET Z, CLEAR C
831
       RTS
832
*
833
* CHECK DRIVE READY DISK DRIVER
834
*
835
CHKDRV LDA  3,X
836
       CLRB             ; CLEAR C, SET Z
837
       RTS
838
*******************************************************
839
*
840
* Bootstrap FLEX Loader
841
*
842
* SBUG1.8 loads the bootstap loader at $C000
843
* however the Flex adaption manual has the
844
* bootstrap loader residing at $C100
845
* Bootstrap Loader is position independent code
846
*
847
******************************************************
848
*
849
* Equates
850
*
851
BSSTACK EQU $C0FF
852
SCTBUF  EQU $C300
853
*
854
* Start of Utility
855
*
856
        ORG MONEXT+$0700
857
BOOT    BRA BLOAD0
858
        FCB 0,0,0
859
TRK     FCB 0        File start track
860
SCT     FCB 0        File start sector
861
DNS     FCB 0        Density Flag (not used)
862
TADR    FDB $C000    Transfer address
863
LADR    FDB 0        Load Address
864
DRNUM   FCB 0        Drive number 0
865
*
866
BLOAD0  LDS  #BSSTACK   Set up Bootstrap stack
867
        LDD  TRK,PCR    Set up start track and sector
868
        STD  SCTBUF
869
        LDY  #SCTBUF+256
870
*
871
* Perform actual file load
872
*
873
BLOAD1  BSR GETCH    Get acharcater
874
        CMPA #$02    Data record hearder ?
875
        BEQ  BLOAD2   Skip, is so
876
        CMPA #$16    Xfr address hearder ?
877
        BNE BLOAD1    Loop if neither
878
*
879
* Get transfer address
880
*
881
        BSR  GETCH
882
        STA  TADR,PCR
883
        BSR  GETCH
884
        STA  TADR+1,PCR
885
        BRA  BLOAD1
886
*
887
* Load data record
888
*
889
BLOAD2 BSR  GETCH  Get load address
890
       STA  LADR,PCR
891
       BSR  GETCH
892
       STA  LADR+1,PCR
893
       BSR  GETCH  Get Bytes count
894
       TFR  A,B
895
       TSTB
896
       BEQ  BLOAD1 Loop if count = 0
897
       LDX  LADR,PCR  Get load address
898
BLOAD3 PSHS B,X
899
       BSR  GETCH  Get data character
900
       PULS B,X
901
       STA  ,X+    Store at load address
902
       DECB
903
       BNE  BLOAD3  Loop until count = 0
904
       BRA  BLOAD1
905
*
906
* Get Character routine
907
* Reads a sector if needed
908
*
909
GETCH  CMPY #SCTBUF+256 out of data ?
910
       BNE  GETCH4      Go read Character if not
911
GETCH2 LDX  #SCTBUF     Point to buffer
912
       LDD  0,X         Get forward Link
913
       BEQ  GOFLEX      if zero, file is loaded
914
       BSR  READ        Read next sector
915
       BNE  BOOT        start over if error
916
       LDY  #SCTBUF+4   Point past link
917
GETCH4 LDA  ,Y+         Else, get a character
918
       RTS
919
*
920
* File is loaded, Jump to it
921
*
922
GOFLEX JMP  [TADR,PCR]      Jump to transfer address
923
 
924
*
925
** FLEX 9 IDE DISK DRIVERS
926
*
927
* Seek track and sector
928
* A holds track number (0 - ??)
929
* B holds sector number (1 - ??)
930
* Sector numbers starts from 1
931
* subtract 1 to start from sector 0 on CF
932
*
933
SEEK   PSHS A
934
       CLRA
935
       DECB
936
       STD  CF_SECNUM
937
       LDB  ,S
938
       STD  CF_CYLLO
939
       LDB  DRNUM,PCR
940
       STD  CF_CYLHI
941
       LDB  #$01
942
       STD  CF_SECCNT
943
       CLRB
944
       PULS A,PC
945
*
946
* READ SECTORS FROM CF
947
*
948
*
949
READ   BSR  SEEK
950
       LDD  #CMDREAD ; IDE READ MULTIPLE
951
       STD  CF_COMAND
952
       BSR  WTRDY
953
*
954
* READ LOOP
955
*
956
       PSHS Y
957
       LDY #256
958
READ1  BSR  WTDRQ
959
       LDD  CF_DATA
960
       STB  ,X+
961
       LEAY -1,Y
962
       BNE  READ1
963
       PULS Y
964
*
965
       BSR  WTRDY
966
       CLRB
967
       RTS
968
*
969
* WAIT UNTIL READY
970
*
971
WTRDY   LDD  CF_STATUS
972
        BITB #BUSY
973
        BNE  WTRDY
974
        LDD  CF_STATUS
975
        BITB #DRDY
976
        BEQ  WTRDY
977
        RTS
978
*
979
* WAIT FOR DATA REQUEST
980
*
981
WTDRQ   LDD  CF_STATUS
982
        BITB #DRQ
983
        BEQ  WTDRQ
984
        RTS
985
*
986
       END

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.