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

Subversion Repositories System09

[/] [System09/] [rev_86/] [src/] [fmt/] [fmt_cf8.asm] - Blame information for rev 161

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

Line No. Rev Author Line
1 59 davidgb
*
2
** FLEX 9 COMPACT FLASH FORMAT PROGRAM
3
*
4
* FOR B5-X300 and CF with 8 Bit Transfer interface
5
*
6
*
7
CFLAG   EQU $01     CARRY FLAG
8
VFLAG   EQU $02     OVERFLOW FLAG
9
ZFLAG   EQU $04     ZERO FLAG
10
NFLAG   EQU $08     NEGATIVE FLAG
11
IFLAG   EQU $10     IRQ MASK CC
12
HFLAG   EQU $20     HALF CARRY
13
FFLAG   EQU $40     FIRQ MASK CC
14
EFLAG   EQU $80     ENTIRE FLAG
15
*
16
MAPPAG  EQU $00     PAGE $0000 DAT ADDRESS
17
*
18
* Serial Port
19
*
20
ACIAS   EQU $E000
21
ACIAC1  EQU ACIAS
22
ACIAD1  EQU ACIAS+1
23
DELCON  EQU 1250    Delay (Processor clock in MHz * 50)
24
*
25
* XMODEM Control characters
26
*
27
SOH     EQU $01
28
EOT     EQU $04
29
ACK     EQU $06
30
NAK     EQU $15
31
CAN     EQU $18
32
*
33
* Some dummy Constants
34
*
35
RMAXTRK EQU 64
36
RMAXSEC EQU 255
37
RTOTSEC EQU RMAXTRK*RMAXSEC-RMAXSEC
38
*
39
* Start
40
*
41
        ORG $0100
42
START   LBSR  UFSUB
43
        JMP  [$F800]  Jump to monitor on Completion.
44
*
45
*
46
* RAM SPACE
47
*
48
DRVNUM  FCB  0
49
TRACK   FCB  0
50
SECTOR  FCB  0
51
CHKSUM  FCB  0
52
BLKNUM  FCB  0 Xmodem block number
53
BYTCNT  FCB  0 Xmodem byte count
54
XSTATE  FDB  0 Xmodem State Vector
55
DELCNT  FCB  $00,$00,$00 Xmodem Poll timer
56
MAXTRK  FCB  0
57
MAXSEC  FCB  0
58
        ORG  $0200
59
*
60
* SECTOR BUFFER
61
*
62
BUFFER  RMB  256
63
*
64
*
65
* recieve char from remote drive.
66
* timeout if no response for approx 1s.
67
* Entry: no parameters
68
* Exit:  (A) = recieved char, (C)=1 if valid char, (C)=0 if timeout.
69
*
70
RCHAR   PSHS    X,Y
71
*
72
        LDX     #1000         1000x inner loop
73
RCHAR1  LDY     #DELCON       delay constant for inner loop (approx 1ms).
74
RCHAR2  LDA     ACIAC1        test for recieved char
75
        ASRA
76
        BCS     RCHAR3        get character
77
        LEAY    -1,Y          else, continue to count delay
78
        BNE     RCHAR2
79
        LEAX    -1,X
80
        BNE     RCHAR1
81
        PULS    X,Y,PC        return with error if timed out
82
*
83
RCHAR3  LDA     ACIAD1        return data (carry bit still set)
84
        PULS    X,Y,PC
85
*
86
*
87
* transmit char to remote drive.
88
* timeout if no response for approx 1s. (allows for use of hardware flow control)
89
* Entry: (A) = char to transmit
90
* Exit:  (A) = recieved char, (C)=1 if valid char, (C)=0 if timeout.
91
*
92
SCHAR   PSHS    X,Y
93
        PSHS    A
94
*
95
        LDX     #1000         1000x inner loop
96
SCHAR1  LDY     #DELCON       delay constant for inner loop (approx 1ms).
97
SCHAR2  LDA     ACIAC1        test for space in transmit FIFO
98
        ASRA
99
        ASRA
100
        BCS     SCHAR3        send character
101
        LEAY    -1,Y          else, continue to count delay
102
        BNE     SCHAR2
103
        LEAX    -1,X
104
        BNE     SCHAR1
105
        PULS    A
106
        PULS    X,Y,PC        return with error if timed out
