This repository has been archived by the owner on Dec 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmemory.c
1691 lines (1419 loc) · 42.7 KB
/
memory.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
#include "common.h"
#ifdef ARM_ARCH
memory_struct memory __attribute__ ((aligned(8192)));
#else
memory_struct memory;
#endif
#ifdef CRC_CHECK
const u32 sgx_table[6] =
{
0xbebfe042,
0x4c2126b0,
0x8c4588e2,
0x1f041166,
0xb486a8ed,
0x3b13af61,
};
#endif
char *get_mpr_region_name(u32 mpr_number)
{
static char name_buffer[32];
switch(memory.mpr[mpr_number])
{
// HuCard ROM
case 0x00 ... 0x67:
sprintf(name_buffer, "ROM-%02x", memory.mpr[mpr_number]);
return name_buffer;
case 0x68 ... 0x7F:
if(config.cd_loaded)
{
sprintf(name_buffer, "SCD-%02x", memory.mpr[mpr_number] - 0x60);
return name_buffer;
}
sprintf(name_buffer, "ROM-%02x", memory.mpr[mpr_number]);
return name_buffer;
case 0x80 ... 0x87:
if(config.cd_loaded)
{
sprintf(name_buffer, "CD-%02x ", memory.mpr[mpr_number] - 0x80);
return name_buffer;
}
return "INV";
// Unusued
case 0x88 ... 0xF6:
return "INV";
// BRAM
case 0xF7:
if(memory_map_get(write, 0xF7) == cd.bram)
return "BRAM";
return "INV";
// work RAM
case 0xF8 ... 0xFB:
if(config.sgx_mode)
{
sprintf(name_buffer, "RAM-%02x", memory.mpr[mpr_number] - 0xF8);
return name_buffer;
}
return "RAM";
// Unused
case 0xFC ... 0xFE:
return "INV";
// I/O
case 0xFF:
return "I/O";
}
return "???";
}
u32 mpr_read(u32 mpr_regs)
{
u32 mpr_value;
u32 i;
if(mpr_regs == 0)
return memory.last_mpr_value;
mpr_value = 0;
// Charles MacDonald's doc simply says the values are
// combined in some way, but he is unsure how. Bitwise
// OR should be as good a guess as any...
for(i = 0; i < 8; i++)
{
if(mpr_regs & (1 << i))
{
mpr_value |= memory.mpr[i];
}
}
return mpr_value;
}
void mpr_write(u32 mpr_regs, u32 mpr_value)
{
u8 *mpr_translated_value_read = memory.memory_map_read[mpr_value];
u8 *mpr_translated_value_write = memory.memory_map_write[mpr_value];
u32 i = 0;
if(mpr_regs)
memory.last_mpr_value = mpr_value;
if(!mpr_check_ext(mpr_translated_value_read))
{
// Read standard
if(!mpr_check_ext(mpr_translated_value_write))
{
// Read and write standard
while(mpr_regs)
{
if(mpr_regs & 1)
{
memory.mpr[i] = mpr_value;
mpr_translated_set_read(mpr_translated_value_read, i);
mpr_translated_set_write(mpr_translated_value_write, i);
}
mpr_regs >>= 1;
i++;
}
}
else
{
// Read standard, write extended
while(mpr_regs)
{
if(mpr_regs & 1)
{
memory.mpr[i] = mpr_value;
mpr_translated_set_read(mpr_translated_value_read, i);
mpr_translated_set_write_ext(mpr_translated_value_write, i);
}
mpr_regs >>= 1;
i++;
}
}
}
else
{
// Read extended
if(!mpr_check_ext(mpr_translated_value_write))
{
// Read extended, write standard
while(mpr_regs)
{
if(mpr_regs & 1)
{
memory.mpr[i] = mpr_value;
mpr_translated_set_read_ext(mpr_translated_value_read, i);
mpr_translated_set_write(mpr_translated_value_write, i);
}
mpr_regs >>= 1;
i++;
}
}
else
{
// Read extended, write extended
while(mpr_regs)
{
if(mpr_regs & 1)
{
memory.mpr[i] = mpr_value;
mpr_translated_set_read_ext(mpr_translated_value_read, i);
mpr_translated_set_write_ext(mpr_translated_value_write, i);
}
mpr_regs >>= 1;
i++;
}
}
}
}
void memory_remap_read(u32 region, u32 size, u8 *ptr)
{
u32 i;
for(i = 0; i < size; i++)
{
memory_map_set(read, region + i, ptr + (i * 0x2000));
}
for(i = 0; i < 8; i++)
{
if(!memory_map_check_ext(read, memory.mpr[i]))
mpr_translated_set_read(memory.memory_map_read[memory.mpr[i]], i);
}
}
void memory_remap_read_fixed(u32 region, u32 size, u8 *ptr)
{
u32 i;
for(i = 0; i < size; i++)
{
memory_map_set(read, region + i, ptr);
}
for(i = 0; i < 8; i++)
{
if(!memory_map_check_ext(read, memory.mpr[i]))
mpr_translated_set_read(memory.memory_map_read[memory.mpr[i]], i);
}
}
void memory_remap_write(u32 region, u32 size, u8 *ptr)
{
u32 i;
for(i = 0; i < size; i++)
{
memory_map_set(write, region + i, ptr + (i * 0x2000));
}
for(i = 0; i < 8; i++)
{
if(!memory_map_check_ext(write, memory.mpr[i]))
mpr_translated_set_write(memory.memory_map_write[memory.mpr[i]], i);
}
}
void memory_remap_write_fixed(u32 region, u32 size, u8 *ptr)
{
u32 i;
for(i = 0; i < size; i++)
{
memory_map_set(write, region + i, ptr);
}
for(i = 0; i < 8; i++)
{
if(!memory_map_check_ext(write, memory.mpr[i]))
mpr_translated_set_write(memory.memory_map_write[memory.mpr[i]], i);
}
}
void memory_remap_write_io(u32 region, u32 size,
io_write_function_ptr *io_write_functions)
{
u32 i;
for(i = 0; i < size; i++)
{
memory_map_set_ext(write, region + i, io_write_functions);
}
for(i = 0; i < 8; i++)
{
if(memory_map_check_ext(write, memory.mpr[i]))
mpr_translated_set_write_ext(memory.memory_map_write[memory.mpr[i]], i);
}
}
void memory_remap_read_write(u32 region, u32 size, u8 *ptr_read,
u8 *ptr_write)
{
u32 i;
for(i = 0; i < size; i++)
{
memory_map_set(read, region + i, ptr_read + (i * 0x2000));
memory_map_set(write, region + i, ptr_write + (i * 0x2000));
}
for(i = 0; i < 8; i++)
{
if((u32)(memory.mpr[i] - region) < size)
{
mpr_translated_set_read(memory.memory_map_read[memory.mpr[i]], i);
mpr_translated_set_write(memory.memory_map_write[memory.mpr[i]], i);
}
}
}
void memory_remap_read_write_io(u32 region, u32 size,
io_read_function_ptr *io_read_functions,
io_write_function_ptr *io_write_functions)
{
u32 i;
for(i = 0; i < size; i++)
{
memory_map_set_ext(read, region + i, io_read_functions);
memory_map_set_ext(write, region + i, io_write_functions);
}
for(i = 0; i < 8; i++)
{
if(memory_map_check_ext(read, memory.mpr[i]))
mpr_translated_set_read_ext(memory.memory_map_read[memory.mpr[i]], i);
if(memory_map_check_ext(write, memory.mpr[i]))
mpr_translated_set_write_ext(memory.memory_map_write[memory.mpr[i]], i);
}
}
void memory_remap_read_null(u32 region, u32 size)
{
memory_remap_read_fixed(region, size, memory.null_space_read);
}
void memory_remap_write_null(u32 region, u32 size)
{
memory_remap_write_fixed(region, size, memory.null_space_write);
}
void memory_remap_read_write_null(u32 region, u32 size)
{
memory_remap_read_write(region, size, memory.null_space_read,
memory.null_space_write);
}
u32 io_buffer_read()
{
return memory.io_buffer;
}
u32 zero_read()
{
return 0;
}
u32 zero_three_read()
{
return 0x03;
}
u32 five_five_read()
{
return 0x55;
}
u32 aa_read()
{
return 0xAA;
}
u32 ff_read()
{
memory.io_buffer = 0xFF;
return 0xFF;
}
void null_write(u32 value)
{
}
void setup_io_tables()
{
u32 i;
io_read_function_ptr *current_io_read_function =
memory.io_read_functions;
io_write_function_ptr *current_io_write_function =
memory.io_write_functions;
printf("Initializing I/O tables.\n");
// VDC section: 0x0000 to 0x03FF
if(config.sgx_mode)
{
printf("Using SGX VDC map.\n");
for(i = 0; i < (0x400 / 0x20); i++, current_io_read_function += 0x20,
current_io_write_function += 0x20)
{
current_io_read_function[0x0] = vdc_status_vdc_a;
current_io_read_function[0x1] = zero_read;
current_io_read_function[0x2] = vdc_data_read_low_vdc_a;
current_io_read_function[0x3] = vdc_data_read_high_vdc_a;
current_io_read_function[0x4] = vdc_status_vdc_a;
current_io_read_function[0x5] = zero_read;
current_io_read_function[0x6] = vdc_data_read_low_vdc_a;
current_io_read_function[0x7] = vdc_data_read_high_vdc_a;
current_io_read_function[0x8] = vpc_read_window_status_low;
current_io_read_function[0x9] = vpc_read_window_status_high;
current_io_read_function[0xA] = vpc_read_window1_low;
current_io_read_function[0xB] = vpc_read_window1_high;
current_io_read_function[0xC] = vpc_read_window2_low;
current_io_read_function[0xD] = vpc_read_window2_high;
current_io_read_function[0xE] = zero_read;
current_io_read_function[0xF] = zero_read;
current_io_read_function[0x10] = vdc_status_vdc_b;
current_io_read_function[0x11] = zero_read;
current_io_read_function[0x12] = vdc_data_read_low_vdc_b;
current_io_read_function[0x13] = vdc_data_read_high_vdc_b;
current_io_read_function[0x14] = vdc_status_vdc_b;
current_io_read_function[0x15] = zero_read;
current_io_read_function[0x16] = vdc_data_read_low_vdc_b;
current_io_read_function[0x17] = vdc_data_read_high_vdc_b;
current_io_read_function[0x18] = zero_read;
current_io_read_function[0x19] = zero_read;
current_io_read_function[0x1A] = zero_read;
current_io_read_function[0x1B] = zero_read;
current_io_read_function[0x1C] = zero_read;
current_io_read_function[0x1D] = zero_read;
current_io_read_function[0x1E] = zero_read;
current_io_read_function[0x1F] = zero_read;
current_io_write_function[0x0] = vdc_register_select_vdc_a;
current_io_write_function[0x1] = null_write;
current_io_write_function[0x2] = vdc_data_write_low_vdc_a;
current_io_write_function[0x3] = vdc_data_write_high_vdc_a;
current_io_write_function[0x4] = vdc_register_select_vdc_a;
current_io_write_function[0x5] = null_write;
current_io_write_function[0x6] = vdc_data_write_low_vdc_a;
current_io_write_function[0x7] = vdc_data_write_high_vdc_a;
current_io_write_function[0x8] = vpc_write_window_status_low;
current_io_write_function[0x9] = vpc_write_window_status_high;
current_io_write_function[0xA] = vpc_write_window1_low;
current_io_write_function[0xB] = vpc_write_window1_high;
current_io_write_function[0xC] = vpc_write_window2_low;
current_io_write_function[0xD] = vpc_write_window2_high;
current_io_write_function[0xE] = vpc_select;
current_io_write_function[0xF] = null_write;
current_io_write_function[0x10] = vdc_register_select_vdc_b;
current_io_write_function[0x11] = null_write;
current_io_write_function[0x12] = vdc_data_write_low_vdc_b;
current_io_write_function[0x13] = vdc_data_write_high_vdc_b;
current_io_write_function[0x14] = vdc_register_select_vdc_b;
current_io_write_function[0x15] = null_write;
current_io_write_function[0x16] = vdc_data_write_low_vdc_b;
current_io_write_function[0x17] = vdc_data_write_high_vdc_b;
current_io_write_function[0x18] = null_write;
current_io_write_function[0x19] = null_write;
current_io_write_function[0x1A] = null_write;
current_io_write_function[0x1B] = null_write;
current_io_write_function[0x1C] = null_write;
current_io_write_function[0x1D] = null_write;
current_io_write_function[0x1E] = null_write;
current_io_write_function[0x1F] = null_write;
}
}
else
{
for(i = 0; i < (0x400 / 0x4); i++, current_io_read_function += 0x4,
current_io_write_function += 0x4)
{
current_io_read_function[0x0] = vdc_status_vdc_a;
current_io_read_function[0x1] = zero_read;
current_io_read_function[0x2] = vdc_data_read_low_vdc_a;
current_io_read_function[0x3] = vdc_data_read_high_vdc_a;
current_io_write_function[0x0] = vdc_register_select_vdc_a;
current_io_write_function[0x1] = null_write;
current_io_write_function[0x2] = vdc_data_write_low_vdc_a;
current_io_write_function[0x3] = vdc_data_write_high_vdc_a;
}
}
// VCE section: 0x0400 to 0x7FF
for(i = 0; i < (0x400 / 0x8); i++, current_io_read_function += 0x8,
current_io_write_function += 8)
{
current_io_read_function[0x0] = ff_read;
current_io_read_function[0x1] = ff_read;
current_io_read_function[0x2] = ff_read;
current_io_read_function[0x3] = ff_read;
current_io_read_function[0x4] = vce_data_read_low;
current_io_read_function[0x5] = vce_data_read_high;
current_io_read_function[0x6] = ff_read;
current_io_read_function[0x7] = ff_read;
current_io_write_function[0x0] = vce_control_write;
current_io_write_function[0x1] = null_write;
current_io_write_function[0x2] = vce_address_write_low;
current_io_write_function[0x3] = vce_address_write_high;
current_io_write_function[0x4] = vce_data_write_low;
current_io_write_function[0x5] = vce_data_write_high;
current_io_write_function[0x6] = null_write;
current_io_write_function[0x7] = null_write;
}
// PSG section: 0x0800 to 0x0BFF
for(i = 0; i < (0x400 / 0x10); i++, current_io_read_function += 0x10,
current_io_write_function += 0x10)
{
current_io_read_function[0x0] = io_buffer_read;
current_io_read_function[0x1] = io_buffer_read;
current_io_read_function[0x2] = io_buffer_read;
current_io_read_function[0x3] = io_buffer_read;
current_io_read_function[0x4] = io_buffer_read;
current_io_read_function[0x5] = io_buffer_read;
current_io_read_function[0x6] = io_buffer_read;
current_io_read_function[0x7] = io_buffer_read;
current_io_read_function[0x8] = io_buffer_read;
current_io_read_function[0x9] = io_buffer_read;
current_io_read_function[0xA] = io_buffer_read;
current_io_read_function[0xB] = io_buffer_read;
current_io_read_function[0xC] = io_buffer_read;
current_io_read_function[0xD] = io_buffer_read;
current_io_read_function[0xE] = io_buffer_read;
current_io_read_function[0xF] = io_buffer_read;
current_io_write_function[0x0] = psg_channel_select;
current_io_write_function[0x1] = psg_global_balance;
current_io_write_function[0x2] = psg_fine_frequency;
current_io_write_function[0x3] = psg_rough_frequency;
current_io_write_function[0x4] = psg_channel_control;
current_io_write_function[0x5] = psg_channel_balance;
current_io_write_function[0x6] = psg_sound_data;
current_io_write_function[0x7] = psg_noise_control;
current_io_write_function[0x8] = psg_lfo_frequency;
current_io_write_function[0x9] = psg_lfo_control;
current_io_write_function[0xA] = null_write;
current_io_write_function[0xB] = null_write;
current_io_write_function[0xC] = null_write;
current_io_write_function[0xD] = null_write;
current_io_write_function[0xE] = null_write;
current_io_write_function[0xF] = null_write;
}
// Timer section: 0x0C00 to 0x0FFF
for(i = 0; i < (0x400 / 0x2); i++, current_io_read_function += 0x2,
current_io_write_function += 0x2)
{
current_io_read_function[0x0] = timer_value_read;
current_io_read_function[0x1] = timer_enable_read;
current_io_write_function[0x0] = timer_reload_write;
current_io_write_function[0x1] = timer_enable_write;
}
// IO section: 0x1000 to 0x13FF
for(i = 0; i < 0x400; i++, current_io_read_function++,
current_io_write_function++)
{
current_io_read_function[0x0] = io_port_read;
current_io_write_function[0x0] = io_port_write;
}
// IRQ section: 0x1400 to 0x17FF
for(i = 0; i < (0x400 / 0x4); i++, current_io_read_function += 0x4,
current_io_write_function += 0x4)
{
current_io_read_function[0x0] = io_buffer_read;
current_io_read_function[0x1] = io_buffer_read;
current_io_read_function[0x2] = irq_read_enable;
current_io_read_function[0x3] = irq_read_status;
current_io_write_function[0x0] = null_write;
current_io_write_function[0x1] = null_write;
current_io_write_function[0x2] = irq_write_enable;
current_io_write_function[0x3] = irq_write_status;
}
// CD-ROM section: 0x1800 to 0x180F, and 0x18Cx
for(i = 0; i < (0x400 / 0x10); i++, current_io_read_function += 0x10,
current_io_write_function += 0x10)
{
if((i & 0xC) == 0xC)
{
current_io_read_function[0x0] = zero_read;
current_io_read_function[0x1] = aa_read;
current_io_read_function[0x2] = five_five_read;
current_io_read_function[0x3] = zero_read;
current_io_read_function[0x4] = zero_read;
current_io_read_function[0x5] = aa_read;
current_io_read_function[0x6] = five_five_read;
current_io_read_function[0x7] = zero_three_read;
current_io_read_function[0x8] = zero_read;
current_io_read_function[0x9] = zero_read;
current_io_read_function[0xA] = zero_read;
current_io_read_function[0xB] = zero_read;
current_io_read_function[0xC] = zero_read;
current_io_read_function[0xD] = zero_read;
current_io_read_function[0xE] = zero_read;
current_io_read_function[0xF] = zero_read;
}
else
{
if(i < 0x1)
{
current_io_read_function[0x0] = cd_bus_status;
current_io_read_function[0x1] = cd_read_data;
current_io_read_function[0x2] = cd_read_irq_enable;
current_io_read_function[0x3] = cd_irq_status;
current_io_read_function[0x4] = cd_read_reset;
current_io_read_function[0x5] = cd_read_cdda_low;
current_io_read_function[0x6] = cd_read_cdda_high;
current_io_read_function[0x7] = cd_read_sub_channel;
current_io_read_function[0x8] = cd_read_data_acknowledge;
current_io_read_function[0x9] = zero_read;
current_io_read_function[0xA] = adpcm_read;
current_io_read_function[0xB] = adpcm_dma_status;
current_io_read_function[0xC] = adpcm_status;
current_io_read_function[0xD] = adpcm_read_command;
current_io_read_function[0xE] = zero_read;
current_io_read_function[0xF] = zero_read;
}
else
{
current_io_read_function[0x0] = ff_read;
current_io_read_function[0x1] = ff_read;
current_io_read_function[0x2] = ff_read;
current_io_read_function[0x3] = ff_read;
current_io_read_function[0x4] = ff_read;
current_io_read_function[0x5] = ff_read;
current_io_read_function[0x6] = ff_read;
current_io_read_function[0x7] = ff_read;
current_io_read_function[0x8] = ff_read;
current_io_read_function[0x9] = ff_read;
current_io_read_function[0xA] = ff_read;
current_io_read_function[0xB] = ff_read;
current_io_read_function[0xC] = ff_read;
current_io_read_function[0xD] = ff_read;
current_io_read_function[0xE] = ff_read;
current_io_read_function[0xF] = ff_read;
}
}
if(i < 0x1)
{
current_io_write_function[0x0] = cd_select;
current_io_write_function[0x1] = cd_write_data;
current_io_write_function[0x2] = cd_acknowledge;
current_io_write_function[0x3] = null_write;
current_io_write_function[0x4] = cd_write_reset;
current_io_write_function[0x5] = cd_prepare_cdda_read;
current_io_write_function[0x6] = cd_prepare_cdda_read;
current_io_write_function[0x7] = cd_enable_bram;
current_io_write_function[0x8] = adpcm_write_latch_low;
current_io_write_function[0x9] = adpcm_write_latch_high;
current_io_write_function[0xA] = adpcm_write_data;
current_io_write_function[0xB] = adpcm_enable_dma;
current_io_write_function[0xC] = null_write;
current_io_write_function[0xD] = adpcm_write_command;
current_io_write_function[0xE] = adpcm_playback_rate;
current_io_write_function[0xF] = cd_fadeout;
}
else
{
current_io_write_function[0x0] = null_write;
current_io_write_function[0x1] = null_write;
current_io_write_function[0x2] = null_write;
current_io_write_function[0x3] = null_write;
current_io_write_function[0x4] = null_write;
current_io_write_function[0x5] = null_write;
current_io_write_function[0x6] = null_write;
current_io_write_function[0x7] = null_write;
current_io_write_function[0x8] = null_write;
current_io_write_function[0x9] = null_write;
current_io_write_function[0xA] = null_write;
current_io_write_function[0xB] = null_write;
current_io_write_function[0xC] = null_write;
current_io_write_function[0xD] = null_write;
current_io_write_function[0xE] = null_write;
current_io_write_function[0xF] = null_write;
}
}
// And the rest is open bus too
for(i = 0; i < 0x400; i++, current_io_read_function++,
current_io_write_function++)
{
current_io_read_function[0] = ff_read;
current_io_write_function[0] = null_write;
}
}
/*
u8 io_read(u32 address)
{
switch(address >> 10)
{
// VDC (0x0000)
case 0x0:
switch(address & 0x3)
{
case 0x0:
return vdc_status();
case 0x1:
return zero_read();
case 0x2:
return vdc_data_read_low();
case 0x3:
return vdc_data_read_high();
}
break;
// VCE (0x0400)
case 0x1:
switch(address & 0x7)
{
case 0x4:
return vce_data_read_low();
case 0x5:
return vce_data_read_high();
case 0x0:
case 0x1:
case 0x2:
case 0x3:
case 0x6:
case 0x7:
return ff_read();
}
break;
// PSG (0x0800)
case 0x2:
return io_buffer_read();
// Timer (0x0C00)
case 0x3:
switch(address & 0x1)
{
case 0x0:
return timer_value_read();
case 0x1:
return timer_enable_read();
}
break;
// I/O port (0x1000)
case 0x4:
return io_port_read();
// Interrupt control (0x1400)
case 0x5:
switch(address & 0x3)
{
case 0x0:
return io_buffer_read();
case 0x1:
return io_buffer_read();
case 0x2:
return irq_read_enable();
case 0x3:
return irq_read_status();
}
break;
// CD-ROM (0x1800)
case 0x6:
case 0x7:
{
if((address & 0x18c0) == 0x18c0)
{
switch(address & 0xF)
{
case 0x1:
case 0x5:
return 0xAA;
case 0x2:
case 0x6:
return 0x55;
case 0x7:
return 0x03;
case 0x0:
case 0x3:
case 0x4:
case 0x8 ... 0xF:
return 0x00;
}
}
else
{
switch(address & 0xF)
{
case 0x0:
return cd_bus_status();
case 0x1:
return cd_read_data();
case 0x2:
return cd_read_irq_enable();
case 0x3:
return cd_irq_status();
case 0x4:
return cd_read_reset();
case 0x5:
return cd_read_cdda_low();
case 0x6:
return cd_read_cdda_high();
case 0x7:
return cd_read_sub_channel();
case 0x8:
return cd_read_data_acknowledge();
case 0xA:
return adpcm_read();
case 0xB:
return adpcm_dma_status();
case 0xC:
return adpcm_status();
case 0xD:
return adpcm_read_command();
case 0x9:
case 0xE:
case 0xF:
return zero_read();
}
}
}
}
return 0;
}
void io_write(u32 address, u32 value)
{
switch(address >> 10)
{
// VDC (0x0000)
case 0x0:
switch(address & 0x3)
{
case 0x0:
vdc_register_select(value);
break;
case 0x1:
null_write(value);
break;
case 0x2:
vdc_data_write_low(value);
break;
case 0x3:
vdc_data_write_high(value);
break;
}
break;
// VCE (0x0400)
case 0x1:
switch(address & 0x7)
{
case 0x0:
vce_control_write(value);
break;
case 0x2:
vce_address_write_low(value);
break;
case 0x3:
vce_address_write_high(value);
break;
case 0x4:
vce_data_write_low(value);
break;
case 0x5:
vce_data_write_high(value);
break;
case 0x1:
case 0x6:
case 0x7:
null_write(value);
break;
}
break;
// PSG (0x0800)
case 0x2:
switch(address & 0xF)
{
case 0x0:
psg_channel_select(value);
break;
case 0x1:
psg_global_balance(value);
break;
case 0x2:
psg_fine_frequency(value);
break;
case 0x3:
psg_rough_frequency(value);
break;
case 0x4:
psg_channel_control(value);
break;
case 0x5:
psg_channel_balance(value);
break;
case 0x6:
psg_sound_data(value);
break;
case 0x7:
psg_noise_control(value);
break;
case 0x8:
psg_lfo_frequency(value);
break;
case 0x9:
psg_lfo_control(value);
break;
default:
null_write(value);
break;
}
break;
// Timer (0x0C00)
case 0x3:
switch(address & 0x1)
{
case 0x0:
timer_reload_write(value);
break;
case 0x1:
timer_enable_write(value);
break;
}
break;
// I/O port (0x1000)
case 0x4:
io_port_write(value);
break;
// Interrupt control (0x1400)
case 0x5:
switch(address & 0x3)
{
case 0x0:
case 0x1:
null_write(value);
break;
case 0x2:
irq_write_enable(value);
break;
case 0x3:
irq_write_status(value);
break;
}
break;
// Usually CD-ROM (0x1C00)
case 0x7:
if(address >= 0x1FF0)
{
// Street Fighter 2
switch(address & 0x3)
{
case 0x0:
map_sf2_0(value);
break;
case 0x1:
map_sf2_1(value);
break;
case 0x2: