Skip to content

Commit

Permalink
Merge pull request #14 from jasmith79/cleancode
Browse files Browse the repository at this point in the history
Cleancode
  • Loading branch information
tjwei committed Apr 6, 2017
2 parents cd72327 + 188b0e0 commit 741561e
Show file tree
Hide file tree
Showing 19 changed files with 1,657 additions and 297 deletions.
6 changes: 3 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Install emscripten and make sure emcc is in your $PATH.
./buildall
see output for compiled results.

snem port is outdated, can only be compiled by a very old version of emscripten.
snem port is outdated, can only be compiled by a very old version of emscripten.
I might update it in future but snes9x seems to be fast enough for modern devices.

snes9x port is updated for emscripten 1.34.3
snes9x port requires emscripten 1.36+

snes9x is build with sound by default. comment out -Dsound in snes9x/sdl/buildhtml to disable sound.

Expand All @@ -17,4 +17,4 @@ Blog posts (Tradition Chinese)
http://weijr-note.blogspot.tw/2012/06/javascript-snes-emulator-wip.html # Orginal version (6/22/2012)
http://weijr-note.blogspot.tw/2012/08/js.html # more videos
http://weijr-note.blogspot.tw/2012/08/coscup-2012.html # COSCUP slides

8 changes: 4 additions & 4 deletions snes9x/apu/resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class Resampler : public ring_buffer
virtual void time_ratio (double) = 0;
virtual void read (short *, int) = 0;
virtual int avail (void) = 0;

Resampler (int num_samples) : ring_buffer (num_samples << 1)
{
}

~Resampler ()
virtual ~Resampler ()
{
}

Expand All @@ -37,13 +37,13 @@ class Resampler : public ring_buffer
{
return buffer_size - size;
}

inline int
space_filled (void)
{
return size;
}

inline int
max_write (void)
{
Expand Down
1 change: 0 additions & 1 deletion snes9x/c4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ void C4Op1F (void)
{
tanval = (double) C41FYVal / C41FXVal;
C41FAngleRes = (int16) (atan(tanval) / (C4_PI * 2) * 512);
C41FAngleRes = C41FAngleRes;
if (C41FXVal< 0)
C41FAngleRes += 0x100;
C41FAngleRes &= 0x1FF;
Expand Down
472 changes: 238 additions & 234 deletions snes9x/controls.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions snes9x/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ typedef struct
} pointer;

uint8 port[4];
};
} input;
} s9xcommand_t;

// Starting out...
Expand All @@ -323,7 +323,7 @@ void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2
void S9xGetController (int port, enum controllers *controller, int8 *id1, int8 *id2, int8 *id3, int8 *id4);
void S9xReportControllers (void);

// Call this when you're done with S9xSetController, or if you change any of the controller Settings.*Master flags.
// Call this when you're done with S9xSetController, or if you change any of the controller Settings.*Master flags.
// Returns true if something was disabled.

bool S9xVerifyControllers (void);
Expand Down
15 changes: 8 additions & 7 deletions snes9x/cpuexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ static inline void S9xReschedule (void);

void S9xMainLoop (void)
{
static int loop_times=0;
// debugging variable?
// static int loop_times=0;
int loops2=0;
//printf("Enter S9xMainLoop %d %x\n", loop_times, Registers.PCw);
for (;;)
Expand All @@ -218,7 +219,7 @@ void S9xMainLoop (void)
}

if (CPU.IRQTransition || CPU.IRQExternal)
{
{
//printf("case 2\n");
if (CPU.IRQPending)
CPU.IRQPending--;
Expand Down Expand Up @@ -274,12 +275,12 @@ void S9xMainLoop (void)
register uint8 Op;
register Opcode *Opcodes;

if (CPU.PCBase)
{
if (CPU.PCBase)
{
Op = CPU.PCBase[Registers.PCw];

CPU.PrevCycles = CPU.Cycles;
CPU.Cycles += CPU.MemSpeed;
CPU.Cycles += CPU.MemSpeed;
S9xCheckInterrupts();
Opcodes = ICPU.S9xOpcodes;
//printf("case 3 %x %x %d %d\n", Registers.PCw, Op, CPU.PrevCycles, CPU.Cycles);
Expand All @@ -293,7 +294,7 @@ void S9xMainLoop (void)
}

if ((Registers.PCw & MEMMAP_MASK) + ICPU.S9xOpLengths[Op] >= MEMMAP_BLOCK_SIZE)
{
{
uint8 *oldPCBase = CPU.PCBase;
//printf("case 5\n");

Expand Down
2 changes: 1 addition & 1 deletion snes9x/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void S9xParseArg (char **, int &, int);
void S9xExtraDisplayUsage (void);
void S9xParseDisplayArg (char **, int &, int);
void S9xSetTitle (const char *);
void S9xInitInputDevices (void);
extern "C" void S9xInitInputDevices (int, int, int, int, int, int, int, int, int, int, int, int) __attribute__((used));
void S9xProcessEvents (bool8);
const char * S9xSelectFilename (const char *, const char *, const char *, const char *);

Expand Down
6 changes: 3 additions & 3 deletions snes9x/dsp1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,9 @@ static void DSP1_Project (int16 X, int16 Y, int16 Z, int16 *H, int16 *V, int16 *
Py = DSP1_ShiftR(Py, E - refE);
Pz = DSP1_ShiftR(Pz, E3 - refE);

C11 =- (Px * DSP1.Nx >> 15);
C8 =- (Py * DSP1.Ny >> 15);
C9 =- (Pz * DSP1.Nz >> 15);
C11 = -(Px * DSP1.Nx >> 15);
C8 = -(Py * DSP1.Ny >> 15);
C9 = -(Pz * DSP1.Nz >> 15);
C12 = C11 + C8 + C9; // this cannot overflow!

aux4 = C12; // de-normalization with 32-bits arithmetic
Expand Down
2 changes: 2 additions & 0 deletions snes9x/gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ static int font_width = 8, font_height = 9;
static void SetupOBJ (void);
static void DrawOBJS (int);
static void DisplayFrameRate (void);
#ifdef fancy
static void DisplayPressedKeys (void);
static void DisplayWatchedAddresses (void);
#endif
static void DisplayStringFromBottom (const char *, int, int, bool);
static void DrawBackground (int, uint8, uint8);
static void DrawBackgroundMosaic (int, uint8, uint8);
Expand Down
Binary file added snes9x/icons/burger1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added snes9x/icons/burger2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added snes9x/icons/burger3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions snes9x/memmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif

static bool8 stopMovie = TRUE;
// static bool8 stopMovie = TRUE;
static char LastRomFilename[PATH_MAX + 1] = "";

// from NSRT
Expand Down Expand Up @@ -948,7 +948,8 @@ static bool8 is_SameGame_Add_On (uint8 *, uint32);
static bool8 is_GNEXT_BIOS (uint8 *, uint32);
static bool8 is_GNEXT_Add_On (uint8 *, uint32);
static uint32 caCRC32 (uint8 *, uint32, uint32 crc32 = 0xffffffff);
static uint32 ReadUPSPointer (const uint8 *, unsigned &, unsigned);
// unused? not externed or used anywhere in file...
// static uint32 ReadUPSPointer (const uint8 *, unsigned &, unsigned);
static bool8 ReadUPSPatch (Reader *, long, int32 &);
static long ReadInt (Reader *, unsigned);
static bool8 ReadIPSPatch (Reader *, long, int32 &);
Expand Down Expand Up @@ -2157,11 +2158,11 @@ bool8 CMemory::SaveSRAM (const char *filename)
if (file)
{
size_t ignore;
printf("Writing file %s.\n", file);
printf("Writing file %s.\n", sramName);
ignore = fwrite((char *) SRAM, 1, size, file);
fclose(file);
#ifdef __linux
printf("Changing permissions for file %s.\n", file);
printf("Changing permissions for file %s.\n", sramName);
ignore = chown(sramName, getuid(), getgid());
#endif

Expand Down Expand Up @@ -3917,7 +3918,7 @@ static bool8 ReadBPSPatch (Reader *r, long, int32 &rom_size)
if(patch_crc32 != pp_crc32) { delete[] data; return false; } //patch is corrupted
if(rom_crc32 != source_crc32) { delete[] data; return false; } //patch is for a different ROM

uint32 source_size = XPSdecode(data, addr, size);
// uint32 source_size = XPSdecode(data, addr, size);
uint32 target_size = XPSdecode(data, addr, size);
uint32 metadata_size = XPSdecode(data, addr, size);
addr += metadata_size;
Expand All @@ -3937,7 +3938,10 @@ static bool8 ReadBPSPatch (Reader *r, long, int32 &rom_size)

switch((int)mode) {
case SourceRead:
while(length--) patched_rom[outputOffset++] = Memory.ROM[outputOffset];
while(length--) {
patched_rom[outputOffset] = Memory.ROM[outputOffset + 1];
outputOffset++;
}
break;
case TargetRead:
while(length--) patched_rom[outputOffset++] = data[addr++];
Expand Down
1 change: 0 additions & 1 deletion snes9x/memmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ struct SMulti
extern CMemory Memory;
extern SMulti Multi;

// void S9xAutoSaveSRAM (void);
extern "C" void S9xAutoSaveSRAM (void);
bool8 LoadZip(const char *, int32 *, int32 *, uint8 *);

Expand Down
2 changes: 1 addition & 1 deletion snes9x/sdl/buildhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -o verbose
OUT=../../output
OBJECTS="../apu/apu.cpp ../apu/SNES_SPC.cpp ../apu/SNES_SPC_misc.cpp ../apu/SNES_SPC_state.cpp ../apu/SPC_DSP.cpp ../apu/SPC_Filter.cpp ../bsx.cpp ../c4.cpp ../c4emu.cpp ../clip.cpp ../controls.cpp ../cpu.cpp ../cpuexec.cpp ../cpuops.cpp ../dma.cpp ../dsp.cpp ../dsp1.cpp ../dsp2.cpp ../dsp3.cpp ../dsp4.cpp ../fxinst.cpp ../fxemu.cpp ../gfx.cpp ../globals.cpp ../memmap.cpp ../obc1.cpp ../ppu.cpp ../reader.cpp ../sa1.cpp ../sa1cpu.cpp ../sdd1.cpp ../sdd1emu.cpp ../seta.cpp ../seta010.cpp ../seta011.cpp ../seta018.cpp ../snes9x.cpp ../spc7110.cpp ../srtc.cpp ../tile.cpp sdlmain.cpp sdlinput.cpp sdlvideo.cpp sdlaudio.cpp"
INCLUDES="-I. -I.. -I../apu/"
CCFLAGS="-U__linux -O3 -DLSB_FIRST -fomit-frame-pointer -fno-exceptions -fno-rtti -pedantic -Wall -W -Wno-unused-parameter -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_MKSTEMP -DHAVE_STRINGS_H -DHAVE_SYS_IOCTL_H -DHAVE_STDINT_H -DRIGHTSHIFT_IS_SAR"
CCFLAGS="-U__linux -O3 -DLSB_FIRST -fomit-frame-pointer -fno-exceptions -fno-rtti -pedantic -Wall -W -Wno-unused-parameter -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -DHAVE_MKSTEMP -DHAVE_STRINGS_H -DHAVE_SYS_IOCTL_H -DHAVE_STDINT_H -DRIGHTSHIFT_IS_SAR -Wno-c++11-extensions"

emcc -O3 -s EXPORTED_FUNCTIONS="['_main', '_set_frameskip', '_set_transparency', '_run', '_toggle_display_framerate', '_S9xAutoSaveSRAM' ]" \
-s FORCE_FILESYSTEM=1 \
Expand Down
Loading

0 comments on commit 741561e

Please sign in to comment.