-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppu.cpp
2791 lines (2632 loc) · 64.9 KB
/
ppu.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
/*
* Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
*
* (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
* Jerremy Koot (jkoot@snes9x.com)
*
* Super FX C emulator code
* (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
* Gary Henderson.
* Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
*
* DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
* C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
* C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
*
* DOS port code contains the works of other authors. See headers in
* individual files.
*
* Snes9x homepage: http://www.snes9x.com
*
* Permission to use, copy, modify and distribute Snes9x in both binary and
* source form, for non-commercial purposes, is hereby granted without fee,
* providing that this license information and copyright notice appear with
* all copies and any derived work.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event shall the authors be held liable for any damages
* arising from the use of this software.
*
* Snes9x is freeware for PERSONAL USE only. Commercial users should
* seek permission of the copyright holders first. Commercial use includes
* charging money for Snes9x or software derived from Snes9x.
*
* The copyright holders request that bug fixes and improvements to the code
* should be forwarded to them so everyone can benefit from the modifications
* in future versions.
*
* Super NES and Super Nintendo Entertainment System are trademarks of
* Nintendo Co., Limited and its subsidiary companies.
*/
#include "snes9x.h"
#include "memmap.h"
#include "ppu.h"
#include "cpuexec.h"
#include "missing.h"
#include "apu.h"
#include "dma.h"
#include "gfx.h"
#include "display.h"
#include "sa1.h"
//#include "netplay.h"
#include "sdd1.h"
#include "srtc.h"
#ifndef ZSNES_FX
#include "fxemu.h"
#include "fxinst.h"
extern struct FxInit_s SuperFX;
extern struct FxRegs_s GSU;
#else
EXTERN_C void S9xSuperFXWriteReg (uint8, uint32);
EXTERN_C uint8 S9xSuperFXReadReg (uint32);
#endif
void S9xUpdateHTimer (struct SPPU *ppu, struct SCPUState *cpu)
{
if (ppu->HTimerEnabled)
{
#ifdef DEBUGGER
missing.hirq_pos = ppu->IRQHBeamPos;
#endif
ppu->HTimerPosition = ppu->IRQHBeamPos * Settings.H_Max / SNES_HCOUNTER_MAX;
if (ppu->HTimerPosition == Settings.H_Max ||
ppu->HTimerPosition == Settings.HBlankStart)
{
ppu->HTimerPosition--;
}
if (!ppu->VTimerEnabled || cpu->V_Counter == ppu->IRQVBeamPos)
{
if (ppu->HTimerPosition < cpu->Cycles)
{
// Missed the IRQ on this line already
if (cpu->WhichEvent == HBLANK_END_EVENT ||
cpu->WhichEvent == HTIMER_AFTER_EVENT)
{
cpu->WhichEvent = HBLANK_END_EVENT;
cpu->NextEvent = Settings.H_Max;
}
else
{
cpu->WhichEvent = HBLANK_START_EVENT;
cpu->NextEvent = Settings.HBlankStart;
}
}
else
{
if (cpu->WhichEvent == HTIMER_BEFORE_EVENT ||
cpu->WhichEvent == HBLANK_START_EVENT)
{
if (ppu->HTimerPosition > Settings.HBlankStart)
{
// HTimer was to trigger before h-blank start,
// now triggers after start of h-blank
cpu->NextEvent = Settings.HBlankStart;
cpu->WhichEvent = HBLANK_START_EVENT;
}
else
{
cpu->NextEvent = ppu->HTimerPosition;
cpu->WhichEvent = HTIMER_BEFORE_EVENT;
}
}
else
{
cpu->WhichEvent = HTIMER_AFTER_EVENT;
cpu->NextEvent = ppu->HTimerPosition;
}
}
}
}
}
void S9xFixColourBrightness ()
{
IPPU.XB = mul_brightness [PPU.Brightness];
#ifndef _ZAURUS
if (Settings.SixteenBit)
#endif
{
for (int i = 0; i < 256; i++)
{
IPPU.Red [i] = IPPU.XB [PPU.CGDATA [i] & 0x1f];
IPPU.Green [i] = IPPU.XB [(PPU.CGDATA [i] >> 5) & 0x1f];
IPPU.Blue [i] = IPPU.XB [(PPU.CGDATA [i] >> 10) & 0x1f];
IPPU.ScreenColors [i] = BUILD_PIXEL (IPPU.Red [i], IPPU.Green [i],
IPPU.Blue [i]);
}
}
}
/**********************************************************************************************/
/* S9xSetPPU() */
/* This function sets a PPU Register to a specific byte */
/**********************************************************************************************/
void S9xSetPPU (uint8 Byte, uint16 Address, struct SPPU *ppu, struct InternalPPU *ippu)
{
if (Address <= 0x2183)
{
switch (Address)
{
case 0x2100 :
// Brightness and screen blank bit
if (Byte != Memory.FillRAM[0x2100])
{
FLUSH_REDRAW();
if (ppu->Brightness != (Byte & 0xF))
{
ippu->ColorsChanged = TRUE;
ippu->DirectColourMapsNeedRebuild = TRUE;
ppu->Brightness = Byte & 0xF;
S9xFixColourBrightness();
if (ppu->Brightness > ippu->MaxBrightness)
ippu->MaxBrightness = ppu->Brightness;
}
if ((Memory.FillRAM[0x2100] & 0x80) != (Byte & 0x80))
{
ippu->ColorsChanged = TRUE;
ppu->ForcedBlanking = (Byte >> 7) & 1;
}
}
break;
case 0x2101 :
// Sprite (OBJ) tile address
if (Byte != Memory.FillRAM[0x2101])
{
FLUSH_REDRAW();
ppu->OBJNameBase = (Byte & 3) << 14;
ppu->OBJNameSelect = ((Byte >> 3) & 3) << 13;
ppu->OBJSizeSelect = (Byte >> 5) & 7;
ippu->OBJChanged = TRUE;
}
break;
case 0x2102 :
// Sprite write address (low)
ppu->OAMAddr = Byte;
ppu->OAMFlip = 2;
ppu->OAMReadFlip = 0;
ppu->SavedOAMAddr = ppu->OAMAddr;
if (ppu->OAMPriorityRotation)
{
ppu->FirstSprite = ppu->OAMAddr & 0x7f;
#ifdef DEBUGGER
missing.sprite_priority_rotation = 1;
#endif
}
break;
case 0x2103 :
// Sprite register write address (high), sprite priority rotation
// bit.
if ((ppu->OAMPriorityRotation = (Byte & 0x80) == 0 ? 0 : 1))
{
ppu->FirstSprite = ppu->OAMAddr & 0x7f;
#ifdef DEBUGGER
missing.sprite_priority_rotation = 1;
#endif
}
// Only update the sprite write address top bit if the low byte has
// been written to first.
if (ppu->OAMFlip & 2)
{
ppu->OAMAddr &= 0x00FF;
ppu->OAMAddr |= (Byte & 1) << 8;
}
ppu->OAMFlip = 0;
ppu->OAMReadFlip = 0;
ppu->SavedOAMAddr = ppu->OAMAddr;
break;
case 0x2104 :
// Sprite register write
REGISTER_2104(Byte, & Memory, ippu, ppu);
break;
case 0x2105 :
// Screen mode (0 - 7), background tile sizes and background 3
// priority
if (Byte != Memory.FillRAM[0x2105])
{
FLUSH_REDRAW();
ppu->BG3Priority = (Byte >> 3) & 1;
ppu->BG[0].BGSize = (Byte >> 4) & 1;
ppu->BG[1].BGSize = (Byte >> 5) & 1;
ppu->BG[2].BGSize = (Byte >> 6) & 1;
ppu->BG[3].BGSize = (Byte >> 7) & 1;
ppu->BGMode = Byte & 7;
#ifdef DEBUGGER
missing.modes[ppu->BGMode] = 1;
#endif
}
break;
case 0x2106 :
// Mosaic pixel size and enable
if (Byte != Memory.FillRAM[0x2106])
{
FLUSH_REDRAW();
#ifdef DEBUGGER
if ((Byte & 0xf0) && (Byte & 0x0f))
missing.mosaic = 1;
#endif
ppu->Mosaic = (Byte >> 4) + 1;
ppu->BGMosaic[0] = (Byte & 1) && ppu->Mosaic > 1;
ppu->BGMosaic[1] = (Byte & 2) && ppu->Mosaic > 1;
ppu->BGMosaic[2] = (Byte & 4) && ppu->Mosaic > 1;
ppu->BGMosaic[3] = (Byte & 8) && ppu->Mosaic > 1;
}
break;
case 0x2107 : // [BG0SC]
if (Byte != Memory.FillRAM[0x2107])
{
FLUSH_REDRAW();
ppu->BG[0].SCSize = Byte & 3;
ppu->BG[0].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x2108 : // [BG1SC]
if (Byte != Memory.FillRAM[0x2108])
{
FLUSH_REDRAW();
ppu->BG[1].SCSize = Byte & 3;
ppu->BG[1].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x2109 : // [BG2SC]
if (Byte != Memory.FillRAM[0x2109])
{
FLUSH_REDRAW();
ppu->BG[2].SCSize = Byte & 3;
ppu->BG[2].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x210A : // [BG3SC]
if (Byte != Memory.FillRAM[0x210a])
{
FLUSH_REDRAW();
ppu->BG[3].SCSize = Byte & 3;
ppu->BG[3].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x210B : // [BG01NBA]
if (Byte != Memory.FillRAM[0x210b])
{
FLUSH_REDRAW();
ppu->BG[0].NameBase = (Byte & 7) << 12;
ppu->BG[1].NameBase = ((Byte >> 4) & 7) << 12;
}
break;
case 0x210C : // [BG23NBA]
if (Byte != Memory.FillRAM[0x210c])
{
FLUSH_REDRAW();
ppu->BG[2].NameBase = (Byte & 7) << 12;
ppu->BG[3].NameBase = ((Byte >> 4) & 7) << 12;
}
break;
case 0x210D :
ppu->BG[0].HOffset =
((ppu->BG[0].HOffset >> 8) & 0xff) | ((uint16) Byte << 8);
break;
case 0x210E :
ppu->BG[0].VOffset =
((ppu->BG[0].VOffset >> 8) & 0xff) | ((uint16) Byte << 8);
break;
case 0x210F :
ppu->BG[1].HOffset =
((ppu->BG[1].HOffset >> 8) & 0xff) | ((uint16) Byte << 8);
break;
case 0x2110 :
ppu->BG[1].VOffset =
((ppu->BG[1].VOffset >> 8) & 0xff) | ((uint16) Byte << 8);
break;
case 0x2111 :
ppu->BG[2].HOffset =
((ppu->BG[2].HOffset >> 8) & 0xff) | ((uint16) Byte << 8);
break;
case 0x2112 :
ppu->BG[2].VOffset =
((ppu->BG[2].VOffset >> 8) & 0xff) | ((uint16) Byte << 8);
break;
case 0x2113 :
ppu->BG[3].HOffset =
((ppu->BG[3].HOffset >> 8) & 0xff) | ((uint16) Byte << 8);
break;
case 0x2114 :
ppu->BG[3].VOffset =
((ppu->BG[3].VOffset >> 8) & 0xff) | ((uint16) Byte << 8);
break;
case 0x2115 :
// VRAM byte/word access flag and increment
ppu->VMA.High = (Byte & 0x80) == 0 ? FALSE : TRUE;
switch (Byte & 3)
{
case 0 :
ppu->VMA.Increment = 1;
break;
case 1 :
ppu->VMA.Increment = 32;
break;
case 2 :
ppu->VMA.Increment = 128;
break;
case 3 :
ppu->VMA.Increment = 128;
break;
}
#ifdef DEBUGGER
if ((Byte & 3) != 0)
missing.vram_inc = Byte & 3;
#endif
if (Byte & 0x0c)
{
static uint16 IncCount[4] = { 0, 32, 64, 128 };
static uint16 Shift[4] = { 0, 5, 6, 7 };
#ifdef DEBUGGER
missing.vram_full_graphic_inc =
(Byte & 0x0c) >> 2;
#endif
ppu->VMA.Increment = 1;
uint8 i = (Byte & 0x0c) >> 2;
ppu->VMA.FullGraphicCount = IncCount[i];
ppu->VMA.Mask1 = IncCount[i] * 8 - 1;
ppu->VMA.Shift = Shift[i];
}
else
ppu->VMA.FullGraphicCount = 0;
break;
case 0x2116 :
// VRAM read/write address (low)
ppu->VMA.Address &= 0xFF00;
ppu->VMA.Address |= Byte;
ippu->FirstVRAMRead = TRUE;
break;
case 0x2117 :
// VRAM read/write address (high)
ppu->VMA.Address &= 0x00FF;
ppu->VMA.Address |= Byte << 8;
ippu->FirstVRAMRead = TRUE;
break;
case 0x2118 :
// VRAM write data (low)
ippu->FirstVRAMRead = TRUE;
REGISTER_2118(Byte, & Memory, ippu, ppu);
break;
case 0x2119 :
// VRAM write data (high)
ippu->FirstVRAMRead = TRUE;
REGISTER_2119(Byte, & Memory, ippu, ppu);
break;
case 0x211a :
// Mode 7 outside rotation area display mode and flipping
if (Byte != Memory.FillRAM[0x211a])
{
FLUSH_REDRAW();
ppu->Mode7Repeat = Byte >> 6;
ppu->Mode7VFlip = (Byte & 2) >> 1;
ppu->Mode7HFlip = Byte & 1;
}
break;
case 0x211b :
// Mode 7 matrix A (low & high)
ppu->MatrixA = ((ppu->MatrixA >> 8) & 0xff) | (Byte << 8);
ppu->Need16x8Mulitply = TRUE;
break;
case 0x211c :
// Mode 7 matrix B (low & high)
ppu->MatrixB = ((ppu->MatrixB >> 8) & 0xff) | (Byte << 8);
ppu->Need16x8Mulitply = TRUE;
break;
case 0x211d :
// Mode 7 matrix C (low & high)
ppu->MatrixC = ((ppu->MatrixC >> 8) & 0xff) | (Byte << 8);
break;
case 0x211e :
// Mode 7 matrix D (low & high)
ppu->MatrixD = ((ppu->MatrixD >> 8) & 0xff) | (Byte << 8);
break;
case 0x211f :
// Mode 7 centre of rotation X (low & high)
ppu->CentreX = ((ppu->CentreX >> 8) & 0xff) | (Byte << 8);
break;
case 0x2120 :
// Mode 7 centre of rotation Y (low & high)
ppu->CentreY = ((ppu->CentreY >> 8) & 0xff) | (Byte << 8);
break;
case 0x2121 :
// CG-RAM address
ppu->CGFLIP = 0;
ppu->CGFLIPRead = 0;
ppu->CGADD = Byte;
break;
case 0x2122 :
REGISTER_2122(Byte, &Memory, ippu, ppu);
break;
case 0x2123 :
// Window 1 and 2 enable for backgrounds 1 and 2
if (Byte != Memory.FillRAM[0x2123])
{
FLUSH_REDRAW();
ppu->ClipWindow1Enable[0] = !!(Byte & 0x02);
ppu->ClipWindow1Enable[1] = !!(Byte & 0x20);
ppu->ClipWindow2Enable[0] = !!(Byte & 0x08);
ppu->ClipWindow2Enable[1] = !!(Byte & 0x80);
ppu->ClipWindow1Inside[0] = !(Byte & 0x01);
ppu->ClipWindow1Inside[1] = !(Byte & 0x10);
ppu->ClipWindow2Inside[0] = !(Byte & 0x04);
ppu->ClipWindow2Inside[1] = !(Byte & 0x40);
ppu->RecomputeClipWindows = TRUE;
#ifdef DEBUGGER
if (Byte & 0x80)
missing.window2[1] = 1;
if (Byte & 0x20)
missing.window1[1] = 1;
if (Byte & 0x08)
missing.window2[0] = 1;
if (Byte & 0x02)
missing.window1[0] = 1;
#endif
}
break;
case 0x2124 :
// Window 1 and 2 enable for backgrounds 3 and 4
if (Byte != Memory.FillRAM[0x2124])
{
FLUSH_REDRAW();
ppu->ClipWindow1Enable[2] = !!(Byte & 0x02);
ppu->ClipWindow1Enable[3] = !!(Byte & 0x20);
ppu->ClipWindow2Enable[2] = !!(Byte & 0x08);
ppu->ClipWindow2Enable[3] = !!(Byte & 0x80);
ppu->ClipWindow1Inside[2] = !(Byte & 0x01);
ppu->ClipWindow1Inside[3] = !(Byte & 0x10);
ppu->ClipWindow2Inside[2] = !(Byte & 0x04);
ppu->ClipWindow2Inside[3] = !(Byte & 0x40);
ppu->RecomputeClipWindows = TRUE;
#ifdef DEBUGGER
if (Byte & 0x80)
missing.window2[3] = 1;
if (Byte & 0x20)
missing.window1[3] = 1;
if (Byte & 0x08)
missing.window2[2] = 1;
if (Byte & 0x02)
missing.window1[2] = 1;
#endif
}
break;
case 0x2125 :
// Window 1 and 2 enable for objects and colour window
if (Byte != Memory.FillRAM[0x2125])
{
FLUSH_REDRAW();
ppu->ClipWindow1Enable[4] = !!(Byte & 0x02);
ppu->ClipWindow1Enable[5] = !!(Byte & 0x20);
ppu->ClipWindow2Enable[4] = !!(Byte & 0x08);
ppu->ClipWindow2Enable[5] = !!(Byte & 0x80);
ppu->ClipWindow1Inside[4] = !(Byte & 0x01);
ppu->ClipWindow1Inside[5] = !(Byte & 0x10);
ppu->ClipWindow2Inside[4] = !(Byte & 0x04);
ppu->ClipWindow2Inside[5] = !(Byte & 0x40);
ppu->RecomputeClipWindows = TRUE;
#ifdef DEBUGGER
if (Byte & 0x80)
missing.window2[5] = 1;
if (Byte & 0x20)
missing.window1[5] = 1;
if (Byte & 0x08)
missing.window2[4] = 1;
if (Byte & 0x02)
missing.window1[4] = 1;
#endif
}
break;
case 0x2126 :
// Window 1 left position
if (Byte != Memory.FillRAM[0x2126])
{
FLUSH_REDRAW();
ppu->Window1Left = Byte;
ppu->RecomputeClipWindows = TRUE;
}
break;
case 0x2127 :
// Window 1 right position
if (Byte != Memory.FillRAM[0x2127])
{
FLUSH_REDRAW();
ppu->Window1Right = Byte;
ppu->RecomputeClipWindows = TRUE;
}
break;
case 0x2128 :
// Window 2 left position
if (Byte != Memory.FillRAM[0x2128])
{
FLUSH_REDRAW();
ppu->Window2Left = Byte;
ppu->RecomputeClipWindows = TRUE;
}
break;
case 0x2129 :
// Window 2 right position
if (Byte != Memory.FillRAM[0x2129])
{
FLUSH_REDRAW();
ppu->Window2Right = Byte;
ppu->RecomputeClipWindows = TRUE;
}
break;
case 0x212a :
// Windows 1 & 2 overlap logic for backgrounds 1 - 4
if (Byte != Memory.FillRAM[0x212a])
{
FLUSH_REDRAW();
ppu->ClipWindowOverlapLogic[0] = (Byte & 0x03);
ppu->ClipWindowOverlapLogic[1] = (Byte & 0x0c) >> 2;
ppu->ClipWindowOverlapLogic[2] = (Byte & 0x30) >> 4;
ppu->ClipWindowOverlapLogic[3] = (Byte & 0xc0) >> 6;
ppu->RecomputeClipWindows = TRUE;
}
break;
case 0x212b :
// Windows 1 & 2 overlap logic for objects and colour window
if (Byte != Memory.FillRAM[0x212b])
{
FLUSH_REDRAW();
ppu->ClipWindowOverlapLogic[4] = Byte & 0x03;
ppu->ClipWindowOverlapLogic[5] = (Byte & 0x0c) >> 2;
ppu->RecomputeClipWindows = TRUE;
}
break;
case 0x212c :
// Main screen designation (backgrounds 1 - 4 and objects)
if (Byte != Memory.FillRAM[0x212c])
{
FLUSH_REDRAW();
ppu->RecomputeClipWindows = TRUE;
Memory.FillRAM[Address] = Byte;
return;
}
break;
case 0x212d :
// Sub-screen designation (backgrounds 1 - 4 and objects)
if (Byte != Memory.FillRAM[0x212d])
{
FLUSH_REDRAW();
#ifdef DEBUGGER
if (Byte & 0x1f)
missing.subscreen = 1;
#endif
ppu->RecomputeClipWindows = TRUE;
Memory.FillRAM[Address] = Byte;
return;
}
break;
case 0x212e :
// Window mask designation for main screen ?
if (Byte != Memory.FillRAM[0x212e])
{
FLUSH_REDRAW();
ppu->RecomputeClipWindows = TRUE;
}
break;
case 0x212f :
// Window mask designation for sub-screen ?
if (Byte != Memory.FillRAM[0x212f])
{
FLUSH_REDRAW();
ppu->RecomputeClipWindows = TRUE;
}
break;
case 0x2130 :
// Fixed colour addition or screen addition
if (Byte != Memory.FillRAM[0x2130])
{
FLUSH_REDRAW();
ppu->RecomputeClipWindows = TRUE;
#ifdef DEBUGGER
if ((Byte & 1) && (ppu->BGMode == 3 || ppu->BGMode == 4
|| ppu->BGMode == 7))
missing.direct = 1;
#endif
}
break;
case 0x2131 :
// Colour addition or subtraction select
if (Byte != Memory.FillRAM[0x2131])
{
FLUSH_REDRAW();
// Backgrounds 1 - 4, objects and backdrop colour add/sub enable
#ifdef DEBUGGER
if (Byte & 0x80)
{
// Subtract
if (Memory.FillRAM[0x2130] & 0x02)
missing.subscreen_sub = 1;
else
missing.fixed_colour_sub = 1;
}
else
{
// Addition
if (Memory.FillRAM[0x2130] & 0x02)
missing.subscreen_add = 1;
else
missing.fixed_colour_add = 1;
}
#endif
Memory.FillRAM[0x2131] = Byte;
}
break;
case 0x2132 :
if (Byte != Memory.FillRAM[0x2132])
{
FLUSH_REDRAW();
// Colour data for fixed colour addition/subtraction
if (Byte & 0x80)
ppu->FixedColourBlue = Byte & 0x1f;
if (Byte & 0x40)
ppu->FixedColourGreen = Byte & 0x1f;
if (Byte & 0x20)
ppu->FixedColourRed = Byte & 0x1f;
}
break;
case 0x2133 :
// Screen settings
if (Byte != Memory.FillRAM[0x2133])
{
#ifdef DEBUGGER
if (Byte & 0x40)
missing.mode7_bgmode = 1;
if (Byte & 0x08)
missing.pseudo_512 = 1;
#endif
if (Byte & 0x04)
{
ppu->ScreenHeight = SNES_HEIGHT_EXTENDED;
#ifdef DEBUGGER
missing.lines_239 = 1;
#endif
}
else
ppu->ScreenHeight = SNES_HEIGHT;
#ifdef DEBUGGER
if (Byte & 0x02)
missing.sprite_double_height = 1;
if (Byte & 1)
missing.interlace = 1;
#endif
}
break;
case 0x2134 :
case 0x2135 :
case 0x2136 :
// Matrix 16bit x 8bit multiply result (read-only)
return;
case 0x2137 :
// Software latch for horizontal and vertical timers (read-only)
return;
case 0x2138 :
// OAM read data (read-only)
return;
case 0x2139 :
case 0x213a :
// VRAM read data (read-only)
return;
case 0x213b :
// CG-RAM read data (read-only)
return;
case 0x213c :
case 0x213d :
// Horizontal and vertical (low/high) read counter (read-only)
return;
case 0x213e :
// PPU status (time over and range over)
return;
case 0x213f :
// NTSC/PAL select and field (read-only)
return;
case 0x2140 :
case 0x2141 :
case 0x2142 :
case 0x2143 :
case 0x2144 :
case 0x2145 :
case 0x2146 :
case 0x2147 :
case 0x2148 :
case 0x2149 :
case 0x214a :
case 0x214b :
case 0x214c :
case 0x214d :
case 0x214e :
case 0x214f :
case 0x2150 :
case 0x2151 :
case 0x2152 :
case 0x2153 :
case 0x2154 :
case 0x2155 :
case 0x2156 :
case 0x2157 :
case 0x2158 :
case 0x2159 :
case 0x215a :
case 0x215b :
case 0x215c :
case 0x215d :
case 0x215e :
case 0x215f :
case 0x2160 :
case 0x2161 :
case 0x2162 :
case 0x2163 :
case 0x2164 :
case 0x2165 :
case 0x2166 :
case 0x2167 :
case 0x2168 :
case 0x2169 :
case 0x216a :
case 0x216b :
case 0x216c :
case 0x216d :
case 0x216e :
case 0x216f :
case 0x2170 :
case 0x2171 :
case 0x2172 :
case 0x2173 :
case 0x2174 :
case 0x2175 :
case 0x2176 :
case 0x2177 :
case 0x2178 :
case 0x2179 :
case 0x217a :
case 0x217b :
case 0x217c :
case 0x217d :
case 0x217e :
case 0x217f :
#ifdef SPCTOOL
_SPCInPB(Address & 3, Byte);
#else
// CPU.Flags |= DEBUG_MODE_FLAG;
Memory.FillRAM[Address] = Byte;
IAPU.RAM[(Address & 3) + 0xf4] = Byte;
#ifdef SPC700_SHUTDOWN
IAPU.APUExecuting = Settings.APUEnabled;
IAPU.WaitCounter++;
#endif
#endif // SPCTOOL
break;
case 0x2180 :
REGISTER_2180(Byte, &Memory,ippu, ppu);
break;
case 0x2181 :
ppu->WRAM &= 0x1FF00;
ppu->WRAM |= Byte;
break;
case 0x2182 :
ppu->WRAM &= 0x100FF;
ppu->WRAM |= Byte << 8;
break;
case 0x2183 :
ppu->WRAM &= 0x0FFFF;
ppu->WRAM |= Byte << 16;
ppu->WRAM &= 0x1FFFF;
break;
}
}
else
{
#ifndef _ZAURUS
if (Settings.SA1)
{
if (Address >= 0x2200 && Address < 0x23ff)
S9xSetSA1(Byte, Address);
else
Memory.FillRAM[Address] = Byte;
return;
}
else
// Dai Kaijyu Monogatari II
if (Address == 0x2801 && Settings.SRTC)
S9xSetSRTC(Byte, Address);
else if (Address < 0x3000 || Address >= 0x3000 + 768)
{
#ifdef DEBUGGER
missing.unknownppu_write = Address;
if (Settings.TraceUnknownRegisters)
{
sprintf(
String,
"Unknown register write: $%02X->$%04X\n",
Byte,
Address);
S9xMessage(S9X_TRACE, S9X_PPU_TRACE, String);
}
#endif
}
else
{
if (!Settings.SuperFX)
return;
#ifdef ZSNES_FX
Memory.FillRAM[Address] = Byte;
if (Address < 0x3040)
S9xSuperFXWriteReg(Byte, Address);
#else
switch (Address)
{
case 0x3030 :
if ((Memory.FillRAM[0x3030] ^ Byte) & FLG_G)
{
Memory.FillRAM[Address] = Byte;
// Go flag has been changed
if (Byte & FLG_G)
S9xSuperFXExec();
else
FxFlushCache(& GSU);
}
else
Memory.FillRAM[Address] = Byte;
break;
case 0x3031 :
Memory.FillRAM[Address] = Byte;
break;
case 0x3033 :
Memory.FillRAM[Address] = Byte;
break;
case 0x3034 :
Memory.FillRAM[Address] = Byte & 0x7f;
break;
case 0x3036 :
Memory.FillRAM[Address] = Byte & 0x7f;
break;
case 0x3037 :
Memory.FillRAM[Address] = Byte;
break;
case 0x3038 :
Memory.FillRAM[Address] = Byte;
break;
case 0x3039 :
Memory.FillRAM[Address] = Byte;
break;
case 0x303a :
Memory.FillRAM[Address] = Byte;
break;
case 0x303b :
break;
case 0x303f :
Memory.FillRAM[Address] = Byte;
break;
case 0x301f :
Memory.FillRAM[Address] = Byte;
Memory.FillRAM[0x3000 + GSU_SFR] |= FLG_G;
S9xSuperFXExec();
return;
default :
Memory.FillRAM[Address] = Byte;
if (Address >= 0x3100)
{
FxCacheWriteAccess(Address, & GSU);
}
break;
}
#endif
return;
}
#endif
}
Memory.FillRAM[Address] = Byte;
}
/**********************************************************************************************/
/* S9xGetPPU() */
/* This function retrieves a PPU Register */
/**********************************************************************************************/
uint8 S9xGetPPU(uint16 Address, struct SPPU *ppu, CMemory *mem)
{
uint8 byte = 0;
if (Address <= 0x2190)
{
switch (Address)
{
case 0x2100 :
case 0x2101 :
return (mem->FillRAM[Address]);
case 0x2102 :
#ifdef DEBUGGER
missing.oam_address_read = 1;
#endif
return (uint8) (ppu->OAMAddr);
case 0x2103 :
return (((ppu->OAMAddr >> 8) & 1) | (ppu->OAMPriorityRotation << 7));
case 0x2104 :
case 0x2105 :
case 0x2106 :
case 0x2107 :
case 0x2108 :