107
*
108
SCHAR3  PULS    A
109
        STA     ACIAD1        send data (carry bit still set)
110
        PULS    X,Y,PC
111
*
112
* Print Data
113
*
114
PDATA0  BSR  SCHAR
115
PDATA1  LDA  ,X+
116
        CMPA #$04
117
        BNE  PDATA0
118
        RTS
119
*
120
** 'UF' Format RAMdisc to FLEX standard.
121
*
122
DISFOS  FCB $0A,$0D
123
        FCC 'Formating RAMdisk... '
124
        FCB $0A,$0D
125
        FCC 'Drive Number ?'
126
        FCB 4
127
MESS6   FCB $0A,$0D,4
128
        FCC 'Ramdisk not allocated! '
129
        FCB 4
130
UFMSG1  FCB $0A,$0D
131
        FCC 'Format Complete'
132
        FCB 4
133
*
134
UFSUB   JSR  INITDR
135
        LDX #DISFOS
136
        JSR PDATA1
137
UFSUB1  LBSR RCHAR
138
        BCC  UFSUB1
139
        LBSR SCHAR
140
        CMPA #'0'
141
        LBLO UFEXIT
142
        CMPA #'3'
143
        LBHI  UFEXIT
144
        SUBA #'0'
145
        TFR  A,B
146
        STB DRVNUM
147
        LDX #DRVNUM-3
148
        JSR DRVSEL
149
*
150
* set up free chain
151
*
152
        LDX #BUFFER clear out buffer
153
        CLRA
154
        CLRB
155
DFL1    STA 0,X+
156
        DECB
157
        BNE DFL1
158
*
159
        CLR TRACK
160
        LDA #1
161
        STA SECTOR
162
DFL2    LDX #BUFFER
163
        LDA TRACK
164
        STA 0,X
165
        LDA SECTOR
166
        INCA
167
        CMPA #RMAXSEC+1 last sector on track?
168
        BNE DFL3
169
        INC 0,X
170
        LDA #1
171
DFL3    STA 1,X
172
        LDA TRACK
173
        LDB SECTOR
174
        JSR WRITSC
175
        INC SECTOR
176
        LDA SECTOR
177
        CMPA #RMAXSEC+1
178
        BNE DFL2
179
        LDA #1
180
        STA  SECTOR
181
        INC TRACK
182
        LDA TRACK
183
        CMPA #RMAXTRK
184
        BNE DFL2
185
* break free chain at last track/sector
186
        LDX  #BUFFER
187
        LDA  #RMAXTRK-1
188
        LDB  #RMAXSEC
189
        JSR  READSC
190
        LDX  #BUFFER
191
        CLR  0,X
192
        CLR  1,X
193
        LDA  #RMAXTRK-1
194
        LDB  #RMAXSEC
195
        JSR  WRITSC
196
* set up sector structure, SIR, directory etc
197
        LDX  #BUFFER
198
        CLRA
199
        LDB  #RMAXSEC
200
        JSR  READSC
201
        LDX  #BUFFER
202
        CLR  0,X break end of directory chain
203
        CLR  1,X
204
        CLRA
205
        LDB  #RMAXSEC
206
        JSR  WRITSC
207
*
208
        LDX  #BUFFER
209
        CLRA
210
        LDB  #3 set up SIR
211
        JSR  READSC
212
        LDX  #BUFFER
213
        CLR  0,X break forward link
214
        CLR  1,X
215
        LDD  #$5241 set volume name (RAMDISK )
216
        STD  16,X
217
        LDD  #$4D44
218
        STD  18,X
219
        LDD  #$4953
220
        STD  20,X
221
        LDD  #$4B20
222
        STD  22,X
223
        LDD  #1 volume number
224
        STD  27,X
225
        LDD  #$0101 first trk/sec  01-01
226
        STD  29,X
227
        LDA  #RMAXTRK-1
228
        LDB  #RMAXSEC
229
        STD  31,X
230
        STD  38,X
231
        LDD  #RTOTSEC total DATA sectors (2912-14)
232
        STD  33,X
233
*
234
        LDA #01 month   set default creation date (SYS09's birthday!)
235
        STA 35,X
236
        LDA #07 day
237
        STA 36,X
238
        LDA #07 year
239
        STA 37,X
240
*
241
RF3     CLRA
242
        LDB  #3
243
        JSR  WRITSC
