Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
RishiRecon
GitHub Repository: RishiRecon/exploits
Path: blob/main/misc/emulator/xnes/snes9x/fxemu.cpp
28515 views
1
/***********************************************************************************
2
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3
4
(c) Copyright 1996 - 2002 Gary Henderson ([email protected]),
5
Jerremy Koot ([email protected])
6
7
(c) Copyright 2002 - 2004 Matthew Kendora
8
9
(c) Copyright 2002 - 2005 Peter Bortas ([email protected])
10
11
(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)
12
13
(c) Copyright 2001 - 2006 John Weidman ([email protected])
14
15
(c) Copyright 2002 - 2006 funkyass ([email protected]),
16
Kris Bleakley ([email protected])
17
18
(c) Copyright 2002 - 2010 Brad Jorsch ([email protected]),
19
Nach ([email protected]),
20
21
(c) Copyright 2002 - 2011 zones ([email protected])
22
23
(c) Copyright 2006 - 2007 nitsuja
24
25
(c) Copyright 2009 - 2011 BearOso,
26
OV2
27
28
29
BS-X C emulator code
30
(c) Copyright 2005 - 2006 Dreamer Nom,
31
zones
32
33
C4 x86 assembler and some C emulation code
34
(c) Copyright 2000 - 2003 _Demo_ ([email protected]),
35
Nach,
36
zsKnight ([email protected])
37
38
C4 C++ code
39
(c) Copyright 2003 - 2006 Brad Jorsch,
40
Nach
41
42
DSP-1 emulator code
43
(c) Copyright 1998 - 2006 _Demo_,
44
Andreas Naive ([email protected]),
45
Gary Henderson,
46
Ivar ([email protected]),
47
John Weidman,
48
Kris Bleakley,
49
Matthew Kendora,
50
Nach,
51
neviksti ([email protected])
52
53
DSP-2 emulator code
54
(c) Copyright 2003 John Weidman,
55
Kris Bleakley,
56
Lord Nightmare ([email protected]),
57
Matthew Kendora,
58
neviksti
59
60
DSP-3 emulator code
61
(c) Copyright 2003 - 2006 John Weidman,
62
Kris Bleakley,
63
Lancer,
64
z80 gaiden
65
66
DSP-4 emulator code
67
(c) Copyright 2004 - 2006 Dreamer Nom,
68
John Weidman,
69
Kris Bleakley,
70
Nach,
71
z80 gaiden
72
73
OBC1 emulator code
74
(c) Copyright 2001 - 2004 zsKnight,
75
pagefault ([email protected]),
76
Kris Bleakley
77
Ported from x86 assembler to C by sanmaiwashi
78
79
SPC7110 and RTC C++ emulator code used in 1.39-1.51
80
(c) Copyright 2002 Matthew Kendora with research by
81
zsKnight,
82
John Weidman,
83
Dark Force
84
85
SPC7110 and RTC C++ emulator code used in 1.52+
86
(c) Copyright 2009 byuu,
87
neviksti
88
89
S-DD1 C emulator code
90
(c) Copyright 2003 Brad Jorsch with research by
91
Andreas Naive,
92
John Weidman
93
94
S-RTC C emulator code
95
(c) Copyright 2001 - 2006 byuu,
96
John Weidman
97
98
ST010 C++ emulator code
99
(c) Copyright 2003 Feather,
100
John Weidman,
101
Kris Bleakley,
102
Matthew Kendora
103
104
Super FX x86 assembler emulator code
105
(c) Copyright 1998 - 2003 _Demo_,
106
pagefault,
107
zsKnight
108
109
Super FX C emulator code
110
(c) Copyright 1997 - 1999 Ivar,
111
Gary Henderson,
112
John Weidman
113
114
Sound emulator code used in 1.5-1.51
115
(c) Copyright 1998 - 2003 Brad Martin
116
(c) Copyright 1998 - 2006 Charles Bilyue'
117
118
Sound emulator code used in 1.52+
119
(c) Copyright 2004 - 2007 Shay Green ([email protected])
120
121
SH assembler code partly based on x86 assembler code
122
(c) Copyright 2002 - 2004 Marcus Comstedt ([email protected])
123
124
2xSaI filter
125
(c) Copyright 1999 - 2001 Derek Liauw Kie Fa
126
127
HQ2x, HQ3x, HQ4x filters
128
(c) Copyright 2003 Maxim Stepin ([email protected])
129
130
NTSC filter
131
(c) Copyright 2006 - 2007 Shay Green
132
133
GTK+ GUI code
134
(c) Copyright 2004 - 2011 BearOso
135
136
Win32 GUI code
137
(c) Copyright 2003 - 2006 blip,
138
funkyass,
139
Matthew Kendora,
140
Nach,
141
nitsuja
142
(c) Copyright 2009 - 2011 OV2
143
144
Mac OS GUI code
145
(c) Copyright 1998 - 2001 John Stiles
146
(c) Copyright 2001 - 2011 zones
147
148
149
Specific ports contains the works of other authors. See headers in
150
individual files.
151
152
153
Snes9x homepage: http://www.snes9x.com/
154
155
Permission to use, copy, modify and/or distribute Snes9x in both binary
156
and source form, for non-commercial purposes, is hereby granted without
157
fee, providing that this license information and copyright notice appear
158
with all copies and any derived work.
159
160
This software is provided 'as-is', without any express or implied
161
warranty. In no event shall the authors be held liable for any damages
162
arising from the use of this software or it's derivatives.
163
164
Snes9x is freeware for PERSONAL USE only. Commercial users should
165
seek permission of the copyright holders first. Commercial use includes,
166
but is not limited to, charging money for Snes9x or software derived from
167
Snes9x, including Snes9x or derivatives in commercial game bundles, and/or
168
using Snes9x as a promotion for your commercial product.
169
170
The copyright holders request that bug fixes and improvements to the code
171
should be forwarded to them so everyone can benefit from the modifications
172
in future versions.
173
174
Super NES and Super Nintendo Entertainment System are trademarks of
175
Nintendo Co., Limited and its subsidiary companies.
176
***********************************************************************************/
177
178
179
#include "snes9x.h"
180
#include "memmap.h"
181
#include "fxinst.h"
182
#include "fxemu.h"
183
184
static void FxReset (struct FxInfo_s *);
185
static void fx_readRegisterSpace (void);
186
static void fx_writeRegisterSpace (void);
187
static void fx_updateRamBank (uint8);
188
static void fx_dirtySCBR (void);
189
static bool8 fx_checkStartAddress (void);
190
static uint32 FxEmulate (uint32);
191
static void FxCacheWriteAccess (uint16);
192
static void FxFlushCache (void);
193
194
195
void S9xInitSuperFX (void)
196
{
197
memset((uint8 *) &GSU, 0, sizeof(struct FxRegs_s));
198
}
199
200
void S9xResetSuperFX (void)
201
{
202
// FIXME: Snes9x can't execute CPU and SuperFX at a time. Don't ask me what is 0.417 :P
203
SuperFX.speedPerLine = (uint32) (0.417 * 10.5e6 * ((1.0 / (float) Memory.ROMFramesPerSecond) / ((float) (Timings.V_Max))));
204
SuperFX.oneLineDone = FALSE;
205
SuperFX.vFlags = 0;
206
CPU.IRQExternal = FALSE;
207
FxReset(&SuperFX);
208
}
209
210
void S9xSetSuperFX (uint8 byte, uint16 address)
211
{
212
switch (address)
213
{
214
case 0x3030:
215
if ((Memory.FillRAM[0x3030] ^ byte) & FLG_G)
216
{
217
Memory.FillRAM[0x3030] = byte;
218
if (byte & FLG_G)
219
{
220
if (!SuperFX.oneLineDone)
221
{
222
S9xSuperFXExec();
223
SuperFX.oneLineDone = TRUE;
224
}
225
}
226
else
227
FxFlushCache();
228
}
229
else
230
Memory.FillRAM[0x3030] = byte;
231
232
break;
233
234
case 0x3031:
235
Memory.FillRAM[0x3031] = byte;
236
break;
237
238
case 0x3033:
239
Memory.FillRAM[0x3033] = byte;
240
break;
241
242
case 0x3034:
243
Memory.FillRAM[0x3034] = byte & 0x7f;
244
break;
245
246
case 0x3036:
247
Memory.FillRAM[0x3036] = byte & 0x7f;
248
break;
249
250
case 0x3037:
251
Memory.FillRAM[0x3037] = byte;
252
break;
253
254
case 0x3038:
255
Memory.FillRAM[0x3038] = byte;
256
fx_dirtySCBR();
257
break;
258
259
case 0x3039:
260
Memory.FillRAM[0x3039] = byte;
261
break;
262
263
case 0x303a:
264
Memory.FillRAM[0x303a] = byte;
265
break;
266
267
case 0x303b:
268
break;
269
270
case 0x303c:
271
Memory.FillRAM[0x303c] = byte;
272
fx_updateRamBank(byte);
273
break;
274
275
case 0x303f:
276
Memory.FillRAM[0x303f] = byte;
277
break;
278
279
case 0x301f:
280
Memory.FillRAM[0x301f] = byte;
281
Memory.FillRAM[0x3000 + GSU_SFR] |= FLG_G;
282
if (!SuperFX.oneLineDone)
283
{
284
S9xSuperFXExec();
285
SuperFX.oneLineDone = TRUE;
286
}
287
288
break;
289
290
default:
291
Memory.FillRAM[address] = byte;
292
if (address >= 0x3100)
293
FxCacheWriteAccess(address);
294
295
break;
296
}
297
}
298
299
uint8 S9xGetSuperFX (uint16 address)
300
{
301
uint8 byte;
302
303
byte = Memory.FillRAM[address];
304
305
if (address == 0x3031)
306
{
307
CPU.IRQExternal = FALSE;
308
Memory.FillRAM[0x3031] = byte & 0x7f;
309
}
310
311
return (byte);
312
}
313
314
void S9xSuperFXExec (void)
315
{
316
if ((Memory.FillRAM[0x3000 + GSU_SFR] & FLG_G) && (Memory.FillRAM[0x3000 + GSU_SCMR] & 0x18) == 0x18)
317
{
318
FxEmulate((Memory.FillRAM[0x3000 + GSU_CLSR] & 1) ? SuperFX.speedPerLine * 2 : SuperFX.speedPerLine);
319
320
uint16 GSUStatus = Memory.FillRAM[0x3000 + GSU_SFR] | (Memory.FillRAM[0x3000 + GSU_SFR + 1] << 8);
321
if ((GSUStatus & (FLG_G | FLG_IRQ)) == FLG_IRQ)
322
CPU.IRQExternal = TRUE;
323
}
324
}
325
326
static void FxReset (struct FxInfo_s *psFxInfo)
327
{
328
// Clear all internal variables
329
memset((uint8 *) &GSU, 0, sizeof(struct FxRegs_s));
330
331
// Set default registers
332
GSU.pvSreg = GSU.pvDreg = &R0;
333
334
// Set RAM and ROM pointers
335
GSU.pvRegisters = psFxInfo->pvRegisters;
336
GSU.nRamBanks = psFxInfo->nRamBanks;
337
GSU.pvRam = psFxInfo->pvRam;
338
GSU.nRomBanks = psFxInfo->nRomBanks;
339
GSU.pvRom = psFxInfo->pvRom;
340
GSU.vPrevScreenHeight = ~0;
341
GSU.vPrevMode = ~0;
342
343
// The GSU can't access more than 2mb (16mbits)
344
if (GSU.nRomBanks > 0x20)
345
GSU.nRomBanks = 0x20;
346
347
// Clear FxChip register space
348
memset(GSU.pvRegisters, 0, 0x300);
349
350
// Set FxChip version Number
351
GSU.pvRegisters[0x3b] = 0;
352
353
// Make ROM bank table
354
for (int i = 0; i < 256; i++)
355
{
356
uint32 b = i & 0x7f;
357
358
if (b >= 0x40)
359
{
360
if (GSU.nRomBanks > 1)
361
b %= GSU.nRomBanks;
362
else
363
b &= 1;
364
365
GSU.apvRomBank[i] = &GSU.pvRom[b << 16];
366
}
367
else
368
{
369
b %= GSU.nRomBanks * 2;
370
GSU.apvRomBank[i] = &GSU.pvRom[(b << 16) + 0x200000];
371
}
372
}
373
374
// Make RAM bank table
375
for (int i = 0; i < 4; i++)
376
{
377
GSU.apvRamBank[i] = &GSU.pvRam[(i % GSU.nRamBanks) << 16];
378
GSU.apvRomBank[0x70 + i] = GSU.apvRamBank[i];
379
}
380
381
// Start with a nop in the pipe
382
GSU.vPipe = 0x01;
383
384
// Set pointer to GSU cache
385
GSU.pvCache = &GSU.pvRegisters[0x100];
386
387
fx_readRegisterSpace();
388
}
389
390
static void fx_readRegisterSpace (void)
391
{
392
static uint32 avHeight[] = { 128, 160, 192, 256 };
393
static uint32 avMult[] = { 16, 32, 32, 64 };
394
395
uint8 *p;
396
int n;
397
398
GSU.vErrorCode = 0;
399
400
// Update R0-R15
401
p = GSU.pvRegisters;
402
for (int i = 0; i < 16; i++)
403
{
404
GSU.avReg[i] = *p++;
405
GSU.avReg[i] += ((uint32) (*p++)) << 8;
406
}
407
408
// Update other registers
409
p = GSU.pvRegisters;
410
GSU.vStatusReg = (uint32) p[GSU_SFR];
411
GSU.vStatusReg |= ((uint32) p[GSU_SFR + 1]) << 8;
412
GSU.vPrgBankReg = (uint32) p[GSU_PBR];
413
GSU.vRomBankReg = (uint32) p[GSU_ROMBR];
414
GSU.vRamBankReg = ((uint32) p[GSU_RAMBR]) & (FX_RAM_BANKS - 1);
415
GSU.vCacheBaseReg = (uint32) p[GSU_CBR];
416
GSU.vCacheBaseReg |= ((uint32) p[GSU_CBR + 1]) << 8;
417
418
// Update status register variables
419
GSU.vZero = !(GSU.vStatusReg & FLG_Z);
420
GSU.vSign = (GSU.vStatusReg & FLG_S) << 12;
421
GSU.vOverflow = (GSU.vStatusReg & FLG_OV) << 16;
422
GSU.vCarry = (GSU.vStatusReg & FLG_CY) >> 2;
423
424
// Set bank pointers
425
GSU.pvRamBank = GSU.apvRamBank[GSU.vRamBankReg & 0x3];
426
GSU.pvRomBank = GSU.apvRomBank[GSU.vRomBankReg];
427
GSU.pvPrgBank = GSU.apvRomBank[GSU.vPrgBankReg];
428
429
// Set screen pointers
430
GSU.pvScreenBase = &GSU.pvRam[USEX8(p[GSU_SCBR]) << 10];
431
n = (int) (!!(p[GSU_SCMR] & 0x04));
432
n |= ((int) (!!(p[GSU_SCMR] & 0x20))) << 1;
433
GSU.vScreenHeight = GSU.vScreenRealHeight = avHeight[n];
434
GSU.vMode = p[GSU_SCMR] & 0x03;
435
436
if (n == 3)
437
GSU.vScreenSize = (256 / 8) * (256 / 8) * 32;
438
else
439
GSU.vScreenSize = (GSU.vScreenHeight / 8) * (256 / 8) * avMult[GSU.vMode];
440
441
if (GSU.vPlotOptionReg & 0x10) // OBJ Mode (for drawing into sprites)
442
GSU.vScreenHeight = 256;
443
444
if (GSU.pvScreenBase + GSU.vScreenSize > GSU.pvRam + (GSU.nRamBanks * 65536))
445
GSU.pvScreenBase = GSU.pvRam + (GSU.nRamBanks * 65536) - GSU.vScreenSize;
446
447
GSU.pfPlot = fx_PlotTable[GSU.vMode];
448
GSU.pfRpix = fx_PlotTable[GSU.vMode + 5];
449
450
fx_OpcodeTable[0x04c] = GSU.pfPlot;
451
fx_OpcodeTable[0x14c] = GSU.pfRpix;
452
fx_OpcodeTable[0x24c] = GSU.pfPlot;
453
fx_OpcodeTable[0x34c] = GSU.pfRpix;
454
455
fx_computeScreenPointers();
456
457
//fx_backupCache();
458
}
459
460
static void fx_writeRegisterSpace (void)
461
{
462
uint8 *p;
463
464
p = GSU.pvRegisters;
465
for (int i = 0; i < 16; i++)
466
{
467
*p++ = (uint8) GSU.avReg[i];
468
*p++ = (uint8) (GSU.avReg[i] >> 8);
469
}
470
471
// Update status register
472
if (USEX16(GSU.vZero) == 0)
473
SF(Z);
474
else
475
CF(Z);
476
477
if (GSU.vSign & 0x8000)
478
SF(S);
479
else
480
CF(S);
481
482
if (GSU.vOverflow >= 0x8000 || GSU.vOverflow < -0x8000)
483
SF(OV);
484
else
485
CF(OV);
486
487
if (GSU.vCarry)
488
SF(CY);
489
else
490
CF(CY);
491
492
p = GSU.pvRegisters;
493
p[GSU_SFR] = (uint8) GSU.vStatusReg;
494
p[GSU_SFR + 1] = (uint8) (GSU.vStatusReg >> 8);
495
p[GSU_PBR] = (uint8) GSU.vPrgBankReg;
496
p[GSU_ROMBR] = (uint8) GSU.vRomBankReg;
497
p[GSU_RAMBR] = (uint8) GSU.vRamBankReg;
498
p[GSU_CBR] = (uint8) GSU.vCacheBaseReg;
499
p[GSU_CBR + 1] = (uint8) (GSU.vCacheBaseReg >> 8);
500
501
//fx_restoreCache();
502
}
503
504
// Update RamBankReg and RAM Bank pointer
505
static void fx_updateRamBank (uint8 byte)
506
{
507
// Update BankReg and Bank pointer
508
GSU.vRamBankReg = (uint32) byte & (FX_RAM_BANKS - 1);
509
GSU.pvRamBank = GSU.apvRamBank[byte & 0x3];
510
}
511
512
// SCBR write seen. We need to update our cached screen pointers
513
static void fx_dirtySCBR (void)
514
{
515
GSU.vSCBRDirty = TRUE;
516
}
517
518
static bool8 fx_checkStartAddress (void)
519
{
520
// Check if we start inside the cache
521
if (GSU.bCacheActive && R15 >= GSU.vCacheBaseReg && R15 < (GSU.vCacheBaseReg + 512))
522
return (TRUE);
523
524
/*
525
// Check if we're in an unused area
526
if (GSU.vPrgBankReg < 0x40 && R15 < 0x8000)
527
return (FALSE);
528
*/
529
530
if (GSU.vPrgBankReg >= 0x60 && GSU.vPrgBankReg <= 0x6f)
531
return (FALSE);
532
533
if (GSU.vPrgBankReg >= 0x74)
534
return (FALSE);
535
536
// Check if we're in RAM and the RAN flag is not set
537
if (GSU.vPrgBankReg >= 0x70 && GSU.vPrgBankReg <= 0x73 && !(SCMR & (1 << 3)))
538
return (FALSE);
539
540
// If not, we're in ROM, so check if the RON flag is set
541
if (!(SCMR & (1 << 4)))
542
return (FALSE);
543
544
return (TRUE);
545
}
546
547
// Execute until the next stop instruction
548
static uint32 FxEmulate (uint32 nInstructions)
549
{
550
uint32 vCount;
551
552
// Read registers and initialize GSU session
553
fx_readRegisterSpace();
554
555
// Check if the start address is valid
556
if (!fx_checkStartAddress())
557
{
558
CF(G);
559
fx_writeRegisterSpace();
560
/*
561
GSU.vIllegalAddress = (GSU.vPrgBankReg << 24) | R15;
562
return (FX_ERROR_ILLEGAL_ADDRESS);
563
*/
564
565
return (0);
566
}
567
568
// Execute GSU session
569
CF(IRQ);
570
571
/*
572
if (GSU.bBreakPoint)
573
vCount = fx_run_to_breakpoint(nInstructions);
574
else
575
*/
576
vCount = fx_run(nInstructions);
577
578
// Store GSU registers
579
fx_writeRegisterSpace();
580
581
// Check for error code
582
if (GSU.vErrorCode)
583
return (GSU.vErrorCode);
584
else
585
return (vCount);
586
}
587
588
void fx_computeScreenPointers (void)
589
{
590
if (GSU.vMode != GSU.vPrevMode || GSU.vPrevScreenHeight != GSU.vScreenHeight || GSU.vSCBRDirty)
591
{
592
GSU.vSCBRDirty = FALSE;
593
594
// Make a list of pointers to the start of each screen column
595
switch (GSU.vScreenHeight)
596
{
597
case 128:
598
switch (GSU.vMode)
599
{
600
case 0:
601
for (int i = 0; i < 32; i++)
602
{
603
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 4);
604
GSU.x[i] = i << 8;
605
}
606
607
break;
608
609
case 1:
610
for (int i = 0; i < 32; i++)
611
{
612
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 5);
613
GSU.x[i] = i << 9;
614
}
615
616
break;
617
618
case 2:
619
case 3:
620
for (int i = 0; i < 32; i++)
621
{
622
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 6);
623
GSU.x[i] = i << 10;
624
}
625
626
break;
627
}
628
629
break;
630
631
case 160:
632
switch (GSU.vMode)
633
{
634
case 0:
635
for (int i = 0; i < 32; i++)
636
{
637
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 4);
638
GSU.x[i] = (i << 8) + (i << 6);
639
}
640
641
break;
642
643
case 1:
644
for (int i = 0; i < 32; i++)
645
{
646
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 5);
647
GSU.x[i] = (i << 9) + (i << 7);
648
}
649
650
break;
651
652
case 2:
653
case 3:
654
for (int i = 0; i < 32; i++)
655
{
656
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 6);
657
GSU.x[i] = (i << 10) + (i << 8);
658
}
659
660
break;
661
}
662
663
break;
664
665
case 192:
666
switch (GSU.vMode)
667
{
668
case 0:
669
for (int i = 0; i < 32; i++)
670
{
671
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 4);
672
GSU.x[i] = (i << 8) + (i << 7);
673
}
674
675
break;
676
677
case 1:
678
for (int i = 0; i < 32; i++)
679
{
680
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 5);
681
GSU.x[i] = (i << 9) + (i << 8);
682
}
683
684
break;
685
686
case 2:
687
case 3:
688
for (int i = 0; i < 32; i++)
689
{
690
GSU.apvScreen[i] = GSU.pvScreenBase + (i << 6);
691
GSU.x[i] = (i << 10) + (i << 9);
692
}
693
694
break;
695
}
696
697
break;
698
699
case 256:
700
switch (GSU.vMode)
701
{
702
case 0:
703
for (int i = 0; i < 32; i++)
704
{
705
GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 9) + ((i & 0xf) << 8);
706
GSU.x[i] = ((i & 0x10) << 8) + ((i & 0xf) << 4);
707
}
708
709
break;
710
711
case 1:
712
for (int i = 0; i < 32; i++)
713
{
714
GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 10) + ((i & 0xf) << 9);
715
GSU.x[i] = ((i & 0x10) << 9) + ((i & 0xf) << 5);
716
}
717
718
break;
719
720
case 2:
721
case 3:
722
for (int i = 0; i < 32; i++)
723
{
724
GSU.apvScreen[i] = GSU.pvScreenBase + ((i & 0x10) << 11) + ((i & 0xf) << 10);
725
GSU.x[i] = ((i & 0x10) << 10) + ((i & 0xf) << 6);
726
}
727
728
break;
729
}
730
731
break;
732
}
733
734
GSU.vPrevMode = GSU.vMode;
735
GSU.vPrevScreenHeight = GSU.vScreenHeight;
736
}
737
}
738
739
// Write access to the cache
740
static void FxCacheWriteAccess (uint16 vAddress)
741
{
742
/*
743
if (!GSU.bCacheActive)
744
{
745
uint8 v = GSU.pvCache[GSU.pvCache[vAddress & 0x1ff];
746
fx_setCache();
747
GSU.pvCache[GSU.pvCache[vAddress & 0x1ff] = v;
748
}
749
*/
750
751
if ((vAddress & 0x00f) == 0x00f)
752
GSU.vCacheFlags |= 1 << ((vAddress & 0x1f0) >> 4);
753
}
754
755
static void FxFlushCache (void)
756
{
757
GSU.vCacheFlags = 0;
758
GSU.vCacheBaseReg = 0;
759
GSU.bCacheActive = FALSE;
760
//GSU.vPipe = 0x1;
761
}
762
763
void fx_flushCache (void)
764
{
765
//fx_restoreCache();
766
GSU.vCacheFlags = 0;
767
GSU.bCacheActive = FALSE;
768
}
769
770
/*
771
static void fx_setCache (void)
772
{
773
uint32 c;
774
775
GSU.bCacheActive = TRUE;
776
GSU.pvRegisters[0x3e] &= 0xf0;
777
778
c = (uint32) GSU.pvRegisters[0x3e];
779
c |= ((uint32) GSU.pvRegisters[0x3f]) << 8;
780
if (c == GSU.vCacheBaseReg)
781
return;
782
783
GSU.vCacheBaseReg = c;
784
GSU.vCacheFlags = 0;
785
786
if (c < (0x10000 - 512))
787
{
788
const uint8 *t = &ROM(c);
789
memcpy(GSU.pvCache, t, 512);
790
}
791
else
792
{
793
const uint8 *t1, *t2;
794
uint32 i = 0x10000 - c;
795
796
t1 = &ROM(c);
797
t2 = &ROM(0);
798
memcpy(GSU.pvCache, t1, i);
799
memcpy(&GSU.pvCache[i], t2, 512 - i);
800
}
801
}
802
*/
803
804
/*
805
static void fx_backupCache (void)
806
{
807
uint32 v = GSU.vCacheFlags;
808
uint32 c = USEX16(GSU.vCacheBaseReg);
809
810
if (v)
811
{
812
for (int i = 0; i < 32; i++)
813
{
814
if (v & 1)
815
{
816
if (c < (0x10000 - 16))
817
{
818
uint8 *t = &GSU.pvPrgBank[c];
819
memcpy(&GSU.avCacheBackup[i << 4], t, 16);
820
memcpy(t, &GSU.pvCache[i << 4], 16);
821
}
822
else
823
{
824
uint8 *t1, *t2;
825
uint32 a = 0x10000 - c;
826
827
t1 = &GSU.pvPrgBank[c];
828
t2 = &GSU.pvPrgBank[0];
829
memcpy(&GSU.avCacheBackup[i << 4], t1, a);
830
memcpy(t1, &GSU.pvCache[i << 4], a);
831
memcpy(&GSU.avCacheBackup[(i << 4) + a], t2, 16 - a);
832
memcpy(t2, &GSU.pvCache[(i << 4) + a], 16 - a);
833
}
834
}
835
836
c = USEX16(c + 16);
837
v >>= 1;
838
}
839
}
840
}
841
*/
842
843
/*
844
static void fx_restoreCache()
845
{
846
uint32 v = GSU.vCacheFlags;
847
uint32 c = USEX16(GSU.vCacheBaseReg);
848
849
if (v)
850
{
851
for (int i = 0; i < 32; i++)
852
{
853
if (v & 1)
854
{
855
if (c < (0x10000 - 16))
856
{
857
uint8 *t = &GSU.pvPrgBank[c];
858
memcpy(t, &GSU.avCacheBackup[i << 4], 16);
859
memcpy(&GSU.pvCache[i << 4], t, 16);
860
}
861
else
862
{
863
uint8 *t1, *t2;
864
uint32 a = 0x10000 - c;
865
866
t1 = &GSU.pvPrgBank[c];
867
t2 = &GSU.pvPrgBank[0];
868
memcpy(t1, &GSU.avCacheBackup[i << 4], a);
869
memcpy(&GSU.pvCache[i << 4], t1, a);
870
memcpy(t2, &GSU.avCacheBackup[(i << 4) + a], 16 - a);
871
memcpy(&GSU.pvCache[(i << 4) + a], t2, 16 - a);
872
}
873
}
874
875
c = USEX16(c + 16);
876
v >>= 1;
877
}
878
}
879
}
880
*/
881
882
// Breakpoints
883
/*
884
static void FxBreakPointSet (uint32 vAddress)
885
{
886
GSU.bBreakPoint = TRUE;
887
GSU.vBreakPoint = USEX16(vAddress);
888
}
889
*/
890
891
/*
892
static void FxBreakPointClear (void)
893
{
894
GSU.bBreakPoint = FALSE;
895
}
896
*/
897
898
// Step by step execution
899
/*
900
static uint32 FxStepOver (uint32 nInstructions)
901
{
902
uint32 vCount;
903
904
fx_readRegisterSpace();
905
906
if (!fx_checkStartAddress())
907
{
908
CF(G);
909
#if 0
910
GSU.vIllegalAddress = (GSU.vPrgBankReg << 24) | R15;
911
return (FX_ERROR_ILLEGAL_ADDRESS);
912
#else
913
return (0);
914
#endif
915
}
916
917
if (PIPE >= 0xf0)
918
GSU.vStepPoint = USEX16(R15 + 3);
919
else
920
if ((PIPE >= 0x05 && PIPE <= 0x0f) || (PIPE >= 0xa0 && PIPE <= 0xaf))
921
GSU.vStepPoint = USEX16(R15 + 2);
922
else
923
GSU.vStepPoint = USEX16(R15 + 1);
924
925
vCount = fx_step_over(nInstructions);
926
927
fx_writeRegisterSpace();
928
929
if (GSU.vErrorCode)
930
return (GSU.vErrorCode);
931
else
932
return (vCount);
933
}
934
*/
935
936
// Errors
937
/*
938
static int FxGetErrorCode (void)
939
{
940
return (GSU.vErrorCode);
941
}
942
*/
943
944
/*
945
static int FxGetIllegalAddress (void)
946
{
947
return (GSU.vIllegalAddress);
948
}
949
*/
950
951
// Access to internal registers
952
/*
953
static uint32 FxGetColorRegister (void)
954
{
955
return (GSU.vColorReg & 0xff);
956
}
957
*/
958
959
/*
960
static uint32 FxGetPlotOptionRegister (void)
961
{
962
return (GSU.vPlotOptionReg & 0x1f);
963
}
964
*/
965
966
/*
967
static uint32 FxGetSourceRegisterIndex (void)
968
{
969
return (GSU.pvSreg - GSU.avReg);
970
}
971
*/
972
973
/*
974
static uint32 FxGetDestinationRegisterIndex (void)
975
{
976
return (GSU.pvDreg - GSU.avReg);
977
}
978
*/
979
980
// Get the byte currently in the pipe
981
/*
982
static uint8 FxPipe (void)
983
{
984
return (GSU.vPipe);
985
}
986
*/
987
988