summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortwinaphex2018-12-28 00:32:13 +0100
committertwinaphex2018-12-28 00:32:13 +0100
commitc007afe6fd51827fade7aa15a0a798be8bd97839 (patch)
tree3b8aca538bec3b42ef9bd33549a15110c3a20e37 /src
parent29db3cf00f552808b3f1dc5d11fcdbbefc659ec4 (diff)
downloadsnes9x2002-c007afe6fd51827fade7aa15a0a798be8bd97839.tar.gz
snes9x2002-c007afe6fd51827fade7aa15a0a798be8bd97839.tar.bz2
snes9x2002-c007afe6fd51827fade7aa15a0a798be8bd97839.zip
Start significantly refactoring this codebase so we can get it
to work with MSVC
Diffstat (limited to 'src')
-rw-r--r--src/65c816.h16
-rw-r--r--src/apu.c4
-rw-r--r--src/apu.h10
-rw-r--r--src/apumem.h2
-rw-r--r--src/c4.c11
-rw-r--r--src/c4.h4
-rw-r--r--src/c4emu.c93
-rw-r--r--src/cheats.c16
-rw-r--r--src/cheats2.c6
-rw-r--r--src/clip.c3
-rw-r--r--src/cpuaddr.h2
-rw-r--r--src/cpuexec.h2
-rw-r--r--src/cpumacro.h78
-rw-r--r--src/cpuops.c12
-rw-r--r--src/display.h2
-rw-r--r--src/dma.c31
-rw-r--r--src/dma.h4
-rw-r--r--src/dsp1.c13
-rw-r--r--src/dsp1.h4
-rw-r--r--src/dsp1_gp32.h6
-rw-r--r--src/dsp1emu.c81
-rw-r--r--src/getset.h30
-rw-r--r--src/gfx.h3
-rw-r--r--src/globals.c8
-rw-r--r--src/memmap.c771
-rw-r--r--src/memmap.h2
-rw-r--r--src/missing.h2
-rw-r--r--src/os9x_asm_cpu.c4
-rw-r--r--src/os9x_asm_cpu.h4
-rw-r--r--src/port.h13
-rw-r--r--src/ppu.h24
-rw-r--r--src/sa1.c6
-rw-r--r--src/sa1.h11
-rw-r--r--src/sdd1.c16
-rw-r--r--src/sdd1emu.h5
-rw-r--r--src/seta.c2
-rw-r--r--src/seta.h2
-rw-r--r--src/snapshot.c144
-rw-r--r--src/snapshot.h2
-rw-r--r--src/snes9x.h6
-rw-r--r--src/soundux.c442
-rw-r--r--src/soundux.h10
-rw-r--r--src/spc700.c128
-rw-r--r--src/spc700.h6
-rw-r--r--src/srtc.c4
45 files changed, 1069 insertions, 976 deletions
diff --git a/src/65c816.h b/src/65c816.h
index 55c1dc2..0f265b9 100644
--- a/src/65c816.h
+++ b/src/65c816.h
@@ -44,6 +44,7 @@
#ifndef _65c816_h_
#define _65c816_h_
+#include <stdint.h>
#include "port.h"
#define AL A.B.l
@@ -102,19 +103,17 @@
typedef union
{
-#ifdef MSB_FIRST
struct
{
+#ifdef MSB_FIRST
uint8 h, l;
- } PACKING B;
#else
- struct
- {
uint8 l, h;
- } PACKING B;
#endif
- uint16 W;
-} ALIGN_BY_ONE pair;
+ } B;
+
+ uint16_t W;
+} pair;
typedef struct
{
@@ -127,9 +126,8 @@ typedef struct
pair S;
pair Y;
uint16 PC;
-} PACKING SRegisters;
+} SRegisters;
#define Registers CPU.Regs
-//EXTERN_C struct SRegisters Registers;
#endif
diff --git a/src/apu.c b/src/apu.c
index 0fa888a..5814070 100644
--- a/src/apu.c
+++ b/src/apu.c
@@ -410,9 +410,9 @@ void S9xDeinitAPU()
}
}
-EXTERN_C uint8 APUROM [64];
+uint8 APUROM [64];
-void S9xResetAPU()
+void S9xResetAPU(void)
{
int i, j;
// Settings.APUEnabled = Settings.NextAPUEnabled;
diff --git a/src/apu.h b/src/apu.h
index c915eed..5d08355 100644
--- a/src/apu.h
+++ b/src/apu.h
@@ -41,8 +41,11 @@
#ifndef _apu_h_
#define _apu_h_
+#include "port.h"
#include "spc700.h"
+#include <retro_inline.h>
+
/*
typedef union
{
@@ -100,8 +103,8 @@ typedef struct
} SIAPU;
-EXTERN_C SAPU APU;
-EXTERN_C SIAPU IAPU;
+SAPU APU;
+SIAPU IAPU;
static INLINE void S9xAPUUnpackStatus(void)
{
@@ -137,7 +140,6 @@ static INLINE void S9xAPUPackStatus(void)
}
}
-START_EXTERN_C
void S9xResetAPU(void);
bool8 S9xInitAPU();
void S9xDeinitAPU();
@@ -154,8 +156,6 @@ extern int32 S9xAPUCycles [256]; // Scaled cycle lengths
extern int32 S9xAPUCycleLengths [256]; // Raw data.
extern void (*S9xApuOpcodes [256])(void);
extern void (*S9xApuOpcodesReal [256])(void);
-END_EXTERN_C
-
#define APU_VOL_LEFT 0x00
#define APU_VOL_RIGHT 0x01
diff --git a/src/apumem.h b/src/apumem.h
index 842ee11..ff9e4a9 100644
--- a/src/apumem.h
+++ b/src/apumem.h
@@ -42,10 +42,8 @@
#ifndef _apumemory_h_
#define _apumemory_h_
-START_EXTERN_C
extern uint8 W4;
extern uint8 APUROM[64];
-END_EXTERN_C
static INLINE uint8 S9xAPUGetByteZ(uint8 Address)
{
diff --git a/src/c4.c b/src/c4.c
index 060b642..20f59c3 100644
--- a/src/c4.c
+++ b/src/c4.c
@@ -81,8 +81,6 @@
#include "c4.h"
//#include "memmap.h"
-START_EXTERN_C
-
short C4WFXVal;
short C4WFYVal;
short C4WFZVal;
@@ -169,24 +167,26 @@ const short C4_SinTable[256] =
short C4_Sin(short Angle)
{
+ int S;
if (Angle < 0)
{
if (Angle == -32768) return 0;
return -C4_Sin(-Angle);
}
- int S = C4_SinTable[Angle >> 8] + (C4_MulTable[Angle & 0xff] * C4_SinTable[0x40 + (Angle >> 8)] >> 15);
+ S = C4_SinTable[Angle >> 8] + (C4_MulTable[Angle & 0xff] * C4_SinTable[0x40 + (Angle >> 8)] >> 15);
if (S > 32767) S = 32767;
return (short) S;
}
short C4_Cos(short Angle)
{
+ int S;
if (Angle < 0)
{
if (Angle == -32768) return -32768;
Angle = -Angle;
}
- int S = C4_SinTable[0x40 + (Angle >> 8)] - (C4_MulTable[Angle & 0xff] * C4_SinTable[Angle >> 8] >> 15);
+ S = C4_SinTable[0x40 + (Angle >> 8)] - (C4_MulTable[Angle & 0xff] * C4_SinTable[Angle >> 8] >> 15);
if (S < -32768) S = -32767;
return (short) S;
}
@@ -426,6 +426,3 @@ void C4Op0D()
C41FXVal = (short) (C41FXVal * tanval * 0.98);
*/
}
-
-END_EXTERN_C
-
diff --git a/src/c4.h b/src/c4.h
index 67c7781..f625213 100644
--- a/src/c4.h
+++ b/src/c4.h
@@ -78,8 +78,6 @@
#include "port.h"
#include "memmap.h"
-START_EXTERN_C
-
extern int16 C4WFXVal;
extern int16 C4WFYVal;
extern int16 C4WFZVal;
@@ -105,8 +103,6 @@ void C4Op0D();
extern int16 C4CosTable[];
extern int16 C4SinTable[];
-END_EXTERN_C
-
static INLINE uint8* C4GetMemPointer(uint32 Address)
{
return (Memory.ROM + ((Address & 0xff0000) >> 1) + (Address & 0x7fff));
diff --git a/src/c4emu.c b/src/c4emu.c
index bec8364..f41d4ec 100644
--- a/src/c4emu.c
+++ b/src/c4emu.c
@@ -120,19 +120,17 @@ static uint8 C4TestPattern [12 * 4] =
static void C4ConvOAM(void)
{
- uint8* ptr;
- uint8* OAMptr = Memory.C4RAM + (Memory.C4RAM[0x626] << 2);
- for (ptr = Memory.C4RAM + 0x1fd; ptr > OAMptr; ptr -= 4)
- {
- // Clear OAM-to-be
- *ptr = 0xe0;
- }
-
uint16 globalX, globalY;
uint8* OAMptr2;
int16 SprX, SprY;
uint8 SprName, SprAttr;
uint8 SprCount;
+ uint8* ptr;
+ uint8* OAMptr = Memory.C4RAM + (Memory.C4RAM[0x626] << 2);
+
+ /* Clear OAM-to-be */
+ for (ptr = Memory.C4RAM + 0x1fd; ptr > OAMptr; ptr -= 4)
+ *ptr = 0xe0;
globalX = READ_WORD(Memory.C4RAM + 0x0621);
globalY = READ_WORD(Memory.C4RAM + 0x0623);
@@ -141,21 +139,29 @@ static void C4ConvOAM(void)
if (Memory.C4RAM[0x0620] != 0)
{
int i;
+ uint8 *srcptr;
+ uint8 offset;
+
SprCount = 128 - Memory.C4RAM[0x626];
- uint8 offset = (Memory.C4RAM[0x626] & 3) * 2;
- uint8* srcptr = Memory.C4RAM + 0x220;
+ offset = (Memory.C4RAM[0x626] & 3) * 2;
+ srcptr = Memory.C4RAM + 0x220;
+
for (i = Memory.C4RAM[0x0620]; i > 0 && SprCount > 0; i--, srcptr += 16)
{
- SprX = READ_WORD(srcptr) - globalX;
- SprY = READ_WORD(srcptr + 2) - globalY;
+ uint8 *sprptr;
+
+ SprX = READ_WORD(srcptr) - globalX;
+ SprY = READ_WORD(srcptr + 2) - globalY;
SprName = srcptr[5];
SprAttr = srcptr[4] | srcptr[0x06]; // XXX: mask bits?
- uint8* sprptr = C4GetMemPointer(READ_3WORD(srcptr + 7));
+ sprptr = C4GetMemPointer(READ_3WORD(srcptr + 7));
+
if (*sprptr != 0)
{
int16 X, Y;
int SprCnt;
+
for (SprCnt = *sprptr++; SprCnt > 0 && SprCount > 0; SprCnt--, sprptr += 4)
{
X = (int8)sprptr[1];
@@ -206,13 +212,24 @@ static void C4ConvOAM(void)
static void C4DoScaleRotate(int row_padding)
{
+ uint8 w, h;
int16 A, B, C, D;
+ int32 XScale, YScale;
+ int32 Cx, Cy;
+ int32 LineX, LineY;
+ uint32 X, Y;
+ uint8 byte;
+ int outidx = 0;
+ uint8 bit = 0x80;
+ int y;
// Calculate matrix
- int32 XScale = READ_WORD(Memory.C4RAM + 0x1f8f);
- if (XScale & 0x8000) XScale = 0x7fff;
- int32 YScale = READ_WORD(Memory.C4RAM + 0x1f92);
- if (YScale & 0x8000) YScale = 0x7fff;
+ XScale = READ_WORD(Memory.C4RAM + 0x1f8f);
+ if (XScale & 0x8000)
+ XScale = 0x7fff;
+ YScale = READ_WORD(Memory.C4RAM + 0x1f92);
+ if (YScale & 0x8000)
+ YScale = 0x7fff;
if (READ_WORD(Memory.C4RAM + 0x1f80) == 0)
{
@@ -257,8 +274,8 @@ static void C4DoScaleRotate(int row_padding)
}
// Calculate Pixel Resolution
- uint8 w = Memory.C4RAM[0x1f89] & ~7;
- uint8 h = Memory.C4RAM[0x1f8c] & ~7;
+ w = Memory.C4RAM[0x1f89] & ~7;
+ h = Memory.C4RAM[0x1f8c] & ~7;
// printf("%dx%d XScale=%04x YScale=%04x angle=%03x\n", w, h, XScale, YScale, READ_WORD(Memory.C4RAM+0x1f80)&0x1ff);
// printf("Matrix: [%10g %10g] [%04x %04x]\n", A/4096.0, B/4096.0, A&0xffff, B&0xffff);
@@ -267,27 +284,25 @@ static void C4DoScaleRotate(int row_padding)
// Clear the output RAM
memset(Memory.C4RAM, 0, (w + row_padding / 4)*h / 2);
- int32 Cx = (int16)READ_WORD(Memory.C4RAM + 0x1f83);
- int32 Cy = (int16)READ_WORD(Memory.C4RAM + 0x1f86);
+
+ Cx = (int16)READ_WORD(Memory.C4RAM + 0x1f83);
+ Cy = (int16)READ_WORD(Memory.C4RAM + 0x1f86);
// Calculate start position (i.e. (Ox, Oy) = (0, 0))
// The low 12 bits are fractional, so (Cx<<12) gives us the Cx we want in
// the function. We do Cx*A etc normally because the matrix parameters
// already have the fractional parts.
- int32 LineX = (Cx << 12) - Cx * A - Cx * B;
- int32 LineY = (Cy << 12) - Cy * C - Cy * D;
+ LineX = (Cx << 12) - Cx * A - Cx * B;
+ LineY = (Cy << 12) - Cy * C - Cy * D;
// Start loop
- uint32 X, Y;
- uint8 byte;
- int outidx = 0;
- uint8 bit = 0x80;
- int y;
for (y = 0; y < h; y++)
{
+ int x;
+
X = LineX;
Y = LineY;
- int x;
+
for (x = 0; x < w; x++)
{
if ((X >> 12) >= w || (Y >> 12) >= h)
@@ -328,6 +343,8 @@ static void C4DoScaleRotate(int row_padding)
static void C4DrawLine(int32 X1, int32 Y1, int16 Z1,
int32 X2, int32 Y2, int16 Z2, uint8 Color)
{
+ int i;
+
// Transform coordinates
C4WFXVal = (short)X1;
C4WFYVal = (short)Y1;
@@ -357,15 +374,15 @@ static void C4DrawLine(int32 X1, int32 Y1, int16 Z1,
Y2 = (int16)C4WFYVal;
// render line
- int i;
for (i = C4WFDist ? C4WFDist : 1; i > 0; i--)
{
//.loop
if (X1 > 0xff && Y1 > 0xff && X1 < 0x6000 && Y1 < 0x6000)
{
+ uint8 bit;
uint16 addr = ((X1 & ~0x7ff) + (Y1 & ~0x7ff) * 12 + (Y1 & 0x700)) >> 7;
addr = (((Y1 >> 8) >> 3) << 8) - (((Y1 >> 8) >> 3) << 6) + (((X1 >> 8) >> 3) << 4) + ((Y1 >> 8) & 7) * 2;
- uint8 bit = 0x80 >> ((X1 >> 8) & 7);
+ bit = 0x80 >> ((X1 >> 8) & 7);
Memory.C4RAM[addr + 0x300] &= ~bit;
Memory.C4RAM[addr + 0x301] &= ~bit;
if (Color & 1) Memory.C4RAM[addr + 0x300] |= bit;
@@ -410,13 +427,17 @@ static void C4DrawWireFrame(void)
static void C4TransformLines(void)
{
+ uint8 *ptr;
+ uint8* ptr2;
+
C4WFX2Val = Memory.C4RAM[0x1f83];
C4WFY2Val = Memory.C4RAM[0x1f86];
C4WFDist = Memory.C4RAM[0x1f89];
C4WFScale = Memory.C4RAM[0x1f8c];
// transform vertices
- uint8* ptr = Memory.C4RAM;
+ ptr = Memory.C4RAM;
+
{
int i;
for (i = READ_WORD(Memory.C4RAM + 0x1f80); i > 0; i--, ptr += 0x10)
@@ -438,8 +459,8 @@ static void C4TransformLines(void)
WRITE_WORD(Memory.C4RAM + 0x602 + 8, 0x60);
WRITE_WORD(Memory.C4RAM + 0x605 + 8, 0x40);
- ptr = Memory.C4RAM + 0xb02;
- uint8* ptr2 = Memory.C4RAM;
+ ptr = Memory.C4RAM + 0xb02;
+ ptr2 = Memory.C4RAM;
{
int i;
for (i = READ_WORD(Memory.C4RAM + 0xb00); i > 0; i--, ptr += 2, ptr2 += 8)
@@ -524,8 +545,9 @@ static void C4BitPlaneWave()
}
}
-static void C4SprDisintegrate()
+static void C4SprDisintegrate(void)
{
+ uint32 y, i;
uint8 width, height;
uint32 StartX, StartY;
uint8* src;
@@ -545,7 +567,6 @@ static void C4SprDisintegrate()
memset(Memory.C4RAM, 0, width * height / 2);
- uint32 y, i;
for (y = StartY, i = 0; i < height; i++, y += scaleY)
{
uint32 x, j;
diff --git a/src/cheats.c b/src/cheats.c
index d614185..c02d1d5 100644
--- a/src/cheats.c
+++ b/src/cheats.c
@@ -76,20 +76,21 @@ const char* S9xGoldFingerToRaw(const char* code, uint32* address, bool8* sram,
uint8* num_bytes, uint8 bytes[3])
{
char tmp [15];
+ int i;
if (strlen(code) != 14)
return ("Invalid Gold Finger code should be 14 hex digits in length.");
strncpy(tmp, code, 5);
tmp [5] = 0;
+
if (sscanf(tmp, "%x", address) != 1)
return ("Invalid Gold Finger code.");
- int i;
for (i = 0; i < 3; i++)
{
+ int byte;
strncpy(tmp, code + 5 + i * 2, 2);
tmp [2] = 0;
- int byte;
if (sscanf(tmp, "%x", &byte) != 1)
break;
bytes [i] = (uint8) byte;
@@ -101,7 +102,11 @@ const char* S9xGoldFingerToRaw(const char* code, uint32* address, bool8* sram,
const char* S9xGameGenieToRaw(const char* code, uint32* address, uint8* byte)
{
+ uint32 data = 0;
char new_code [12];
+ static char* real_hex = "0123456789ABCDEF";
+ static char* genie_hex = "DF4709156BC8A23E";
+ int i;
if (strlen(code) != 9 || *(code + 4) != '-' || !S9xAllHex(code, 4) ||
!S9xAllHex(code + 5, 4))
@@ -111,15 +116,11 @@ const char* S9xGameGenieToRaw(const char* code, uint32* address, uint8* byte)
strncpy(new_code + 2, code, 4);
strcpy(new_code + 6, code + 5);
- static char* real_hex = "0123456789ABCDEF";
- static char* genie_hex = "DF4709156BC8A23E";
-
- int i;
for (i = 2; i < 10; i++)
{
+ int j;
if (islower(new_code [i]))
new_code [i] = toupper(new_code [i]);
- int j;
for (j = 0; j < 16; j++)
{
if (new_code [i] == genie_hex [j])
@@ -131,7 +132,6 @@ const char* S9xGameGenieToRaw(const char* code, uint32* address, uint8* byte)
if (j == 16)
return ("Invalid hex-character in Game Genie(tm) code");
}
- uint32 data = 0;
sscanf(new_code, "%x", &data);
*byte = (uint8)(data >> 24);
*address = data & 0xffffff;
diff --git a/src/cheats2.c b/src/cheats2.c
index 623a6e3..bf4864a 100644
--- a/src/cheats2.c
+++ b/src/cheats2.c
@@ -129,13 +129,15 @@ void S9xRemoveCheat(uint32 which1)
void S9xApplyCheat(uint32 which1)
{
+ int block;
+ uint8 *ptr;
uint32 address = Cheat.c [which1].address;
if (!Cheat.c [which1].saved)
Cheat.c [which1].saved_byte = S9xGetByte(address);
- int block = (address >> MEMMAP_SHIFT) & MEMMAP_MASK;
- uint8* ptr = Memory.Map [block];
+ block = (address >> MEMMAP_SHIFT) & MEMMAP_MASK;
+ ptr = Memory.Map [block];
if (ptr >= (uint8*) MAP_LAST)
*(ptr + (address & 0xffff)) = Cheat.c [which1].byte;
diff --git a/src/clip.c b/src/clip.c
index 66d6964..bbab8b5 100644
--- a/src/clip.c
+++ b/src/clip.c
@@ -641,8 +641,9 @@ void ComputeClipWindow(bool8_32 invert, int w, int wok, ClipData* pClip)
// the same as the colour window.
if (pClip->Count [w] == 0)
{
- pClip->Count [w] = pClip->Count [5];
int i;
+
+ pClip->Count [w] = pClip->Count [5];
for (i = pClip->Count[w] - 1; i >= 0 ; i--)
{
pClip->Left [i][w] = pClip->Left [i][5];
diff --git a/src/cpuaddr.h b/src/cpuaddr.h
index 8ddbc72..d68a328 100644
--- a/src/cpuaddr.h
+++ b/src/cpuaddr.h
@@ -46,7 +46,7 @@
#ifndef _CPUADDR_H_
#define _CPUADDR_H_
-EXTERN_C long OpAddress;
+extern long OpAddress;
static INLINE void Immediate8()
{
diff --git a/src/cpuexec.h b/src/cpuexec.h
index 06ccfc0..5ca4f86 100644
--- a/src/cpuexec.h
+++ b/src/cpuexec.h
@@ -70,7 +70,6 @@ typedef struct
uint32 FrameAdvanceCount;
} SICPU;
-START_EXTERN_C
void S9xMainLoop(void);
void S9xReset(void);
void S9xDoHBlankProcessing();
@@ -91,7 +90,6 @@ extern uint8 S9xE0M0X1 [256];
#endif
extern SICPU ICPU;
-END_EXTERN_C
static INLINE void CLEAR_IRQ_SOURCE(uint32 M)
{
diff --git a/src/cpumacro.h b/src/cpumacro.h
index 565f1b2..abafc64 100644
--- a/src/cpumacro.h
+++ b/src/cpumacro.h
@@ -59,6 +59,7 @@ static INLINE void ADC8()
if (CheckDecimal())
{
+ uint8 Ans8;
uint8 A1 = (Registers.A.W) & 0xF;
uint8 A2 = (Registers.A.W >> 4) & 0xF;
uint8 W1 = Work8 & 0xF;
@@ -80,7 +81,7 @@ static INLINE void ADC8()
else
ClearCarry();
- uint8 Ans8 = (A2 << 4) | A1;
+ Ans8 = (A2 << 4) | A1;
if (~(Registers.AL ^ Work8) &
(Work8 ^ Ans8) & 0x80)
SetOverflow();
@@ -112,6 +113,7 @@ static INLINE void ADC16()
if (CheckDecimal())
{
+ uint16 Ans16;
uint8 A1 = (Registers.A.W) & 0xF;
uint8 A2 = (Registers.A.W >> 4) & 0xF;
uint8 A3 = (Registers.A.W >> 8) & 0xF;
@@ -151,7 +153,7 @@ static INLINE void ADC16()
else
ClearCarry();
- uint16 Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1);
+ Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1);
if (~(Registers.A.W ^ Work16) &
(Work16 ^ Ans16) & 0x8000)
SetOverflow();
@@ -208,24 +210,26 @@ static INLINE void A_ASL8()
SetZN8(Registers.AL);
}
-static INLINE void ASL16()
+static INLINE void ASL16(void)
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint16 Work16 = S9xGetWord(OpAddress);
+ Work16 = S9xGetWord(OpAddress);
ICPU._Carry = (Work16 & 0x8000) != 0;
Work16 <<= 1;
S9xSetWord(Work16, OpAddress);
SetZN16(Work16);
}
-static INLINE void ASL8()
+static INLINE void ASL8(void)
{
+ uint8 Work8;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint8 Work8 = S9xGetByte(OpAddress);
+ Work8 = S9xGetByte(OpAddress);
ICPU._Carry = (Work8 & 0x80) != 0;
Work8 <<= 1;
S9xSetByte(Work8, OpAddress);
@@ -324,6 +328,7 @@ static INLINE void A_DEC8()
static INLINE void DEC16()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
@@ -331,13 +336,14 @@ static INLINE void DEC16()
CPU.WaitAddress = NULL;
#endif
- uint16 Work16 = S9xGetWord(OpAddress) - 1;
+ Work16 = S9xGetWord(OpAddress) - 1;
S9xSetWord(Work16, OpAddress);
SetZN16(Work16);
}
static INLINE void DEC8()
{
+ uint8 Work8;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
@@ -345,7 +351,7 @@ static INLINE void DEC8()
CPU.WaitAddress = NULL;
#endif
- uint8 Work8 = S9xGetByte(OpAddress) - 1;
+ Work8 = S9xGetByte(OpAddress) - 1;
S9xSetByte(Work8, OpAddress);
SetZN8(Work8);
}
@@ -390,6 +396,7 @@ static INLINE void A_INC8()
static INLINE void INC16()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
@@ -397,13 +404,14 @@ static INLINE void INC16()
CPU.WaitAddress = NULL;
#endif
- uint16 Work16 = S9xGetWord(OpAddress) + 1;
+ Work16 = S9xGetWord(OpAddress) + 1;
S9xSetWord(Work16, OpAddress);
SetZN16(Work16);
}
static INLINE void INC8()
{
+ uint8 Work8;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
@@ -411,7 +419,7 @@ static INLINE void INC8()
CPU.WaitAddress = NULL;
#endif
- uint8 Work8 = S9xGetByte(OpAddress) + 1;
+ Work8 = S9xGetByte(OpAddress) + 1;
S9xSetByte(Work8, OpAddress);
SetZN8(Work8);
}
@@ -474,10 +482,11 @@ static INLINE void A_LSR8()
static INLINE void LSR16()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint16 Work16 = S9xGetWord(OpAddress);
+ Work16 = S9xGetWord(OpAddress);
ICPU._Carry = Work16 & 1;
Work16 >>= 1;
S9xSetWord(Work16, OpAddress);
@@ -486,10 +495,11 @@ static INLINE void LSR16()
static INLINE void LSR8()
{
+ uint8 Work8;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint8 Work8 = S9xGetByte(OpAddress);
+ Work8 = S9xGetByte(OpAddress);
ICPU._Carry = Work8 & 1;
Work8 >>= 1;
S9xSetByte(Work8, OpAddress);
@@ -510,10 +520,11 @@ static INLINE void ORA8()
static INLINE void A_ROL16()
{
+ uint32 Work32;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint32 Work32 = (Registers.A.W << 1) | CheckCarry();
+ Work32 = (Registers.A.W << 1) | CheckCarry();
ICPU._Carry = Work32 >= 0x10000;
Registers.A.W = (uint16) Work32;
SetZN16((uint16) Work32);
@@ -521,12 +532,13 @@ static INLINE void A_ROL16()
static INLINE void A_ROL8()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint16 Work16 = Registers.AL;
+ Work16 = Registers.AL;
Work16 <<= 1;
- Work16 |= CheckCarry();
+ Work16 |= CheckCarry();
ICPU._Carry = Work16 >= 0x100;
Registers.AL = (uint8) Work16;
SetZN8((uint8) Work16);
@@ -534,10 +546,11 @@ static INLINE void A_ROL8()
static INLINE void ROL16()
{
+ uint32 Work32;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint32 Work32 = S9xGetWord(OpAddress);
+ Work32 = S9xGetWord(OpAddress);
Work32 <<= 1;
Work32 |= CheckCarry();
ICPU._Carry = Work32 >= 0x10000;
@@ -547,10 +560,11 @@ static INLINE void ROL16()
static INLINE void ROL8()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint16 Work16 = S9xGetByte(OpAddress);
+ Work16 = S9xGetByte(OpAddress);
Work16 <<= 1;
Work16 |= CheckCarry();
ICPU._Carry = Work16 >= 0x100;
@@ -560,10 +574,11 @@ static INLINE void ROL8()
static INLINE void A_ROR16()
{
+ uint32 Work32;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint32 Work32 = Registers.A.W;
+ Work32 = Registers.A.W;
Work32 |= (int) CheckCarry() << 16;
ICPU._Carry = (uint8)(Work32 & 1);
Work32 >>= 1;
@@ -573,10 +588,11 @@ static INLINE void A_ROR16()
static INLINE void A_ROR8()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint16 Work16 = Registers.AL | ((uint16) CheckCarry() << 8);
+ Work16 = Registers.AL | ((uint16) CheckCarry() << 8);
ICPU._Carry = (uint8) Work16 & 1;
Work16 >>= 1;
Registers.AL = (uint8) Work16;
@@ -585,10 +601,11 @@ static INLINE void A_ROR8()
static INLINE void ROR16()
{
+ uint32 Work32;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint32 Work32 = S9xGetWord(OpAddress);
+ Work32 = S9xGetWord(OpAddress);
Work32 |= (int) CheckCarry() << 16;
ICPU._Carry = (uint8)(Work32 & 1);
Work32 >>= 1;
@@ -598,10 +615,11 @@ static INLINE void ROR16()
static INLINE void ROR8()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint16 Work16 = S9xGetByte(OpAddress);
+ Work16 = S9xGetByte(OpAddress);
Work16 |= (int) CheckCarry() << 8;
ICPU._Carry = (uint8)(Work16 & 1);
Work16 >>= 1;
@@ -615,6 +633,7 @@ static INLINE void SBC16()
if (CheckDecimal())
{
+ uint16 Ans16;
uint8 A1 = (Registers.A.W) & 0xF;
uint8 A2 = (Registers.A.W >> 4) & 0xF;
uint8 A3 = (Registers.A.W >> 8) & 0xF;
@@ -651,7 +670,7 @@ static INLINE void SBC16()
else
SetCarry();
- uint16 Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1);
+ Ans16 = (A4 << 12) | (A3 << 8) | (A2 << 4) | (A1);
if ((Registers.A.W ^ Work16) &
(Registers.A.W ^ Ans16) & 0x8000)
SetOverflow();
@@ -682,6 +701,7 @@ static INLINE void SBC8()
uint8 Work8 = S9xGetByte(OpAddress);
if (CheckDecimal())
{
+ uint8 Ans8;
uint8 A1 = (Registers.A.W) & 0xF;
uint8 A2 = (Registers.A.W >> 4) & 0xF;
uint8 W1 = Work8 & 0xF;
@@ -702,7 +722,7 @@ static INLINE void SBC8()
else
SetCarry();
- uint8 Ans8 = (A2 << 4) | A1;
+ Ans8 = (A2 << 4) | A1;
if ((Registers.AL ^ Work8) &
(Registers.AL ^ Ans8) & 0x80)
SetOverflow();
@@ -768,10 +788,11 @@ static INLINE void STZ8()
static INLINE void TSB16()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint16 Work16 = S9xGetWord(OpAddress);
+ Work16 = S9xGetWord(OpAddress);
ICPU._Zero = (Work16 & Registers.A.W) != 0;
Work16 |= Registers.A.W;
S9xSetWord(Work16, OpAddress);
@@ -779,10 +800,11 @@ static INLINE void TSB16()
static INLINE void TSB8()
{
+ uint8 Work8;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint8 Work8 = S9xGetByte(OpAddress);
+ Work8 = S9xGetByte(OpAddress);
ICPU._Zero = Work8 & Registers.AL;
Work8 |= Registers.AL;
S9xSetByte(Work8, OpAddress);
@@ -790,10 +812,11 @@ static INLINE void TSB8()
static INLINE void TRB16()
{
+ uint16 Work16;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint16 Work16 = S9xGetWord(OpAddress);
+ Work16 = S9xGetWord(OpAddress);
ICPU._Zero = (Work16 & Registers.A.W) != 0;
Work16 &= ~Registers.A.W;
S9xSetWord(Work16, OpAddress);
@@ -801,10 +824,11 @@ static INLINE void TRB16()
static INLINE void TRB8()
{
+ uint8 Work8;
#ifdef VAR_CYCLES
CPU.Cycles += ONE_CYCLE;
#endif
- uint8 Work8 = S9xGetByte(OpAddress);
+ Work8 = S9xGetByte(OpAddress);
ICPU._Zero = Work8 & Registers.AL;
Work8 &= ~Registers.AL;
S9xSetByte(Work8, OpAddress);
diff --git a/src/cpuops.c b/src/cpuops.c
index b0c4b78..c58502a 100644
--- a/src/cpuops.c
+++ b/src/cpuops.c
@@ -3292,13 +3292,14 @@ static void OpBBX0(void)
/* XCE *************************************************************************************** */
static void OpFB(void)
{
+ uint8 A1, A2;
#ifdef VAR_CYCLES
- CPU.Cycles += ONE_CYCLE;
+ CPU.Cycles += ONE_CYCLE;
#endif
- uint8 A1 = ICPU._Carry;
- uint8 A2 = Registers.PH;
- ICPU._Carry = A2 & 1;
+ A1 = ICPU._Carry;
+ A2 = Registers.PH;
+ ICPU._Carry = A2 & 1;
Registers.PH = A1;
if (CheckEmulation())
@@ -3881,6 +3882,7 @@ static void Op42(void)
{
#ifndef SA1_OPCODES
uint8 b;
+ int8_t s9xInt8;
CPU.WaitAddress = NULL;
CPU.Cycles = CPU.NextEvent;
@@ -3889,7 +3891,7 @@ static void Op42(void)
b = *CPU.PC++;
//relative
- signed char s9xInt8 = 0xF0 | (b & 0xF);
+ s9xInt8 = 0xF0 | (b & 0xF);
#ifdef VAR_CYCLES
CPU.Cycles += CPU.MemSpeed;
#endif
diff --git a/src/display.h b/src/display.h
index fdb1726..339e68f 100644
--- a/src/display.h
+++ b/src/display.h
@@ -41,7 +41,6 @@
#ifndef _DISPLAY_H_
#define _DISPLAY_H_
-START_EXTERN_C
// Routines the port specific code has to implement
void S9xSetPalette();
void S9xTextMode();
@@ -67,6 +66,5 @@ const char* S9xGetSnapshotDirectory();
const char* S9xGetROMDirectory();
const char* S9xGetSRAMFilename();
const char* S9xGetFilename(const char* extension);
-END_EXTERN_C
#endif
diff --git a/src/dma.c b/src/dma.c
index 4aaff99..b501c43 100644
--- a/src/dma.c
+++ b/src/dma.c
@@ -74,22 +74,24 @@ static int S9xCompareSDD1IndexEntries(const void* p1, const void* p2)
/**********************************************************************************************/
void S9xDoDMA(uint8 Channel)
{
+ int count, inc;
uint8 Work;
+ bool8 in_sa1_dma = FALSE;
+ uint8* in_sdd1_dma = NULL;
+ SDMA *d;
if (Channel > 7 || CPU.InDMA)
return;
CPU.InDMA = TRUE;
- bool8 in_sa1_dma = FALSE;
- uint8* in_sdd1_dma = NULL;
- SDMA* d = &DMA[Channel];
+ d = &DMA[Channel];
- int count = d->TransferBytes;
+ count = d->TransferBytes;
if (count == 0)
count = 0x10000;
- int inc = d->AAddressFixed ? 0 : (!d->AAddressDecrement ? 1 : -1);
+ inc = d->AAddressFixed ? 0 : (!d->AAddressDecrement ? 1 : -1);
if ((d->ABank == 0x7E || d->ABank == 0x7F) && d->BAddress == 0x80)
{
@@ -113,9 +115,11 @@ void S9xDoDMA(uint8 Channel)
{
if (d->AAddressFixed && Memory.FillRAM [0x4801] > 0)
{
+ uint32 address;
+
// Hacky support for pre-decompressed S-DD1 data
- inc = !d->AAddressDecrement ? 1 : -1;
- uint32 address = (((d->ABank << 16) | d->AAddress) & 0xfffff) << 4;
+ inc = !d->AAddressDecrement ? 1 : -1;
+ address = (((d->ABank << 16) | d->AAddress) & 0xfffff) << 4;
address |= Memory.FillRAM [0x4804 + ((d->ABank - 0xc0) >> 4)];
if (Settings.SDD1Pack)
@@ -192,6 +196,7 @@ void S9xDoDMA(uint8 Channel)
if (d->BAddress == 0x18 && (d->ABank & 0xf0) == 0x40)
#endif
{
+ int i;
// Perform packed bitmap to PPU character format conversion on the
// data before transmitting it to V-RAM via-DMA.
int num_chars = 1 << ((Memory.FillRAM [0x2231] >> 2) & 7);
@@ -213,7 +218,6 @@ void S9xDoDMA(uint8 Channel)
//printf ("%08x,", base); fflush (stdout);
//printf ("depth = %d, count = %d, bytes_per_char = %d, bytes_per_line = %d, num_chars = %d, char_line_bytes = %d\n",
//depth, count, bytes_per_char, bytes_per_line, num_chars, char_line_bytes);
- int i;
switch (depth)
{
@@ -320,6 +324,9 @@ void S9xDoDMA(uint8 Channel)
if (!d->TransferDirection)
{
+ uint8 *base;
+ uint16 p;
+
#ifdef VAR_CYCLES
//reflects extra cycle used by DMA
CPU.Cycles += 8 * (count + 1);
@@ -327,8 +334,8 @@ void S9xDoDMA(uint8 Channel)
//needs fixing for the extra DMA cycle
CPU.Cycles += (1 + count) + ((1 + count) >> 2);
#endif
- uint8* base = GetBasePointer((d->ABank << 16) + d->AAddress);
- uint16 p = d->AAddress;
+ base = GetBasePointer((d->ABank << 16) + d->AAddress);
+ p = d->AAddress;
if (!base)
base = Memory.ROM;
@@ -690,8 +697,9 @@ update_address:
CPU.InDMA = FALSE;
}
-void S9xStartHDMA()
+void S9xStartHDMA(void)
{
+ uint8 i;
//if (Settings.DisableHDMA)
//IPPU.HDMA = 0;
//else
@@ -699,7 +707,6 @@ void S9xStartHDMA()
IPPU.HDMAStarted = TRUE;
- uint8 i;
for (i = 0; i < 8; i++)
{
if (IPPU.HDMA & (1 << i))
diff --git a/src/dma.h b/src/dma.h
index 6ffc070..a2270d0 100644
--- a/src/dma.h
+++ b/src/dma.h
@@ -41,11 +41,9 @@
#ifndef _DMA_H_
#define _DMA_H_
-START_EXTERN_C
void S9xResetDMA(void);
uint8 S9xDoHDMA(uint8);
-void S9xStartHDMA();
+void S9xStartHDMA(void);
void S9xDoDMA(uint8);
-END_EXTERN_C
#endif
diff --git a/src/dsp1.c b/src/dsp1.c
index 5287575..e3910bb 100644
--- a/src/dsp1.c
+++ b/src/dsp1.c
@@ -952,12 +952,13 @@ void DSP2SetByte(uint8 byte, uint16 address)
#ifdef FAST_LSB_WORD_ACCESS
*(uint32*)DSP1.output = DSP2Op09Word1 * DSP2Op09Word2;
#else
- uint32 temp;
- temp = DSP2Op09Word1 * DSP2Op09Word2;
- DSP1.output[0] = temp & 0xFF;
- DSP1.output[1] = (temp >> 8) & 0xFF;
- DSP1.output[2] = (temp >> 16) & 0xFF;
- DSP1.output[3] = (temp >> 24) & 0xFF;
+ {
+ uint32 temp = DSP2Op09Word1 * DSP2Op09Word2;
+ DSP1.output[0] = temp & 0xFF;
+ DSP1.output[1] = (temp >> 8) & 0xFF;
+ DSP1.output[2] = (temp >> 16) & 0xFF;
+ DSP1.output[3] = (temp >> 24) & 0xFF;
+ }
#endif
break;
case 0x05:
diff --git a/src/dsp1.h b/src/dsp1.h
index b1e522a..ffe68e6 100644
--- a/src/dsp1.h
+++ b/src/dsp1.h
@@ -120,11 +120,9 @@ typedef struct
uint8 output [512];
} SDSP1;
-START_EXTERN_C
-void S9xResetDSP1();
+void S9xResetDSP1(void);
uint8 S9xGetDSP(uint16 Address);
void S9xSetDSP(uint8 Byte, uint16 Address);
-END_EXTERN_C
extern SDSP1 DSP1;
diff --git a/src/dsp1_gp32.h b/src/dsp1_gp32.h
index 56223c4..669ad35 100644
--- a/src/dsp1_gp32.h
+++ b/src/dsp1_gp32.h
@@ -230,16 +230,14 @@ struct DSP1_Inverse
int16 B;
};
-START_EXTERN_C
-void S9xResetDSP1();
+void S9xResetDSP1(void);
uint8 S9xGetDSP(uint16 Address);
void S9xSetDSP(uint8 Byte, uint16 Address);
-END_EXTERN_C
#ifndef __GP32__
extern struct SDSP1 DSP1;
#else
-extern "C" struct SDSP1 DSP1;
+extern struct SDSP1 DSP1;
#endif
#endif
diff --git a/src/dsp1emu.c b/src/dsp1emu.c
index e14ddf0..c243c9f 100644
--- a/src/dsp1emu.c
+++ b/src/dsp1emu.c
@@ -214,7 +214,7 @@ short Op00Multiplicand;
short Op00Multiplier;
short Op00Result;
-void DSPOp00()
+void DSPOp00(void)
{
Op00Result = Op00Multiplicand * Op00Multiplier >> 15;
}
@@ -223,7 +223,7 @@ short Op20Multiplicand;
short Op20Multiplier;
short Op20Result;
-void DSPOp20()
+void DSPOp20(void)
{
Op20Result = Op20Multiplicand * Op20Multiplier >> 15;
Op20Result++;
@@ -285,7 +285,7 @@ void DSP1_Inverse(short Coefficient, short Exponent, short* iCoefficient, short*
}
}
-void DSPOp10()
+void DSPOp10(void)
{
DSP1_Inverse(Op10Coefficient, Op10Exponent, &Op10CoefficientR, &Op10ExponentR);
}
@@ -369,24 +369,26 @@ const short DSP1_SinTable[256] =
short DSP1_Sin(short Angle)
{
+ int S;
if (Angle < 0)
{
if (Angle == -32768) return 0;
return -DSP1_Sin(-Angle);
}
- int S = DSP1_SinTable[Angle >> 8] + (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[0x40 + (Angle >> 8)] >> 15);
+ S = DSP1_SinTable[Angle >> 8] + (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[0x40 + (Angle >> 8)] >> 15);
if (S > 32767) S = 32767;
return (short) S;
}
short DSP1_Cos(short Angle)
{
+ int S;
if (Angle < 0)
{
if (Angle == -32768) return -32768;
Angle = -Angle;
}
- int S = DSP1_SinTable[0x40 + (Angle >> 8)] - (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[Angle >> 8] >> 15);
+ S = DSP1_SinTable[0x40 + (Angle >> 8)] - (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[Angle >> 8] >> 15);
if (S < -32768) S = -32767;
return (short) S;
}
@@ -472,7 +474,7 @@ void DSP1_Normalizefloat(int Product, short* Coefficient, short* Exponent)
*Exponent = e;
}
-void DSPOp04()
+void DSPOp04(void)
{
Op04Sin = DSP1_Sin(Op04Angle) * Op04Radius >> 15;
Op04Cos = DSP1_Cos(Op04Angle) * Op04Radius >> 15;
@@ -484,7 +486,7 @@ short Op0CY1;
short Op0CX2;
short Op0CY2;
-void DSPOp0C()
+void DSPOp0C(void)
{
Op0CX2 = (Op0CY1 * DSP1_Sin(Op0CA) >> 15) + (Op0CX1 * DSP1_Cos(Op0CA) >> 15);
Op0CY2 = (Op0CY1 * DSP1_Cos(Op0CA) >> 15) - (Op0CX1 * DSP1_Sin(Op0CA) >> 15);
@@ -551,7 +553,7 @@ short ScrDispl;
#ifdef __OPT02__
-void DSPOp02()
+void DSPOp02(void)
{
ViewerZ1 = -Cos(Angle(Op02AZS));
ViewerX1 = Sin(Angle(Op02AZS)) * Sin(Angle(Op02AAS));
@@ -638,7 +640,7 @@ void DSPOp02()
}
#else
-void DSPOp02()
+void DSPOp02(void)
{
ViewerZ1 = -cosf(Op02AZS * 6.2832 / 65536.0);
ViewerX1 = sinf(Op02AZS * 6.2832 / 65536.0) * sinf(Op02AAS * 6.2832 / 65536.0);
@@ -742,7 +744,7 @@ float NAzs, NAas;
float RVPos, RHPos, RXRes, RYRes;
-void GetRXYPos()
+void GetRXYPos(void)
{
float scalar;
@@ -762,7 +764,7 @@ void GetRXYPos()
RYRes += scalar * cosf(NAas + PI / 2) * RHPos;
}
-void DSPOp0A()
+void DSPOp0A(void)
{
float x2, y2, x3, y3, x4, y4, m, ypos;
@@ -858,7 +860,7 @@ int tanval2;
#define SADDMULT1616(res,a,b,c,d) res=((int64)a*(int64)b+(int64)c*(int64)d)>>16;
#ifdef __OPT06__
-void DSPOp06()
+void DSPOp06(void)
{
ObjPX = Op06X - Op02FX;
@@ -920,7 +922,7 @@ void DSPOp06()
}
#else
-void DSPOp06()
+void DSPOp06(void)
{
ObjPX = Op06X - Op02FX;
ObjPY = Op06Y - Op02FY;
@@ -981,7 +983,7 @@ short Op21Zr;
short Op21Xr;
short Op21Yr;
-void DSPOp01()
+void DSPOp01(void)
{
short SinAz = DSP1_Sin(Op01Zr);
short CosAz = DSP1_Cos(Op01Zr);
@@ -1005,7 +1007,7 @@ void DSPOp01()
matrixA[2][2] = (Op01m * CosAx >> 15) * CosAy >> 15;
}
-void DSPOp11()
+void DSPOp11(void)
{
short SinAz = DSP1_Sin(Op11Zr);
short CosAz = DSP1_Cos(Op11Zr);
@@ -1029,7 +1031,7 @@ void DSPOp11()
matrixB[2][2] = (Op11m * CosAx >> 15) * CosAy >> 15;
}
-void DSPOp21()
+void DSPOp21(void)
{
short SinAz = DSP1_Sin(Op21Zr);
short CosAz = DSP1_Cos(Op21Zr);
@@ -1072,21 +1074,21 @@ short Op2DF;
short Op2DL;
short Op2DU;
-void DSPOp0D()
+void DSPOp0D(void)
{
Op0DF = (Op0DX * matrixA[0][0] >> 15) + (Op0DY * matrixA[0][1] >> 15) + (Op0DZ * matrixA[0][2] >> 15);
Op0DL = (Op0DX * matrixA[1][0] >> 15) + (Op0DY * matrixA[1][1] >> 15) + (Op0DZ * matrixA[1][2] >> 15);
Op0DU = (Op0DX * matrixA[2][0] >> 15) + (Op0DY * matrixA[2][1] >> 15) + (Op0DZ * matrixA[2][2] >> 15);
}
-void DSPOp1D()
+void DSPOp1D(void)
{
Op1DF = (Op1DX * matrixB[0][0] >> 15) + (Op1DY * matrixB[0][1] >> 15) + (Op1DZ * matrixB[0][2] >> 15);
Op1DL = (Op1DX * matrixB[1][0] >> 15) + (Op1DY * matrixB[1][1] >> 15) + (Op1DZ * matrixB[1][2] >> 15);
Op1DU = (Op1DX * matrixB[2][0] >> 15) + (Op1DY * matrixB[2][1] >> 15) + (Op1DZ * matrixB[2][2] >> 15);
}
-void DSPOp2D()
+void DSPOp2D(void)
{
Op2DF = (Op2DX * matrixC[0][0] >> 15) + (Op2DY * matrixC[0][1] >> 15) + (Op2DZ * matrixC[0][2] >> 15);
Op2DL = (Op2DX * matrixC[1][0] >> 15) + (Op2DY * matrixC[1][1] >> 15) + (Op2DZ * matrixC[1][2] >> 15);
@@ -1112,21 +1114,21 @@ short Op23X;
short Op23Y;
short Op23Z;
-void DSPOp03()
+void DSPOp03(void)
{
Op03X = (Op03F * matrixA[0][0] >> 15) + (Op03L * matrixA[1][0] >> 15) + (Op03U * matrixA[2][0] >> 15);
Op03Y = (Op03F * matrixA[0][1] >> 15) + (Op03L * matrixA[1][1] >> 15) + (Op03U * matrixA[2][1] >> 15);
Op03Z = (Op03F * matrixA[0][2] >> 15) + (Op03L * matrixA[1][2] >> 15) + (Op03U * matrixA[2][2] >> 15);
}
-void DSPOp13()
+void DSPOp13(void)
{
Op13X = (Op13F * matrixB[0][0] >> 15) + (Op13L * matrixB[1][0] >> 15) + (Op13U * matrixB[2][0] >> 15);
Op13Y = (Op13F * matrixB[0][1] >> 15) + (Op13L * matrixB[1][1] >> 15) + (Op13U * matrixB[2][1] >> 15);
Op13Z = (Op13F * matrixB[0][2] >> 15) + (Op13L * matrixB[1][2] >> 15) + (Op13U * matrixB[2][2] >> 15);
}
-void DSPOp23()
+void DSPOp23(void)
{
Op23X = (Op23F * matrixC[0][0] >> 15) + (Op23L * matrixC[1][0] >> 15) + (Op23U * matrixC[2][0] >> 15);
Op23Y = (Op23F * matrixC[0][1] >> 15) + (Op23L * matrixC[1][1] >> 15) + (Op23U * matrixC[2][1] >> 15);
@@ -1143,7 +1145,7 @@ short Op14Zrr;
short Op14Xrr;
short Op14Yrr;
-void DSPOp14()
+void DSPOp14(void)
{
short CSec, ESec, CTan, CSin, C, E;
@@ -1200,7 +1202,7 @@ short Op0EV;
short Op0EX;
short Op0EY;
-void DSPOp0E()
+void DSPOp0E(void)
{
// screen Directions UP
RVPos = Op0EV;
@@ -1223,24 +1225,24 @@ short Op2BY;
short Op2BZ;
short Op2BS;
-void DSPOp0B()
+void DSPOp0B(void)
{
Op0BS = (Op0BX * matrixA[0][0] + Op0BY * matrixA[0][1] + Op0BZ * matrixA[0][2]) >> 15;
}
-void DSPOp1B()
+void DSPOp1B(void)
{
Op1BS = (Op1BX * matrixB[0][0] + Op1BY * matrixB[0][1] + Op1BZ * matrixB[0][2]) >> 15;
}
-void DSPOp2B()
+void DSPOp2B(void)
{
Op2BS = (Op2BX * matrixC[0][0] + Op2BY * matrixC[0][1] + Op2BZ * matrixC[0][2]) >> 15;
}
short Op08X, Op08Y, Op08Z, Op08Ll, Op08Lh;
-void DSPOp08()
+void DSPOp08(void)
{
int Op08Size = (Op08X * Op08X + Op08Y * Op08Y + Op08Z * Op08Z) << 1;
Op08Ll = Op08Size & 0xffff;
@@ -1249,14 +1251,14 @@ void DSPOp08()
short Op18X, Op18Y, Op18Z, Op18R, Op18D;
-void DSPOp18()
+void DSPOp18(void)
{
Op18D = (Op18X * Op18X + Op18Y * Op18Y + Op18Z * Op18Z - Op18R * Op18R) >> 15;
}
short Op38X, Op38Y, Op38Z, Op38R, Op38D;
-void DSPOp38()
+void DSPOp38(void)
{
Op38D = (Op38X * Op38X + Op38Y * Op38Y + Op38Z * Op38Z - Op38R * Op38R) >> 15;
Op38D++;
@@ -1267,7 +1269,7 @@ short Op28Y;
short Op28Z;
short Op28R;
-void DSPOp28()
+void DSPOp28(void)
{
int Radius = Op28X * Op28X + Op28Y * Op28Y + Op28Z * Op28Z;
@@ -1275,15 +1277,16 @@ void DSPOp28()
else
{
short C, E;
+ short Pos, Node1, Node2;
+
DSP1_Normalizefloat(Radius, &C, &E);
if (E & 1) C = C * 0x4000 >> 15;
- short Pos = C * 0x0040 >> 15;
-
- short Node1 = DSP1ROM[(0x00d5 + Pos) & 1023];
- short Node2 = DSP1ROM[(0x00d6 + Pos) & 1023];
+ Pos = C * 0x0040 >> 15;
+ Node1 = DSP1ROM[(0x00d5 + Pos) & 1023];
+ Node2 = DSP1ROM[(0x00d6 + Pos) & 1023];
- Op28R = ((Node2 - Node1) * (C & 0x1ff) >> 9) + Node1;
+ Op28R = ((Node2 - Node1) * (C & 0x1ff) >> 9) + Node1;
Op28R >>= (E >> 1);
}
}
@@ -1297,7 +1300,7 @@ short Op1CX2;
short Op1CY2;
short Op1CZ2;
-void DSPOp1C()
+void DSPOp1C(void)
{
// Rotate Around Op1CZ1
@@ -1322,7 +1325,7 @@ void DSPOp1C()
unsigned short Op0FRamsize;
unsigned short Op0FPass;
-void DSPOp0F()
+void DSPOp0F(void)
{
Op0FPass = 0x0000;
}
@@ -1330,7 +1333,7 @@ void DSPOp0F()
short Op2FUnknown;
short Op2FSize;
-void DSPOp2F()
+void DSPOp2F(void)
{
Op2FSize = 0x100;
}
diff --git a/src/getset.h b/src/getset.h
index 98c156c..5cb4c74 100644
--- a/src/getset.h
+++ b/src/getset.h
@@ -129,13 +129,17 @@ static INLINE uint8 S9xGetByte(uint32 Address)
static INLINE uint16 S9xGetWord(uint32 Address)
{
+#if defined(VAR_CYCLES) || defined(CPU_SHUTDOWN)
+ int block;
+#endif
+ uint8 *GetAddress;
+
if ((Address & 0x1fff) == 0x1fff)
return (S9xGetByte(Address) | (S9xGetByte(Address + 1) << 8));
#if defined(VAR_CYCLES) || defined(CPU_SHUTDOWN)
- int block;
- uint8* GetAddress = Memory.Map [block = (Address >> MEMMAP_SHIFT) & MEMMAP_MASK];
+ GetAddress = Memory.Map [block = (Address >> MEMMAP_SHIFT) & MEMMAP_MASK];
#else
- uint8* GetAddress = Memory.Map [(Address >> MEMMAP_SHIFT) & MEMMAP_MASK];
+ GetAddress = Memory.Map [(Address >> MEMMAP_SHIFT) & MEMMAP_MASK];
#endif
if (GetAddress >= (uint8*) MAP_LAST)
{
@@ -225,14 +229,18 @@ static INLINE uint16 S9xGetWord(uint32 Address)
static INLINE void S9xSetByte(uint8 Byte, uint32 Address)
{
+#if defined(VAR_CYCLES)
+ int block;
+#endif
+ uint8 *SetAddress;
+
#if defined(CPU_SHUTDOWN)
CPU.WaitAddress = NULL;
#endif
#if defined(VAR_CYCLES)
- int block;
- uint8* SetAddress = Memory.WriteMap [block = ((Address >> MEMMAP_SHIFT) & MEMMAP_MASK)];
+ SetAddress = Memory.WriteMap [block = ((Address >> MEMMAP_SHIFT) & MEMMAP_MASK)];
#else
- uint8* SetAddress = Memory.WriteMap [(Address >> MEMMAP_SHIFT) & MEMMAP_MASK];
+ SetAddress = Memory.WriteMap [(Address >> MEMMAP_SHIFT) & MEMMAP_MASK];
#endif
if (SetAddress >= (uint8*) MAP_LAST)
@@ -345,14 +353,18 @@ static INLINE void S9xSetByte(uint8 Byte, uint32 Address)
static INLINE void S9xSetWord(uint16 Word, uint32 Address)
{
+#if defined (VAR_CYCLES)
+ int block;
+#endif
+ uint8* SetAddress;
+
#if defined(CPU_SHUTDOWN)
CPU.WaitAddress = NULL;
#endif
#if defined (VAR_CYCLES)
- int block;
- uint8* SetAddress = Memory.WriteMap [block = ((Address >> MEMMAP_SHIFT) & MEMMAP_MASK)];
+ SetAddress = Memory.WriteMap [block = ((Address >> MEMMAP_SHIFT) & MEMMAP_MASK)];
#else
- uint8* SetAddress = Memory.WriteMap [(Address >> MEMMAP_SHIFT) & MEMMAP_MASK];
+ SetAddress = Memory.WriteMap [(Address >> MEMMAP_SHIFT) & MEMMAP_MASK];
#endif
if (SetAddress >= (uint8*) MAP_LAST)
diff --git a/src/gfx.h b/src/gfx.h
index ce7efde..f873531 100644
--- a/src/gfx.h
+++ b/src/gfx.h
@@ -252,7 +252,6 @@ typedef struct
LargePixelRenderer Large;
} TileRendererSet;
-START_EXTERN_C
void S9xStartScreenRefresh();
void S9xDrawScanLine(uint8 Line);
void S9xEndScreenRefresh();
@@ -278,6 +277,4 @@ void S9xSyncSpeed();
bool8_32 S9xSetRenderPixelFormat(int format);
#endif
-END_EXTERN_C
-
#endif
diff --git a/src/globals.c b/src/globals.c
index cc60f25..8d09213 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -41,7 +41,6 @@
* Super NES and Super Nintendo Entertainment System are trademarks of
* Nintendo Co., Limited and its subsidiary companies.
*/
-// START_EXTERN_C
#include "snes9x.h"
#include "memmap.h"
#include "ppu.h"
@@ -55,9 +54,7 @@
#include "soundux.h"
#include "cheats.h"
#include "sa1.h"
-// END_EXTERN_C
-START_EXTERN_C
char String[513];
int (*APUMainLoop)(int);
@@ -100,8 +97,6 @@ CMemory Memory;
SSNESGameFixes SNESGameFixes;
-END_EXTERN_C
-
FxInit_s SuperFX;
SPPU PPU;
@@ -281,7 +276,6 @@ uint32 TailMask [5] =
#endif
};
-START_EXTERN_C
uint8 APUROM [64] =
{
0xCD, 0xEF, 0xBD, 0xE8, 0x00, 0xC6, 0x1D, 0xD0, 0xFC, 0x8F, 0xAA, 0xF4, 0x8F,
@@ -437,5 +431,3 @@ uint8 S9xE0M0X0 [256] =
2, 7, 6, 8, 5, 5, 8, 7, 2, 6, 5, 2, 6, 6, 9, 6
};
#endif
-
-END_EXTERN_C
diff --git a/src/memmap.c b/src/memmap.c
index 03e2e9a..c077f98 100644
--- a/src/memmap.c
+++ b/src/memmap.c
@@ -133,27 +133,27 @@ static int ScoreLoROM (bool8_32 skip_header)
static char *Safe (const char *s)
{
- static char *safe = NULL;
- static int safe_len = 0;
+ int i;
+ static char *safe = NULL;
+ static int safe_len = 0;
+ int len = strlen (s);
- int len = strlen (s);
- if (!safe || len + 1 > safe_len)
- {
- if (safe)
- free ((char *) safe);
- safe = (char *) malloc (safe_len = len + 1);
- }
+ if (!safe || len + 1 > safe_len)
+ {
+ if (safe)
+ free ((char *) safe);
+ safe = (char *) malloc (safe_len = len + 1);
+ }
- int i;
- for (i = 0; i < len; i++)
- {
- if (s [i] >= 32 && s [i] < 127)
- safe [i] = s[i];
- else
- safe [i] = '?';
- }
- safe [len] = 0;
- return (safe);
+ for (i = 0; i < len; i++)
+ {
+ if (s [i] >= 32 && s [i] < 127)
+ safe [i] = s[i];
+ else
+ safe [i] = '?';
+ }
+ safe [len] = 0;
+ return (safe);
}
/**********************************************************************************************/
@@ -294,6 +294,8 @@ void FreeSDD1Data ()
/**********************************************************************************************/
bool8_32 LoadROM (const char *filename)
{
+ int hi_score, lo_score;
+ int32 TotalFileSize = 0;
unsigned long FileSize = 0;
int retry_count = 0;
STREAM ROMFile;
@@ -321,23 +323,28 @@ again:
memmove (&ext [0], &ext[1], 4);
#endif
- int32 TotalFileSize = 0;
{
+ uint8 *ptr;
+ bool8_32 more = FALSE;
+
if ((ROMFile = OPEN_STREAM (fname, "rb")) == NULL)
return (FALSE);
strcpy (Memory.ROMFilename, fname);
Memory.HeaderCount = 0;
- uint8 *ptr = Memory.ROM;
- bool8_32 more = FALSE;
+ ptr = Memory.ROM;
+ more = FALSE;
do
{
+ int len;
+ int calc_size;
+
FileSize = READ_STREAM (ptr, MAX_ROM_SIZE + 0x200 - (ptr - Memory.ROM), ROMFile);
CLOSE_STREAM (ROMFile);
- int calc_size = (FileSize / 0x2000) * 0x2000;
+ calc_size = (FileSize / 0x2000) * 0x2000;
if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) ||
Settings.ForceHeader)
@@ -349,7 +356,6 @@ again:
ptr += FileSize;
TotalFileSize += FileSize;
- int len;
if (ptr - Memory.ROM < MAX_ROM_SIZE + 0x200 &&
(isdigit (ext [0]) && ext [1] == 0 && ext [0] < '9'))
{
@@ -393,8 +399,8 @@ again:
"Found multiple ROM file headers (and ignored them).");
}
- int hi_score = ScoreHiROM (FALSE);
- int lo_score = ScoreLoROM (FALSE);
+ hi_score = ScoreHiROM (FALSE);
+ lo_score = ScoreLoROM (FALSE);
if (Memory.HeaderCount == 0 && !Settings.ForceNoHeader &&
((hi_score > lo_score && ScoreHiROM (TRUE) > hi_score) ||
@@ -510,11 +516,15 @@ again:
if (!Settings.ForceNotInterleaved && Interleaved)
{
+ uint8 *tmp;
+ int nblocks;
+ uint8 blocks [256];
+
CPU.TriedInterleavedMode2 = TRUE;
S9xMessage (S9X_INFO, S9X_ROM_INTERLEAVED_INFO,
"ROM image is in interleaved format - converting...");
- int nblocks = Memory.CalculatedSize >> 16;
+ nblocks = Memory.CalculatedSize >> 16;
#if 0
int step = 64;
@@ -523,7 +533,6 @@ again:
nblocks = step;
#endif
- uint8 blocks [256];
if (Tales)
{
@@ -564,7 +573,7 @@ again:
}
}
- uint8 *tmp = (uint8 *) malloc (0x8000);
+ tmp = (uint8 *) malloc (0x8000);
if (tmp)
{
for (i = 0; i < nblocks * 2; i++)
@@ -574,11 +583,13 @@ again:
{
if (blocks [j] == i)
{
+ uint8 b;
+
memmove (tmp, &Memory.ROM [blocks [j] * 0x8000], 0x8000);
memmove (&Memory.ROM [blocks [j] * 0x8000],
&Memory.ROM [blocks [i] * 0x8000], 0x8000);
memmove (&Memory.ROM [blocks [i] * 0x8000], tmp, 0x8000);
- uint8 b = blocks [j];
+ b = blocks [j];
blocks [j] = blocks [i];
blocks [i] = b;
break;
@@ -618,321 +629,328 @@ again:
return (TRUE);
}
-void S9xDeinterleaveMode2 ()
+void S9xDeinterleaveMode2(void)
{
- S9xMessage (S9X_INFO, S9X_ROM_INTERLEAVED_INFO,
- "ROM image is in interleaved format - converting...");
+ int nblocks;
+ int step = 64;
+ uint8 blocks [256];
+ int i;
+ uint8 *tmp;
- int nblocks = Memory.CalculatedSize >> 15;
- int step = 64;
+ S9xMessage (S9X_INFO, S9X_ROM_INTERLEAVED_INFO,
+ "ROM image is in interleaved format - converting...");
- while (nblocks <= step)
- step >>= 1;
-
- nblocks = step;
- uint8 blocks [256];
- int i;
+ nblocks = Memory.CalculatedSize >> 15;
- for (i = 0; i < nblocks * 2; i++)
- {
- blocks [i] = (i & ~0x1e) | ((i & 2) << 2) | ((i & 4) << 2) |
- ((i & 8) >> 2) | ((i & 16) >> 2);
- }
+ while (nblocks <= step)
+ step >>= 1;
- uint8 *tmp = (uint8 *) malloc (0x8000);
+ nblocks = step;
- if (tmp)
- {
- for (i = 0; i < nblocks * 2; i++)
- {
- int j;
- for (j = i; j < nblocks * 2; j++)
- {
- if (blocks [j] == i)
- {
- memmove (tmp, &Memory.ROM [blocks [j] * 0x8000], 0x8000);
- memmove (&Memory.ROM [blocks [j] * 0x8000],
- &Memory.ROM [blocks [i] * 0x8000], 0x8000);
- memmove (&Memory.ROM [blocks [i] * 0x8000], tmp, 0x8000);
- uint8 b = blocks [j];
- blocks [j] = blocks [i];
- blocks [i] = b;
- break;
- }
- }
- }
- free ((char *) tmp);
- }
- InitROM (FALSE);
- S9xReset ();
+ for (i = 0; i < nblocks * 2; i++)
+ {
+ blocks [i] = (i & ~0x1e) | ((i & 2) << 2) | ((i & 4) << 2) |
+ ((i & 8) >> 2) | ((i & 16) >> 2);
+ }
+
+ tmp = (uint8 *) malloc (0x8000);
+
+ if (tmp)
+ {
+ for (i = 0; i < nblocks * 2; i++)
+ {
+ int j;
+ for (j = i; j < nblocks * 2; j++)
+ {
+ if (blocks [j] == i)
+ {
+ uint8 b;
+
+ memmove (tmp, &Memory.ROM [blocks [j] * 0x8000], 0x8000);
+ memmove (&Memory.ROM [blocks [j] * 0x8000],
+ &Memory.ROM [blocks [i] * 0x8000], 0x8000);
+ memmove (&Memory.ROM [blocks [i] * 0x8000], tmp, 0x8000);
+ b = blocks [j];
+ blocks [j] = blocks [i];
+ blocks [i] = b;
+ break;
+ }
+ }
+ }
+ free ((char *) tmp);
+ }
+ InitROM (FALSE);
+ S9xReset ();
}
void InitROM (bool8_32 Interleaved)
{
- SuperFX.nRomBanks = Memory.CalculatedSize >> 15;
- Settings.MultiPlayer5Master = Settings.MultiPlayer5;
- Settings.MouseMaster = Settings.Mouse;
- Settings.SuperScopeMaster = Settings.SuperScope;
- Settings.DSP1Master = Settings.ForceDSP1;
- Settings.SuperFX = FALSE;
- Settings.SA1 = FALSE;
- Settings.C4 = FALSE;
- Settings.SDD1 = FALSE;
- Settings.SRTC = FALSE;
-
- memset (Memory.BlockIsRAM, 0, MEMMAP_NUM_BLOCKS);
- memset (Memory.BlockIsROM, 0, MEMMAP_NUM_BLOCKS);
-
- SRAM = Memory.SRAM;
- memset (Memory.ROMId, 0, 5);
- memset (Memory.CompanyId, 0, 3);
-
- if (Memory.HiROM)
- {
- Memory.SRAMSize = Memory.ROM [0xffd8];
- strncpy (Memory.ROMName, (char *) &Memory.ROM[0xffc0], ROM_NAME_LEN - 1);
- Memory.ROMSpeed = Memory.ROM [0xffd5];
- Memory.ROMType = Memory.ROM [0xffd6];
- Memory.ROMSize = Memory.ROM [0xffd7];
- Memory.ROMChecksum = Memory.ROM [0xffde] + (Memory.ROM [0xffdf] << 8);
- Memory.ROMComplementChecksum = Memory.ROM [0xffdc] + (Memory.ROM [0xffdd] << 8);
-
- memmove (Memory.ROMId, &Memory.ROM [0xffb2], 4);
- memmove (Memory.CompanyId, &Memory.ROM [0xffb0], 2);
-
- // Try to auto-detect the DSP1 chip
- if (!Settings.ForceNoDSP1 &&
- (Memory.ROMType & 0xf) >= 3 && (Memory.ROMType & 0xf0) == 0)
- Settings.DSP1Master = TRUE;
+ uint32 remainder;
+ int size;
+ int power2 = 0;
+ uint32 sum1 = 0;
+ uint32 sum2 = 0;
- Settings.SDD1 = Settings.ForceSDD1;
- if ((Memory.ROMType & 0xf0) == 0x40)
- Settings.SDD1 = !Settings.ForceNoSDD1;
+ int i;
- if (Settings.BS)
- BSHiROMMap ();
- else
- if ((Memory.ROMSpeed & ~0x10) == 0x25)
- TalesROMMap (Interleaved);
- else
- if ((Memory.ROMSpeed & ~0x10) == 0x22 &&
- strncmp (Memory.ROMName, "Super Street Fighter", 20) != 0)
- {
- AlphaROMMap ();
- }
- else
- HiROMMap ();
- }
- else
- {
- Memory.HiROM = FALSE;
- Memory.SRAMSize = Memory.ROM [0x7fd8];
- Memory.ROMSpeed = Memory.ROM [0x7fd5];
- Memory.ROMType = Memory.ROM [0x7fd6];
- Memory.ROMSize = Memory.ROM [0x7fd7];
- Memory.ROMChecksum = Memory.ROM [0x7fde] + (Memory.ROM [0x7fdf] << 8);
- Memory.ROMComplementChecksum = Memory.ROM [0x7fdc] + (Memory.ROM [0x7fdd] << 8);
- memmove (Memory.ROMId, &Memory.ROM [0x7fb2], 4);
- memmove (Memory.CompanyId, &Memory.ROM [0x7fb0], 2);
-
- strncpy (Memory.ROMName, (char *) &Memory.ROM[0x7fc0], ROM_NAME_LEN - 1);
- Settings.SuperFX = Settings.ForceSuperFX;
-
- if ((Memory.ROMType & 0xf0) == 0x10)
- Settings.SuperFX = !Settings.ForceNoSuperFX;
-
- // Try to auto-detect the DSP1 chip
- if (!Settings.ForceNoDSP1 &&
- (Memory.ROMType & 0xf) >= 3 && (Memory.ROMType & 0xf0) == 0)
- Settings.DSP1Master = TRUE;
-
- Settings.SDD1 = Settings.ForceSDD1;
- if ((Memory.ROMType & 0xf0) == 0x40)
- Settings.SDD1 = !Settings.ForceNoSDD1;
-
- if (Settings.SDD1)
- S9xLoadSDD1Data ();
-
- Settings.C4 = Settings.ForceC4;
- if ((Memory.ROMType & 0xf0) == 0xf0 &&
+ SuperFX.nRomBanks = Memory.CalculatedSize >> 15;
+ Settings.MultiPlayer5Master = Settings.MultiPlayer5;
+ Settings.MouseMaster = Settings.Mouse;
+ Settings.SuperScopeMaster = Settings.SuperScope;
+ Settings.DSP1Master = Settings.ForceDSP1;
+ Settings.SuperFX = FALSE;
+ Settings.SA1 = FALSE;
+ Settings.C4 = FALSE;
+ Settings.SDD1 = FALSE;
+ Settings.SRTC = FALSE;
+
+ memset (Memory.BlockIsRAM, 0, MEMMAP_NUM_BLOCKS);
+ memset (Memory.BlockIsROM, 0, MEMMAP_NUM_BLOCKS);
+
+ SRAM = Memory.SRAM;
+ memset (Memory.ROMId, 0, 5);
+ memset (Memory.CompanyId, 0, 3);
+
+ if (Memory.HiROM)
+ {
+ Memory.SRAMSize = Memory.ROM [0xffd8];
+ strncpy (Memory.ROMName, (char *) &Memory.ROM[0xffc0], ROM_NAME_LEN - 1);
+ Memory.ROMSpeed = Memory.ROM [0xffd5];
+ Memory.ROMType = Memory.ROM [0xffd6];
+ Memory.ROMSize = Memory.ROM [0xffd7];
+ Memory.ROMChecksum = Memory.ROM [0xffde] + (Memory.ROM [0xffdf] << 8);
+ Memory.ROMComplementChecksum = Memory.ROM [0xffdc] + (Memory.ROM [0xffdd] << 8);
+
+ memmove (Memory.ROMId, &Memory.ROM [0xffb2], 4);
+ memmove (Memory.CompanyId, &Memory.ROM [0xffb0], 2);
+
+ // Try to auto-detect the DSP1 chip
+ if (!Settings.ForceNoDSP1 &&
+ (Memory.ROMType & 0xf) >= 3 && (Memory.ROMType & 0xf0) == 0)
+ Settings.DSP1Master = TRUE;
+
+ Settings.SDD1 = Settings.ForceSDD1;
+ if ((Memory.ROMType & 0xf0) == 0x40)
+ Settings.SDD1 = !Settings.ForceNoSDD1;
+
+ if (Settings.BS)
+ BSHiROMMap ();
+ else
+ if ((Memory.ROMSpeed & ~0x10) == 0x25)
+ TalesROMMap (Interleaved);
+ else
+ if ((Memory.ROMSpeed & ~0x10) == 0x22 &&
+ strncmp (Memory.ROMName, "Super Street Fighter", 20) != 0)
+ {
+ AlphaROMMap ();
+ }
+ else
+ HiROMMap ();
+ }
+ else
+ {
+ Memory.HiROM = FALSE;
+ Memory.SRAMSize = Memory.ROM [0x7fd8];
+ Memory.ROMSpeed = Memory.ROM [0x7fd5];
+ Memory.ROMType = Memory.ROM [0x7fd6];
+ Memory.ROMSize = Memory.ROM [0x7fd7];
+ Memory.ROMChecksum = Memory.ROM [0x7fde] + (Memory.ROM [0x7fdf] << 8);
+ Memory.ROMComplementChecksum = Memory.ROM [0x7fdc] + (Memory.ROM [0x7fdd] << 8);
+ memmove (Memory.ROMId, &Memory.ROM [0x7fb2], 4);
+ memmove (Memory.CompanyId, &Memory.ROM [0x7fb0], 2);
+
+ strncpy (Memory.ROMName, (char *) &Memory.ROM[0x7fc0], ROM_NAME_LEN - 1);
+ Settings.SuperFX = Settings.ForceSuperFX;
+
+ if ((Memory.ROMType & 0xf0) == 0x10)
+ Settings.SuperFX = !Settings.ForceNoSuperFX;
+
+ // Try to auto-detect the DSP1 chip
+ if (!Settings.ForceNoDSP1 &&
+ (Memory.ROMType & 0xf) >= 3 && (Memory.ROMType & 0xf0) == 0)
+ Settings.DSP1Master = TRUE;
+
+ Settings.SDD1 = Settings.ForceSDD1;
+ if ((Memory.ROMType & 0xf0) == 0x40)
+ Settings.SDD1 = !Settings.ForceNoSDD1;
+
+ if (Settings.SDD1)
+ S9xLoadSDD1Data ();
+
+ Settings.C4 = Settings.ForceC4;
+ if ((Memory.ROMType & 0xf0) == 0xf0 &&
(strncmp (Memory.ROMName, "MEGAMAN X", 9) == 0 ||
strncmp (Memory.ROMName, "ROCKMAN X", 9) == 0))
- {
- Settings.C4 = !Settings.ForceNoC4;
- }
+ {
+ Settings.C4 = !Settings.ForceNoC4;
+ }
- if (Settings.SuperFX)
- {
- //SRAM = ROM + 1024 * 1024 * 4;
- SuperFXROMMap ();
- Settings.MultiPlayer5Master = FALSE;
- //Settings.MouseMaster = FALSE;
- //Settings.SuperScopeMaster = FALSE;
- Settings.DSP1Master = FALSE;
- Settings.SA1 = FALSE;
- Settings.C4 = FALSE;
- Settings.SDD1 = FALSE;
- }
- else
- if (Settings.ForceSA1 ||
- (!Settings.ForceNoSA1 && (Memory.ROMSpeed & ~0x10) == 0x23 &&
- (Memory.ROMType & 0xf) > 3 && (Memory.ROMType & 0xf0) == 0x30))
- {
- Settings.SA1 = TRUE;
- Settings.MultiPlayer5Master = FALSE;
- //Settings.MouseMaster = FALSE;
- //Settings.SuperScopeMaster = FALSE;
- Settings.DSP1Master = FALSE;
- Settings.C4 = FALSE;
- Settings.SDD1 = FALSE;
- SA1ROMMap ();
- }
- else
- if ((Memory.ROMSpeed & ~0x10) == 0x25)
- TalesROMMap (Interleaved);
- else
- if (strncmp ((char *) &Memory.ROM [0x7fc0], "SOUND NOVEL-TCOOL", 17) == 0 ||
- strncmp ((char *) &Memory.ROM [0x7fc0], "DERBY STALLION 96", 17) == 0)
- {
- LoROM24MBSMap ();
- Settings.DSP1Master = FALSE;
- }
- else
- if (strncmp ((char *) &Memory.ROM [0x7fc0], "THOROUGHBRED BREEDER3", 21) == 0 ||
- strncmp ((char *) &Memory.ROM [0x7fc0], "RPG-TCOOL 2", 11) == 0)
- {
- SRAM512KLoROMMap ();
- Settings.DSP1Master = FALSE;
- }
- else
- if (strncmp ((char *) &Memory.ROM [0x7fc0], "DEZAEMON ", 10) == 0)
- {
- Settings.DSP1Master = FALSE;
- SRAM1024KLoROMMap ();
- }
- else
- if (strncmp ((char *) &Memory.ROM [0x7fc0], "ADD-ON BASE CASSETE", 19) == 0)
- {
- Settings.MultiPlayer5Master = FALSE;
- Settings.MouseMaster = FALSE;
- Settings.SuperScopeMaster = FALSE;
- Settings.DSP1Master = FALSE;
- SufamiTurboLoROMMap();
- Memory.SRAMSize = 3;
- }
- else
- if ((Memory.ROMSpeed & ~0x10) == 0x22 &&
- strncmp (Memory.ROMName, "Super Street Fighter", 20) != 0)
- {
- AlphaROMMap ();
- }
- else
- LoROMMap ();
- }
+ if (Settings.SuperFX)
+ {
+ //SRAM = ROM + 1024 * 1024 * 4;
+ SuperFXROMMap ();
+ Settings.MultiPlayer5Master = FALSE;
+ //Settings.MouseMaster = FALSE;
+ //Settings.SuperScopeMaster = FALSE;
+ Settings.DSP1Master = FALSE;
+ Settings.SA1 = FALSE;
+ Settings.C4 = FALSE;
+ Settings.SDD1 = FALSE;
+ }
+ else
+ if (Settings.ForceSA1 ||
+ (!Settings.ForceNoSA1 && (Memory.ROMSpeed & ~0x10) == 0x23 &&
+ (Memory.ROMType & 0xf) > 3 && (Memory.ROMType & 0xf0) == 0x30))
+ {
+ Settings.SA1 = TRUE;
+ Settings.MultiPlayer5Master = FALSE;
+ //Settings.MouseMaster = FALSE;
+ //Settings.SuperScopeMaster = FALSE;
+ Settings.DSP1Master = FALSE;
+ Settings.C4 = FALSE;
+ Settings.SDD1 = FALSE;
+ SA1ROMMap ();
+ }
+ else
+ if ((Memory.ROMSpeed & ~0x10) == 0x25)
+ TalesROMMap (Interleaved);
+ else
+ if (strncmp ((char *) &Memory.ROM [0x7fc0], "SOUND NOVEL-TCOOL", 17) == 0 ||
+ strncmp ((char *) &Memory.ROM [0x7fc0], "DERBY STALLION 96", 17) == 0)
+ {
+ LoROM24MBSMap ();
+ Settings.DSP1Master = FALSE;
+ }
+ else
+ if (strncmp ((char *) &Memory.ROM [0x7fc0], "THOROUGHBRED BREEDER3", 21) == 0 ||
+ strncmp ((char *) &Memory.ROM [0x7fc0], "RPG-TCOOL 2", 11) == 0)
+ {
+ SRAM512KLoROMMap ();
+ Settings.DSP1Master = FALSE;
+ }
+ else
+ if (strncmp ((char *) &Memory.ROM [0x7fc0], "DEZAEMON ", 10) == 0)
+ {
+ Settings.DSP1Master = FALSE;
+ SRAM1024KLoROMMap ();
+ }
+ else
+ if (strncmp ((char *) &Memory.ROM [0x7fc0], "ADD-ON BASE CASSETE", 19) == 0)
+ {
+ Settings.MultiPlayer5Master = FALSE;
+ Settings.MouseMaster = FALSE;
+ Settings.SuperScopeMaster = FALSE;
+ Settings.DSP1Master = FALSE;
+ SufamiTurboLoROMMap();
+ Memory.SRAMSize = 3;
+ }
+ else
+ if ((Memory.ROMSpeed & ~0x10) == 0x22 &&
+ strncmp (Memory.ROMName, "Super Street Fighter", 20) != 0)
+ {
+ AlphaROMMap ();
+ }
+ else
+ LoROMMap ();
+ }
- int power2 = 0;
- int size = Memory.CalculatedSize;
+ size = Memory.CalculatedSize;
- while (size >>= 1)
- power2++;
+ while (size >>= 1)
+ power2++;
- size = 1 << power2;
- uint32 remainder = Memory.CalculatedSize - size;
+ size = 1 << power2;
+ remainder = Memory.CalculatedSize - size;
- uint32 sum1 = 0;
- uint32 sum2 = 0;
+ for (i = 0; i < size; i++)
+ sum1 += Memory.ROM [i];
- int i;
+ for (i = 0; i < (int) remainder; i++)
+ sum2 += Memory.ROM [size + i];
- for (i = 0; i < size; i++)
- sum1 += Memory.ROM [i];
+ if (remainder)
+ {
+ //for Tengai makyou
+ if (Memory.CalculatedSize == 0x500000 && Memory.HiROM &&
+ strncmp ((const char *)&Memory.ROM[0xffb0], "18AZ", 4) == 0 &&
+ !memcmp(&Memory.ROM[0xffd5], "\x3a\xf9\x0d\x03\x00\x33\x00", 7))
+ sum1 += sum2;
+ else
+ sum1 += sum2 * (size / remainder);
+ }
- for (i = 0; i < (int) remainder; i++)
- sum2 += Memory.ROM [size + i];
+ sum1 &= 0xffff;
- if (remainder)
- {
- //for Tengai makyou
- if (Memory.CalculatedSize == 0x500000 && Memory.HiROM &&
- strncmp ((const char *)&Memory.ROM[0xffb0], "18AZ", 4) == 0 &&
- !memcmp(&Memory.ROM[0xffd5], "\x3a\xf9\x0d\x03\x00\x33\x00", 7))
- sum1 += sum2;
- else
- sum1 += sum2 * (size / remainder);
- }
-
- sum1 &= 0xffff;
-
- Memory.CalculatedChecksum = caCRC32(&Memory.ROM[0], Memory.CalculatedSize);
- if (Settings.ForceNTSC)
- Settings.PAL = FALSE;
- else
- if (Settings.ForcePAL)
- Settings.PAL = TRUE;
- else
- if (Memory.HiROM)
- // Country code
- Settings.PAL = Memory.ROM [0xffd9] >= 2;
- else
- Settings.PAL = Memory.ROM [0x7fd9] >= 2;
-
- if (Settings.PAL)
- {
- Settings.FrameTime = Settings.FrameTimePAL;
- Memory.ROMFramesPerSecond = 50;
- }
- else
- {
- Settings.FrameTime = Settings.FrameTimeNTSC;
- Memory.ROMFramesPerSecond = 60;
- }
-
- Memory.ROMName[ROM_NAME_LEN - 1] = 0;
- if (strlen (Memory.ROMName))
- {
- char *p = Memory.ROMName + strlen (Memory.ROMName) - 1;
+ Memory.CalculatedChecksum = caCRC32(&Memory.ROM[0], Memory.CalculatedSize);
+ if (Settings.ForceNTSC)
+ Settings.PAL = FALSE;
+ else
+ if (Settings.ForcePAL)
+ Settings.PAL = TRUE;
+ else
+ if (Memory.HiROM)
+ // Country code
+ Settings.PAL = Memory.ROM [0xffd9] >= 2;
+ else
+ Settings.PAL = Memory.ROM [0x7fd9] >= 2;
- while (p > Memory.ROMName && *(p - 1) == ' ')
- p--;
- *p = 0;
- }
+ if (Settings.PAL)
+ {
+ Settings.FrameTime = Settings.FrameTimePAL;
+ Memory.ROMFramesPerSecond = 50;
+ }
+ else
+ {
+ Settings.FrameTime = Settings.FrameTimeNTSC;
+ Memory.ROMFramesPerSecond = 60;
+ }
- if (Settings.SuperFX)
- {
- CPU.Memory_SRAMMask = 0xffff;
- Memory.SRAMSize = 16;
- }
- else
- {
- CPU.Memory_SRAMMask = Memory.SRAMSize ?
- ((1 << (Memory.SRAMSize + 3)) * 128) - 1 : 0;
- }
-
- IAPU.OneCycle = ONE_APU_CYCLE;
- Settings.Shutdown = Settings.ShutdownMaster;
-
- SetDSP = &DSP1SetByte;
- GetDSP = &DSP1GetByte;
-
- ApplyROMFixes ();
- sprintf (Memory.ROMName, "%s", Safe (Memory.ROMName));
- sprintf (Memory.ROMId, "%s", Safe (Memory.ROMId));
- sprintf (Memory.CompanyId, "%s", Safe (Memory.CompanyId));
-
- sprintf (String, "\"%s\" [%s] %s, %s, Type: %s, Mode: %s, TV: %s, S-RAM: %s, ROMId: %s Company: %2.2s",
- Memory.ROMName,
- (Memory.ROMChecksum + Memory.ROMComplementChecksum != 0xffff ||
- Memory.ROMChecksum != sum1) ? "bad checksum" : "checksum ok",
- MapType (),
- Size (),
- KartContents (),
- MapMode (),
- TVStandard (),
- StaticRAMSize (),
- Memory.ROMId,
- Memory.CompanyId);
-
- S9xMessage (S9X_INFO, S9X_ROM_INFO, String);
+ Memory.ROMName[ROM_NAME_LEN - 1] = 0;
+ if (strlen (Memory.ROMName))
+ {
+ char *p = Memory.ROMName + strlen (Memory.ROMName) - 1;
+
+ while (p > Memory.ROMName && *(p - 1) == ' ')
+ p--;
+ *p = 0;
+ }
+
+ if (Settings.SuperFX)
+ {
+ CPU.Memory_SRAMMask = 0xffff;
+ Memory.SRAMSize = 16;
+ }
+ else
+ {
+ CPU.Memory_SRAMMask = Memory.SRAMSize ?
+ ((1 << (Memory.SRAMSize + 3)) * 128) - 1 : 0;
+ }
+
+ IAPU.OneCycle = ONE_APU_CYCLE;
+ Settings.Shutdown = Settings.ShutdownMaster;
+
+ SetDSP = &DSP1SetByte;
+ GetDSP = &DSP1GetByte;
+
+ ApplyROMFixes ();
+ sprintf (Memory.ROMName, "%s", Safe (Memory.ROMName));
+ sprintf (Memory.ROMId, "%s", Safe (Memory.ROMId));
+ sprintf (Memory.CompanyId, "%s", Safe (Memory.CompanyId));
+
+ sprintf (String, "\"%s\" [%s] %s, %s, Type: %s, Mode: %s, TV: %s, S-RAM: %s, ROMId: %s Company: %2.2s",
+ Memory.ROMName,
+ (Memory.ROMChecksum + Memory.ROMComplementChecksum != 0xffff ||
+ Memory.ROMChecksum != sum1) ? "bad checksum" : "checksum ok",
+ MapType (),
+ Size (),
+ KartContents (),
+ MapMode (),
+ TVStandard (),
+ StaticRAMSize (),
+ Memory.ROMId,
+ Memory.CompanyId);
+
+ S9xMessage (S9X_INFO, S9X_ROM_INFO, String);
}
void FixROMSpeed ()
@@ -946,73 +964,74 @@ void FixROMSpeed ()
}
}
-void WriteProtectROM ()
+void WriteProtectROM(void)
{
- memmove ((void *) Memory.WriteMap, (void *) Memory.Map, sizeof (Memory.Map));
- int c;
- for (c = 0; c < 0x1000; c++)
- {
- if (Memory.BlockIsROM [c])
- Memory.WriteMap [c] = (uint8 *) MAP_NONE;
- }
+ int c;
+
+ memmove ((void *) Memory.WriteMap, (void *) Memory.Map, sizeof (Memory.Map));
+ for (c = 0; c < 0x1000; c++)
+ {
+ if (Memory.BlockIsROM [c])
+ Memory.WriteMap [c] = (uint8 *) MAP_NONE;
+ }
}
-void MapRAM ()
+void MapRAM(void)
{
- int c;
+ int c;
- // Banks 7e->7f, RAM
- for (c = 0; c < 16; c++)
- {
- Memory.Map [c + 0x7e0] = Memory.RAM;
- Memory.Map [c + 0x7f0] = Memory.RAM + 0x10000;
- Memory.BlockIsRAM [c + 0x7e0] = TRUE;
- Memory.BlockIsRAM [c + 0x7f0] = TRUE;
- Memory.BlockIsROM [c + 0x7e0] = FALSE;
- Memory.BlockIsROM [c + 0x7f0] = FALSE;
- }
+ // Banks 7e->7f, RAM
+ for (c = 0; c < 16; c++)
+ {
+ Memory.Map [c + 0x7e0] = Memory.RAM;
+ Memory.Map [c + 0x7f0] = Memory.RAM + 0x10000;
+ Memory.BlockIsRAM [c + 0x7e0] = TRUE;
+ Memory.BlockIsRAM [c + 0x7f0] = TRUE;
+ Memory.BlockIsROM [c + 0x7e0] = FALSE;
+ Memory.BlockIsROM [c + 0x7f0] = FALSE;
+ }
- // Banks 70->77, S-RAM
- for (c = 0; c < 0x80; c++)
- {
- Memory.Map [c + 0x700] = (uint8 *) MAP_LOROM_SRAM;
- Memory.BlockIsRAM [c + 0x700] = TRUE;
- Memory.BlockIsROM [c + 0x700] = FALSE;
- }
+ // Banks 70->77, S-RAM
+ for (c = 0; c < 0x80; c++)
+ {
+ Memory.Map [c + 0x700] = (uint8 *) MAP_LOROM_SRAM;
+ Memory.BlockIsRAM [c + 0x700] = TRUE;
+ Memory.BlockIsROM [c + 0x700] = FALSE;
+ }
}
-void MapExtraRAM ()
+void MapExtraRAM(void)
{
- int c;
+ int c;
- // Banks 7e->7f, RAM
- for (c = 0; c < 16; c++)
- {
- Memory.Map [c + 0x7e0] = Memory.RAM;
- Memory.Map [c + 0x7f0] = Memory.RAM + 0x10000;
- Memory.BlockIsRAM [c + 0x7e0] = TRUE;
- Memory.BlockIsRAM [c + 0x7f0] = TRUE;
- Memory.BlockIsROM [c + 0x7e0] = FALSE;
- Memory.BlockIsROM [c + 0x7f0] = FALSE;
- }
-
- // Banks 70->73, S-RAM
- for (c = 0; c < 16; c++)
- {
- Memory.Map [c + 0x700] = SRAM;
- Memory.Map [c + 0x710] = SRAM + 0x8000;
- Memory.Map [c + 0x720] = SRAM + 0x10000;
- Memory.Map [c + 0x730] = SRAM + 0x18000;
+ // Banks 7e->7f, RAM
+ for (c = 0; c < 16; c++)
+ {
+ Memory.Map [c + 0x7e0] = Memory.RAM;
+ Memory.Map [c + 0x7f0] = Memory.RAM + 0x10000;
+ Memory.BlockIsRAM [c + 0x7e0] = TRUE;
+ Memory.BlockIsRAM [c + 0x7f0] = TRUE;
+ Memory.BlockIsROM [c + 0x7e0] = FALSE;
+ Memory.BlockIsROM [c + 0x7f0] = FALSE;
+ }
- Memory.BlockIsRAM [c + 0x700] = TRUE;
- Memory.BlockIsROM [c + 0x700] = FALSE;
- Memory.BlockIsRAM [c + 0x710] = TRUE;
- Memory.BlockIsROM [c + 0x710] = FALSE;
- Memory.BlockIsRAM [c + 0x720] = TRUE;
- Memory.BlockIsROM [c + 0x720] = FALSE;
- Memory.BlockIsRAM [c + 0x730] = TRUE;
- Memory.BlockIsROM [c + 0x730] = FALSE;
- }
+ // Banks 70->73, S-RAM
+ for (c = 0; c < 16; c++)
+ {
+ Memory.Map [c + 0x700] = SRAM;
+ Memory.Map [c + 0x710] = SRAM + 0x8000;
+ Memory.Map [c + 0x720] = SRAM + 0x10000;
+ Memory.Map [c + 0x730] = SRAM + 0x18000;
+
+ Memory.BlockIsRAM [c + 0x700] = TRUE;
+ Memory.BlockIsROM [c + 0x700] = FALSE;
+ Memory.BlockIsRAM [c + 0x710] = TRUE;
+ Memory.BlockIsROM [c + 0x710] = FALSE;
+ Memory.BlockIsRAM [c + 0x720] = TRUE;
+ Memory.BlockIsROM [c + 0x720] = FALSE;
+ Memory.BlockIsRAM [c + 0x730] = TRUE;
+ Memory.BlockIsROM [c + 0x730] = FALSE;
+ }
}
void LoROMMap ()
diff --git a/src/memmap.h b/src/memmap.h
index 175bc39..4e0e338 100644
--- a/src/memmap.h
+++ b/src/memmap.h
@@ -163,13 +163,11 @@ typedef struct
char ROMFilename [_MAX_PATH];
} CMemory;
-START_EXTERN_C
extern CMemory Memory;
extern uint8* SRAM;
extern uint8* ROM;
extern uint8* RegRAM;
void S9xDeinterleaveMode2();
-END_EXTERN_C
#ifdef NO_INLINE_SET_GET
uint8 S9xGetByte(uint32 Address, struct SCPUState*);
diff --git a/src/missing.h b/src/missing.h
index 8c2a235..694caf3 100644
--- a/src/missing.h
+++ b/src/missing.h
@@ -110,5 +110,5 @@ typedef struct
uint16 unknowndsp_write;
} Missing;
-EXTERN_C Missing missing;
+extern Missing missing;
#endif
diff --git a/src/os9x_asm_cpu.c b/src/os9x_asm_cpu.c
index 7b34956..2c920b7 100644
--- a/src/os9x_asm_cpu.c
+++ b/src/os9x_asm_cpu.c
@@ -11,8 +11,6 @@
//#define __debug_c_hblank__
//#define __debug_c_io__
-START_EXTERN_C
-
void asm_S9xSetPCBase(uint32 Address)
{
#ifdef __debug_c_setpc__
@@ -202,5 +200,3 @@ void asm_S9xOpcode_IRQ(void)
// S9xPackStatus(); // not needed
}
#endif
-
-END_EXTERN_C
diff --git a/src/os9x_asm_cpu.h b/src/os9x_asm_cpu.h
index a389973..48c9a6b 100644
--- a/src/os9x_asm_cpu.h
+++ b/src/os9x_asm_cpu.h
@@ -3,8 +3,6 @@
#include "snes9x.h"
-START_EXTERN_C
-
void test_opcode(SCPUState* cpuptr);
void asmMainLoop_spcC(SCPUState* cpuptr);
@@ -13,6 +11,4 @@ void asmMainLoop(SCPUState* cpuptr);
void asm_S9xMainLoop(void);
-END_EXTERN_C
-
#endif
diff --git a/src/port.h b/src/port.h
index 81cc42f..e6b5c1d 100644
--- a/src/port.h
+++ b/src/port.h
@@ -85,17 +85,6 @@ typedef signed char int8_32;
typedef short int16_32;
-//Defines for Extern C
-#if defined(__cplusplus) || defined(c_plusplus)
-#define EXTERN_C extern "C"
-#define START_EXTERN_C extern "C" {
-#define END_EXTERN_C }
-#else
-#define EXTERN_C extern
-#define START_EXTERN_C
-#define END_EXTERN_C
-#endif
-
//Path Defines
#ifndef PATH_MAX
#define PATH_MAX 1024
@@ -131,7 +120,7 @@ typedef short int16_32;
#undef SPC700_SHUTDOWN
#endif
-EXTERN_C void S9xGenerateSound();
+void S9xGenerateSound(void);
#ifndef _MSC_VER
void _makepath(char* path, const char* drive, const char* dir,
diff --git a/src/ppu.h b/src/ppu.h
index 87b14b7..b6d0be0 100644
--- a/src/ppu.h
+++ b/src/ppu.h
@@ -248,7 +248,6 @@ typedef struct
uint8 FirstLine;
} SDMA;
-START_EXTERN_C
//void S9xUpdateScreen ();
void S9xResetPPU();
void S9xFixColourBrightness();
@@ -270,7 +269,6 @@ uint8 S9xGetC4RAM(uint16 Address);
extern SPPU PPU;
extern SDMA DMA [8];
extern InternalPPU IPPU;
-END_EXTERN_C
#include "gfx.h"
#include "memmap.h"
@@ -307,6 +305,7 @@ static INLINE void REGISTER_2104(uint8 byte)
int addr = ((PPU.OAMAddr & 0x10f) << 1) + (PPU.OAMFlip & 1);
if (byte != PPU.OAMData [addr])
{
+ SOBJ *pObj;
#ifdef __DEBUG__
printf("SetPPU_2104, PPU.OAMData. Byte : %x\n", byte);
#endif
@@ -316,16 +315,16 @@ static INLINE void REGISTER_2104(uint8 byte)
IPPU.OBJChanged = TRUE;
// X position high bit, and sprite size (x4)
- SOBJ* pObj = &PPU.OBJ [(addr & 0x1f) * 4];
+ pObj = &PPU.OBJ [(addr & 0x1f) * 4];
- pObj->HPos = (pObj->HPos & 0xFF) | SignExtend[(byte >> 0) & 1];
+ pObj->HPos = (pObj->HPos & 0xFF) | SignExtend[(byte >> 0) & 1];
pObj++->Size = byte & 2;
- pObj->HPos = (pObj->HPos & 0xFF) | SignExtend[(byte >> 2) & 1];
+ pObj->HPos = (pObj->HPos & 0xFF) | SignExtend[(byte >> 2) & 1];
pObj++->Size = byte & 8;
- pObj->HPos = (pObj->HPos & 0xFF) | SignExtend[(byte >> 4) & 1];
+ pObj->HPos = (pObj->HPos & 0xFF) | SignExtend[(byte >> 4) & 1];
pObj++->Size = byte & 32;
- pObj->HPos = (pObj->HPos & 0xFF) | SignExtend[(byte >> 6) & 1];
- pObj->Size = byte & 128;
+ pObj->HPos = (pObj->HPos & 0xFF) | SignExtend[(byte >> 6) & 1];
+ pObj->Size = byte & 128;
}
PPU.OAMFlip ^= 1;
if (!(PPU.OAMFlip & 1))
@@ -342,12 +341,15 @@ static INLINE void REGISTER_2104(uint8 byte)
}
else
{
+ int addr;
+ uint8 lowbyte, highbyte;
+
PPU.OAMWriteRegister &= 0x00ff;
- uint8 lowbyte = (uint8)(PPU.OAMWriteRegister);
- uint8 highbyte = byte;
+ lowbyte = (uint8)(PPU.OAMWriteRegister);
+ highbyte = byte;
PPU.OAMWriteRegister |= byte << 8;
- int addr = (PPU.OAMAddr << 1);
+ addr = (PPU.OAMAddr << 1);
if (lowbyte != PPU.OAMData [addr] ||
highbyte != PPU.OAMData [addr + 1])
diff --git a/src/sa1.c b/src/sa1.c
index 9cf2b5b..0b2ed65 100644
--- a/src/sa1.c
+++ b/src/sa1.c
@@ -749,6 +749,8 @@ static void S9xSA1DMA()
void S9xSA1ReadVariableLengthData(bool8 inc, bool8 no_shift)
{
+ uint32 data;
+ uint8 s;
uint32 addr = Memory.FillRAM [0x2259] |
(Memory.FillRAM [0x225a] << 8) |
(Memory.FillRAM [0x225b] << 16);
@@ -759,14 +761,14 @@ void S9xSA1ReadVariableLengthData(bool8 inc, bool8 no_shift)
else if (shift == 0)
shift = 16;
- uint8 s = shift + SA1.variable_bit_pos;
+ s = shift + SA1.variable_bit_pos;
if (s >= 16)
{
addr += (s >> 4) << 1;
s &= 15;
}
- uint32 data = S9xSA1GetWord(addr) |
+ data = S9xSA1GetWord(addr) |
(S9xSA1GetWord(addr + 2) << 16);
data >>= s;
diff --git a/src/sa1.h b/src/sa1.h
index aaea698..51ccc2e 100644
--- a/src/sa1.h
+++ b/src/sa1.h
@@ -123,7 +123,6 @@ extern uint8* SA1_WriteMap [MEMMAP_NUM_BLOCKS];
#define SA1SetFlags(f) (SA1Registers.P.W |= (f))
#define SA1CheckFlag(f) (SA1Registers.PL & (f))
-START_EXTERN_C
uint8 S9xSA1GetByte(uint32);
//uint16 S9xSA1GetWord (uint32);
#define S9xSA1GetWord(address) (S9xSA1GetByte(address) | (S9xSA1GetByte(address+1) << 8))
@@ -139,11 +138,11 @@ extern SOpcodes S9xSA1OpcodesM1X0 [256];
extern SOpcodes S9xSA1OpcodesM0X1 [256];
extern SOpcodes S9xSA1OpcodesM0X0 [256];
-void S9xSA1MainLoop();
-void S9xSA1Init();
-void S9xFixSA1AfterSnapshotLoad();
-void S9xSA1ExecuteDuringSleep();
-END_EXTERN_C
+void S9xSA1MainLoop(void);
+void S9xSA1Init(void);
+void S9xFixSA1AfterSnapshotLoad(void);
+void S9xSA1ExecuteDuringSleep(void);
+
#define SNES_IRQ_SOURCE (1 << 7)
#define TIMER_IRQ_SOURCE (1 << 6)
diff --git a/src/sdd1.c b/src/sdd1.c
index e02172e..c6e7f57 100644
--- a/src/sdd1.c
+++ b/src/sdd1.c
@@ -53,11 +53,11 @@
void S9xSetSDD1MemoryMap(uint32 bank, uint32 value)
{
+ int c;
+
bank = 0xc00 + bank * 0x100;
value = value * 1024 * 1024;
- int c;
-
for (c = 0; c < 0x100; c += 16)
{
uint8* block = &Memory.ROM [value + (c << 12)];
@@ -68,10 +68,12 @@ void S9xSetSDD1MemoryMap(uint32 bank, uint32 value)
}
}
-void S9xResetSDD1()
+void S9xResetSDD1(void)
{
- memset(&Memory.FillRAM [0x4800], 0, 4);
int i;
+
+ memset(&Memory.FillRAM [0x4800], 0, 4);
+
for (i = 0; i < 4; i++)
{
Memory.FillRAM [0x4804 + i] = i;
@@ -79,7 +81,7 @@ void S9xResetSDD1()
}
}
-void S9xSDD1PostLoadState()
+void S9xSDD1PostLoadState(void)
{
int i;
for (i = 0; i < 4; i++)
@@ -100,10 +102,12 @@ void S9xSDD1SaveLoggedData()
{
if (Memory.SDD1LoggedDataCount != Memory.SDD1LoggedDataCountPrev)
{
+ FILE *fs;
+
qsort(Memory.SDD1LoggedData, Memory.SDD1LoggedDataCount, 8,
S9xCompareSDD1LoggedDataEntries);
- FILE* fs = fopen(S9xGetFilename(".dat"), "wb");
+ fs = fopen(S9xGetFilename(".dat"), "wb");
if (fs)
{
diff --git a/src/sdd1emu.h b/src/sdd1emu.h
index a509a10..138b149 100644
--- a/src/sdd1emu.h
+++ b/src/sdd1emu.h
@@ -89,16 +89,11 @@
#ifndef SDD1EMU_H
#define SDD1EMU_H
-/* for START_EXTERN_C/END_EXTERN_C */
#include "port.h"
-START_EXTERN_C
-
void SDD1_decompress(uint8* out, uint8* in, int output_length);
void SDD1_init(uint8* in);
uint8 SDD1_get_byte(void);
-END_EXTERN_C
-
#endif
diff --git a/src/seta.c b/src/seta.c
index 7b306c5..cb1aaf4 100644
--- a/src/seta.c
+++ b/src/seta.c
@@ -95,7 +95,6 @@
void (*SetSETA)(uint32, uint8) = &S9xSetST010;
uint8(*GetSETA)(uint32) = &S9xGetST010;
-START_EXTERN_C
uint8 S9xGetSetaDSP(uint32 Address)
{
return GetSETA(Address);
@@ -105,5 +104,4 @@ void S9xSetSetaDSP(uint8 Byte, uint32 Address)
{
SetSETA(Address, Byte);
}
-END_EXTERN_C
diff --git a/src/seta.h b/src/seta.h
index 37368f5..ab298e9 100644
--- a/src/seta.h
+++ b/src/seta.h
@@ -98,7 +98,6 @@
#define ST_018 0x03
-START_EXTERN_C
uint8 S9xGetSetaDSP(uint32 Address);
void S9xSetSetaDSP(uint8 byte, uint32 Address);
uint8 S9xGetST018(uint32 Address);
@@ -108,7 +107,6 @@ uint8 S9xGetST010(uint32 Address);
void S9xSetST010(uint32 Address, uint8 Byte);
uint8 S9xGetST011(uint32 Address);
void S9xSetST011(uint32 Address, uint8 Byte);
-END_EXTERN_C
extern void (*SetSETA)(uint32, uint8);
extern uint8(*GetSETA)(uint32);
diff --git a/src/snapshot.c b/src/snapshot.c
index 47e9e16..a88a462 100644
--- a/src/snapshot.c
+++ b/src/snapshot.c
@@ -497,10 +497,11 @@ static void Freeze()
FreezeBlock("FIL", Memory.FillRAM, 0x8000);
if (Settings.APUEnabled)
{
+ SAPURegisters spcregs;
+
// APU
FreezeStruct("APU", &APU, SnapAPU, COUNT(SnapAPU));
// copy all SPC700 regs to savestate compatible struct
- SAPURegisters spcregs;
spcregs.P = IAPU.P;
spcregs.YA.W = IAPU.YA.W;
spcregs.X = IAPU.X;
@@ -526,14 +527,16 @@ static void Freeze()
S9xSetSoundMute(FALSE);
}
-static int Unfreeze()
+static int Unfreeze(void)
{
+ uint32 old_flags;
+ uint32 sa1_old_flags;
// notaz: overflowing the damn Symbian stack again
char buffer [16];
char rom_filename [512];
int result;
-
int version;
+ unsigned int i;
unsigned int len = strlen(SNAPSHOT_MAGIC) + 1 + 4 + 1;
if (statef_read(buffer, len) != (int)len)
@@ -553,11 +556,9 @@ static int Unfreeze()
"Current loaded ROM image doesn't match that required by freeze-game file.");
}
-
-
- uint32 old_flags = CPU.Flags;
+ old_flags = CPU.Flags;
#ifdef USE_SA1
- uint32 sa1_old_flags = SA1.Flags;
+ sa1_old_flags = SA1.Flags;
#endif
S9xReset();
S9xSetSoundMute(TRUE);
@@ -580,7 +581,6 @@ static int Unfreeze()
IPPU.OBJChanged = TRUE;
CPU.InDMA = FALSE;
// Restore colors from PPU
- unsigned int i;
for (i = 0; i < 256; i++)
{
IPPU.Red[i] = PPU.CGDATA[i] & 0x1f;
@@ -617,7 +617,9 @@ static int Unfreeze()
if (UnfreezeStruct("APU", &APU, SnapAPU, COUNT(SnapAPU)) == SUCCESS)
{
+ int u;
SAPURegisters spcregs;
+
if ((result = UnfreezeStruct("ARE", &spcregs, SnapAPURegisters,
COUNT(SnapAPURegisters))) != SUCCESS)
return (result);
@@ -636,7 +638,6 @@ static int Unfreeze()
return (result);
// notaz: just to be sure
- int u;
for (u = 0; u < 8; u++)
{
SoundData.channels[u].env_ind_attack &= 0xf;
@@ -708,6 +709,11 @@ void FreezeStruct(char* name, void* base, FreezeData* fields,
int len = 0;
int i;
int j;
+ uint8 *block;
+ uint8 *ptr;
+ uint16 word;
+ uint32 dword;
+ int64 qword;
for (i = 0; i < num_fields; i++)
{
@@ -717,71 +723,67 @@ void FreezeStruct(char* name, void* base, FreezeData* fields,
fields [i].type);
}
- // uint8 *block = new uint8 [len];
- uint8* block = (uint8*)malloc(len);
- uint8* ptr = block;
- uint16 word;
- uint32 dword;
- int64 qword;
+ block = (uint8*)malloc(len);
+ ptr = block;
// Build the block ready to be streamed out
for (i = 0; i < num_fields; i++)
{
switch (fields [i].type)
{
- case INT_V:
- switch (fields [i].size)
- {
- case 1:
- *ptr++ = *((uint8*) base + fields [i].offset);
+ case INT_V:
+ switch (fields [i].size)
+ {
+ case 1:
+ *ptr++ = *((uint8*) base + fields [i].offset);
+ break;
+ case 2:
+ word = *((uint16*)((uint8*) base + fields [i].offset));
+ *ptr++ = (uint8)(word >> 8);
+ *ptr++ = (uint8) word;
+ break;
+ case 4:
+ dword = *((uint32*)((uint8*) base + fields [i].offset));
+ *ptr++ = (uint8)(dword >> 24);
+ *ptr++ = (uint8)(dword >> 16);
+ *ptr++ = (uint8)(dword >> 8);
+ *ptr++ = (uint8) dword;
+ break;
+ case 8:
+ qword = *((int64*)((uint8*) base + fields [i].offset));
+ *ptr++ = (uint8)(qword >> 56);
+ *ptr++ = (uint8)(qword >> 48);
+ *ptr++ = (uint8)(qword >> 40);
+ *ptr++ = (uint8)(qword >> 32);
+ *ptr++ = (uint8)(qword >> 24);
+ *ptr++ = (uint8)(qword >> 16);
+ *ptr++ = (uint8)(qword >> 8);
+ *ptr++ = (uint8) qword;
+ break;
+ }
break;
- case 2:
- word = *((uint16*)((uint8*) base + fields [i].offset));
- *ptr++ = (uint8)(word >> 8);
- *ptr++ = (uint8) word;
+ case uint8_ARRAY_V:
+ memmove(ptr, (uint8*) base + fields [i].offset, fields [i].size);
+ ptr += fields [i].size;
break;
- case 4:
- dword = *((uint32*)((uint8*) base + fields [i].offset));
- *ptr++ = (uint8)(dword >> 24);
- *ptr++ = (uint8)(dword >> 16);
- *ptr++ = (uint8)(dword >> 8);
- *ptr++ = (uint8) dword;
+ case uint16_ARRAY_V:
+ for (j = 0; j < fields [i].size; j++)
+ {
+ word = *((uint16*)((uint8*) base + fields [i].offset + j * 2));
+ *ptr++ = (uint8)(word >> 8);
+ *ptr++ = (uint8) word;
+ }
break;
- case 8:
- qword = *((int64*)((uint8*) base + fields [i].offset));
- *ptr++ = (uint8)(qword >> 56);
- *ptr++ = (uint8)(qword >> 48);
- *ptr++ = (uint8)(qword >> 40);
- *ptr++ = (uint8)(qword >> 32);
- *ptr++ = (uint8)(qword >> 24);
- *ptr++ = (uint8)(qword >> 16);
- *ptr++ = (uint8)(qword >> 8);
- *ptr++ = (uint8) qword;
+ case uint32_ARRAY_V:
+ for (j = 0; j < fields [i].size; j++)
+ {
+ dword = *((uint32*)((uint8*) base + fields [i].offset + j * 4));
+ *ptr++ = (uint8)(dword >> 24);
+ *ptr++ = (uint8)(dword >> 16);
+ *ptr++ = (uint8)(dword >> 8);
+ *ptr++ = (uint8) dword;
+ }
break;
- }
- break;
- case uint8_ARRAY_V:
- memmove(ptr, (uint8*) base + fields [i].offset, fields [i].size);
- ptr += fields [i].size;
- break;
- case uint16_ARRAY_V:
- for (j = 0; j < fields [i].size; j++)
- {
- word = *((uint16*)((uint8*) base + fields [i].offset + j * 2));
- *ptr++ = (uint8)(word >> 8);
- *ptr++ = (uint8) word;
- }
- break;
- case uint32_ARRAY_V:
- for (j = 0; j < fields [i].size; j++)
- {
- dword = *((uint32*)((uint8*) base + fields [i].offset + j * 4));
- *ptr++ = (uint8)(dword >> 24);
- *ptr++ = (uint8)(dword >> 16);
- *ptr++ = (uint8)(dword >> 8);
- *ptr++ = (uint8) dword;
- }
- break;
}
}
@@ -806,6 +808,12 @@ int UnfreezeStruct(char* name, void* base, FreezeData* fields,
int len = 0;
int i;
int j;
+ uint16 word;
+ uint32 dword;
+ int64 qword;
+ int result;
+ uint8 *block;
+ uint8 *ptr;
for (i = 0; i < num_fields; i++)
{
@@ -815,12 +823,8 @@ int UnfreezeStruct(char* name, void* base, FreezeData* fields,
fields [i].type);
}
- uint8* block = (uint8*)malloc(len);
- uint8* ptr = block;
- uint16 word;
- uint32 dword;
- int64 qword;
- int result;
+ block = (uint8*)malloc(len);
+ ptr = block;
if ((result = UnfreezeBlock(name, block, len)) != SUCCESS)
{
diff --git a/src/snapshot.h b/src/snapshot.h
index 5c55d2c..649c2a1 100644
--- a/src/snapshot.h
+++ b/src/snapshot.h
@@ -52,11 +52,9 @@
#define WRONG_VERSION (-2)
#define FILE_NOT_FOUND (-3)
-START_EXTERN_C
bool8 S9xFreezeGame(const char* filename);
bool8 S9xUnfreezeGame(const char* filename);
bool8 Snapshot(const char* filename);
bool8 S9xLoadSnapshot(const char* filename);
-END_EXTERN_C
#endif
diff --git a/src/snes9x.h b/src/snes9x.h
index ac1dcfe..3bc6df0 100644
--- a/src/snes9x.h
+++ b/src/snes9x.h
@@ -373,16 +373,14 @@ typedef struct
uint8 Mode7Hack;
} SSNESGameFixes;
-START_EXTERN_C
extern SSettings Settings;
extern SCPUState CPU;
extern SSNESGameFixes SNESGameFixes;
extern char String [513];
-void S9xExit();
+void S9xExit(void);
void S9xMessage(int type, int number, const char* message);
-void S9xLoadSDD1Data();
-END_EXTERN_C
+void S9xLoadSDD1Data(void);
enum
{
diff --git a/src/soundux.c b/src/soundux.c
index 56e5edb..78f3ba8 100644
--- a/src/soundux.c
+++ b/src/soundux.c
@@ -167,8 +167,10 @@ void S9xSetSoundKeyOff(int channel)
}
}
-void S9xFixSoundAfterSnapshotLoad()
+void S9xFixSoundAfterSnapshotLoad(void)
{
+ int i;
+
SoundData.echo_write_enabled = !(APU.DSP [APU_FLG] & 0x20);
SoundData.echo_channel_enable = APU.DSP [APU_EON];
S9xSetEchoDelay(APU.DSP [APU_EDL] & 0xf);
@@ -183,7 +185,6 @@ void S9xFixSoundAfterSnapshotLoad()
S9xSetFilterCoefficient(6, (signed char) APU.DSP [APU_C6]);
S9xSetFilterCoefficient(7, (signed char) APU.DSP [APU_C7]);
- int i;
for (i = 0; i < 8; i++)
{
SoundData.channels[i].needs_decode = TRUE;
@@ -243,6 +244,17 @@ void S9xSetSoundSample(int channel, uint16 sample_number)
static void DecodeBlock(Channel* ch)
{
+ int16* raw;
+ int8_t * compressed;
+ uint8_t filter;
+#ifndef ASM_SPC700
+ int32 out;
+ uint8_t shift;
+ int8_t sample1, sample2;
+ unsigned int i;
+ int32 prev0, prev1;
+#endif
+
if (ch->block_pointer >= 0x10000 - 9)
{
ch->last_block = TRUE;
@@ -251,100 +263,96 @@ static void DecodeBlock(Channel* ch)
memset32((uint32_t*) ch->decoded, 0, 8);
return;
}
- signed char* compressed = (signed char*) &IAPU.RAM [ch->block_pointer];
+ compressed = (int8_t*) &IAPU.RAM [ch->block_pointer];
+ filter = *compressed;
- unsigned char filter = *compressed;
if ((ch->last_block = filter & 1))
ch->loop = (filter & 2) != 0;
- int16* raw = ch->block = ch->decoded;
+ raw = ch->block = ch->decoded;
#ifdef ASM_SPC700
DecodeBlockAsm(compressed, raw, &ch->previous [0], &ch->previous [1]);
#else
- int32 out;
- unsigned char shift;
- signed char sample1, sample2;
- unsigned int i;
-
compressed++;
- int32 prev0 = ch->previous [0];
- int32 prev1 = ch->previous [1];
+
+ prev0 = ch->previous [0];
+ prev1 = ch->previous [1];
shift = filter >> 4;
switch ((filter >> 2) & 3)
{
- case 0:
- for (i = 8; i != 0; i--)
- {
- sample1 = *compressed++;
- sample2 = sample1 << 4;
- sample2 >>= 4;
- sample1 >>= 4;
- *raw++ = ((int32) sample1 << shift);
- *raw++ = ((int32) sample2 << shift);
- }
- prev1 = *(raw - 2);
- prev0 = *(raw - 1);
- break;
- case 1:
- for (i = 8; i != 0; i--)
- {
- sample1 = *compressed++;
- sample2 = sample1 << 4;
- sample2 >>= 4;
- sample1 >>= 4;
- prev0 = (int16) prev0;
- *raw++ = prev1 = ((int32) sample1 << shift) + prev0 - (prev0 >> 4);
- prev1 = (int16) prev1;
- *raw++ = prev0 = ((int32) sample2 << shift) + prev1 - (prev1 >> 4);
- }
- break;
- case 2:
- for (i = 8; i != 0; i--)
- {
- sample1 = *compressed++;
- sample2 = sample1 << 4;
- sample2 >>= 4;
- sample1 >>= 4;
-
- out = (sample1 << shift) - prev1 + (prev1 >> 4);
- prev1 = (int16) prev0;
- prev0 &= ~3;
- *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) -
- (prev0 >> 4);
-
- out = (sample2 << shift) - prev1 + (prev1 >> 4);
- prev1 = (int16) prev0;
- prev0 &= ~3;
- *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) -
- (prev0 >> 4);
- }
- break;
- case 3:
- for (i = 8; i != 0; i--)
- {
- sample1 = *compressed++;
- sample2 = sample1 << 4;
- sample2 >>= 4;
- sample1 >>= 4;
- out = (sample1 << shift);
-
- out = out - prev1 + (prev1 >> 3) + (prev1 >> 4);
- prev1 = (int16) prev0;
- prev0 &= ~3;
- *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) -
- (prev0 >> 4) - (prev1 >> 6);
-
- out = (sample2 << shift);
- out = out - prev1 + (prev1 >> 3) + (prev1 >> 4);
- prev1 = (int16) prev0;
- prev0 &= ~3;
- *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) -
- (prev0 >> 4) - (prev1 >> 6);
- }
- break;
+ case 0:
+ for (i = 8; i != 0; i--)
+ {
+ sample1 = *compressed++;
+ sample2 = sample1 << 4;
+ sample2 >>= 4;
+ sample1 >>= 4;
+ *raw++ = ((int32) sample1 << shift);
+ *raw++ = ((int32) sample2 << shift);
+ }
+ prev1 = *(raw - 2);
+ prev0 = *(raw - 1);
+ break;
+ case 1:
+ for (i = 8; i != 0; i--)
+ {
+ sample1 = *compressed++;
+ sample2 = sample1 << 4;
+ sample2 >>= 4;
+ sample1 >>= 4;
+ prev0 = (int16) prev0;
+ *raw++ = prev1 = ((int32) sample1 << shift) + prev0 - (prev0 >> 4);
+ prev1 = (int16) prev1;
+ *raw++ = prev0 = ((int32) sample2 << shift) + prev1 - (prev1 >> 4);
+ }
+ break;
+ case 2:
+ for (i = 8; i != 0; i--)
+ {
+ sample1 = *compressed++;
+ sample2 = sample1 << 4;
+ sample2 >>= 4;
+ sample1 >>= 4;
+
+ out = (sample1 << shift) - prev1 + (prev1 >> 4);
+ prev1 = (int16) prev0;
+ prev0 &= ~3;
+ *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) -
+ (prev0 >> 4);
+
+ out = (sample2 << shift) - prev1 + (prev1 >> 4);
+ prev1 = (int16) prev0;
+ prev0 &= ~3;
+ *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) -
+ (prev0 >> 4);
+ }
+ break;
+ case 3:
+ for (i = 8; i != 0; i--)
+ {
+ sample1 = *compressed++;
+ sample2 = sample1 << 4;
+ sample2 >>= 4;
+ sample1 >>= 4;
+ out = (sample1 << shift);
+
+ out = out - prev1 + (prev1 >> 3) + (prev1 >> 4);
+ prev1 = (int16) prev0;
+ prev0 &= ~3;
+ *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) -
+ (prev0 >> 4) - (prev1 >> 6);
+
+ out = (sample2 << shift);
+ out = out - prev1 + (prev1 >> 3) + (prev1 >> 4);
+ prev1 = (int16) prev0;
+ prev0 &= ~3;
+ *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) -
+ (prev0 >> 4) - (prev1 >> 6);
+ }
+ break;
}
ch->previous [0] = prev0;
ch->previous [1] = prev1;
@@ -361,6 +369,8 @@ static void MixStereo(int sample_count)
uint32 J;
for (J = 0; J < NUM_CHANNELS; J++)
{
+ uint32 I;
+ bool8 mod;
int32 VL, VR;
Channel* ch = &SoundData.channels[J];
unsigned long freq0 = ch->frequency;
@@ -370,7 +380,7 @@ static void MixStereo(int sample_count)
// freq0 = (unsigned long) ((double) freq0 * 0.985);//uncommented by jonathan gevaryahu, as it is necessary for most cards in linux
- bool8 mod = pitch_mod & (1 << J);
+ mod = pitch_mod & (1 << J);
if (ch->needs_decode)
{
@@ -393,7 +403,6 @@ static void MixStereo(int sample_count)
VL = (ch->sample * ch-> left_vol_level) / 128;
VR = (ch->sample * ch->right_vol_level) / 128;
- uint32 I;
for (I = 0; I < (uint32) sample_count; I += 2)
{
unsigned long freq = freq0;
@@ -581,9 +590,11 @@ static void MixStereo(int sample_count)
}
else
{
+ uint16 *dir;
+
S9xAPUSetEndX(J);
- ch->last_block = FALSE;
- uint16* dir = S9xGetSampleAddress(ch->sample_number);
+ ch->last_block = FALSE;
+ dir = S9xGetSampleAddress(ch->sample_number);
ch->block_pointer = *(dir + 1);
}
}
@@ -663,6 +674,9 @@ static void MixMono(int sample_count)
uint32 J;
for (J = 0; J < NUM_CHANNELS; J++)
{
+ int32 V;
+ bool8 mod;
+ uint32 I;
Channel* ch = &SoundData.channels[J];
unsigned long freq0 = ch->frequency;
@@ -671,7 +685,7 @@ static void MixMono(int sample_count)
// freq0 = (unsigned long) ((double) freq0 * 0.985);
- bool8 mod = pitch_mod & (1 << J);
+ mod = pitch_mod & (1 << J);
if (ch->needs_decode)
{
@@ -686,9 +700,8 @@ static void MixMono(int sample_count)
ch->next_sample = ch->block[ch->sample_pointer];
}
- int32 V = (ch->sample * ch->left_vol_level) / 128;
+ V = (ch->sample * ch->left_vol_level) / 128;
- uint32 I;
for (I = 0; I < (uint32) sample_count; I++)
{
unsigned long freq = freq0;
@@ -703,144 +716,144 @@ static void MixMono(int sample_count)
switch (ch->state)
{
- case SOUND_ATTACK:
- ch->env_error &= FIXED_POINT_REMAINDER;
- ch->envx += step << 1;
- ch->envxx = ch->envx << ENVX_SHIFT;
+ case SOUND_ATTACK:
+ ch->env_error &= FIXED_POINT_REMAINDER;
+ ch->envx += step << 1;
+ ch->envxx = ch->envx << ENVX_SHIFT;
- if (ch->envx >= 126)
- {
- ch->envx = 127;
- ch->envxx = 127 << ENVX_SHIFT;
- ch->state = SOUND_DECAY;
- if (ch->sustain_level != 8)
+ if (ch->envx >= 126)
{
- S9xSetEnvRate(ch, ch->decay_rate, -1,
- (MAX_ENVELOPE_HEIGHT * ch->sustain_level) >> 3, 1 << 28);
- break;
+ ch->envx = 127;
+ ch->envxx = 127 << ENVX_SHIFT;
+ ch->state = SOUND_DECAY;
+ if (ch->sustain_level != 8)
+ {
+ S9xSetEnvRate(ch, ch->decay_rate, -1,
+ (MAX_ENVELOPE_HEIGHT * ch->sustain_level) >> 3, 1 << 28);
+ break;
+ }
+ ch->state = SOUND_SUSTAIN;
+ S9xSetEnvRate(ch, ch->sustain_rate, -1, 0, 2 << 28);
}
- ch->state = SOUND_SUSTAIN;
- S9xSetEnvRate(ch, ch->sustain_rate, -1, 0, 2 << 28);
- }
- break;
+ break;
- case SOUND_DECAY:
- while (ch->env_error >= FIXED_POINT)
- {
- ch->envxx = (ch->envxx >> 8) * 255;
- ch->env_error -= FIXED_POINT;
- }
- ch->envx = ch->envxx >> ENVX_SHIFT;
- if (ch->envx <= ch->envx_target)
- {
+ case SOUND_DECAY:
+ while (ch->env_error >= FIXED_POINT)
+ {
+ ch->envxx = (ch->envxx >> 8) * 255;
+ ch->env_error -= FIXED_POINT;
+ }
+ ch->envx = ch->envxx >> ENVX_SHIFT;
+ if (ch->envx <= ch->envx_target)
+ {
+ if (ch->envx <= 0)
+ {
+ S9xAPUSetEndOfSample(J, ch);
+ goto mono_exit;
+ }
+ ch->state = SOUND_SUSTAIN;
+ S9xSetEnvRate(ch, ch->sustain_rate, -1, 0, 2 << 28);
+ }
+ break;
+
+ case SOUND_SUSTAIN:
+ while (ch->env_error >= FIXED_POINT)
+ {
+ ch->envxx = (ch->envxx >> 8) * 255;
+ ch->env_error -= FIXED_POINT;
+ }
+ ch->envx = ch->envxx >> ENVX_SHIFT;
if (ch->envx <= 0)
{
S9xAPUSetEndOfSample(J, ch);
goto mono_exit;
}
- ch->state = SOUND_SUSTAIN;
- S9xSetEnvRate(ch, ch->sustain_rate, -1, 0, 2 << 28);
- }
- break;
-
- case SOUND_SUSTAIN:
- while (ch->env_error >= FIXED_POINT)
- {
- ch->envxx = (ch->envxx >> 8) * 255;
- ch->env_error -= FIXED_POINT;
- }
- ch->envx = ch->envxx >> ENVX_SHIFT;
- if (ch->envx <= 0)
- {
- S9xAPUSetEndOfSample(J, ch);
- goto mono_exit;
- }
- break;
-
- case SOUND_RELEASE:
- while (ch->env_error >= FIXED_POINT)
- {
- ch->envxx -= (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
- ch->env_error -= FIXED_POINT;
- }
- ch->envx = ch->envxx >> ENVX_SHIFT;
- if (ch->envx <= 0)
- {
- S9xAPUSetEndOfSample(J, ch);
- goto mono_exit;
- }
- break;
-
- case SOUND_INCREASE_LINEAR:
- ch->env_error &= FIXED_POINT_REMAINDER;
- ch->envx += step << 1;
- ch->envxx = ch->envx << ENVX_SHIFT;
+ break;
- if (ch->envx >= 126)
- {
- ch->envx = 127;
- ch->envxx = 127 << ENVX_SHIFT;
- ch->state = SOUND_GAIN;
- ch->mode = MODE_GAIN;
- S9xSetEnvRate(ch, 0, -1, 0, 0);
- }
- break;
-
- case SOUND_INCREASE_BENT_LINE:
- if (ch->envx >= (MAX_ENVELOPE_HEIGHT * 3) / 4)
- {
+ case SOUND_RELEASE:
while (ch->env_error >= FIXED_POINT)
{
- ch->envxx += (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
+ ch->envxx -= (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
ch->env_error -= FIXED_POINT;
}
ch->envx = ch->envxx >> ENVX_SHIFT;
- }
- else
- {
+ if (ch->envx <= 0)
+ {
+ S9xAPUSetEndOfSample(J, ch);
+ goto mono_exit;
+ }
+ break;
+
+ case SOUND_INCREASE_LINEAR:
ch->env_error &= FIXED_POINT_REMAINDER;
ch->envx += step << 1;
ch->envxx = ch->envx << ENVX_SHIFT;
- }
- if (ch->envx >= 126)
- {
- ch->envx = 127;
- ch->envxx = 127 << ENVX_SHIFT;
- ch->state = SOUND_GAIN;
- ch->mode = MODE_GAIN;
- S9xSetEnvRate(ch, 0, -1, 0, 0);
- }
- break;
+ if (ch->envx >= 126)
+ {
+ ch->envx = 127;
+ ch->envxx = 127 << ENVX_SHIFT;
+ ch->state = SOUND_GAIN;
+ ch->mode = MODE_GAIN;
+ S9xSetEnvRate(ch, 0, -1, 0, 0);
+ }
+ break;
- case SOUND_DECREASE_LINEAR:
- ch->env_error &= FIXED_POINT_REMAINDER;
- ch->envx -= step << 1;
- ch->envxx = ch->envx << ENVX_SHIFT;
- if (ch->envx <= 0)
- {
- S9xAPUSetEndOfSample(J, ch);
- goto mono_exit;
- }
- break;
+ case SOUND_INCREASE_BENT_LINE:
+ if (ch->envx >= (MAX_ENVELOPE_HEIGHT * 3) / 4)
+ {
+ while (ch->env_error >= FIXED_POINT)
+ {
+ ch->envxx += (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
+ ch->env_error -= FIXED_POINT;
+ }
+ ch->envx = ch->envxx >> ENVX_SHIFT;
+ }
+ else
+ {
+ ch->env_error &= FIXED_POINT_REMAINDER;
+ ch->envx += step << 1;
+ ch->envxx = ch->envx << ENVX_SHIFT;
+ }
- case SOUND_DECREASE_EXPONENTIAL:
- while (ch->env_error >= FIXED_POINT)
- {
- ch->envxx = (ch->envxx >> 8) * 255;
- ch->env_error -= FIXED_POINT;
- }
- ch->envx = ch->envxx >> ENVX_SHIFT;
- if (ch->envx <= 0)
- {
- S9xAPUSetEndOfSample(J, ch);
- goto mono_exit;
- }
- break;
+ if (ch->envx >= 126)
+ {
+ ch->envx = 127;
+ ch->envxx = 127 << ENVX_SHIFT;
+ ch->state = SOUND_GAIN;
+ ch->mode = MODE_GAIN;
+ S9xSetEnvRate(ch, 0, -1, 0, 0);
+ }
+ break;
- case SOUND_GAIN:
- S9xSetEnvRate(ch, 0, -1, 0, 0);
- break;
+ case SOUND_DECREASE_LINEAR:
+ ch->env_error &= FIXED_POINT_REMAINDER;
+ ch->envx -= step << 1;
+ ch->envxx = ch->envx << ENVX_SHIFT;
+ if (ch->envx <= 0)
+ {
+ S9xAPUSetEndOfSample(J, ch);
+ goto mono_exit;
+ }
+ break;
+
+ case SOUND_DECREASE_EXPONENTIAL:
+ while (ch->env_error >= FIXED_POINT)
+ {
+ ch->envxx = (ch->envxx >> 8) * 255;
+ ch->env_error -= FIXED_POINT;
+ }
+ ch->envx = ch->envxx >> ENVX_SHIFT;
+ if (ch->envx <= 0)
+ {
+ S9xAPUSetEndOfSample(J, ch);
+ goto mono_exit;
+ }
+ break;
+
+ case SOUND_GAIN:
+ S9xSetEnvRate(ch, 0, -1, 0, 0);
+ break;
}
ch->left_vol_level = (ch->envx * ch->volume_left) / 128;
V = (ch->sample * ch->left_vol_level) / 128;
@@ -874,8 +887,10 @@ static void MixMono(int sample_count)
}
else
{
- ch->last_block = FALSE;
- uint16* dir = S9xGetSampleAddress(ch->sample_number);
+ uint16 *dir;
+
+ ch->last_block = FALSE;
+ dir = S9xGetSampleAddress(ch->sample_number);
ch->block_pointer = *(dir + 1);
S9xAPUSetEndX(J);
}
@@ -1188,19 +1203,23 @@ extern unsigned long DecreaseRateExp [32];
void S9xSetPlaybackRate(uint32 playback_rate)
{
+ int i;
+
so.playback_rate = playback_rate;
if (playback_rate)
{
- // notaz: calclulate a value (let's call it freqbase) to simplify channel freq calculations later.
- so.freqbase = (FIXED_POINT << 11) / (playback_rate * 33 / 32);
- // now precalculate env rates for S9xSetEnvRate
static int steps [] =
{
//0, 64, 1238, 1238, 256, 1, 64, 109, 64, 1238
0, 64, 619, 619, 128, 1, 64, 55, 64, 619
};
- int i, u;
+ int u;
+
+ // notaz: calculate a value (let's call it freqbase) to simplify
+ // channel freq calculations later.
+ so.freqbase = (FIXED_POINT << 11) / (playback_rate * 33 / 32);
+ // now precalculate env rates for S9xSetEnvRate
for (i = 0; i < 16; i++)
for (u = 0; u < 10; u++)
AttackERate[i][u] = (unsigned long)(((int64) FIXED_POINT * 1000 * steps[u]) /
@@ -1231,7 +1250,6 @@ void S9xSetPlaybackRate(uint32 playback_rate)
}
S9xSetEchoDelay(APU.DSP [APU_EDL] & 0xf);
- int i;
for (i = 0; i < 8; i++)
S9xSetSoundFrequency(i, SoundData.channels [i].hertz);
}
diff --git a/src/soundux.h b/src/soundux.h
index d79dfca..d44613f 100644
--- a/src/soundux.h
+++ b/src/soundux.h
@@ -76,7 +76,7 @@ typedef struct
uint32 freqbase; // notaz
} SoundStatus;
-EXTERN_C SoundStatus so;
+extern SoundStatus so;
typedef struct
{
@@ -152,7 +152,7 @@ typedef struct
int noise_hertz;
} SSoundData;
-EXTERN_C SSoundData SoundData;
+extern SSoundData SoundData;
void S9xSetEnvelopeHeight(int channel, int height);
void S9xSetSoundKeyOff(int channel);
@@ -162,13 +162,13 @@ void S9xSoundStartEnvelope(Channel*);
void S9xSetSoundSample(int channel, uint16 sample_number);
void S9xSetEchoDelay(int byte);
void S9xResetSound(bool8 full);
-void S9xFixSoundAfterSnapshotLoad();
+void S9xFixSoundAfterSnapshotLoad(void);
void S9xPlaybackSoundSetting(int channel);
void S9xFixEnvelope(int channel, uint8 gain, uint8 adsr1, uint8 adsr2);
void S9xStartSample(int channel);
-EXTERN_C void S9xMixSamples(signed short* buffer, int sample_count);
-EXTERN_C void S9xMixSamplesO(signed short* buffer, int sample_count, int sample_offset);
+void S9xMixSamples(signed short* buffer, int sample_count);
+void S9xMixSamplesO(signed short* buffer, int sample_count, int sample_offset);
void S9xSetPlaybackRate(uint32 rate);
bool8 S9xInitSound(void);
#endif
diff --git a/src/spc700.c b/src/spc700.c
index 5a74eda..84c5d51 100644
--- a/src/spc700.c
+++ b/src/spc700.c
@@ -114,8 +114,9 @@ void STOP(char* s)
}
// XXX: HalfCarry - BJ fixed?
-#define SBC(a,b)\
-short Int16 = (short) (a) - (short) (b) + (short) (APUCheckCarry ()) - 1;\
+#define SBC(a,b) \
+{ \
+int16_t Int16 = (int16_t) (a) - (int16_t) (b) + (int16_t) (APUCheckCarry ()) - 1;\
IAPU._Carry = Int16 >= 0;\
if ((((a) ^ (b)) & 0x80) && (((a) ^ (uint8) Int16) & 0x80))\
APUSetOverflow ();\
@@ -125,27 +126,32 @@ APUSetHalfCarry ();\
if(((a) ^ (b) ^ (uint8) Int16) & 0x10)\
APUClearHalfCarry ();\
(a) = (uint8) Int16;\
-APUSetZN8 ((uint8) Int16);
+APUSetZN8 ((uint8) Int16); \
+}
// XXX: HalfCarry - BJ fixed?
#define ADC(a,b)\
-uint16 Work16 = (a) + (b) + APUCheckCarry();\
+{ \
+uint16 Work16 = (a) + (b) + APUCheckCarry(); \
IAPU._Carry = Work16 >= 0x100; \
if (~((a) ^ (b)) & ((b) ^ (uint8) Work16) & 0x80)\
- APUSetOverflow ();\
+ APUSetOverflow (); \
else \
APUClearOverflow (); \
-APUClearHalfCarry ();\
+APUClearHalfCarry (); \
/*if(((a) ^ (b) ^ (uint8) Int16) & 0x10) notaz: Int16!? */\
if(((a) ^ (b) ^ (uint8) Work16) & 0x10)\
- APUSetHalfCarry ();\
-(a) = (uint8) Work16;\
-APUSetZN8 ((uint8) Work16);
+ APUSetHalfCarry (); \
+(a) = (uint8) Work16; \
+APUSetZN8 ((uint8) Work16); \
+}
#define CMP(a,b)\
-short Int16 = (short) (a) - (short) (b);\
-IAPU._Carry = Int16 >= 0;\
-APUSetZN8 ((uint8) Int16);
+{ \
+int16_t Int16 = (int16_t) (a) - (int16_t) (b); \
+IAPU._Carry = Int16 >= 0; \
+APUSetZN8 ((uint8) Int16); \
+}
#define ASL(b)\
IAPU._Carry = ((b) & 0x80) != 0; \
@@ -156,16 +162,21 @@ APUSetZN8 ((uint8) Int16);
(b) >>= 1;\
APUSetZN8 (b);
#define ROL(b)\
+{ \
uint16 Work16 = ((b) << 1) | APUCheckCarry (); \
IAPU._Carry = Work16 >= 0x100; \
(b) = (uint8) Work16; \
- APUSetZN8 (b);
+ APUSetZN8 (b); \
+}
+
#define ROR(b)\
+{ \
uint16 Work16 = (b) | ((uint16) APUCheckCarry () << 8); \
IAPU._Carry = (uint8) Work16 & 1; \
Work16 >>= 1; \
(b) = (uint8) Work16; \
- APUSetZN8 (b);
+ APUSetZN8 (b); \
+}
#define Push(b)\
*(IAPU.RAM + 0x100 + IAPU.S) = b;\
@@ -193,11 +204,11 @@ APUSetZN8 ((uint8) Int16);
#endif
#define Relative()\
- signed char Int8 = OP1;\
+ int8_t Int8 = OP1;\
short Int16 = (int) (IAPU.PC + 2 - IAPU.RAM) + Int8;
#define Relative2()\
- signed char Int8 = OP2;\
+ int8_t Int8 = OP2;\
short Int16 = (int) (IAPU.PC + 3 - IAPU.RAM) + Int8;
#ifdef FAST_LSB_WORD_ACCESS
@@ -749,17 +760,18 @@ void Apu0B()
IAPU.PC += 2;
}
-void Apu0C()
+void Apu0C(void)
{
+ uint8 Work8;
// ASL abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address);
+ Work8 = S9xAPUGetByte(IAPU.Address);
ASL(Work8);
S9xAPUSetByte(Work8, IAPU.Address);
IAPU.PC += 3;
}
-void Apu1B()
+void Apu1B(void)
{
// ASL dp+X
uint8 Work8 = S9xAPUGetByteZ(OP1 + IAPU.X);
@@ -839,9 +851,10 @@ void ApuEE()
void Apu0E()
{
+ uint8 Work8;
// TSET1 abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address);
+ Work8 = S9xAPUGetByte(IAPU.Address);
S9xAPUSetByte(Work8 | IAPU.YA.B.A, IAPU.Address);
Work8 &= IAPU.YA.B.A;
APUSetZN8(Work8);
@@ -850,9 +863,10 @@ void Apu0E()
void Apu4E()
{
+ uint8 Work8;
// TCLR1 abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address);
+ Work8 = S9xAPUGetByte(IAPU.Address);
S9xAPUSetByte(Work8 & ~IAPU.YA.B.A, IAPU.Address);
Work8 &= IAPU.YA.B.A;
APUSetZN8(Work8);
@@ -1137,9 +1151,10 @@ void Apu64()
void Apu65()
{
+ uint8 Work8;
// CMP A,abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address);
+ Work8 = S9xAPUGetByte(IAPU.Address);
CMP(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
@@ -1154,9 +1169,10 @@ void Apu66()
void Apu67()
{
+ uint8 Work8;
// CMP A,(dp+X)
IndexedXIndirect();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
CMP(IAPU.YA.B.A, Work8);
IAPU.PC += 2;
}
@@ -1188,27 +1204,30 @@ void Apu74()
void Apu75()
{
+ uint8 Work8;
// CMP A,abs+X
AbsoluteX();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address);
+ Work8 = S9xAPUGetByte(IAPU.Address);
CMP(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
void Apu76()
{
+ uint8 Work8;
// CMP A, abs+Y
AbsoluteY();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address);
+ Work8 = S9xAPUGetByte(IAPU.Address);
CMP(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
void Apu77()
{
+ uint8 Work8;
// CMP A,(dp)+Y
IndirectIndexedY();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address);
+ Work8 = S9xAPUGetByte(IAPU.Address);
CMP(IAPU.YA.B.A, Work8);
IAPU.PC += 2;
}
@@ -1233,9 +1252,10 @@ void Apu79()
void Apu1E()
{
+ uint8 Work8;
// CMP X,abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address);
+ Work8 = S9xAPUGetByte(IAPU.Address);
CMP(IAPU.X, Work8);
IAPU.PC += 3;
}
@@ -1257,9 +1277,10 @@ void ApuC8()
void Apu5E()
{
+ uint8 Work8;
// CMP Y,abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
CMP(IAPU.YA.B.Y, Work8);
IAPU.PC += 3;
}
@@ -1437,9 +1458,10 @@ void Apu2B()
void Apu2C()
{
+ uint8 Work8;
// ROL abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
ROL(Work8);
S9xAPUSetByte(Work8, IAPU.Address);
IAPU.PC += 3;
@@ -1561,9 +1583,10 @@ void ApuAB()
void ApuAC()
{
+ uint8 Work8;
// INC abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(IAPU.Address) + 1;
+ Work8 = S9xAPUGetByte(IAPU.Address) + 1;
S9xAPUSetByte(Work8, IAPU.Address);
APUSetZN8(Work8);
@@ -1617,9 +1640,10 @@ void Apu8B()
void Apu8C()
{
+ uint8 Work8;
// DEC abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address))) - 1;
+ Work8 = S9xAPUGetByte(((IAPU.Address))) - 1;
S9xAPUSetByte(Work8, IAPU.Address);
APUSetZN8(Work8);
@@ -1774,9 +1798,10 @@ void Apu4B()
void Apu4C()
{
+ uint8 Work8;
// LSR abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
LSR(Work8);
S9xAPUSetByte(Work8, IAPU.Address);
IAPU.PC += 3;
@@ -1856,9 +1881,10 @@ void Apu6B()
void Apu6C()
{
+ uint8 Work8;
// ROR abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
ROR(Work8);
S9xAPUSetByte(Work8, IAPU.Address);
IAPU.PC += 3;
@@ -1882,10 +1908,11 @@ void Apu7C()
void Apu6E()
{
+ uint8 W1;
// DBNZ dp,rel
uint8 Work8 = OP1;
Relative2();
- uint8 W1 = S9xAPUGetByteZ(Work8) - 1;
+ W1 = S9xAPUGetByteZ(Work8) - 1;
S9xAPUSetByteZ(W1, Work8);
if (W1 != 0)
{
@@ -1939,9 +1966,10 @@ void Apu84()
void Apu85()
{
+ uint8 Work8;
// ADC A, abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
ADC(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
@@ -1956,9 +1984,10 @@ void Apu86()
void Apu87()
{
+ uint8 Work8;
// ADC A,(dp+X)
IndexedXIndirect();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
ADC(IAPU.YA.B.A, Work8);
IAPU.PC += 2;
}
@@ -1991,27 +2020,30 @@ void Apu94()
void Apu95()
{
+ uint8 Work8;
// ADC A, abs+X
AbsoluteX();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
ADC(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
void Apu96()
{
+ uint8 Work8;
// ADC A, abs+Y
AbsoluteY();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
ADC(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
void Apu97()
{
+ uint8 Work8;
// ADC A, (dp)+Y
IndirectIndexedY();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
ADC(IAPU.YA.B.A, Work8);
IAPU.PC += 2;
}
@@ -2063,8 +2095,9 @@ void Apu9E()
}
else
{
+ uint8 Work8;
APUClearOverflow();
- uint8 Work8 = IAPU.YA.W / IAPU.X;
+ Work8 = IAPU.YA.W / IAPU.X;
IAPU.YA.B.Y = IAPU.YA.W % IAPU.X;
IAPU.YA.B.A = Work8;
}
@@ -2092,9 +2125,10 @@ void ApuA4()
void ApuA5()
{
+ uint8 Work8;
// SBC A, abs
Absolute();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
SBC(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
@@ -2109,9 +2143,10 @@ void ApuA6()
void ApuA7()
{
+ uint8 Work8;
// SBC A,(dp+X)
IndexedXIndirect();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
SBC(IAPU.YA.B.A, Work8);
IAPU.PC += 2;
}
@@ -2144,27 +2179,30 @@ void ApuB4()
void ApuB5()
{
+ uint8 Work8;
// SBC A,abs+X
AbsoluteX();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
SBC(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
void ApuB6()
{
+ uint8 Work8;
// SBC A,abs+Y
AbsoluteY();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
SBC(IAPU.YA.B.A, Work8);
IAPU.PC += 3;
}
void ApuB7()
{
+ uint8 Work8;
// SBC A,(dp)+Y
IndirectIndexedY();
- uint8 Work8 = S9xAPUGetByte(((IAPU.Address)));
+ Work8 = S9xAPUGetByte(((IAPU.Address)));
SBC(IAPU.YA.B.A, Work8);
IAPU.PC += 2;
}
diff --git a/src/spc700.h b/src/spc700.h
index 805392c..748f789 100644
--- a/src/spc700.h
+++ b/src/spc700.h
@@ -110,8 +110,6 @@ typedef struct
uint16 PC;
} SAPURegisters;
-//EXTERN_C struct SAPURegisters APURegisters;
-
// Needed by ILLUSION OF GAIA
//#define ONE_APU_CYCLE 14
#define ONE_APU_CYCLE 21
@@ -123,7 +121,7 @@ typedef struct
// 1.953us := 1.024065.54MHz
#ifdef SPCTOOL
-EXTERN_C int32 ESPC(int32);
+extern int32 ESPC(int32);
#define APU_EXECUTE() \
{ \
@@ -139,7 +137,7 @@ EXTERN_C int32 ESPC(int32);
// return cycles left (always negative)
-EXTERN_C int spc700_execute(int cycles);
+int spc700_execute(int cycles);
#endif // SPCTOOL
diff --git a/src/srtc.c b/src/srtc.c
index 81f7bfe..04007a3 100644
--- a/src/srtc.c
+++ b/src/srtc.c
@@ -459,9 +459,11 @@ void S9xSRTCPreSaveState()
{
if (Settings.SRTC)
{
+ int s;
+
S9xUpdateSrtcTime();
- int s = Memory.SRAMSize ?
+ s = Memory.SRAMSize ?
(1 << (Memory.SRAMSize + 3)) * 128 : 0;
if (s > 0x20000)
s = 0x20000;