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

Subversion Repositories System09

[/] [System09/] [rev_86/] [src/] [upld/] [upld_ide.asm] - Blame information for rev 205

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

Line No. Rev Author Line
1 59 davidgb
*
2
** FLEX 9 DISK DRIVERS
3
*
4
* FOR SYS09BUG ON THE DIGILENT SPARTAN 3 STARTER BOARD
5
* WITH I/O MAPPED AT $XE000
6
* AND ROM MAPPED AT $XF000
7
* THE DIGILENT SPARTAN 3 STARTER BOARD HAS 1MBYTE OF SRAM
8
* THE FIRST 64K IS USED BY FLEX,
9
* THE SECOND 128K IS USED AS A ROM DISK
10
* THE REMAINING RAM IS USED FOR A RAM DISK
11
*
12
*
13
CFLAG   EQU $01     CARRY FLAG
14
VFLAG   EQU $02     OVERFLOW FLAG
15
ZFLAG   EQU $04     ZERO FLAG
16
NFLAG   EQU $08     NEGATIVE FLAG
17
IFLAG   EQU $10     IRQ MASK CC
18
HFLAG   EQU $20     HALF CARRY
19
FFLAG   EQU $40     FIRQ MASK CC
20
EFLAG   EQU $80     ENTIRE FLAG
21
*
22
MAPPAG  EQU $00     PAGE $0000 DAT ADDRESS
23
*
24
* Serial Port
25
*
26
ACIAS   EQU $E000
27
ACIAC1  EQU ACIAS
28
ACIAD1  EQU ACIAS+1
29
DELCON  EQU 1250    Delay (Processor clock in MHz * 50)
30
*
31
* XMODEM Control characters
32
*
33
SOH     EQU $01
34
EOT     EQU $04
35
ACK     EQU $06
36
NAK     EQU $15
37
CAN     EQU $18
38
*
39
* Some dummy Constants
40
*
41
RMAXTRK EQU 64
42
RMAXSEC EQU 255
43
RTOTSEC EQU RMAXTRK*RMAXSEC-RMAXSEC
44
*
45
* Start
46
*
47
        ORG $0100
48
START   LBSR  UXSUB
49
        JMP  [$F800]  Jump to monitor on Completion.
50
*
51
*
52
* RAM SPACE
53
*
54
DRVNUM  FCB  0
55
TRACK   FCB  0
56
SECTOR  FCB  0
57
CHKSUM  FCB  0
58
BLKNUM  FCB  0 Xmodem block number
59
BYTCNT  FCB  0 Xmodem byte count
60
XSTATE  FDB  0 Xmodem State Vector
61
DELCNT  FCB  $00,$00,$00 Xmodem Poll timer
62
MAXTRK  FCB  0
63
MAXSEC  FCB  0
64
        ORG  $0200
65
*
66
* SECTOR BUFFER
67
*
68
BUFFER  RMB  256
69
*
70
*
71
* recieve char from remote drive.
72
* timeout if no response for approx 1s.
73
* Entry: no parameters
74
* Exit:  (A) = recieved char, (C)=1 if valid char, (C)=0 if timeout.
75
*
76
RCHAR   PSHS    X,Y
77
*
78
        LDX     #1000         1000x inner loop
79
RCHAR1  LDY     #DELCON       delay constant for inner loop (approx 1ms).
80
RCHAR2  LDA     ACIAC1        test for recieved char
81
        ASRA
82
        BCS     RCHAR3        get character
83
        LEAY    -1,Y          else, continue to count delay
84
        BNE     RCHAR2
85
        LEAX    -1,X
86
        BNE     RCHAR1
87
        PULS    X,Y,PC        return with error if timed out
88
*
89
RCHAR3  LDA     ACIAD1        return data (carry bit still set)
90
        PULS    X,Y,PC
91
*
92
*
93
* transmit char to remote drive.
94
* timeout if no response for approx 1s. (allows for use of hardware flow control)
95
* Entry: (A) = char to transmit
96
* Exit:  (A) = recieved char, (C)=1 if valid char, (C)=0 if timeout.
97
*
98
SCHAR   PSHS    X,Y
99
        PSHS    A
