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

Subversion Repositories System09

[/] [System09/] [trunk/] [src/] [Flex9/] [f9-monex.asm] - Blame information for rev 159

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

powered by: WebSVN 2.1.0

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