244
*
245
*        LDX #BUFFER
246
*        CLRA
247
*        LDB #1
248
*        JSR READSC
249
*        LDX #BUFFER
250
*        LDA #$AA set the init flag
251
*        STA 0,X
252
*        LDA  #$55
253
*        STA 1,X
254
*        CLRA
255
*        LDB #1
256
*        JSR WRITSC
257
*
258
*  Write Boot sector
259
*
260
        LDX  #$C000
261
        CLRA         TRACK 0
262
        LDB  #$01    SECTOR 1
263
        STA  TRACK
264
        STB  SECTOR
265
        LBSR WRITSC
266
*
267
UFEXIT  LDX #UFMSG1
268
        JMP PDATA1
269
*
270
*
271
** FLEX 9 COMPACT FLASH DISK DRIVERS
272
*
273
* FOR SYS09BUG 1.2 ON THE BURCHED B5-X300
274
* WITH I/O MAPPED AT $XE000
275
* AND ROM MAPPED AT $XF000
276
* THE BURCHED B5-X300 HAS 256KBYTES OF SRAM
277
* THE FIRST 64K IS USED BY FLEX,
278
* THE SECOND 192K MAY BE USED AS A RAM DISK
279
*
280
*
281
IMASK  EQU $10     IRQ MASK CC
282
FMASK  EQU $40     FIRQ MASK CC
283
DATREG EQU $FFF0   DAT REGISTERS
284
*
285
CF_BASE    EQU $E040
286
CF_DATA    EQU CF_BASE+0
287
CF_ERROR   EQU CF_BASE+1 ; read error
288
CF_FEATURE EQU CF_BASE+1 ; write feature
289
CF_SCNT    EQU CF_BASE+2
290
CF_SNUM    EQU CF_BASE+3
291
CF_CLO     EQU CF_BASE+4
292
CF_CHI     EQU CF_BASE+5
293
CF_HEAD    EQU CF_BASE+6
294
CF_STATUS  EQU CF_BASE+7 ; read status
295
CF_COMAND  EQU CF_BASE+7 ; write command
296
*
297
* Command Equates
298
*
299
CMDREAD    EQU $20 ; Read Single sector
300
CMDWRITE   EQU $30 ; Write Single sector
301
CMDFEATURE EQU $EF
302
FEAT8BIT   EQU $01 ; enable 8 bit transfers
303
HEADLBA    EQU $E0
304
*
305
* Status bit equates
306
*
307
BSY        EQU $80
308
DRDY       EQU $40
309
DRQ        EQU $08
310
ERR        EQU $01
311
*
312
*
313
* INITIALIZE CF CARD FOR 8 BIT LBA MODE
314
*
315
INITDR BSR WAITRDY
316
       LDA  #HEADLBA
317
       STA  CF_HEAD
318
       LDA #FEAT8BIT
319
       STA CF_FEATURE
320
       LDA #CMDFEATURE
321
       STA CF_COMAND
322
       BRA WAITRDY
323
*
324
* RESTORE DISK DRIVER (SEEK TRACK 00)
325
*
326
RESTR1 BSR   DRVSEL
327
       CLRA           ; Track 0
328
       LDB   #$01     ; Sector 1
329
*
330
* Seek track and sector
331
* A holds track number (0 - ??)
332
* B holds sector number (1 - ??)
333
* Sector numbers starts from 1
334
* subtract 1 to start from sector 0 on CF
335
*
336
SEEKTS DECB
337
       STB  CF_SNUM
338
       STA  CF_CLO
339
       LDB  DRVNUM
340
       STB  CF_CHI
341
       LDB  #$01
342
       STB  CF_SCNT
343
       CLRB
344
       RTS
345
*
346
* READ SECTORS FROM CF
347
*
348
*
349
READSC BSR  SEEKTS
350
       LDA  #CMDREAD ; IDE READ MULTIPLE
351
       STA  CF_COMAND
352
       BSR  WAITRDY
353
*
354
* READ LOOP
355
*
356
       CLRB
357
RDLP1  BSR  WAITDRQ
358
       LDA  CF_DATA
359
       STA  ,X+
360
       DECB
361
       BNE  RDLP1
362
*
363
       CLRB
364
RDLP2  BSR  WAITDRQ
365
       LDA  CF_DATA
366
       DECB
367
       BNE  RDLP2
