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

Subversion Repositories System09

[/] [System09/] [trunk/] [src/] [fmt/] [fmt_ide.asm] - Blame information for rev 147

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  UFSUB
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
** 'UF' Format IDE Drive to FLEX standard.
119
*
120
DISFOS  FCB $0A,$0D
121
        FCC 'Formating IDE disk... '
122
        FCB $0A,$0D
123
        FCC 'Drive Number ?'
124
        FCB 4
125
MESS6   FCB $0A,$0D,4
126
        FCC 'IDE drive not allocated! '
127
        FCB 4
128
UFMSG1  FCB $0A,$0D
129
        FCC 'Format Complete'
130
        FCB 4
131
*
132
UFSUB   JSR  INITDR
133
        LDX #DISFOS
134
        JSR PDATA1
135
UFSUB1  LBSR RCHAR
136
        BCC  UFSUB1
137
        LBSR SCHAR
138
        CMPA #'0'
139
        LBLO UFEXIT
140
        CMPA #'3'
141
        LBHI  UFEXIT
142
        SUBA #'0'
143
        TFR  A,B
144
        STB DRVNUM
145
        LDX #DRVNUM-3
146
        JSR DRVSEL
147
*
148
* set up free chain
149
*
150
        LDX #BUFFER clear out buffer
151
        CLRA
152
        CLRB
153
DFL1    STA 0,X+
154
        DECB
155
        BNE DFL1
156
*
157
        CLR TRACK
158
        LDA #1
159
        STA SECTOR
160
DFL2    LDX #BUFFER
161
        LDA TRACK
162
        STA 0,X
163
        LDA SECTOR
164
        INCA
165
        CMPA #RMAXSEC+1 last sector on track?
166
        BNE DFL3
167
        INC 0,X
168
        LDA #1
169
DFL3    STA 1,X
170
        LDA TRACK
171
        LDB SECTOR
172
        JSR WRITSC
173
        INC SECTOR
174
        LDA SECTOR
175
        CMPA #RMAXSEC+1
176
        BNE DFL2
177
        LDA #1
178
        STA  SECTOR
179
        INC TRACK
180
        LDA TRACK
181
        CMPA #RMAXTRK
182
        BNE DFL2
183
* break free chain at last track/sector
184
        LDX  #BUFFER
185
        LDA  #RMAXTRK-1
186
        LDB  #RMAXSEC
187
        JSR  READSC
188
        LDX  #BUFFER
189
        CLR  0,X
190
        CLR  1,X
191
        LDA  #RMAXTRK-1
192
        LDB  #RMAXSEC
193
        JSR  WRITSC
194
* set up sector structure, SIR, directory etc
195
        LDX  #BUFFER
196
        CLRA
197
        LDB  #RMAXSEC
198
        JSR  READSC
199
        LDX  #BUFFER
200
        CLR  0,X break end of directory chain
201
        CLR  1,X
202
        CLRA
203
        LDB  #RMAXSEC
204
        JSR  WRITSC
205
*
206
        LDX  #BUFFER
207
        CLRA
208
        LDB  #3 set up SIR
209
        JSR  READSC
210
        LDX  #BUFFER
211
        CLR  0,X break forward link
212
        CLR  1,X
213
        LDD  #$5241 set volume name (RAMDISK )
214
        STD  16,X
215
        LDD  #$4D44
216
        STD  18,X
217
        LDD  #$4953
218
        STD  20,X
219
        LDD  #$4B20
220
        STD  22,X
221
        LDD  #1 volume number
222
        STD  27,X
223
        LDD  #$0101 first trk/sec  01-01
224
        STD  29,X
225
        LDA  #RMAXTRK-1
226
        LDB  #RMAXSEC
227
        STD  31,X
228
        STD  38,X
229
        LDD  #RTOTSEC total DATA sectors (2912-14)
230
        STD  33,X
231
*
232
        LDA #01 month   set default creation date (SYS09's birthday!)
233
        STA 35,X
234
        LDA #07 day
235
        STA 36,X
236
        LDA #07 year
237
        STA 37,X
238
*
239
RF3     CLRA
240
        LDB  #3
241
        JSR  WRITSC
242
*
243
* Not sure what this is about
244
* put bootstrap on track 0 sector 1
245
*
246
*        LDX #BUFFER
247
*        CLRA
248
*        LDB #1
249
*        JSR READSC
250
*        LDX #BUFFER
251
*        LDA #$AA set the init flag
252
*        STA 0,X
253
*        LDA  #$55
254
*        STA 1,X
255
*        CLRA
256
*        LDB #1
257
*        JSR WRITSC
258
*
259
*  Write Boot sector
260
*
261
        LDX  #$C000
262
        CLRA         TRACK 0
263
        LDB  #$01    SECTOR 1
264
        STA  TRACK
