Skip to content

Commit

Permalink
Adding s2p2bin_plus.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Jun 9, 2015
1 parent 213118c commit 5347fa6
Show file tree
Hide file tree
Showing 11 changed files with 1,307 additions and 0 deletions.
101 changes: 101 additions & 0 deletions build_plus.bat
@@ -0,0 +1,101 @@
@ECHO OFF

REM // make sure we can write to the file s2built.bin
REM // also make a backup to s2built.prev.bin
IF NOT EXIST s2built.bin goto LABLNOCOPY
IF EXIST s2built.prev.bin del s2built.prev.bin
IF EXIST s2built.prev.bin goto LABLNOCOPY
move /Y s2built.bin s2built.prev.bin
IF EXIST s2built.bin goto LABLERROR3
REM IF EXIST s2built.prev.bin copy /Y s2built.prev.bin s2built.bin
:LABLNOCOPY

REM // delete some intermediate assembler output just in case
IF EXIST s2.p del s2.p
IF EXIST s2.p goto LABLERROR2
IF EXIST s2.h del s2.h
IF EXIST s2.h goto LABLERROR1

REM // clear the output window
cls


REM // run the assembler
REM // -xx shows the most detailed error output
REM // -c outputs a shared file (s2.h)
REM // -A gives us a small speedup
set AS_MSGPATH=win32/msg
set USEANSI=n

REM // allow the user to choose to print error messages out by supplying the -pe parameter
IF "%1"=="-pe" ( "win32/asw" -xx -c -A -L s2.asm ) ELSE "win32/asw" -xx -c -E -A -L s2.asm

REM // if there were errors, there won't be any s2.p output
IF NOT EXIST s2.p goto LABLERROR5

REM // combine the assembler output into a rom
IF EXIST s2.p "win32/s2p2bin_plus" s2.p s2built.bin s2.h

REM // fix some pointers and things that are impossible to fix from the assembler without un-splitting their data
IF EXIST s2built.bin "win32/fixpointer" s2.h s2built.bin off_3A294 MapRUnc_Sonic $2D 0 4 word_728C_user Obj5F_MapUnc_7240 2 2 1

REM REM // fix the rom header (checksum)
IF EXIST s2built.bin "win32/fixheader" s2built.bin

REM // if there were errors/warnings, a log file is produced
IF EXIST s2.log goto LABLERROR4


REM // done -- pause if we seem to have failed, then exit
IF EXIST s2built.bin exit /b

pause


exit /b

:LABLERROR1
echo Failed to build because write access to s2.h was denied.
pause


exit /b

:LABLERROR2
echo Failed to build because write access to s2.p was denied.
pause


exit /b

:LABLERROR3
echo Failed to build because write access to s2built.bin was denied.
pause

exit /b

:LABLERROR4
REM // display a noticeable message
echo.
echo **********************************************************************
echo * *
echo * There were build warnings. See s2.log for more details. *
echo * *
echo **********************************************************************
echo.
pause

exit /b

:LABLERROR5
REM // display a noticeable message
echo.
echo **********************************************************************
echo * *
echo * There were build errors. See s2.log for more details. *
echo * *
echo **********************************************************************
echo.
pause


56 changes: 56 additions & 0 deletions build_plus.sh
@@ -0,0 +1,56 @@
#!/bin/bash

[[ ! -d bin ]] && mkdir bin

if [[ ! -f bin/s2p2bin_plus ]]; then
echo "Compiling s2p2bin_plus..."
g++ -O3 -s -o bin/s2p2bin_plus build_source/s2p2bin_plus.cpp build_source/saxman.cpp &> /dev/null
fi

if [[ ! -f bin/fixpointer ]]; then
echo "Compiling fixpointer..."
g++ -O3 -s -o bin/fixpointer build_source/fixpointer.cpp &> /dev/null
fi

if [[ ! -f bin/fixheader ]]; then
echo "Compiling fixheader..."
g++ -O3 -s -o bin/fixheader build_source/fixheader.cpp &> /dev/null
fi

[[ -f s2built.bin ]] && mv -f s2built.bin s2built.prev.bin
rm -f s2.p s2.h s2.log

debug_syms=""
print_err="-E -q"

for n in `seq 1 2`; do
if [[ "$1" == "-ds" ]]; then
debug_syms="-g MAP"
echo "Will generate debug symbols"
elif [[ "$1" == "-pe" ]]; then
print_err=""
echo "Selected detailed assembler output"
fi
shift
done

echo Assembling...

asl -xx -c $debug_syms $print_err -A -U -L s2.asm