368
*
369
       BSR  WAITRDY
370
       CLRB
371
       RTS
372
*
373
* WRITE SECTOR TO CF
374
*
375
WRITSC BSR  SEEKTS   ; SEEK TRACK & SECTOR
376
       LDA  #CMDWRITE ; IDE WRITE MULTIPLE
377
       STA  CF_COMAND
378
       BSR  WAITRDY
379
*
380
* WRITE LOOP
381
*
382
       CLRB
383
WRTLP1 BSR  WAITDRQ
384
       LDA  ,X+
385
       STA  CF_DATA
386
       DECB
387
       BNE  WRTLP1
388
*
389
       CLRB
390
WRTLP2 BSR  WAITDRQ
391
       CLRA
392
       STA  CF_DATA
393
       DECB
394
       BNE WRTLP2
395
*
396
       BSR  WAITRDY
397
       CLRB
398
       RTS
399
*
400
* CHECK FOR BUSY
401
* Doubles as VERIFY
402
*
403
BUSY   CLRB            Never busy
404
       RTS
405
*
406
* DRIVE SELECT DISK DRIVER
407
*
408
DRVSEL LDA   3,X       GET DRIVE # FROM FCB
409
       CMPA  #3
410
       BLS   DRVS2     IF > 3, SET IT TO 0
411
       CLRA
412
DRVS2  STA   DRVNUM
413
       CLRB            ; SET Z, CLEAR C
414
       RTS
415
*
416
* CHECK DRIVE READY DISK DRIVER
417
*
418
CHKDRV LDA  3,X
419
       CLRB             ; CLEAR C, SET Z
420
       RTS
421
*
422
* WAIT UNTIL READY
423
*
424
WAITRDY LDA  CF_STATUS
425
        BITA #BSY
426
        BNE  WAITRDY
427
        LDA  CF_STATUS
428
        BITA #DRDY
429
        BEQ  WAITRDY
430
        RTS
431
*
432
* WAIT FOR DATA REQUEST
433
*
434
WAITDRQ LDA  CF_STATUS
435
        BITA #DRQ
436
        BEQ  WAITDRQ
437
        RTS
438
*
439
*******************************************************
440
*
441
* Bootstrap FLEX Loader
442
*
443
* SBUG1.8 loads the bootstap loader at $C000
444
* however the Flex adaption manual has the
445
* bootstrap loader residing at $C100
446
*
447
******************************************************
448
*
449
* Equates
450
*
451
STACK   EQU $C0FF
452
SCTBUF  EQU $C300
453
*
454
* Start of Utility
455
*
456
        ORG $C000
457
BOOT    BRA LOAD0
458
        FCB 0,0,0
459
TRK     FCB 0        File start track
460
SCT     FCB 0        File start sector
461
DNS     FCB 0        Density Flag (not used)
462
TADR    FDB $C000    Transfer address
463
LADR    FDB 0        Load Address
464
DRNUM   FCB 0        Drive number 0
465
*
466
LOAD0   LDS  #STACK   Set up stack
467
        LDD  TRK      Set up start track and sector
468
        STD  SCTBUF
469
        LDY  #SCTBUF+256
470
*
471
* Perform actual file load
472
*
473
LOAD1   BSR GETCH    Get acharcater
474
        CMPA #$02    Data record hearder ?
475
        BEQ  LOAD2   Skip, is so
476
        CMPA #$16    Xfr address hearder ?
477
        BNE LOAD1    Loop if neither
478
*
479
* Get transfer address
480
*
481
        BSR  GETCH
482
        STA  TADR
483
        BSR  GETCH
484
        STA  TADR+1
485
        BRA  LOAD1
486
*
487
* Load data record
488
*
489
LOAD2  BSR  GETCH  Get load address
490
       STA  LADR
491
       BSR  GETCH
492
       STA  LADR+1
493
       BSR  GETCH  Get Bytes count
494
       TFR  A,B
495
       TSTB
496
       BEQ  LOAD1 Loop if count = 0
497
       LDX  LADR  Get load address
498
LOAD3  PSHS B,X
499
       BSR  GETCH  Get data character
500
       PULS B,X
501
       STA  ,X+    Store at load address
502
       DECB
503
       BNE  LOAD3  Loop until count = 0
504
       BRA  LOAD1
