Partially fixes#87, but there are probably more potential overflows
lurking in there; I didn't go over it too thoroughly.
FYI: In C, integer overflow when adding and multiplying signed integers
is undefined, as is shifting any integer by too high a width, and
left-shifting a signed integer if it changes the sign. GCC started
performing optimizations based on these a decade ago, but those
optimizations don't usually apply in any particular situation, so
usually you just get away with it.
But on my system, with clang-802.0.42, Mario 64 actually fails to boot
in the interpreter without this patch: it fails the ROM checksum test
performed early on (at 0x800001AC). (Not sure exactly which operation
was responsible; I compiled with -fsanitize=undefined, fixed everything
that made it crash under that and some nearby code, and now Mario 64
works. However, all of the changes here should be correct/necessary.)
It originally mapped to SDL_GL_SWAP_CONTROL, which was removed in SDL
1.3; whoever wrote this decided to replace it with
SDL_RENDERER_PRESENTVSYNC. However, SDL_RENDERER_PRESENTVSYNC is not a
GL attribute: it's a setting used when creating a 2D renderer, which
this code doesn't use at all. If passed to SDL_GL_(Get|Set)Attribute,
it'll be interpreted as the SDL_GLattr value which happens to have the
same numeric value, 4, namely SDL_GL_BUFFER_SIZE.
This changes the code to use the functions SDL_GL_(Get|Set)SwapInterval
instead.
- Explicitly name asm_defines_gas.h and asm_defines_nasm.h rather than
using a wildcard rule: otherwise make automatically deletes the latter
after the build is complete(!?) - see [1].
- Add missing dependency of the awk rule on ../../tools/gen_asm_defines.awk.
[1]
https://www.gnu.org/software/make/manual/html_node/Chained-Rules.html
This didn't work correctly for two reasons:
- The symbols were being marked as undefined (imported) rather than
exported. I could fix that by adding an initializer (= {0}), but then
the binary gets huge; not sure if there's a way around that.
- Mach-O binaries don't store symbol sizes. You can get nm to try to
calculate them with --size-sort, but I'm not sure if this will always
output the correct result.
In lieu of more complicated platform-specific fixes, I switched to an
approach that renders the value as hex, allowing the object file to be
piped directly to awk on all platforms.
- Fix BITS=32 build (-Wl,-m,elf_i386 obviously doesn't work, and -m32
isn't needed since another part adds '-arch i686' to CFLAGS).
- Change -bundle to -dynamiclib. (-bundle has been effectively
deprecated altogether since the early days of OS X, and was never the
right setting for .dylib files.)
- Only pass '-read_only_relocs suppress' on 32-bit. On x86-64 this flag
just emits a warning saying that it has no effect, and evidently isn't
necessary. (On 32-bit x86 it enables text relocations, which are used
by some of the asm stuff.)
Fixed a small formatting error in the README file's markdown. Prior to fix, It listed the mupen64plus website AND a link separately. This is to address that.