100
*
101
        LDX     #1000         1000x inner loop
102
SCHAR1  LDY     #DELCON       delay constant for inner loop (approx 1ms).
103
SCHAR2  LDA     ACIAC1        test for space in transmit FIFO
104
        ASRA
105
        ASRA
106
        BCS     SCHAR3        send character
107
        LEAY    -1,Y          else, continue to count delay
108
        BNE     SCHAR2
109
        LEAX    -1,X
110
        BNE     SCHAR1
111
        PULS    A
112
        PULS    X,Y,PC        return with error if timed out
113
*
114
SCHAR3  PULS    A
115
        STA     ACIAD1        send data (carry bit still set)
116
        PULS    X,Y,PC
117
*
118
* Read a byte from the serial port
119
*
120
LRBYTE  PSHS B
121
        BSR  LRHEX                  Get hex digit.
122
        ASLA
123
        ASLA                           Shift to msb.
124
        ASLA
125
        ASLA
126
        TFR  A,B                    Save in B.
127
        BSR  LRHEX                  Get next digit.
128
        PSHS B
129
        ADDA 0,S+                    Add together bytes.
130
        PULS B,PC
131
*
132
LRHEX   JSR  INTER
133
        BVS  LRHEX
134
        SUBA #$30                   Remove ascii bias.
135
        BMI  LRHEX
136
        CMPA #$09                   Number?
137
        BLE  LRHEX1                 Yes.
138
        CMPA #$11                   Keep testing.
139
        BMI  LRHEX
140
        CMPA #$16
141
        BGT  LRHEX
142
        SUBA #$07
143
LRHEX1  RTS
144
*
145
* ACIA INPUT TEST
146
*
147
INTEST  LDA ACIAC1
148
        BITA #$01
149
        RTS
150
*
151
* RESET ACIA
152
*
153
ACIRST  LDA #$03 master reset
154
        STA  ACIAC1
155
        LDA #$11
156
        STA ACIAC1
157
        RTS
158
*
159
* ACIA INPUT
160
*
161
INTER   LDA  #16
162
        STA  DELCNT+0
163
        CLR  DELCNT+1
164
        CLR  DELCNT+2
165
INTER0  LDA  ACIAC1
166
        BITA #$01
167
        BNE  INTER1
168
        BITA #$78
169
        BEQ  INTER2
170
        BSR  ACIRST
171
        BRA  INTER
172
*
173
INTER1  LDA  ACIAD1
174
        ANDCC #$FF-VFLAG
175
        RTS
176
*
177
INTER2  DEC  DELCNT+2
178
        BNE  INTER0
179
        DEC  DELCNT+1
180
        BNE  INTER0
181
        DEC  DELCNT+0
182
        BNE  INTER0
183
        CLRA
184
        ORCC #VFLAG
185
        RTS
186
*
187
* ACIA OUTPUT
188
*
189
OUTTER  PSHS A
190
*
191
OUTTE1  LDA ACIAC1
192
        BITA #$02
193
        BNE  OUTTE2
194
        BITA #$78
195
        BEQ  OUTTE1
196
        BSR  ACIRST
197
        BRA  OUTTE1
198
*
199
OUTTE2  PULS A
200
        STA ACIAD1
201
        RTS
202
*
203
* Print Data
204
*
205
PDATA0  BSR  OUTTER
206
PDATA1  LDA  ,X+
207
        CMPA #$04
208
        BNE  PDATA0
209
        RTS
210
*
211
*
212
** 'UX' Xmodem ROM Disk upload
213
*
214
UXMES0  FCB $0D,$0A
215
        FCC 'Xmodem ROM Disk Upload'
216
        FCB 4
217
UXMES1  FCB $0D,$0A
218
        FCC 'Upload Complete'
219
        FCB 4
220
UXMES2  FCB $0D,$0A
221
        FCC 'Upload Error'
222
        FCB 4
223
UXMSG3  FCB $0D,$0A
224
        FCC 'Drive Number :'
225
        FCB 4
226
UXMSG4  FCB $0D,$0A
227
        FCC 'Are You Sure ? (Y/N)'
228
        FCB 4
229
*
230
* Print Banner
231
*
232
UXSUB   LDX #UXMES0
233
        LBSR PDATA1
234
*
235
* Prompt for Disk drive number (0 to 3)
236
*
237
        LDX #UXMSG3
238
        LBSR PDATA1
239
UXSUB1  LBSR INTER
240
        BVS  UXSUB1
241
        LBSR OUTTER
242
        CMPA #'0
243
        LBLO UXEXIT
244
        CMPA #'3
245
        LBHI UXEXIT
246
        SUBA #'0
247
        STA  DRVNUM
248
*
249
* Report selected drive
250
*
251
        LDX #UXMSG3
252
        LBSR PDATA1
253
        LDA  DRVNUM
254
        ADDA #'0
255
        LBSR OUTTER
256
*
257
* Ask for confirmation (Y/N)
258
*
259
        LDX #UXMSG4
260
        LBSR PDATA1
261
UXSUB2  LBSR INTER
262
        BVS  UXSUB2
263
        LBSR OUTTER
264
        ANDA #$5F
265
        CMPA #'N
266
        LBEQ UXEXIT
267
        CMPA #'Y
268
        BNE  UXSUB
269
*
270
* We have confirmation ... now load the disk image
271
*
272
        LBSR INITDR
273
        LDU  #XSTST
274
        STU  XSTATE
275
        LDA  #1
276
        STA  BLKNUM
277
*
278
* Sector1
279
*
280
        LDX  #BUFFER
281
*
282
        CLRA         TRACK 0
283
        LDB  #$01    SECTOR 1
284
        STA  TRACK
285
        STB  SECTOR
286
*
287
        LBSR XREAD
288
        LBCS UXERR
289
        LBSR XACK
290
        LBSR XREAD
291
        LBCS UXERR
292
*
293
        LDX  #BUFFER
294
        LDA  TRACK
295
        LDB  SECTOR
296
        LBSR WRITSC
297
        LBSR XACK
298
*
299
* Sector 2
300
*
301
        LDX  #BUFFER
302
*
303
        LDA  TRACK
304
        LDB  SECTOR
305
        INCB
306
        STA  TRACK
307
        STB  SECTOR
308
*
309
        LBSR XREAD
310
        LBCS UXERR
311
        LBSR XACK
312
        LBSR XREAD
313
        LBCS UXERR
314
*
315
        LDX  #BUFFER
316
        LDA  TRACK
317
        LDB  SECTOR
318
        LBSR WRITSC
319
*
320
        LBSR XACK
321
*
322
* Sector 3 - SIR
323
*
324
        LDX  #BUFFER
325
*
326
        LDA  TRACK
327
        LDB  SECTOR
328
        INCB
329
        STA  TRACK
330
        STB  SECTOR
331
*
332
        LBSR XREAD
333
        LBCS UXERR
334
        LBSR XACK
335
        LBSR XREAD
336
        LBCS UXERR
337
*
338
        LDX  #BUFFER
339
        LDA  38,X
340
        INCA
341
        STA  MAXTRK
342
        LDB  39,X
343
        INCB
344
        STB  MAXSEC
345
        LDA  TRACK
346
        LDB  SECTOR
347
        LBSR WRITSC
348
*
349
        LBSR XACK
350
*
351
* Sector 4 to Last Track & Sector
352
*
353
*
354
        LDA  TRACK
355
        LDB  SECTOR
356
        INCB
357
*
358
UXLOOP  LDX  #BUFFER
359
        STA  TRACK
360
        STB  SECTOR
361
*
362
        LBSR XREAD
363
        LBCS UXERR
364
        LBSR XACK
365
        LBSR XREAD
366
        LBCS UXERR
367
*
368
        LDX  #BUFFER
369
        LDA  TRACK
370
        LDB  SECTOR
371
        LBSR WRITSC
372
        LBSR XACK
373
*
374
        LDA  TRACK
375
        LDB  SECTOR
376
        INCB
377
        CMPB MAXSEC
378
        BNE  UXLOOP
379
        LDB  #1
380
        INCA
381
        CMPA MAXTRK
382
        BNE  UXLOOP
383
*
384
*
385
*  Write Boot sector
386
*
387
        LDX  #$C000
388
        CLRA         TRACK 0
389
        LDB  #$01    SECTOR 1
390
        STA  TRACK
391
        STB  SECTOR
392
        LBSR WRITSC
393
*
394
UXEXIT  LDX  #UXMES1
395
        JMP  PDATA1
396
*
397
UXERR   LDX  #UXMES2
398
        LBRA PDATA1
399
*
400
* Get a Byte using XModem protocol
401
* Carry clear => no errors
402
* Carry set   => errors
403
*
404
XREAD   PSHS U
405
        LDU  XSTATE
406
*
407
XBYTE0  LBSR INTER
408
        BVC  XBYTE1
409
        LDA  #NAK
410
        LBSR OUTTER
411
        LDU  #XSTST
412
        BRA  XBYTE0
413
*
414
XBYTE1  JSR  ,U
415
        BNE  XBYTE0
416
        STU  XSTATE
417
        PULS U,PC
418
*
419
* START - LOOK FOR SOH (START OF HEADER) = $01
420
*
421
XSTST   CMPA #SOH
422
        BNE  XSTST1
423
        LDU  #XSTBL
424
        ANDCC #$FF-CFLAG-ZFLAG No abort, no valid data (no exit)
425
        RTS
426
*
427
XSTST1  CMPA #EOT
428
        BNE  XSTST2
429
        LDA  #ACK
430
        LBSR OUTTER
431
        ORCC  #CFLAG+ZFLAG  Set (c)=1 abort & exit
432
        RTS
433
*
434
XSTST2  CMPA #CAN
435
        BNE  XSTST3
436
        ORCC  #CFLAG+ZFLAG  Set (c)=1 abort & exit
437
        RTS
438
*
439
XSTST3  ANDCC #$FF-CFLAG-ZFLAG
440
        RTS
441
*
442
* Got SOH
443
* Now get block number
444
*
445
XSTBL   CMPA BLKNUM
446
        BNE  XSTBLE
447
        LDU  #XSTCOM
448
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
449
        RTS
450
*
451
* Error in block number
452
*
453
XSTBLE  LDA  #NAK
454
        LBSR OUTTER
455
        LDU  #XSTST
456
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
457
        RTS
458
*
459
* Get complement of block number
460
*
461
XSTCOM  COMA
462
        CMPA BLKNUM
463
        BNE  XSTBLE
464
        CLR  CHKSUM
465
        LDA  #128
466
        STA  BYTCNT
467
        LDU  #XSTDA
468
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
469
        RTS
470
*
471
* Get data bytes
472
*
473
XSTDA   PSHS A
474
        ADDA CHKSUM
475
        STA  CHKSUM
476
        PULS A
477
        DEC  BYTCNT
478
        BNE  XSTDA1
479
        LDU  #XSTCK
480
XSTDA1  STA  ,X+
481
        ANDCC #$FF-CFLAG-ZFLAG No abort, no valid data (no exit)
482
        RTS
483
*
484
* Byte count reached zero
485
* Check checksum byte
486
*
487
XSTCK   CMPA CHKSUM
488
        BNE  XSTCK1 retry if wrong checksum
489
*
490
* Checksum OK ...
491
* increment block number
492
* Don't send ACK until data written to CF
493
*
494
        INC  BLKNUM
495
        LDU  #XSTST
496
        ANDCC #$FF-CFLAG No abort
497
        ORCC #ZFLAG      Valid data (exit)
498
        RTS
499
*
500
* Checksum Error detected ...
501
* Reset Sector counter in ACCB to last 128 byte boundary
502
* and send NAK
503
*
504
XSTCK1  PSHS B
505
        TFR  X,D
