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

Subversion Repositories System09

[/] [System09/] [trunk/] [src/] [Flex9/] [f9-monex.txt] - Blame information for rev 209

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

Line No. Rev Author Line
1 120 dilbert57
*
2
** FLEX 9 DISK DRIVERS
3
*
4
* FOR SYS09BUG ON THE
5
* DIGILENT SPARTAN 3 STARTER BOARD AND
6
* TERASIC CYCLONE 2 DE1 BOARD
7
* WITH I/O MAPPED AT $XE000
8
* AND ROM MAPPED AT $XF000
9
* THE DIGILENT SPARTAN 3 STARTER BOARD HAS 1MBYTE OF SRAM
10
* THE TERASIC CYCLONE 2 DE1 BOARD HAS 512KBYTE OF SRAM
11
* THE FIRST 64K IS USED BY FLEX,
12
* THE SECOND 128K IS USED AS A ROM DISK
13
* THE REMAINING RAM IS USED FOR A RAM DISK
14
*
15
*
16
CFLAG   EQU $01     CARRY FLAG
17
VFLAG   EQU $02     OVERFLOW FLAG
18
ZFLAG   EQU $04     ZERO FLAG
19
NFLAG   EQU $08     NEGATIVE FLAG
20
IFLAG   EQU $10     IRQ MASK CC
21
HFLAG   EQU $20     HALF CARRY
22
FFLAG   EQU $40     FIRQ MASK CC
23
EFLAG   EQU $80     ENTIRE FLAG
24
*
25
MAPPAG  EQU $00     PAGE $0000 DAT ADDRESS
26
DATREG  EQU IC11    DAT REGISTERS
27
*
28
* Serial Port
29
*
30
ACIAC1  EQU ACIAS
31
ACIAD1  EQU ACIAS+1
32
DELCON  EQU 1250    Delay (Processor clock in MHz * 50)
33
*
34
* XMODEM Control characters
35
*
36
SOH     EQU $01
37
EOT     EQU $04
38
ACK     EQU $06
39
NAK     EQU $15
40
CAN     EQU $18
41
*
42
* DRIVE GEOMETRY
43
*
44
EMAXSEC EQU 14     ROM DISK
45
EMAXTRK EQU 48     3  * 16 * 14 * 256 = 172,032 Bytes
46
ETOTSEC EQU EMAXTRK*EMAXSEC-EMAXSEC
47
*
48
RMAXSEC EQU 14     RAM DISK
49
*RMAXTRK EQU 192    12 * 16 * 14 * 256 = 688,128 Bytes Digilent Spartan 3
50
RMAXTRK EQU 64    4 * 16 * 14 * 256 = 229,376 Bytes Terasic Cyclone 2
51
RTOTSEC EQU RMAXTRK*RMAXSEC-RMAXSEC
52
*
53
* DRIVE TYPES
54
*
55
DTYPROM EQU 0      ROM DISK
56
DTYPRAM EQU 1      RAM DISK
57
DTYPFLS EQU 2      FLASH DISK
58
DTYPNET EQU 3      FLEXNET DISK
59
*
60
       ORG   $DE00
61
*
62
* DISK DRIVER JUMP TABLE LAST UPDATE: 22/12/2006
63
* Disk driver for RAM Disk.
64
*
65
* 14 SECTORS PER TRACK
66
* 16 * N TRACKS PER DISK
67
*
68
* ROM DISK OCCUPIES $10000 - $1E000 ... $30000 - $3E000
69
* RAM DISK OCCUPIES $40000 - $4E000 ... $F0000 - $FE000
70
* Track Buffer page mapped at $E000 - $EFFF
71
* MAPPAG = $00 = 0 x $1000 (4 K pages)
72
 
73
* ON SWTPC ROM AT $XF000 AND IO AT $XE000
74
* APPEARS THROUGHOUT THE MEMORY SO MUST BE SKIPPED OVER
75
* WHEN USING RAM AS A RAMDISK.
76
* THE MSN OF THE TRACK MAPS INTO THE MSN OF THE DAT
77
* THE LSN OF THE TRACK NUMBER INDEXES INTO THE 4K RAM PAGE
78
* THE SECTOR MAPS INTO THE LSN OF THE DAT WHICH IS INVERTED
79
*
80
*
81
*
82
* FLEX disk jump table.
83
*
84
READ   JMP   READSC
85
WRITE  JMP   WRITSC
86
VERIFY JMP   BUSY
87
RESTOR JMP   RESTR1
88
DRIVE  JMP   DRVSEL
89
DRVRDY JMP   CHKRDY
90
QUICK  JMP   CHKQIK
91
COLDDR JMP   DINIT
92
WARMDR JMP   DWARM
93
SEEK   JMP   SEEKTS
94
*
95
* RAM SPACE
96
*
97
DRVNUM  FCB  0
98
TRACK   FCB  0
99
SECTOR  FCB  0
100
CHKSUM  FCB  0
101
CCSAVE  FCB  0
102
BLKNUM  FCB  0 Xmodem block number
103
BYTCNT  FCB  0 Xmodem byte count
104
XSTATE  FDB  0 Xmodem State Vector
105
DELCNT  FCB  $00,$00,$00 Xmodem Poll timer
106
*
107
* Disc driver type table.
108
* Indexed by drive number
109
*
110
DTYPTAB FCB  DTYPROM Drive 0 (ROM Disk)
111
        FCB  DTYPRAM Drive 1 (RAM Disk)
112
        FCB  DTYPFLS Drive 2 (FLASH Disk)
113
        FCB  DTYPNET Drive 3 (NETPC Disk)
114
*
115
* RAM Disk offset
116
* Indexed by drive type
117
*
118
DOFFTAB FCB  $10 ROM Disk $10000
119
        FCB  $40 RAM DISK $40000
120
        FCB  $FF Flash Disk
121
        FCB  $FF NETPC Disk
