-
Notifications
You must be signed in to change notification settings - Fork 30
/
ppu.cpp
3261 lines (3046 loc) · 78.6 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 ([email protected]) and
* Jerremy Koot ([email protected])
*
* Super FX C emulator code
* (c) Copyright 1997 - 1999 Ivar ([email protected]) 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 ([email protected]).
*
* 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"
#if not (defined(__os9x__)||defined(__psp__))
#include "netplay.h"
#endif
#include "sdd1.h"
#include "srtc.h"
#include "bsx.h"
extern uint32 os9x_gammavalue;
extern int debug_counts[];
extern char str_tmp[256];
extern unsigned char gammatab[10][32];
#ifndef ZSNES_FX
#include "fxemu.h"
#include "fxinst.h"
extern struct FxInit_s SuperFX;
#else
EXTERN_C void S9xSuperFXWriteReg (uint8, uint32);
EXTERN_C uint8 S9xSuperFXReadReg (uint32);
#endif
void ComputeClipWindowsFix();
void S9xUpdateHTimer ()
{
if (PPUPack.PPU.HTimerEnabled)
{
#ifdef DEBUGGER
missing.hirq_pos = PPUPack.PPU.IRQHBeamPos;
#endif
PPUPack.PPU.HTimerPosition = PPUPack.PPU.IRQHBeamPos * Settings.H_Max / SNES_HCOUNTER_MAX;
if (PPUPack.PPU.HTimerPosition == Settings.H_Max ||
PPUPack.PPU.HTimerPosition == Settings.HBlankStart)
{
PPUPack.PPU.HTimerPosition--;
}
if (!PPUPack.PPU.VTimerEnabled || CPU.V_Counter == PPUPack.PPU.IRQVBeamPos)
{
if (PPUPack.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;
S9x_Current_HBlank_Event=S9xDoHBlankProcessing_HBLANK_END_EVENT;
CPU.NextEvent = Settings.H_Max;
}
else
{
CPU.WhichEvent = HBLANK_START_EVENT;
S9x_Current_HBlank_Event=S9xDoHBlankProcessing_HBLANK_START_EVENT;
CPU.NextEvent = Settings.HBlankStart;
}
}
else
{
if (CPU.WhichEvent == HTIMER_BEFORE_EVENT ||
CPU.WhichEvent == HBLANK_START_EVENT)
{
if (PPUPack.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;
S9x_Current_HBlank_Event=S9xDoHBlankProcessing_HBLANK_START_EVENT;
}
else
{
CPU.NextEvent = PPUPack.PPU.HTimerPosition;
CPU.WhichEvent = HTIMER_BEFORE_EVENT;
S9x_Current_HBlank_Event=S9xDoHBlankProcessing_HTIMER_BEFORE_EVENT;
}
}
else
{
CPU.WhichEvent = HTIMER_AFTER_EVENT;
S9x_Current_HBlank_Event=S9xDoHBlankProcessing_HTIMER_AFTER_EVENT;
CPU.NextEvent = PPUPack.PPU.HTimerPosition;
}
}
}
}
}
void S9xFixColourBrightness ()
{
IPPU.XB = mul_brightness [PPUPack.PPU.Brightness];
// if (Settings.SixteenBit)
{
for (int i = 0; i < 256; i++)
{
IPPU.Red [i] = gammatab[os9x_gammavalue][IPPU.XB [PPUPack.PPU.CGDATA [i] & 0x1f]];
IPPU.Green [i] = gammatab[os9x_gammavalue][IPPU.XB [(PPUPack.PPU.CGDATA [i] >> 5) & 0x1f]];
IPPU.Blue [i] = gammatab[os9x_gammavalue][IPPU.XB [(PPUPack.PPU.CGDATA [i] >> 10) & 0x1f]];
IPPU.ScreenColors [i]=BUILD_PIXEL(IPPU.Red [i],IPPU.Green [i],IPPU.Blue [i]);
}
//YOYO
os9x_ColorsChanged=1;
}
}
/**********************************************************************************************/
/* S9xSetPPU() */
/* This function sets a PPU Register to a specific byte */
/**********************************************************************************************/
#ifdef yoyo__PSP__
#include "opti/ppu_setppu.h"
#else
void S9xSetPPU (uint8 Byte, uint16 Address)
{
int apu_ram_write_pos;
if (Address <= 0x2183)
{
switch (Address)
{
case 0x2100:
// Brightness and screen blank bit
if (Byte != ROM_GLOBAL [0x2100])
{
//extern int debug_Line[20];
//extern int debug_Value[20];
//static int i=0;
//debug_Line[i]=IPPU.CurrentLine;
//debug_Value[i]=Byte;
//i++;
//if(i==20)i=0;
INFO_FLUSH_REDRAW("2100");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(0);
if (PPUPack.PPU.Brightness != (Byte & 0xF))
{
IPPU.ColorsChanged = TRUE;
IPPU.DirectColourMapsNeedRebuild = TRUE;
PPUPack.PPU.Brightness = Byte & 0xF;
S9xFixColourBrightness ();
if (PPUPack.PPU.Brightness > IPPU.MaxBrightness)
IPPU.MaxBrightness = PPUPack.PPU.Brightness;
}
if ((ROM_GLOBAL[0x2100] & 0x80) != (Byte & 0x80))
{
IPPU.ColorsChanged = TRUE;
PPUPack.PPU.ForcedBlanking = (Byte >> 7) & 1;
}
}
break;
case 0x2101:
// Sprite (OBJ) tile address
if (Byte != ROM_GLOBAL [0x2101])
{
INFO_FLUSH_REDRAW("2101");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(1);
PPUPack.PPU.OBJNameBase = (Byte & 3) << 14;
PPUPack.PPU.OBJNameSelect = ((Byte >> 3) & 3) << 13;
PPUPack.PPU.OBJSizeSelect = (Byte >> 5) & 7;
IPPU.OBJChanged = TRUE;
}
break;
case 0x2102:
// Sprite write address (low)
PPUPack.PPU.OAMAddr = Byte;
PPUPack.PPU.OAMFlip = 2;
PPUPack.PPU.OAMReadFlip = 0;
PPUPack.PPU.SavedOAMAddr = PPUPack.PPU.OAMAddr;
if (PPUPack.PPU.OAMPriorityRotation)
{
PPUPack.PPU.FirstSprite = PPUPack.PPU.OAMAddr & 0x7f;
#ifdef DEBUGGER
missing.sprite_priority_rotation = 1;
#endif
}
break;
case 0x2103:
// Sprite register write address (high), sprite priority rotation
// bit.
if ((PPUPack.PPU.OAMPriorityRotation = (Byte & 0x80) == 0 ? 0 : 1))
{
PPUPack.PPU.FirstSprite = PPUPack.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 (PPUPack.PPU.OAMFlip & 2)
{
PPUPack.PPU.OAMAddr &= 0x00FF;
PPUPack.PPU.OAMAddr |= (Byte & 1) << 8;
}
PPUPack.PPU.OAMFlip = 0;
PPUPack.PPU.OAMReadFlip = 0;
PPUPack.PPU.SavedOAMAddr = PPUPack.PPU.OAMAddr;
break;
case 0x2104:
// Sprite register write
REGISTER_2104(Byte);
break;
case 0x2105:
// Screen mode (0 - 7), background tile sizes and background 3
// priority
if (Byte != ROM_GLOBAL [0x2105])
{
INFO_FLUSH_REDRAW("2105");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(2);
PPUPack.PPU.BG3Priority = (Byte >> 3) & 1;
PPUPack.PPU.BG[0].BGSize = (Byte >> 4) & 1;
PPUPack.PPU.BG[1].BGSize = (Byte >> 5) & 1;
PPUPack.PPU.BG[2].BGSize = (Byte >> 6) & 1;
PPUPack.PPU.BG[3].BGSize = (Byte >> 7) & 1;
PPUPack.PPU.BGMode = Byte & 7;
#ifdef DEBUGGER
missing.modes[PPUPack.PPU.BGMode] = 1;
#endif
}
break;
case 0x2106:
// Mosaic pixel size and enable
if (Byte != ROM_GLOBAL [0x2106])
{
INFO_FLUSH_REDRAW("2106");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(3);
#ifdef DEBUGGER
if ((Byte & 0xf0) && (Byte & 0x0f))
missing.mosaic = 1;
#endif
PPUPack.PPU.Mosaic = (Byte >> 4) + 1;
PPUPack.PPU.BGMosaic [0] = (Byte & 1) && PPUPack.PPU.Mosaic > 1;
PPUPack.PPU.BGMosaic [1] = (Byte & 2) && PPUPack.PPU.Mosaic > 1;
PPUPack.PPU.BGMosaic [2] = (Byte & 4) && PPUPack.PPU.Mosaic > 1;
PPUPack.PPU.BGMosaic [3] = (Byte & 8) && PPUPack.PPU.Mosaic > 1;
}
break;
case 0x2107: // [BG0SC]
if (Byte != ROM_GLOBAL [0x2107])
{
INFO_FLUSH_REDRAW("2107");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(4);
PPUPack.PPU.BG[0].SCSize = Byte & 3;
PPUPack.PPU.BG[0].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x2108: // [BG1SC]
if (Byte != ROM_GLOBAL [0x2108])
{
INFO_FLUSH_REDRAW("2108");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(5);
PPUPack.PPU.BG[1].SCSize = Byte & 3;
PPUPack.PPU.BG[1].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x2109: // [BG2SC]
if (Byte != ROM_GLOBAL [0x2109])
{
INFO_FLUSH_REDRAW("2109");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(6);
PPUPack.PPU.BG[2].SCSize = Byte & 3;
PPUPack.PPU.BG[2].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x210A: // [BG3SC]
if (Byte != ROM_GLOBAL [0x210a])
{
INFO_FLUSH_REDRAW("210A");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(7);
PPUPack.PPU.BG[3].SCSize = Byte & 3;
PPUPack.PPU.BG[3].SCBase = (Byte & 0x7c) << 8;
}
break;
case 0x210B: // [BG01NBA]
if (Byte != ROM_GLOBAL [0x210b])
{
INFO_FLUSH_REDRAW("210B");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(8);
PPUPack.PPU.BG[0].NameBase = (Byte & 7) << 12;
PPUPack.PPU.BG[1].NameBase = ((Byte >> 4) & 7) << 12;
}
break;
case 0x210C: // [BG23NBA]
if (Byte != ROM_GLOBAL [0x210c])
{
INFO_FLUSH_REDRAW("210C");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(9);
PPUPack.PPU.BG[2].NameBase = (Byte & 7) << 12;
PPUPack.PPU.BG[3].NameBase = ((Byte >> 4) & 7) << 12;
}
break;
case 0x210D:
PPUPack.PPU.BG[0].HOffset = PPUPack.PPU.BG[0].HOffset_Byte[HIGHBYTE] | ((uint16) Byte << 8);
break;
case 0x210E:
PPUPack.PPU.BG[0].VOffset = PPUPack.PPU.BG[0].VOffset_Byte[HIGHBYTE] | ((uint16) Byte << 8);
break;
case 0x210F:
PPUPack.PPU.BG[1].HOffset = PPUPack.PPU.BG[1].HOffset_Byte[HIGHBYTE] | ((uint16) Byte << 8);
break;
case 0x2110:
PPUPack.PPU.BG[1].VOffset = PPUPack.PPU.BG[1].VOffset_Byte[HIGHBYTE] | ((uint16) Byte << 8);
break;
case 0x2111:
PPUPack.PPU.BG[2].HOffset = PPUPack.PPU.BG[2].HOffset_Byte[HIGHBYTE] | ((uint16) Byte << 8);
break;
case 0x2112:
PPUPack.PPU.BG[2].VOffset = PPUPack.PPU.BG[2].VOffset_Byte[HIGHBYTE] | ((uint16) Byte << 8);
break;
case 0x2113:
PPUPack.PPU.BG[3].HOffset = PPUPack.PPU.BG[3].HOffset_Byte[HIGHBYTE] | ((uint16) Byte << 8);
break;
case 0x2114:
PPUPack.PPU.BG[3].VOffset = PPUPack.PPU.BG[3].VOffset_Byte[HIGHBYTE] | ((uint16) Byte << 8);
break;
case 0x2115:
// VRAM byte/word access flag and increment
PPUPack.PPU.VMA.High = (Byte & 0x80) == 0 ? FALSE : TRUE;
switch (Byte & 3)
{
case 0:
PPUPack.PPU.VMA.Increment = 1;
break;
case 1:
PPUPack.PPU.VMA.Increment = 32;
break;
case 2:
PPUPack.PPU.VMA.Increment = 128;
break;
case 3:
PPUPack.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
PPUPack.PPU.VMA.Increment = 1;
uint8 i = (Byte & 0x0c) >> 2;
PPUPack.PPU.VMA.FullGraphicCount = IncCount [i];
PPUPack.PPU.VMA.Mask1 = IncCount [i] * 8 - 1;
PPUPack.PPU.VMA.Shift = Shift [i];
}
else
PPUPack.PPU.VMA.FullGraphicCount = 0;
break;
case 0x2116:
// VRAM read/write address (low)
PPUPack.PPU.VMA.Address &= 0xFF00;
PPUPack.PPU.VMA.Address |= Byte;
IPPU.FirstVRAMRead = TRUE;
break;
case 0x2117:
// VRAM read/write address (high)
PPUPack.PPU.VMA.Address &= 0x00FF;
PPUPack.PPU.VMA.Address |= Byte << 8;
IPPU.FirstVRAMRead = TRUE;
break;
case 0x2118:
// VRAM write data (low)
IPPU.FirstVRAMRead = TRUE;
REGISTER_2118(Byte);
break;
case 0x2119:
// VRAM write data (high)
IPPU.FirstVRAMRead = TRUE;
REGISTER_2119(Byte);
break;
case 0x211a:
// Mode 7 outside rotation area display mode and flipping
if (Byte != ROM_GLOBAL [0x211a])
{
INFO_FLUSH_REDRAW("211A");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(10);
PPUPack.PPU.Mode7Repeat = Byte >> 6;
PPUPack.PPU.Mode7VFlip = (Byte & 2) >> 1;
PPUPack.PPU.Mode7HFlip = Byte & 1;
}
break;
case 0x211b:
// Mode 7 matrix A (low & high)
PPUPack.PPU.MatrixA = PPUPack.PPU.MatrixA_Byte[HIGHBYTE] | (Byte << 8);
PPUPack.PPU.Need16x8Mulitply = TRUE;
break;
case 0x211c:
// Mode 7 matrix B (low & high)
PPUPack.PPU.MatrixB = PPUPack.PPU.MatrixB_Byte[HIGHBYTE] | (Byte << 8);
PPUPack.PPU.Need16x8Mulitply = TRUE;
break;
case 0x211d:
// Mode 7 matrix C (low & high)
PPUPack.PPU.MatrixC = PPUPack.PPU.MatrixC_Byte[HIGHBYTE] | (Byte << 8);
break;
case 0x211e:
// Mode 7 matrix D (low & high)
PPUPack.PPU.MatrixD = PPUPack.PPU.MatrixD_Byte[HIGHBYTE] | (Byte << 8);
break;
case 0x211f:
// Mode 7 centre of rotation X (low & high)
PPUPack.PPU.CentreX = PPUPack.PPU.CentreX_Byte[HIGHBYTE] | (Byte << 8);
break;
case 0x2120:
// Mode 7 centre of rotation Y (low & high)
PPUPack.PPU.CentreY = PPUPack.PPU.CentreY_Byte[HIGHBYTE] | (Byte << 8);
break;
case 0x2121:
// CG-RAM address
PPUPack.PPU.CGFLIP = 0;
PPUPack.PPU.CGFLIPRead = 0;
PPUPack.PPU.CGADD = Byte;
break;
case 0x2122:
REGISTER_2122(Byte);
break;
case 0x2123:
// Window 1 and 2 enable for backgrounds 1 and 2
if (Byte != ROM_GLOBAL [0x2123])
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("2123");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(11);
PPUPack.PPU.ClipWindow1Enable [0] = !!(Byte & 0x02);
PPUPack.PPU.ClipWindow1Enable [1] = !!(Byte & 0x20);
PPUPack.PPU.ClipWindow2Enable [0] = !!(Byte & 0x08);
PPUPack.PPU.ClipWindow2Enable [1] = !!(Byte & 0x80);
PPUPack.PPU.ClipWindow1Inside [0] = !(Byte & 0x01);
PPUPack.PPU.ClipWindow1Inside [1] = !(Byte & 0x10);
PPUPack.PPU.ClipWindow2Inside [0] = !(Byte & 0x04);
PPUPack.PPU.ClipWindow2Inside [1] = !(Byte & 0x40);
PPUPack.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 != ROM_GLOBAL [0x2124])
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("2124");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(12);
PPUPack.PPU.ClipWindow1Enable [2] = !!(Byte & 0x02);
PPUPack.PPU.ClipWindow1Enable [3] = !!(Byte & 0x20);
PPUPack.PPU.ClipWindow2Enable [2] = !!(Byte & 0x08);
PPUPack.PPU.ClipWindow2Enable [3] = !!(Byte & 0x80);
PPUPack.PPU.ClipWindow1Inside [2] = !(Byte & 0x01);
PPUPack.PPU.ClipWindow1Inside [3] = !(Byte & 0x10);
PPUPack.PPU.ClipWindow2Inside [2] = !(Byte & 0x04);
PPUPack.PPU.ClipWindow2Inside [3] = !(Byte & 0x40);
PPUPack.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 != ROM_GLOBAL [0x2125])
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("2125");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(13);
PPUPack.PPU.ClipWindow1Enable [4] = !!(Byte & 0x02);
PPUPack.PPU.ClipWindow1Enable [5] = !!(Byte & 0x20);
PPUPack.PPU.ClipWindow2Enable [4] = !!(Byte & 0x08);
PPUPack.PPU.ClipWindow2Enable [5] = !!(Byte & 0x80);
PPUPack.PPU.ClipWindow1Inside [4] = !(Byte & 0x01);
PPUPack.PPU.ClipWindow1Inside [5] = !(Byte & 0x10);
PPUPack.PPU.ClipWindow2Inside [4] = !(Byte & 0x04);
PPUPack.PPU.ClipWindow2Inside [5] = !(Byte & 0x40);
PPUPack.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 != ROM_GLOBAL [0x2126])
{
//if(os9x_softrendering<2 || !((PPUPack.PPU.BGMode!=2)&&(!Settings.WrestlemaniaArcade)) || (PPUPack.PPU.BGMode==4) || (PPUPack.PPU.BGMode==7))
if(os9x_softrendering>=2 && !((os9x_hack&OLD_PSP_ACCEL)&&(PPUPack.PPU.BGMode==2)&&(!Settings.WrestlemaniaArcade)) && !((os9x_hack&OLD_PSP_ACCEL)&&(PPUPack.PPU.BGMode==4)) && (PPUPack.PPU.BGMode!=7))
{
ComputeClipWindowsFix();
PPUPack.PPU.Window1Left = Byte;
}
else
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("2126");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(14);
PPUPack.PPU.Window1Left = Byte;
PPUPack.PPU.RecomputeClipWindows = TRUE;
}
}
break;
case 0x2127:
// Window 1 right position
if (Byte != ROM_GLOBAL [0x2127])
{
if(os9x_softrendering>=2 && !((os9x_hack&OLD_PSP_ACCEL)&&(PPUPack.PPU.BGMode==2)&&(!Settings.WrestlemaniaArcade)) && !((os9x_hack&OLD_PSP_ACCEL)&&(PPUPack.PPU.BGMode==4)) && (PPUPack.PPU.BGMode!=7))
{
ComputeClipWindowsFix();
PPUPack.PPU.Window1Right = Byte;
}
else
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("2127");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(15);
PPUPack.PPU.Window1Right = Byte;
PPUPack.PPU.RecomputeClipWindows = TRUE;
}
}
break;
case 0x2128:
// Window 2 left position
if (Byte != ROM_GLOBAL [0x2128])
{
if(os9x_softrendering>=2 && !((os9x_hack&OLD_PSP_ACCEL)&&(PPUPack.PPU.BGMode==2)&&(!Settings.WrestlemaniaArcade)) && !((os9x_hack&OLD_PSP_ACCEL)&&(PPUPack.PPU.BGMode==4)) && (PPUPack.PPU.BGMode!=7))
{
ComputeClipWindowsFix();
PPUPack.PPU.Window2Left = Byte;
}
else
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("2128");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(16);
PPUPack.PPU.Window2Left = Byte;
PPUPack.PPU.RecomputeClipWindows = TRUE;
}
}
break;
case 0x2129:
// Window 2 right position
if (Byte != ROM_GLOBAL [0x2129])
{
if(os9x_softrendering>=2 && !((os9x_hack&OLD_PSP_ACCEL)&&(PPUPack.PPU.BGMode==2)&&(!Settings.WrestlemaniaArcade)) && !((os9x_hack&OLD_PSP_ACCEL)&&(PPUPack.PPU.BGMode==4)) && (PPUPack.PPU.BGMode!=7))
{
ComputeClipWindowsFix();
PPUPack.PPU.Window2Right = Byte;
}
else
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("2129");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(17);
PPUPack.PPU.Window2Right = Byte;
PPUPack.PPU.RecomputeClipWindows = TRUE;
}
}
break;
case 0x212a:
// Windows 1 & 2 overlap logic for backgrounds 1 - 4
if (Byte != ROM_GLOBAL [0x212a])
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("212A");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(18);
PPUPack.PPU.ClipWindowOverlapLogic [0] = (Byte & 0x03);
PPUPack.PPU.ClipWindowOverlapLogic [1] = (Byte & 0x0c) >> 2;
PPUPack.PPU.ClipWindowOverlapLogic [2] = (Byte & 0x30) >> 4;
PPUPack.PPU.ClipWindowOverlapLogic [3] = (Byte & 0xc0) >> 6;
PPUPack.PPU.RecomputeClipWindows = TRUE;
}
break;
case 0x212b:
// Windows 1 & 2 overlap logic for objects and colour window
if (Byte != ROM_GLOBAL [0x212b])
{
if (os9x_hack&PPU_IGNORE_WINDOW) return;
INFO_FLUSH_REDRAW("212B");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(19);
PPUPack.PPU.ClipWindowOverlapLogic [4] = Byte & 0x03;
PPUPack.PPU.ClipWindowOverlapLogic [5] = (Byte & 0x0c) >> 2;
PPUPack.PPU.RecomputeClipWindows = TRUE;
}
break;
case 0x212c:
// Main screen designation (backgrounds 1 - 4 and objects)
if (Byte != ROM_GLOBAL [0x212c])
{
INFO_FLUSH_REDRAW("212C");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(20);
PPUPack.PPU.RecomputeClipWindows = TRUE;
ROM_GLOBAL [Address] = Byte;
return;
}
break;
case 0x212d:
// Sub-screen designation (backgrounds 1 - 4 and objects)
if (Byte != ROM_GLOBAL [0x212d])
{
INFO_FLUSH_REDRAW("212D");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(21);
#ifdef DEBUGGER
if (Byte & 0x1f)
missing.subscreen = 1;
#endif
PPUPack.PPU.RecomputeClipWindows = TRUE;
ROM_GLOBAL [Address] = Byte;
return;
}
break;
case 0x212e:
// Window mask designation for main screen ?
if (Byte != ROM_GLOBAL [0x212e])
{
INFO_FLUSH_REDRAW("212E");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(22);
PPUPack.PPU.RecomputeClipWindows = TRUE;
}
break;
case 0x212f:
// Window mask designation for sub-screen ?
if (Byte != ROM_GLOBAL [0x212f])
{
INFO_FLUSH_REDRAW("212F");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(23);
PPUPack.PPU.RecomputeClipWindows = TRUE;
}
break;
case 0x2130:
// Fixed colour addition or screen addition
if (Byte != ROM_GLOBAL [0x2130])
{
if (os9x_hack&PPU_IGNORE_ADDSUB) return;
INFO_FLUSH_REDRAW("2130");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(24);
PPUPack.PPU.RecomputeClipWindows = TRUE;
#ifdef DEBUGGER
if ((Byte & 1) && (PPUPack.PPU.BGMode == 3 || PPUPack.PPU.BGMode == 4 || PPUPack.PPU.BGMode == 7))
missing.direct = 1;
#endif
}
break;
case 0x2131:
// Colour addition or subtraction select
if (Byte != ROM_GLOBAL[0x2131])
{
if (os9x_hack&PPU_IGNORE_ADDSUB) return;
INFO_FLUSH_REDRAW("2131");
FLUSH_REDRAW ();
INC_DEBUG_COUNT(25);
// Backgrounds 1 - 4, objects and backdrop colour add/sub enable
#ifdef DEBUGGER
if (Byte & 0x80)
{
// Subtract
if (ROM_GLOBAL[0x2130] & 0x02)
missing.subscreen_sub = 1;
else
missing.fixed_colour_sub = 1;
}
else
{
// Addition
if (ROM_GLOBAL[0x2130] & 0x02)
missing.subscreen_add = 1;
else
missing.fixed_colour_add = 1;
}
#endif
}
break;
case 0x2132:
if (Byte != ROM_GLOBAL [0x2132])
{
INC_DEBUG_COUNT(44);
if(os9x_softrendering>=2 && !(os9x_hack&OLD_PSP_ACCEL) && (PPUPack.PPU.BGMode!=7))
{
INC_DEBUG_COUNT(45);
FixColorsLog_BeforeUpdate();
if (Byte & 0x80)
PPUPack.PPU.FixedColourBlue = Byte & 0x1f;
if (Byte & 0x40)
PPUPack.PPU.FixedColourGreen = Byte & 0x1f;
if (Byte & 0x20)
PPUPack.PPU.FixedColourRed = Byte & 0x1f;
FixColorsLog_Update();
}
else
{
int new_fixedcol;
// Colour data for fixed colour addition/subtraction
if (Byte & 0x80) {
//PPUPack.PPU.FixedColourBlue = Byte & 0x1f;
new_fixedcol=(Byte & 0x1f);
if (new_fixedcol!=PPUPack.PPU.FixedColourBlue) {if (!(os9x_hack&PPU_IGNORE_FIXEDCOLCHANGES)) {INFO_FLUSH_REDRAW("2132");FLUSH_REDRAW();}PPUPack.PPU.FixedColourBlue=new_fixedcol;}
}
if (Byte & 0x40) {
//PPUPack.PPU.FixedColourGreen = Byte & 0x1f;
new_fixedcol=(Byte & 0x1f);
if (new_fixedcol!=PPUPack.PPU.FixedColourGreen) {if (!(os9x_hack&PPU_IGNORE_FIXEDCOLCHANGES)) {INFO_FLUSH_REDRAW("2132");FLUSH_REDRAW();}PPUPack.PPU.FixedColourGreen=new_fixedcol;}
}
if (Byte & 0x20) {
//PPUPack.PPU.FixedColourRed = Byte & 0x1f;
new_fixedcol=(Byte & 0x1f);
if (new_fixedcol!=PPUPack.PPU.FixedColourRed) {if (!(os9x_hack&PPU_IGNORE_FIXEDCOLCHANGES)) {INFO_FLUSH_REDRAW("2132");FLUSH_REDRAW();}PPUPack.PPU.FixedColourRed=new_fixedcol;}
}
}
//else if((os9x_hack&PPU_IGNORE_FIXEDCOLCHANGES))
//{
// int new_fixedcol;
// // Colour data for fixed colour addition/subtraction
// if (Byte & 0x80) {
// //PPUPack.PPU.FixedColourBlue = Byte & 0x1f;
// new_fixedcol=(Byte & 0x1f);
// if (new_fixedcol!=PPUPack.PPU.FixedColourBlue) {if (1) {INFO_FLUSH_REDRAW("2132");FLUSH_REDRAW();}PPUPack.PPU.FixedColourBlue=new_fixedcol;}
// }
// if (Byte & 0x40) {
// //PPUPack.PPU.FixedColourGreen = Byte & 0x1f;
// new_fixedcol=(Byte & 0x1f);
// if (new_fixedcol!=PPUPack.PPU.FixedColourGreen) {if (1) {INFO_FLUSH_REDRAW("2132");FLUSH_REDRAW();}PPUPack.PPU.FixedColourGreen=new_fixedcol;}
// }
// if (Byte & 0x20) {
// //PPUPack.PPU.FixedColourRed = Byte & 0x1f;
// new_fixedcol=(Byte & 0x1f);
// if (new_fixedcol!=PPUPack.PPU.FixedColourRed) {if (1) {INFO_FLUSH_REDRAW("2132");FLUSH_REDRAW();}PPUPack.PPU.FixedColourRed=new_fixedcol;}
// }
//}
}
break;
case 0x2133:
// Screen settings
if (Byte != ROM_GLOBAL [0x2133])
{
#ifdef DEBUGGER
if (Byte & 0x40)
missing.mode7_bgmode = 1;
if (Byte & 0x08)
missing.pseudo_512 = 1;
#endif
if (Byte & 0x04)
{
PPUPack.PPU.ScreenHeight = SNES_HEIGHT_EXTENDED;
#ifdef DEBUGGER
missing.lines_239 = 1;
#endif
}
else
PPUPack.PPU.ScreenHeight = (Settings.PAL?SNES_HEIGHT_PAL:SNES_HEIGHT_NTSC);
#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:
if (os9x_hack&APU_FIX) {
switch (Address&3) {
case 0: //0x2140
APUI00a=Byte;
break;
case 1: //0x2141
APUI01a=Byte;
APUI01b=0;
break;
case 2: //0x2142
APUI02a=Byte;
APUI02b=0;
break;
case 3: //0x2143
APUI03a=Byte;
APUI03b=0;
break;
}
}
#ifdef SPCTOOL
_SPCInPB (Address & 3, Byte);
#else
// CPU.Flags |= DEBUG_MODE_FLAG;
ROM_GLOBAL [Address] = Byte;
APU_EXECUTE2 ();
//(IAPU.RAM) [(Address & 3) + 0xf4] = Byte;
#ifdef ME_SOUND
apu_ram_write_pos = apu_ram_write_cpt2_main++;
apu_ram_write_log[(apu_ram_write_pos)&0xFFFF]=((Address & 3)<<8)|Byte;
(apu_ram_write_cpt2)=apu_ram_write_cpt2_main;
#else
apu_ram_write_pos = apu_ram_write_cpt2;
apu_ram_write_log[(apu_ram_write_pos)&0xFFFF]=((Address & 3)<<8)|Byte;
(apu_ram_write_cpt2)=apu_ram_write_pos+1;
#endif
#ifdef SPC700_SHUTDOWN
(IAPU_APUExecuting) = Settings.APUEnabled;
(IAPU.WaitCounter)++;
#endif
#endif // SPCTOOL
break;
case 0x2180:
REGISTER_2180(Byte);
break;
case 0x2181:
PPUPack.PPU.WRAM &= 0x1FF00;
PPUPack.PPU.WRAM |= Byte;
break;
case 0x2182:
PPUPack.PPU.WRAM &= 0x100FF;
PPUPack.PPU.WRAM |= Byte << 8;
break;
case 0x2183:
PPUPack.PPU.WRAM &= 0x0FFFF;
PPUPack.PPU.WRAM |= Byte << 16;
PPUPack.PPU.WRAM &= 0x1FFFF;
break;
#ifdef _BSX_151_
case 0x2188:
case 0x2189:
case 0x218a:
case 0x218b:
case 0x218c:
case 0x218d:
case 0x218e:
case 0x218f: