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

Subversion Repositories System09

[/] [System09/] [branches/] [before_delte/] [src/] [flex9/] [f9-monex.txt] - Blame information for rev 168

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

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

powered by: WebSVN 2.1.0

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