506
        DECB
507
        ANDB #128
508
        TFR  D,X
509
        PULS B
510
        LDA  #NAK
511
XSTCK2  LBSR OUTTER
512
        LDU  #XSTST
513
        ANDCC #$FF-CFLAG-ZFLAG No abort, no valid data (no exit)
514
        RTS
515
*
516
* Acknowledge Data Received
517
*
518
XACK    PSHS A
519
        LDA  #ACK
520
        LBSR OUTTER
521
        PULS A,PC
522
*
523
*
524
** FLEX 9 IDE DISK DRIVERS
525
*
526
* FOR SYS09BUG 1.2 ON THE XSA-3S1000
527
* WITH I/O MAPPED AT $XE000
528
* AND ROM MAPPED AT $XF000
529
*
530
*
531
IMASK  EQU $10     IRQ MASK CC
532
FMASK  EQU $40     FIRQ MASK CC
533
*
534
CF_BASE    EQU $E100
535
CF_DATA    EQU CF_BASE+0
536
CF_ERROR   EQU CF_BASE+2 ; read error
537
CF_FEATURE EQU CF_BASE+2 ; write feature
538
CF_SCNT    EQU CF_BASE+4
539
CF_SNUM    EQU CF_BASE+6
540
CF_CLO     EQU CF_BASE+8
541
CF_CHI     EQU CF_BASE+10
542
CF_HEAD    EQU CF_BASE+12
543
CF_STATUS  EQU CF_BASE+14 ; read status
544
CF_COMAND  EQU CF_BASE+14 ; write command
545
CF_AUX     EQU CF_BASE+30
546
*
547
* Command Equates
548
*
549
CMDREAD    EQU $20 ; Read Single sector
550
CMDWRITE   EQU $30 ; Write Single sector
551
AUXRESET   EQU $06
552
AUXRSTREL  EQU $02
553
HEADLBA    EQU $E0
554
*
555
* Status bit equates
556
*
557
BSY        EQU $80
558
DRDY       EQU $40
559
DRQ        EQU $08
560
ERR        EQU $01
561
*
562
*
563
* INITIALIZE CF CARD FOR 8 BIT LBA MODE
564
*
565
INITDR LDD #AUXRESET
566
       STD CF_AUX
567
       LDD #AUXRSTREL
568
       STD CF_AUX
569
       LDD  #HEADLBA
570
       STD  CF_HEAD
571
       BRA WAITRDY
572
*
573
* RESTORE DISK DRIVER (SEEK TRACK 00)
574
*
575
RESTR1 BSR   DRVSEL
576
       CLRA           ; Track 0
577
       LDB   #$01     ; Sector 1
578
*
579
* Seek track and sector
580
* A holds track number (0 - ??)
581
* B holds sector number (1 - ??)
582
* Sector numbers starts from 1
583
* subtract 1 to start from sector 0 on CF
584
*
585
SEEKTS PSHS A
586
       CLRA
587
       DECB
588
       STD  CF_SNUM
589
       LDB ,S
590
       STD  CF_CLO
591
       LDB  DRVNUM
592
       STD  CF_CHI
593
       LDB  #$01
594
       STD  CF_SCNT
595
       CLRB
596
       PULS A,PC
597
*
598
* READ SECTORS FROM CF
599
*
600
*
601
READSC BSR  SEEKTS
602
       LDD  #CMDREAD ; IDE READ MULTIPLE
603
       STD  CF_COMAND
604
       BSR  WAITRDY
605
*
606
* READ LOOP
607
*
608
       PSHS Y
609
       LDY #256
610
RDLP1  BSR  WAITDRQ
611
       LDD  CF_DATA
612
       STB  ,X+
613
       LEAY -1,Y
614
       BNE  RDLP1
615
       PULS Y
616
*
617
       BSR  WAITRDY
618
       CLRB
619
       RTS
620
*
621
* WRITE SECTOR TO CF
622
*
623
WRITSC BSR  SEEKTS   ; SEEK TRACK & SECTOR
624
       LDD  #CMDWRITE ; IDE WRITE MULTIPLE
