-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy paths100_tarbell.c
1435 lines (1162 loc) · 53.7 KB
/
s100_tarbell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* s100_tarbell.c: Tarbell 1011/2022 Disk Controller
Created by Patrick Linstruth ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
PETER SCHORN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Patrick Linstruth shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Patrick Linstruth.
These functions support simulated Tarbell model 1011 single density and
model 2022 double density floppy disk controllers.
The model is selected using the "SET TARBELL MODEL={SD|DD}" command.
This device does not support the DMA feature of the double density
controller. All software using this simulator must use programmed
I/O.
*/
/* #define DBG_MSG */
#include "altairz80_defs.h"
#include "sim_imd.h"
#ifdef DBG_MSG
#define DBG_PRINT(args) sim_printf args
#else
#define DBG_PRINT(args)
#endif
extern uint32 PCX;
extern t_stat set_membase(UNIT *uptr, int32 val, CONST char *cptr, void *desc);
extern t_stat show_membase(FILE *st, UNIT *uptr, int32 val, CONST void *desc);
extern t_stat set_iobase(UNIT *uptr, int32 val, CONST char *cptr, void *desc);
extern t_stat show_iobase(FILE *st, UNIT *uptr, int32 val, CONST void *desc);
extern uint32 sim_map_resource(uint32 baseaddr, uint32 size, uint32 resource_type,
int32 (*routine)(const int32, const int32, const int32), const char* name, uint8 unmap);
/* These are needed for DMA. */
extern void PutByteDMA(const uint32 addr, const uint32 val);
extern uint8 GetByteDMA(const uint32 addr);
#define TARBELL_MAX_ADAPTERS 1
#define TARBELL_MAX_DRIVES 4
#define TARBELL_SECTOR_LEN 128
#define TARBELL_SPT_SD 26
#define TARBELL_SPT_DD 51
#define TARBELL_TRACKS 77
#define TARBELL_CAPACITY (256256) /* Default Tarbell Single Density Disk Capacity */
#define TARBELL_ROTATION_MS (166) /* 166 milliseconds per revolution */
#define TARBELL_HEAD_TIMEOUT (TARBELL_ROTATION_MS * 1000 * 2) /* usec * 2 revolutions */
#define IBM3740_TRK_HDR_LEN 73
#define IBM3740_SD_SEC_LEN 186
#define IBM3740_DD_SEC_LEN 196
#define TARBELL_PROM_SIZE 32
#define TARBELL_PROM_MASK (TARBELL_PROM_SIZE-1)
#define TARBELL_RAM_SIZE 256
#define TARBELL_RAM_MASK (TARBELL_RAM_SIZE-1)
#define TARBELL_PROM_READ FALSE
#define TARBELL_PROM_WRITE TRUE
#define TARBELL_MEMBASE 0x0000
#define TARBELL_MEMSIZE TARBELL_RAM_SIZE
#define TARBELL_IOBASE 0xF8
#define TARBELL_IOSIZE_SD 5
#define TARBELL_IOSIZE_DD 6
#define TARBELL_DMABASE 0xE0
#define TARBELL_DMASIZE 16
/* Tarbell PROM is 32 bytes */
static uint8 tarbell_prom[TARBELL_PROM_SIZE] = {
0xdb, 0xfc, 0xaf, 0x6f, 0x67, 0x3c, 0xd3, 0xfa,
0x3e, 0x8c, 0xd3, 0xf8, 0xdb, 0xfc, 0xb7, 0xf2,
0x19, 0x00, 0xdb, 0xfb, 0x77, 0x23, 0xc3, 0x0c,
0x00, 0xdb, 0xf8, 0xb7, 0xca, 0x7d, 0x00, 0x76
};
static uint8 tarbell_ram[TARBELL_RAM_SIZE];
/*
** Western Digital FD17XX Registers and Interface Controls
*/
typedef struct {
uint8 track; /* Track Register */
uint8 sector; /* Sector Register */
uint8 command; /* Command Register */
uint8 status; /* Status Register */
uint8 data; /* Data Register */
uint8 intrq; /* Interrupt Request */
int8 stepDir; /* Last Step Direction */
uint32 dataCount; /* Number of data bytes transferred from controller for current sector/address */
uint32 trkCount; /* Number of data bytes transferred from controller for current track */
uint8 readActive; /* Read Active */
uint8 readTrkActive; /* Read Track Active */
uint8 writeActive; /* Write Active */
uint8 writeTrkActive; /* Write Track Active */
uint8 dataAddrMrk; /* Data Addr Mark Flag */
uint8 addrActive; /* Address Active */
} FD17XX_REG;
#define FD17XX_STAT_NOTREADY 0x80
#define FD17XX_STAT_WRITEPROT 0x40
#define FD17XX_STAT_RTYPEMSB 0x40
#define FD17XX_STAT_HEADLOAD 0x20
#define FD17XX_STAT_RTYPELSB 0x20
#define FD17XX_STAT_WRITEFAULT 0x20
#define FD17XX_STAT_SEEKERROR 0x10
#define FD17XX_STAT_NOTFOUND 0x10
#define FD17XX_STAT_CRCERROR 0x08
#define FD17XX_STAT_TRACK0 0x04
#define FD17XX_STAT_LOSTDATA 0x04
#define FD17XX_STAT_INDEX 0x02
#define FD17XX_STAT_DRQ 0x02
#define FD17XX_STAT_BUSY 0x01
typedef struct {
PNP_INFO pnp; /* Plug and Play */
uint32 dma_base; /* DMA base I/O address */
uint32 dma_size; /* DMA I/O size */
uint32 ddEnabled; /* 0=SD,1=DD */
uint32 headTimeout; /* Head unload timer value */
uint8 promEnabled; /* PROM is enabled */
uint8 writeProtect; /* Write Protect is enabled */
uint8 currentDrive; /* currently selected drive */
uint8 secsPerTrack; /* sectors per track */
uint16 bytesPerTrack; /* bytes per track */
uint8 headLoaded[TARBELL_MAX_DRIVES]; /* Head Loaded */
uint8 doubleDensity[TARBELL_MAX_DRIVES]; /* true if double density */
uint8 side[TARBELL_MAX_DRIVES]; /* side 0 or side 1 */
FD17XX_REG FD17XX; /* FD17XX Registers and Data */
UNIT *uptr[TARBELL_MAX_DRIVES];
} TARBELL_INFO;
static TARBELL_INFO tarbell_info_data = {
{ TARBELL_MEMBASE, TARBELL_MEMSIZE, TARBELL_IOBASE, TARBELL_IOSIZE_SD }, TARBELL_DMABASE, TARBELL_DMASIZE
};
static TARBELL_INFO *tarbell_info = &tarbell_info_data;
static uint8 sdata[TARBELL_SECTOR_LEN];
/* Tarbell Registers */
#define TARBELL_REG_STATUS 0x00
#define TARBELL_REG_COMMAND 0x00
#define TARBELL_REG_TRACK 0x01
#define TARBELL_REG_SECTOR 0x02
#define TARBELL_REG_DATA 0x03
#define TARBELL_REG_WAIT 0x04
#define TARBELL_REG_DRVSEL 0x04
#define TARBELL_REG_DMASTAT 0x05
#define TARBELL_REG_EXTADDR 0x05
/* Tarbell Commands */
#define TARBELL_CMD_RESTORE 0x00
#define TARBELL_CMD_SEEK 0x10
#define TARBELL_CMD_STEP 0x20
#define TARBELL_CMD_STEPU (TARBELL_CMD_STEP | TARBELL_FLAG_U)
#define TARBELL_CMD_STEPIN 0x40
#define TARBELL_CMD_STEPINU (TARBELL_CMD_STEPIN | TARBELL_FLAG_U)
#define TARBELL_CMD_STEPOUT 0x60
#define TARBELL_CMD_STEPOUTU (TARBELL_CMD_STEPOUT | TARBELL_FLAG_U)
#define TARBELL_CMD_READ 0x80
#define TARBELL_CMD_READM (TARBELL_CMD_READM | TARBELL_FLAG_M)
#define TARBELL_CMD_WRITE 0xA0
#define TARBELL_CMD_WRITEM (TARBELL_CMD_WRITEM | TARBELL_FLAG_M)
#define TARBELL_CMD_READ_ADDRESS 0xC0
#define TARBELL_CMD_READ_TRACK 0xE0
#define TARBELL_CMD_WRITE_TRACK 0xF0
#define TARBELL_CMD_FORCE_INTR 0xD0
#define TARBELL_FLAG_V 0x04
#define TARBELL_FLAG_H 0x08
#define TARBELL_FLAG_U 0x10
#define TARBELL_FLAG_M 0x10
#define TARBELL_FLAG_B 0x08
#define TARBELL_FLAG_S 0x01
#define TARBELL_FLAG_E 0x04
#define TARBELL_FLAG_A1A0_FB 0x00
#define TARBELL_FLAG_A1A0_FA 0x01
#define TARBELL_FLAG_A1A0_F9 0x02
#define TARBELL_FLAG_A1A0_F8 0x03
#define TARBELL_FLAG_I0 0x01
#define TARBELL_FLAG_I1 0x02
#define TARBELL_FLAG_I2 0x04
#define TARBELL_FLAG_I3 0x08
#define TARBELL_FLAG_R1R0_6MS 0x00
#define TARBELL_FLAG_R1R0_10ms 0x02
#define TARBELL_FLAG_R1R0_20ms 0x03
#define TARBELL_ADDR_TRACK 0x00
#define TARBELL_ADDR_ZEROS 0x01
#define TARBELL_ADDR_SECTOR 0x02
#define TARBELL_ADDR_LENGTH 0x03
#define TARBELL_ADDR_CRC1 0x04
#define TARBELL_ADDR_CRC2 0x05
#define TARBELL_DENS_MASK 0x08
#define TARBELL_DSEL_MASK 0x30
#define TARBELL_SIDE_MASK 0x40
/* Local function prototypes */
static t_stat tarbell_reset(DEVICE *tarbell_dev);
static t_stat tarbell_svc(UNIT *uptr);
static t_stat tarbell_attach(UNIT *uptr, CONST char *cptr);
static t_stat tarbell_detach(UNIT *uptr);
static t_stat tarbell_boot(int32 unitno, DEVICE *dptr);
static t_stat tarbell_set_dmabase(UNIT *uptr, int32 val, CONST char *cptr, void *desc);
static t_stat tarbell_show_dmabase(FILE *st, UNIT *uptr, int32 val, CONST void *desc);
static t_stat tarbell_set_prom(UNIT *uptr, int32 val, CONST char *cptr, void *desc);
static t_stat tarbell_show_prom(FILE *st, UNIT *uptr, int32 val, CONST void *desc);
static t_stat tarbell_set_model(UNIT *uptr, int32 val, CONST char *cptr, void *desc);
static t_stat tarbell_show_model(FILE *st, UNIT *uptr, int32 val, CONST void *desc);
static uint32 secs_per_track(uint8 track);
static uint32 bytes_per_track(uint8 track);
static uint32 calculate_tarbell_sec_offset(uint8 track, uint8 sector);
static void TARBELL_HeadLoad(UNIT *uptr, FD17XX_REG *pFD17XX, uint8 load);
static uint8 TARBELL_Read(uint32 Addr);
static uint8 TARBELL_Write(uint32 Addr, int32 data);
static uint8 TARBELL_Command(UNIT *uptr, FD17XX_REG *pFD17XX, int32 data);
static uint32 TARBELL_ReadSector(UNIT *uptr, uint8 track, uint8 sector, uint8 *buffer);
static uint32 TARBELL_WriteSector(UNIT *uptr, uint8 track, uint8 sector, uint8 *buffer);
static const char* tarbell_description(DEVICE *dptr);
static void showdata(int32 isRead);
static int32 tarbelldev(int32 Addr, int32 rw, int32 data);
static int32 tarbelldma(int32 Addr, int32 rw, int32 data);
static int32 tarbellprom(int32 Addr, int32 rw, int32 data);
static UNIT tarbell_unit[TARBELL_MAX_DRIVES] = {
{ UDATA (tarbell_svc, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, TARBELL_CAPACITY), 10000 },
{ UDATA (tarbell_svc, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, TARBELL_CAPACITY), 10000 },
{ UDATA (tarbell_svc, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, TARBELL_CAPACITY), 10000 },
{ UDATA (tarbell_svc, UNIT_FIX + UNIT_ATTABLE + UNIT_DISABLE + UNIT_ROABLE, TARBELL_CAPACITY), 10000 }
};
static REG tarbell_reg[] = {
{ DRDATAD (DRIVE, tarbell_info_data.currentDrive, 8, "Current drive register"), },
{ HRDATAD (STATUS, tarbell_info_data.FD17XX.status, 8, "Status register"), },
{ HRDATAD (COMMAND, tarbell_info_data.FD17XX.command, 8, "Command register"), },
{ HRDATAD (DATA, tarbell_info_data.FD17XX.data, 8, "Data register"), },
{ DRDATAD (TRACK, tarbell_info_data.FD17XX.track, 8, "Track register"), },
{ DRDATAD (SECTOR, tarbell_info_data.FD17XX.sector, 8, "Sector register"), },
{ DRDATAD (SPT, tarbell_info_data.secsPerTrack, 8, "Sectors per track register"), },
{ DRDATAD (BPT, tarbell_info_data.bytesPerTrack, 16, "Bytes per track register"), },
{ DRDATAD (STEPDIR, tarbell_info_data.FD17XX.stepDir, 8, "Last step direction register"), },
{ DRDATAD (SECCNT, tarbell_info_data.FD17XX.dataCount, 16, "Sector byte count register"), },
{ DRDATAD (TRKCNT, tarbell_info_data.FD17XX.trkCount, 16, "Track byte count register"), },
{ FLDATAD (RDACT, tarbell_info_data.FD17XX.readActive, 0, "Read sector active status bit"), },
{ FLDATAD (WRACT, tarbell_info_data.FD17XX.writeActive, 0, "Write sector active status bit"), },
{ FLDATAD (RDTACT, tarbell_info_data.FD17XX.readTrkActive, 0, "Read track active status bit"), },
{ FLDATAD (WRTACT, tarbell_info_data.FD17XX.writeTrkActive, 0, "Write track active status bit"), },
{ FLDATAD (INTRQ, tarbell_info_data.FD17XX.intrq, 0, "INTRQ status bit"), },
{ FLDATAD (PROM, tarbell_info_data.promEnabled, 0, "PROM enabled bit"), },
{ FLDATAD (WRTPROT, tarbell_info_data.writeProtect, 0, "Write protect enabled bit"), },
{ DRDATAD (HDUNLD, tarbell_info_data.headTimeout, 32, "Head unload timeout"), },
{ NULL }
};
#define TARBELL_NAME "Tarbell SD/DD Floppy Disk Interface"
#define TARBELL_SNAME "TARBELL"
static const char* tarbell_description(DEVICE *dptr) {
return TARBELL_NAME;
}
#define UNIT_V_TARBELL_VERBOSE (UNIT_V_UF + 0) /* VERBOSE / QUIET */
#define UNIT_TARBELL_VERBOSE (1 << UNIT_V_TARBELL_VERBOSE)
#define UNIT_V_TARBELL_WPROTECT (UNIT_V_UF + 1) /* WRTENB / WRTPROT */
#define UNIT_TARBELL_WPROTECT (1 << UNIT_V_TARBELL_WPROTECT)
#define UNIT_V_SIO_SLEEP (UNIT_V_UF + 7) /* sleep after keyboard status check */
#define UNIT_SIO_SLEEP (1 << UNIT_V_SIO_SLEEP)
static MTAB tarbell_mod[] = {
{ MTAB_XTD|MTAB_VDV, 0, "IOBASE", "IOBASE",
&set_iobase, &show_iobase, NULL, "Sets disk controller I/O base address" },
{ MTAB_XTD|MTAB_VDV, 0, "DMABASE", "DMABASE",
&tarbell_set_dmabase, &tarbell_show_dmabase, NULL, "Sets disk controller DMA base address" },
{ MTAB_XTD|MTAB_VDV|MTAB_VALR, 0, "PROM", "PROM={ENABLE|DISABLE}",
&tarbell_set_prom, &tarbell_show_prom, NULL, "Set/Show PROM enabled/disabled status"},
{ MTAB_XTD|MTAB_VDV|MTAB_VALR, 0, "MODEL", "MODEL={SD|DD}",
&tarbell_set_model, &tarbell_show_model, NULL, "Set/Show the current controller model" },
{ UNIT_TARBELL_VERBOSE, 0, "QUIET", "QUIET",
NULL, NULL, NULL, "No verbose messages for unit " TARBELL_SNAME "n" },
{ UNIT_TARBELL_VERBOSE, UNIT_TARBELL_VERBOSE, "VERBOSE", "VERBOSE",
NULL, NULL, NULL, "Verbose messages for unit " TARBELL_SNAME "n" },
{ UNIT_TARBELL_WPROTECT, 0, "WRTENB", "WRTENB", NULL, NULL, NULL,
"Enables " TARBELL_SNAME "n for writing" },
{ UNIT_TARBELL_WPROTECT, UNIT_TARBELL_WPROTECT, "WRTPROT", "WRTPROT", NULL, NULL, NULL,
"Protects " TARBELL_SNAME "n from writing" },
{ 0 }
};
/* Debug flags */
#define ERROR_MSG (1 << 0)
#define SEEK_MSG (1 << 1)
#define CMD_MSG (1 << 2)
#define RD_DATA_MSG (1 << 3)
#define WR_DATA_MSG (1 << 4)
#define STATUS_MSG (1 << 5)
#define RD_DATA_DETAIL_MSG (1 << 6)
#define WR_DATA_DETAIL_MSG (1 << 7)
/* Debug Flags */
static DEBTAB tarbell_dt[] = {
{ "ERROR", ERROR_MSG, "Error messages" },
{ "SEEK", SEEK_MSG, "Seek messages" },
{ "CMD", CMD_MSG, "Command messages" },
{ "READ", RD_DATA_MSG, "Read messages" },
{ "WRITE", WR_DATA_MSG, "Write messages" },
{ "STATUS", STATUS_MSG, "Status messages" },
{ "RDDETAIL", RD_DATA_DETAIL_MSG, "Read detail messages" },
{ "WRDETAIL", WR_DATA_DETAIL_MSG, "Write detail messages" },
{ NULL, 0 }
};
DEVICE tarbell_dev = {
TARBELL_SNAME, /* name */
tarbell_unit, /* unit */
tarbell_reg, /* registers */
tarbell_mod, /* modifiers */
TARBELL_MAX_DRIVES, /* # units */
10, /* address radix */
31, /* address width */
1, /* addr increment */
TARBELL_MAX_DRIVES, /* data radix */
TARBELL_MAX_DRIVES, /* data width */
NULL, /* examine routine */
NULL, /* deposit routine */
&tarbell_reset, /* reset routine */
&tarbell_boot, /* boot routine */
&tarbell_attach, /* attach routine */
&tarbell_detach, /* detach routine */
&tarbell_info_data, /* context */
(DEV_DISABLE | DEV_DIS | DEV_DEBUG), /* flags */
ERROR_MSG, /* debug control */
tarbell_dt, /* debug flags */
NULL, /* mem size routine */
NULL, /* logical name */
NULL, /* help */
NULL, /* attach help */
NULL, /* context for help */
&tarbell_description /* description */
};
/* Reset routine */
static t_stat tarbell_reset(DEVICE *dptr)
{
uint8 i;
TARBELL_INFO *pInfo = (TARBELL_INFO *)dptr->ctxt;
if (dptr->flags & DEV_DIS) { /* Disconnect I/O Ports */
sim_map_resource(pInfo->pnp.mem_base, pInfo->pnp.mem_size, RESOURCE_TYPE_MEMORY, &tarbellprom, "tarbellprom", TRUE);
sim_map_resource(pInfo->pnp.io_base, pInfo->pnp.io_size, RESOURCE_TYPE_IO, &tarbelldev, "tarbelldev", TRUE);
sim_map_resource(pInfo->dma_base, pInfo->dma_size, RESOURCE_TYPE_IO, &tarbelldma, "tarbelldma", TRUE);
} else {
if (sim_map_resource(pInfo->pnp.mem_base, pInfo->pnp.mem_size, RESOURCE_TYPE_MEMORY, &tarbellprom, "tarbellprom", FALSE) != 0) {
sim_debug(ERROR_MSG, &tarbell_dev, TARBELL_SNAME ": Error mapping MEM resource at 0x%04x\n", pInfo->pnp.mem_base);
return SCPE_ARG;
}
/* Connect I/O Ports at base address */
if (sim_map_resource(pInfo->pnp.io_base, pInfo->pnp.io_size, RESOURCE_TYPE_IO, &tarbelldev, "tarbelldev", FALSE) != 0) {
sim_debug(ERROR_MSG, &tarbell_dev, TARBELL_SNAME ": Error mapping I/O resource at 0x%02x\n", pInfo->pnp.io_base);
return SCPE_ARG;
}
/* If simulating a DD, connect DMA ports */
if (tarbell_info->ddEnabled) {
if (sim_map_resource(pInfo->dma_base, pInfo->dma_size, RESOURCE_TYPE_IO, &tarbelldma, "tarbelldma", FALSE) != 0) {
sim_debug(ERROR_MSG, &tarbell_dev, TARBELL_SNAME ": Error mapping DMA resource at 0x%02x\n", pInfo->dma_base);
return SCPE_ARG;
}
}
}
pInfo->currentDrive = 0;
pInfo->promEnabled = TRUE;
pInfo->writeProtect = FALSE;
/* Reset Registers and Interface Controls */
for (i=0; i < TARBELL_MAX_DRIVES; i++) {
if (tarbell_info->uptr[i] == NULL) {
tarbell_info->uptr[i] = &tarbell_dev.units[i];
}
pInfo->FD17XX.track = 0;
pInfo->FD17XX.sector = 1;
pInfo->FD17XX.command = 0;
pInfo->FD17XX.status = 0;
pInfo->FD17XX.data = 0;
pInfo->FD17XX.intrq = 0;
pInfo->FD17XX.stepDir = 1;
pInfo->FD17XX.dataCount = 0;
pInfo->FD17XX.trkCount = 0;
pInfo->FD17XX.addrActive = FALSE;
pInfo->FD17XX.readActive = FALSE;
pInfo->FD17XX.readTrkActive = FALSE;
pInfo->FD17XX.writeActive = FALSE;
pInfo->FD17XX.writeTrkActive = FALSE;
pInfo->FD17XX.addrActive = FALSE;
tarbell_info->headLoaded[i] = FALSE;
tarbell_info->doubleDensity[i] = FALSE;
tarbell_info->side[i] = 0;
}
/*
** If the SIO device sleeps during checks, the SCP usec timer
** is no longer accurate and our wait time has to be adjusted
*/
pInfo->headTimeout = TARBELL_HEAD_TIMEOUT; /* usec timeout */
sim_debug(STATUS_MSG, &tarbell_dev, TARBELL_SNAME ": reset controller.\n");
return SCPE_OK;
}
static t_stat tarbell_svc(UNIT *uptr)
{
FD17XX_REG *pFD17XX;
pFD17XX = &tarbell_info->FD17XX;
if (tarbell_info->headLoaded[tarbell_info->currentDrive] == TRUE) {
TARBELL_HeadLoad(uptr, pFD17XX, FALSE);
}
return SCPE_OK;
}
/* Attach routine */
static t_stat tarbell_attach(UNIT *uptr, CONST char *cptr)
{
char header[4];
t_stat r;
unsigned int i = 0;
r = attach_unit(uptr, cptr); /* attach unit */
if (r != SCPE_OK) { /* error? */
sim_debug(ERROR_MSG, &tarbell_dev, TARBELL_SNAME ": ATTACH error=%d\n", r);
return r;
}
/* Determine length of this disk */
if (sim_fsize(uptr->fileref) != 0) {
uptr->capac = sim_fsize(uptr->fileref);
} else {
uptr->capac = TARBELL_CAPACITY;
}
DBG_PRINT(("TARBELL: ATTACH uptr->capac=%d\n", uptr->capac));
for (i = 0; i < TARBELL_MAX_DRIVES; i++) {
if (tarbell_dev.units[i].fileref == uptr->fileref) {
break;
}
}
if (i >= TARBELL_MAX_DRIVES) {
return SCPE_ARG;
}
/* Default for new file is DSK */
uptr->u3 = IMAGE_TYPE_DSK;
if (uptr->capac > 0) {
char *rtn = fgets(header, 4, uptr->fileref);
if ((rtn != NULL) && (strncmp(header, "CPT", 3) == 0)) {
sim_printf("CPT images not yet supported\n");
uptr->u3 = IMAGE_TYPE_CPT;
tarbell_detach(uptr);
return SCPE_OPENERR;
} else {
uptr->u3 = IMAGE_TYPE_DSK;
}
}
if (uptr->flags & UNIT_TARBELL_VERBOSE) {
sim_printf(TARBELL_SNAME "%d, attached to '%s', type=%s, len=%d\n", i, cptr,
uptr->u3 == IMAGE_TYPE_CPT ? "CPT" : "DSK",
uptr->capac);
}
return SCPE_OK;
}
/* Detach routine */
static t_stat tarbell_detach(UNIT *uptr)
{
t_stat r;
int8 i;
for (i = 0; i < TARBELL_MAX_DRIVES; i++) {
if (tarbell_dev.units[i].fileref == uptr->fileref) {
break;
}
}
if (i >= TARBELL_MAX_DRIVES) {
return SCPE_ARG;
}
DBG_PRINT(("Detach TARBELL%d\n", i));
r = detach_unit(uptr); /* detach unit */
if (r != SCPE_OK) {
return r;
}
tarbell_dev.units[i].fileref = NULL;
if (uptr->flags & UNIT_TARBELL_VERBOSE) {
sim_printf(TARBELL_SNAME "%d detached.\n", i);
}
return SCPE_OK;
}
static t_stat tarbell_set_dmabase(UNIT *uptr, int32 val, CONST char *cptr, void *desc)
{
uint32 newba;
t_stat r;
if (cptr == NULL || !(tarbell_info->ddEnabled)) {
return SCPE_ARG;
}
newba = get_uint (cptr, 16, 0xFF, &r);
if (r != SCPE_OK) {
return r;
}
if ((newba > 0xFF) || (newba % tarbell_info->dma_size)) {
return SCPE_ARG;
}
if (tarbell_dev.flags & DEV_DIS) {
sim_printf("device not enabled yet.\n");
tarbell_info->dma_base = newba & ~(tarbell_info->dma_size-1);
} else {
tarbell_dev.flags |= DEV_DIS;
tarbell_reset(&tarbell_dev);
tarbell_info->dma_base = newba & ~(tarbell_info->dma_size-1);
tarbell_dev.flags &= ~DEV_DIS;
tarbell_reset(&tarbell_dev);
}
return SCPE_OK;
}
static t_stat tarbell_show_dmabase(FILE *st, UNIT *uptr, int32 val, CONST void *desc)
{
if (tarbell_info->ddEnabled) {
fprintf(st, "DMA=0x%02X-0x%02X", tarbell_info->dma_base, tarbell_info->dma_base+tarbell_info->dma_size-1);
} else {
fprintf(st, "DMA=N/A");
}
return SCPE_OK;
}
static t_stat tarbell_set_model(UNIT *uptr, int32 val, CONST char *cptr, void *desc)
{
if (!cptr) return SCPE_IERR;
/* this assumes that the parameter has already been upcased */
if (!strcmp(cptr, "DD")) {
tarbell_info->ddEnabled = TRUE;
tarbell_info->pnp.io_size = TARBELL_IOSIZE_DD;
} else if (!strcmp(cptr, "SD")) {
tarbell_info->ddEnabled = FALSE;
tarbell_info->pnp.io_size = TARBELL_IOSIZE_SD;
} else {
return SCPE_ARG;
}
/* Reset the device if enabled */
if (!(tarbell_dev.flags & DEV_DIS)) {
tarbell_dev.flags |= DEV_DIS;
tarbell_reset(&tarbell_dev);
tarbell_dev.flags &= ~DEV_DIS;
tarbell_reset(&tarbell_dev);
}
return SCPE_OK;
}
static t_stat tarbell_show_model(FILE *st, UNIT *uptr, int32 val, CONST void *desc)
{
fprintf(st, "MODEL=%s", (tarbell_info->ddEnabled) ? "DD" : "SD");
return SCPE_OK;
}
static t_stat tarbell_set_prom(UNIT *uptr, int32 val, CONST char *cptr, void *desc)
{
if (!cptr) return SCPE_IERR;
if (!strlen(cptr)) return SCPE_ARG;
/* this assumes that the parameter has already been upcased */
if (!strncmp(cptr, "ENABLE", strlen(cptr))) {
tarbell_info->promEnabled = TRUE;
} else if (!strncmp(cptr, "DISABLE", strlen(cptr))) {
tarbell_info->promEnabled = FALSE;
} else {
return SCPE_ARG;
}
return SCPE_OK;
}
static t_stat tarbell_show_prom(FILE *st, UNIT *uptr, int32 val, CONST void *desc)
{
fprintf(st, "%s", (tarbell_info->promEnabled) ? "PROM" : "NOPROM");
return SCPE_OK;
}
static t_stat tarbell_boot(int32 unitno, DEVICE *dptr)
{
PNP_INFO *pnp = (PNP_INFO *)dptr->ctxt;
sim_debug(STATUS_MSG, &tarbell_dev, TARBELL_SNAME ": Booting Controller at 0x%04x\n", pnp->mem_base);
*((int32 *) sim_PC->loc) = pnp->mem_base;
return SCPE_OK;
}
static int32 tarbelldev(int32 Addr, int32 rw, int32 data)
{
if (rw == 0) { /* Read */
return(TARBELL_Read(Addr));
} else { /* Write */
return(TARBELL_Write(Addr, data));
}
}
static void showdata(int32 isRead) {
int32 i;
sim_debug(isRead ? RD_DATA_DETAIL_MSG : WR_DATA_DETAIL_MSG, &tarbell_dev, TARBELL_SNAME ": %s track/sector %02d/%03d:\n\t", isRead ? "Read" : "Write", tarbell_info->FD17XX.track, tarbell_info->FD17XX.sector);
for (i=0; i < TARBELL_SECTOR_LEN; i++) {
sim_debug(isRead ? RD_DATA_DETAIL_MSG : WR_DATA_DETAIL_MSG, &tarbell_dev, "%02X ", sdata[i]);
if (((i+1) & 0xf) == 0) {
sim_debug(isRead ? RD_DATA_DETAIL_MSG : WR_DATA_DETAIL_MSG, &tarbell_dev, "\n\t");
}
}
sim_debug(RD_DATA_DETAIL_MSG|WR_DATA_DETAIL_MSG, &tarbell_dev, "\n");
}
static uint32 secs_per_track(uint8 track)
{
/* Track 0 / side 0 is always single density */
int32 secs = (tarbell_info->doubleDensity[tarbell_info->currentDrive] &&
(tarbell_info->side[tarbell_info->currentDrive] || track > 0)) ? TARBELL_SPT_DD : TARBELL_SPT_SD;
tarbell_info->secsPerTrack = secs;
return secs;
}
static uint32 bytes_per_track(uint8 track)
{
int32 bytes;
int32 dd;
dd = tarbell_info->doubleDensity[tarbell_info->currentDrive];
if (dd) {
bytes = IBM3740_TRK_HDR_LEN + 247 + (TARBELL_SPT_DD * IBM3740_DD_SEC_LEN);
} else {
bytes = IBM3740_TRK_HDR_LEN + 247 + (TARBELL_SPT_SD * IBM3740_SD_SEC_LEN);
}
tarbell_info->bytesPerTrack = bytes;
return bytes;
}
static uint32 calculate_tarbell_sec_offset(uint8 track, uint8 sector)
{
uint32 offset;
uint8 ds = tarbell_info->side[tarbell_info->currentDrive];
/*
** Side 0: tracks 0-76
** Side 1: tracks 77-153
*/
if (ds) {
track += 77;
}
/*
** Calculate track offset
*/
if (track==0) {
offset=0;
} else {
offset=TARBELL_SPT_SD * TARBELL_SECTOR_LEN; /* Track 0 / Side 0 always SD */
offset+=(track-1) * secs_per_track(track) * TARBELL_SECTOR_LEN; /* Track 1-153 */
}
/*
** Add sector offset to track offset
*/
offset += (sector-1)*TARBELL_SECTOR_LEN;
DBG_PRINT(("TARBELL: OFFSET drive=%d side=%d den=%d track=%03d sector=%03d\n", tarbell_info->currentDrive, ds, tarbell_info->doubleDensity[tarbell_info->currentDrive], track, sector));
return (offset);
}
static void TARBELL_HeadLoad(UNIT *uptr, FD17XX_REG *pFD17XX, uint8 load)
{
/*
** If no disk has been attached, uptr will be NULL - return
*/
if (uptr == NULL) {
return;
}
if (load) {
sim_activate_after_abs(uptr, tarbell_info->headTimeout); /* activate timer */
if (tarbell_info->headLoaded[tarbell_info->currentDrive] == FALSE) {
sim_debug(STATUS_MSG, &tarbell_dev, TARBELL_SNAME ": Drive %d head Loaded.\n", tarbell_info->currentDrive);
}
}
if (load == FALSE && tarbell_info->headLoaded[tarbell_info->currentDrive] == TRUE) {
sim_cancel(uptr); /* cancel timer */
sim_debug(STATUS_MSG, &tarbell_dev, TARBELL_SNAME ": Drive %d head Unloaded.\n", tarbell_info->currentDrive);
}
tarbell_info->headLoaded[tarbell_info->currentDrive] = load;
}
static uint8 TARBELL_Read(uint32 Addr)
{
uint8 cData;
uint8 driveNum;
FD17XX_REG *pFD17XX;
UNIT *uptr;
driveNum = tarbell_info->currentDrive;
uptr = tarbell_info->uptr[driveNum];
pFD17XX = &tarbell_info->FD17XX;
switch(Addr & 0x07) {
case TARBELL_REG_STATUS:
cData = pFD17XX->status;
break;
case TARBELL_REG_TRACK:
cData = pFD17XX->track;
break;
case TARBELL_REG_DATA:
/*
** If a READ operation is currently active, get the next byte
*/
if (pFD17XX->readActive) {
/* Store byte in DATA register */
pFD17XX->data = sdata[pFD17XX->dataCount++];
/* If we reached the end of the sector, terminate command and set INTRQ */
if (pFD17XX->dataCount == TARBELL_SECTOR_LEN) {
pFD17XX->readActive = FALSE;
pFD17XX->dataCount = 0;
pFD17XX->status = 0x00;
pFD17XX->intrq = TRUE;
} else {
pFD17XX->status |= FD17XX_STAT_DRQ; /* Another byte is ready */
}
TARBELL_HeadLoad(uptr, pFD17XX, TRUE);
} else if (pFD17XX->readTrkActive) {
/* If we reached the end of the track data, terminate command and set INTRQ */
if (pFD17XX->trkCount == bytes_per_track(pFD17XX->track)) {
pFD17XX->readTrkActive = FALSE;
pFD17XX->status = 0x00;
pFD17XX->intrq = TRUE;
} else {
pFD17XX->trkCount++;
pFD17XX->status |= FD17XX_STAT_DRQ; /* Another byte is ready */
}
TARBELL_HeadLoad(uptr, pFD17XX, TRUE);
} else if (pFD17XX->addrActive) {
/* Store byte in DATA register */
pFD17XX->data = sdata[pFD17XX->dataCount++];
DBG_PRINT(("TARBELL: READ ADDR data=%03d\n", pFD17XX->data));
/* If we reached the end of the address data, terminate command and set INTRQ */
if (pFD17XX->dataCount > TARBELL_ADDR_CRC2) {
pFD17XX->addrActive = FALSE;
pFD17XX->status = 0x00;
pFD17XX->intrq = TRUE;
} else {
pFD17XX->status |= FD17XX_STAT_DRQ; /* Another byte is ready */
}
TARBELL_HeadLoad(uptr, pFD17XX, TRUE);
}
cData = pFD17XX->data;
break;
case TARBELL_REG_SECTOR:
cData = pFD17XX->sector;
break;
case TARBELL_REG_WAIT:
cData = (pFD17XX->intrq) ? 0x00 : 0x80; /* Bit 7 True if DRQ */
break;
case TARBELL_REG_DMASTAT:
cData = 0x00; /* Always show DMA is complete */
break;
default:
sim_debug(ERROR_MSG, &tarbell_dev, TARBELL_SNAME ": READ Invalid I/O Address %02x (%02x)\n", Addr & 0xFF, Addr & 0x07);
cData = 0xff;
break;
}
DBG_PRINT(("TARBELL: READ COMPLETE currentDrive=%d doubleDensity=%d sector=%03d track=%02d data=%02x\n", tarbell_info->currentDrive, tarbell_info->doubleDensity[tarbell_info->currentDrive], pFD17XX->track, pFD17XX->sector, pFD17XX->data));
return (cData);
}
static uint8 TARBELL_Write(uint32 Addr, int32 Data)
{
uint8 cData;
uint8 driveNum;
int32 rtn;
UNIT *uptr;
FD17XX_REG *pFD17XX;
sim_debug(CMD_MSG, &tarbell_dev, TARBELL_SNAME ": OUT %02x Data %02x\n", Addr & 0xFF, Data & 0xFF);
cData = 0;
driveNum = tarbell_info->currentDrive;
uptr = tarbell_info->uptr[driveNum];
pFD17XX = &tarbell_info->FD17XX;
switch(Addr & 0x07) {
case TARBELL_REG_COMMAND:
cData = TARBELL_Command(uptr, pFD17XX, Data);
break;
case TARBELL_REG_DATA:
pFD17XX->data = Data; /* Store byte in DATA register */
if (pFD17XX->writeActive) {
/* Store DATA register in Sector Buffer */
sdata[pFD17XX->dataCount++] = pFD17XX->data;
/* If we reached the end of the sector, write sector, terminate command and set INTRQ */
if (pFD17XX->dataCount == TARBELL_SECTOR_LEN) {
pFD17XX->status = 0x00; /* Clear Status Bits */
rtn = TARBELL_WriteSector(uptr, pFD17XX->track, pFD17XX->sector, sdata);
showdata(FALSE);
if (rtn != TARBELL_SECTOR_LEN) {
sim_debug(ERROR_MSG, &tarbell_dev, TARBELL_SNAME ": sim_fwrite errno=%d\n", errno);
pFD17XX->status |= FD17XX_STAT_WRITEFAULT;
}
pFD17XX->writeActive = FALSE;
pFD17XX->dataCount = 0;
pFD17XX->intrq = TRUE;
} else {
pFD17XX->status |= FD17XX_STAT_DRQ; /* Ready for another byte */
}
TARBELL_HeadLoad(uptr, pFD17XX, TRUE);
} else if (pFD17XX->writeTrkActive) {
if (pFD17XX->dataAddrMrk) {
/* Store DATA register in Sector Buffer */
sdata[pFD17XX->dataCount++] = pFD17XX->data;
/* If we reached the end of the sector, write sector */
if (pFD17XX->dataCount == TARBELL_SECTOR_LEN) {
pFD17XX->status &= ~FD17XX_STAT_WRITEFAULT; /* Clear Status Bit */
rtn = TARBELL_WriteSector(uptr, pFD17XX->track, pFD17XX->sector, sdata);
if (rtn != TARBELL_SECTOR_LEN) {
pFD17XX->status |= FD17XX_STAT_WRITEFAULT;
sim_debug(ERROR_MSG, &tarbell_dev, TARBELL_SNAME ": WRITE ERROR could not write track %03d sector %03d\n", pFD17XX->track, pFD17XX->sector);
}
DBG_PRINT(("TARBELL: WRITE TRACK drive=%d track=%03d sector=%03d trkcount=%d datacount=%d data=%02X status=%02X\n", driveNum, pFD17XX->track, pFD17XX->sector, pFD17XX->trkCount, pFD17XX->dataCount, pFD17XX->data, pFD17XX->status));
pFD17XX->dataCount = 0;
pFD17XX->dataAddrMrk = 0;
if (pFD17XX->sector < secs_per_track(pFD17XX->track)) {
pFD17XX->sector++;
}
}
} else if (pFD17XX->data == 0xFB) {
pFD17XX->dataAddrMrk = 1;
DBG_PRINT(("TARBELL: 0xFB Address Mark Found\n"));
}
/*
** Increment number for bytes written to track
*/
pFD17XX->trkCount++;
if (pFD17XX->trkCount < bytes_per_track(pFD17XX->track)) {
pFD17XX->status |= FD17XX_STAT_DRQ; /* Ready for another byte */
} else {
pFD17XX->status = 0x00; /* Clear Status Bits */
pFD17XX->intrq = TRUE;
pFD17XX->status &= ~FD17XX_STAT_BUSY; /* Clear BUSY Bit */
pFD17XX->writeTrkActive = FALSE;
sim_debug(WR_DATA_MSG, &tarbell_dev, TARBELL_SNAME ": WRITE TRACK COMPLETE track=%03d sector=%03d trkcount=%d datacount=%d data=%02X status=%02X\n", pFD17XX->track, pFD17XX->sector, pFD17XX->trkCount, pFD17XX->dataCount, pFD17XX->data, pFD17XX->status);
}
TARBELL_HeadLoad(uptr, pFD17XX, TRUE);
}
DBG_PRINT(("TARBELL: WRITE DATA REG %02X\n", Data));
break;
case TARBELL_REG_TRACK:
pFD17XX->track = Data;
DBG_PRINT(("TARBELL: TRACK REG=%d\n", pFD17XX->track));
break;
case TARBELL_REG_SECTOR:
pFD17XX->sector = Data;
DBG_PRINT(("TARBELL: SECTOR REG=%d\n", pFD17XX->sector));
break;
case TARBELL_REG_DRVSEL:
/* Drive Select */
if (tarbell_info->ddEnabled) { /* Tarbell DD Controller */
cData = (Data & TARBELL_DSEL_MASK) >> 4;
/* Density */
tarbell_info->doubleDensity[cData] = (Data & TARBELL_DENS_MASK) != 0x00;
/* Side */
tarbell_info->side[cData] = (Data & TARBELL_SIDE_MASK) != 0x00;
DBG_PRINT(("REG_DRVSEL=%02X\n", Data));
} else {
cData = ~(Data >> 4) & 0x03; /* Tarbell SD drive bits inverted */
}
if (tarbell_info->currentDrive != cData) {
sim_debug(STATUS_MSG, &tarbell_dev, TARBELL_SNAME ": Current drive now %d\n", cData);
}
tarbell_info->currentDrive = cData;
break;
case TARBELL_REG_EXTADDR:
cData = 0x00;