forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idecontrollers.cpp
1586 lines (1390 loc) · 40 KB
/
idecontrollers.cpp
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
/*
* UAE - The Un*x Amiga Emulator
*
* Other IDE controllers
*
* (c) 2015 Toni Wilen
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include "options.h"
#include "memory.h"
#include "newcpu.h"
#include "uae.h"
#include "gui.h"
#include "filesys.h"
#include "threaddep/thread.h"
#include "debug.h"
#include "ide.h"
#include "idecontrollers.h"
#include "zfile.h"
#include "custom.h"
#include "rommgr.h"
#include "cpuboard.h"
#include "scsi.h"
#include "ncr9x_scsi.h"
#include "autoconf.h"
#define DEBUG_IDE 0
#define DEBUG_IDE_GVP 0
#define DEBUG_IDE_ALF 0
#define DEBUG_IDE_APOLLO 0
#define DEBUG_IDE_MASOBOSHI 0
#define GVP_IDE 0 // GVP A3001
#define ALF_IDE 1
#define APOLLO_IDE (ALF_IDE + MAX_DUPLICATE_EXPANSION_BOARDS)
#define MASOBOSHI_IDE (APOLLO_IDE + MAX_DUPLICATE_EXPANSION_BOARDS)
#define ADIDE_IDE (MASOBOSHI_IDE + MAX_DUPLICATE_EXPANSION_BOARDS)
#define MTEC_IDE (ADIDE_IDE + MAX_DUPLICATE_EXPANSION_BOARDS)
#define PROTAR_IDE (MTEC_IDE + MAX_DUPLICATE_EXPANSION_BOARDS)
#define ROCHARD_IDE (PROTAR_IDE + MAX_DUPLICATE_EXPANSION_BOARDS)
#define x86_AT_IDE (ROCHARD_IDE + 2 * MAX_DUPLICATE_EXPANSION_BOARDS)
#define TOTAL_IDE (x86_AT_IDE + MAX_DUPLICATE_EXPANSION_BOARDS)
#define ALF_ROM_OFFSET 0x0100
#define GVP_IDE_ROM_OFFSET 0x8000
#define APOLLO_ROM_OFFSET 0x8000
#define ADIDE_ROM_OFFSET 0x8000
#define MASOBOSHI_ROM_OFFSET 0x0080
#define MASOBOSHI_ROM_OFFSET_END 0xf000
#define MASOBOSHI_SCSI_OFFSET 0xf800
#define MASOBOSHI_SCSI_OFFSET_END 0xfc00
/* masoboshi:
IDE
- FFCC = base address, data (0)
- FF81 = -004B
- FF41 = -008B
- FF01 = -01CB
- FEC1 = -010B
- FE81 = -014B
- FE41 = -018B select (6)
- FE01 = -01CB status (7)
- FE03 = command (7)
- FA00 = ESP, 2 byte register spacing
- F9CC = data
- F047 = -0F85 (-0FB9) interrupt request? (bit 3)
- F040 = -0F8C interrupt request? (bit 1) Write anything = clear irq?
- F000 = some status register
- F04C = DMA address (long)
- F04A = number of words
- F044 = ???
- F047 = bit 7 = start dma
*/
#define MAX_IDE_UNITS 10
static struct ide_board *gvp_ide_rom_board, *gvp_ide_controller_board;
static struct ide_board *alf_board[MAX_DUPLICATE_EXPANSION_BOARDS];
static struct ide_board *apollo_board[MAX_DUPLICATE_EXPANSION_BOARDS];
static struct ide_board *masoboshi_board[MAX_DUPLICATE_EXPANSION_BOARDS];
static struct ide_board *adide_board[MAX_DUPLICATE_EXPANSION_BOARDS];
static struct ide_board *mtec_board[MAX_DUPLICATE_EXPANSION_BOARDS];
static struct ide_board *protar_board[MAX_DUPLICATE_EXPANSION_BOARDS];
static struct ide_board *rochard_board[MAX_DUPLICATE_EXPANSION_BOARDS];
static struct ide_board *x86_at_ide_board[MAX_DUPLICATE_EXPANSION_BOARDS];
static struct ide_hdf *idecontroller_drive[TOTAL_IDE * 2];
static struct ide_thread_state idecontroller_its;
static struct ide_board *ide_boards[MAX_IDE_UNITS + 1];
static void freencrunit(struct ide_board *ide)
{
if (!ide)
return;
for (int i = 0; i < MAX_IDE_UNITS; i++) {
if (ide_boards[i] == ide) {
ide_boards[i] = NULL;
}
}
for(int i = 0; i < MAX_IDE_PORTS_BOARD; i++) {
remove_ide_unit(&ide->ide[i], 0);
}
if (ide->self_ptr)
*ide->self_ptr = NULL;
xfree(ide->rom);
xfree(ide);
}
static struct ide_board *allocide(struct ide_board **idep, struct romconfig *rc, int ch)
{
struct ide_board *ide;
if (ch < 0) {
if (*idep) {
freencrunit(*idep);
*idep = NULL;
}
ide = xcalloc(struct ide_board, 1);
for (int i = 0; i < MAX_IDE_UNITS; i++) {
if (ide_boards[i] == NULL) {
ide_boards[i] = ide;
rc->unitdata = ide;
ide->rc = rc;
ide->self_ptr = idep;
if (idep)
*idep = ide;
return ide;
}
}
}
return *idep;
}
static struct ide_board *getide(struct romconfig *rc)
{
for (int i = 0; i < MAX_IDE_UNITS; i++) {
if (ide_boards[i]) {
struct ide_board *ide = ide_boards[i];
if (ide->rc == rc) {
ide->original_rc = rc;
ide->rc = NULL;
return ide;
}
}
}
return NULL;
}
static struct ide_board *getideboard(uaecptr addr)
{
for (int i = 0; ide_boards[i]; i++) {
if (!ide_boards[i]->baseaddress && !ide_boards[i]->configured)
return ide_boards[i];
if ((addr & ~ide_boards[i]->mask) == ide_boards[i]->baseaddress)
return ide_boards[i];
}
return NULL;
}
static void init_ide(struct ide_board *board, int ide_num, int maxunit, bool byteswap, bool adide)
{
for (int i = 0; i < maxunit / 2; i++) {
struct ide_hdf **idetable = &idecontroller_drive[(ide_num + i) * 2];
alloc_ide_mem (idetable, 2, &idecontroller_its);
board->ide[i] = idetable[0];
idetable[0]->board = board;
idetable[1]->board = board;
idetable[0]->byteswap = byteswap;
idetable[1]->byteswap = byteswap;
idetable[0]->adide = adide;
idetable[1]->adide = adide;
ide_initialize(idecontroller_drive, ide_num + i);
}
idecontroller_its.idetable = idecontroller_drive;
idecontroller_its.idetotal = TOTAL_IDE * 2;
start_ide_thread(&idecontroller_its);
}
static void add_ide_standard_unit(int ch, struct uaedev_config_info *ci, struct romconfig *rc, struct ide_board **ideboard, int idetype, bool byteswap, bool adide, int maxunit)
{
struct ide_hdf *ide;
struct ide_board *ideb;
if (ch >= maxunit)
return;
ideb = allocide(&ideboard[ci->controller_type_unit], rc, ch);
if (!ideb)
return;
ideb->keepautoconfig = true;
ideb->type = idetype;
ide = add_ide_unit (&idecontroller_drive[(idetype + ci->controller_type_unit) * 2], 2, ch, ci, rc);
init_ide(ideb, idetype + ci->controller_type_unit, maxunit, byteswap, adide);
}
static bool ide_interrupt_check(struct ide_board *board, bool edge_triggered)
{
if (!board->configured)
return false;
bool irq = false;
for (int i = 0; i < MAX_IDE_PORTS_BOARD; i++) {
if (board->ide[i] && !irq) {
irq = ide_irq_check(board->ide[i], edge_triggered);
}
}
#if 0
if (board->irq != irq)
write_log(_T("IDE irq %d -> %d\n"), board->irq, irq);
#endif
board->irq = irq;
return irq;
}
static bool ide_rethink(struct ide_board *board, bool edge_triggered)
{
bool irq = false;
if (board->configured) {
if (board->intena && ide_interrupt_check(board, edge_triggered)) {
irq = true;
}
}
return irq;
}
void x86_doirq(uint8_t irqnum);
void idecontroller_rethink(void)
{
bool irq = false;
for (int i = 0; ide_boards[i]; i++) {
if (ide_boards[i] == x86_at_ide_board[0] || ide_boards[i] == x86_at_ide_board[1]) {
bool x86irq = ide_rethink(ide_boards[i], true);
if (x86irq) {
//write_log(_T("x86 IDE IRQ\n"));
x86_doirq(ide_boards[i] == x86_at_ide_board[0] ? 14 : 15);
}
} else {
irq |= ide_rethink(ide_boards[i], false);
}
}
if (irq && !(intreq & 0x0008)) {
INTREQ_0(0x8000 | 0x0008);
}
}
void idecontroller_hsync(void)
{
for (int i = 0; ide_boards[i]; i++) {
struct ide_board *board = ide_boards[i];
if (board->configured) {
for (int j = 0; j < MAX_IDE_PORTS_BOARD; j++) {
if (board->ide[j]) {
ide_interrupt_hsync(board->ide[j]);
}
}
if (ide_interrupt_check(board, false)) {
idecontroller_rethink();
}
}
}
}
static void reset_ide(struct ide_board *board)
{
board->configured = 0;
board->intena = false;
board->enabled = false;
}
void idecontroller_reset(void)
{
for (int i = 0; ide_boards[i]; i++) {
reset_ide(ide_boards[i]);
}
}
void idecontroller_free(void)
{
stop_ide_thread(&idecontroller_its);
for (int i = 0; i < MAX_IDE_UNITS; i++) {
freencrunit(ide_boards[i]);
}
}
static bool is_gvp2_intreq(uaecptr addr)
{
if (ISCPUBOARD(BOARD_GVP, BOARD_GVP_SUB_A3001SII) && (addr & 0x440) == 0x440)
return true;
return false;
}
static bool is_gvp1_intreq(uaecptr addr)
{
if (ISCPUBOARD(BOARD_GVP, BOARD_GVP_SUB_A3001SI) && (addr & 0x440) == 0x40)
return true;
return false;
}
static bool get_ide_is_8bit(struct ide_board *board)
{
struct ide_hdf *ide = board->ide[0];
if (!ide)
return false;
if (ide->ide_drv)
ide = ide->pair;
return ide->mode_8bit;
}
static uae_u32 get_ide_reg_multi(struct ide_board *board, int reg, int portnum, int dataportsize)
{
struct ide_hdf *ide = board->ide[portnum];
if (!ide)
return 0;
if (ide->ide_drv)
ide = ide->pair;
if (reg == 0) {
if (dataportsize)
return ide_get_data(ide);
else
return ide_get_data_8bit(ide);
} else {
return ide_read_reg(ide, reg);
}
}
static void put_ide_reg_multi(struct ide_board *board, int reg, uae_u32 v, int portnum, int dataportsize)
{
struct ide_hdf *ide = board->ide[portnum];
if (!ide)
return;
if (ide->ide_drv)
ide = ide->pair;
if (reg == 0) {
if (dataportsize)
ide_put_data(ide, v);
else
ide_put_data_8bit(ide, v);
} else {
ide_write_reg(ide, reg, v);
}
}
static uae_u32 get_ide_reg(struct ide_board *board, int reg)
{
return get_ide_reg_multi(board, reg, 0, 1);
}
static void put_ide_reg(struct ide_board *board, int reg, uae_u32 v)
{
put_ide_reg_multi(board, reg, v, 0, 1);
}
static uae_u32 get_ide_reg_8bitdata(struct ide_board *board, int reg)
{
return get_ide_reg_multi(board, reg, 0, 0);
}
static void put_ide_reg_8bitdata(struct ide_board *board, int reg, uae_u32 v)
{
put_ide_reg_multi(board, reg, v, 0, 0);
}
static int get_gvp_reg(uaecptr addr, struct ide_board *board)
{
int reg = -1;
if (addr & 0x1000) {
reg = IDE_SECONDARY + ((addr >> 8) & 7);
} else if (addr & 0x0800) {
reg = (addr >> 8) & 7;
}
if (!(addr & 0x400) && (addr & 0x20)) {
if (reg < 0)
reg = 0;
int extra = (addr >> 1) & 15;
if (extra >= 8)
reg |= IDE_SECONDARY;
reg |= extra;
}
if (reg >= 0)
reg &= IDE_SECONDARY | 7;
return reg;
}
static int get_apollo_reg(uaecptr addr, struct ide_board *board)
{
if (addr & 0x4000)
return -1;
int reg = addr & 0x1fff;
reg >>= 10;
if (addr & 0x2000)
reg |= IDE_SECONDARY;
if (reg != 0 && !(addr & 1))
reg = -1;
return reg;
}
static int get_alf_reg(uaecptr addr, struct ide_board *board)
{
if (addr & 0x8000)
return -1;
if (addr & 0x4000) {
;
} else if (addr & 0x1000) {
addr &= 0xfff;
addr >>= 9;
} else if (addr & 0x2000) {
addr &= 0xfff;
addr >>= 9;
addr |= IDE_SECONDARY;
}
return addr;
}
static int get_masoboshi_reg(uaecptr addr, struct ide_board *board)
{
int reg;
if (addr < 0xfc00)
return -1;
reg = 7 - ((addr >> 6) & 7);
if (addr < 0xfe00)
reg |= IDE_SECONDARY;
return reg;
}
static int get_adide_reg(uaecptr addr, struct ide_board *board)
{
int reg;
if (addr & 0x8000)
return -1;
reg = (addr >> 1) & 7;
if (addr & 0x10)
reg |= IDE_SECONDARY;
return reg;
}
static int get_rochard_reg(uaecptr addr, struct ide_board *board, int *portnum)
{
int reg = -1;
if ((addr & 0x8001) != 0x8001)
return -1;
*portnum = (addr & 0x4000) ? 1 : 0;
reg = (addr >> 5) & 7;
if (addr & 0x2000)
reg |= IDE_SECONDARY;
return reg;
}
static int getidenum(struct ide_board *board, struct ide_board **arr)
{
for (int i = 0; i < MAX_DUPLICATE_EXPANSION_BOARDS; i++) {
if (board == arr[i])
return i;
}
return 0;
}
static uae_u32 ide_read_byte(struct ide_board *board, uaecptr addr)
{
uaecptr oaddr = addr;
uae_u8 v = 0xff;
addr &= board->mask;
#if DEBUG_IDE
write_log(_T("IDE IO BYTE READ %08x %08x\n"), addr, M68K_GETPC);
#endif
if (addr < 0x40 && (!board->configured || board->keepautoconfig))
return board->acmemory[addr];
if (board->type == ALF_IDE) {
if (addr < 0x1100 || (addr & 1)) {
if (board->rom)
v = board->rom[addr & board->rom_mask];
return v;
}
int regnum = get_alf_reg(addr, board);
if (regnum >= 0) {
v = get_ide_reg(board, regnum);
}
#if DEBUG_IDE_ALF
write_log(_T("ALF GET %08x %02x %d %08x\n"), addr, v, regnum, M68K_GETPC);
#endif
} else if (board->type == MASOBOSHI_IDE) {
int regnum = -1;
bool rom = false;
if (addr >= MASOBOSHI_ROM_OFFSET && addr < MASOBOSHI_ROM_OFFSET_END) {
if (board->rom) {
v = board->rom[addr & board->rom_mask];
rom = true;
}
} else if (addr >= 0xf000 && addr <= 0xf007) {
if (board->subtype)
v = masoboshi_ncr9x_scsi_get(oaddr, getidenum(board, masoboshi_board));
} else if (addr == 0xf040) {
v = 1;
if (ide_irq_check(board->ide[0], false)) {
v |= 2;
board->irq = true;
}
if (board->irq) {
v &= ~1;
}
v |= masoboshi_ncr9x_scsi_get(oaddr, getidenum(board, masoboshi_board));
} else if (addr == 0xf047) {
v = board->state;
} else {
regnum = get_masoboshi_reg(addr, board);
if (regnum >= 0) {
v = get_ide_reg(board, regnum);
} else if (addr >= MASOBOSHI_SCSI_OFFSET && addr < MASOBOSHI_SCSI_OFFSET_END) {
if (board->subtype)
v = masoboshi_ncr9x_scsi_get(oaddr, getidenum(board, masoboshi_board));
else
v = 0xff;
}
}
#if DEBUG_IDE_MASOBOSHI
if (!rom)
write_log(_T("MASOBOSHI BYTE GET %08x %02x %d %08x\n"), addr, v, regnum, M68K_GETPC);
#endif
} else if (board->type == APOLLO_IDE) {
if (addr >= APOLLO_ROM_OFFSET) {
if (board->rom)
v = board->rom[(addr - APOLLO_ROM_OFFSET) & board->rom_mask];
} else if (board->configured) {
if ((addr & 0xc000) == 0x4000) {
v = apollo_scsi_bget(oaddr);
} else if (addr < 0x4000) {
int regnum = get_apollo_reg(addr, board);
if (regnum >= 0) {
v = get_ide_reg(board, regnum);
} else {
v = 0;
}
}
}
} else if (board->type == GVP_IDE) {
if (addr >= GVP_IDE_ROM_OFFSET) {
if (board->rom) {
if (addr & 1)
v = 0xe8; // board id
else
v = board->rom[((addr - GVP_IDE_ROM_OFFSET) / 2) & board->rom_mask];
return v;
}
v = 0xe8;
#if DEBUG_IDE_GVP
write_log(_T("GVP BOOT GET %08x %02x %08x\n"), addr, v, M68K_GETPC);
#endif
return v;
}
if (board->configured) {
if (board == gvp_ide_rom_board && ISCPUBOARD(BOARD_GVP, BOARD_GVP_SUB_A3001SII)) {
if (addr == 0x42) {
v = 0xff;
}
#if DEBUG_IDE_GVP
write_log(_T("GVP BOOT GET %08x %02x %08x\n"), addr, v, M68K_GETPC);
#endif
} else {
int regnum = get_gvp_reg(addr, board);
#if DEBUG_IDE_GVP
write_log(_T("GVP IDE GET %08x %02x %d %08x\n"), addr, v, regnum, M68K_GETPC);
#endif
if (regnum >= 0) {
v = get_ide_reg(board, regnum);
} else if (is_gvp2_intreq(addr)) {
v = board->irq ? 0x40 : 0x00;
#if DEBUG_IDE_GVP
write_log(_T("GVP IRQ %02x\n"), v);
#endif
ide_interrupt_check(board, false);
} else if (is_gvp1_intreq(addr)) {
v = board->irq ? 0x80 : 0x00;
#if DEBUG_IDE_GVP
write_log(_T("GVP IRQ %02x\n"), v);
#endif
ide_interrupt_check(board, false);
}
}
} else {
v = 0xff;
}
} else if (board->type == ADIDE_IDE) {
if (addr & ADIDE_ROM_OFFSET) {
v = board->rom[addr & board->rom_mask];
} else if (board->configured) {
int regnum = get_adide_reg(addr, board);
v = get_ide_reg(board, regnum);
v = adide_decode_word(v);
}
} else if (board->type == MTEC_IDE) {
if (!(addr & 0x8000)) {
v = board->rom[addr & board->rom_mask];
} else if (board->configured) {
v = get_ide_reg(board, (addr >> 8) & 7);
}
} else if (board->type == PROTAR_IDE) {
v = board->rom[addr & board->rom_mask];
} else if (board->type == ROCHARD_IDE) {
if (addr & 0x8000) {
int portnum;
int regnum = get_rochard_reg(addr, board, &portnum);
if (regnum >= 0 && board->ide[portnum])
v = get_ide_reg_multi(board, regnum, portnum, 1);
} else if ((addr & 0x7c00) == 0x7000) {
if (board->subtype)
v = rochard_scsi_get(oaddr);
else
v = 0;
} else {
v = board->rom[addr & board->rom_mask];
}
}
return v;
}
static uae_u32 ide_read_word(struct ide_board *board, uaecptr addr)
{
uae_u32 v = 0xffff;
addr &= board->mask;
if (addr < 0x40 && (!board->configured || board->keepautoconfig)) {
v = board->acmemory[addr] << 8;
v |= board->acmemory[addr + 1];
return v;
}
if (board->type == APOLLO_IDE) {
if (addr >= APOLLO_ROM_OFFSET) {
if (board->rom) {
v = board->rom[(addr + 0 - APOLLO_ROM_OFFSET) & board->rom_mask];
v <<= 8;
v |= board->rom[(addr + 1 - APOLLO_ROM_OFFSET) & board->rom_mask];
}
}
} else if (board->type == ROCHARD_IDE) {
if (addr < 8192) {
if (board->rom) {
v = board->rom[(addr + 0) & board->rom_mask];
v <<= 8;
v |= board->rom[(addr + 1) & board->rom_mask];
}
}
}
if (board->configured) {
if (board->type == ALF_IDE) {
int regnum = get_alf_reg(addr, board);
if (regnum == IDE_DATA) {
v = get_ide_reg(board, IDE_DATA);
} else {
v = 0;
if (addr == 0x4000 && board->intena)
v = board->irq ? 0x8000 : 0x0000;
#if DEBUG_IDE_ALF
write_log(_T("ALF IO WORD READ %08x %08x\n"), addr, M68K_GETPC);
#endif
}
} else if (board->type == MASOBOSHI_IDE) {
if (addr >= MASOBOSHI_ROM_OFFSET && addr < MASOBOSHI_ROM_OFFSET_END) {
if (board->rom) {
v = board->rom[addr & board->rom_mask] << 8;
v |= board->rom[(addr + 1) & board->rom_mask];
}
} else {
int regnum = get_masoboshi_reg(addr, board);
if (regnum == IDE_DATA) {
v = get_ide_reg(board, IDE_DATA);
} else {
v = ide_read_byte(board, addr) << 8;
v |= ide_read_byte(board, addr + 1);
}
}
} else if (board->type == APOLLO_IDE) {
if ((addr & 0xc000) == 0x4000) {
v = apollo_scsi_bget(addr);
v <<= 8;
v |= apollo_scsi_bget(addr + 1);
} else if (addr < 0x4000) {
int regnum = get_apollo_reg(addr, board);
if (regnum == IDE_DATA) {
v = get_ide_reg(board, IDE_DATA);
} else {
v = 0;
}
}
} else if (board->type == GVP_IDE) {
if (board == gvp_ide_controller_board || ISCPUBOARD(BOARD_GVP, BOARD_GVP_SUB_A3001SI)) {
if (addr < 0x60) {
if (is_gvp1_intreq(addr))
v = gvp_ide_controller_board->irq ? 0x8000 : 0x0000;
else if (addr == 0x40) {
if (ISCPUBOARD(BOARD_GVP, BOARD_GVP_SUB_A3001SII))
v = board->intena ? 8 : 0;
}
#if DEBUG_IDE_GVP
write_log(_T("GVP IO WORD READ %08x %08x\n"), addr, M68K_GETPC);
#endif
} else {
int regnum = get_gvp_reg(addr, board);
if (regnum == IDE_DATA) {
v = get_ide_reg(board, IDE_DATA);
#if DEBUG_IDE_GVP > 2
write_log(_T("IDE WORD READ %04x\n"), v);
#endif
} else {
v = ide_read_byte(board, addr) << 8;
v |= ide_read_byte(board, addr + 1);
}
}
}
} else if (board->type == ADIDE_IDE) {
int regnum = get_adide_reg(addr, board);
if (regnum == IDE_DATA) {
v = get_ide_reg(board, IDE_DATA);
} else {
v = get_ide_reg(board, regnum) << 8;
v = adide_decode_word(v);
}
} else if (board->type == MTEC_IDE) {
if (board->configured && (addr & 0x8000)) {
int regnum = (addr >> 8) & 7;
if (regnum == IDE_DATA)
v = get_ide_reg(board, regnum);
else
v = ide_read_byte(board, addr) << 8;
}
} else if (board->type == ROCHARD_IDE) {
if (board->configured && (addr & 0x8020) == 0x8000) {
v = get_ide_reg_multi(board, IDE_DATA, (addr & 0x4000) ? 1 : 0, 1);
}
}
}
#if DEBUG_IDE
write_log(_T("IDE IO WORD READ %08x %04x %08x\n"), addr, v, M68K_GETPC);
#endif
return v;
}
static void ide_write_byte(struct ide_board *board, uaecptr addr, uae_u8 v)
{
uaecptr oaddr = addr;
addr &= board->mask;
#if DEBUG_IDE
write_log(_T("IDE IO BYTE WRITE %08x=%02x %08x\n"), addr, v, M68K_GETPC);
#endif
if (!board->configured) {
addrbank *ab = board->bank;
if (addr == 0x48) {
map_banks_z2(ab, v, (board->mask + 1) >> 16);
board->baseaddress = v << 16;
board->configured = 1;
if (board->type == ROCHARD_IDE) {
rochard_scsi_init(board->original_rc, board->baseaddress);
} else if (board->type == MASOBOSHI_IDE) {
ncr_masoboshi_autoconfig_init(board->original_rc, board->baseaddress);
}
expamem_next(ab, NULL);
return;
}
if (addr == 0x4c) {
board->configured = 1;
expamem_shutup(ab);
return;
}
}
if (board->configured) {
if (board->type == ALF_IDE) {
int regnum = get_alf_reg(addr, board);
if (regnum >= 0)
put_ide_reg(board, regnum, v);
#if DEBUG_IDE_ALF
write_log(_T("ALF PUT %08x %02x %d %08x\n"), addr, v, regnum, M68K_GETPC);
#endif
} else if (board->type == MASOBOSHI_IDE) {
#if DEBUG_IDE_MASOBOSHI
write_log(_T("MASOBOSHI IO BYTE PUT %08x %02x %08x\n"), addr, v, M68K_GETPC);
#endif
int regnum = get_masoboshi_reg(addr, board);
if (regnum >= 0) {
put_ide_reg(board, regnum, v);
} else if (addr >= MASOBOSHI_SCSI_OFFSET && addr < MASOBOSHI_SCSI_OFFSET_END) {
if (board->subtype)
masoboshi_ncr9x_scsi_put(oaddr, v, getidenum(board, masoboshi_board));
} else if ((addr >= 0xf000 && addr <= 0xf007)) {
if (board->subtype)
masoboshi_ncr9x_scsi_put(oaddr, v, getidenum(board, masoboshi_board));
} else if (addr >= 0xf04a && addr <= 0xf04f) {
// dma controller
masoboshi_ncr9x_scsi_put(oaddr, v, getidenum(board, masoboshi_board));
} else if (addr >= 0xf040 && addr < 0xf048) {
masoboshi_ncr9x_scsi_put(oaddr, v, getidenum(board, masoboshi_board));
if (addr == 0xf047) {
board->state = v;
board->intena = (v & 8) != 0;
}
if (addr == 0xf040) {
board->irq = false;
}
write_log(_T("MASOBOSHI STATUS BYTE PUT %08x %02x %08x\n"), addr, v, M68K_GETPC);
}
} else if (board->type == APOLLO_IDE) {
if ((addr & 0xc000) == 0x4000) {
apollo_scsi_bput(oaddr, v);
} else if (addr < 0x4000) {
int regnum = get_apollo_reg(addr, board);
if (regnum >= 0) {
put_ide_reg(board, regnum, v);
}
}
} else if (board->type == GVP_IDE) {
if (board == gvp_ide_rom_board && ISCPUBOARD(BOARD_GVP, BOARD_GVP_SUB_A3001SII)) {
#if DEBUG_IDE_GVP
write_log(_T("GVP BOOT PUT %08x %02x %08x\n"), addr, v, M68K_GETPC);
#endif
} else {
int regnum = get_gvp_reg(addr, board);
#if DEBUG_IDE_GVP
write_log(_T("GVP IDE PUT %08x %02x %d %08x\n"), addr, v, regnum, M68K_GETPC);
#endif
if (regnum >= 0)
put_ide_reg(board, regnum, v);
}
} else if (board->type == ADIDE_IDE) {
if (board->configured) {
int regnum = get_adide_reg(addr, board);
v = adide_encode_word(v);
put_ide_reg(board, regnum, v);
}
} else if (board->type == MTEC_IDE) {
if (board->configured && (addr & 0x8000)) {
put_ide_reg(board, (addr >> 8) & 7, v);
}
} else if (board->type == ROCHARD_IDE) {
if (board->configured) {
if (addr & 0x8000) {
int portnum;
int regnum = get_rochard_reg(addr, board, &portnum);
if (regnum >= 0 && board->ide[portnum])
put_ide_reg_multi(board, regnum, v, portnum, 1);
} else if ((addr & 0x7c00) == 0x7000) {
if (board->subtype)
rochard_scsi_put(oaddr, v);
}
}
}
}
}
static void ide_write_word(struct ide_board *board, uaecptr addr, uae_u16 v)
{
addr &= board->mask;
#if DEBUG_IDE
write_log(_T("IDE IO WORD WRITE %08x=%04x %08x\n"), addr, v, M68K_GETPC);
#endif
if (board->configured) {
if (board->type == ALF_IDE) {
int regnum = get_alf_reg(addr, board);
if (regnum == IDE_DATA) {
put_ide_reg(board, IDE_DATA, v);
} else {
#if DEBUG_IDE_ALF
write_log(_T("ALF IO WORD WRITE %08x %04x %08x\n"), addr, v, M68K_GETPC);
#endif
}
} else if (board->type == MASOBOSHI_IDE) {
int regnum = get_masoboshi_reg(addr, board);
if (regnum == IDE_DATA) {
put_ide_reg(board, IDE_DATA, v);
} else {
ide_write_byte(board, addr, v >> 8);
ide_write_byte(board, addr + 1, v);
}
#if DEBUG_IDE_MASOBOSHI
write_log(_T("MASOBOSHI IO WORD WRITE %08x %04x %08x\n"), addr, v, M68K_GETPC);
#endif
} else if (board->type == APOLLO_IDE) {
if ((addr & 0xc000) == 0x4000) {
apollo_scsi_bput(addr, v >> 8);
apollo_scsi_bput(addr + 1, v);
} else if (addr < 0x4000) {
int regnum = get_apollo_reg(addr, board);
if (regnum == IDE_DATA) {
put_ide_reg(board, IDE_DATA, v);
}
}
} else if (board->type == GVP_IDE) {
if (board == gvp_ide_controller_board || ISCPUBOARD(BOARD_GVP, BOARD_GVP_SUB_A3001SI)) {
if (addr < 0x60) {
#if DEBUG_IDE_GVP
write_log(_T("GVP IO WORD WRITE %08x %04x %08x\n"), addr, v, M68K_GETPC);
#endif
if (addr == 0x40 && ISCPUBOARD(BOARD_GVP, BOARD_GVP_SUB_A3001SII))
board->intena = (v & 8) != 0;
} else {
int regnum = get_gvp_reg(addr, board);
if (regnum == IDE_DATA) {
put_ide_reg(board, IDE_DATA, v);
#if DEBUG_IDE_GVP > 2
write_log(_T("IDE WORD WRITE %04x\n"), v);
#endif
} else {
ide_write_byte(board, addr, v >> 8);
ide_write_byte(board, addr + 1, v & 0xff);
}
}
}
} else if (board->type == ADIDE_IDE) {
int regnum = get_adide_reg(addr, board);
if (regnum == IDE_DATA) {
put_ide_reg(board, IDE_DATA, v);
} else {
v = adide_encode_word(v);
put_ide_reg(board, regnum, v >> 8);
}
} else if (board->type == MTEC_IDE) {
if (board->configured && (addr & 0x8000)) {
int regnum = (addr >> 8) & 7;
if (regnum == IDE_DATA)
put_ide_reg(board, regnum, v);
else
ide_write_byte(board, addr, v >> 8);
}
} else if (board->type == ROCHARD_IDE) {