625
       STD  CF_COMAND
626
       BSR  WAITRDY
627
*
628
* WRITE LOOP
629
*
630
       PSHS Y
631
       LDY #256
632
       CLRA
633
WRTLP1 BSR  WAITDRQ
634
       LDB  ,X+
635
       STD  CF_DATA
636
       LEAY -1,Y
637
       BNE  WRTLP1
638
       PULS Y
639
*
640
       BSR  WAITRDY
641
       CLRB
642
       RTS
643
*
644
* CHECK FOR BUSY
645
* Doubles as VERIFY
646
*
647
BUSY   CLRB            Never busy
648
       RTS
649
*
650
* DRIVE SELECT DISK DRIVER
651
*
652
DRVSEL LDA   3,X       GET DRIVE # FROM FCB
653
       CMPA  #3
654
       BLS   DRVS2     IF > 3, SET IT TO 0
655
       CLRA
656
DRVS2  STA   DRVNUM
657
       CLRB            ; SET Z, CLEAR C
658
       RTS
659
*
660
* CHECK DRIVE READY DISK DRIVER
661
*
662
CHKDRV LDA  3,X
663
       CLRB             ; CLEAR C, SET Z
664
       RTS
665
*
666
* WAIT UNTIL READY
667
*
668
WAITRDY LDD  CF_STATUS
669
        BITB #BSY
670
        BNE  WAITRDY
671
        LDD  CF_STATUS
672
        BITB #DRDY
673
        BEQ  WAITRDY
674
        RTS
675
*
676
* WAIT FOR DATA REQUEST
677
*
678
WAITDRQ LDD  CF_STATUS
679
        BITB #DRQ
680
        BEQ  WAITDRQ
681
        RTS
682
*
683
*******************************************************
684
*
685
* Bootstrap FLEX Loader
686
*
687
* SBUG1.8 loads the bootstap loader at $C000
688
* however the Flex adaption manual has the
689
* bootstrap loader residing at $C100
690
*
691
******************************************************
692
*
693
* Equates
694
*
695
STACK   EQU $C0FF
696
SCTBUF  EQU $C300
697
*
698
* Start of Utility
699
*
700
        ORG $C000
701
BOOT    BRA LOAD0
702
        FCB 0,0,0
703
TRK     FCB 0        File start track
704
SCT     FCB 0        File start sector
705
DNS     FCB 0        Density Flag (not used)
706
TADR    FDB $C000    Transfer address
707
LADR    FDB 0        Load Address
708
DRNUM   FCB 0        Drive number 0
709
*
710
LOAD0   LDS  #STACK   Set up stack
711
        LDD  TRK      Set up start track and sector
712
        STD  SCTBUF
713
        LDY  #SCTBUF+256
714
*
715
* Perform actual file load
716
*
717
LOAD1   BSR GETCH    Get acharcater
718
        CMPA #$02    Data record hearder ?
719
        BEQ  LOAD2   Skip, is so
720
        CMPA #$16    Xfr address hearder ?
721
        BNE LOAD1    Loop if neither
722
*
723
* Get transfer address
724
*
725
        BSR  GETCH
726
        STA  TADR
727
        BSR  GETCH
728
        STA  TADR+1
729
        BRA  LOAD1
730
*
731
* Load data record
732
*
733
LOAD2  BSR  GETCH  Get load address
734
       STA  LADR
735
       BSR  GETCH
736
       STA  LADR+1
737
       BSR  GETCH  Get Bytes count
738
       TFR  A,B
739
       TSTB
740
       BEQ  LOAD1 Loop if count = 0
741
       LDX  LADR  Get load address
742
LOAD3  PSHS B,X
743
       BSR  GETCH  Get data character
744
       PULS B,X
745
       STA  ,X+    Store at load address
746
       DECB
747
       BNE  LOAD3  Loop until count = 0
748
       BRA  LOAD1