if [[ -f s2.log ]]; then
echo
echo "*****************************************"
echo "* *"
echo "* There were build errors/warnings. *"
echo "* *"
echo "*****************************************"
echo
cat s2.log
exit 1
fi

[[ -f s2.p ]] && bin/s2p2bin_plus s2.p s2built.bin s2.h
[[ -f s2built.bin ]] && bin/fixpointer s2.h s2built.bin off_3A294 MapRUnc_Sonic \$2D 0 4 word_728C_user Obj5F_MapUnc_7240 2 2 1
[[ -f s2built.bin ]] && bin/fixheader s2built.bin

169 changes: 169 additions & 0 deletions build_source/bigendian_io.h
@@ -0,0 +1,169 @@
/* -*- Mode: C++; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* Copyright (C) Flamewing 2011-2013 <flamewing.sonic@gmail.com>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _BIGENDIAN_IO_H_
#define _BIGENDIAN_IO_H_

#include <iosfwd>
#include <iterator>
#include <string>

#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(__LCLINT__)
# define UNUSED(x) /*@unused@*/ x
#elif defined(__cplusplus)
# define UNUSED(x)
#else
# define UNUSED(x) x
#endif

inline size_t Read1(std::istream &in) {
size_t c = static_cast<unsigned char>(in.get());
return c;
}

inline size_t Read1(char const *& in) {
size_t c = static_cast<unsigned char>(*in++);
return c;
}

inline size_t Read1(unsigned char const *& in) {
size_t c = *in++;
return c;
}

inline size_t Read1(std::istream_iterator<unsigned char>& in) {
size_t c = *in++;
return c;
}

inline void Write1(std::ostream &out, size_t c) {
out.put(static_cast<char>(c & 0xff));
}

inline void Write1(char *&out, size_t c) {
*out++ = static_cast<char>(c & 0xff);
}

inline void Write1(unsigned char *&out, size_t c) {
*out++ = static_cast<char>(c & 0xff);
}

inline void Write1(std::string &out, size_t c) {
out.push_back(static_cast<char>(c & 0xff));
}

inline void Write1(std::ostream_iterator<unsigned char>&out, size_t c) {
*out++ = static_cast<char>(c & 0xff);
}

namespace BigEndian {
template <typename T>
inline size_t Read2(T &in) {
size_t c = Read1(in) << 8;
c |= Read1(in);
return c;
}

template <typename T>
inline size_t Read4(T &in) {
size_t c = Read1(in) << 24;
c |= Read1(in) << 16;
c |= Read1(in) << 8;
c |= Read1(in);
return c;
}

template <typename T, int N>
inline size_t ReadN(T &in) {
size_t c = 0;
for (size_t i = 0; i < N; i++)
c = (c << 8) | Read1(in);
return c;
}

template <typename T>
inline void Write2(T &out, size_t c) {
Write1(out, (c & 0xff00) >> 8);
Write1(out, c & 0xff);
}

template <typename T>
inline void Write4(T &out, size_t c) {
Write1(out, (c & 0xff000000) >> 24);
Write1(out, (c & 0x00ff0000) >> 16);
Write1(out, (c & 0x0000ff00) >> 8);
Write1(out, (c & 0x000000ff));
}

template <typename T, int N>
inline void WriteN(T &out, size_t c) {
for (int i = 8 * (N - 1); i >= 0; i -= 8)
Write1(out, (c >> i) & 0xff);
}
}

namespace LittleEndian {
template <typename T>
inline size_t Read2(T &in) {
size_t c = Read1(in);
c |= Read1(in) << 8;
return c;
}

template <typename T>
inline size_t Read4(T &in) {
size_t c = Read1(in);
c |= Read1(in) << 8;
c |= Read1(in) << 16;
c |= Read1(in) << 24;
return c;
}

template <typename T, int N>
inline size_t ReadN(T &in) {
size_t c = 0;
for (size_t i = 0; i < 8 * N; i += 8)
c = c | (Read1(in) << i);
return c;
}

template <typename T>
inline void Write2(T &out, size_t c) {
Write1(out, c & 0xff);
Write1(out, (c & 0xff00) >> 8);
}

template <typename T>
inline void Write4(T &out, size_t c) {
Write1(out, (c & 0x000000ff));
Write1(out, (c & 0x0000ff00) >> 8);
Write1(out, (c & 0x00ff0000) >> 16);
Write1(out, (c & 0xff000000) >> 24);
}

template <typename T, int N>
inline void WriteN(T &out, size_t c) {
for (size_t i = 0; i < 8 * N; i += 8)
Write1(out, (c >> i) & 0xff);
}
}

#endif

0 comments on commit 5347fa6

Please sign in to comment.