Repository navigation
Conversation
The big-endian branch in graphics.cpp dates from SDL1, where the screen surface could have a display format other than RGB565 and the double buffer had to go through SDL_DisplayFormat(). Its SDL2 side was never written: it refers to sdlTexture and myPixels, which do not exist anywhere, so the build fails on big-endian machines: FeLib/Source/graphics.cpp:288:21: error: use of undeclared identifier 'sdlTexture' The same #if also hides the whole stretch-region implementation and the real BlitDBToScreen() behind its #else, so fixing only that line would move the failure to link time. With SDL2 the texture is created as SDL_PIXELFORMAT_RGB565, a packed format that SDL reads in native byte order, which is exactly what the packcol16 double buffer holds. The regular code path is therefore correct on big-endian too. Limit the special case to SDL1 and drop the dead SDL2 placeholder. Tested on FreeBSD/powerpc64 (big-endian POWER9).
The SMF parser converts the big-endian header and track fields by reversing the bytes in place and then reading them back as native integers, which only works on little-endian machines. On big-endian ones the track count of Cathedral.mid comes out as 4608 instead of 18, MPB_ResetMIDITracks() writes past Track[MAX_MIDI_TRACKS] and the audio thread crashes as soon as the first song is loaded. The tempo meta event has the same problem and additionally memcpy()s its three bytes into the first bytes of a uint32_t, which are the high bytes there. Assemble the values from the individual bytes instead. That is correct on either byte order and also avoids the unaligned 16- and 32-bit accesses into the read buffer. Tested on FreeBSD/powerpc64 (big-endian POWER9): the parsed header of Music/Cathedral.mid now matches the file and the game reaches the main menu.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two small fixes found while packaging IVAN 0.59 for FreeBSD/powerpc64 (big-endian POWER9). Both apply to current master.
0001 Fix SDL2 build on big-endian hosts
FeLib/Source/graphics.cppguards an SDL1-eraBlitDBToScreen()with#if SDL_BYTEORDER == SDL_BIG_ENDIAN. Its SDL2 side refers tosdlTextureandmyPixels, which do not exist, so the build fails:The
#elseof the same#ifalso hides the whole stretch-region implementation and the realBlitDBToScreen(). With SDL2 the texture isSDL_PIXELFORMAT_RGB565, a packed format SDL reads in native byte order, which is what thepackcol16double buffer holds, so the regular path is already correct on big-endian. The patch limits the special case to SDL1 and drops the dead placeholder.0002 Fix MIDI parsing on big-endian hosts
audio/midiparser.cppconverts the big-endian SMF header and track fields by reversing bytes in place and reading them as native integers, which only works on little-endian. On powerpc64 Cathedral.mid reports 4608 tracks instead of 18,MPB_ResetMIDITracks()runs pastTrack[MAX_MIDI_TRACKS]and the audio thread segfaults while loading the first song. The tempo meta event inaudio/midiplayback.cpphas the same problem plus amemcpyof 3 bytes into auint32_t. The patch assembles the values from bytes, which is byte-order independent and also avoids the unaligned accesses.Testing
MIDIParse_Header()/MIDIParse_Track()onMusic/Cathedral.midreturns format 1, 18 tracks, PPQ 96, first track length 12, matching the file bytes.