749
*
750
* Get Character routine
751
* Reads a sector if needed
752
*
753
GETCH  CMPY #SCTBUF+256 out of data ?
754
       BNE  GETCH4      Go read Character if not
755
GETCH2 LDX  #SCTBUF     Point to buffer
756
       LDD  0,X         Get forward Link
757
       BEQ  GO          if zero, file is loaded
758
       BSR  READ        Read next sector
759
       BNE  BOOT        start over if error
760
       LDY  #SCTBUF+4   Point past link
761
GETCH4 LDA  ,Y+         Else, get a character
762
       RTS
763
*
764
* File is loaded, Jump to it
765
*
766
GO     JMP  [TADR]      Jump to transfer address
767
 
768
*
769
** FLEX 9 IDE DISK DRIVERS
770
*
771
* FOR SYS09BUG 1.2 ON THE XSA-3S1000
772
* WITH I/O MAPPED AT $XE000
773
* AND ROM MAPPED AT $XF000
774
*
775
*IMASK  EQU $10     IRQ MASK CC
776
*FMASK  EQU $40     FIRQ MASK CC
777
*
778
*CF_BASE    EQU $E100
779
*CF_DATA    EQU CF_BASE+0
780
*CF_ERROR   EQU CF_BASE+2 ; read error
781
*CF_FEATURE EQU CF_BASE+2 ; write feature
782
*CF_SCNT  EQU CF_BASE+4
783
*CF_SNUM  EQU CF_BASE+6
784
*CF_CLO   EQU CF_BASE+8
785
*CF_CHI   EQU CF_BASE+10
786
*CF_HEAD    EQU CF_BASE+12
787
*CF_STATUS  EQU CF_BASE+14 ; read status
788
*CF_COMAND  EQU CF_BASE+14 ; write command
789
*CF_AUX     EQU CF_BASE+30
790
*
791
* Command Equates
792
*
793
*CMDREAD    EQU $20 ; Read Single sector
794
*CMDWRITE   EQU $30 ; Write Single sector
795
*HEADLBA    EQU $E0
796
*AUXRESET   EQU $06
797
*AUXRSTREL  EQU $02
798
*
799
* Status bit equates
800
*
801
*BSY        EQU $80
802
*DRDY       EQU $40
803
*DRQ        EQU $08
804
*ERR        EQU $01
805
*
806
* Seek track and sector
807
* A holds track number (0 - ??)
808
* B holds sector number (1 - ??)
809
* Sector numbers starts from 1
810
* subtract 1 to start from sector 0 on CF
811
*
812
SEEK   PSHS A
813
       CLRA
814
       DECB
815
       STD  CF_SNUM
816
       LDB  ,S
817
       STD  CF_CLO
818
       LDB  DRNUM
819
       STD  CF_CHI
820
       LDB  #$01
821
       STD  CF_SCNT
822
       CLRB
823
       PULS A,PC
824
*
825
* READ SECTORS FROM CF
826
*
827
*
828
READ   BSR  SEEK
829
       LDD  #CMDREAD ; IDE READ MULTIPLE
830
       STD  CF_COMAND
831
       BSR  WTRDY
832
*
833
* READ LOOP
834
*
835
       PSHS Y
836
       LDY #256
837
READ1  BSR  WTDRQ
838
       LDD  CF_DATA
839
       STB  ,X+
840
       LEAY -1,Y
841
       BNE  READ1
842
       PULS Y
843
*
844
       BSR  WTRDY
845
       CLRB
846
       RTS
847
*
848
* WAIT UNTIL READY
849
*
850
WTRDY   LDD  CF_STATUS
851
        BITB #BSY
852
        BNE  WTRDY
853
        LDD  CF_STATUS
854
        BITB #DRDY
855
        BEQ  WTRDY
856
        RTS
857
*
858
* WAIT FOR DATA REQUEST
859
*
860
WTDRQ   LDD  CF_STATUS
861
        BITB #DRQ
862
        BEQ  WTDRQ
863
        RTS
864
*
865
       END START

powered by: WebSVN 2.1.0

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