505
*
506
* Get Character routine
507
* Reads a sector if needed
508
*
509
GETCH  CMPY #SCTBUF+256 out of data ?
510
       BNE  GETCH4      Go read Character if not
511
GETCH2 LDX  #SCTBUF     Point to buffer
512
       LDD  0,X         Get forward Link
513
       BEQ  GO          if zero, file is loaded
514
       BSR  READ        Read next sector
515
       BNE  BOOT        start over if error
516
       LDY  #SCTBUF+4   Point past link
517
GETCH4 LDA  ,Y+         Else, get a character
518
       RTS
519
*
520
* File is loaded, Jump to it
521
*
522
GO     JMP  [TADR]      Jump to transfer address
523
 
524
*
525
** FLEX 9 COMPACT FLASH DISK DRIVERS
526
*
527
* FOR SYS09BUG 1.2 ON THE BURCHED B5-X300
528
* WITH I/O MAPPED AT $XE000
529
* AND ROM MAPPED AT $XF000
530
* THE BURCHED B5-X300 HAS 256KBYTES OF SRAM
531
* THE FIRST 64K IS USED BY FLEX,
532
* THE SECOND 192K MAY BE USED AS A RAM DISK
533
*
534
*
535
*IMASK  EQU $10     IRQ MASK CC
536
*FMASK  EQU $40     FIRQ MASK CC
537
*DATREG EQU $FFF0   DAT REGISTERS
538
*
539
*CF_BASE    EQU $E040
540
*CF_DATA    EQU CF_BASE+0
541
*CF_ERROR   EQU CF_BASE+1 ; read error
542
*CF_FEATURE EQU CF_BASE+1 ; write feature
543
*CF_SCNT  EQU CF_BASE+2
544
*CF_SNUM  EQU CF_BASE+3
545
*CF_CLO   EQU CF_BASE+4
546
*CF_CHI   EQU CF_BASE+5
547
*CF_HEAD    EQU CF_BASE+6
548
*CF_STATUS  EQU CF_BASE+7 ; read status
549
*CF_COMAND  EQU CF_BASE+7 ; write command
550
*
551
* Command Equates
552
*
553
*CMDREAD    EQU $20 ; Read Single sector
554
*CMDWRITE   EQU $30 ; Write Single sector
555
*CMDFEATURE EQU $EF
556
*FEAT8BIT   EQU $01 ; enable 8 bit transfers
557
*HEADLBA    EQU $E0
558
*
559
* Status bit equates
560
*
561
*BSY        EQU $80
562
*DRDY       EQU $40
563
*DRQ        EQU $08
564
*ERR        EQU $01
565
*
566
* Seek track and sector
567
* A holds track number (0 - ??)
568
* B holds sector number (1 - ??)
569
* Sector numbers starts from 1
570
* subtract 1 to start from sector 0 on CF
571
*
572
SEEK   DECB
573
       STB  CF_SNUM
574
       STA  CF_CLO
575
       LDB  DRNUM
576
       STB  CF_CHI
577
       LDB  #$01
578
       STB  CF_SCNT
579
       CLRB
580
       RTS
581
*
582
* READ SECTORS FROM CF
583
*
584
*
585
READ   BSR  SEEK
586
       LDA  #CMDREAD ; IDE READ MULTIPLE
587
       STA  CF_COMAND
588
       BSR  WTRDY
589
*
590
* READ LOOP
591
*
592
       CLRB
593
READ1  BSR  WTDRQ
594
       LDA  CF_DATA
595
       STA  ,X+
596
       DECB
597
       BNE  READ1
598
*
599
       CLRB
600
READ2  BSR  WTDRQ
601
       LDA  CF_DATA
602
       DECB
603
       BNE  READ2
604
*
605
       BSR  WTRDY
606
       CLRB
607
       RTS
608
*
609
* WAIT UNTIL READY
610
*
611
WTRDY   LDA  CF_STATUS
612
        BITA #BSY
613
        BNE  WTRDY
614
        LDA  CF_STATUS
615
        BITA #DRDY
616
        BEQ  WTRDY
617
        RTS
618
*
619
* WAIT FOR DATA REQUEST
620
*
621
WTDRQ   LDA  CF_STATUS
622
        BITA #DRQ
623
        BEQ  WTDRQ
624
        RTS
625
*
626
       END START

powered by: WebSVN 2.1.0

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