122
*
123
REAVEC  RMB  2             Disc driver jump table.
124
WRIVEC  RMB  2
125
VERVEC  RMB  2
126
RSTVEC  RMB  2
127
DRVVEC  RMB  2
128
CHKVEC  RMB  2
129
QUIVEC  RMB  2
130
INIVEC  RMB  2
131
WARVEC  RMB  2
132
SEEVEC  RMB  2
133
*
134
* SECTOR BUFFER
135
*
136
BUFFER  RMB  256
137
SYNCREG RMB  4      Prom input register
138
*
139
****************************************
140
*
141
* START OF EXTENSION COMMANDS
142
*
143
****************************************
144
*
145
        ORG MONEXT
146
        FDB NEXTEXT   Jump to next extended command
147
*
148
*
149
*****************************************
150
* Disk drivers                          *
151
* ------------                          *
152
* The system dependant code for the     *
153
* disc drivers fits here. Two tables    *
154
* must be included. These are DTYPTAB a  *
155
* four byte table that defines which of *
156
* the (up to four) following sets of    *
157
* jump tables to use, and TABSRT the    *
158
* jump tables themselves. For a full    *
159
* description of the floppy drivers see *
160
* section 4 (pp9-14) of the general     *
161
* Flex adaptation guide.                *
162
*****************************************
163
*
164
* Mass storage drivers for embedded applications.
165
*
166
* Jump tables.
167
TABSRT  FDB EREAD Drive type 0 (ROM disk).
168
        FDB EWRITE
169
        FDB ECHECK
170
        FDB ECHECK
171
        FDB ECHECK
172
        FDB ECHECK
173
        FDB ECHECK
174
        FDB DDUMMY
175
        FDB DDUMMY
176
        FDB DDUMMY
177
*
178
        FDB EREAD Drive type 1 (RAM disk).
179
        FDB EWRITE
180
        FDB ECHECK
181
        FDB ECHECK
182
        FDB ECHECK
183
        FDB ECHECK
184
        FDB ECHECK
185
        FDB DDUMMY
186
        FDB DDUMMY
187
        FDB DDUMMY
188
*
189
        FDB DDUMMY Drive type 2 (External Flash disk).
190
        FDB DDUMMY
191
        FDB DDUMMY
192
        FDB DDUMMY
193
        FDB DDUMMY
194
        FDB DDUMMY
195
        FDB DDUMMY
196
        FDB DDUMMY
197
        FDB DDUMMY
198
        FDB DDUMMY
199
*
200
        FDB NREAD  Drive type 3 (NetPC drive via serial port).
201
        FDB NWRITE
202
        FDB NVERIFY
203
        FDB NCHECK
204
        FDB NCHECK
205
        FDB NCHECK
206
        FDB NCHECK
207
        FDB DDUMMY
208
        FDB DDUMMY
209
        FDB DDUMMY
210
*
211
*
212
* Dummy routine (no errors).
213
DDUMMY  CLRB
214
        TSTB  Set (z)=1
215
        ANDCC  #$FF-CFLAG  Set (c)=0
216
        RTS
217
*               *
218
**************************
219
* Main Flex entry points *
220
*************************
221
*
222
* Read sector routine.
223
* Entry: (X) = address where sector is to be placed.
224
*        (A) = Track  number.
225
*        (B) = Sector number.
226
* Exit:  (B) = Error code  (z)=1 if no error.
227
READSC  JMP  [REAVEC]
228
*
229
* Write track routine.
230
* Entry: (X) = Address of area of memory from which the data will be taken.
231
*        (A) = Track number.
232
*        (B) = Sector number.
233
* Exit:  (B) = Error condition, (Z)=1 no an error.
234
WRITSC  JMP  [WRIVEC]
235
*
236
* Verify sector routine.
237
* Entry: no parameters.
238
* Exit:  (B) = Error condition (Z)=1 if no error.
239
BUSY  JMP  [VERVEC]
240
*
241
* Restore drive to track 00.
242
* Entry: (X) = FCB address (3,X contains drive number).
243
* Exit:  (B) = Error condition, (Z)=1 if no error.
244
RESTR1  BSR  DRVSEL Select drive first.
245
        BEQ  RST1
246
        RTS
247
RST1    JMP  [RSTVEC]
248
*
249
* Select current drive.
250
* Entry: (X) = FCB address (3,X contains drive number).
251
* Exit:  (B) = Error condition, (Z)=0 and (c)=1 if error.
252
*        (B) = $0F if non existant drive.
253
DRVSEL  PSHS  X,Y
254
        LDB  3,X  Get driver type.
255
        STB  DRVNUM
256
        LDX  #DTYPTAB
257
        LDA  B,X
258
        CMPA  #$FF  Is the drive nonexistant?
259
        BNE  DRIVE1
260
        PULS  X,Y
261
        LDB  #$0F
262
        TSTB
263
        ORCC  #$01
264
        RTS
265
*
266
DRIVE1  LDB  #20  Get correct table start address.
267
        MUL
268
        LDX  #TABSRT
269
        LEAX  D,X
270
        LDY  #REAVEC Copy table into ram.
271
        LDB  #20
272
DRIVE2  LDA  0,X+
273
        STA  0,Y+
274
        DECB
275
        BNE  DRIVE2
276
        PULS X,Y
277
        JMP  [DRVVEC]
278
*
279
* Check for drive ready.
280
* Entry: (X) = FCB address (3,X contains drive number)>
281
* Exit:  (B) = Error condition, (Z)=0 AND (C)=1 if drive is not ready.
282
CHKRDY  JMP  [CHKVEC]
283
*
284
* Quick drive ready check.
285
* Entry: (X) = FCB address (3,X contains drive number).
286
* Exit:  (B) = Error condition, (Z)=0 AND (c)=1 if drive not ready.
287
CHKQIK  JMP  [QUIVEC]
288
*
289
* Init (cold start).
290
* Entry: no parameters.
291
* Exit: no change.
292
DINIT   CLRA
293
DINIT1  STA  DRVNUM  Init each valid drive in turn.
294
        LDX  #DRVNUM-3