265
        STB  SECTOR
266
        LBSR WRITSC
267
*
268
UFEXIT  LDX #UFMSG1
269
        JMP PDATA1
270
*
271
* Read a byte from the serial port
272
*
273
LRBYTE  PSHS B
274
        BSR  LRHEX                  Get hex digit.
275
        ASLA
276
        ASLA                           Shift to msb.
277
        ASLA
278
        ASLA
279
        TFR  A,B                    Save in B.
280
        BSR  LRHEX                  Get next digit.
281
        PSHS B
282
        ADDA 0,S+                    Add together bytes.
283
        PULS B,PC
284
*
285
LRHEX   JSR  INTER
286
        BVS  LRHEX
287
        SUBA #$30                   Remove ascii bias.
288
        BMI  LRHEX
289
        CMPA #$09                   Number?
290
        BLE  LRHEX1                 Yes.
291
        CMPA #$11                   Keep testing.
292
        BMI  LRHEX
293
        CMPA #$16
294
        BGT  LRHEX
295
        SUBA #$07
296
LRHEX1  RTS
297
*
298
* ACIA INPUT TEST
299
*
300
INTEST  LDA ACIAC1
301
        BITA #$01
302
        RTS
303
*
304
* RESET ACIA
305
*
306
ACIRST  LDA #$03 master reset
307
        STA  ACIAC1
308
        LDA #$11
309
        STA ACIAC1
310
        RTS
311
*
312
* ACIA INPUT
313
*
314
INTER   LDA  #16
315
        STA  DELCNT+0
316
        CLR  DELCNT+1
317
        CLR  DELCNT+2
318
INTER0  LDA  ACIAC1
319
        BITA #$01
320
        BNE  INTER1
321
        BITA #$78
322
        BEQ  INTER2
323
        BSR  ACIRST
324
        BRA  INTER
325
*
326
INTER1  LDA  ACIAD1
327
        ANDCC #VFLAG
328
        RTS
329
*
330
INTER2  DEC  DELCNT+2
331
        BNE  INTER0
332
        DEC  DELCNT+1
333
        BNE  INTER0
334
        DEC  DELCNT+0
335
        BNE  INTER0
336
        CLRA
337
        ORCC #VFLAG
338
        RTS
339
*
340
* ACIA OUTPUT
341
*
342
OUTTER  PSHS A
343
*
344
OUTTE1  LDA ACIAC1
345
        BITA #$02
346
        BNE  OUTTE2
347
        BITA #$78
348
        BEQ  OUTTE1
349
        BSR  ACIRST
350
        BRA  OUTTE1
351
*
352
OUTTE2  PULS A
353
        STA ACIAD1
354
        RTS
355
*
356
* Print Data
357
*
358
PDATA0  BSR  OUTTER
359
PDATA1  LDA  ,X+
360
        CMPA #$04
361
        BNE  PDATA0
362
        RTS
363
*
364
** FLEX 9 IDE DISK DRIVERS
365
*
366
* FOR SYS09BUG 1.2 ON THE XSA-3S1000
367
* WITH I/O MAPPED AT $XE000
368
* AND ROM MAPPED AT $XF000
369
*
370
*
371
IMASK  EQU $10     IRQ MASK CC
372
FMASK  EQU $40     FIRQ MASK CC
373
*
374
CF_BASE    EQU $E100
375
CF_DATA    EQU CF_BASE+0
376
CF_ERROR   EQU CF_BASE+2 ; read error
377
CF_FEATURE EQU CF_BASE+2 ; write feature
378
CF_SCNT    EQU CF_BASE+4
379
CF_SNUM    EQU CF_BASE+6
380
CF_CLO     EQU CF_BASE+8
381
CF_CHI     EQU CF_BASE+10
382
CF_HEAD    EQU CF_BASE+12
383
CF_STATUS  EQU CF_BASE+14 ; read status
384
CF_COMAND  EQU CF_BASE+14 ; write command
385
CF_AUX     EQU CF_BASE+30
386
*
387
* Command Equates
388
*
389
CMDREAD    EQU $20 ; Read Single sector
390
CMDWRITE   EQU $30 ; Write Single sector
391
AUXRESET   EQU $06
392
AUXRSTREL  EQU $02
393
HEADLBA    EQU $E0
394
*
395
* Status bit equates
396
*
397
BSY        EQU $80
398
DRDY       EQU $40
399
DRQ        EQU $08
400
ERR        EQU $01
401
*
402
*
403
* INITIALIZE CF CARD FOR 8 BIT LBA MODE
404
*
405
INITDR LDD #AUXRESET
406
       STD CF_AUX
407
       LDD #AUXRSTREL
408
       STD CF_AUX
409
       LDD  #HEADLBA
410
       STD  CF_HEAD
411
       BRA WAITRDY
412
*
413
* RESTORE DISK DRIVER (SEEK TRACK 00)
414
*
415
RESTR1 BSR   DRVSEL
416
       CLRA           ; Track 0
417
       LDB   #$01     ; Sector 1
418
*
419
* Seek track and sector
420
* A holds track number (0 - ??)
421
* B holds sector number (1 - ??)
422
* Sector numbers starts from 1
423
* subtract 1 to start from sector 0 on CF
424
*
425
SEEKTS PSHS A
426
       CLRA
427
       DECB
428
       STD  CF_SNUM
429
       LDB ,S
430
       STD  CF_CLO
431
       LDB  DRVNUM
432
       STD  CF_CHI
433
       LDB  #$01
434
       STD  CF_SCNT
435
       CLRB
436
       PULS A,PC
437
*
438
* READ SECTORS FROM CF
439
*
440
*
441
READSC BSR  SEEKTS
442
       LDD  #CMDREAD ; IDE READ MULTIPLE
443
       STD  CF_COMAND
444
       BSR  WAITRDY
445
*
446
* READ LOOP
447
*
448
       PSHS Y
449
       LDY #256
450
RDLP1  BSR  WAITDRQ
451
       LDD  CF_DATA
452
       STB  ,X+
453
       LEAY -1,Y
454
       BNE  RDLP1
455
       PULS Y
456
*
457
       BSR  WAITRDY
458
       CLRB
459
       RTS
460
*
461
* WRITE SECTOR TO CF
462
*
463
WRITSC BSR  SEEKTS   ; SEEK TRACK & SECTOR
464
       LDD  #CMDWRITE ; IDE WRITE MULTIPLE
465
       STD  CF_COMAND
466
       BSR  WAITRDY
467
*
468
* WRITE LOOP
469
*
470
       PSHS Y
471
       LDY #256
472
       CLRA
473
WRTLP1 BSR  WAITDRQ
474
       LDB  ,X+
475
       STD  CF_DATA
476
       LEAY -1,Y
477
       BNE  WRTLP1
478
       PULS Y
479
*
480
       BSR  WAITRDY
481
       CLRB
482
       RTS
483
*
484
* CHECK FOR BUSY
485
* Doubles as VERIFY
486
*
487
BUSY   CLRB            Never busy
488
       RTS
489
*
490
* DRIVE SELECT DISK DRIVER
491
*
492
DRVSEL LDA   3,X       GET DRIVE # FROM FCB
493
       CMPA  #3
494
       BLS   DRVS2     IF > 3, SET IT TO 0
495
       CLRA
496
DRVS2  STA   DRVNUM
497
       CLRB            ; SET Z, CLEAR C
498
       RTS
499
*
500
* CHECK DRIVE READY DISK DRIVER
501
*
502
CHKDRV LDA  3,X
503
       CLRB             ; CLEAR C, SET Z
504
       RTS
505
*
506
* WAIT UNTIL READY
507
*
508
WAITRDY LDD  CF_STATUS
509
        BITB #BSY
510
        BNE  WAITRDY
511
        LDD  CF_STATUS
512
        BITB #DRDY
513
        BEQ  WAITRDY
514
        RTS
515
*
516
* WAIT FOR DATA REQUEST
517
*
518
WAITDRQ LDD  CF_STATUS
519
        BITB #DRQ
520
        BEQ  WAITDRQ
521
        RTS
522
*
523
*******************************************************
524
*
525
* Bootstrap FLEX Loader
526
*
527
* SBUG1.8 loads the bootstap loader at $C000
528
* however the Flex adaption manual has the
529
* bootstrap loader residing at $C100
530
*
531
******************************************************
532
*
533
* Equates
534
*
535
STACK   EQU $C0FF
536
SCTBUF  EQU $C300
537
*
538
* Start of Utility
539
*
540
        ORG $C000
541
BOOT    BRA LOAD0
542
        FCB 0,0,0
543
TRK     FCB 0        File start track
544
SCT     FCB 0        File start sector
545
DNS     FCB 0        Density Flag (not used)
546
TADR    FDB $C000    Transfer address
547
LADR    FDB 0        Load Address
548
DRNUM   FCB 0        Drive number 0
549
*
550
LOAD0   LDS  #STACK   Set up stack
551
        LDD  TRK      Set up start track and sector
552
        STD  SCTBUF
553
        LDY  #SCTBUF+256
554
*
555
* Perform actual file load
556
*
557
LOAD1   BSR GETCH    Get acharcater
558
        CMPA #$02    Data record hearder ?
559
        BEQ  LOAD2   Skip, is so
560
        CMPA #$16    Xfr address hearder ?
561
        BNE LOAD1    Loop if neither
562
*
563
* Get transfer address
564
*
565
        BSR  GETCH
566
        STA  TADR
567
        BSR  GETCH
568
        STA  TADR+1
569
        BRA  LOAD1
570
*
571
* Load data record
572
*
573
LOAD2  BSR  GETCH  Get load address
574
       STA  LADR
575
       BSR  GETCH
576
       STA  LADR+1
577
       BSR  GETCH  Get Bytes count
578
       TFR  A,B
579
       TSTB
580
       BEQ  LOAD1 Loop if count = 0
581
       LDX  LADR  Get load address
582
LOAD3  PSHS B,X
583
       BSR  GETCH  Get data character
584
       PULS B,X
585
       STA  ,X+    Store at load address
586
       DECB
587
       BNE  LOAD3  Loop until count = 0
588
       BRA  LOAD1
589
*
590
* Get Character routine
591
* Reads a sector if needed
592
*
593
GETCH  CMPY #SCTBUF+256 out of data ?
594
       BNE  GETCH4      Go read Character if not
595
GETCH2 LDX  #SCTBUF     Point to buffer
596
       LDD  0,X         Get forward Link
597
       BEQ  GO          if zero, file is loaded
598
       BSR  READ        Read next sector
599
       BNE  BOOT        start over if error
600
       LDY  #SCTBUF+4   Point past link
601
GETCH4 LDA  ,Y+         Else, get a character
602
       RTS
603
*
604
* File is loaded, Jump to it
605
*
606
GO     JMP  [TADR]      Jump to transfer address
607
 
608
*
609
** FLEX 9 IDE DISK DRIVERS
610
*
611
* FOR SYS09BUG 1.2 ON THE XSA-3S1000
612
* WITH I/O MAPPED AT $XE000
613
* AND ROM MAPPED AT $XF000
614
*
615
*IMASK  EQU $10     IRQ MASK CC
616
*FMASK  EQU $40     FIRQ MASK CC
617
*
618
*CF_BASE    EQU $E100
619
*CF_DATA    EQU CF_BASE+0
620
*CF_ERROR   EQU CF_BASE+2 ; read error
621
*CF_FEATURE EQU CF_BASE+2 ; write feature
622
*CF_SCNT  EQU CF_BASE+4
623
*CF_SNUM  EQU CF_BASE+6
624
*CF_CLO   EQU CF_BASE+8
625
*CF_CHI   EQU CF_BASE+10
626
*CF_HEAD    EQU CF_BASE+12
627
*CF_STATUS  EQU CF_BASE+14 ; read status
628
*CF_COMAND  EQU CF_BASE+14 ; write command
629
*CF_AUX     EQU CF_BASE+30
630
*
631
* Command Equates
632
*
633
*CMDREAD    EQU $20 ; Read Single sector
634
*CMDWRITE   EQU $30 ; Write Single sector
635
*HEADLBA    EQU $E0
636
*AUXRESET   EQU $06
637
*AUXRSTREL  EQU $02
638
*
639
* Status bit equates
640
*
641
*BSY        EQU $80
642
*DRDY       EQU $40
643
*DRQ        EQU $08
644
*ERR        EQU $01
645
*
646
* Seek track and sector
647
* A holds track number (0 - ??)
648
* B holds sector number (1 - ??)
649
* Sector numbers starts from 1
650
* subtract 1 to start from sector 0 on CF
651
*
652
SEEK   PSHS A
653
       CLRA
654
       DECB
655
       STD  CF_SNUM
656
       LDB  ,S
657
       STD  CF_CLO
658
       LDB  DRNUM
659
       STD  CF_CHI
660
       LDB  #$01
661
       STD  CF_SCNT
662
       CLRB
663
       PULS A,PC
664
*
665
* READ SECTORS FROM CF
666
*
667
*
668
READ   BSR  SEEK
669
       LDD  #CMDREAD ; IDE READ MULTIPLE
670
       STD  CF_COMAND
671
       BSR  WTRDY
672
*
673
* READ LOOP
674
*
675
       PSHS Y
676
       LDY #256
677
READ1  BSR  WTDRQ
678
       LDD  CF_DATA
679
       STB  ,X+
680
       LEAY -1,Y
681
       BNE  READ1
682
       PULS Y
683
*
684
       BSR  WTRDY
685
       CLRB
686
       RTS
687
*
688
* WAIT UNTIL READY
689
*
690
WTRDY   LDD  CF_STATUS
691
        BITB #BSY
692
        BNE  WTRDY
693
        LDD  CF_STATUS
694
        BITB #DRDY
695
        BEQ  WTRDY
696
        RTS
697
*
698
* WAIT FOR DATA REQUEST
699
*
700
WTDRQ   LDD  CF_STATUS
701
        BITB #DRQ
702
        BEQ  WTDRQ
703
        RTS
704
*
705
       END START

powered by: WebSVN 2.1.0

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