295
        BSR  DRVSEL
296
        BCS  DINIT2
297
        JSR  [INIVEC]
298
DINIT2  LDA  DRVNUM
299
        INCA
300
        CMPA  #4
301
        BNE  DINIT1
302
        RTS
303
*
304
* Warm start.
305
* Entry: no parameters.
306
* Exit: no change.
307
DWARM    JMP  [WARVEC]
308
*
309
* Seek track.
310
* Entry: (A) = Track number.
311
*        (B) = Sector number.
312
* Exit:  (B) = Error condition, (Z)=1 if no error.
313
SEEKTS  JMP  [SEEVEC]
314
*
315
*
316
*****************************************************
317
* ROMdisk drivers                                   *
318
* ---------------                                   *
319
* Drivers to support a ROMdisk in the external RAM  *
320
* of the SYS09. The ROMdisk base address is $10000   *
321
*****************************************************
322
* Dummy return for ROM disk (write protected!)
323
*
324
* MAP RAM DISK INTO MEMORY SPACE
325
*
326
MAPIN   TFR   CC,A     ; Save state of interrupt masks
327
        STA   CCSAVE
328
        ORCC  #FFLAG+IFLAG ; Mask interrupts while IO mapped out
329
        LDU   #DTYPTAB  ; Point to Drive Type table
330
        LDB   DRVNUM   ; Get working drive number
331
        LDB   B,U
332
        LDU   #DOFFTAB
333
        LDA   TRACK
334
        ADDA  B,U      ; Add Base offset into RAM
335
        ANDA  #$F0     ; Mask MSN
336
        STA   ,-S      ; Save A on stack
337
*
338
        LDA   SECTOR
339
        SUBA  #1       ; Sectors 1 to 14 => 0 to 13
340
        EORA  #$0F     ; Complement LSNybble
341
        ANDA  #$0F
342
*
343
        ADDA  ,S+       ; Add sector to LSN of Track and pop
344
        STA   DATREG+MAPPAG
345
*
346
        LDA   TRACK   ; LSN of Track indexes into 4K page
347
        ANDA  #$0F
348
        ADDA  #MAPPAG*16
349
        CLRB
350
        TFR   D,U
351
        RTS
352
*
353
* MAP RAM DISK OUT OF MEMORY
354
*
355
MAPOUT  LDA   #MAPPAG  ; Point to the Flex page
356
        EORA  #$0F     ; Complement LSNybble
357
        STA   DATREG+MAPPAG ; map in Flex page
358
        LDA   CCSAVE   ; restore interrupt masks
359
        TFR   A,CC
360
        RTS
361
*
362
* Seek track and sector
363
* A holds track number (0-32)
364
* B holds sector number (1-14)
365
*
366
ESEEK   STA   TRACK
367
        STB   SECTOR
368
        ANDCC #$FE   ; CLEAR CARRY
369
        ORCC  #$04   ; SET Z
370
        RTS
371
*
372
* MARK DISK READ ONLY
373
*
374
EDUMMY  LDB  #$40
375
        TSTB
376
        ORCC  #$01
377
        RTS
378
*
379
EREAD   PSHS X,Y,U push sequentialy to preserve order on stack
380
        LBSR ESEEK
381
        LBSR MAPIN build external ram address
382
*
383
        LDY #BUFFER
384
        CLRB
385
ERLOOP1 LDA 0,U+ move 256 bytes to buffer from external RAM
386
        STA 0,Y+
387
        DECB
388
        BNE ERLOOP1
389
*
390
        LBSR MAPOUT
391
*
392
        LDY #BUFFER
393
        CLRB
394
ERLOOP2 LDA 0,Y+ move 256 bytes from buffer to Flex RAM
395
        STA 0,X+
396
        DECB
397
        BNE ERLOOP2
398
*
399
        CLRB
400
        PULS X,Y,U,PC  restore all registers
401
*
402
* check for marker bytes $AA55 in first bytes of first track/sector
403
*
404
*ECHECK  CLRA
405
*        LDB  #1
406
*        LDX  #BUFFER
407
*        BSR  EREAD
408
*        LDD  BUFFER
409
*        CMPD  #$AA55
410
*        BNE  EERR
411
*        LBRA  DDUMMY
412
*EERR    LDB  #$80 not ready bit set
413
*        TSTB
414
*        ORCC  #$01
415
*        RTS
416
ECHECK CLRB
417
       RTS
418
*
419
* Write Sector
420
*
421
EWRITE  PSHS X,Y,U
422
        LBSR ESEEK
423
        LDU  #DTYPTAB  ; Point to Drive Type table
424
        LDB  DRVNUM    ; Get working drive number
425
        LDB  B,U       ; Fetch Drive type
426
        CMPB #DTYPRAM  ; Is it a RAM Disk ?
427
        BEQ  EWOK      ; Yep, can write to it
428
        CMPB #DTYPROM  ; Allow writes to ROM Disk too
429
        BEQ  EWOK
430
        LBRA EDUMMY    ; Nope report read only
431
*
432
EWOK    LDY #BUFFER
433
        CLRB
434
EWLOOP1 LDA 0,X+ move 256 bytes to buffer from Flex RAM
435
        STA 0,Y+
436
        DECB
437
        BNE EWLOOP1
438
*
439
        LBSR MAPIN
440
*
441
        LDY #BUFFER
442
        CLRB
443
EWLOOP2 LDA 0,Y+ move 256 bytes from buffer to external RAM
444
        STA 0,U+
445
        DECB
446
        BNE EWLOOP2
447
*
448
        LBSR MAPOUT
449
*
450
        CLRB
451
        PULS X,Y,U,PC
452
*
453
*
454
*****************************************************
455
* FlexNet drivers                                   *
456
* ---------------                                   *
457
* Drivers to support a remote connection via the    *
458
* serial port using the FlexNet protocol as defined *
459
* in FLEXNet_421B                                   *
460
*****************************************************
461
*
462
*
463
* read sector from remote drive
464
*
465
NREAD   PSHS    B
466
        PSHS    A
467
        CLR     CHKSUM          clear checksum
468
        CLR     CHKSUM+1
469
*
470
        LDA     #'s             Send read sector command
471
        JSR     SCHAR
472
        BCC     NRD_DNR         if timeout, then flag drive not ready
473
*
474
        LDA     DRVNUM           send drive
475
        JSR     SCHAR
476
        BCC     NRD_DNR
477
*
478
        PULS    A               send track
479
        JSR     SCHAR
480
        BCC     NRD_DNR
481
*
482
        PULS    A               send sector
483
        JSR     SCHAR
484
        BCC     NRD_DNR
485
*
486
* transfer 256 bytes
487
        CLRB
488
NREAD1  JSR     RCHAR           read byte
489
        BCC     NRD_DNR         if timeout, then flag drive not ready
490
        STA     0,X+
491
        ADDA    CHKSUM+1        update checksum
492
        STA     CHKSUM+1
493
        BCC     NREAD2
494
        INC     CHKSUM
495
NREAD2  DECB
496
        BNE     NREAD1
497
*
498
* compare checksums
499
        JSR     RCHAR           get checksum msb
500
        BCC     NRD_DNR
501
        PSHS    A
502
        JSR     RCHAR           get checksum lsb
503
        BCC     NRD_DNR
504
        TFR     A,B
505
        PULS    A
506
        CMPD    CHKSUM          compare checksums
507
        BNE     NRD_ERR         if checksum error, then flag crc read error
508
*
509
        LDA     #ACK            no checksum error, send ACK char
510
        JSR     SCHAR
511
        BCC     NRD_DNR
512
        CLRB                    all OK, flag no error
513
        BRA     NRD_END
514
*
515
NRD_DNR LDB     #16             flag drive not ready
516
        BRA     NRD_END
517
*
518
NRD_ERR LDA     #NAK            send NAK
519
        JSR     SCHAR
520
        BCC     NRD_DNR
521
        LDB     #09             flag crc read error
522
*
523
NRD_END STB     CHKSUM          used by VERIFY
524
        TSTB
525
        RTS
526
*
527
*
528
* write sector to remote drive
529
*
530
NWRITE  PSHS B
531
        PSHS A
532
        CLR     CHKSUM          clear checksum
533
        CLR     CHKSUM+1
534
*
535
        LDA     #'r             Send write sector command
536
        JSR     SCHAR
537
        BCC     NRD_DNR         if timeout, then flag drive not ready
538
*
539
        LDA     DRVNUM           send drive
540
        JSR     SCHAR
541
        BCC     NRD_DNR
542
*
543
        PULS    A               send track
544
        JSR     SCHAR
545
        BCC     NRD_DNR
546
*
547
        PULS    A               send sector
548
        JSR     SCHAR
549
        BCC     NRD_DNR
550
*
551
* transfer 256 bytes
552
        CLRB
553
NWRITE1 LDA     0,X+
554
        JSR     SCHAR           write byte
555
        BCC     NRD_DNR         if timeout, then flag drive not ready
556
        ADDA    CHKSUM+1        update checksum
557
        STA     CHKSUM+1
558
        BCC     NWRITE2
559
        INC     CHKSUM
560
NWRITE2 DECB
561
        BNE     NWRITE1
562
*
563
* compare checksums
564
        LDA     CHKSUM
565
        JSR     SCHAR           send checksum msb
566
        BCC     NRD_DNR
567
        LDA     CHKSUM+1
568
        JSR     SCHAR           send checksum lsb
569
        BCC     NRD_DNR
570
*
571
        JSR     RCHAR           get checksum response
572
        BCC     NRD_DNR
573
        CMPA    #ACK
574
        BNE     NWR_ERR         if checksum error, then flag write error
575
*
576
        CLRB                    all OK, flag no error
577
        BRA     NWR_END
578
*
579
NWR_ERR LDB     #10             flag write error
580
*
581
NWR_END STB     CHKSUM          used by VERIFY
582
        TSTB
583
        RTS
584
*
585
*
586
*   verify last sector written to remote drive
587
*
588
NVERIFY LDB     CHKSUM         test last checksum
589
        TSTB
590
        RTS
591
*
592
*
593
*   quck check and check drive ready
594
*
595
NCHECK  LDA     #'Q             quick check command
596
        JSR     SCHAR
597
        BCC     NCK_ERR         if timeout, then flag drive not ready
598
 
599
        JSR     RCHAR           get response from host
600
        BCC     NCK_ERR
601
        CMPA    #ACK
602
        BNE     NCK_ERR         if NAK, then flag drive not ready
603
 
604
        CLRB                    all OK, flag drive ready
605
        BRA     NCK_END
606
*
607
NCK_ERR LDB     #16             report drive not ready
608
        ORCC    #$01            check needs carry set as well
609
*
610
NCK_END TSTB
611
        RTS
612
*
613
*
614
* recieve char from remote drive.
615
* timeout if no response for approx 1s.
616
* Entry: no parameters
617
* Exit:  (A) = recieved char, (C)=1 if valid char, (C)=0 if timeout.
618
*
619
RCHAR   PSHS    X,Y
620
*
621
        LDX     #1000         1000x inner loop
622
RCHAR1  LDY     #DELCON       delay constant for inner loop (approx 1ms).
623
RCHAR2  LDA     ACIAC1        test for recieved char
624
        ASRA
625
        BCS     RCHAR3        get character
626
        LEAY    -1,Y          else, continue to count delay
627
        BNE     RCHAR2
628
        LEAX    -1,X
629
        BNE     RCHAR1
630
        PULS    X,Y,PC        return with error if timed out
631
*
632
RCHAR3  LDA     ACIAD1        return data (carry bit still set)
633
        PULS    X,Y,PC
634
*
635
*
636
* transmit char to remote drive.
637
* timeout if no response for approx 1s. (allows for use of hardware flow control)
638
* Entry: (A) = char to transmit
639
* Exit:  (A) = recieved char, (C)=1 if valid char, (C)=0 if timeout.
640
*
641
SCHAR   PSHS    X,Y
642
        PSHS    A
643
*
644
        LDX     #1000         1000x inner loop
645
SCHAR1  LDY     #DELCON       delay constant for inner loop (approx 1ms).
646
SCHAR2  LDA     ACIAC1        test for space in transmit FIFO
647
        ASRA
648
        ASRA
649
        BCS     SCHAR3        send character
650
        LEAY    -1,Y          else, continue to count delay
651
        BNE     SCHAR2
652
        LEAX    -1,X
653
        BNE     SCHAR1
654
        PULS    A
655
        PULS    X,Y,PC        return with error if timed out
656
*
657
SCHAR3  PULS    A
658
        STA     ACIAD1        send data (carry bit still set)
659
        PULS    X,Y,PC
660
*
661
** 'UF' Format RAMdisc to FLEX standard.
662
*
663
DISFOS  FCB $0A,$0D
664
        FCC 'Formating RAMdisk... '
665
        FCB 4
666
MESS6   FCB $0A,$0D,4
667
        FCC 'Ramdisk not allocated! '
668
        FCB 4
669
*
670
UFSUB   LDX #DISFOS
671
        JSR PDATA1
672
        LDX #DTYPTAB            search for allocated ramdisk
673
        CLRB
674
FMT9    LDA B,X
675
        CMPA #DTYPRAM           driver type 1 is ramdisk
676
        BEQ FFOUND
677
        INCB
678
        CMPB #4         end of table? then not allocated.
679
        BNE FMT9
680
        LDX #MESS6
681
        JSR PDATA1
682
        RTS
683
*
684
FFOUND  STB DRVNUM
685
        LDX #DRVNUM-3
686
        JSR DRVSEL
687
*
688
* set up free chain
689
*
690
        LDX #BUFFER clear out buffer
691
        CLRA
692
        CLRB
693
DFL1    STA 0,X+
694
        DECB
695
        BNE DFL1
696
*
697
        CLR TRACK
698
        LDA #1
699
        STA SECTOR
700
DFL2    LDX #BUFFER
701
        LDA TRACK
702
        STA 0,X
703
        LDA SECTOR
704
        INCA
705
        CMPA #RMAXSEC+1 last sector on track?
706
        BNE DFL3
707
        INC 0,X
708
        LDA #1
709
DFL3    STA 1,X
710
        LDA TRACK
711
        LDB SECTOR
712
        JSR WRITSC
713
        INC SECTOR
714
        LDA SECTOR
715
        CMPA #RMAXSEC+1
716
        BNE DFL2
717
        LDA #1
718
        STA  SECTOR
719
        INC TRACK
720
        LDA TRACK
721
        CMPA #RMAXTRK
722
        BNE DFL2
723
* break free chain at last track/sector
724
        LDX  #BUFFER
725
        LDA  #RMAXTRK-1
726
        LDB  #RMAXSEC
727
        JSR  READSC
728
        LDX  #BUFFER
729
        CLR  0,X
730
        CLR  1,X
731
        LDA  #RMAXTRK-1
732
        LDB  #RMAXSEC
733
        JSR  WRITSC
734
* set up sector structure, SIR, directory etc
735
        LDX  #BUFFER
736
        CLRA
737
        LDB  #RMAXSEC
738
        JSR  READSC
739
        LDX  #BUFFER
740
        CLR  0,X break end of directory chain
741
        CLR  1,X
742
        CLRA
743
        LDB  #RMAXSEC
744
        JSR  WRITSC
745
*
746
        LDX  #BUFFER
747
        CLRA
748
        LDB  #3 set up SIR
749
        JSR  READSC
750
        LDX  #BUFFER
751
        CLR  0,X break forward link
752
        CLR  1,X
753
        LDD  #$5241 set volume name (RAMDISK )
754
        STD  16,X
755
        LDD  #$4D44
756
        STD  18,X
757
        LDD  #$4953
758
        STD  20,X
759
        LDD  #$4B20
760
        STD  22,X
761
        LDD  #1 volume number
762
        STD  27,X
763
        LDD  #$0101 first trk/sec  01-01
764
        STD  29,X
765
        LDA  #RMAXTRK-1
766
        LDB  #RMAXSEC
767
        STD  31,X
768
        STD  38,X
769
        LDD  #RTOTSEC total DATA sectors (2912-14)
770
        STD  33,X
771
*
772
        LDA #01 month   set default creation date (SYS09's birthday!)
773
        STA 35,X
774
        LDA #07 day
775
        STA 36,X
776
        LDA #07 year
777
        STA 37,X
778
*
779
RF3     CLRA
780
        LDB  #3
781
        JSR  WRITSC
782
*
783
        LDX #BUFFER
784
        CLRA
785
        LDB #1
786
        JSR READSC
787
        LDX #BUFFER
788
        LDA #$AA set the init flag
789
        STA 0,X
790
        LDA  #$55
791
        STA 1,X
792
        CLRA
793
        LDB #1
794
        JMP WRITSC
795
*
796
********************************
797
*    System specific Boot      *
798
*    command goes here.        *
799
********************************
800
*
801
* Boot FLEX from the FPGA's internal pre-loaded scratch RAM
802
*
803
UBMESS  FCB $08, $08
804
        FCC 'Booting internal FLEX....'
805
        FCB $0D,$0A,$04
806
*
807
UBSUB   LDX #UBMESS
808
        JSR PDATA1
809
*
810
        LDX #$D3E5
811
        LDY #CONTAB Overlay console driver table
812
UB1     LDD 0,Y++
813
        STD 0,X++
814
        CMPX #$D3FD
815
        BNE UB1
816
*
817
        LDX #$DE00 Overlay disk driver table
818
        LDY #DISTAB
819
UB2     LDD 0,Y++
820
        STD 0,X++
821
        CMPX #$DE1E
822
        BNE UB2
823
*
824
UBEND   JMP $CD00
825
*
826
* FLEX console jump table.
827
CONTAB  FDB INPNE       INPUT NO ECHO
828
        FDB DUMMY       INTERRUPT HANDLER
829
        FDB MONRAM+$02 SWI VECTOR
830
        FDB MONRAM+$08 IRQ VECTOR
831
        FDB DUMMY       TIMER OFF
832
        FDB DUMMY       TIMER ON
833
        FDB DUMMY       TIMER INITIALIZATION
834
        FDB CONTRL      MONITOR
835
        FDB DUMMY       TERMINAL INITIALIZATION
836
        FDB STATUS      INPUT CHECK
837
        FDB OUTP        TERMINAL OUTPUT
838
        FDB INPE        TERMINAL INPUT WITH ECHO
839
*
840
* FLEX disk jump table.
841
DISTAB  JMP READSC
842
        JMP WRITSC
843
        JMP BUSY
844
        JMP RESTR1
845
        JMP DRVSEL
846
        JMP CHKRDY
847
        JMP CHKQIK
848
        JMP DINIT
849
        JMP DWARM
850
        JMP SEEKTS
851
*
852
* Monitor jumps
853
*
854
PDATA1  JMP [PDATAV]
855
OUTP    JMP [OUTCHV]
856
INPE    JMP [INCHEV]
857
INPNE   JMP [INCHV]
858
STATUS  JMP [INCHKV]
859
CONTRL  JMP [MONITV]
860
DUMMY   RTS
861
*
862
** 'UL' LOAD ROM DISK VIA SERIAL PORT
863
*
864
ULMES   FCC  'Serial ROM Disk upload ...'
865
        FCB  $0D,$0A,$04
866
ULMES1  FCC  'ROM Disk Loaded'
867
        FCB  $0D,$0A,$04
868
*
869
ULSUB   LDX  #ULMES
870
        JSR  PDATA1
871
*
872
        LDA  #$00
873
        STA  DRVNUM
874
        CLRA         TRACK 0
875
        LDB  #$01    SECTOR 1
876
ULLOOP0 STA  TRACK
877
        STB  SECTOR`
878
        LBSR MAPIN
879
*
880
        CLRB  xfer 256 bytes at a time.
881
ULLOOP1 JSR  LRBYTE transfer should be hex bytes
882
        STA  ,U+
883
        DECB
884
        BNE  ULLOOP1
885
*
886
        LBSR MAPOUT
887
*
888
        LDA  TRACK
889
        LDB  SECTOR
890
        INCB
891
        CMPB #EMAXSEC+1
892
        BNE  ULLOOP0
893
        LDB  #1
894
        INCA
895
        CMPA #EMAXTRK
896
        BNE  ULLOOP0
897
*
898
ULEXIT  LDX  #ULMES1
899
        JMP  PDATA1
900
*
901
* Read a byte from the serial port
902
*
903
LRBYTE  PSHS B
904
        BSR  LRHEX                  Get hex digit.
905
        ASLA
906
        ASLA                           Shift to msb.
907
        ASLA
908
        ASLA
909
        TFR  A,B                    Save in B.
910
        BSR  LRHEX                  Get next digit.
911
        PSHS B
912
        ADDA 0,S+                    Add together bytes.
913
        PULS B,PC
914
*
915
LRHEX   JSR  INTER
916
        BVS  LRHEX
917
        SUBA #$30                   Remove ascii bias.
918
        BMI  LRHEX
919
        CMPA #$09                   Number?
920
        BLE  LRHEX1                 Yes.
921
        CMPA #$11                   Keep testing.
922
        BMI  LRHEX
923
        CMPA #$16
924
        BGT  LRHEX
925
        SUBA #$07
926
LRHEX1  RTS
927
*
928
* ACIA INPUT TEST
929
*
930
INTEST  LDA ACIAC1
931
        BITA #$01
932
        RTS
933
*
934
* RESET ACIA
935
*
936
ACIRST  LDA #$03 master reset
937
        STA  ACIAC1
938
        LDA #$11
939
        STA ACIAC1
940
        RTS
941
*
942
* ACIA INPUT
943
*
944
INTER   LDA  #16
945
        STA  DELCNT+0
946
        CLR  DELCNT+1
947
        CLR  DELCNT+2
948
INTER0  LDA  ACIAC1
949
        BITA #$01
950
        BNE  INTER1
951
        BITA #$78
952
        BEQ  INTER2
953
        BSR  ACIRST
954
        BRA  INTER
955
*
956
INTER1  LDA  ACIAD1
957
        ANDCC #VFLAG
958
        RTS
959
*
960
INTER2  DEC  DELCNT+2
961
        BNE  INTER0
962
        DEC  DELCNT+1
963
        BNE  INTER0
964
        DEC  DELCNT+0
965
        BNE  INTER0
966
        CLRA
967
        ORCC #VFLAG
968
        RTS
969
*
970
* ACIA OUTPUT
971
*
972
OUTTER  PSHS A
973
*
974
OUTTE1  LDA ACIAC1
975
        BITA #$02
976
        BNE  OUTTE2
977
        BITA #$78
978
        BEQ  OUTTE1
979
        BSR  ACIRST
980
        BRA  OUTTE1
981
*
982
OUTTE2  PULS A
983
        STA ACIAD1
984
        RTS
985
*
986
** 'UX' Xmodem ROM Disk upload
987
*
988
UXMES   FCB $0D,$0A
989
        FCC 'Xmodem ROM Disk Upload'
990
        FCB 4
991
UXMES1  FCB $0D,$0A
992
        FCC 'Upload Complete'
993
        FCB 4
994
UXMES2  FCB $0D,$0A
995
        FCC 'Upload Error'
996
        FCB 4
997
*
998
UXSUB   LDX #UXMES
999
        LBSR PDATA1
1000
*
1001
        LDA  #1
1002
        STA BLKNUM
1003
        LDX  #XSTSTR
1004
        STX  XSTATE
1005
*
1006
        LDA  #$00
1007
        STA  DRVNUM
1008
        CLRA         TRACK 0
1009
        LDB  #$01    SECTOR 1
1010
UXLOOP0 STA  TRACK
1011
        STB  SECTOR
1012
        LBSR MAPIN
1013
*
1014
        CLRB       xfer 256 bytes at a time.
1015
UXLOOP1 LBSR XBYTE transfer should be hex bytes
1016
        BCS  UXERR
1017
        STA  ,U+
1018
        DECB
1019
        BNE  UXLOOP1
1020
*
1021
        LBSR MAPOUT
1022
*
1023
        LDA  TRACK
1024
        LDB  SECTOR
1025
        INCB
1026
        CMPB #EMAXSEC+1
1027
        BNE  UXLOOP0
1028
        LDB  #1
1029
        INCA
1030
        CMPA #EMAXTRK
1031
        BNE  UXLOOP0
1032
*
1033
UXEXIT  LDX  #UXMES1
1034
        JMP  PDATA1
1035
*
1036
UXERR   LBSR MAPOUT
1037
        LDX  #UXMES2
1038
        LBRA PDATA1
1039
*
1040
* Get a Byte using XModem protocol
1041
* Carry clear => no errors
1042
* Carry set   => errors
1043
*
1044
XBYTE   PSHS X
1045
        LDX  XSTATE
1046
*
1047
XBYTE0  LBSR INTER
1048
        BVC  XBYTE1
1049
        LDA  #NAK
1050
        LBSR OUTTER
1051
        LDX  #XSTSTR
1052
        BRA  XBYTE0
1053
*
1054
XBYTE1  JSR  ,X
1055
        BNE  XBYTE0
1056
        STX  XSTATE
1057
        PULS X,PC
1058
*
1059
* START - LOOK FOR SOH (START OF HEADER) = $01
1060
*
1061
XSTSTR  CMPA #SOH
1062
        BNE  XSTSTR1
1063
        LDX  #XSTBLK
1064
        ANDCC #$FF-CFLAG-ZFLAG No abort, no valid data (no exit)
1065
        RTS
1066
*
1067
XSTSTR1 CMPA #EOT
1068
        BNE  XSTSTR2
1069
        LDA  #ACK
1070
        LBSR OUTTER
1071
        ORCC  #CFLAG+ZFLAG  Set (c)=1 abort & exit
1072
        RTS
1073
*
1074
XSTSTR2 CMPA #CAN
1075
        BNE  XSTSTR3
1076
        ORCC  #CFLAG+ZFLAG  Set (c)=1 abort & exit
1077
        RTS
1078
*
1079
XSTSTR3 ANDCC #$FF-CFLAG-ZFLAG
1080
        RTS
1081
*
1082
* Got SOH
1083
* Now get block number
1084
*
1085
XSTBLK  CMPA BLKNUM
1086
        BNE  XSTBLKE
1087
        LDX  #XSTCOM
1088
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
1089
        RTS
1090
*
1091
* Error in block number
1092
*
1093
XSTBLKE LDA  #NAK
1094
        LBSR OUTTER
1095
        LDX  #XSTSTR
1096
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
1097
        RTS
1098
*
1099
* Get complement of block number
1100
*
1101
XSTCOM  COMA
1102
        CMPA BLKNUM
1103
        BNE  XSTBLKE
1104
        CLR  CHKSUM
1105
        LDA  #128
1106
        STA  BYTCNT
1107
        LDX  #XSTDAT
1108
        ANDCC #$FF-CFLAG-ZFLAG No abort, No valid data (no exit)
1109
        RTS
1110
*
1111
* Get data bytes
1112
*
1113
XSTDAT  PSHS A
1114
        ADDA CHKSUM
1115
        STA  CHKSUM
1116
        PULS A
1117
        DEC  BYTCNT
1118
        BNE  XSTDAT1
1119
        LDX  #XSTCHK
1120
XSTDAT1 ANDCC #$FF-CFLAG No abort
1121
        ORCC #ZFLAG      Valid data (exit)
1122
        RTS
1123
*
1124
* Byte count reached zero
1125
* Check checksum byte
1126
*
1127
XSTCHK  CMPA CHKSUM
1128
        BNE  XSTCHK1 retry if wrong checksum
1129
*
1130
* Checksum OK ...
1131
* increment block number
1132
* and send ACK
1133
*
1134
        INC  BLKNUM
1135
        LDA  #ACK
1136
        BRA  XSTCHK2
1137
*
1138
* Checksum Error detected ...
1139
* Reset Sector counter in ACCB to last 128 byte boundary
1140
* and send NAK
1141
*
1142
XSTCHK1 PSHS B
1143
        TFR  U,D
1144
        DECB
1145
        ANDB #128
1146
        TFR  D,U
1147
        PULS B
1148
        LDA  #NAK
1149
XSTCHK2 LBSR OUTTER
1150
        LDX  #XSTSTR
1151
        ANDCC #$FF-CFLAG-ZFLAG No abort, no valid data (no exit)
1152
        RTS
1153
*
1154
** 'UP' Load ROMdisk via config PROM.
1155
*
1156
UPMES   FCB  $08,$08
1157
        FCC  'Load ROM disk from config PROM.'
1158
        FCB  4
1159
UPMES1  FCC  'Found SYNC, loading data...'
1160
        FCB  $0A,$0D,4
1161
UPMES2  FCC  'ROM Disk Loaded.'
1162
        FCB  $0A,$0D,4
1163
UPMES3  FCC  'ROM Disk Not Found.'
1164
        FCB  $0A,$0D,4
1165
*
1166
UPSUB   LDX  #UPMES
1167
        JSR  PDATA1
1168
*
1169
        BSR  UPRESET
1170
        LDY  #$0020  Set up count for 2 MBit
1171
        LDX  #$0000
1172
UPSUB1  BSR  UPBIT   Shift in bit
1173
        BSR  UPSYNC  Test for Sync pattern`
1174
        BEQ  UPSUB4  Skip if found
1175
        LEAX -1,X    Count Down inner loop
1176
        CMPX #$0000
1177
        BNE  UPSUB1   Branch if inner loop not complete
1178
        LEAY -1,X    Count down outer loop
1179
        CMPY #$0000
1180
        BNE  UPSUB1   Branch if outer loop not complete
1181
*
1182
        LDX  #UPMES3 2MBits scanned, no synch, report error
1183
        JMP  PDATA1
1184
*
1185
UPSUB4  LDX  #UPMES1 Sync found, now load disk
1186
        JSR  PDATA1
1187
*
1188
        CLRA
1189
        STA  DRVNUM   select Drive 0
1190
        LDB  #$01
1191
UPSUB2  STA  TRACK   track 0
1192
        STB  SECTOR  sector 1
1193
*
1194
        LBSR MAPIN   map in buffer
1195
        CLRB         256 byte sector
1196
UPSUB3  BSR  UPBYTE  read byte from prom
1197
        STA  ,U+     Store in buffer
1198
        DECB
1199
        BNE  UPSUB3  Loop until sector read`
1200
        LBSR MAPOUT  map out buffer
1201
*
1202
        LDA  TRACK   Advance sector
1203
        LDB  SECTOR
1204
        INCB
1205
        CMPB #EMAXSEC+1 Wrap on max sector count
1206
        BNE  UPSUB2
1207
        LDB  #1
1208
        INCA          Advance track
1209
        CMPA #EMAXTRK
1210
        BNE  UPSUB2
1211
*
1212
UPEXIT  LDX  #UPMES2  Load complete, report message
1213
        JMP  PDATA1
1214
*
1215
* Reset Serial PROM
1216
*
1217
UPRESET LDA  #PRSTHI    Strobe the reset line
1218
        STA  PROMREG
1219
        LDA  #PRSTLO
1220
        STA  PROMREG
1221
        LDX  #$0000     Delay a while`
1222
UPRST1  LEAX -1,X
1223
        CMPX #$0000
1224
        BNE  UPRST1
1225
        STX  SYNCREG+0  Clear Sync Shift Register
1226
        STX  SYNCREG+2
1227
        RTS
1228
*
1229
* Input 1 Bit From PROM
1230
*
1231
UPBIT   LDA  #PCLKHI
1232
        STA  PROMREG
1233
        LDA  #PCLKLO
1234
        STA  PROMREG
1235
        LDA  PROMREG
1236
        LSRA
1237
        ASL  SYNCREG+3
1238
        RTS
1239
*
1240
* Test for 32 bit Sync Word
1241
*
1242
UPSYNC  ROL  SYNCREG+2
1243
        ROL  SYNCREG+1
1244
        ROL  SYNCREG+0
1245
        LDD  #SYNCLO
1246
        CMPD SYNCREG+2
1247
        BNE  UPSYNCX
1248
        LDD  #SYNCHI
1249
        CMPD SYNCREG+0
1250
UPSYNCX RTS
1251
*
1252
* Input 1 Byte From PROM
1253
*
1254
UPBYTE  PSHS B
1255
        LDB  #8
1256
UPBYTE1 BSR  UPBIT
1257
        DECB
1258
        BNE  UPBYTE1
1259
        LDA  SYNCREG+3
1260
        PULS B,PC
1261
*
1262
***** NEXTCMD *****
1263
*
1264
NEXTEXT LBSR INPE  GET ONE CHAR. FROM TERMINAL
1265
        ANDA #$7F STRIP PARITY FROM CHAR.
1266
        TFR  A,B
1267
        LDA  #$20
1268
        LBSR OUTP PRNT SPACE
1269
        CMPB #$60
1270
        BLE NXTEX0
1271
        SUBB #$20
1272
*
1273
***** DO TABLE LOOKUP *****
1274
*   FOR COMMAND FUNCTIONS
1275
*
1276
NXTEX0  LDX #EXTTAB    POINT TO JUMP TABLE
1277
NXTEX1  CMPB ,X+       DOES COMMAND MATCH TABLE ENTRY ?
1278
        BEQ  JMPEXT    BRANCH IF MATCH FOUND
1279
        LEAX 2,X       POINT TO NEXT ENTRY IN TABLE
1280
        CMPX #EXTEND   REACHED END OF TABLE YET ?
1281
        BNE  NXTEX1    IF NOT END, CHECK NEXT ENTRY
1282
        LDX  #MSGWHAT  POINT TO MSG "WHAT?"
1283
        LBRA PDATA1    PRINT MSG AND RETURN
1284
JMPEXT  JMP  [,X]      JUMP TO COMMAND ROUTINE
1285
*
1286
* EXTENDED COMMAND JUMP TABLE
1287
*
1288
EXTTAB EQU *
1289
       FCC 'B'   BOOT FLEX
1290
       FDB UBSUB
1291
       FCC 'L'   LOAD ROM DISK OVER SERIAL PORT
1292
       FDB ULSUB
1293
       FCC 'F'   FORMAT RAM DISK
1294
       FDB UFSUB
1295
       FCC 'P'   LOAD ROM DISK FROM PROM
1296
       FDB UPSUB
1297
       FCC 'X'   XMODEM ROM DISK UPLOAD
1298
       FDB UXSUB
1299
*
1300
EXTEND EQU *
1301
*
1302
MSGWHAT FCC "WHAT ?"
1303
        FCB $0A,$0D,$04
1304
       END

powered by: WebSVN 2.1.0

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